Browse Source

更新socketio的版本

research/11.0
richie 6 years ago
parent
commit
43ff8a8d20
  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. 85
      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. 46
      fine-socketio/src/com/fr/third/socketio/handler/AuthorizeHandler.java
  34. 45
      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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,17 +15,19 @@
*/ */
package com.fr.third.socketio; 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.handler.SuccessAuthorizationListener;
import com.fr.third.socketio.listener.DefaultExceptionListener; import com.fr.third.socketio.listener.DefaultExceptionListener;
import com.fr.third.socketio.listener.ExceptionListener; import com.fr.third.socketio.listener.ExceptionListener;
import com.fr.third.socketio.protocol.JsonSupport; import com.fr.third.socketio.protocol.JsonSupport;
import com.fr.third.socketio.store.MemoryStoreFactory; import com.fr.third.socketio.store.MemoryStoreFactory;
import com.fr.third.socketio.store.RedissonStoreFactory;
import com.fr.third.socketio.store.StoreFactory; import com.fr.third.socketio.store.StoreFactory;
import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.KeyManagerFactory;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
public class Configuration { public class Configuration {
@ -85,6 +87,8 @@ public class Configuration {
private boolean websocketCompression = true; private boolean websocketCompression = true;
private boolean randomSession = false;
public Configuration() { public Configuration() {
} }
@ -150,6 +154,7 @@ public class Configuration {
setHttpCompression(conf.isHttpCompression()); setHttpCompression(conf.isHttpCompression());
setWebsocketCompression(conf.isWebsocketCompression()); setWebsocketCompression(conf.isWebsocketCompression());
setRandomSession(conf.randomSession);
} }
public JsonSupport getJsonSupport() { public JsonSupport getJsonSupport() {
@ -358,6 +363,7 @@ public class Configuration {
* @param clientStoreFactory - implements StoreFactory * @param clientStoreFactory - implements StoreFactory
* *
* @see MemoryStoreFactory * @see MemoryStoreFactory
* @see RedissonStoreFactory
*/ */
public void setStoreFactory(StoreFactory clientStoreFactory) { public void setStoreFactory(StoreFactory clientStoreFactory) {
this.storeFactory = clientStoreFactory; this.storeFactory = clientStoreFactory;
@ -571,4 +577,11 @@ public class Configuration {
return websocketCompression; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.TrustManager;
import javax.net.ssl.TrustManagerFactory; 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.Logger;
import org.slf4j.LoggerFactory; 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.PacketDecoder;
import com.fr.third.socketio.protocol.PacketEncoder; import com.fr.third.socketio.protocol.PacketEncoder;
import com.fr.third.socketio.scheduler.CancelableScheduler; 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.StoreFactory;
import com.fr.third.socketio.store.pubsub.DisconnectMessage; import com.fr.third.socketio.store.pubsub.DisconnectMessage;
import com.fr.third.socketio.store.pubsub.PubSubType; 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.Channel;
import io.netty.channel.ChannelHandlerContext; 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.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder; import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder; import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
import io.netty.handler.ssl.SslHandler; import io.netty.handler.ssl.SslHandler;
public class SocketIOChannelInitializer extends ChannelInitializer<Channel> implements DisconnectableHub { public class SocketIOChannelInitializer extends ChannelInitializer<Channel> implements DisconnectableHub {
@ -83,7 +84,7 @@ public class SocketIOChannelInitializer extends ChannelInitializer<Channel> impl
private AuthorizeHandler authorizeHandler; private AuthorizeHandler authorizeHandler;
private PollingTransport xhrPollingTransport; private PollingTransport xhrPollingTransport;
private WebSocketTransport webSocketTransport; private WebSocketTransport webSocketTransport;
//private WebSocketServerCompressionHandler webSocketTransportCompression = new WebSocketServerCompressionHandler(); private WebSocketServerCompressionHandler webSocketTransportCompression = new WebSocketServerCompressionHandler();
private EncoderHandler encoderHandler; private EncoderHandler encoderHandler;
private WrongUrlHandler wrongUrlHandler; private WrongUrlHandler wrongUrlHandler;
@ -185,8 +186,7 @@ public class SocketIOChannelInitializer extends ChannelInitializer<Channel> impl
pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport); pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport);
// TODO use single instance when https://github.com/netty/netty/issues/4755 will be resolved // TODO use single instance when https://github.com/netty/netty/issues/4755 will be resolved
if (configuration.isWebsocketCompression()) { 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); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

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

@ -1,12 +1,12 @@
/** /**
* Copyright 2012 Nikita Koksharov * Copyright (c) 2012-2019 Nikita Koksharov
* <p> *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* <p> *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* <p> *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -15,7 +15,6 @@
*/ */
package com.fr.third.socketio; package com.fr.third.socketio;
import com.fr.third.socketio.listener.*;
import com.fr.third.socketio.listener.ClientListeners; import com.fr.third.socketio.listener.ClientListeners;
import com.fr.third.socketio.listener.ConnectListener; import com.fr.third.socketio.listener.ConnectListener;
import com.fr.third.socketio.listener.DataListener; import com.fr.third.socketio.listener.DataListener;
@ -39,7 +38,6 @@ import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import io.netty.util.concurrent.GenericFutureListener;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -48,27 +46,24 @@ import com.fr.third.socketio.namespace.NamespacesHub;
/** /**
* Fully thread-safe. * Fully thread-safe.
*
*/ */
public class SocketIOServer implements ClientListeners { public class SocketIOServer implements ClientListeners {
private static final Logger log = LoggerFactory.getLogger(SocketIOServer.class); private static final Logger log = LoggerFactory.getLogger(SocketIOServer.class);
private final Configuration configCopy; private final Configuration configCopy;
private final Configuration configuration; private final Configuration configuration;
private final NamespacesHub namespacesHub; private final NamespacesHub namespacesHub;
private final SocketIONamespace mainNamespace; private final SocketIONamespace mainNamespace;
private SocketIOChannelInitializer pipelineFactory = new SocketIOChannelInitializer(); private SocketIOChannelInitializer pipelineFactory = new SocketIOChannelInitializer();
private EventLoopGroup bossGroup; private EventLoopGroup bossGroup;
private EventLoopGroup workerGroup; private EventLoopGroup workerGroup;
public SocketIOServer(Configuration configuration) { public SocketIOServer(Configuration configuration) {
this.configuration = configuration; this.configuration = configuration;
this.configCopy = new Configuration(configuration); this.configCopy = new Configuration(configuration);
namespacesHub = new NamespacesHub(configCopy); namespacesHub = new NamespacesHub(configCopy);
@ -76,7 +71,6 @@ public class SocketIOServer implements ClientListeners {
} }
public void setPipelineFactory(SocketIOChannelInitializer pipelineFactory) { public void setPipelineFactory(SocketIOChannelInitializer pipelineFactory) {
this.pipelineFactory = pipelineFactory; this.pipelineFactory = pipelineFactory;
} }
@ -86,7 +80,6 @@ public class SocketIOServer implements ClientListeners {
* @return clients collection * @return clients collection
*/ */
public Collection<SocketIOClient> getAllClients() { public Collection<SocketIOClient> getAllClients() {
return namespacesHub.get(Namespace.DEFAULT_NAME).getAllClients(); return namespacesHub.get(Namespace.DEFAULT_NAME).getAllClients();
} }
@ -97,7 +90,6 @@ public class SocketIOServer implements ClientListeners {
* @return client * @return client
*/ */
public SocketIOClient getClient(UUID uuid) { public SocketIOClient getClient(UUID uuid) {
return namespacesHub.get(Namespace.DEFAULT_NAME).getClient(uuid); return namespacesHub.get(Namespace.DEFAULT_NAME).getClient(uuid);
} }
@ -107,12 +99,10 @@ public class SocketIOServer implements ClientListeners {
* @return namespaces collection * @return namespaces collection
*/ */
public Collection<SocketIONamespace> getAllNamespaces() { public Collection<SocketIONamespace> getAllNamespaces() {
return namespacesHub.getAllNamespaces(); return namespacesHub.getAllNamespaces();
} }
public BroadcastOperations getBroadcastOperations() { public BroadcastOperations getBroadcastOperations() {
return new BroadcastOperations(getAllClients(), configCopy.getStoreFactory()); return new BroadcastOperations(getAllClients(), configCopy.getStoreFactory());
} }
@ -124,7 +114,6 @@ public class SocketIOServer implements ClientListeners {
* @return broadcast operations * @return broadcast operations
*/ */
public BroadcastOperations getRoomOperations(String room) { public BroadcastOperations getRoomOperations(String room) {
Iterable<SocketIOClient> clients = namespacesHub.getRoomClients(room); Iterable<SocketIOClient> clients = namespacesHub.getRoomClients(room);
return new BroadcastOperations(clients, configCopy.getStoreFactory()); return new BroadcastOperations(clients, configCopy.getStoreFactory());
} }
@ -133,41 +122,15 @@ public class SocketIOServer implements ClientListeners {
* Start server * Start server
*/ */
public void start() { public void start() {
startAsync().syncUninterruptibly(); startAsync().syncUninterruptibly();
} }
public void start(GenericFutureListener<? extends Future<? super Void>> listener) {
startAsync(listener).syncUninterruptibly();
}
/** /**
* Start server asynchronously * Start server asynchronously
* *
* @return void * @return void
*/ */
public Future<Void> startAsync() { 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()); log.info("Session store / pubsub factory used: {}", configCopy.getStoreFactory());
initGroups(); initGroups();
@ -189,11 +152,19 @@ public class SocketIOServer implements ClientListeners {
addr = new InetSocketAddress(configCopy.getHostname(), configCopy.getPort()); 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) { protected void applyConnectionOptions(ServerBootstrap bootstrap) {
SocketConfig config = configCopy.getSocketConfig(); SocketConfig config = configCopy.getSocketConfig();
bootstrap.childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay()); bootstrap.childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay());
if (config.getTcpSendBufferSize() != -1) { if (config.getTcpSendBufferSize() != -1) {
@ -211,7 +182,6 @@ public class SocketIOServer implements ClientListeners {
} }
protected void initGroups() { protected void initGroups() {
if (configCopy.isUseLinuxNativeEpoll()) { if (configCopy.isUseLinuxNativeEpoll()) {
bossGroup = new EpollEventLoopGroup(configCopy.getBossThreads()); bossGroup = new EpollEventLoopGroup(configCopy.getBossThreads());
workerGroup = new EpollEventLoopGroup(configCopy.getWorkerThreads()); workerGroup = new EpollEventLoopGroup(configCopy.getWorkerThreads());
@ -225,7 +195,6 @@ public class SocketIOServer implements ClientListeners {
* Stop server * Stop server
*/ */
public void stop() { public void stop() {
bossGroup.shutdownGracefully().syncUninterruptibly(); bossGroup.shutdownGracefully().syncUninterruptibly();
workerGroup.shutdownGracefully().syncUninterruptibly(); workerGroup.shutdownGracefully().syncUninterruptibly();
@ -233,31 +202,22 @@ public class SocketIOServer implements ClientListeners {
log.info("SocketIO server stopped"); log.info("SocketIO server stopped");
} }
/**
* Stop server
* 不等待
*/
public void stopImmediately() { public void stopImmediately() {
this.bossGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly();
bossGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly(); this.workerGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly();
workerGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly(); this.pipelineFactory.stop();
pipelineFactory.stop();
log.info("SocketIO server stopped"); log.info("SocketIO server stopped");
} }
public SocketIONamespace addNamespace(String name) { public SocketIONamespace addNamespace(String name) {
return namespacesHub.create(name); return namespacesHub.create(name);
} }
public SocketIONamespace getNamespace(String name) { public SocketIONamespace getNamespace(String name) {
return namespacesHub.get(name); return namespacesHub.get(name);
} }
public void removeNamespace(String name) { public void removeNamespace(String name) {
namespacesHub.remove(name); namespacesHub.remove(name);
} }
@ -269,55 +229,46 @@ public class SocketIOServer implements ClientListeners {
* @return Configuration object * @return Configuration object
*/ */
public Configuration getConfiguration() { public Configuration getConfiguration() {
return configuration; return configuration;
} }
@Override @Override
public void addMultiTypeEventListener(String eventName, MultiTypeEventListener listener, Class<?>... eventClass) { public void addMultiTypeEventListener(String eventName, MultiTypeEventListener listener, Class<?>... eventClass) {
mainNamespace.addMultiTypeEventListener(eventName, listener, eventClass); mainNamespace.addMultiTypeEventListener(eventName, listener, eventClass);
} }
@Override @Override
public <T> void addEventListener(String eventName, Class<T> eventClass, DataListener<T> listener) { public <T> void addEventListener(String eventName, Class<T> eventClass, DataListener<T> listener) {
mainNamespace.addEventListener(eventName, eventClass, listener); mainNamespace.addEventListener(eventName, eventClass, listener);
} }
@Override @Override
public void removeAllListeners(String eventName) { public void removeAllListeners(String eventName) {
mainNamespace.removeAllListeners(eventName); mainNamespace.removeAllListeners(eventName);
} }
@Override @Override
public void addDisconnectListener(DisconnectListener listener) { public void addDisconnectListener(DisconnectListener listener) {
mainNamespace.addDisconnectListener(listener); mainNamespace.addDisconnectListener(listener);
} }
@Override @Override
public void addConnectListener(ConnectListener listener) { public void addConnectListener(ConnectListener listener) {
mainNamespace.addConnectListener(listener); mainNamespace.addConnectListener(listener);
} }
@Override @Override
public void addPingListener(PingListener listener) { public void addPingListener(PingListener listener) {
mainNamespace.addPingListener(listener); mainNamespace.addPingListener(listener);
} }
@Override @Override
public void addListeners(Object listeners) { public void addListeners(Object listeners) {
mainNamespace.addListeners(listeners); mainNamespace.addListeners(listeners);
} }
@Override @Override
public void addListeners(Object listeners, Class<?> listenersClass) { public void addListeners(Object listeners, Class<?> listenersClass) {
mainNamespace.addListeners(listeners, 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,27 +15,28 @@
*/ */
package com.fr.third.socketio.ack; 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.AckCallback;
import com.fr.third.socketio.Disconnectable; import com.fr.third.socketio.Disconnectable;
import com.fr.third.socketio.MultiTypeAckCallback; import com.fr.third.socketio.MultiTypeAckCallback;
import com.fr.third.socketio.MultiTypeArgs; import com.fr.third.socketio.MultiTypeArgs;
import com.fr.third.socketio.SocketIOClient; 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 io.netty.util.internal.PlatformDependent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AckManager implements Disconnectable { public class AckManager implements Disconnectable {
class AckEntry { class AckEntry {
@ -69,7 +70,7 @@ public class AckManager implements Disconnectable {
private static final Logger log = LoggerFactory.getLogger(AckManager.class); 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; private final CancelableScheduler scheduler;
@ -87,7 +88,7 @@ public class AckManager implements Disconnectable {
AckEntry ackEntry = ackEntries.get(sessionId); AckEntry ackEntry = ackEntries.get(sessionId);
if (ackEntry == null) { if (ackEntry == null) {
ackEntry = new AckEntry(); ackEntry = new AckEntry();
AckEntry oldAckEntry = ackEntries.put(sessionId, ackEntry); AckEntry oldAckEntry = ackEntries.putIfAbsent(sessionId, ackEntry);
if (oldAckEntry != null) { if (oldAckEntry != null) {
ackEntry = oldAckEntry; ackEntry = oldAckEntry;
} }
@ -97,7 +98,7 @@ public class AckManager implements Disconnectable {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void onAck(SocketIOClient client, Packet packet) { 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); scheduler.cancel(key);
AckCallback callback = removeCallback(client.getSessionId(), packet.getAckId()); AckCallback callback = removeCallback(client.getSessionId(), packet.getAckId());
@ -153,7 +154,7 @@ public class AckManager implements Disconnectable {
if (callback.getTimeout() == -1) { if (callback.getTimeout() == -1) {
return; 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() { scheduler.scheduleCallback(key, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -178,7 +179,7 @@ public class AckManager implements Disconnectable {
if (callback != null) { if (callback != null) {
callback.onTimeout(); 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); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.List;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import com.fr.third.socketio.SocketIOServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.fr.third.springframework.beans.BeansException; 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.MethodCallback;
import com.fr.third.springframework.util.ReflectionUtils.MethodFilter; import com.fr.third.springframework.util.ReflectionUtils.MethodFilter;
import com.fr.third.socketio.SocketIOServer;
public class SpringAnnotationScanner implements BeanPostProcessor { public class SpringAnnotationScanner implements BeanPostProcessor {
private static final Logger log = LoggerFactory.getLogger(SpringAnnotationScanner.class); private static final Logger log = LoggerFactory.getLogger(SpringAnnotationScanner.class);

46
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.HandshakeData;
import com.fr.third.socketio.SocketIOClient; import com.fr.third.socketio.SocketIOClient;
import com.fr.third.socketio.Transport; 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.messages.HttpErrorMessage;
import com.fr.third.socketio.namespace.Namespace; import com.fr.third.socketio.namespace.Namespace;
import com.fr.third.socketio.namespace.NamespacesHub; 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.protocol.PacketType;
import com.fr.third.socketio.scheduler.CancelableScheduler; import com.fr.third.socketio.scheduler.CancelableScheduler;
import com.fr.third.socketio.scheduler.SchedulerKey; import com.fr.third.socketio.scheduler.SchedulerKey;
import org.slf4j.Logger; import com.fr.third.socketio.scheduler.SchedulerKey.Type;
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 io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
@ -93,7 +94,7 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
@Override @Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception { 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() { disconnectScheduler.schedule(key, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -106,7 +107,7 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { 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); disconnectScheduler.cancel(key);
if (msg instanceof FullHttpRequest) { if (msg instanceof FullHttpRequest) {
@ -164,7 +165,12 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
return false; 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"); List<String> transportValue = params.get("transport");
if (transportValue == null) { if (transportValue == null) {
@ -207,11 +213,20 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
} }
/** /**
This method will either generate a new random sessionId or will retrieve the value stored * 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 * 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). * random uuid to be generated instead (same as not passing a cookie in the first place).
*/ */
private UUID generateOrGetSessionIdFromRequest(HttpHeaders headers) { private UUID generateOrGetSessionIdFromRequest(HttpHeaders headers) {
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)) { for (String cookieHeader : headers.getAll(HttpHeaderNames.COOKIE)) {
Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieHeader); Set<Cookie> cookies = ServerCookieDecoder.LAX.decode(cookieHeader);
@ -225,11 +240,12 @@ public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Di
} }
} }
} }
return UUID.randomUUID(); return UUID.randomUUID();
} }
public void connect(UUID sessionId) { 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); disconnectScheduler.cancel(key);
} }

45
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,40 +15,35 @@
*/ */
package com.fr.third.socketio.handler; 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.Configuration;
import com.fr.third.socketio.DisconnectableHub; import com.fr.third.socketio.DisconnectableHub;
import com.fr.third.socketio.HandshakeData; import com.fr.third.socketio.HandshakeData;
import com.fr.third.socketio.Transport; 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.messages.OutPacketMessage;
import com.fr.third.socketio.namespace.Namespace; import com.fr.third.socketio.namespace.Namespace;
import com.fr.third.socketio.protocol.Packet; import com.fr.third.socketio.protocol.Packet;
import com.fr.third.socketio.protocol.PacketType; import com.fr.third.socketio.protocol.PacketType;
import com.fr.third.socketio.scheduler.CancelableScheduler; import com.fr.third.socketio.scheduler.CancelableScheduler;
import com.fr.third.socketio.scheduler.SchedulerKey; import com.fr.third.socketio.scheduler.SchedulerKey;
import com.fr.third.socketio.transport.NamespaceClient; import com.fr.third.socketio.scheduler.SchedulerKey.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fr.third.socketio.ack.AckManager;
import com.fr.third.socketio.store.Store; import com.fr.third.socketio.store.Store;
import com.fr.third.socketio.store.StoreFactory; import com.fr.third.socketio.store.StoreFactory;
import com.fr.third.socketio.transport.NamespaceClient;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import io.netty.util.internal.PlatformDependent; 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 { public class ClientHead {
@ -104,6 +99,14 @@ public class ClientHead {
sendPackets(transport, channel); 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() { public String getOrigin() {
return handshakeData.getHttpHeaders().get(HttpHeaderNames.ORIGIN); return handshakeData.getHttpHeaders().get(HttpHeaderNames.ORIGIN);
} }
@ -113,18 +116,18 @@ public class ClientHead {
} }
public void cancelPingTimeout() { public void cancelPingTimeout() {
SchedulerKey key = new SchedulerKey(SchedulerKey.Type.PING_TIMEOUT, sessionId); SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
disconnectScheduler.cancel(key); disconnectScheduler.cancel(key);
} }
public void schedulePingTimeout() { 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() { disconnectScheduler.schedule(key, new Runnable() {
@Override @Override
public void run() { public void run() {
ClientHead client = clientsBox.get(sessionId); ClientHead client = clientsBox.get(sessionId);
if (client != null) { if (client != null) {
client.onChannelDisconnect(); client.disconnect();
log.debug("{} removed due to ping timeout", sessionId); log.debug("{} removed due to ping timeout", sessionId);
} }
} }
@ -204,7 +207,9 @@ public class ClientHead {
public void disconnect() { public void disconnect() {
ChannelFuture future = send(new Packet(PacketType.DISCONNECT)); ChannelFuture future = send(new Packet(PacketType.DISCONNECT));
if(future != null) {
future.addListener(ChannelFutureListener.CLOSE); future.addListener(ChannelFutureListener.CLOSE);
}
onChannelDisconnect(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.Configuration;
import com.fr.third.socketio.Transport; 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.HttpErrorMessage;
import com.fr.third.socketio.messages.HttpMessage; import com.fr.third.socketio.messages.HttpMessage;
import com.fr.third.socketio.messages.OutPacketMessage; 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.messages.XHRPostMessage;
import com.fr.third.socketio.protocol.Packet; import com.fr.third.socketio.protocol.Packet;
import com.fr.third.socketio.protocol.PacketEncoder; 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.ByteBuf;
import io.netty.buffer.ByteBufOutputStream; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,13 +15,6 @@
*/ */
package com.fr.third.socketio.handler; 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 com.fr.third.socketio.transport.NamespaceClient;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
@ -32,6 +25,14 @@ import io.netty.util.CharsetUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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 @Sharable
public class InPacketHandler extends SimpleChannelInboundHandler<PacketsMessage> { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,9 +16,8 @@
package com.fr.third.socketio.messages; package com.fr.third.socketio.messages;
import com.fr.third.socketio.Transport; import com.fr.third.socketio.Transport;
import io.netty.buffer.ByteBuf;
import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.handler.ClientHead;
import io.netty.buffer.ByteBuf;
public class PacketsMessage { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.SocketIOClient;
import com.fr.third.socketio.SocketIONamespace; import com.fr.third.socketio.SocketIONamespace;
import com.fr.third.socketio.annotation.ScannerEngine; 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.JsonSupport;
import com.fr.third.socketio.protocol.Packet; import com.fr.third.socketio.protocol.Packet;
import com.fr.third.socketio.store.StoreFactory; 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.store.pubsub.PubSubType;
import com.fr.third.socketio.transport.NamespaceClient; 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; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.Configuration;
import com.fr.third.socketio.SocketIOClient; import com.fr.third.socketio.SocketIOClient;
import com.fr.third.socketio.SocketIONamespace; import com.fr.third.socketio.SocketIONamespace;
import com.fr.third.socketio.misc.CompositeIterable;
import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;
import java.util.ArrayList; import java.util.ArrayList;
@ -25,8 +26,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import com.fr.third.socketio.misc.CompositeIterable;
public class NamespacesHub { public class NamespacesHub {
private final ConcurrentMap<String, SocketIONamespace> namespaces = PlatformDependent.newConcurrentHashMap(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,14 +15,9 @@
*/ */
package com.fr.third.socketio.protocol; 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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -32,9 +27,12 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.fr.third.socketio.AckCallback;
import com.fr.third.socketio.MultiTypeAckCallback;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.annotation.JsonInclude.Include;
import com.fr.third.fasterxml.jackson.core.JsonGenerationException; import com.fr.third.fasterxml.jackson.core.JsonGenerationException;
import com.fr.third.fasterxml.jackson.core.JsonGenerator; 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.ser.std.StdSerializer;
import com.fr.third.fasterxml.jackson.databind.type.ArrayType; 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 { public class JacksonJsonSupport implements JsonSupport {
private class AckArgsDeserializer extends StdDeserializer<AckArgs> { private class AckArgsDeserializer extends StdDeserializer<AckArgs> {
@ -337,19 +339,19 @@ public class JacksonJsonSupport implements JsonSupport {
@Override @Override
public <T> T readValue(String namespaceName, ByteBufInputStream src, Class<T> valueType) throws IOException { public <T> T readValue(String namespaceName, ByteBufInputStream src, Class<T> valueType) throws IOException {
namespaceClass.set(namespaceName); namespaceClass.set(namespaceName);
return objectMapper.readValue(src, valueType); return objectMapper.readValue((InputStream)src, valueType);
} }
@Override @Override
public AckArgs readAckArgs(ByteBufInputStream src, AckCallback<?> callback) throws IOException { public AckArgs readAckArgs(ByteBufInputStream src, AckCallback<?> callback) throws IOException {
currentAckClass.set(callback); currentAckClass.set(callback);
return objectMapper.readValue(src, AckArgs.class); return objectMapper.readValue((InputStream)src, AckArgs.class);
} }
@Override @Override
public void writeValue(ByteBufOutputStream out, Object value) throws IOException { public void writeValue(ByteBufOutputStream out, Object value) throws IOException {
modifier.getSerializer().clear(); modifier.getSerializer().clear();
objectMapper.writeValue(out, value); objectMapper.writeValue((OutputStream)out, value);
} }
@Override @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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,7 +15,6 @@
*/ */
package com.fr.third.socketio.protocol; package com.fr.third.socketio.protocol;
import com.fr.third.socketio.namespace.Namespace;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.io.Serializable; import java.io.Serializable;
@ -23,6 +22,8 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.fr.third.socketio.namespace.Namespace;
public class Packet implements Serializable { public class Packet implements Serializable {
private static final long serialVersionUID = 4560159536486711426L; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.getType() == PacketType.MESSAGE) {
if (packet.getSubType() == PacketType.CONNECT if (packet.getSubType() == PacketType.CONNECT
|| packet.getSubType() == PacketType.DISCONNECT) { || packet.getSubType() == PacketType.DISCONNECT) {
packet.setNsp(readString(frame)); packet.setNsp(readNamespace(frame));
} }
if (packet.hasAttachments() && !packet.isAttachmentsLoaded()) { if (packet.hasAttachments() && !packet.isAttachmentsLoaded()) {
@ -310,4 +310,21 @@ 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,13 +15,14 @@
*/ */
package com.fr.third.socketio.store; 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 io.netty.util.internal.PlatformDependent;
import java.util.Map; import java.util.Map;
import java.util.UUID; 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 { public class MemoryStoreFactory extends BaseStoreFactory {
private final MemoryPubSubStore pubSubMemoryStore = new MemoryPubSubStore(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap; 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.PubSubListener;
import com.fr.third.socketio.store.pubsub.PubSubMessage; import com.fr.third.socketio.store.pubsub.PubSubMessage;
import com.fr.third.socketio.store.pubsub.PubSubStore; import com.fr.third.socketio.store.pubsub.PubSubStore;
import com.fr.third.socketio.store.pubsub.PubSubType; 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; import io.netty.util.internal.PlatformDependent;
@ -77,7 +78,7 @@ public class RedissonPubSubStore implements PubSubStore {
public void unsubscribe(PubSubType type) { public void unsubscribe(PubSubType type) {
String name = type.toString(); String name = type.toString();
Queue<Integer> regIds = map.remove(name); Queue<Integer> regIds = map.remove(name);
RTopic<Object> topic = redissonSub.getTopic(name); RTopic topic = redissonSub.getTopic(name);
for (Integer id : regIds) { for (Integer id : regIds) {
topic.removeListener(id); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.Map;
import java.util.UUID; 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.Redisson;
import com.fr.third.org.redisson.api.RedissonClient; 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 { public class RedissonStoreFactory extends BaseStoreFactory {
private final RedissonClient redisClient; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; 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.AuthorizeHandler;
import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.handler.ClientHead;
import com.fr.third.socketio.namespace.NamespacesHub; import com.fr.third.socketio.namespace.NamespacesHub;
import com.fr.third.socketio.protocol.JsonSupport; 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 { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,9 +15,10 @@
*/ */
package com.fr.third.socketio.transport; package com.fr.third.socketio.transport;
import com.fr.third.socketio.Disconnectable;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import com.fr.third.socketio.Disconnectable;
@Deprecated @Deprecated
public abstract class BaseTransport extends ChannelInboundHandlerAdapter implements Disconnectable { 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.UUID;
import java.util.concurrent.atomic.AtomicBoolean; 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.AckCallback;
import com.fr.third.socketio.HandshakeData; import com.fr.third.socketio.HandshakeData;
import com.fr.third.socketio.SocketIOClient; import com.fr.third.socketio.SocketIOClient;
import com.fr.third.socketio.Transport; 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.handler.ClientHead;
import com.fr.third.socketio.namespace.Namespace; import com.fr.third.socketio.namespace.Namespace;
import com.fr.third.socketio.protocol.Packet; 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -15,16 +15,7 @@
*/ */
package com.fr.third.socketio.transport; 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 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.AuthorizeHandler;
import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.handler.ClientHead;
import com.fr.third.socketio.handler.ClientsBox; 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.XHROptionsMessage;
import com.fr.third.socketio.messages.XHRPostMessage; import com.fr.third.socketio.messages.XHRPostMessage;
import com.fr.third.socketio.protocol.PacketDecoder; import com.fr.third.socketio.protocol.PacketDecoder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.*;
import io.netty.handler.codec.http.FullHttpRequest; import org.slf4j.Logger;
import io.netty.handler.codec.http.HttpHeaderNames; import org.slf4j.LoggerFactory;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponse; import java.io.IOException;
import io.netty.handler.codec.http.HttpResponseStatus; import java.util.List;
import io.netty.handler.codec.http.QueryStringDecoder; import java.util.UUID;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
@Sharable @Sharable
public class PollingTransport extends ChannelInboundHandlerAdapter { public class PollingTransport extends ChannelInboundHandlerAdapter {
@ -186,4 +179,15 @@ public class PollingTransport extends ChannelInboundHandlerAdapter {
ctx.channel().writeAndFlush(res).addListener(ChannelFutureListener.CLOSE); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.fr.third.socketio.Configuration; import com.fr.third.socketio.protocol.Packet;
import com.fr.third.socketio.SocketIOChannelInitializer; import com.fr.third.socketio.protocol.PacketType;
import com.fr.third.socketio.Transport;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.AuthorizeHandler;
import com.fr.third.socketio.handler.ClientHead; import com.fr.third.socketio.handler.ClientHead;
import com.fr.third.socketio.handler.ClientsBox; 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.WebSocketFrameAggregator;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.ReferenceCountUtil;
@Sharable @Sharable
public class WebSocketTransport extends ChannelInboundHandlerAdapter { public class WebSocketTransport extends ChannelInboundHandlerAdapter {
@ -78,8 +79,7 @@ public class WebSocketTransport extends ChannelInboundHandlerAdapter {
@Override @Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof CloseWebSocketFrame) { if (msg instanceof CloseWebSocketFrame) {
ctx.channel().close(); ctx.channel().writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE);
ReferenceCountUtil.release(msg);
} else if (msg instanceof BinaryWebSocketFrame } else if (msg instanceof BinaryWebSocketFrame
|| msg instanceof TextWebSocketFrame) { || msg instanceof TextWebSocketFrame) {
ByteBufHolder frame = (ByteBufHolder) msg; ByteBufHolder frame = (ByteBufHolder) msg;
@ -138,12 +138,20 @@ public class WebSocketTransport extends ChannelInboundHandlerAdapter {
@Override @Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception { 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)) { if (client != null && client.isTransportChannel(ctx.channel(), Transport.WEBSOCKET)) {
log.debug("channel inactive {}", client.getSessionId()); log.debug("channel inactive {}", client.getSessionId());
client.onChannelDisconnect(); client.onChannelDisconnect();
} }
super.channelInactive(ctx); 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) { private void handshake(ChannelHandlerContext ctx, final UUID sessionId, String path, FullHttpRequest req) {

Loading…
Cancel
Save