From 848445c995da2ba9c3efb70685c77c3d4958905f Mon Sep 17 00:00:00 2001 From: richie Date: Wed, 17 Oct 2018 14:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=90=AF=E5=8A=A8=E7=9B=91?= =?UTF-8?q?=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/third/socketio/SocketIOServer.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java b/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java index 329448eb0..7dc37c2df 100644 --- a/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java +++ b/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java @@ -39,6 +39,7 @@ import java.util.Collection; import java.util.UUID; import java.util.concurrent.TimeUnit; +import io.netty.util.concurrent.GenericFutureListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -135,13 +136,37 @@ public class SocketIOServer implements ClientListeners { startAsync().syncUninterruptibly(); } - + + public void start(GenericFutureListener> listener) { + startAsync(listener).syncUninterruptibly(); + } + /** * Start server asynchronously * * @return void */ public Future startAsync() { + return startAsync(new FutureListener() { + + @Override + public void operationComplete(Future future) throws Exception { + + if (future.isSuccess()) { + log.info("SocketIO server started at port: {}", configCopy.getPort()); + } else { + log.error("SocketIO server start failed at port: {}!", configCopy.getPort()); + } + } + }); + } + + /** + * Start server asynchronously + * + * @return void + */ + public Future startAsync(GenericFutureListener> listener) { log.info("Session store / pubsub factory used: {}", configCopy.getStoreFactory()); initGroups(); @@ -164,18 +189,7 @@ public class SocketIOServer implements ClientListeners { addr = new InetSocketAddress(configCopy.getHostname(), configCopy.getPort()); } - return b.bind(addr).addListener(new FutureListener() { - - @Override - public void operationComplete(Future future) throws Exception { - - if (future.isSuccess()) { - log.info("SocketIO server started at port: {}", configCopy.getPort()); - } else { - log.error("SocketIO server start failed at port: {}!", configCopy.getPort()); - } - } - }); + return b.bind(addr).addListener(listener); } protected void applyConnectionOptions(ServerBootstrap bootstrap) {