Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions server/src/main/java/org/atmosphere/nettosphere/BridgeRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Do not use *

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -123,6 +118,7 @@
@Sharable
public class BridgeRuntime extends HttpStaticFileServerHandler {

private final ExecutorService executor = Executors.newSingleThreadExecutor();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should make this optional, and the Thread pool configuration and optional. Making it the default change the current behaviour, and we will have to bump to a major version 4.0.0

public static boolean NETTY_41_PLUS;

static {
Expand Down Expand Up @@ -294,15 +290,21 @@ public AtmosphereFramework framework() {

@Override
public void channelRead(final ChannelHandlerContext ctx, final Object messageEvent) throws URISyntaxException, IOException {
try {
handleMessageEvent(ctx, messageEvent);
} finally {
if (messageEvent instanceof ReferenceCounted) {
ReferenceCounted refMsg = (ReferenceCounted) messageEvent;
if (refMsg.refCnt() > 0)
refMsg.release();
executor.execute(() -> {
try {
handleMessageEvent(ctx, messageEvent);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (messageEvent instanceof ReferenceCounted) {
ReferenceCounted refMsg = (ReferenceCounted) messageEvent;
if (refMsg.refCnt() > 0)
refMsg.release();
}
}
}
});
}

private void handleMessageEvent(final ChannelHandlerContext ctx, final Object messageEvent) throws URISyntaxException, IOException {
Expand Down