Browse Source

KERNEL-478 升级socketio

bugfix/10.0
richie 5 years ago
parent
commit
edb69b0208
  1. 2
      fine-socketio/src/com/fr/third/socketio/AckCallback.java
  2. 2
      fine-socketio/src/com/fr/third/socketio/AckMode.java
  3. 2
      fine-socketio/src/com/fr/third/socketio/AckRequest.java
  4. 2
      fine-socketio/src/com/fr/third/socketio/AuthorizationListener.java
  5. 2
      fine-socketio/src/com/fr/third/socketio/BroadcastAckCallback.java
  6. 2
      fine-socketio/src/com/fr/third/socketio/BroadcastOperations.java
  7. 2
      fine-socketio/src/com/fr/third/socketio/ClientOperations.java
  8. 21
      fine-socketio/src/com/fr/third/socketio/Configuration.java
  9. 2
      fine-socketio/src/com/fr/third/socketio/Disconnectable.java
  10. 2
      fine-socketio/src/com/fr/third/socketio/DisconnectableHub.java
  11. 2
      fine-socketio/src/com/fr/third/socketio/HandshakeData.java
  12. 2
      fine-socketio/src/com/fr/third/socketio/JsonSupportWrapper.java
  13. 2
      fine-socketio/src/com/fr/third/socketio/MultiTypeAckCallback.java
  14. 2
      fine-socketio/src/com/fr/third/socketio/MultiTypeArgs.java
  15. 2
      fine-socketio/src/com/fr/third/socketio/SocketConfig.java
  16. 14
      fine-socketio/src/com/fr/third/socketio/SocketIOChannelInitializer.java
  17. 2
      fine-socketio/src/com/fr/third/socketio/SocketIOClient.java
  18. 2
      fine-socketio/src/com/fr/third/socketio/SocketIONamespace.java
  19. 167
      fine-socketio/src/com/fr/third/socketio/SocketIOServer.java
  20. 2
      fine-socketio/src/com/fr/third/socketio/Transport.java
  21. 2
      fine-socketio/src/com/fr/third/socketio/VoidAckCallback.java
  22. 27
      fine-socketio/src/com/fr/third/socketio/ack/AckManager.java
  23. 2
      fine-socketio/src/com/fr/third/socketio/ack/AckSchedulerKey.java
  24. 2
      fine-socketio/src/com/fr/third/socketio/annotation/AnnotationScanner.java
  25. 2
      fine-socketio/src/com/fr/third/socketio/annotation/OnConnect.java
  26. 2
      fine-socketio/src/com/fr/third/socketio/annotation/OnConnectScanner.java
  27. 2
      fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnect.java
  28. 2
      fine-socketio/src/com/fr/third/socketio/annotation/OnDisconnectScanner.java
  29. 2
      fine-socketio/src/com/fr/third/socketio/annotation/OnEvent.java
  30. 2
      fine-socketio/src/com/fr/third/socketio/annotation/OnEventScanner.java
  31. 2
      fine-socketio/src/com/fr/third/socketio/annotation/ScannerEngine.java
  32. 5
      fine-socketio/src/com/fr/third/socketio/annotation/SpringAnnotationScanner.java
  33. 62
      fine-socketio/src/com/fr/third/socketio/handler/AuthorizeHandler.java
  34. 51
      fine-socketio/src/com/fr/third/socketio/handler/ClientHead.java
  35. 2
      fine-socketio/src/com/fr/third/socketio/handler/ClientsBox.java
  36. 11
      fine-socketio/src/com/fr/third/socketio/handler/EncoderHandler.java
  37. 17
      fine-socketio/src/com/fr/third/socketio/handler/InPacketHandler.java
  38. 2
      fine-socketio/src/com/fr/third/socketio/handler/PacketListener.java
  39. 2
      fine-socketio/src/com/fr/third/socketio/handler/SocketIOException.java
  40. 2
      fine-socketio/src/com/fr/third/socketio/handler/SuccessAuthorizationListener.java
  41. 2
      fine-socketio/src/com/fr/third/socketio/handler/TransportState.java
  42. 2
      fine-socketio/src/com/fr/third/socketio/handler/WrongUrlHandler.java
  43. 2
      fine-socketio/src/com/fr/third/socketio/listener/ClientListeners.java
  44. 2
      fine-socketio/src/com/fr/third/socketio/listener/ConnectListener.java
  45. 2
      fine-socketio/src/com/fr/third/socketio/listener/DataListener.java
  46. 2
      fine-socketio/src/com/fr/third/socketio/listener/DefaultExceptionListener.java
  47. 2
      fine-socketio/src/com/fr/third/socketio/listener/DisconnectListener.java
  48. 2
      fine-socketio/src/com/fr/third/socketio/listener/ExceptionListener.java
  49. 7
      fine-socketio/src/com/fr/third/socketio/listener/ExceptionListenerAdapter.java
  50. 2
      fine-socketio/src/com/fr/third/socketio/listener/MultiTypeEventListener.java
  51. 2
      fine-socketio/src/com/fr/third/socketio/listener/PingListener.java
  52. 2
      fine-socketio/src/com/fr/third/socketio/messages/HttpErrorMessage.java
  53. 2
      fine-socketio/src/com/fr/third/socketio/messages/HttpMessage.java
  54. 2
      fine-socketio/src/com/fr/third/socketio/messages/OutPacketMessage.java
  55. 5
      fine-socketio/src/com/fr/third/socketio/messages/PacketsMessage.java
  56. 2
      fine-socketio/src/com/fr/third/socketio/messages/XHROptionsMessage.java
  57. 2
      fine-socketio/src/com/fr/third/socketio/messages/XHRPostMessage.java
  58. 2
      fine-socketio/src/com/fr/third/socketio/misc/CompositeIterable.java
  59. 2
      fine-socketio/src/com/fr/third/socketio/misc/IterableCollection.java
  60. 2
      fine-socketio/src/com/fr/third/socketio/namespace/EventEntry.java
  61. 15
      fine-socketio/src/com/fr/third/socketio/namespace/Namespace.java
  62. 5
      fine-socketio/src/com/fr/third/socketio/namespace/NamespacesHub.java
  63. 2
      fine-socketio/src/com/fr/third/socketio/protocol/AckArgs.java
  64. 2
      fine-socketio/src/com/fr/third/socketio/protocol/AuthPacket.java
  65. 2
      fine-socketio/src/com/fr/third/socketio/protocol/Event.java
  66. 24
      fine-socketio/src/com/fr/third/socketio/protocol/JacksonJsonSupport.java
  67. 2
      fine-socketio/src/com/fr/third/socketio/protocol/JsonSupport.java
  68. 5
      fine-socketio/src/com/fr/third/socketio/protocol/Packet.java
  69. 21
      fine-socketio/src/com/fr/third/socketio/protocol/PacketDecoder.java
  70. 2
      fine-socketio/src/com/fr/third/socketio/protocol/PacketEncoder.java
  71. 2
      fine-socketio/src/com/fr/third/socketio/protocol/PacketType.java
  72. 2
      fine-socketio/src/com/fr/third/socketio/protocol/UTF8CharsScanner.java
  73. 2
      fine-socketio/src/com/fr/third/socketio/scheduler/CancelableScheduler.java
  74. 2
      fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelScheduler.java
  75. 2
      fine-socketio/src/com/fr/third/socketio/scheduler/HashedWheelTimeoutScheduler.java
  76. 2
      fine-socketio/src/com/fr/third/socketio/scheduler/SchedulerKey.java
  77. 2
      fine-socketio/src/com/fr/third/socketio/store/MemoryPubSubStore.java
  78. 2
      fine-socketio/src/com/fr/third/socketio/store/MemoryStore.java
  79. 7
      fine-socketio/src/com/fr/third/socketio/store/MemoryStoreFactory.java
  80. 11
      fine-socketio/src/com/fr/third/socketio/store/RedissonPubSubStore.java
  81. 2
      fine-socketio/src/com/fr/third/socketio/store/RedissonStore.java
  82. 7
      fine-socketio/src/com/fr/third/socketio/store/RedissonStoreFactory.java
  83. 2
      fine-socketio/src/com/fr/third/socketio/store/Store.java
  84. 2
      fine-socketio/src/com/fr/third/socketio/store/StoreFactory.java
  85. 10
      fine-socketio/src/com/fr/third/socketio/store/pubsub/BaseStoreFactory.java
  86. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/ConnectMessage.java
  87. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/DisconnectMessage.java
  88. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/DispatchMessage.java
  89. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/JoinLeaveMessage.java
  90. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubListener.java
  91. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubMessage.java
  92. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubStore.java
  93. 2
      fine-socketio/src/com/fr/third/socketio/store/pubsub/PubSubType.java
  94. 5
      fine-socketio/src/com/fr/third/socketio/transport/BaseTransport.java
  95. 8
      fine-socketio/src/com/fr/third/socketio/transport/NamespaceClient.java
  96. 40
      fine-socketio/src/com/fr/third/socketio/transport/PollingTransport.java
  97. 24
      fine-socketio/src/com/fr/third/socketio/transport/WebSocketTransport.java

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

21
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;
}
}

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

14
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<Channel> implements DisconnectableHub {
@ -83,7 +84,7 @@ public class SocketIOChannelInitializer extends ChannelInitializer<Channel> 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<Channel> 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);

2
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.

2
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.

167
fine-socketio/src/com/fr/third/socketio/SocketIOServer.java

@ -1,12 +1,12 @@
/**
* Copyright 2012 Nikita Koksharov
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* 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<SocketIOClient> 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<SocketIONamespace> getAllNamespaces() {
return namespacesHub.getAllNamespaces();
}
public BroadcastOperations getBroadcastOperations() {
return new BroadcastOperations(getAllClients(), configCopy.getStoreFactory());
}
/**
* Get broadcast operations for clients within
* room by <code>room</code> name
@ -124,76 +114,57 @@ public class SocketIOServer implements ClientListeners {
* @return broadcast operations
*/
public BroadcastOperations getRoomOperations(String room) {
Iterable<SocketIOClient> clients = namespacesHub.getRoomClients(room);
return new BroadcastOperations(clients, configCopy.getStoreFactory());
}
/**
* Start server
*/
public void start() {
startAsync().syncUninterruptibly();
}
public void start(GenericFutureListener<? extends Future<? super Void>> listener) {
startAsync(listener).syncUninterruptibly();
}
/**
* Start server asynchronously
*
*
* @return void
*/
public Future<Void> startAsync() {
return startAsync(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> 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<Void> startAsync(GenericFutureListener<? extends Future<? super Void>> listener) {
log.info("Session store / pubsub factory used: {}", configCopy.getStoreFactory());
initGroups();
pipelineFactory.start(configCopy, namespacesHub);
Class<? extends ServerChannel> 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<Void>() {
@Override
public void operationComplete(Future<Void> 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 <T> void addEventListener(String eventName, Class<T> eventClass, DataListener<T> 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);
}
}

2
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.

2
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.

27
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<UUID, AckEntry> ackEntries = PlatformDependent.newConcurrentHashMap();
private final ConcurrentMap<UUID, AckEntry> 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);
}
}

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

5
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);

62
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<String> 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<String> 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<Cookie> 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);
}

51
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();
}

2
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.

11
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;

17
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<PacketsMessage> {

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

7
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) {
}
}

2
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.

2
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.

2
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.

2
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.

2
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.

5
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 {

2
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.

2
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.

2
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.

2
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.

2
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.

15
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;
/**

5
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<String, SocketIONamespace> namespaces = PlatformDependent.newConcurrentHashMap();

2
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.

2
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.

2
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.

24
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<AckArgs> {
@ -337,19 +339,19 @@ public class JacksonJsonSupport implements JsonSupport {
@Override
public <T> T readValue(String namespaceName, ByteBufInputStream src, Class<T> 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

2
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.

5
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;

21
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);
}
}

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

7
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();

11
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<Integer> regIds = map.remove(name);
RTopic<Object> topic = redissonSub.getTopic(name);
RTopic topic = redissonSub.getTopic(name);
for (Integer id : regIds) {
topic.removeListener(id);
}

2
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.

7
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;

2
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.

2
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.

10
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 {

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

2
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.

5
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 {

8
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;

40
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);
}
}

24
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) {

Loading…
Cancel
Save