diff --git a/fine-socketio/src/com/fr/third/socketio/AckCallback.java b/fine-socketio/src/com/fr/third/socketio/AckCallback.java index 2e30f897d..ba7a5a6b9 100644 --- a/fine-socketio/src/com/fr/third/socketio/AckCallback.java +++ b/fine-socketio/src/com/fr/third/socketio/AckCallback.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/AckMode.java b/fine-socketio/src/com/fr/third/socketio/AckMode.java index a73339e55..77eb27be4 100644 --- a/fine-socketio/src/com/fr/third/socketio/AckMode.java +++ b/fine-socketio/src/com/fr/third/socketio/AckMode.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/AckRequest.java b/fine-socketio/src/com/fr/third/socketio/AckRequest.java index d1c857c6d..c341eb4f3 100644 --- a/fine-socketio/src/com/fr/third/socketio/AckRequest.java +++ b/fine-socketio/src/com/fr/third/socketio/AckRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/AuthorizationListener.java b/fine-socketio/src/com/fr/third/socketio/AuthorizationListener.java index 139578e97..21be7f735 100644 --- a/fine-socketio/src/com/fr/third/socketio/AuthorizationListener.java +++ b/fine-socketio/src/com/fr/third/socketio/AuthorizationListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/BroadcastAckCallback.java b/fine-socketio/src/com/fr/third/socketio/BroadcastAckCallback.java index b5ca3a826..233b82164 100644 --- a/fine-socketio/src/com/fr/third/socketio/BroadcastAckCallback.java +++ b/fine-socketio/src/com/fr/third/socketio/BroadcastAckCallback.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/BroadcastOperations.java b/fine-socketio/src/com/fr/third/socketio/BroadcastOperations.java index 080e0200a..dd011d0bb 100644 --- a/fine-socketio/src/com/fr/third/socketio/BroadcastOperations.java +++ b/fine-socketio/src/com/fr/third/socketio/BroadcastOperations.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/ClientOperations.java b/fine-socketio/src/com/fr/third/socketio/ClientOperations.java index 357a6c08e..1f2924800 100644 --- a/fine-socketio/src/com/fr/third/socketio/ClientOperations.java +++ b/fine-socketio/src/com/fr/third/socketio/ClientOperations.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/Configuration.java b/fine-socketio/src/com/fr/third/socketio/Configuration.java index f3c5355f4..78d1f8463 100644 --- a/fine-socketio/src/com/fr/third/socketio/Configuration.java +++ b/fine-socketio/src/com/fr/third/socketio/Configuration.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,19 @@ */ package com.fr.third.socketio; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; + import com.fr.third.socketio.handler.SuccessAuthorizationListener; import com.fr.third.socketio.listener.DefaultExceptionListener; import com.fr.third.socketio.listener.ExceptionListener; import com.fr.third.socketio.protocol.JsonSupport; import com.fr.third.socketio.store.MemoryStoreFactory; +import com.fr.third.socketio.store.RedissonStoreFactory; import com.fr.third.socketio.store.StoreFactory; import javax.net.ssl.KeyManagerFactory; -import java.io.InputStream; -import java.util.Arrays; -import java.util.List; public class Configuration { @@ -85,6 +87,8 @@ public class Configuration { private boolean websocketCompression = true; + private boolean randomSession = false; + public Configuration() { } @@ -150,6 +154,7 @@ public class Configuration { setHttpCompression(conf.isHttpCompression()); setWebsocketCompression(conf.isWebsocketCompression()); + setRandomSession(conf.randomSession); } public JsonSupport getJsonSupport() { @@ -358,6 +363,7 @@ public class Configuration { * @param clientStoreFactory - implements StoreFactory * * @see MemoryStoreFactory + * @see RedissonStoreFactory */ public void setStoreFactory(StoreFactory clientStoreFactory) { this.storeFactory = clientStoreFactory; @@ -571,4 +577,11 @@ public class Configuration { return websocketCompression; } + public boolean isRandomSession() { + return randomSession; + } + + public void setRandomSession(boolean randomSession) { + this.randomSession = randomSession; + } } diff --git a/fine-socketio/src/com/fr/third/socketio/Disconnectable.java b/fine-socketio/src/com/fr/third/socketio/Disconnectable.java index 8edadbb83..644c18e2b 100644 --- a/fine-socketio/src/com/fr/third/socketio/Disconnectable.java +++ b/fine-socketio/src/com/fr/third/socketio/Disconnectable.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/DisconnectableHub.java b/fine-socketio/src/com/fr/third/socketio/DisconnectableHub.java index 28cf2c484..2fe1acb2a 100644 --- a/fine-socketio/src/com/fr/third/socketio/DisconnectableHub.java +++ b/fine-socketio/src/com/fr/third/socketio/DisconnectableHub.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/HandshakeData.java b/fine-socketio/src/com/fr/third/socketio/HandshakeData.java index 616d98e95..48a87e9f5 100644 --- a/fine-socketio/src/com/fr/third/socketio/HandshakeData.java +++ b/fine-socketio/src/com/fr/third/socketio/HandshakeData.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/JsonSupportWrapper.java b/fine-socketio/src/com/fr/third/socketio/JsonSupportWrapper.java index 87146ef03..6d65fbfb1 100644 --- a/fine-socketio/src/com/fr/third/socketio/JsonSupportWrapper.java +++ b/fine-socketio/src/com/fr/third/socketio/JsonSupportWrapper.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/MultiTypeAckCallback.java b/fine-socketio/src/com/fr/third/socketio/MultiTypeAckCallback.java index 7fc2f886a..975a2f7b2 100644 --- a/fine-socketio/src/com/fr/third/socketio/MultiTypeAckCallback.java +++ b/fine-socketio/src/com/fr/third/socketio/MultiTypeAckCallback.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/MultiTypeArgs.java b/fine-socketio/src/com/fr/third/socketio/MultiTypeArgs.java index 2bf29263f..591b33c85 100644 --- a/fine-socketio/src/com/fr/third/socketio/MultiTypeArgs.java +++ b/fine-socketio/src/com/fr/third/socketio/MultiTypeArgs.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/SocketConfig.java b/fine-socketio/src/com/fr/third/socketio/SocketConfig.java index 7406b0bde..a1ea9f5a7 100644 --- a/fine-socketio/src/com/fr/third/socketio/SocketConfig.java +++ b/fine-socketio/src/com/fr/third/socketio/SocketConfig.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/SocketIOChannelInitializer.java b/fine-socketio/src/com/fr/third/socketio/SocketIOChannelInitializer.java index a6ec0ffc1..645767565 100644 --- a/fine-socketio/src/com/fr/third/socketio/SocketIOChannelInitializer.java +++ b/fine-socketio/src/com/fr/third/socketio/SocketIOChannelInitializer.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,9 @@ import javax.net.ssl.SSLEngine; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; +import com.fr.third.socketio.scheduler.HashedWheelTimeoutScheduler; +import com.fr.third.socketio.transport.PollingTransport; +import com.fr.third.socketio.transport.WebSocketTransport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,12 +42,9 @@ import com.fr.third.socketio.protocol.JsonSupport; import com.fr.third.socketio.protocol.PacketDecoder; import com.fr.third.socketio.protocol.PacketEncoder; import com.fr.third.socketio.scheduler.CancelableScheduler; -import com.fr.third.socketio.scheduler.HashedWheelTimeoutScheduler; import com.fr.third.socketio.store.StoreFactory; import com.fr.third.socketio.store.pubsub.DisconnectMessage; import com.fr.third.socketio.store.pubsub.PubSubType; -import com.fr.third.socketio.transport.PollingTransport; -import com.fr.third.socketio.transport.WebSocketTransport; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; @@ -55,6 +55,7 @@ import io.netty.handler.codec.http.HttpMessage; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpResponseEncoder; +import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler; import io.netty.handler.ssl.SslHandler; public class SocketIOChannelInitializer extends ChannelInitializer implements DisconnectableHub { @@ -83,7 +84,7 @@ public class SocketIOChannelInitializer extends ChannelInitializer impl private AuthorizeHandler authorizeHandler; private PollingTransport xhrPollingTransport; private WebSocketTransport webSocketTransport; - //private WebSocketServerCompressionHandler webSocketTransportCompression = new WebSocketServerCompressionHandler(); + private WebSocketServerCompressionHandler webSocketTransportCompression = new WebSocketServerCompressionHandler(); private EncoderHandler encoderHandler; private WrongUrlHandler wrongUrlHandler; @@ -185,8 +186,7 @@ public class SocketIOChannelInitializer extends ChannelInitializer impl pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport); // TODO use single instance when https://github.com/netty/netty/issues/4755 will be resolved if (configuration.isWebsocketCompression()) { - // TODO:richie 去掉了压缩 - //pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler()); + pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler()); } pipeline.addLast(WEB_SOCKET_TRANSPORT, webSocketTransport); diff --git a/fine-socketio/src/com/fr/third/socketio/SocketIOClient.java b/fine-socketio/src/com/fr/third/socketio/SocketIOClient.java index 99add2817..a56d2ffe0 100644 --- a/fine-socketio/src/com/fr/third/socketio/SocketIOClient.java +++ b/fine-socketio/src/com/fr/third/socketio/SocketIOClient.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/SocketIONamespace.java b/fine-socketio/src/com/fr/third/socketio/SocketIONamespace.java index 3440608aa..892331fcc 100644 --- a/fine-socketio/src/com/fr/third/socketio/SocketIONamespace.java +++ b/fine-socketio/src/com/fr/third/socketio/SocketIONamespace.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java b/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java index 7dc37c2df..140ddbdfb 100644 --- a/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java +++ b/fine-socketio/src/com/fr/third/socketio/SocketIOServer.java @@ -1,12 +1,12 @@ /** - * Copyright 2012 Nikita Koksharov - *

+ * Copyright (c) 2012-2019 Nikita Koksharov + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * + * http://www.apache.org/licenses/LICENSE-2.0 + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,7 +15,6 @@ */ package com.fr.third.socketio; -import com.fr.third.socketio.listener.*; import com.fr.third.socketio.listener.ClientListeners; import com.fr.third.socketio.listener.ConnectListener; import com.fr.third.socketio.listener.DataListener; @@ -39,7 +38,6 @@ 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; @@ -48,48 +46,43 @@ import com.fr.third.socketio.namespace.NamespacesHub; /** * Fully thread-safe. + * */ public class SocketIOServer implements ClientListeners { - + private static final Logger log = LoggerFactory.getLogger(SocketIOServer.class); - + private final Configuration configCopy; - private final Configuration configuration; - + private final NamespacesHub namespacesHub; - private final SocketIONamespace mainNamespace; - + private SocketIOChannelInitializer pipelineFactory = new SocketIOChannelInitializer(); - + private EventLoopGroup bossGroup; - private EventLoopGroup workerGroup; - + public SocketIOServer(Configuration configuration) { - this.configuration = configuration; this.configCopy = new Configuration(configuration); namespacesHub = new NamespacesHub(configCopy); mainNamespace = addNamespace(Namespace.DEFAULT_NAME); } - + public void setPipelineFactory(SocketIOChannelInitializer pipelineFactory) { - this.pipelineFactory = pipelineFactory; } - + /** * Get all clients connected to default namespace * * @return clients collection */ public Collection getAllClients() { - return namespacesHub.get(Namespace.DEFAULT_NAME).getAllClients(); } - + /** * Get client by uuid from default namespace * @@ -97,25 +90,22 @@ public class SocketIOServer implements ClientListeners { * @return client */ public SocketIOClient getClient(UUID uuid) { - return namespacesHub.get(Namespace.DEFAULT_NAME).getClient(uuid); } - + /** * Get all namespaces * * @return namespaces collection */ public Collection getAllNamespaces() { - return namespacesHub.getAllNamespaces(); } - + public BroadcastOperations getBroadcastOperations() { - return new BroadcastOperations(getAllClients(), configCopy.getStoreFactory()); } - + /** * Get broadcast operations for clients within * room by room name @@ -124,76 +114,57 @@ public class SocketIOServer implements ClientListeners { * @return broadcast operations */ public BroadcastOperations getRoomOperations(String room) { - Iterable clients = namespacesHub.getRoomClients(room); return new BroadcastOperations(clients, configCopy.getStoreFactory()); } - + /** * Start server */ public void start() { - 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(); - + pipelineFactory.start(configCopy, namespacesHub); - + Class channelClass = NioServerSocketChannel.class; if (configCopy.isUseLinuxNativeEpoll()) { channelClass = EpollServerSocketChannel.class; } - + ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup) - .channel(channelClass) - .childHandler(pipelineFactory); + .channel(channelClass) + .childHandler(pipelineFactory); applyConnectionOptions(b); - + InetSocketAddress addr = new InetSocketAddress(configCopy.getPort()); if (configCopy.getHostname() != null) { addr = new InetSocketAddress(configCopy.getHostname(), configCopy.getPort()); } - - return b.bind(addr).addListener(listener); + + 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()); + } + } + }); } - + protected void applyConnectionOptions(ServerBootstrap bootstrap) { - SocketConfig config = configCopy.getSocketConfig(); bootstrap.childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay()); if (config.getTcpSendBufferSize() != -1) { @@ -205,13 +176,12 @@ public class SocketIOServer implements ClientListeners { } bootstrap.childOption(ChannelOption.SO_KEEPALIVE, config.isTcpKeepAlive()); bootstrap.childOption(ChannelOption.SO_LINGER, config.getSoLinger()); - + bootstrap.option(ChannelOption.SO_REUSEADDR, config.isReuseAddress()); bootstrap.option(ChannelOption.SO_BACKLOG, config.getAcceptBackLog()); } - + protected void initGroups() { - if (configCopy.isUseLinuxNativeEpoll()) { bossGroup = new EpollEventLoopGroup(configCopy.getBossThreads()); workerGroup = new EpollEventLoopGroup(configCopy.getWorkerThreads()); @@ -220,47 +190,37 @@ public class SocketIOServer implements ClientListeners { workerGroup = new NioEventLoopGroup(configCopy.getWorkerThreads()); } } - + /** * Stop server */ public void stop() { - bossGroup.shutdownGracefully().syncUninterruptibly(); workerGroup.shutdownGracefully().syncUninterruptibly(); - + pipelineFactory.stop(); log.info("SocketIO server stopped"); } - - /** - * Stop server - * 不等待 - */ + public void stopImmediately() { - - bossGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly(); - workerGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly(); - - pipelineFactory.stop(); + this.bossGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly(); + this.workerGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly(); + this.pipelineFactory.stop(); log.info("SocketIO server stopped"); } - + public SocketIONamespace addNamespace(String name) { - return namespacesHub.create(name); } - + public SocketIONamespace getNamespace(String name) { - return namespacesHub.get(name); } - + public void removeNamespace(String name) { - namespacesHub.remove(name); } - + /** * Allows to get configuration provided * during server creation. Further changes on @@ -269,57 +229,48 @@ public class SocketIOServer implements ClientListeners { * @return Configuration object */ public Configuration getConfiguration() { - return configuration; } - + @Override public void addMultiTypeEventListener(String eventName, MultiTypeEventListener listener, Class... eventClass) { - mainNamespace.addMultiTypeEventListener(eventName, listener, eventClass); } - + @Override public void addEventListener(String eventName, Class eventClass, DataListener listener) { - mainNamespace.addEventListener(eventName, eventClass, listener); } - + @Override public void removeAllListeners(String eventName) { - mainNamespace.removeAllListeners(eventName); } - + @Override public void addDisconnectListener(DisconnectListener listener) { - mainNamespace.addDisconnectListener(listener); } - + @Override public void addConnectListener(ConnectListener listener) { - mainNamespace.addConnectListener(listener); } - + @Override public void addPingListener(PingListener listener) { - mainNamespace.addPingListener(listener); } - + @Override public void addListeners(Object listeners) { - mainNamespace.addListeners(listeners); } @Override public void addListeners(Object listeners, Class listenersClass) { - mainNamespace.addListeners(listeners, listenersClass); } - - + + } diff --git a/fine-socketio/src/com/fr/third/socketio/Transport.java b/fine-socketio/src/com/fr/third/socketio/Transport.java index d04937a42..a2dc635a0 100644 --- a/fine-socketio/src/com/fr/third/socketio/Transport.java +++ b/fine-socketio/src/com/fr/third/socketio/Transport.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/VoidAckCallback.java b/fine-socketio/src/com/fr/third/socketio/VoidAckCallback.java index 0d3b404ab..de5e30589 100644 --- a/fine-socketio/src/com/fr/third/socketio/VoidAckCallback.java +++ b/fine-socketio/src/com/fr/third/socketio/VoidAckCallback.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/ack/AckManager.java b/fine-socketio/src/com/fr/third/socketio/ack/AckManager.java index dbb3eabc6..b941fc962 100644 --- a/fine-socketio/src/com/fr/third/socketio/ack/AckManager.java +++ b/fine-socketio/src/com/fr/third/socketio/ack/AckManager.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,27 +15,28 @@ */ package com.fr.third.socketio.ack; +import com.fr.third.socketio.handler.ClientHead; +import com.fr.third.socketio.protocol.Packet; +import com.fr.third.socketio.scheduler.CancelableScheduler; +import com.fr.third.socketio.scheduler.SchedulerKey; +import com.fr.third.socketio.scheduler.SchedulerKey.Type; import com.fr.third.socketio.AckCallback; import com.fr.third.socketio.Disconnectable; import com.fr.third.socketio.MultiTypeAckCallback; import com.fr.third.socketio.MultiTypeArgs; import com.fr.third.socketio.SocketIOClient; -import com.fr.third.socketio.handler.ClientHead; -import com.fr.third.socketio.protocol.Packet; -import com.fr.third.socketio.scheduler.CancelableScheduler; -import com.fr.third.socketio.scheduler.SchedulerKey; import io.netty.util.internal.PlatformDependent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class AckManager implements Disconnectable { class AckEntry { @@ -69,7 +70,7 @@ public class AckManager implements Disconnectable { private static final Logger log = LoggerFactory.getLogger(AckManager.class); - private final Map ackEntries = PlatformDependent.newConcurrentHashMap(); + private final ConcurrentMap ackEntries = PlatformDependent.newConcurrentHashMap(); private final CancelableScheduler scheduler; @@ -87,7 +88,7 @@ public class AckManager implements Disconnectable { AckEntry ackEntry = ackEntries.get(sessionId); if (ackEntry == null) { ackEntry = new AckEntry(); - AckEntry oldAckEntry = ackEntries.put(sessionId, ackEntry); + AckEntry oldAckEntry = ackEntries.putIfAbsent(sessionId, ackEntry); if (oldAckEntry != null) { ackEntry = oldAckEntry; } @@ -97,7 +98,7 @@ public class AckManager implements Disconnectable { @SuppressWarnings("unchecked") public void onAck(SocketIOClient client, Packet packet) { - AckSchedulerKey key = new AckSchedulerKey(SchedulerKey.Type.ACK_TIMEOUT, client.getSessionId(), packet.getAckId()); + AckSchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, client.getSessionId(), packet.getAckId()); scheduler.cancel(key); AckCallback callback = removeCallback(client.getSessionId(), packet.getAckId()); @@ -153,7 +154,7 @@ public class AckManager implements Disconnectable { if (callback.getTimeout() == -1) { return; } - SchedulerKey key = new AckSchedulerKey(SchedulerKey.Type.ACK_TIMEOUT, sessionId, index); + SchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, sessionId, index); scheduler.scheduleCallback(key, new Runnable() { @Override public void run() { @@ -178,7 +179,7 @@ public class AckManager implements Disconnectable { if (callback != null) { callback.onTimeout(); } - SchedulerKey key = new AckSchedulerKey(SchedulerKey.Type.ACK_TIMEOUT, client.getSessionId(), index); + SchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, client.getSessionId(), index); scheduler.cancel(key); } } diff --git a/fine-socketio/src/com/fr/third/socketio/ack/AckSchedulerKey.java b/fine-socketio/src/com/fr/third/socketio/ack/AckSchedulerKey.java index 81c8254f9..5cc8ddb6b 100644 --- a/fine-socketio/src/com/fr/third/socketio/ack/AckSchedulerKey.java +++ b/fine-socketio/src/com/fr/third/socketio/ack/AckSchedulerKey.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/AnnotationScanner.java b/fine-socketio/src/com/fr/third/socketio/annotation/AnnotationScanner.java index a44d2c13d..9110a24a7 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/AnnotationScanner.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/AnnotationScanner.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/OnConnect.java b/fine-socketio/src/com/fr/third/socketio/annotation/OnConnect.java index cd839a1c2..fcbb357f1 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/OnConnect.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/OnConnect.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/OnConnectScanner.java b/fine-socketio/src/com/fr/third/socketio/annotation/OnConnectScanner.java index cfb5927fb..3c9bcf1f4 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/OnConnectScanner.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/OnConnectScanner.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnect.java b/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnect.java index 42d6cdc05..0a26baa90 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnect.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnect.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnectScanner.java b/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnectScanner.java index bb00f1c56..378bf49ba 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnectScanner.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnectScanner.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/OnEvent.java b/fine-socketio/src/com/fr/third/socketio/annotation/OnEvent.java index c1ac8e0fd..e245132e7 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/OnEvent.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/OnEvent.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/OnEventScanner.java b/fine-socketio/src/com/fr/third/socketio/annotation/OnEventScanner.java index c1b6eedb6..1f682fc14 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/OnEventScanner.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/OnEventScanner.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/ScannerEngine.java b/fine-socketio/src/com/fr/third/socketio/annotation/ScannerEngine.java index cd1ac030e..a36af1669 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/ScannerEngine.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/ScannerEngine.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/annotation/SpringAnnotationScanner.java b/fine-socketio/src/com/fr/third/socketio/annotation/SpringAnnotationScanner.java index 9e870446f..be860c795 100644 --- a/fine-socketio/src/com/fr/third/socketio/annotation/SpringAnnotationScanner.java +++ b/fine-socketio/src/com/fr/third/socketio/annotation/SpringAnnotationScanner.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import com.fr.third.socketio.SocketIOServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fr.third.springframework.beans.BeansException; @@ -30,6 +29,8 @@ import com.fr.third.springframework.util.ReflectionUtils; import com.fr.third.springframework.util.ReflectionUtils.MethodCallback; import com.fr.third.springframework.util.ReflectionUtils.MethodFilter; +import com.fr.third.socketio.SocketIOServer; + public class SpringAnnotationScanner implements BeanPostProcessor { private static final Logger log = LoggerFactory.getLogger(SpringAnnotationScanner.class); diff --git a/fine-socketio/src/com/fr/third/socketio/handler/AuthorizeHandler.java b/fine-socketio/src/com/fr/third/socketio/handler/AuthorizeHandler.java index 0a13de846..db772781a 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/AuthorizeHandler.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/AuthorizeHandler.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,6 +32,13 @@ import com.fr.third.socketio.DisconnectableHub; import com.fr.third.socketio.HandshakeData; import com.fr.third.socketio.SocketIOClient; import com.fr.third.socketio.Transport; +import com.fr.third.socketio.ack.AckManager; +import com.fr.third.socketio.store.StoreFactory; +import com.fr.third.socketio.store.pubsub.ConnectMessage; +import com.fr.third.socketio.store.pubsub.PubSubType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fr.third.socketio.messages.HttpErrorMessage; import com.fr.third.socketio.namespace.Namespace; import com.fr.third.socketio.namespace.NamespacesHub; @@ -40,13 +47,7 @@ import com.fr.third.socketio.protocol.Packet; import com.fr.third.socketio.protocol.PacketType; import com.fr.third.socketio.scheduler.CancelableScheduler; import com.fr.third.socketio.scheduler.SchedulerKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fr.third.socketio.ack.AckManager; -import com.fr.third.socketio.store.StoreFactory; -import com.fr.third.socketio.store.pubsub.ConnectMessage; -import com.fr.third.socketio.store.pubsub.PubSubType; +import com.fr.third.socketio.scheduler.SchedulerKey.Type; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; @@ -93,7 +94,7 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di @Override public void channelActive(final ChannelHandlerContext ctx) throws Exception { - SchedulerKey key = new SchedulerKey(SchedulerKey.Type.PING_TIMEOUT, ctx.channel()); + SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel()); disconnectScheduler.schedule(key, new Runnable() { @Override public void run() { @@ -106,7 +107,7 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - SchedulerKey key = new SchedulerKey(SchedulerKey.Type.PING_TIMEOUT, ctx.channel()); + SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel()); disconnectScheduler.cancel(key); if (msg instanceof FullHttpRequest) { @@ -145,9 +146,9 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di } HandshakeData data = new HandshakeData(req.headers(), params, - (InetSocketAddress)channel.remoteAddress(), - (InetSocketAddress)channel.localAddress(), - req.uri(), origin != null && !origin.equalsIgnoreCase("null")); + (InetSocketAddress)channel.remoteAddress(), + (InetSocketAddress)channel.localAddress(), + req.uri(), origin != null && !origin.equalsIgnoreCase("null")); boolean result = false; try { @@ -164,7 +165,12 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di return false; } - UUID sessionId = this.generateOrGetSessionIdFromRequest(req.headers()); + UUID sessionId = null; + if (configuration.isRandomSession()) { + sessionId = UUID.randomUUID(); + } else { + sessionId = this.generateOrGetSessionIdFromRequest(req.headers()); + } List transportValue = params.get("transport"); if (transportValue == null) { @@ -192,11 +198,11 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di String[] transports = {}; if (configuration.getTransports().contains(Transport.WEBSOCKET)) { - transports = new String[] {"websocket"}; + transports = new String[]{"websocket"}; } AuthPacket authPacket = new AuthPacket(sessionId, transports, configuration.getPingInterval(), - configuration.getPingTimeout()); + configuration.getPingTimeout()); Packet packet = new Packet(PacketType.OPEN); packet.setData(authPacket); client.send(packet); @@ -207,29 +213,39 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di } /** - This method will either generate a new random sessionId or will retrieve the value stored - in the "io" cookie. Failures to parse will cause a logging warning to be generated and a - random uuid to be generated instead (same as not passing a cookie in the first place). - */ + * This method will either generate a new random sessionId or will retrieve the value stored + * in the "io" cookie. Failures to parse will cause a logging warning to be generated and a + * random uuid to be generated instead (same as not passing a cookie in the first place). + */ private UUID generateOrGetSessionIdFromRequest(HttpHeaders headers) { - for (String cookieHeader: headers.getAll(HttpHeaderNames.COOKIE)) { + List values = headers.getAll("io"); + if (values.size() == 1) { + try { + return UUID.fromString(values.get(0)); + } catch (IllegalArgumentException iaex) { + log.warn("Malformed UUID received for session! io=" + values.get(0)); + } + } + + for (String cookieHeader : headers.getAll(HttpHeaderNames.COOKIE)) { Set cookies = ServerCookieDecoder.LAX.decode(cookieHeader); for (Cookie cookie : cookies) { if (cookie.name().equals("io")) { try { return UUID.fromString(cookie.value()); - } catch ( IllegalArgumentException iaex ) { + } catch (IllegalArgumentException iaex) { log.warn("Malformed UUID received for session! io=" + cookie.value()); } } } } + return UUID.randomUUID(); } public void connect(UUID sessionId) { - SchedulerKey key = new SchedulerKey(SchedulerKey.Type.PING_TIMEOUT, sessionId); + SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId); disconnectScheduler.cancel(key); } diff --git a/fine-socketio/src/com/fr/third/socketio/handler/ClientHead.java b/fine-socketio/src/com/fr/third/socketio/handler/ClientHead.java index 2ed6a028f..b1fb85350 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/ClientHead.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/ClientHead.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,40 +15,35 @@ */ package com.fr.third.socketio.handler; -import java.net.SocketAddress; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Queue; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - import com.fr.third.socketio.Configuration; import com.fr.third.socketio.DisconnectableHub; import com.fr.third.socketio.HandshakeData; import com.fr.third.socketio.Transport; +import com.fr.third.socketio.ack.AckManager; import com.fr.third.socketio.messages.OutPacketMessage; import com.fr.third.socketio.namespace.Namespace; import com.fr.third.socketio.protocol.Packet; import com.fr.third.socketio.protocol.PacketType; import com.fr.third.socketio.scheduler.CancelableScheduler; import com.fr.third.socketio.scheduler.SchedulerKey; -import com.fr.third.socketio.transport.NamespaceClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fr.third.socketio.ack.AckManager; +import com.fr.third.socketio.scheduler.SchedulerKey.Type; import com.fr.third.socketio.store.Store; import com.fr.third.socketio.store.StoreFactory; - +import com.fr.third.socketio.transport.NamespaceClient; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.util.AttributeKey; import io.netty.util.internal.PlatformDependent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.net.SocketAddress; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; public class ClientHead { @@ -75,8 +70,8 @@ public class ClientHead { private volatile Transport currentTransport; public ClientHead(UUID sessionId, AckManager ackManager, DisconnectableHub disconnectable, - StoreFactory storeFactory, HandshakeData handshakeData, ClientsBox clientsBox, Transport transport, CancelableScheduler disconnectScheduler, - Configuration configuration) { + StoreFactory storeFactory, HandshakeData handshakeData, ClientsBox clientsBox, Transport transport, CancelableScheduler disconnectScheduler, + Configuration configuration) { this.sessionId = sessionId; this.ackManager = ackManager; this.disconnectableHub = disconnectable; @@ -104,6 +99,14 @@ public class ClientHead { sendPackets(transport, channel); } + public void releasePollingChannel(Channel channel) { + TransportState state = channels.get(Transport.POLLING); + if(channel.equals(state.getChannel())) { + clientsBox.remove(channel); + state.update(null); + } + } + public String getOrigin() { return handshakeData.getHttpHeaders().get(HttpHeaderNames.ORIGIN); } @@ -113,18 +116,18 @@ public class ClientHead { } public void cancelPingTimeout() { - SchedulerKey key = new SchedulerKey(SchedulerKey.Type.PING_TIMEOUT, sessionId); + SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId); disconnectScheduler.cancel(key); } public void schedulePingTimeout() { - SchedulerKey key = new SchedulerKey(SchedulerKey.Type.PING_TIMEOUT, sessionId); + SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId); disconnectScheduler.schedule(key, new Runnable() { @Override public void run() { ClientHead client = clientsBox.get(sessionId); if (client != null) { - client.onChannelDisconnect(); + client.disconnect(); log.debug("{} removed due to ping timeout", sessionId); } } @@ -204,7 +207,9 @@ public class ClientHead { public void disconnect() { ChannelFuture future = send(new Packet(PacketType.DISCONNECT)); - future.addListener(ChannelFutureListener.CLOSE); + if(future != null) { + future.addListener(ChannelFutureListener.CLOSE); + } onChannelDisconnect(); } diff --git a/fine-socketio/src/com/fr/third/socketio/handler/ClientsBox.java b/fine-socketio/src/com/fr/third/socketio/handler/ClientsBox.java index 0db284c46..e7c2a718b 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/ClientsBox.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/ClientsBox.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/handler/EncoderHandler.java b/fine-socketio/src/com/fr/third/socketio/handler/EncoderHandler.java index b574c16ee..238c965d8 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/EncoderHandler.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/EncoderHandler.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,11 @@ import java.util.jar.Manifest; import com.fr.third.socketio.Configuration; import com.fr.third.socketio.Transport; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.GenericFutureListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fr.third.socketio.messages.HttpErrorMessage; import com.fr.third.socketio.messages.HttpMessage; import com.fr.third.socketio.messages.OutPacketMessage; @@ -35,10 +40,6 @@ import com.fr.third.socketio.messages.XHROptionsMessage; import com.fr.third.socketio.messages.XHRPostMessage; import com.fr.third.socketio.protocol.Packet; import com.fr.third.socketio.protocol.PacketEncoder; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; diff --git a/fine-socketio/src/com/fr/third/socketio/handler/InPacketHandler.java b/fine-socketio/src/com/fr/third/socketio/handler/InPacketHandler.java index 88d6b0d35..b213fec2f 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/InPacketHandler.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/InPacketHandler.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,6 @@ */ package com.fr.third.socketio.handler; -import com.fr.third.socketio.listener.ExceptionListener; -import com.fr.third.socketio.messages.PacketsMessage; -import com.fr.third.socketio.namespace.Namespace; -import com.fr.third.socketio.namespace.NamespacesHub; -import com.fr.third.socketio.protocol.Packet; -import com.fr.third.socketio.protocol.PacketDecoder; -import com.fr.third.socketio.protocol.PacketType; import com.fr.third.socketio.transport.NamespaceClient; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandler.Sharable; @@ -32,6 +25,14 @@ import io.netty.util.CharsetUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fr.third.socketio.listener.ExceptionListener; +import com.fr.third.socketio.messages.PacketsMessage; +import com.fr.third.socketio.namespace.Namespace; +import com.fr.third.socketio.namespace.NamespacesHub; +import com.fr.third.socketio.protocol.Packet; +import com.fr.third.socketio.protocol.PacketDecoder; +import com.fr.third.socketio.protocol.PacketType; + @Sharable public class InPacketHandler extends SimpleChannelInboundHandler { diff --git a/fine-socketio/src/com/fr/third/socketio/handler/PacketListener.java b/fine-socketio/src/com/fr/third/socketio/handler/PacketListener.java index 6e448102d..7eb0099d8 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/PacketListener.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/PacketListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/handler/SocketIOException.java b/fine-socketio/src/com/fr/third/socketio/handler/SocketIOException.java index fdb16e5d8..78bd1da2b 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/SocketIOException.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/SocketIOException.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/handler/SuccessAuthorizationListener.java b/fine-socketio/src/com/fr/third/socketio/handler/SuccessAuthorizationListener.java index d118729eb..44683d8c4 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/SuccessAuthorizationListener.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/SuccessAuthorizationListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/handler/TransportState.java b/fine-socketio/src/com/fr/third/socketio/handler/TransportState.java index dd1aefe06..c26607138 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/TransportState.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/TransportState.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/handler/WrongUrlHandler.java b/fine-socketio/src/com/fr/third/socketio/handler/WrongUrlHandler.java index c46fdf794..a982d32be 100644 --- a/fine-socketio/src/com/fr/third/socketio/handler/WrongUrlHandler.java +++ b/fine-socketio/src/com/fr/third/socketio/handler/WrongUrlHandler.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/ClientListeners.java b/fine-socketio/src/com/fr/third/socketio/listener/ClientListeners.java index e1061be4b..ffeb16f69 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/ClientListeners.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/ClientListeners.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/ConnectListener.java b/fine-socketio/src/com/fr/third/socketio/listener/ConnectListener.java index 48fae31b6..ba83eba58 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/ConnectListener.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/ConnectListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/DataListener.java b/fine-socketio/src/com/fr/third/socketio/listener/DataListener.java index a7e86c586..ebe81719a 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/DataListener.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/DataListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/DefaultExceptionListener.java b/fine-socketio/src/com/fr/third/socketio/listener/DefaultExceptionListener.java index 62a17aaa6..a9dbad9d2 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/DefaultExceptionListener.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/DefaultExceptionListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/DisconnectListener.java b/fine-socketio/src/com/fr/third/socketio/listener/DisconnectListener.java index aa928ee91..f73798f21 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/DisconnectListener.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/DisconnectListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListener.java b/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListener.java index 3870ae0b3..13d813560 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListener.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListenerAdapter.java b/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListenerAdapter.java index db36cb73b..1a12c9a41 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListenerAdapter.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/ExceptionListenerAdapter.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,4 +44,9 @@ public abstract class ExceptionListenerAdapter implements ExceptionListener { return false; } + @Override + public void onPingException(Exception e, SocketIOClient client) { + + } + } diff --git a/fine-socketio/src/com/fr/third/socketio/listener/MultiTypeEventListener.java b/fine-socketio/src/com/fr/third/socketio/listener/MultiTypeEventListener.java index 803271d81..d750f70ac 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/MultiTypeEventListener.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/MultiTypeEventListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/listener/PingListener.java b/fine-socketio/src/com/fr/third/socketio/listener/PingListener.java index 5063c15a4..c9f33d6b5 100644 --- a/fine-socketio/src/com/fr/third/socketio/listener/PingListener.java +++ b/fine-socketio/src/com/fr/third/socketio/listener/PingListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/messages/HttpErrorMessage.java b/fine-socketio/src/com/fr/third/socketio/messages/HttpErrorMessage.java index 398592c59..7be5e8639 100644 --- a/fine-socketio/src/com/fr/third/socketio/messages/HttpErrorMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/messages/HttpErrorMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/messages/HttpMessage.java b/fine-socketio/src/com/fr/third/socketio/messages/HttpMessage.java index 4e4ef096a..5c9858e40 100644 --- a/fine-socketio/src/com/fr/third/socketio/messages/HttpMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/messages/HttpMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/messages/OutPacketMessage.java b/fine-socketio/src/com/fr/third/socketio/messages/OutPacketMessage.java index 960091a6b..363cf55a1 100644 --- a/fine-socketio/src/com/fr/third/socketio/messages/OutPacketMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/messages/OutPacketMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/messages/PacketsMessage.java b/fine-socketio/src/com/fr/third/socketio/messages/PacketsMessage.java index 7ef12deac..682045901 100644 --- a/fine-socketio/src/com/fr/third/socketio/messages/PacketsMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/messages/PacketsMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,8 @@ package com.fr.third.socketio.messages; import com.fr.third.socketio.Transport; -import io.netty.buffer.ByteBuf; - import com.fr.third.socketio.handler.ClientHead; +import io.netty.buffer.ByteBuf; public class PacketsMessage { diff --git a/fine-socketio/src/com/fr/third/socketio/messages/XHROptionsMessage.java b/fine-socketio/src/com/fr/third/socketio/messages/XHROptionsMessage.java index e50644c87..bacc716bb 100644 --- a/fine-socketio/src/com/fr/third/socketio/messages/XHROptionsMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/messages/XHROptionsMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/messages/XHRPostMessage.java b/fine-socketio/src/com/fr/third/socketio/messages/XHRPostMessage.java index 59e40b0a9..54e5129bb 100644 --- a/fine-socketio/src/com/fr/third/socketio/messages/XHRPostMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/messages/XHRPostMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/misc/CompositeIterable.java b/fine-socketio/src/com/fr/third/socketio/misc/CompositeIterable.java index e5889b5d0..251f4e2cf 100644 --- a/fine-socketio/src/com/fr/third/socketio/misc/CompositeIterable.java +++ b/fine-socketio/src/com/fr/third/socketio/misc/CompositeIterable.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/misc/IterableCollection.java b/fine-socketio/src/com/fr/third/socketio/misc/IterableCollection.java index 0f35db7a4..ef65dabc5 100644 --- a/fine-socketio/src/com/fr/third/socketio/misc/IterableCollection.java +++ b/fine-socketio/src/com/fr/third/socketio/misc/IterableCollection.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/namespace/EventEntry.java b/fine-socketio/src/com/fr/third/socketio/namespace/EventEntry.java index f41bd986f..ba9e8dcf3 100644 --- a/fine-socketio/src/com/fr/third/socketio/namespace/EventEntry.java +++ b/fine-socketio/src/com/fr/third/socketio/namespace/EventEntry.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/namespace/Namespace.java b/fine-socketio/src/com/fr/third/socketio/namespace/Namespace.java index 217e5c662..83d1ab4c7 100644 --- a/fine-socketio/src/com/fr/third/socketio/namespace/Namespace.java +++ b/fine-socketio/src/com/fr/third/socketio/namespace/Namespace.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,13 +34,6 @@ import com.fr.third.socketio.MultiTypeArgs; import com.fr.third.socketio.SocketIOClient; import com.fr.third.socketio.SocketIONamespace; import com.fr.third.socketio.annotation.ScannerEngine; -import com.fr.third.socketio.listener.*; -import com.fr.third.socketio.listener.ConnectListener; -import com.fr.third.socketio.listener.DataListener; -import com.fr.third.socketio.listener.DisconnectListener; -import com.fr.third.socketio.listener.ExceptionListener; -import com.fr.third.socketio.listener.MultiTypeEventListener; -import com.fr.third.socketio.listener.PingListener; import com.fr.third.socketio.protocol.JsonSupport; import com.fr.third.socketio.protocol.Packet; import com.fr.third.socketio.store.StoreFactory; @@ -48,6 +41,12 @@ import com.fr.third.socketio.store.pubsub.JoinLeaveMessage; import com.fr.third.socketio.store.pubsub.PubSubType; import com.fr.third.socketio.transport.NamespaceClient; +import com.fr.third.socketio.listener.ConnectListener; +import com.fr.third.socketio.listener.DataListener; +import com.fr.third.socketio.listener.DisconnectListener; +import com.fr.third.socketio.listener.ExceptionListener; +import com.fr.third.socketio.listener.MultiTypeEventListener; +import com.fr.third.socketio.listener.PingListener; import io.netty.util.internal.PlatformDependent; /** diff --git a/fine-socketio/src/com/fr/third/socketio/namespace/NamespacesHub.java b/fine-socketio/src/com/fr/third/socketio/namespace/NamespacesHub.java index 230ef262e..fbb0ff2b5 100644 --- a/fine-socketio/src/com/fr/third/socketio/namespace/NamespacesHub.java +++ b/fine-socketio/src/com/fr/third/socketio/namespace/NamespacesHub.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package com.fr.third.socketio.namespace; import com.fr.third.socketio.Configuration; import com.fr.third.socketio.SocketIOClient; import com.fr.third.socketio.SocketIONamespace; +import com.fr.third.socketio.misc.CompositeIterable; import io.netty.util.internal.PlatformDependent; import java.util.ArrayList; @@ -25,8 +26,6 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentMap; -import com.fr.third.socketio.misc.CompositeIterable; - public class NamespacesHub { private final ConcurrentMap namespaces = PlatformDependent.newConcurrentHashMap(); diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/AckArgs.java b/fine-socketio/src/com/fr/third/socketio/protocol/AckArgs.java index a881f94de..e04542821 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/AckArgs.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/AckArgs.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/AuthPacket.java b/fine-socketio/src/com/fr/third/socketio/protocol/AuthPacket.java index f65a05807..5192ee43d 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/AuthPacket.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/AuthPacket.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/Event.java b/fine-socketio/src/com/fr/third/socketio/protocol/Event.java index cd557b417..942e65410 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/Event.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/Event.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/JacksonJsonSupport.java b/fine-socketio/src/com/fr/third/socketio/protocol/JacksonJsonSupport.java index 7658b590c..7737ff291 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/JacksonJsonSupport.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/JacksonJsonSupport.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,9 @@ */ package com.fr.third.socketio.protocol; -import com.fr.third.socketio.AckCallback; -import com.fr.third.socketio.MultiTypeAckCallback; -import com.fr.third.socketio.namespace.Namespace; -import io.netty.buffer.ByteBufInputStream; -import io.netty.buffer.ByteBufOutputStream; -import io.netty.util.internal.PlatformDependent; - import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; @@ -32,9 +27,12 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import com.fr.third.socketio.AckCallback; +import com.fr.third.socketio.MultiTypeAckCallback; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fr.third.socketio.namespace.Namespace; import com.fr.third.fasterxml.jackson.annotation.JsonInclude.Include; import com.fr.third.fasterxml.jackson.core.JsonGenerationException; import com.fr.third.fasterxml.jackson.core.JsonGenerator; @@ -64,6 +62,10 @@ import com.fr.third.fasterxml.jackson.databind.ser.BeanSerializerModifier; import com.fr.third.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fr.third.fasterxml.jackson.databind.type.ArrayType; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import io.netty.util.internal.PlatformDependent; + public class JacksonJsonSupport implements JsonSupport { private class AckArgsDeserializer extends StdDeserializer { @@ -337,19 +339,19 @@ public class JacksonJsonSupport implements JsonSupport { @Override public T readValue(String namespaceName, ByteBufInputStream src, Class valueType) throws IOException { namespaceClass.set(namespaceName); - return objectMapper.readValue(src, valueType); + return objectMapper.readValue((InputStream)src, valueType); } @Override public AckArgs readAckArgs(ByteBufInputStream src, AckCallback callback) throws IOException { currentAckClass.set(callback); - return objectMapper.readValue(src, AckArgs.class); + return objectMapper.readValue((InputStream)src, AckArgs.class); } @Override public void writeValue(ByteBufOutputStream out, Object value) throws IOException { modifier.getSerializer().clear(); - objectMapper.writeValue(out, value); + objectMapper.writeValue((OutputStream)out, value); } @Override diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/JsonSupport.java b/fine-socketio/src/com/fr/third/socketio/protocol/JsonSupport.java index 54ac79331..31b896bc9 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/JsonSupport.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/JsonSupport.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/Packet.java b/fine-socketio/src/com/fr/third/socketio/protocol/Packet.java index 80b829039..150632971 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/Packet.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/Packet.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,6 @@ */ package com.fr.third.socketio.protocol; -import com.fr.third.socketio.namespace.Namespace; import io.netty.buffer.ByteBuf; import java.io.Serializable; @@ -23,6 +22,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import com.fr.third.socketio.namespace.Namespace; + public class Packet implements Serializable { private static final long serialVersionUID = 4560159536486711426L; diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/PacketDecoder.java b/fine-socketio/src/com/fr/third/socketio/protocol/PacketDecoder.java index fbcd7e46a..7373d5b41 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/PacketDecoder.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/PacketDecoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -279,7 +279,7 @@ public class PacketDecoder { if (packet.getType() == PacketType.MESSAGE) { if (packet.getSubType() == PacketType.CONNECT || packet.getSubType() == PacketType.DISCONNECT) { - packet.setNsp(readString(frame)); + packet.setNsp(readNamespace(frame)); } if (packet.hasAttachments() && !packet.isAttachmentsLoaded()) { @@ -309,5 +309,22 @@ public class PacketDecoder { } } } + + private String readNamespace(ByteBuf frame){ + /** + * namespace post request with url queryString, like + * /message?a=1, + * /message, + */ + int endIndex = frame.bytesBefore((byte)'?'); + if(endIndex > 0){ + return readString(frame,endIndex); + } + endIndex = frame.bytesBefore((byte)','); + if(endIndex > 0){ + return readString(frame,endIndex); + } + return readString(frame); + } } diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/PacketEncoder.java b/fine-socketio/src/com/fr/third/socketio/protocol/PacketEncoder.java index cbbaee9ca..6228c1b57 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/PacketEncoder.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/PacketEncoder.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/PacketType.java b/fine-socketio/src/com/fr/third/socketio/protocol/PacketType.java index 794181fb4..7031d52ff 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/PacketType.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/PacketType.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/protocol/UTF8CharsScanner.java b/fine-socketio/src/com/fr/third/socketio/protocol/UTF8CharsScanner.java index 9e735ba57..d11ff1799 100644 --- a/fine-socketio/src/com/fr/third/socketio/protocol/UTF8CharsScanner.java +++ b/fine-socketio/src/com/fr/third/socketio/protocol/UTF8CharsScanner.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/scheduler/CancelableScheduler.java b/fine-socketio/src/com/fr/third/socketio/scheduler/CancelableScheduler.java index 0d9472d57..1cd23d97b 100644 --- a/fine-socketio/src/com/fr/third/socketio/scheduler/CancelableScheduler.java +++ b/fine-socketio/src/com/fr/third/socketio/scheduler/CancelableScheduler.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelScheduler.java b/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelScheduler.java index bd1da4754..d0e699c5b 100644 --- a/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelScheduler.java +++ b/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelScheduler.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelTimeoutScheduler.java b/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelTimeoutScheduler.java index 67e2d587d..c04eb7a25 100644 --- a/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelTimeoutScheduler.java +++ b/fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelTimeoutScheduler.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/scheduler/SchedulerKey.java b/fine-socketio/src/com/fr/third/socketio/scheduler/SchedulerKey.java index 89125b093..2f81f12b5 100644 --- a/fine-socketio/src/com/fr/third/socketio/scheduler/SchedulerKey.java +++ b/fine-socketio/src/com/fr/third/socketio/scheduler/SchedulerKey.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/MemoryPubSubStore.java b/fine-socketio/src/com/fr/third/socketio/store/MemoryPubSubStore.java index afbba8562..e2eb50b27 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/MemoryPubSubStore.java +++ b/fine-socketio/src/com/fr/third/socketio/store/MemoryPubSubStore.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/MemoryStore.java b/fine-socketio/src/com/fr/third/socketio/store/MemoryStore.java index e3f2cd4f3..fce3b32b8 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/MemoryStore.java +++ b/fine-socketio/src/com/fr/third/socketio/store/MemoryStore.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/MemoryStoreFactory.java b/fine-socketio/src/com/fr/third/socketio/store/MemoryStoreFactory.java index 724e6576f..e87d804b6 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/MemoryStoreFactory.java +++ b/fine-socketio/src/com/fr/third/socketio/store/MemoryStoreFactory.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,14 @@ */ package com.fr.third.socketio.store; -import com.fr.third.socketio.store.pubsub.BaseStoreFactory; -import com.fr.third.socketio.store.pubsub.PubSubStore; import io.netty.util.internal.PlatformDependent; import java.util.Map; import java.util.UUID; +import com.fr.third.socketio.store.pubsub.BaseStoreFactory; +import com.fr.third.socketio.store.pubsub.PubSubStore; + public class MemoryStoreFactory extends BaseStoreFactory { private final MemoryPubSubStore pubSubMemoryStore = new MemoryPubSubStore(); diff --git a/fine-socketio/src/com/fr/third/socketio/store/RedissonPubSubStore.java b/fine-socketio/src/com/fr/third/socketio/store/RedissonPubSubStore.java index efa6bac5f..8c4287d84 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/RedissonPubSubStore.java +++ b/fine-socketio/src/com/fr/third/socketio/store/RedissonPubSubStore.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,14 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; +import com.fr.third.org.redisson.api.RTopic; +import com.fr.third.org.redisson.api.RedissonClient; +import com.fr.third.org.redisson.api.listener.MessageListener; + import com.fr.third.socketio.store.pubsub.PubSubListener; import com.fr.third.socketio.store.pubsub.PubSubMessage; import com.fr.third.socketio.store.pubsub.PubSubStore; import com.fr.third.socketio.store.pubsub.PubSubType; -import com.fr.third.org.redisson.api.RTopic; -import com.fr.third.org.redisson.api.RedissonClient; -import com.fr.third.org.redisson.api.listener.MessageListener; import io.netty.util.internal.PlatformDependent; @@ -77,7 +78,7 @@ public class RedissonPubSubStore implements PubSubStore { public void unsubscribe(PubSubType type) { String name = type.toString(); Queue regIds = map.remove(name); - RTopic topic = redissonSub.getTopic(name); + RTopic topic = redissonSub.getTopic(name); for (Integer id : regIds) { topic.removeListener(id); } diff --git a/fine-socketio/src/com/fr/third/socketio/store/RedissonStore.java b/fine-socketio/src/com/fr/third/socketio/store/RedissonStore.java index fcdf3602b..c738e4954 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/RedissonStore.java +++ b/fine-socketio/src/com/fr/third/socketio/store/RedissonStore.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/RedissonStoreFactory.java b/fine-socketio/src/com/fr/third/socketio/store/RedissonStoreFactory.java index 18ea4e905..e548871c0 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/RedissonStoreFactory.java +++ b/fine-socketio/src/com/fr/third/socketio/store/RedissonStoreFactory.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,12 @@ package com.fr.third.socketio.store; import java.util.Map; import java.util.UUID; -import com.fr.third.socketio.store.pubsub.BaseStoreFactory; -import com.fr.third.socketio.store.pubsub.PubSubStore; import com.fr.third.org.redisson.Redisson; import com.fr.third.org.redisson.api.RedissonClient; +import com.fr.third.socketio.store.pubsub.BaseStoreFactory; +import com.fr.third.socketio.store.pubsub.PubSubStore; + public class RedissonStoreFactory extends BaseStoreFactory { private final RedissonClient redisClient; diff --git a/fine-socketio/src/com/fr/third/socketio/store/Store.java b/fine-socketio/src/com/fr/third/socketio/store/Store.java index e243b0e50..f0fa9b58c 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/Store.java +++ b/fine-socketio/src/com/fr/third/socketio/store/Store.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/StoreFactory.java b/fine-socketio/src/com/fr/third/socketio/store/StoreFactory.java index 4d074f1b8..d1eeaaba6 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/StoreFactory.java +++ b/fine-socketio/src/com/fr/third/socketio/store/StoreFactory.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/BaseStoreFactory.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/BaseStoreFactory.java index be95e1aa8..d578349f3 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/BaseStoreFactory.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/BaseStoreFactory.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,14 @@ */ package com.fr.third.socketio.store.pubsub; +import com.fr.third.socketio.store.StoreFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fr.third.socketio.handler.AuthorizeHandler; import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.namespace.NamespacesHub; import com.fr.third.socketio.protocol.JsonSupport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.fr.third.socketio.store.StoreFactory; public abstract class BaseStoreFactory implements StoreFactory { diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/ConnectMessage.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/ConnectMessage.java index 2441ed7be..d24e44592 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/ConnectMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/ConnectMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/DisconnectMessage.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/DisconnectMessage.java index f64d45d71..b3a6d7b91 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/DisconnectMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/DisconnectMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/DispatchMessage.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/DispatchMessage.java index 3e2925a2e..12c633860 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/DispatchMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/DispatchMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/JoinLeaveMessage.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/JoinLeaveMessage.java index e532b46e7..cb49785af 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/JoinLeaveMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/JoinLeaveMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubListener.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubListener.java index 0b1ab9a4a..a8ee3db53 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubListener.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubListener.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubMessage.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubMessage.java index dddb66fda..f228a1677 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubMessage.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubMessage.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubStore.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubStore.java index aa5bcdb4c..7e7d5be77 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubStore.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubStore.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubType.java b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubType.java index 5c2cbcc29..b6b39f275 100644 --- a/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubType.java +++ b/fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubType.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/fine-socketio/src/com/fr/third/socketio/transport/BaseTransport.java b/fine-socketio/src/com/fr/third/socketio/transport/BaseTransport.java index 319d85ab0..15ee58fd5 100644 --- a/fine-socketio/src/com/fr/third/socketio/transport/BaseTransport.java +++ b/fine-socketio/src/com/fr/third/socketio/transport/BaseTransport.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,10 @@ */ package com.fr.third.socketio.transport; -import com.fr.third.socketio.Disconnectable; import io.netty.channel.ChannelInboundHandlerAdapter; +import com.fr.third.socketio.Disconnectable; + @Deprecated public abstract class BaseTransport extends ChannelInboundHandlerAdapter implements Disconnectable { diff --git a/fine-socketio/src/com/fr/third/socketio/transport/NamespaceClient.java b/fine-socketio/src/com/fr/third/socketio/transport/NamespaceClient.java index 719a28353..cf564fe4d 100644 --- a/fine-socketio/src/com/fr/third/socketio/transport/NamespaceClient.java +++ b/fine-socketio/src/com/fr/third/socketio/transport/NamespaceClient.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,13 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fr.third.socketio.AckCallback; import com.fr.third.socketio.HandshakeData; import com.fr.third.socketio.SocketIOClient; import com.fr.third.socketio.Transport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.namespace.Namespace; import com.fr.third.socketio.protocol.Packet; diff --git a/fine-socketio/src/com/fr/third/socketio/transport/PollingTransport.java b/fine-socketio/src/com/fr/third/socketio/transport/PollingTransport.java index b0d2722e8..36e45fedc 100644 --- a/fine-socketio/src/com/fr/third/socketio/transport/PollingTransport.java +++ b/fine-socketio/src/com/fr/third/socketio/transport/PollingTransport.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,7 @@ */ package com.fr.third.socketio.transport; -import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; - -import java.io.IOException; -import java.util.List; -import java.util.UUID; - import com.fr.third.socketio.Transport; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fr.third.socketio.handler.AuthorizeHandler; import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.handler.ClientsBox; @@ -33,19 +24,21 @@ import com.fr.third.socketio.messages.PacketsMessage; import com.fr.third.socketio.messages.XHROptionsMessage; import com.fr.third.socketio.messages.XHRPostMessage; import com.fr.third.socketio.protocol.PacketDecoder; - import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import io.netty.handler.codec.http.DefaultHttpResponse; -import io.netty.handler.codec.http.FullHttpRequest; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpMethod; -import io.netty.handler.codec.http.HttpResponse; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.QueryStringDecoder; +import io.netty.handler.codec.http.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; +import java.util.UUID; + +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; @Sharable public class PollingTransport extends ChannelInboundHandlerAdapter { @@ -186,4 +179,15 @@ public class PollingTransport extends ChannelInboundHandlerAdapter { ctx.channel().writeAndFlush(res).addListener(ChannelFutureListener.CLOSE); } + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + final Channel channel = ctx.channel(); + ClientHead client = clientsBox.get(channel); + if (client != null && client.isTransportChannel(ctx.channel(), Transport.POLLING)) { + log.debug("channel inactive {}", client.getSessionId()); + client.releasePollingChannel(channel); + } + super.channelInactive(ctx); + } + } diff --git a/fine-socketio/src/com/fr/third/socketio/transport/WebSocketTransport.java b/fine-socketio/src/com/fr/third/socketio/transport/WebSocketTransport.java index e00842418..137cb15b3 100644 --- a/fine-socketio/src/com/fr/third/socketio/transport/WebSocketTransport.java +++ b/fine-socketio/src/com/fr/third/socketio/transport/WebSocketTransport.java @@ -1,5 +1,5 @@ /** - * Copyright 2012 Nikita Koksharov + * Copyright (c) 2012-2019 Nikita Koksharov * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,14 @@ import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; -import com.fr.third.socketio.Configuration; -import com.fr.third.socketio.SocketIOChannelInitializer; -import com.fr.third.socketio.Transport; +import com.fr.third.socketio.protocol.Packet; +import com.fr.third.socketio.protocol.PacketType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fr.third.socketio.Configuration; +import com.fr.third.socketio.SocketIOChannelInitializer; +import com.fr.third.socketio.Transport; import com.fr.third.socketio.handler.AuthorizeHandler; import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.handler.ClientsBox; @@ -49,7 +51,6 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; -import io.netty.util.ReferenceCountUtil; @Sharable public class WebSocketTransport extends ChannelInboundHandlerAdapter { @@ -78,8 +79,7 @@ public class WebSocketTransport extends ChannelInboundHandlerAdapter { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof CloseWebSocketFrame) { - ctx.channel().close(); - ReferenceCountUtil.release(msg); + ctx.channel().writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); } else if (msg instanceof BinaryWebSocketFrame || msg instanceof TextWebSocketFrame) { ByteBufHolder frame = (ByteBufHolder) msg; @@ -138,12 +138,20 @@ public class WebSocketTransport extends ChannelInboundHandlerAdapter { @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { - ClientHead client = clientsBox.get(ctx.channel()); + final Channel channel = ctx.channel(); + ClientHead client = clientsBox.get(channel); + Packet packet = new Packet(PacketType.MESSAGE); + packet.setSubType(PacketType.DISCONNECT); if (client != null && client.isTransportChannel(ctx.channel(), Transport.WEBSOCKET)) { log.debug("channel inactive {}", client.getSessionId()); client.onChannelDisconnect(); } super.channelInactive(ctx); + if (client != null) { + client.send(packet); + } + channel.close(); + ctx.close(); } private void handshake(ChannelHandlerContext ctx, final UUID sessionId, String path, FullHttpRequest req) {