Skip to content

Commit

Permalink
Fixes #7514 - Adding InheritedListeners to already-started components… (
Browse files Browse the repository at this point in the history
#7522)

* Fixes #7514 - Adding InheritedListeners to already-started components can cause IllegalStateException

Removed the unnecessary check-and-throw statements from SelectorManager.
Use COW array for listeners that can be modified whilst selector is running.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Signed-off-by: Greg Wilkins <gregw@webtide.com>
Co-authored-by: Greg Wilkins <gregw@webtide.com>
  • Loading branch information
sbordet and gregw committed Feb 3, 2022
1 parent 221f677 commit 4037861
Showing 1 changed file with 2 additions and 6 deletions.
Expand Up @@ -22,10 +22,10 @@
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.IntUnaryOperator;
Expand Down Expand Up @@ -60,7 +60,7 @@ public abstract class SelectorManager extends ContainerLifeCycle implements Dump
private final ManagedSelector[] _selectors;
private final AtomicInteger _selectorIndex = new AtomicInteger();
private final IntUnaryOperator _selectorIndexUpdate;
private final List<AcceptListener> _acceptListeners = new ArrayList<>();
private final List<AcceptListener> _acceptListeners = new CopyOnWriteArrayList<>();
private long _connectTimeout = DEFAULT_CONNECT_TIMEOUT;
private ThreadPoolBudget.Lease _lease;

Expand Down Expand Up @@ -396,8 +396,6 @@ protected void connectionFailed(SelectableChannel channel, Throwable ex, Object
@Override
public boolean addEventListener(EventListener listener)
{
if (isRunning())
throw new IllegalStateException(this.toString());
if (super.addEventListener(listener))
{
if (listener instanceof AcceptListener)
Expand All @@ -410,8 +408,6 @@ public boolean addEventListener(EventListener listener)
@Override
public boolean removeEventListener(EventListener listener)
{
if (isRunning())
throw new IllegalStateException(this.toString());
if (super.removeEventListener(listener))
{
if (listener instanceof AcceptListener)
Expand Down

0 comments on commit 4037861

Please sign in to comment.