From 2de1ea519f2d837fab3df4a7794593274b957142 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Wed, 5 Dec 2012 19:46:20 +0400 Subject: [PATCH 01/16] EventSourceClient introduced, it allows to utilize single netty bootstrap for multiple event streams, granting singnificant performance on multiple event-stream connections. Event stream content-type detection fixed, now it accepts event streams with addition data in content type maven-gpg-plugin new run in disabled by default profile sign --- pom.xml | 44 ++++++---- .../eventsource/client/EventSource.java | 57 +++---------- .../eventsource/client/EventSourceClient.java | 81 +++++++++++++++++++ .../impl/netty/EventSourceChannelHandler.java | 21 +++-- .../client/EventSourceClientTest.java | 5 +- 5 files changed, 137 insertions(+), 71 deletions(-) create mode 100644 src/main/java/com/github/eventsource/client/EventSourceClient.java diff --git a/pom.xml b/pom.xml index 1f60e61..ee02e5b 100644 --- a/pom.xml +++ b/pom.xml @@ -67,23 +67,33 @@ 1.6 - - org.apache.maven.plugins - maven-gpg-plugin - 1.1 - - true - - - - sign-artifacts - verify - - sign - - - - + + + + sign + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.1 + + true + + + + sign-artifacts + verify + + sign + + + + + + + + diff --git a/src/main/java/com/github/eventsource/client/EventSource.java b/src/main/java/com/github/eventsource/client/EventSource.java index 17d8cce..ffd010d 100644 --- a/src/main/java/com/github/eventsource/client/EventSource.java +++ b/src/main/java/com/github/eventsource/client/EventSource.java @@ -2,67 +2,35 @@ import com.github.eventsource.client.impl.AsyncEventSourceHandler; import com.github.eventsource.client.impl.netty.EventSourceChannelHandler; -import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.channel.ChannelFuture; -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; -import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; -import org.jboss.netty.handler.codec.frame.Delimiters; -import org.jboss.netty.handler.codec.http.HttpRequestEncoder; -import org.jboss.netty.handler.codec.string.StringDecoder; -import java.net.InetSocketAddress; import java.net.URI; import java.util.concurrent.Executor; -import java.util.concurrent.Executors; -public class EventSource { +public class EventSource { public static final long DEFAULT_RECONNECTION_TIME_MILLIS = 2000; - public static final int CONNECTING = 0; - public static final int OPEN = 1; - public static final int CLOSED = 2; - - private final ClientBootstrap bootstrap; private final EventSourceChannelHandler clientHandler; - private int readyState; - /** - * Creates a new EventSource client. The client will reconnect on - * lost connections automatically, unless the connection is closed explicitly by a call to + * Creates a new EventSource client. The client will reconnect on + * lost connections automatically, unless the connection is closed explicitly by a call to * {@link com.github.eventsource.client.EventSource#close()}. * * For sample usage, see examples at GitHub. - * - * @param executor the executor that will receive events + * + * @param eventSourceClient EventSourceClient to start event source at * @param reconnectionTimeMillis delay before a reconnect is made - in the event of a lost connection * @param uri where to connect * @param eventSourceHandler receives events * @see #close() */ - public EventSource(Executor executor, long reconnectionTimeMillis, final URI uri, EventSourceHandler eventSourceHandler) { - bootstrap = new ClientBootstrap( - new NioClientSocketChannelFactory( - Executors.newSingleThreadExecutor(), - Executors.newSingleThreadExecutor())); - bootstrap.setOption("remoteAddress", new InetSocketAddress(uri.getHost(), uri.getPort())); - - clientHandler = new EventSourceChannelHandler(new AsyncEventSourceHandler(executor, eventSourceHandler), reconnectionTimeMillis, bootstrap, uri); - - bootstrap.setPipelineFactory(new ChannelPipelineFactory() { - public ChannelPipeline getPipeline() throws Exception { - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast("line", new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, Delimiters.lineDelimiter())); - pipeline.addLast("string", new StringDecoder()); + public EventSource(EventSourceClient eventSourceClient, long reconnectionTimeMillis, final URI uri, EventSourceHandler eventSourceHandler) { + clientHandler = new EventSourceChannelHandler(new AsyncEventSourceHandler(eventSourceClient.getEventExecutor(), eventSourceHandler), reconnectionTimeMillis, eventSourceClient, uri); + } - pipeline.addLast("encoder", new HttpRequestEncoder()); - pipeline.addLast("es-handler", clientHandler); - return pipeline; - } - }); + public EventSource(Executor eventExecutor, long reconnectionTimeMillis, URI uri, EventSourceHandler eventSourceHandler) { + this(new EventSourceClient(eventExecutor), reconnectionTimeMillis, uri, eventSourceHandler); } public EventSource(String uri, EventSourceHandler eventSourceHandler) { @@ -70,12 +38,11 @@ public EventSource(String uri, EventSourceHandler eventSourceHandler) { } public EventSource(URI uri, EventSourceHandler eventSourceHandler) { - this(Executors.newSingleThreadExecutor(), DEFAULT_RECONNECTION_TIME_MILLIS, uri, eventSourceHandler); + this(new EventSourceClient(), DEFAULT_RECONNECTION_TIME_MILLIS, uri, eventSourceHandler); } public ChannelFuture connect() { - readyState = CONNECTING; - return bootstrap.connect(); + return clientHandler.connect(); } /** diff --git a/src/main/java/com/github/eventsource/client/EventSourceClient.java b/src/main/java/com/github/eventsource/client/EventSourceClient.java new file mode 100644 index 0000000..c0bed2b --- /dev/null +++ b/src/main/java/com/github/eventsource/client/EventSourceClient.java @@ -0,0 +1,81 @@ +package com.github.eventsource.client; + +import org.jboss.netty.bootstrap.ClientBootstrap; +import org.jboss.netty.channel.*; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; +import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; +import org.jboss.netty.handler.codec.frame.Delimiters; +import org.jboss.netty.handler.codec.http.HttpRequestEncoder; +import org.jboss.netty.handler.codec.string.StringDecoder; + +import java.net.InetSocketAddress; +import java.util.HashMap; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +/** + * created by andrey.chursin, 05.12.12 + */ +public class EventSourceClient { + private final ClientBootstrap bootstrap; + private final Executor eventExecutor; + + private final HashMap handlerMap = new HashMap(); + + public EventSourceClient() { + this(Executors.newSingleThreadExecutor()); + } + + public EventSourceClient(Executor eventExecutor) { + this.eventExecutor = eventExecutor; + bootstrap = new ClientBootstrap( + new NioClientSocketChannelFactory( + Executors.newSingleThreadExecutor(), + Executors.newCachedThreadPool())); + + bootstrap.setPipelineFactory(new ChannelPipelineFactory() { + public ChannelPipeline getPipeline() throws Exception { + ChannelPipeline pipeline = Channels.pipeline(); + pipeline.addLast("line", new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, Delimiters.lineDelimiter())); + pipeline.addLast("string", new StringDecoder()); + + pipeline.addLast("encoder", new HttpRequestEncoder()); + pipeline.addLast("es-handler", new Handler()); + return pipeline; + } + }); + } + + public ChannelFuture connect(InetSocketAddress address, ChannelUpstreamHandler handler) { + synchronized (handlerMap) { + ChannelFuture channelFuture = bootstrap.connect(address); + handlerMap.put(channelFuture.getChannel(), handler); + return channelFuture; + } + } + + private class Handler extends SimpleChannelUpstreamHandler { + @Override + public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception { + final ChannelUpstreamHandler handler; + synchronized (handlerMap) { + handler = handlerMap.get(ctx.getChannel()); + } + if (handler == null) { + super.handleUpstream(ctx, e); + + if (e instanceof ChannelStateEvent && ((ChannelStateEvent) e).getState() == ChannelState.OPEN) { + return; //Do nothing, this one will not be dispatched to handler, but it's ok + } + + System.err.println("Something wrong with dispatching"); + } else { + handler.handleUpstream(ctx, e); + } + } + } + + public Executor getEventExecutor() { + return eventExecutor; + } +} diff --git a/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java b/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java index 6ad7d7b..cd21eea 100644 --- a/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java +++ b/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java @@ -1,10 +1,10 @@ package com.github.eventsource.client.impl.netty; +import com.github.eventsource.client.EventSourceClient; import com.github.eventsource.client.EventSourceException; import com.github.eventsource.client.EventSourceHandler; import com.github.eventsource.client.impl.ConnectionHandler; import com.github.eventsource.client.impl.EventStreamParser; -import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.channel.*; import org.jboss.netty.handler.codec.http.DefaultHttpRequest; import org.jboss.netty.handler.codec.http.HttpHeaders.Names; @@ -17,6 +17,7 @@ import org.jboss.netty.util.TimerTask; import java.net.ConnectException; +import java.net.InetSocketAddress; import java.net.URI; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -25,10 +26,10 @@ public class EventSourceChannelHandler extends SimpleChannelUpstreamHandler implements ConnectionHandler { private static final Pattern STATUS_PATTERN = Pattern.compile("HTTP/1.1 (\\d+) (.*)"); - private static final Pattern CONTENT_TYPE_PATTERN = Pattern.compile("Content-Type: text/event-stream"); + private static final Pattern CONTENT_TYPE_PATTERN = Pattern.compile("Content-Type: text/event-stream;?.*"); private final EventSourceHandler eventSourceHandler; - private final ClientBootstrap bootstrap; + private final EventSourceClient client; private final URI uri; private final EventStreamParser messageDispatcher; @@ -42,10 +43,10 @@ public class EventSourceChannelHandler extends SimpleChannelUpstreamHandler impl private Integer status; private AtomicBoolean reconnecting = new AtomicBoolean(false); - public EventSourceChannelHandler(EventSourceHandler eventSourceHandler, long reconnectionTimeMillis, ClientBootstrap bootstrap, URI uri) { + public EventSourceChannelHandler(EventSourceHandler eventSourceHandler, long reconnectionTimeMillis, EventSourceClient client, URI uri) { this.eventSourceHandler = eventSourceHandler; this.reconnectionTimeMillis = reconnectionTimeMillis; - this.bootstrap = bootstrap; + this.client = client; this.uri = uri; this.messageDispatcher = new EventStreamParser(uri.toString(), eventSourceHandler, this); } @@ -143,6 +144,10 @@ public EventSourceChannelHandler close() { return this; } + public ChannelFuture connect() { + return client.connect(getConnectAddress(), this); + } + public EventSourceChannelHandler join() throws InterruptedException { if (channel != null) { channel.getCloseFuture().await(); @@ -157,9 +162,13 @@ private void reconnect() { @Override public void run(Timeout timeout) throws Exception { reconnecting.set(false); - bootstrap.connect().await(); + connect().await(); } }, reconnectionTimeMillis, TimeUnit.MILLISECONDS); } } + + public InetSocketAddress getConnectAddress() { + return new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()); + } } \ No newline at end of file diff --git a/src/test/java/com/github/eventsource/client/EventSourceClientTest.java b/src/test/java/com/github/eventsource/client/EventSourceClientTest.java index 02fb54a..1203795 100644 --- a/src/test/java/com/github/eventsource/client/EventSourceClientTest.java +++ b/src/test/java/com/github/eventsource/client/EventSourceClientTest.java @@ -12,7 +12,6 @@ import java.net.URI; import java.util.List; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import static java.util.Arrays.asList; @@ -84,7 +83,7 @@ public void onClose(EventSourceConnection connection) throws Exception { webServer.start(); - eventSource = new EventSource(Executors.newSingleThreadExecutor(), 100, URI.create("http://localhost:59504/es/hello"), new EventSourceHandler() { + eventSource = new EventSource(new EventSourceClient(), 100, URI.create("http://localhost:59504/es/hello"), new EventSourceHandler() { @Override public void onConnect() { } @@ -129,7 +128,7 @@ private void assertSentAndReceived(final List messages) throws IOExcepti } private void startClient(final List expectedMessages, final CountDownLatch messageCountdown, final CountDownLatch errorCountdown, long reconnectionTimeMillis) throws InterruptedException { - eventSource = new EventSource(Executors.newSingleThreadExecutor(), reconnectionTimeMillis, URI.create("http://localhost:59504/es/hello?echoThis=yo"), new EventSourceHandler() { + eventSource = new EventSource(new EventSourceClient(), reconnectionTimeMillis, URI.create("http://localhost:59504/es/hello?echoThis=yo"), new EventSourceHandler() { int n = 0; @Override From 78982687d11145733474921a4b5a3a4007ad7930 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Wed, 5 Dec 2012 20:30:08 +0400 Subject: [PATCH 02/16] EventSourceClient channel cleanup added --- .../github/eventsource/client/EventSourceClient.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/com/github/eventsource/client/EventSourceClient.java b/src/main/java/com/github/eventsource/client/EventSourceClient.java index c0bed2b..10380dc 100644 --- a/src/main/java/com/github/eventsource/client/EventSourceClient.java +++ b/src/main/java/com/github/eventsource/client/EventSourceClient.java @@ -21,6 +21,7 @@ public class EventSourceClient { private final Executor eventExecutor; private final HashMap handlerMap = new HashMap(); + private final ThreadLocal currentlyConnectingChannel = new ThreadLocal(); public EventSourceClient() { this(Executors.newSingleThreadExecutor()); @@ -71,6 +72,15 @@ public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exc System.err.println("Something wrong with dispatching"); } else { handler.handleUpstream(ctx, e); + + if (e instanceof ChannelStateEvent) { + ChannelStateEvent stateEvent = (ChannelStateEvent) e; + if (stateEvent.getState() == ChannelState.BOUND && stateEvent.getValue() == null) { + synchronized (handlerMap) { + handlerMap.remove(ctx.getChannel()); + } + } + } } } } From 2cec72583a108ff8e9ad51b81733698df8fdad42 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 19:54:20 +0400 Subject: [PATCH 03/16] Fixed pom and removed author ref from event source client --- pom.xml | 22 ++++++++----------- .../eventsource/client/EventSourceClient.java | 4 ---- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index ee02e5b..bdbb540 100644 --- a/pom.xml +++ b/pom.xml @@ -1,17 +1,13 @@ - + 4.0.0 - com.github.aslakhellesoy + com.github eventsource-client - ${project.artifactId} + Java EventSource Client A Java EventSource Client - http://aslakhellesoy.github.com/eventsource-java - 0.1.2.1 + 0.2-SNAPSHOT jar - - org.sonatype.oss - oss-parent - 6 - + BSD License @@ -20,9 +16,9 @@ - scm:git:git://github.com/aslakhellesoy/eventsource-java.git - scm:git:git@github.com:aslakhellesoy/eventsource-java.git - git://github.com/aslakhellesoy/eventsource-java.git + scm:git:https://github.com/andll/eventsource-java.git + scm:git:git@github.com:andll/eventsource-java.git + git://github.com/andll/eventsource-java.git diff --git a/src/main/java/com/github/eventsource/client/EventSourceClient.java b/src/main/java/com/github/eventsource/client/EventSourceClient.java index 10380dc..952fa9e 100644 --- a/src/main/java/com/github/eventsource/client/EventSourceClient.java +++ b/src/main/java/com/github/eventsource/client/EventSourceClient.java @@ -13,15 +13,11 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; -/** - * created by andrey.chursin, 05.12.12 - */ public class EventSourceClient { private final ClientBootstrap bootstrap; private final Executor eventExecutor; private final HashMap handlerMap = new HashMap(); - private final ThreadLocal currentlyConnectingChannel = new ThreadLocal(); public EventSourceClient() { this(Executors.newSingleThreadExecutor()); From ecc3ff7b7ae77339b5d1391ab2af90be3eb34ed8 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 19:58:09 +0400 Subject: [PATCH 04/16] Removed idea project files --- eventsource-client.iml | 25 ---- eventsource-client.ipr | 294 ----------------------------------------- 2 files changed, 319 deletions(-) delete mode 100644 eventsource-client.iml delete mode 100644 eventsource-client.ipr diff --git a/eventsource-client.iml b/eventsource-client.iml deleted file mode 100644 index cd369a0..0000000 --- a/eventsource-client.iml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/eventsource-client.ipr b/eventsource-client.ipr deleted file mode 100644 index 95c6fbf..0000000 --- a/eventsource-client.ipr +++ /dev/null @@ -1,294 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://www.w3.org/1999/xhtml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 3166ae717502cb375db0ec9c4c5dda75baff5ea9 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 19:59:10 +0400 Subject: [PATCH 05/16] [maven-release-plugin] prepare release eventsource-client-0.2 --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index bdbb540..341dc20 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 com.github eventsource-client Java EventSource Client A Java EventSource Client - 0.2-SNAPSHOT + 0.2 jar From 066dc851e549ae585da681811382d3c3345a662d Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:08:56 +0400 Subject: [PATCH 06/16] Misc fixed --- .gitignore | 2 ++ pom.xml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 20502b0..5a919a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ target out *.iws +*.iml +*.ipr *.swp .idea release.properties diff --git a/pom.xml b/pom.xml index 341dc20..6617a2f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eventsource-client Java EventSource Client A Java EventSource Client - 0.2 + 0.3-SNAPSHOT jar From d67192a8fd11f4feaac19c5b4aaf4d0ae450ccc1 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:16:19 +0400 Subject: [PATCH 07/16] Added mind repository --- pom.xml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 6617a2f..827595f 100644 --- a/pom.xml +++ b/pom.xml @@ -14,17 +14,24 @@ repo + scm:git:https://github.com/andll/eventsource-java.git scm:git:git@github.com:andll/eventsource-java.git git://github.com/andll/eventsource-java.git - + + - repository.jboss.org - http://repository.jboss.org/nexus/content/groups/public/ + mind.releases + http://nexus.mindlabs.com/content/repositories/mind.releases - + + mind.snapshots + http://nexus.mindlabs.com/content/repositories/mind.snapshots + + + org.jboss.netty From 985d30c59670179c178d41d1e4c8b4e62af48929 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:18:49 +0400 Subject: [PATCH 08/16] Fixed pom --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 827595f..19543f3 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ scm:git:https://github.com/andll/eventsource-java.git - scm:git:git@github.com:andll/eventsource-java.git + scm:git:https://github.com/andll/eventsource-java.git git://github.com/andll/eventsource-java.git From f69cc2b6fca5956457db9b95e36b3a7f8bbb7525 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:19:20 +0400 Subject: [PATCH 09/16] [maven-release-plugin] prepare release eventsource-client-0.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 19543f3..d53a14d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eventsource-client Java EventSource Client A Java EventSource Client - 0.3-SNAPSHOT + 0.3 jar From 581f7f571d13dce9a3f75ca4f1ae18fbc060c3d7 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:19:29 +0400 Subject: [PATCH 10/16] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d53a14d..12fbbe5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eventsource-client Java EventSource Client A Java EventSource Client - 0.3 + 0.4-SNAPSHOT jar From 75432cfcaa3701a1f8c79b28f973c033cb2c6427 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:40:02 +0400 Subject: [PATCH 11/16] Added shutdown method --- .../java/com/github/eventsource/client/EventSourceClient.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/github/eventsource/client/EventSourceClient.java b/src/main/java/com/github/eventsource/client/EventSourceClient.java index 952fa9e..dc30d25 100644 --- a/src/main/java/com/github/eventsource/client/EventSourceClient.java +++ b/src/main/java/com/github/eventsource/client/EventSourceClient.java @@ -84,4 +84,8 @@ public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exc public Executor getEventExecutor() { return eventExecutor; } + + public void shutdown() { + bootstrap.releaseExternalResources(); + } } From 3ffaebfdf20d645fcb143f768c4c50a06f71dd46 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:40:23 +0400 Subject: [PATCH 12/16] [maven-release-plugin] prepare release eventsource-client-0.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 12fbbe5..73f768e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eventsource-client Java EventSource Client A Java EventSource Client - 0.4-SNAPSHOT + 0.4 jar From aca81caec655d5ef2f7f52f29cbcc721d788e5a4 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 20:40:35 +0400 Subject: [PATCH 13/16] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 73f768e..2730923 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eventsource-client Java EventSource Client A Java EventSource Client - 0.4 + 0.5-SNAPSHOT jar From 03325dabed2ab0d6f2b4a97ec3ff89a5d2da28fc Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 21:14:18 +0400 Subject: [PATCH 14/16] Fixed usage of HashedWheelTimer. Added support for disabled reconnection --- .../impl/netty/EventSourceChannelHandler.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java b/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java index cd21eea..f301a5a 100644 --- a/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java +++ b/src/main/java/com/github/eventsource/client/impl/netty/EventSourceChannelHandler.java @@ -33,7 +33,7 @@ public class EventSourceChannelHandler extends SimpleChannelUpstreamHandler impl private final URI uri; private final EventStreamParser messageDispatcher; - private final Timer timer = new HashedWheelTimer(); + private static final Timer TIMER = new HashedWheelTimer(); private Channel channel; private boolean reconnectOnClose = true; private long reconnectionTimeMillis; @@ -156,15 +156,19 @@ public EventSourceChannelHandler join() throws InterruptedException { } private void reconnect() { - if(!reconnecting.get()) { - reconnecting.set(true); - timer.newTimeout(new TimerTask() { - @Override - public void run(Timeout timeout) throws Exception { - reconnecting.set(false); - connect().await(); - } - }, reconnectionTimeMillis, TimeUnit.MILLISECONDS); + if(reconnectionTimeMillis >= 0) { + if(!reconnecting.get()) { + reconnecting.set(true); + TIMER.newTimeout(new TimerTask() + { + @Override + public void run(Timeout timeout) throws Exception + { + reconnecting.set(false); + connect().await(); + } + }, reconnectionTimeMillis, TimeUnit.MILLISECONDS); + } } } From bc6a36466882fd387fe444ccfff247fb5977e448 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 21:14:45 +0400 Subject: [PATCH 15/16] [maven-release-plugin] prepare release eventsource-client-0.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2730923..5405d2a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eventsource-client Java EventSource Client A Java EventSource Client - 0.5-SNAPSHOT + 0.5 jar From 6931e8745539fc166c0cae57f9d8835d0661fc33 Mon Sep 17 00:00:00 2001 From: Andrey Chursin Date: Thu, 20 Dec 2012 21:14:54 +0400 Subject: [PATCH 16/16] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5405d2a..64dc0f8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ eventsource-client Java EventSource Client A Java EventSource Client - 0.5 + 0.6-SNAPSHOT jar