getTransports() {
- return transports;
- }
-
- /**
- * Package prefix for sending json-object from client
- * without full class name.
- *
- * With defined package prefix socket.io client
- * just need to define '@class: 'SomeType'' in json object
- * instead of '@class: 'com.full.package.name.SomeType''
- *
- * @param packagePrefix - prefix string
- *
- */
- public void setPackagePrefix(String packagePrefix) {
- this.packagePrefix = packagePrefix;
- }
- public String getPackagePrefix() {
- return packagePrefix;
- }
-
- /**
- * Buffer allocation method used during packet encoding.
- * Default is {@code true}
- *
- * @param preferDirectBuffer {@code true} if a direct buffer should be tried to be used as target for
- * the encoded messages. If {@code false} is used it will allocate a heap
- * buffer, which is backed by an byte array.
- */
- public void setPreferDirectBuffer(boolean preferDirectBuffer) {
- this.preferDirectBuffer = preferDirectBuffer;
- }
- public boolean isPreferDirectBuffer() {
- return preferDirectBuffer;
- }
-
- /**
- * Data store - used to store session data and implements distributed pubsub.
- * Default is {@code MemoryStoreFactory}
- *
- * @param clientStoreFactory - implements StoreFactory
- *
- * @see MemoryStoreFactory
- * @see RedissonStoreFactory
- */
- public void setStoreFactory(StoreFactory clientStoreFactory) {
- this.storeFactory = clientStoreFactory;
- }
- public StoreFactory getStoreFactory() {
- return storeFactory;
- }
-
- /**
- * Authorization listener invoked on every handshake.
- * Accepts or denies a client by {@code AuthorizationListener.isAuthorized} method.
- * Accepts all clients by default.
- *
- * @param authorizationListener - authorization listener itself
- *
- * @see AuthorizationListener
- */
- public void setAuthorizationListener(AuthorizationListener authorizationListener) {
- this.authorizationListener = authorizationListener;
- }
- public AuthorizationListener getAuthorizationListener() {
- return authorizationListener;
- }
-
- /**
- * Exception listener invoked on any exception in
- * SocketIO listener
- *
- * @param exceptionListener - listener
- *
- * @see ExceptionListener
- */
- public void setExceptionListener(ExceptionListener exceptionListener) {
- this.exceptionListener = exceptionListener;
- }
- public ExceptionListener getExceptionListener() {
- return exceptionListener;
- }
-
- public SocketConfig getSocketConfig() {
- return socketConfig;
- }
- /**
- * TCP socket configuration
- *
- * @param socketConfig - config
- */
- public void setSocketConfig(SocketConfig socketConfig) {
- this.socketConfig = socketConfig;
- }
-
- /**
- * Auto ack-response mode
- * Default is {@code AckMode.AUTO_SUCCESS_ONLY}
- *
- * @see AckMode
- *
- * @param ackMode - ack mode
- */
- public void setAckMode(AckMode ackMode) {
- this.ackMode = ackMode;
- }
- public AckMode getAckMode() {
- return ackMode;
- }
-
-
- public String getTrustStoreFormat() {
- return trustStoreFormat;
- }
- public void setTrustStoreFormat(String trustStoreFormat) {
- this.trustStoreFormat = trustStoreFormat;
- }
-
- public InputStream getTrustStore() {
- return trustStore;
- }
- public void setTrustStore(InputStream trustStore) {
- this.trustStore = trustStore;
- }
-
- public String getTrustStorePassword() {
- return trustStorePassword;
- }
- public void setTrustStorePassword(String trustStorePassword) {
- this.trustStorePassword = trustStorePassword;
- }
-
- public String getKeyManagerFactoryAlgorithm() {
- return keyManagerFactoryAlgorithm;
- }
- public void setKeyManagerFactoryAlgorithm(String keyManagerFactoryAlgorithm) {
- this.keyManagerFactoryAlgorithm = keyManagerFactoryAlgorithm;
- }
-
-
- /**
- * Set maximum websocket frame content length limit
- *
- * @param maxFramePayloadLength - length
- */
- public void setMaxFramePayloadLength(int maxFramePayloadLength) {
- this.maxFramePayloadLength = maxFramePayloadLength;
- }
- public int getMaxFramePayloadLength() {
- return maxFramePayloadLength;
- }
-
- /**
- * Transport upgrade timeout in milliseconds
- *
- * @param upgradeTimeout - upgrade timeout
- */
- public void setUpgradeTimeout(int upgradeTimeout) {
- this.upgradeTimeout = upgradeTimeout;
- }
- public int getUpgradeTimeout() {
- return upgradeTimeout;
- }
-
- /**
- * Adds Server header with lib version to http response.
- *
- * Default is true
- *
- * @param addVersionHeader - true
to add header
- */
- public void setAddVersionHeader(boolean addVersionHeader) {
- this.addVersionHeader = addVersionHeader;
- }
- public boolean isAddVersionHeader() {
- return addVersionHeader;
- }
-
- /**
- * Set Access-Control-Allow-Origin header value for http each
- * response.
- * Default is null
- *
- * If value is null
then request ORIGIN header value used.
- *
- * @param origin - origin
- */
- public void setOrigin(String origin) {
- this.origin = origin;
- }
- public String getOrigin() {
- return origin;
- }
-
- public boolean isUseLinuxNativeEpoll() {
- return useLinuxNativeEpoll;
- }
- public void setUseLinuxNativeEpoll(boolean useLinuxNativeEpoll) {
- this.useLinuxNativeEpoll = useLinuxNativeEpoll;
- }
-
- /**
- * Set the name of the requested SSL protocol
- *
- * @param sslProtocol - name of protocol
- */
- public void setSSLProtocol(String sslProtocol) {
- this.sslProtocol = sslProtocol;
- }
- public String getSSLProtocol() {
- return sslProtocol;
- }
-
- /**
- * Timeout between channel opening and first data transfer
- * Helps to avoid 'silent channel' attack and prevents
- * 'Too many open files' problem in this case
- *
- * @param firstDataTimeout - timeout value
- */
- public void setFirstDataTimeout(int firstDataTimeout) {
- this.firstDataTimeout = firstDataTimeout;
- }
- public int getFirstDataTimeout() {
- return firstDataTimeout;
- }
-
- /**
- * Activate http protocol compression. Uses {@code gzip} or
- * {@code deflate} encoding choice depends on the {@code "Accept-Encoding"} header value.
- *
- * Default is true
- *
- * @param httpCompression - true
to use http compression
- */
- public void setHttpCompression(boolean httpCompression) {
- this.httpCompression = httpCompression;
- }
- public boolean isHttpCompression() {
- return httpCompression;
- }
-
- /**
- * Activate websocket protocol compression.
- * Uses {@code permessage-deflate} encoding only.
- *
- * Default is true
- *
- * @param websocketCompression - true
to use websocket compression
- */
- public void setWebsocketCompression(boolean websocketCompression) {
- this.websocketCompression = websocketCompression;
- }
- public boolean isWebsocketCompression() {
- return websocketCompression;
- }
-
- public boolean isRandomSession() {
- return randomSession;
- }
-
- public void setRandomSession(boolean randomSession) {
- this.randomSession = randomSession;
- }
-
- public String getAccessControlAllowHeaders() {
- return accessControlAllowHeaders;
- }
-
- public void setAccessControlAllowHeaders(String accessControlAllowHeaders) {
- this.accessControlAllowHeaders = accessControlAllowHeaders;
- }
-
- public List getConnectInterceptors() {
- return connectInterceptors;
- }
-
- public void setConnectInterceptors(Interceptor[] connectInterceptors) {
- this.connectInterceptors = Arrays.asList(connectInterceptors);
- }
-
- public List getDisconnectInterceptors() {
- return disconnectInterceptors;
- }
-
- public void setDisconnectInterceptors(Interceptor[] disconnectInterceptors) {
- this.disconnectInterceptors = Arrays.asList(disconnectInterceptors);
- }
-
- public List getEventInterceptors() {
- return eventInterceptors;
- }
-
- public void setEventInterceptors(EventInterceptor[] eventInterceptors) {
- this.eventInterceptors = Arrays.asList(eventInterceptors);
- }
-
- public String[] getNettyProtocols() {
- return nettyProtocols;
- }
-
- public void setNettyProtocols(String[] nettyProtocols) {
- this.nettyProtocols = nettyProtocols;
- }
-
- public String[] getNettyCiphers() {
- return nettyCiphers;
- }
-
- public void setNettyCiphers(String[] nettyCiphers) {
- this.nettyCiphers = nettyCiphers;
- }
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/Disconnectable.java b/fine-socketio/src/main/java/com/fr/third/socketio/Disconnectable.java
deleted file mode 100644
index 644c18e2b..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/Disconnectable.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import com.fr.third.socketio.handler.ClientHead;
-
-
-
-public interface Disconnectable {
-
- void onDisconnect(ClientHead client);
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/DisconnectableHub.java b/fine-socketio/src/main/java/com/fr/third/socketio/DisconnectableHub.java
deleted file mode 100644
index 2fe1acb2a..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/DisconnectableHub.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-public interface DisconnectableHub extends Disconnectable {
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/HandshakeData.java b/fine-socketio/src/main/java/com/fr/third/socketio/HandshakeData.java
deleted file mode 100644
index 48a87e9f5..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/HandshakeData.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import java.io.Serializable;
-import java.net.InetSocketAddress;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import io.netty.handler.codec.http.HttpHeaders;
-
-public class HandshakeData implements Serializable {
-
- private static final long serialVersionUID = 1196350300161819978L;
-
- private HttpHeaders headers;
- private InetSocketAddress address;
- private Date time = new Date();
- private InetSocketAddress local;
- private String url;
- private Map> urlParams;
- private boolean xdomain;
-
- // needed for correct deserialization
- public HandshakeData() {
- }
-
- public HandshakeData(HttpHeaders headers, Map> urlParams, InetSocketAddress address, String url, boolean xdomain) {
- this(headers, urlParams, address, null, url, xdomain);
- }
-
- public HandshakeData(HttpHeaders headers, Map> urlParams, InetSocketAddress address, InetSocketAddress local, String url, boolean xdomain) {
- super();
- this.headers = headers;
- this.urlParams = urlParams;
- this.address = address;
- this.local = local;
- this.url = url;
- this.xdomain = xdomain;
- }
-
- /**
- * Client network address
- *
- * @return network address
- */
- public InetSocketAddress getAddress() {
- return address;
- }
-
- /**
- * Connection local address
- *
- * @return local address
- */
- public InetSocketAddress getLocal() {
- return local;
- }
-
- /**
- * Http headers sent during first client request
- *
- * @return headers
- */
- public HttpHeaders getHttpHeaders() {
- return headers;
- }
-
- /**
- * Client connection date
- *
- * @return date
- */
- public Date getTime() {
- return time;
- }
-
- /**
- * Url used by client during first request
- *
- * @return url
- */
- public String getUrl() {
- return url;
- }
-
- public boolean isXdomain() {
- return xdomain;
- }
-
- /**
- * Url params stored in url used by client during first request
- *
- * @return map
- */
- public Map> getUrlParams() {
- return urlParams;
- }
-
- public String getSingleUrlParam(String name) {
- List values = urlParams.get(name);
- if (values != null && values.size() == 1) {
- return values.iterator().next();
- }
- return null;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/JsonSupportWrapper.java b/fine-socketio/src/main/java/com/fr/third/socketio/JsonSupportWrapper.java
deleted file mode 100644
index ff9c8509b..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/JsonSupportWrapper.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import io.netty.buffer.ByteBufInputStream;
-import io.netty.buffer.ByteBufOutputStream;
-
-import java.io.IOException;
-import java.util.List;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.protocol.AckArgs;
-import com.fr.third.socketio.protocol.JsonSupport;
-
-class JsonSupportWrapper implements JsonSupport {
-
- private static final Logger log = LoggerFactory.getLogger(JsonSupportWrapper.class);
-
- private final JsonSupport delegate;
-
- JsonSupportWrapper(JsonSupport delegate) {
- this.delegate = delegate;
- }
-
- @Override
- public AckArgs readAckArgs(ByteBufInputStream src, AckCallback> callback) throws IOException {
- try {
- return delegate.readAckArgs(src, callback);
- } catch (Exception e) {
- src.reset();
- log.error("Can't read ack args: " + src.readLine() + " for type: " + callback.getResultClass(), e);
- throw new IOException(e);
- }
- }
-
- @Override
- public T readValue(String namespaceName, ByteBufInputStream src, Class valueType) throws IOException {
- try {
- return delegate.readValue(namespaceName, src, valueType);
- } catch (Exception e) {
- src.reset();
- log.error("Can't read value: " + src.readLine() + " for type: " + valueType, e);
- throw new IOException(e);
- }
- }
-
- @Override
- public void writeValue(ByteBufOutputStream out, Object value) throws IOException {
- try {
- delegate.writeValue(out, value);
- } catch (Exception e) {
- log.error("Can't write value: " + value, e);
- throw new IOException(e);
- }
- }
-
- @Override
- public void addEventMapping(String namespaceName, String eventName, Class> ... eventClass) {
- delegate.addEventMapping(namespaceName, eventName, eventClass);
- }
-
- @Override
- public void removeEventMapping(String namespaceName, String eventName) {
- delegate.removeEventMapping(namespaceName, eventName);
- }
-
- @Override
- public List getArrays() {
- return delegate.getArrays();
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/MultiRoomBroadcastOperations.java b/fine-socketio/src/main/java/com/fr/third/socketio/MultiRoomBroadcastOperations.java
deleted file mode 100644
index f31e73c09..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/MultiRoomBroadcastOperations.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import com.fr.third.socketio.protocol.Packet;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * author: liangjiaqi
- * date: 2020/8/8 6:02 PM
- */
-public class MultiRoomBroadcastOperations implements BroadcastOperations {
-
- private Collection broadcastOperations;
-
- public MultiRoomBroadcastOperations(Collection broadcastOperations) {
- this.broadcastOperations = broadcastOperations;
- }
-
- @Override
- public Collection getClients() {
- Set clients = new HashSet();
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return clients;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- clients.addAll( b.getClients() );
- }
- return clients;
- }
-
- @Override
- public void send(Packet packet, BroadcastAckCallback ackCallback) {
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- b.send( packet, ackCallback );
- }
- }
-
- @Override
- public void sendEvent(String name, SocketIOClient excludedClient, Object... data) {
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- b.sendEvent( name, excludedClient, data );
- }
- }
-
- @Override
- public void sendEvent(String name, Object data, BroadcastAckCallback ackCallback) {
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- b.sendEvent( name, data, ackCallback );
- }
- }
-
- @Override
- public void sendEvent(String name, Object data, SocketIOClient excludedClient, BroadcastAckCallback ackCallback) {
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- b.sendEvent( name, data, excludedClient, ackCallback );
- }
- }
-
- @Override
- public void send(Packet packet) {
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- b.send( packet );
- }
- }
-
- @Override
- public void disconnect() {
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- b.disconnect();
- }
- }
-
- @Override
- public void sendEvent(String name, Object... data) {
- if( this.broadcastOperations == null || this.broadcastOperations.size() == 0 ) {
- return;
- }
- for( BroadcastOperations b : this.broadcastOperations ) {
- b.sendEvent( name, data );
- }
- }
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/MultiTypeAckCallback.java b/fine-socketio/src/main/java/com/fr/third/socketio/MultiTypeAckCallback.java
deleted file mode 100644
index 975a2f7b2..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/MultiTypeAckCallback.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-/**
- * Multi type ack callback used in case of multiple ack arguments
- *
- */
-public abstract class MultiTypeAckCallback extends AckCallback {
-
- private Class>[] resultClasses;
-
- public MultiTypeAckCallback(Class> ... resultClasses) {
- super(MultiTypeArgs.class);
- this.resultClasses = resultClasses;
- }
-
- public Class>[] getResultClasses() {
- return resultClasses;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/MultiTypeArgs.java b/fine-socketio/src/main/java/com/fr/third/socketio/MultiTypeArgs.java
deleted file mode 100644
index 591b33c85..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/MultiTypeArgs.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import java.util.Iterator;
-import java.util.List;
-
-public class MultiTypeArgs implements Iterable {
-
- private final List args;
-
- public MultiTypeArgs(List args) {
- super();
- this.args = args;
- }
-
- public boolean isEmpty() {
- return size() == 0;
- }
-
- public int size() {
- return args.size();
- }
-
- public List getArgs() {
- return args;
- }
-
- public T first() {
- return get(0);
- }
-
- public T second() {
- return get(1);
- }
-
- /**
- * "index out of bounds"-safe method for getting elements
- *
- * @param type of argument
- * @param index to get
- * @return argument
- */
- public T get(int index) {
- if (size() <= index) {
- return null;
- }
- return (T) args.get(index);
- }
-
- @Override
- public Iterator iterator() {
- return args.iterator();
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/SingleRoomBroadcastOperations.java b/fine-socketio/src/main/java/com/fr/third/socketio/SingleRoomBroadcastOperations.java
deleted file mode 100644
index 317458e2f..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/SingleRoomBroadcastOperations.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import com.fr.third.socketio.misc.IterableCollection;
-import com.fr.third.socketio.protocol.Packet;
-import com.fr.third.socketio.protocol.PacketType;
-import com.fr.third.socketio.store.StoreFactory;
-import com.fr.third.socketio.store.pubsub.DispatchMessage;
-import com.fr.third.socketio.store.pubsub.PubSubType;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-/**
- * Author: liangjiaqi
- * Date: 2020/8/8 6:08 PM
- */
-public class SingleRoomBroadcastOperations implements BroadcastOperations {
- private final String namespace;
- private final String room;
- private final Iterable clients;
- private final StoreFactory storeFactory;
-
- public SingleRoomBroadcastOperations(String namespace, String room, Iterable clients, StoreFactory storeFactory) {
- super();
- this.namespace = namespace;
- this.room = room;
- this.clients = clients;
- this.storeFactory = storeFactory;
- }
-
- private void dispatch(Packet packet) {
- this.storeFactory.pubSubStore().publish(
- PubSubType.DISPATCH,
- new DispatchMessage(this.room, packet, this.namespace));
- }
-
- @Override
- public Collection getClients() {
- return new IterableCollection(clients);
- }
-
- @Override
- public void send(Packet packet) {
- for (SocketIOClient client : clients) {
- client.send(packet);
- }
- dispatch(packet);
- }
-
- @Override
- public void send(Packet packet, BroadcastAckCallback ackCallback) {
- for (SocketIOClient client : clients) {
- client.send(packet, ackCallback.createClientCallback(client));
- }
- ackCallback.loopFinished();
- }
-
- @Override
- public void disconnect() {
- for (SocketIOClient client : clients) {
- client.disconnect();
- }
- }
-
- @Override
- public void sendEvent(String name, SocketIOClient excludedClient, Object... data) {
- Packet packet = new Packet(PacketType.MESSAGE);
- packet.setSubType(PacketType.EVENT);
- packet.setName(name);
- packet.setData(Arrays.asList(data));
-
- for (SocketIOClient client : clients) {
- if (client.getSessionId().equals(excludedClient.getSessionId())) {
- continue;
- }
- client.send(packet);
- }
- dispatch(packet);
- }
-
- @Override
- public void sendEvent(String name, Object... data) {
- Packet packet = new Packet(PacketType.MESSAGE);
- packet.setSubType(PacketType.EVENT);
- packet.setName(name);
- packet.setData(Arrays.asList(data));
- send(packet);
- }
-
- @Override
- public void sendEvent(String name, Object data, BroadcastAckCallback ackCallback) {
- for (SocketIOClient client : clients) {
- client.sendEvent(name, ackCallback.createClientCallback(client), data);
- }
- ackCallback.loopFinished();
- }
-
- @Override
- public void sendEvent(String name, Object data, SocketIOClient excludedClient, BroadcastAckCallback ackCallback) {
- for (SocketIOClient client : clients) {
- if (client.getSessionId().equals(excludedClient.getSessionId())) {
- continue;
- }
- client.sendEvent(name, ackCallback.createClientCallback(client), data);
- }
- ackCallback.loopFinished();
- }
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/SocketConfig.java b/fine-socketio/src/main/java/com/fr/third/socketio/SocketConfig.java
deleted file mode 100644
index a1ea9f5a7..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/SocketConfig.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-/**
- * TCP socket configuration contains configuration for main server channel
- * and client channels
- *
- * @see java.net.SocketOptions
- */
-public class SocketConfig {
-
- private boolean tcpNoDelay = true;
-
- private int tcpSendBufferSize = -1;
-
- private int tcpReceiveBufferSize = -1;
-
- private boolean tcpKeepAlive = false;
-
- private int soLinger = -1;
-
- private boolean reuseAddress = false;
-
- private int acceptBackLog = 1024;
-
- public boolean isTcpNoDelay() {
- return tcpNoDelay;
- }
- public void setTcpNoDelay(boolean tcpNoDelay) {
- this.tcpNoDelay = tcpNoDelay;
- }
-
- public int getTcpSendBufferSize() {
- return tcpSendBufferSize;
- }
- public void setTcpSendBufferSize(int tcpSendBufferSize) {
- this.tcpSendBufferSize = tcpSendBufferSize;
- }
-
- public int getTcpReceiveBufferSize() {
- return tcpReceiveBufferSize;
- }
- public void setTcpReceiveBufferSize(int tcpReceiveBufferSize) {
- this.tcpReceiveBufferSize = tcpReceiveBufferSize;
- }
-
- public boolean isTcpKeepAlive() {
- return tcpKeepAlive;
- }
- public void setTcpKeepAlive(boolean tcpKeepAlive) {
- this.tcpKeepAlive = tcpKeepAlive;
- }
-
- public int getSoLinger() {
- return soLinger;
- }
- public void setSoLinger(int soLinger) {
- this.soLinger = soLinger;
- }
-
- public boolean isReuseAddress() {
- return reuseAddress;
- }
- public void setReuseAddress(boolean reuseAddress) {
- this.reuseAddress = reuseAddress;
- }
-
- public int getAcceptBackLog() {
- return acceptBackLog;
- }
- public void setAcceptBackLog(int acceptBackLog) {
- this.acceptBackLog = acceptBackLog;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOChannelInitializer.java b/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOChannelInitializer.java
deleted file mode 100644
index 0ea37272d..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOChannelInitializer.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import java.security.KeyStore;
-
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.TrustManagerFactory;
-
-import com.fr.stable.ArrayUtils;
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.ack.AckManager;
-import com.fr.third.socketio.handler.AuthorizeHandler;
-import com.fr.third.socketio.handler.ClientHead;
-import com.fr.third.socketio.handler.ClientsBox;
-import com.fr.third.socketio.handler.EncoderHandler;
-import com.fr.third.socketio.handler.InPacketHandler;
-import com.fr.third.socketio.handler.PacketListener;
-import com.fr.third.socketio.handler.WrongUrlHandler;
-import com.fr.third.socketio.namespace.NamespacesHub;
-import com.fr.third.socketio.protocol.JsonSupport;
-import com.fr.third.socketio.protocol.PacketDecoder;
-import com.fr.third.socketio.protocol.PacketEncoder;
-import com.fr.third.socketio.scheduler.CancelableScheduler;
-import com.fr.third.socketio.scheduler.HashedWheelTimeoutScheduler;
-import com.fr.third.socketio.store.StoreFactory;
-import com.fr.third.socketio.store.pubsub.DisconnectMessage;
-import com.fr.third.socketio.store.pubsub.PubSubType;
-import com.fr.third.socketio.transport.PollingTransport;
-import com.fr.third.socketio.transport.WebSocketTransport;
-
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.ChannelPipeline;
-import io.netty.handler.codec.http.HttpContentCompressor;
-import io.netty.handler.codec.http.HttpMessage;
-import io.netty.handler.codec.http.HttpObjectAggregator;
-import io.netty.handler.codec.http.HttpRequestDecoder;
-import io.netty.handler.codec.http.HttpResponseEncoder;
-import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
-import io.netty.handler.ssl.SslHandler;
-
-public class SocketIOChannelInitializer extends ChannelInitializer implements DisconnectableHub {
-
- public static final String SOCKETIO_ENCODER = "socketioEncoder";
- public static final String WEB_SOCKET_TRANSPORT_COMPRESSION = "webSocketTransportCompression";
- public static final String WEB_SOCKET_TRANSPORT = "webSocketTransport";
- public static final String WEB_SOCKET_AGGREGATOR = "webSocketAggregator";
- public static final String XHR_POLLING_TRANSPORT = "xhrPollingTransport";
- public static final String AUTHORIZE_HANDLER = "authorizeHandler";
- public static final String PACKET_HANDLER = "packetHandler";
- public static final String HTTP_ENCODER = "httpEncoder";
- public static final String HTTP_COMPRESSION = "httpCompression";
- public static final String HTTP_AGGREGATOR = "httpAggregator";
- public static final String HTTP_REQUEST_DECODER = "httpDecoder";
- public static final String SSL_HANDLER = "ssl";
-
- public static final String RESOURCE_HANDLER = "resourceHandler";
- public static final String WRONG_URL_HANDLER = "wrongUrlBlocker";
-
- private static final Logger log = LoggerFactory.getLogger(SocketIOChannelInitializer.class);
-
- private AckManager ackManager;
-
- private ClientsBox clientsBox = new ClientsBox();
- private AuthorizeHandler authorizeHandler;
- private PollingTransport xhrPollingTransport;
- private WebSocketTransport webSocketTransport;
- private WebSocketServerCompressionHandler webSocketTransportCompression = new WebSocketServerCompressionHandler();
- private EncoderHandler encoderHandler;
- private WrongUrlHandler wrongUrlHandler;
-
- private CancelableScheduler scheduler = new HashedWheelTimeoutScheduler();
-
- private InPacketHandler packetHandler;
- private SSLContext sslContext;
- private Configuration configuration;
-
- @Override
- public void handlerAdded(ChannelHandlerContext ctx) {
- scheduler.update(ctx);
- }
-
- public void start(Configuration configuration, NamespacesHub namespacesHub) {
- this.configuration = configuration;
-
- ackManager = new AckManager(scheduler);
-
- JsonSupport jsonSupport = configuration.getJsonSupport();
- PacketEncoder encoder = new PacketEncoder(configuration, jsonSupport);
- PacketDecoder decoder = new PacketDecoder(jsonSupport, ackManager);
-
- String connectPath = configuration.getContext() + "/";
-
- boolean isSsl = configuration.getKeyStore() != null;
- if (isSsl) {
- try {
- sslContext = createSSLContext(configuration);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
- }
-
- StoreFactory factory = configuration.getStoreFactory();
- authorizeHandler = new AuthorizeHandler(connectPath, scheduler, configuration, namespacesHub, factory, this, ackManager, clientsBox);
- factory.init(namespacesHub, authorizeHandler, jsonSupport);
- xhrPollingTransport = new PollingTransport(decoder, authorizeHandler, clientsBox);
- webSocketTransport = new WebSocketTransport(isSsl, authorizeHandler, configuration, scheduler, clientsBox);
-
- PacketListener packetListener = new PacketListener(ackManager, namespacesHub, xhrPollingTransport, scheduler);
-
-
- packetHandler = new InPacketHandler(packetListener, decoder, namespacesHub, configuration.getExceptionListener());
-
- try {
- encoderHandler = new EncoderHandler(configuration, encoder);
- } catch (Exception e) {
- throw new IllegalStateException(e);
- }
-
- wrongUrlHandler = new WrongUrlHandler();
- }
-
- @Override
- protected void initChannel(Channel ch) throws Exception {
- ChannelPipeline pipeline = ch.pipeline();
- addSslHandler(pipeline);
- addSocketioHandlers(pipeline);
- }
-
- /**
- * Adds the ssl handler
- *
- * @param pipeline - channel pipeline
- */
- protected void addSslHandler(ChannelPipeline pipeline) {
- if (sslContext != null) {
- SSLEngine engine = sslContext.createSSLEngine();
- engine.setUseClientMode(false);
-
- if (ArrayUtils.isNotEmpty(configuration.getNettyProtocols())) {
- engine.setEnabledProtocols(configuration.getNettyProtocols());
- }
-
- if (ArrayUtils.isNotEmpty(configuration.getNettyCiphers())) {
- engine.setEnabledCipherSuites(configuration.getNettyCiphers());
- }
-
- pipeline.addLast(SSL_HANDLER, new SslHandler(engine));
- }
- }
-
- /**
- * Adds the socketio channel handlers
- *
- * @param pipeline - channel pipeline
- */
- protected void addSocketioHandlers(ChannelPipeline pipeline) {
- pipeline.addLast(HTTP_REQUEST_DECODER, new HttpRequestDecoder());
- pipeline.addLast(HTTP_AGGREGATOR, new HttpObjectAggregator(configuration.getMaxHttpContentLength()) {
- @Override
- protected Object newContinueResponse(HttpMessage start, int maxContentLength,
- ChannelPipeline pipeline) {
- return null;
- }
-
- });
- pipeline.addLast(HTTP_ENCODER, new HttpResponseEncoder());
-
- if (configuration.isHttpCompression()) {
- pipeline.addLast(HTTP_COMPRESSION, new HttpContentCompressor());
- }
-
- pipeline.addLast(PACKET_HANDLER, packetHandler);
-
- pipeline.addLast(AUTHORIZE_HANDLER, authorizeHandler);
- pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport);
- // TODO use single instance when https://github.com/netty/netty/issues/4755 will be resolved
- if (configuration.isWebsocketCompression()) {
- pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler());
- }
- pipeline.addLast(WEB_SOCKET_TRANSPORT, webSocketTransport);
-
- pipeline.addLast(SOCKETIO_ENCODER, encoderHandler);
-
- pipeline.addLast(WRONG_URL_HANDLER, wrongUrlHandler);
- }
-
- private SSLContext createSSLContext(Configuration configuration) throws Exception {
- TrustManager[] managers = null;
- if (configuration.getTrustStore() != null) {
- KeyStore ts = KeyStore.getInstance(configuration.getTrustStoreFormat());
- ts.load(configuration.getTrustStore(), configuration.getTrustStorePassword().toCharArray());
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(ts);
- managers = tmf.getTrustManagers();
- }
-
- KeyStore ks = KeyStore.getInstance(configuration.getKeyStoreFormat());
- ks.load(configuration.getKeyStore(), configuration.getKeyStorePassword().toCharArray());
-
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(configuration.getKeyManagerFactoryAlgorithm());
- kmf.init(ks, configuration.getKeyStorePassword().toCharArray());
-
- SSLContext serverContext = SSLContext.getInstance(configuration.getSSLProtocol());
- serverContext.init(kmf.getKeyManagers(), managers, null);
- return serverContext;
- }
-
- @Override
- public void onDisconnect(ClientHead client) {
- ackManager.onDisconnect(client);
- authorizeHandler.onDisconnect(client);
- configuration.getStoreFactory().onDisconnect(client);
-
- configuration.getStoreFactory().pubSubStore().publish(PubSubType.DISCONNECT, new DisconnectMessage(client.getSessionId()));
-
- log.debug("Client with sessionId: {} disconnected", client.getSessionId());
- }
-
- public void stop() {
- StoreFactory factory = configuration.getStoreFactory();
- factory.shutdown();
- scheduler.shutdown();
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOClient.java b/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOClient.java
deleted file mode 100644
index a56d2ffe0..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOClient.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import java.net.SocketAddress;
-import java.util.Set;
-import java.util.UUID;
-
-import com.fr.third.socketio.protocol.Packet;
-import com.fr.third.socketio.store.Store;
-
-
-/**
- * Fully thread-safe.
- *
- */
-public interface SocketIOClient extends ClientOperations, Store {
-
- /**
- * Handshake data used during client connection
- *
- * @return HandshakeData
- */
- HandshakeData getHandshakeData();
-
- /**
- * Current client transport protocol
- *
- * @return transport protocol
- */
- Transport getTransport();
-
- /**
- * Send event with ack callback
- *
- * @param name - event name
- * @param data - event data
- * @param ackCallback - ack callback
- */
- void sendEvent(String name, AckCallback> ackCallback, Object ... data);
-
- /**
- * Send packet with ack callback
- *
- * @param packet - packet to send
- * @param ackCallback - ack callback
- */
- void send(Packet packet, AckCallback> ackCallback);
-
- /**
- * Client namespace
- *
- * @return - namespace
- */
- SocketIONamespace getNamespace();
-
- /**
- * Client session id, uses {@link UUID} object
- *
- * @return - session id
- */
- UUID getSessionId();
-
- /**
- * Get client remote address
- *
- * @return remote address
- */
- SocketAddress getRemoteAddress();
-
- /**
- * Check is underlying channel open
- *
- * @return true
if channel open, otherwise false
- */
- boolean isChannelOpen();
-
- /**
- * Join client to room
- *
- * @param room - name of room
- */
- void joinRoom(String room);
-
- /**
- * Join client to room
- *
- * @param room - name of room
- */
- void leaveRoom(String room);
-
- /**
- * Get all rooms a client is joined in.
- *
- * @return name of rooms
- */
- Set getAllRooms();
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIONamespace.java b/fine-socketio/src/main/java/com/fr/third/socketio/SocketIONamespace.java
deleted file mode 100644
index 892331fcc..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIONamespace.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import java.util.Collection;
-import java.util.UUID;
-
-import com.fr.third.socketio.listener.ClientListeners;
-
-/**
- * Fully thread-safe.
- *
- */
-public interface SocketIONamespace extends ClientListeners {
-
- String getName();
-
- BroadcastOperations getBroadcastOperations();
-
- BroadcastOperations getRoomOperations(String room);
-
- /**
- * Get all clients connected to namespace
- *
- * @return collection of clients
- */
- Collection getAllClients();
-
- /**
- * Get client by uuid connected to namespace
- *
- * @param uuid - id of client
- * @return client
- */
- SocketIOClient getClient(UUID uuid);
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOServer.java b/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOServer.java
deleted file mode 100644
index 5c5128b72..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/SocketIOServer.java
+++ /dev/null
@@ -1,307 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import com.fr.third.socketio.listener.*;
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.ChannelOption;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.FixedRecvByteBufAllocator;
-import io.netty.channel.ServerChannel;
-import io.netty.channel.epoll.EpollEventLoopGroup;
-import io.netty.channel.epoll.EpollServerSocketChannel;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.FutureListener;
-
-import java.net.InetSocketAddress;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
-
-import io.netty.util.concurrent.GenericFutureListener;
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.namespace.Namespace;
-import com.fr.third.socketio.namespace.NamespacesHub;
-
-/**
- * Fully thread-safe.
- *
- */
-public class SocketIOServer implements ClientListeners {
-
- private static final Logger log = LoggerFactory.getLogger(SocketIOServer.class);
-
- private final Configuration configCopy;
- private final Configuration configuration;
-
- private final NamespacesHub namespacesHub;
- private final SocketIONamespace mainNamespace;
-
- private SocketIOChannelInitializer pipelineFactory = new SocketIOChannelInitializer();
-
- private EventLoopGroup bossGroup;
- private EventLoopGroup workerGroup;
-
- public SocketIOServer(Configuration configuration) {
- this.configuration = configuration;
- this.configCopy = new Configuration(configuration);
- namespacesHub = new NamespacesHub(configCopy);
- mainNamespace = addNamespace(Namespace.DEFAULT_NAME);
- }
-
- public void setPipelineFactory(SocketIOChannelInitializer pipelineFactory) {
- this.pipelineFactory = pipelineFactory;
- }
-
- /**
- * Get all clients connected to default namespace
- *
- * @return clients collection
- */
- public Collection getAllClients() {
- return namespacesHub.get(Namespace.DEFAULT_NAME).getAllClients();
- }
-
- /**
- * Get client by uuid from default namespace
- *
- * @param uuid - id of client
- * @return client
- */
- public SocketIOClient getClient(UUID uuid) {
- return namespacesHub.get(Namespace.DEFAULT_NAME).getClient(uuid);
- }
-
- /**
- * Get all namespaces
- *
- * @return namespaces collection
- */
- public Collection getAllNamespaces() {
- return namespacesHub.getAllNamespaces();
- }
-
- public BroadcastOperations getBroadcastOperations() {
- Collection namespaces = namespacesHub.getAllNamespaces();
- List list = new ArrayList();
- BroadcastOperations broadcast = null;
- if( namespaces != null && namespaces.size() > 0 ) {
- for( SocketIONamespace n : namespaces ) {
- broadcast = n.getBroadcastOperations();
- list.add( broadcast );
- }
- }
- return new MultiRoomBroadcastOperations( list );
- }
-
- /**
- * Get broadcast operations for clients within
- * room by room
name
- *
- * @param room - name of room
- * @return broadcast operations
- */
- public BroadcastOperations getRoomOperations(String room) {
- Collection namespaces = namespacesHub.getAllNamespaces();
- List list = new ArrayList();
- BroadcastOperations broadcast = null;
- if( namespaces != null && namespaces.size() > 0 ) {
- for( SocketIONamespace n : namespaces ) {
- broadcast = n.getRoomOperations( room );
- list.add( broadcast );
- }
- }
- return new MultiRoomBroadcastOperations( list );
- }
-
- /**
- * Start server
- */
- public void start() {
- startAsync().syncUninterruptibly();
- }
-
- public void start(GenericFutureListener extends Future super Void>> listener) {
- startAsync(listener).syncUninterruptibly();
- }
-
- /**
- * Start server asynchronously
- *
- * @return void
- */
- public Future startAsync() {
- return startAsync(new FutureListener() {
-
- @Override
- public void operationComplete(Future future) throws Exception {
-
- if (future.isSuccess()) {
- log.info("SocketIO server started at port: {}", configCopy.getPort());
- } else {
- log.error("SocketIO server start failed at port: {}!", configCopy.getPort());
- }
- }
- });
- }
-
- /**
- * Start server asynchronously
- *
- * @return void
- */
- public Future startAsync(GenericFutureListener extends Future super Void>> listener) {
-
- log.info("Session store / pubsub factory used: {}", configCopy.getStoreFactory());
- initGroups();
-
- pipelineFactory.start(configCopy, namespacesHub);
-
- Class extends ServerChannel> channelClass = NioServerSocketChannel.class;
- if (configCopy.isUseLinuxNativeEpoll()) {
- channelClass = EpollServerSocketChannel.class;
- }
-
- ServerBootstrap b = new ServerBootstrap();
- b.group(bossGroup, workerGroup)
- .channel(channelClass)
- .childHandler(pipelineFactory);
- applyConnectionOptions(b);
-
- InetSocketAddress addr = new InetSocketAddress(configCopy.getPort());
- if (configCopy.getHostname() != null) {
- addr = new InetSocketAddress(configCopy.getHostname(), configCopy.getPort());
- }
-
- return b.bind(addr).addListener(listener);
- }
-
- protected void applyConnectionOptions(ServerBootstrap bootstrap) {
- SocketConfig config = configCopy.getSocketConfig();
- bootstrap.childOption(ChannelOption.TCP_NODELAY, config.isTcpNoDelay());
- if (config.getTcpSendBufferSize() != -1) {
- bootstrap.childOption(ChannelOption.SO_SNDBUF, config.getTcpSendBufferSize());
- }
- if (config.getTcpReceiveBufferSize() != -1) {
- bootstrap.childOption(ChannelOption.SO_RCVBUF, config.getTcpReceiveBufferSize());
- bootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(config.getTcpReceiveBufferSize()));
- }
- bootstrap.childOption(ChannelOption.SO_KEEPALIVE, config.isTcpKeepAlive());
- bootstrap.childOption(ChannelOption.SO_LINGER, config.getSoLinger());
-
- bootstrap.option(ChannelOption.SO_REUSEADDR, config.isReuseAddress());
- bootstrap.option(ChannelOption.SO_BACKLOG, config.getAcceptBackLog());
- }
-
- protected void initGroups() {
- if (configCopy.isUseLinuxNativeEpoll()) {
- bossGroup = new EpollEventLoopGroup(configCopy.getBossThreads());
- workerGroup = new EpollEventLoopGroup(configCopy.getWorkerThreads());
- } else {
- bossGroup = new NioEventLoopGroup(configCopy.getBossThreads());
- workerGroup = new NioEventLoopGroup(configCopy.getWorkerThreads());
- }
- }
-
- /**
- * Stop server
- */
- public void stop() {
- bossGroup.shutdownGracefully().syncUninterruptibly();
- workerGroup.shutdownGracefully().syncUninterruptibly();
-
- pipelineFactory.stop();
- log.info("SocketIO server stopped");
- }
-
- public void stopImmediately() {
- this.bossGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly();
- this.workerGroup.shutdownGracefully(0L, 1L, TimeUnit.SECONDS).syncUninterruptibly();
- this.pipelineFactory.stop();
- log.info("SocketIO server stopped");
- }
-
- public SocketIONamespace addNamespace(String name) {
- return namespacesHub.create(name);
- }
-
- public SocketIONamespace getNamespace(String name) {
- return namespacesHub.get(name);
- }
-
- public void removeNamespace(String name) {
- namespacesHub.remove(name);
- }
-
- /**
- * Allows to get configuration provided
- * during server creation. Further changes on
- * this object not affect server.
- *
- * @return Configuration object
- */
- public Configuration getConfiguration() {
- return configuration;
- }
-
- @Override
- public void addMultiTypeEventListener(String eventName, MultiTypeEventListener listener, Class>... eventClass) {
- mainNamespace.addMultiTypeEventListener(eventName, listener, eventClass);
- }
-
- @Override
- public void addEventListener(String eventName, Class eventClass, DataListener listener) {
- mainNamespace.addEventListener(eventName, eventClass, listener);
- }
-
- @Override
- public void removeAllListeners(String eventName) {
- mainNamespace.removeAllListeners(eventName);
- }
-
- @Override
- public void addDisconnectListener(DisconnectListener listener) {
- mainNamespace.addDisconnectListener(listener);
- }
-
- @Override
- public void addConnectListener(ConnectListener listener) {
- mainNamespace.addConnectListener(listener);
- }
-
- @Override
- public void addPingListener(PingListener listener) {
- mainNamespace.addPingListener(listener);
- }
-
- @Override
- public void addListeners(Object listeners) {
- mainNamespace.addListeners(listeners);
- }
-
- @Override
- public void addListeners(Object listeners, Class> listenersClass) {
- mainNamespace.addListeners(listeners, listenersClass);
- }
-
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/Transport.java b/fine-socketio/src/main/java/com/fr/third/socketio/Transport.java
deleted file mode 100644
index a2dc635a0..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/Transport.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-import com.fr.third.socketio.transport.WebSocketTransport;
-import com.fr.third.socketio.transport.PollingTransport;
-
-public enum Transport {
-
- WEBSOCKET(WebSocketTransport.NAME),
- POLLING(PollingTransport.NAME);
-
- private final String value;
-
- Transport(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- public static Transport byName(String value) {
- for (Transport t : Transport.values()) {
- if (t.getValue().equals(value)) {
- return t;
- }
- }
- throw new IllegalArgumentException("Can't find " + value + " transport");
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/VoidAckCallback.java b/fine-socketio/src/main/java/com/fr/third/socketio/VoidAckCallback.java
deleted file mode 100644
index de5e30589..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/VoidAckCallback.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio;
-
-/**
- * Base ack callback with {@link Void} class as type.
- *
- */
-public abstract class VoidAckCallback extends AckCallback {
-
- public VoidAckCallback() {
- super(Void.class);
- }
-
- public VoidAckCallback(int timeout) {
- super(Void.class, timeout);
- }
-
- @Override
- public final void onSuccess(Void result) {
- onSuccess();
- }
-
- protected abstract void onSuccess();
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/ack/AckManager.java b/fine-socketio/src/main/java/com/fr/third/socketio/ack/AckManager.java
deleted file mode 100644
index 40aa49bda..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/ack/AckManager.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.ack;
-
-import com.fr.third.socketio.*;
-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 io.netty.util.internal.PlatformDependent;
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
-public class AckManager implements Disconnectable {
-
- class AckEntry {
-
- final Map> ackCallbacks = PlatformDependent.newConcurrentHashMap();
- final AtomicLong ackIndex = new AtomicLong(-1);
-
- public long addAckCallback(AckCallback> callback) {
- long index = ackIndex.incrementAndGet();
- ackCallbacks.put(index, callback);
- return index;
- }
-
- public Set getAckIndexes() {
- return ackCallbacks.keySet();
- }
-
- public AckCallback> getAckCallback(long index) {
- return ackCallbacks.get(index);
- }
-
- public AckCallback> removeCallback(long index) {
- return ackCallbacks.remove(index);
- }
-
- public void initAckIndex(long index) {
- ackIndex.compareAndSet(-1, index);
- }
-
- }
-
- private static final Logger log = LoggerFactory.getLogger(AckManager.class);
-
- private final ConcurrentMap ackEntries = PlatformDependent.newConcurrentHashMap();
-
- private final CancelableScheduler scheduler;
-
- public AckManager(CancelableScheduler scheduler) {
- super();
- this.scheduler = scheduler;
- }
-
- public void initAckIndex(UUID sessionId, long index) {
- AckEntry ackEntry = getAckEntry(sessionId);
- ackEntry.initAckIndex(index);
- }
-
- private AckEntry getAckEntry(UUID sessionId) {
- AckEntry ackEntry = ackEntries.get(sessionId);
- if (ackEntry == null) {
- ackEntry = new AckEntry();
- AckEntry oldAckEntry = ackEntries.putIfAbsent(sessionId, ackEntry);
- if (oldAckEntry != null) {
- ackEntry = oldAckEntry;
- }
- }
- return ackEntry;
- }
-
- @SuppressWarnings("unchecked")
- public void onAck(SocketIOClient client, Packet packet) {
- AckSchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, client.getSessionId(), packet.getAckId());
- scheduler.cancel(key);
-
- AckCallback callback = removeCallback(client.getSessionId(), packet.getAckId());
- if (callback == null) {
- return;
- }
- if (callback instanceof MultiTypeAckCallback) {
- callback.onSuccess(new MultiTypeArgs(packet.>getData()));
- } else {
- Object param = null;
- List args = packet.getData();
- if (!args.isEmpty()) {
- param = args.get(0);
- }
- if (args.size() > 1) {
- log.error("Wrong ack args amount. Should be only one argument, but current amount is: {}. Ack id: {}, sessionId: {}",
- args.size(), packet.getAckId(), client.getSessionId());
- }
- callback.onSuccess(param);
- }
- }
-
- private AckCallback> removeCallback(UUID sessionId, long index) {
- AckEntry ackEntry = ackEntries.get(sessionId);
- // may be null if client disconnected
- // before timeout occurs
- if (ackEntry != null) {
- return ackEntry.removeCallback(index);
- }
- return null;
- }
-
- public AckCallback> getCallback(UUID sessionId, long index) {
- AckEntry ackEntry = getAckEntry(sessionId);
- return ackEntry.getAckCallback(index);
- }
-
- public long registerAck(UUID sessionId, AckCallback> callback) {
- AckEntry ackEntry = getAckEntry(sessionId);
- ackEntry.initAckIndex(0);
- long index = ackEntry.addAckCallback(callback);
-
- if (log.isDebugEnabled()) {
- log.debug("AckCallback registered with id: {} for client: {}", index, sessionId);
- }
-
- scheduleTimeout(index, sessionId, callback);
-
- return index;
- }
-
- private void scheduleTimeout(final long index, final UUID sessionId, AckCallback> callback) {
- if (callback.getTimeout() == -1) {
- return;
- }
- SchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, sessionId, index);
- scheduler.scheduleCallback(key, new Runnable() {
- @Override
- public void run() {
- AckCallback> cb = removeCallback(sessionId, index);
- if (cb != null) {
- cb.onTimeout();
- }
- }
- }, callback.getTimeout(), TimeUnit.SECONDS);
- }
-
- @Override
- public void onDisconnect(ClientHead client) {
- AckEntry e = ackEntries.remove(client.getSessionId());
- if (e == null) {
- return;
- }
-
- Set indexes = e.getAckIndexes();
- for (Long index : indexes) {
- AckCallback> callback = e.getAckCallback(index);
- if (callback != null) {
- callback.onTimeout();
- }
- SchedulerKey key = new AckSchedulerKey(Type.ACK_TIMEOUT, client.getSessionId(), index);
- scheduler.cancel(key);
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/ack/AckSchedulerKey.java b/fine-socketio/src/main/java/com/fr/third/socketio/ack/AckSchedulerKey.java
deleted file mode 100644
index 5cc8ddb6b..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/ack/AckSchedulerKey.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.ack;
-
-import java.util.UUID;
-
-import com.fr.third.socketio.scheduler.SchedulerKey;
-
-public class AckSchedulerKey extends SchedulerKey {
-
- private final long index;
-
- public AckSchedulerKey(Type type, UUID sessionId, long index) {
- super(type, sessionId);
- this.index = index;
- }
-
- public long getIndex() {
- return index;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + (int) (index ^ (index >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (!super.equals(obj))
- return false;
- if (getClass() != obj.getClass())
- return false;
- AckSchedulerKey other = (AckSchedulerKey) obj;
- if (index != other.index)
- return false;
- return true;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/AnnotationScanner.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/AnnotationScanner.java
deleted file mode 100644
index 9110a24a7..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/AnnotationScanner.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-import com.fr.third.socketio.namespace.Namespace;
-
-public interface AnnotationScanner {
-
- Class extends Annotation> getScanAnnotation();
-
- void addListener(Namespace namespace, Object object, Method method, Annotation annotation);
-
- void validate(Method method, Class> clazz);
-
-}
\ No newline at end of file
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnConnect.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnConnect.java
deleted file mode 100644
index fcbb357f1..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnConnect.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-
-/**
- * Annotation that defines Connect handler.
- *
- * Arguments in method:
- *
- * - SocketIOClient (required)
- *
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface OnConnect {
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnConnectScanner.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnConnectScanner.java
deleted file mode 100644
index 3c9bcf1f4..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnConnectScanner.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import com.fr.third.socketio.SocketIOClient;
-import com.fr.third.socketio.handler.SocketIOException;
-import com.fr.third.socketio.listener.ConnectListener;
-import com.fr.third.socketio.namespace.Namespace;
-
-public class OnConnectScanner implements AnnotationScanner {
-
- @Override
- public Class extends Annotation> getScanAnnotation() {
- return OnConnect.class;
- }
-
- @Override
- public void addListener(Namespace namespace, final Object object, final Method method, Annotation annotation) {
- namespace.addConnectListener(new ConnectListener() {
- @Override
- public void onConnect(SocketIOClient client) {
- try {
- method.invoke(object, client);
- } catch (InvocationTargetException e) {
- throw new SocketIOException(e.getCause());
- } catch (Exception e) {
- throw new SocketIOException(e);
- }
- }
- });
- }
-
- @Override
- public void validate(Method method, Class> clazz) {
- if (method.getParameterTypes().length != 1) {
- throw new IllegalArgumentException("Wrong OnConnect listener signature: " + clazz + "." + method.getName());
- }
- boolean valid = false;
- for (Class> eventType : method.getParameterTypes()) {
- if (eventType.equals(SocketIOClient.class)) {
- valid = true;
- }
- }
- if (!valid) {
- throw new IllegalArgumentException("Wrong OnConnect listener signature: " + clazz + "." + method.getName());
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnDisconnect.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnDisconnect.java
deleted file mode 100644
index 0a26baa90..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnDisconnect.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation that defines Disconnect handler.
- *
- * Arguments in method:
- *
- * - SocketIOClient (required)
- *
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface OnDisconnect {
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnDisconnectScanner.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnDisconnectScanner.java
deleted file mode 100644
index 378bf49ba..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnDisconnectScanner.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import com.fr.third.socketio.SocketIOClient;
-import com.fr.third.socketio.handler.SocketIOException;
-import com.fr.third.socketio.listener.DisconnectListener;
-import com.fr.third.socketio.namespace.Namespace;
-
-public class OnDisconnectScanner implements AnnotationScanner {
-
- @Override
- public Class extends Annotation> getScanAnnotation() {
- return OnDisconnect.class;
- }
-
- @Override
- public void addListener(Namespace namespace, final Object object, final Method method, Annotation annotation) {
- namespace.addDisconnectListener(new DisconnectListener() {
- @Override
- public void onDisconnect(SocketIOClient client) {
- try {
- method.invoke(object, client);
- } catch (InvocationTargetException e) {
- throw new SocketIOException(e.getCause());
- } catch (Exception e) {
- throw new SocketIOException(e);
- }
- }
- });
- }
-
- @Override
- public void validate(Method method, Class> clazz) {
- if (method.getParameterTypes().length != 1) {
- throw new IllegalArgumentException("Wrong OnDisconnect listener signature: " + clazz + "." + method.getName());
- }
- boolean valid = false;
- for (Class> eventType : method.getParameterTypes()) {
- if (eventType.equals(SocketIOClient.class)) {
- valid = true;
- }
- }
- if (!valid) {
- throw new IllegalArgumentException("Wrong OnDisconnect listener signature: " + clazz + "." + method.getName());
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnEvent.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnEvent.java
deleted file mode 100644
index e245132e7..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnEvent.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Annotation that defines Event handler.
- * The value is required, and represents event name.
- *
- * Arguments in method:
- *
- * - SocketIOClient (optional)
- * - AckRequest (optional)
- * - Event data (optional)
- *
- */
-@Target(ElementType.METHOD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface OnEvent {
-
- /**
- * Event name
- *
- * @return value
- */
- String value();
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnEventScanner.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnEventScanner.java
deleted file mode 100644
index 1f682fc14..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/OnEventScanner.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fr.third.socketio.AckRequest;
-import com.fr.third.socketio.MultiTypeArgs;
-import com.fr.third.socketio.SocketIOClient;
-import com.fr.third.socketio.handler.SocketIOException;
-import com.fr.third.socketio.listener.DataListener;
-import com.fr.third.socketio.listener.MultiTypeEventListener;
-import com.fr.third.socketio.namespace.Namespace;
-
-public class OnEventScanner implements AnnotationScanner {
-
- @Override
- public Class extends Annotation> getScanAnnotation() {
- return OnEvent.class;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public void addListener(Namespace namespace, final Object object, final Method method, Annotation annot) {
- OnEvent annotation = (OnEvent) annot;
- if (annotation.value() == null || annotation.value().trim().length() == 0) {
- throw new IllegalArgumentException("OnEvent \"value\" parameter is required");
- }
- final int socketIOClientIndex = paramIndex(method, SocketIOClient.class);
- final int ackRequestIndex = paramIndex(method, AckRequest.class);
- final List dataIndexes = dataIndexes(method);
-
- if (dataIndexes.size() > 1) {
- List> classes = new ArrayList>();
- for (int index : dataIndexes) {
- Class> param = method.getParameterTypes()[index];
- classes.add(param);
- }
-
- namespace.addMultiTypeEventListener(annotation.value(), new MultiTypeEventListener() {
- @Override
- public void onData(SocketIOClient client, MultiTypeArgs data, AckRequest ackSender) {
- try {
- Object[] args = new Object[method.getParameterTypes().length];
- if (socketIOClientIndex != -1) {
- args[socketIOClientIndex] = client;
- }
- if (ackRequestIndex != -1) {
- args[ackRequestIndex] = ackSender;
- }
- int i = 0;
- for (int index : dataIndexes) {
- args[index] = data.get(i);
- i++;
- }
- method.invoke(object, args);
- } catch (InvocationTargetException e) {
- throw new SocketIOException(e.getCause());
- } catch (Exception e) {
- throw new SocketIOException(e);
- }
- }
- }, classes.toArray(new Class[classes.size()]));
- } else {
- Class objectType = Void.class;
- if (!dataIndexes.isEmpty()) {
- objectType = method.getParameterTypes()[dataIndexes.iterator().next()];
- }
-
- namespace.addEventListener(annotation.value(), objectType, new DataListener() {
- @Override
- public void onData(SocketIOClient client, Object data, AckRequest ackSender) {
- try {
- Object[] args = new Object[method.getParameterTypes().length];
- if (socketIOClientIndex != -1) {
- args[socketIOClientIndex] = client;
- }
- if (ackRequestIndex != -1) {
- args[ackRequestIndex] = ackSender;
- }
- if (!dataIndexes.isEmpty()) {
- int dataIndex = dataIndexes.iterator().next();
- args[dataIndex] = data;
- }
- method.invoke(object, args);
- } catch (InvocationTargetException e) {
- throw new SocketIOException(e.getCause());
- } catch (Exception e) {
- throw new SocketIOException(e);
- }
- }
- });
- }
- }
-
- private List dataIndexes(Method method) {
- List result = new ArrayList();
- int index = 0;
- for (Class> type : method.getParameterTypes()) {
- if (!type.equals(AckRequest.class) && !type.equals(SocketIOClient.class)) {
- result.add(index);
- }
- index++;
- }
- return result;
- }
-
- private int paramIndex(Method method, Class> clazz) {
- int index = 0;
- for (Class> type : method.getParameterTypes()) {
- if (type.equals(clazz)) {
- return index;
- }
- index++;
- }
- return -1;
- }
-
- @Override
- public void validate(Method method, Class> clazz) {
- int paramsCount = method.getParameterTypes().length;
- final int socketIOClientIndex = paramIndex(method, SocketIOClient.class);
- final int ackRequestIndex = paramIndex(method, AckRequest.class);
- List dataIndexes = dataIndexes(method);
- paramsCount -= dataIndexes.size();
- if (socketIOClientIndex != -1) {
- paramsCount--;
- }
- if (ackRequestIndex != -1) {
- paramsCount--;
- }
- if (paramsCount != 0) {
- throw new IllegalArgumentException("Wrong OnEvent listener signature: " + clazz + "." + method.getName());
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/ScannerEngine.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/ScannerEngine.java
deleted file mode 100644
index 796f8017e..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/ScannerEngine.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.List;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.namespace.Namespace;
-
-public class ScannerEngine {
-
- private static final Logger log = LoggerFactory.getLogger(ScannerEngine.class);
-
- private static final List extends AnnotationScanner> annotations =
- Arrays.asList(new OnConnectScanner(), new OnDisconnectScanner(), new OnEventScanner());
-
- private Method findSimilarMethod(Class> objectClazz, Method method) {
- Method[] methods = objectClazz.getDeclaredMethods();
- for (Method m : methods) {
- if (isEquals(m, method)) {
- return m;
- }
- }
- return null;
- }
-
- public void scan(Namespace namespace, Object object, Class> clazz)
- throws IllegalArgumentException {
- Method[] methods = clazz.getDeclaredMethods();
-
- if (!clazz.isAssignableFrom(object.getClass())) {
- for (Method method : methods) {
- for (AnnotationScanner annotationScanner : annotations) {
- Annotation ann = method.getAnnotation(annotationScanner.getScanAnnotation());
- if (ann != null) {
- annotationScanner.validate(method, clazz);
-
- Method m = findSimilarMethod(object.getClass(), method);
- if (m != null) {
- annotationScanner.addListener(namespace, object, m, ann);
- } else {
- log.warn("Method similar to " + method.getName() + " can't be found in " + object.getClass());
- }
- }
- }
- }
- } else {
- for (Method method : methods) {
- for (AnnotationScanner annotationScanner : annotations) {
- Annotation ann = method.getAnnotation(annotationScanner.getScanAnnotation());
- if (ann != null) {
- annotationScanner.validate(method, clazz);
- makeAccessible(method);
- annotationScanner.addListener(namespace, object, method, ann);
- }
- }
- }
-
- if (clazz.getSuperclass() != null) {
- scan(namespace, object, clazz.getSuperclass());
- } else if (clazz.isInterface()) {
- for (Class> superIfc : clazz.getInterfaces()) {
- scan(namespace, object, superIfc);
- }
- }
- }
-
- }
-
- private boolean isEquals(Method method1, Method method2) {
- if (!method1.getName().equals(method2.getName())
- || !method1.getReturnType().equals(method2.getReturnType())) {
- return false;
- }
-
- return Arrays.equals(method1.getParameterTypes(), method2.getParameterTypes());
- }
-
- private void makeAccessible(Method method) {
- if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
- && !method.isAccessible()) {
- method.setAccessible(true);
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/SpringAnnotationScanner.java b/fine-socketio/src/main/java/com/fr/third/socketio/annotation/SpringAnnotationScanner.java
deleted file mode 100644
index 7a2916c87..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/annotation/SpringAnnotationScanner.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.annotation;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-import com.fr.third.springframework.beans.BeansException;
-import com.fr.third.springframework.beans.factory.config.BeanPostProcessor;
-import com.fr.third.springframework.util.ReflectionUtils;
-import com.fr.third.springframework.util.ReflectionUtils.MethodCallback;
-import com.fr.third.springframework.util.ReflectionUtils.MethodFilter;
-
-import com.fr.third.socketio.SocketIOServer;
-
-public class SpringAnnotationScanner implements BeanPostProcessor {
-
- private static final Logger log = LoggerFactory.getLogger(SpringAnnotationScanner.class);
-
- private final List> annotations =
- Arrays.asList(OnConnect.class, OnDisconnect.class, OnEvent.class);
-
- private final SocketIOServer socketIOServer;
-
- private Class originalBeanClass;
-
- public SpringAnnotationScanner(SocketIOServer socketIOServer) {
- super();
- this.socketIOServer = socketIOServer;
- }
-
- @Override
- public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
- if (originalBeanClass != null) {
- socketIOServer.addListeners(bean, originalBeanClass);
- log.info("{} bean listeners added", beanName);
- originalBeanClass = null;
- }
- return bean;
- }
-
- @Override
- public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
- final AtomicBoolean add = new AtomicBoolean();
- ReflectionUtils.doWithMethods(bean.getClass(),
- new MethodCallback() {
- @Override
- public void doWith(Method method) throws IllegalArgumentException,
- IllegalAccessException {
- add.set(true);
- }
- },
- new MethodFilter() {
- @Override
- public boolean matches(Method method) {
- for (Class extends Annotation> annotationClass : annotations) {
- if (method.isAnnotationPresent(annotationClass)) {
- return true;
- }
- }
- return false;
- }
- });
-
- if (add.get()) {
- originalBeanClass = bean.getClass();
- }
- return bean;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/AuthorizeHandler.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/AuthorizeHandler.java
deleted file mode 100644
index 634f7ae45..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/AuthorizeHandler.java
+++ /dev/null
@@ -1,272 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.Configuration;
-import com.fr.third.socketio.Disconnectable;
-import com.fr.third.socketio.DisconnectableHub;
-import com.fr.third.socketio.HandshakeData;
-import com.fr.third.socketio.SocketIOClient;
-import com.fr.third.socketio.Transport;
-import com.fr.third.socketio.ack.AckManager;
-import com.fr.third.socketio.messages.HttpErrorMessage;
-import com.fr.third.socketio.namespace.Namespace;
-import com.fr.third.socketio.namespace.NamespacesHub;
-import com.fr.third.socketio.protocol.AuthPacket;
-import com.fr.third.socketio.protocol.Packet;
-import com.fr.third.socketio.protocol.PacketType;
-import com.fr.third.socketio.scheduler.CancelableScheduler;
-import com.fr.third.socketio.scheduler.SchedulerKey;
-import com.fr.third.socketio.scheduler.SchedulerKey.Type;
-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.ChannelFutureListener;
-import io.netty.channel.ChannelHandler.Sharable;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.handler.codec.http.DefaultHttpResponse;
-import io.netty.handler.codec.http.FullHttpRequest;
-import io.netty.handler.codec.http.HttpHeaderNames;
-import io.netty.handler.codec.http.HttpHeaders;
-import io.netty.handler.codec.http.HttpResponse;
-import io.netty.handler.codec.http.HttpResponseStatus;
-import io.netty.handler.codec.http.QueryStringDecoder;
-import io.netty.handler.codec.http.cookie.Cookie;
-import io.netty.handler.codec.http.cookie.ServerCookieDecoder;
-
-@Sharable
-public class AuthorizeHandler extends ChannelInboundHandlerAdapter implements Disconnectable {
-
- private static final Logger log = LoggerFactory.getLogger(AuthorizeHandler.class);
-
- private final CancelableScheduler disconnectScheduler;
-
- private final String connectPath;
- private final Configuration configuration;
- private final NamespacesHub namespacesHub;
- private final StoreFactory storeFactory;
- private final DisconnectableHub disconnectable;
- private final AckManager ackManager;
- private final ClientsBox clientsBox;
-
- public AuthorizeHandler(String connectPath, CancelableScheduler scheduler, Configuration configuration, NamespacesHub namespacesHub, StoreFactory storeFactory,
- DisconnectableHub disconnectable, AckManager ackManager, ClientsBox clientsBox) {
- super();
- this.connectPath = connectPath;
- this.configuration = configuration;
- this.disconnectScheduler = scheduler;
- this.namespacesHub = namespacesHub;
- this.storeFactory = storeFactory;
- this.disconnectable = disconnectable;
- this.ackManager = ackManager;
- this.clientsBox = clientsBox;
- }
-
- @Override
- public void channelActive(final ChannelHandlerContext ctx) throws Exception {
- SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel());
- disconnectScheduler.schedule(key, new Runnable() {
- @Override
- public void run() {
- ctx.channel().close();
- log.debug("Client with ip {} opened channel but doesn't send any data! Channel closed!", ctx.channel().remoteAddress());
- }
- }, configuration.getFirstDataTimeout(), TimeUnit.MILLISECONDS);
- super.channelActive(ctx);
- }
-
- @Override
- public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
- SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, ctx.channel());
- disconnectScheduler.cancel(key);
-
- if (msg instanceof FullHttpRequest) {
- FullHttpRequest req = (FullHttpRequest) msg;
- Channel channel = ctx.channel();
- QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
-
- if (!configuration.isAllowCustomRequests()
- && !queryDecoder.path().startsWith(connectPath)) {
- HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
- channel.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
- req.release();
- return;
- }
-
- List sid = queryDecoder.parameters().get("sid");
- if (queryDecoder.path().equals(connectPath)
- && sid == null) {
- String origin = req.headers().get(HttpHeaderNames.ORIGIN);
- if (!authorize(ctx, channel, origin, queryDecoder.parameters(), req)) {
- req.release();
- return;
- }
- // forward message to polling or websocket handler to bind channel
- }
- }
- ctx.fireChannelRead(msg);
- }
-
- private boolean authorize(ChannelHandlerContext ctx, Channel channel, String origin, Map> params, FullHttpRequest req)
- throws IOException {
- Map> headers = new HashMap>(req.headers().names().size());
- for (String name : req.headers().names()) {
- List values = req.headers().getAll(name);
- headers.put(name, values);
- }
-
- HandshakeData data = new HandshakeData(req.headers(), params,
- (InetSocketAddress)channel.remoteAddress(),
- (InetSocketAddress)channel.localAddress(),
- req.uri(), origin != null && !origin.equalsIgnoreCase("null"));
-
- boolean result = false;
- try {
- result = configuration.getAuthorizationListener().isAuthorized(data);
- } catch (Exception e) {
- log.error("Authorization error", e);
- }
-
- if (!result) {
- HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
- channel.writeAndFlush(res)
- .addListener(ChannelFutureListener.CLOSE);
- log.debug("Handshake unauthorized, query params: {} headers: {}", params, headers);
- return false;
- }
-
- UUID sessionId = null;
- if (configuration.isRandomSession()) {
- sessionId = UUID.randomUUID();
- } else {
- sessionId = this.generateOrGetSessionIdFromRequest(req.headers());
- }
-
- List transportValue = params.get("transport");
- if (transportValue == null) {
- log.error("Got no transports for request {}", req.uri());
-
- HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
- channel.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
- return false;
- }
-
- Transport transport = Transport.byName(transportValue.get(0));
- if (!configuration.getTransports().contains(transport)) {
- Map errorData = new HashMap();
- errorData.put("code", 0);
- errorData.put("message", "Transport unknown");
-
- channel.attr(EncoderHandler.ORIGIN).set(origin);
- channel.writeAndFlush(new HttpErrorMessage(errorData));
- return false;
- }
-
- ClientHead client = new ClientHead(sessionId, ackManager, disconnectable, storeFactory, data, clientsBox, transport, disconnectScheduler, configuration);
- channel.attr(ClientHead.CLIENT).set(client);
- clientsBox.addClient(client);
-
- String[] transports = {};
- if (configuration.getTransports().contains(Transport.WEBSOCKET)) {
- transports = new String[]{"websocket"};
- }
-
- AuthPacket authPacket = new AuthPacket(sessionId, transports, configuration.getPingInterval(),
- configuration.getPingTimeout());
- Packet packet = new Packet(PacketType.OPEN);
- packet.setData(authPacket);
- client.send(packet);
-
- client.schedulePingTimeout();
- log.debug("Handshake authorized for sessionId: {}, query params: {} headers: {}", sessionId, params, headers);
- return true;
- }
-
- /**
- * This method will either generate a new random sessionId or will retrieve the value stored
- * in the "io" cookie. Failures to parse will cause a logging warning to be generated and a
- * random uuid to be generated instead (same as not passing a cookie in the first place).
- */
- private UUID generateOrGetSessionIdFromRequest(HttpHeaders headers) {
- List values = headers.getAll("io");
- if (values.size() == 1) {
- try {
- return UUID.fromString(values.get(0));
- } catch (IllegalArgumentException iaex) {
- log.warn("Malformed UUID received for session! io=" + values.get(0));
- }
- }
-
- for (String cookieHeader : headers.getAll(HttpHeaderNames.COOKIE)) {
- Set cookies = ServerCookieDecoder.LAX.decode(cookieHeader);
-
- for (Cookie cookie : cookies) {
- if (cookie.name().equals("io")) {
- try {
- return UUID.fromString(cookie.value());
- } catch (IllegalArgumentException iaex) {
- log.warn("Malformed UUID received for session! io=" + cookie.value());
- }
- }
- }
- }
-
- return UUID.randomUUID();
- }
-
- public void connect(UUID sessionId) {
- SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
- disconnectScheduler.cancel(key);
- }
-
- public void connect(ClientHead client) {
- Namespace ns = namespacesHub.get(Namespace.DEFAULT_NAME);
-
- if (!client.getNamespaces().contains(ns)) {
- Packet packet = new Packet(PacketType.MESSAGE);
- packet.setSubType(PacketType.CONNECT);
- client.send(packet);
-
- configuration.getStoreFactory().pubSubStore().publish(PubSubType.CONNECT, new ConnectMessage(client.getSessionId()));
-
- SocketIOClient nsClient = client.addNamespaceClient(ns);
- ns.onConnect(nsClient);
- }
- }
-
- @Override
- public void onDisconnect(ClientHead client) {
- clientsBox.removeClient(client.getSessionId());
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/ClientHead.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/ClientHead.java
deleted file mode 100644
index 285274a3b..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/ClientHead.java
+++ /dev/null
@@ -1,298 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import com.fr.third.socketio.Configuration;
-import com.fr.third.socketio.DisconnectableHub;
-import com.fr.third.socketio.HandshakeData;
-import com.fr.third.socketio.Transport;
-import com.fr.third.socketio.ack.AckManager;
-import com.fr.third.socketio.messages.OutPacketMessage;
-import com.fr.third.socketio.namespace.Namespace;
-import com.fr.third.socketio.protocol.Packet;
-import com.fr.third.socketio.protocol.PacketType;
-import com.fr.third.socketio.scheduler.CancelableScheduler;
-import com.fr.third.socketio.scheduler.SchedulerKey;
-import com.fr.third.socketio.scheduler.SchedulerKey.Type;
-import com.fr.third.socketio.store.Store;
-import com.fr.third.socketio.store.StoreFactory;
-import com.fr.third.socketio.transport.NamespaceClient;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
-import io.netty.handler.codec.http.HttpHeaderNames;
-import io.netty.util.AttributeKey;
-import io.netty.util.internal.PlatformDependent;
-import com.fr.third.slf4j.Logger;
-import com.fr.third.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 {
-
- private static final Logger log = LoggerFactory.getLogger(ClientHead.class);
-
- public static final AttributeKey CLIENT = AttributeKey.valueOf("client");
-
- private final AtomicBoolean disconnected = new AtomicBoolean();
- private final Map namespaceClients = PlatformDependent.newConcurrentHashMap();
- private final Map channels = new HashMap(2);
- private final HandshakeData handshakeData;
- private final UUID sessionId;
-
- private final Store store;
- private final DisconnectableHub disconnectableHub;
- private final AckManager ackManager;
- private ClientsBox clientsBox;
- private final CancelableScheduler disconnectScheduler;
- private final Configuration configuration;
-
- private Packet lastBinaryPacket;
-
- // TODO use lazy set
- private volatile Transport currentTransport;
-
- public ClientHead(UUID sessionId, AckManager ackManager, DisconnectableHub disconnectable,
- StoreFactory storeFactory, HandshakeData handshakeData, ClientsBox clientsBox, Transport transport, CancelableScheduler disconnectScheduler,
- Configuration configuration) {
- this.sessionId = sessionId;
- this.ackManager = ackManager;
- this.disconnectableHub = disconnectable;
- this.store = storeFactory.createStore(sessionId);
- this.handshakeData = handshakeData;
- this.clientsBox = clientsBox;
- this.currentTransport = transport;
- this.disconnectScheduler = disconnectScheduler;
- this.configuration = configuration;
-
- channels.put(Transport.POLLING, new TransportState());
- channels.put(Transport.WEBSOCKET, new TransportState());
- }
-
-
- /**
- * 这里多线程下,会有问题,
- * 因为 channel 不会变, 但是 state 可能因为多线程下调用 bindChannel
- * 从而导致 state.update , 致使真正 add() 时,
- * channel 和 state 得数据不一致。
- *
- * 解决方法
- * 1. 加锁
- * 2. 为 clientbox 加一个子线程, 定时清除 disconnected 为 true 的值。
- *
- * @param channel 频道
- * @param transport 协议
- */
- public synchronized void bindChannel(Channel channel, Transport transport) {
- log.debug("binding channel: {} to transport: {}", channel, transport);
-
- TransportState state = channels.get(transport);
- Channel prevChannel = state.update(channel);
- if (prevChannel != null) {
- clientsBox.remove(prevChannel);
- prevChannel.disconnect();
- }
- clientsBox.add(channel, this);
-
- sendPackets(transport, channel);
- }
-
- public void releasePollingChannel(Channel channel) {
- TransportState state = channels.get(Transport.POLLING);
- if(channel.equals(state.getChannel())) {
- clientsBox.remove(channel);
- state.update(null);
- }
- }
-
- public String getOrigin() {
- return handshakeData.getHttpHeaders().get(HttpHeaderNames.ORIGIN);
- }
-
- public ChannelFuture send(Packet packet) {
- return send(packet, getCurrentTransport());
- }
-
- public void cancelPingTimeout() {
- SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
- disconnectScheduler.cancel(key);
- }
-
- public void schedulePingTimeout() {
- SchedulerKey key = new SchedulerKey(Type.PING_TIMEOUT, sessionId);
- disconnectScheduler.schedule(key, new TimeOutTask(this), configuration.getPingTimeout() + configuration.getPingInterval(), TimeUnit.MILLISECONDS);
- }
-
- public ChannelFuture send(Packet packet, Transport transport) {
- TransportState state = channels.get(transport);
- state.getPacketsQueue().add(packet);
-
- Channel channel = state.getChannel();
- if (channel == null
- || (transport == Transport.POLLING && channel.attr(EncoderHandler.WRITE_ONCE).get() != null)) {
- return null;
- }
- return sendPackets(transport, channel);
- }
-
- private ChannelFuture sendPackets(Transport transport, Channel channel) {
- return channel.writeAndFlush(new OutPacketMessage(this, transport));
- }
-
- public void removeNamespaceClient(NamespaceClient client) {
- namespaceClients.remove(client.getNamespace());
-
- // 清空到最后一个的时候, 断开连接。 调用 initializer.disconnect
- if (namespaceClients.isEmpty()) {
- disconnectableHub.onDisconnect(this);
- }
- }
-
- public NamespaceClient getChildClient(Namespace namespace) {
- return namespaceClients.get(namespace);
- }
-
- public NamespaceClient addNamespaceClient(Namespace namespace) {
- NamespaceClient client = new NamespaceClient(this, namespace);
- namespaceClients.put(namespace, client);
- return client;
- }
-
- public Set getNamespaces() {
- return namespaceClients.keySet();
- }
-
- public boolean isConnected() {
- return !disconnected.get();
- }
-
- public void onChannelDisconnect() {
- cancelPingTimeout();
-
- disconnected.set(true);
- for (NamespaceClient client : namespaceClients.values()) {
- client.onDisconnect();
- }
- for (TransportState state : channels.values()) {
- if (state.getChannel() != null) {
- clientsBox.remove(state.getChannel());
- }
- }
- }
-
- public HandshakeData getHandshakeData() {
- return handshakeData;
- }
-
- public AckManager getAckManager() {
- return ackManager;
- }
-
- public UUID getSessionId() {
- return sessionId;
- }
-
- public SocketAddress getRemoteAddress() {
- return handshakeData.getAddress();
- }
-
- public void disconnect() {
- ChannelFuture future = send(new Packet(PacketType.DISCONNECT));
- if(future != null) {
- future.addListener(ChannelFutureListener.CLOSE);
- }
-
- onChannelDisconnect();
- }
-
- public boolean isChannelOpen() {
- for (TransportState state : channels.values()) {
- if (state.getChannel() != null
- && state.getChannel().isActive()) {
- return true;
- }
- }
- return false;
- }
-
- public Store getStore() {
- return store;
- }
-
- public boolean isTransportChannel(Channel channel, Transport transport) {
- TransportState state = channels.get(transport);
- if (state.getChannel() == null) {
- return false;
- }
- return state.getChannel().equals(channel);
- }
-
- public void upgradeCurrentTransport(Transport currentTransport) {
- TransportState state = channels.get(currentTransport);
-
- for (Entry entry : channels.entrySet()) {
- if (!entry.getKey().equals(currentTransport)) {
-
- Queue queue = entry.getValue().getPacketsQueue();
- state.setPacketsQueue(queue);
-
- sendPackets(currentTransport, state.getChannel());
- this.currentTransport = currentTransport;
- log.debug("Transport upgraded to: {} for: {}", currentTransport, sessionId);
- break;
- }
- }
- }
-
- public Transport getCurrentTransport() {
- return currentTransport;
- }
-
- public Queue getPacketsQueue(Transport transport) {
- return channels.get(transport).getPacketsQueue();
- }
-
- public void setLastBinaryPacket(Packet lastBinaryPacket) {
- this.lastBinaryPacket = lastBinaryPacket;
- }
- public Packet getLastBinaryPacket() {
- return lastBinaryPacket;
- }
-
- private class TimeOutTask implements Runnable{
-
- ClientHead client;
-
- public TimeOutTask(ClientHead client) {
-
- assert client != null;
- this.client = client;
- }
-
- @Override
- public void run() {
-
- if (client != null && !client.disconnected.get()) {
- client.disconnect();
- log.debug("{} removed due to ping timeout", client.getSessionId());
- }
- }
- }
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/ClientsBox.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/ClientsBox.java
deleted file mode 100644
index d45667fb4..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/ClientsBox.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import io.netty.channel.Channel;
-import io.netty.util.internal.PlatformDependent;
-
-import java.util.Map;
-import java.util.UUID;
-
-import com.fr.third.socketio.HandshakeData;
-
-public class ClientsBox {
-
- private final Map uuid2clients = PlatformDependent.newConcurrentHashMap();
- private final Map channel2clients = PlatformDependent.newConcurrentHashMap();
-
- // TODO use storeFactory
- public HandshakeData getHandshakeData(UUID sessionId) {
- ClientHead client = uuid2clients.get(sessionId);
- if (client == null) {
- return null;
- }
-
- return client.getHandshakeData();
- }
-
- public void addClient(ClientHead clientHead) {
- uuid2clients.put(clientHead.getSessionId(), clientHead);
- }
-
- public void removeClient(UUID sessionId) {
- uuid2clients.remove(sessionId);
- }
-
- public ClientHead get(UUID sessionId) {
- return uuid2clients.get(sessionId);
- }
-
- public void add(Channel channel, ClientHead clientHead) {
- channel2clients.put(channel, clientHead);
- }
-
- public void remove(Channel channel) {
- channel2clients.remove(channel);
- }
-
-
- public ClientHead get(Channel channel) {
- return channel2clients.get(channel);
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java
deleted file mode 100644
index 656f2ccb7..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/EncoderHandler.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import static com.fr.third.springframework.util.StringUtils.isEmpty;
-import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Queue;
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
-
-import com.fr.third.socketio.Configuration;
-import com.fr.third.socketio.Transport;
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.GenericFutureListener;
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.messages.HttpErrorMessage;
-import com.fr.third.socketio.messages.HttpMessage;
-import com.fr.third.socketio.messages.OutPacketMessage;
-import com.fr.third.socketio.messages.XHROptionsMessage;
-import com.fr.third.socketio.messages.XHRPostMessage;
-import com.fr.third.socketio.protocol.Packet;
-import com.fr.third.socketio.protocol.PacketEncoder;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.ByteBufOutputStream;
-import io.netty.buffer.ByteBufUtil;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
-import io.netty.channel.ChannelHandler.Sharable;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelOutboundHandlerAdapter;
-import io.netty.channel.ChannelPromise;
-import io.netty.handler.codec.http.DefaultHttpContent;
-import io.netty.handler.codec.http.DefaultHttpResponse;
-import io.netty.handler.codec.http.HttpHeaderNames;
-import io.netty.handler.codec.http.HttpHeaderValues;
-import io.netty.handler.codec.http.HttpResponse;
-import io.netty.handler.codec.http.HttpResponseStatus;
-import io.netty.handler.codec.http.HttpUtil;
-import io.netty.handler.codec.http.LastHttpContent;
-import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.WebSocketFrame;
-import io.netty.util.Attribute;
-import io.netty.util.AttributeKey;
-import io.netty.util.CharsetUtil;
-
-@Sharable
-public class EncoderHandler extends ChannelOutboundHandlerAdapter {
-
- private static final byte[] OK = "ok".getBytes(CharsetUtil.UTF_8);
-
- public static final AttributeKey ORIGIN = AttributeKey.valueOf("origin");
- public static final AttributeKey USER_AGENT = AttributeKey.valueOf("userAgent");
- public static final AttributeKey B64 = AttributeKey.valueOf("b64");
- public static final AttributeKey JSONP_INDEX = AttributeKey.valueOf("jsonpIndex");
- public static final AttributeKey WRITE_ONCE = AttributeKey.valueOf("writeOnce");
-
- private static final Logger log = LoggerFactory.getLogger(EncoderHandler.class);
-
- private static final String SEPARATOR_COMMA = ",";
-
- private final PacketEncoder encoder;
-
- private String version;
- private Configuration configuration;
-
- public EncoderHandler(Configuration configuration, PacketEncoder encoder) throws IOException {
- this.encoder = encoder;
- this.configuration = configuration;
-
- if (configuration.isAddVersionHeader()) {
- readVersion();
- }
- }
-
- private void readVersion() throws IOException {
- Enumeration resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
- while (resources.hasMoreElements()) {
- try {
- Manifest manifest = new Manifest(resources.nextElement().openStream());
- Attributes attrs = manifest.getMainAttributes();
- if (attrs == null) {
- continue;
- }
- String name = attrs.getValue("Bundle-Name");
- if (name != null && name.equals("netty-socketio")) {
- version = name + "/" + attrs.getValue("Bundle-Version");
- break;
- }
- } catch (IOException E) {
- // skip it
- }
- }
- }
-
- private void write(XHROptionsMessage msg, ChannelHandlerContext ctx, ChannelPromise promise) {
- HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.OK);
-
- res.headers().add(HttpHeaderNames.SET_COOKIE, "io=" + msg.getSessionId())
- .add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE)
- .add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, HttpHeaderNames.CONTENT_TYPE);
-
- String origin = ctx.channel().attr(ORIGIN).get();
- addOriginAndAllowHeaders(origin, res);
-
- ByteBuf out = encoder.allocateBuffer(ctx.alloc());
- sendMessage(msg, ctx.channel(), out, res, promise);
- }
-
- private void write(XHRPostMessage msg, ChannelHandlerContext ctx, ChannelPromise promise) {
- ByteBuf out = encoder.allocateBuffer(ctx.alloc());
- out.writeBytes(OK);
- sendMessage(msg, ctx.channel(), out, "text/html", promise, HttpResponseStatus.OK);
- }
-
- private void sendMessage(HttpMessage msg, Channel channel, ByteBuf out, String type, ChannelPromise promise, HttpResponseStatus status) {
- HttpResponse res = new DefaultHttpResponse(HTTP_1_1, status);
-
- res.headers().add(HttpHeaderNames.CONTENT_TYPE, type)
- .add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
- if (msg.getSessionId() != null) {
- res.headers().add(HttpHeaderNames.SET_COOKIE, "io=" + msg.getSessionId());
- }
-
- String origin = channel.attr(ORIGIN).get();
- addOriginAndAllowHeaders(origin, res);
-
- HttpUtil.setContentLength(res, out.readableBytes());
-
- // prevent XSS warnings on IE
- // https://github.com/LearnBoost/socket.io/pull/1333
- String userAgent = channel.attr(EncoderHandler.USER_AGENT).get();
- if (userAgent != null && (userAgent.contains(";MSIE") || userAgent.contains("Trident/"))) {
- res.headers().add("X-XSS-Protection", "0");
- }
-
- sendMessage(msg, channel, out, res, promise);
- }
-
- private void sendMessage(HttpMessage msg, Channel channel, ByteBuf out, HttpResponse res, ChannelPromise promise) {
- channel.write(res);
-
- if (log.isTraceEnabled()) {
- if (msg.getSessionId() != null) {
- log.trace("Out message: {} - sessionId: {}", out.toString(CharsetUtil.UTF_8), msg.getSessionId());
- } else {
- log.trace("Out message: {}", out.toString(CharsetUtil.UTF_8));
- }
- }
-
- if (out.isReadable()) {
- channel.write(new DefaultHttpContent(out));
- } else {
- out.release();
- }
-
- channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, promise).addListener(ChannelFutureListener.CLOSE);
- }
-
- private void sendError(HttpErrorMessage errorMsg, ChannelHandlerContext ctx, ChannelPromise promise) throws IOException {
- final ByteBuf encBuf = encoder.allocateBuffer(ctx.alloc());
- ByteBufOutputStream out = new ByteBufOutputStream(encBuf);
- encoder.getJsonSupport().writeValue(out, errorMsg.getData());
-
- sendMessage(errorMsg, ctx.channel(), encBuf, "application/json", promise, HttpResponseStatus.BAD_REQUEST);
- }
-
- private void addOriginAndAllowHeaders(String origin, HttpResponse res) {
-
- if (version != null) {
- res.headers().add(HttpHeaderNames.SERVER, version);
- }
-
- if (origin != null) {
- String configOrigin = configuration.getOrigin();
- if (!isEmpty(configOrigin) && !configOrigin.contains(origin)) {
- throw new IllegalArgumentException();
- }
- res.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, origin);
- res.headers().add(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS, Boolean.TRUE);
- }
-
- // 使websocket请求可携带特定header
- String allowHeaders = configuration.getAccessControlAllowHeaders();
- // 取出现有access-control-allow-headers,去掉空格并拼接新的header到末尾。直接addHeader时IE 10/11会找不到。
- if (!isEmpty(allowHeaders)) {
- String header = res.headers().get(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS);
- if (!isEmpty(header)) {
- header = header.trim() + SEPARATOR_COMMA + configuration.getAccessControlAllowHeaders();
- res.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, header);
- } else {
- res.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_HEADERS, configuration.getAccessControlAllowHeaders());
- }
- }
- }
-
- @Override
- public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
- if (!(msg instanceof HttpMessage)) {
- super.write(ctx, msg, promise);
- return;
- }
-
- if (msg instanceof OutPacketMessage) {
- OutPacketMessage m = (OutPacketMessage) msg;
- if (m.getTransport() == Transport.WEBSOCKET) {
- handleWebsocket((OutPacketMessage) msg, ctx, promise);
- }
- if (m.getTransport() == Transport.POLLING) {
- handleHTTP((OutPacketMessage) msg, ctx, promise);
- }
- } else if (msg instanceof XHROptionsMessage) {
- write((XHROptionsMessage) msg, ctx, promise);
- } else if (msg instanceof XHRPostMessage) {
- write((XHRPostMessage) msg, ctx, promise);
- } else if (msg instanceof HttpErrorMessage) {
- sendError((HttpErrorMessage) msg, ctx, promise);
- }
- }
-
- private void handleWebsocket(final OutPacketMessage msg, ChannelHandlerContext ctx, ChannelPromise promise) throws IOException {
- ChannelFutureList writeFutureList = new ChannelFutureList();
-
- while (true) {
- Queue queue = msg.getClientHead().getPacketsQueue(msg.getTransport());
- Packet packet = queue.poll();
- if (packet == null) {
- writeFutureList.setChannelPromise(promise);
- break;
- }
-
- final ByteBuf out = encoder.allocateBuffer(ctx.alloc());
- encoder.encodePacket(packet, out, ctx.alloc(), true);
-
- WebSocketFrame res = new TextWebSocketFrame(out);
- if (log.isTraceEnabled()) {
- log.trace("Out message: {} sessionId: {}", out.toString(CharsetUtil.UTF_8), msg.getSessionId());
- }
-
- if (out.isReadable()) {
- writeFutureList.add(ctx.channel().writeAndFlush(res));
- } else {
- out.release();
- }
-
- for (ByteBuf buf : packet.getAttachments()) {
- ByteBuf outBuf = encoder.allocateBuffer(ctx.alloc());
- outBuf.writeByte(4);
- outBuf.writeBytes(buf);
- if (log.isTraceEnabled()) {
- log.trace("Out attachment: {} sessionId: {}", ByteBufUtil.hexDump(outBuf), msg.getSessionId());
- }
- writeFutureList.add(ctx.channel().writeAndFlush(new BinaryWebSocketFrame(outBuf)));
- }
- }
- }
-
- private void handleHTTP(OutPacketMessage msg, ChannelHandlerContext ctx, ChannelPromise promise) throws IOException {
- Channel channel = ctx.channel();
- Attribute attr = channel.attr(WRITE_ONCE);
-
- Queue queue = msg.getClientHead().getPacketsQueue(msg.getTransport());
-
- if (!channel.isActive() || queue.isEmpty() || !attr.compareAndSet(null, true)) {
- promise.trySuccess();
- return;
- }
-
- ByteBuf out = encoder.allocateBuffer(ctx.alloc());
- Boolean b64 = ctx.channel().attr(EncoderHandler.B64).get();
- if (b64 != null && b64) {
- Integer jsonpIndex = ctx.channel().attr(EncoderHandler.JSONP_INDEX).get();
- encoder.encodeJsonP(jsonpIndex, queue, out, ctx.alloc(), 50);
- String type = "application/javascript";
- if (jsonpIndex == null) {
- type = "text/plain";
- }
- sendMessage(msg, channel, out, type, promise, HttpResponseStatus.OK);
- } else {
- encoder.encodePackets(queue, out, ctx.alloc(), 50);
- sendMessage(msg, channel, out, "application/octet-stream", promise, HttpResponseStatus.OK);
- }
- }
-
- /**
- * Helper class for the handleWebsocket method, handles a list of ChannelFutures and
- * sets the status of a promise when
- * - any of the operations fail
- * - all of the operations succeed
- * The setChannelPromise method should be called after all the futures are added
- */
- private class ChannelFutureList implements GenericFutureListener> {
-
- private List futureList = new ArrayList();
- private ChannelPromise promise = null;
-
- private void cleanup() {
- promise = null;
- for (ChannelFuture f : futureList) f.removeListener(this);
- }
-
- private void validate() {
- boolean allSuccess = true;
- for (ChannelFuture f : futureList) {
- if (f.isDone()) {
- if (!f.isSuccess()) {
- promise.tryFailure(f.cause());
- cleanup();
- return;
- }
- }
- else {
- allSuccess = false;
- }
- }
- if (allSuccess) {
- promise.trySuccess();
- cleanup();
- }
- }
-
- public void add(ChannelFuture f) {
- futureList.add(f);
- f.addListener(this);
- }
-
- public void setChannelPromise(ChannelPromise p) {
- promise = p;
- validate();
- }
-
- @Override
- public void operationComplete(Future voidFuture) throws Exception {
- if (promise != null) validate();
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/InPacketHandler.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/InPacketHandler.java
deleted file mode 100644
index 0ad437c87..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/InPacketHandler.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandler.Sharable;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.SimpleChannelInboundHandler;
-import io.netty.util.CharsetUtil;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.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;
-import com.fr.third.socketio.transport.NamespaceClient;
-
-@Sharable
-public class InPacketHandler extends SimpleChannelInboundHandler {
-
- private static final Logger log = LoggerFactory.getLogger(InPacketHandler.class);
-
- private final PacketListener packetListener;
- private final PacketDecoder decoder;
- private final NamespacesHub namespacesHub;
- private final ExceptionListener exceptionListener;
-
- public InPacketHandler(PacketListener packetListener, PacketDecoder decoder, NamespacesHub namespacesHub, ExceptionListener exceptionListener) {
- super();
- this.packetListener = packetListener;
- this.decoder = decoder;
- this.namespacesHub = namespacesHub;
- this.exceptionListener = exceptionListener;
- }
-
- @Override
- protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, PacketsMessage message)
- throws Exception {
- ByteBuf content = message.getContent();
- ClientHead client = message.getClient();
-
- if (log.isTraceEnabled()) {
- log.trace("In message: {} sessionId: {}", content.toString(CharsetUtil.UTF_8), client.getSessionId());
- }
- while (content.isReadable()) {
- try {
- Packet packet = decoder.decodePackets(content, client);
- if (packet.hasAttachments() && !packet.isAttachmentsLoaded()) {
- return;
- }
- Namespace ns = namespacesHub.get(packet.getNsp());
- if (ns == null) {
- if (packet.getSubType() == PacketType.CONNECT) {
- Packet p = new Packet(PacketType.MESSAGE);
- p.setSubType(PacketType.ERROR);
- p.setNsp(packet.getNsp());
- p.setData("Invalid namespace");
- client.send(p);
- return;
- }
- log.debug("Can't find namespace for endpoint: {}, sessionId: {} probably it was removed.", packet.getNsp(), client.getSessionId());
- return;
- }
-
- if (packet.getSubType() == PacketType.CONNECT) {
- client.addNamespaceClient(ns);
- }
-
- NamespaceClient nClient = client.getChildClient(ns);
- if (nClient == null) {
- log.debug("Can't find namespace client in namespace: {}, sessionId: {} probably it was disconnected.", ns.getName(), client.getSessionId());
- return;
- }
- packetListener.onPacket(packet, nClient, message.getTransport());
- } catch (Exception ex) {
- String c = content.toString(CharsetUtil.UTF_8);
- log.error("Error during data processing. Client sessionId: " + client.getSessionId() + ", data: " + c, ex);
- throw ex;
- }
- }
- }
-
- @Override
- public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception {
- if (!exceptionListener.exceptionCaught(ctx, e)) {
- super.exceptionCaught(ctx, e);
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/PacketListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/PacketListener.java
deleted file mode 100644
index 7eb0099d8..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/PacketListener.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import java.util.Collections;
-import java.util.List;
-
-import com.fr.third.socketio.AckRequest;
-import com.fr.third.socketio.Transport;
-import com.fr.third.socketio.ack.AckManager;
-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.PacketType;
-import com.fr.third.socketio.scheduler.CancelableScheduler;
-import com.fr.third.socketio.scheduler.SchedulerKey;
-import com.fr.third.socketio.transport.NamespaceClient;
-import com.fr.third.socketio.transport.PollingTransport;
-
-public class PacketListener {
-
- private final NamespacesHub namespacesHub;
- private final AckManager ackManager;
- private final CancelableScheduler scheduler;
-
- public PacketListener(AckManager ackManager, NamespacesHub namespacesHub, PollingTransport xhrPollingTransport,
- CancelableScheduler scheduler) {
- this.ackManager = ackManager;
- this.namespacesHub = namespacesHub;
- this.scheduler = scheduler;
- }
-
- public void onPacket(Packet packet, NamespaceClient client, Transport transport) {
- final AckRequest ackRequest = new AckRequest(packet, client);
-
- if (packet.isAckRequested()) {
- ackManager.initAckIndex(client.getSessionId(), packet.getAckId());
- }
-
- switch (packet.getType()) {
- case PING: {
- Packet outPacket = new Packet(PacketType.PONG);
- outPacket.setData(packet.getData());
- // TODO use future
- client.getBaseClient().send(outPacket, transport);
-
- if ("probe".equals(packet.getData())) {
- client.getBaseClient().send(new Packet(PacketType.NOOP), Transport.POLLING);
- } else {
- client.getBaseClient().schedulePingTimeout();
- }
- Namespace namespace = namespacesHub.get(packet.getNsp());
- namespace.onPing(client);
- break;
- }
-
- case UPGRADE: {
- client.getBaseClient().schedulePingTimeout();
-
- SchedulerKey key = new SchedulerKey(SchedulerKey.Type.UPGRADE_TIMEOUT, client.getSessionId());
- scheduler.cancel(key);
-
- client.getBaseClient().upgradeCurrentTransport(transport);
- break;
- }
-
- case MESSAGE: {
- client.getBaseClient().schedulePingTimeout();
-
- if (packet.getSubType() == PacketType.DISCONNECT) {
- client.onDisconnect();
- }
-
- if (packet.getSubType() == PacketType.CONNECT) {
- Namespace namespace = namespacesHub.get(packet.getNsp());
- namespace.onConnect(client);
- // send connect handshake packet back to client
- client.getBaseClient().send(packet, transport);
- }
-
- if (packet.getSubType() == PacketType.ACK
- || packet.getSubType() == PacketType.BINARY_ACK) {
- ackManager.onAck(client, packet);
- }
-
- if (packet.getSubType() == PacketType.EVENT
- || packet.getSubType() == PacketType.BINARY_EVENT) {
- Namespace namespace = namespacesHub.get(packet.getNsp());
- List args = Collections.emptyList();
- if (packet.getData() != null) {
- args = packet.getData();
- }
- namespace.onEvent(client, packet.getName(), args, ackRequest);
- }
- break;
- }
-
- case CLOSE:
- client.getBaseClient().onChannelDisconnect();
- break;
-
- default:
- break;
- }
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/SocketIOException.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/SocketIOException.java
deleted file mode 100644
index 78bd1da2b..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/SocketIOException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-public class SocketIOException extends RuntimeException {
-
- private static final long serialVersionUID = -9218908839842557188L;
-
- public SocketIOException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public SocketIOException(String message) {
- super(message);
- }
-
- public SocketIOException(Throwable cause) {
- super(cause);
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/SuccessAuthorizationListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/SuccessAuthorizationListener.java
deleted file mode 100644
index 44683d8c4..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/SuccessAuthorizationListener.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import com.fr.third.socketio.AuthorizationListener;
-import com.fr.third.socketio.HandshakeData;
-
-public class SuccessAuthorizationListener implements AuthorizationListener {
-
- @Override
- public boolean isAuthorized(HandshakeData data) {
- return true;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/TransportState.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/TransportState.java
deleted file mode 100644
index c26607138..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/TransportState.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import com.fr.third.socketio.protocol.Packet;
-
-import io.netty.channel.Channel;
-
-public class TransportState {
-
- private Queue packetsQueue = new ConcurrentLinkedQueue();
- private Channel channel;
-
- public void setPacketsQueue(Queue packetsQueue) {
- this.packetsQueue = packetsQueue;
- }
-
- public Queue getPacketsQueue() {
- return packetsQueue;
- }
-
- public Channel getChannel() {
- return channel;
- }
-
- public Channel update(Channel channel) {
- Channel prevChannel = this.channel;
- this.channel = channel;
- return prevChannel;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/handler/WrongUrlHandler.java b/fine-socketio/src/main/java/com/fr/third/socketio/handler/WrongUrlHandler.java
deleted file mode 100644
index 2906a886e..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/handler/WrongUrlHandler.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.handler;
-
-import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
-import io.netty.channel.ChannelHandler.Sharable;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.handler.codec.http.DefaultHttpResponse;
-import io.netty.handler.codec.http.FullHttpRequest;
-import io.netty.handler.codec.http.HttpResponse;
-import io.netty.handler.codec.http.HttpResponseStatus;
-import io.netty.handler.codec.http.QueryStringDecoder;
-
-@Sharable
-public class WrongUrlHandler extends ChannelInboundHandlerAdapter {
-
- private static final Logger log = LoggerFactory.getLogger(WrongUrlHandler.class);
-
- @Override
- public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
- if (msg instanceof FullHttpRequest) {
- FullHttpRequest req = (FullHttpRequest) msg;
- Channel channel = ctx.channel();
- QueryStringDecoder queryDecoder = new QueryStringDecoder(req.uri());
-
- HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.BAD_REQUEST);
- ChannelFuture f = channel.writeAndFlush(res);
- f.addListener(ChannelFutureListener.CLOSE);
- req.release();
- log.warn("Blocked wrong socket.io-context request! url: {}, params: {}, ip: {}", queryDecoder.path(), queryDecoder.parameters(), channel.remoteAddress());
- return;
- }
- super.channelRead(ctx, msg);
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ClientListeners.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/ClientListeners.java
deleted file mode 100644
index ffeb16f69..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ClientListeners.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-public interface ClientListeners {
-
- void addMultiTypeEventListener(String eventName, MultiTypeEventListener listener, Class> ... eventClass);
-
- void addEventListener(String eventName, Class eventClass, DataListener listener);
-
- void addDisconnectListener(DisconnectListener listener);
-
- void addConnectListener(ConnectListener listener);
-
- void addPingListener(PingListener listener);
-
- void addListeners(Object listeners);
-
- void addListeners(Object listeners, Class> listenersClass);
-
- void removeAllListeners(String eventName);
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ConnectListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/ConnectListener.java
deleted file mode 100644
index ba83eba58..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ConnectListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import com.fr.third.socketio.SocketIOClient;
-
-public interface ConnectListener {
-
- void onConnect(SocketIOClient client);
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/DataListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/DataListener.java
deleted file mode 100644
index cd5b6e2a9..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/DataListener.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import com.fr.third.socketio.AckRequest;
-import com.fr.third.socketio.SocketIOClient;
-
-public interface DataListener {
-
- /**
- * Invokes when data object received from client
- *
- * @param client - receiver
- * @param data - received object
- * @param ackSender - ack request
- *
- */
- void onData(SocketIOClient client, T data, AckRequest ackSender) throws Exception;
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/DefaultExceptionListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/DefaultExceptionListener.java
deleted file mode 100644
index 0b94c8fc1..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/DefaultExceptionListener.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import io.netty.channel.ChannelHandlerContext;
-
-import java.util.List;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.SocketIOClient;
-
-public class DefaultExceptionListener extends ExceptionListenerAdapter {
-
- private static final Logger log = LoggerFactory.getLogger(DefaultExceptionListener.class);
-
- @Override
- public void onEventException(Exception e, List args, SocketIOClient client) {
- log.error(e.getMessage(), e);
- }
-
- @Override
- public void onDisconnectException(Exception e, SocketIOClient client) {
- log.error(e.getMessage(), e);
- }
-
- @Override
- public void onConnectException(Exception e, SocketIOClient client) {
- log.error(e.getMessage(), e);
- }
-
- @Override
- public void onPingException(Exception e, SocketIOClient client) {
- log.error(e.getMessage(), e);
- }
-
- @Override
- public boolean exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception {
- log.error(e.getMessage(), e);
- return true;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/DisconnectListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/DisconnectListener.java
deleted file mode 100644
index f73798f21..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/DisconnectListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import com.fr.third.socketio.SocketIOClient;
-
-public interface DisconnectListener {
-
- void onDisconnect(SocketIOClient client);
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ExceptionListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/ExceptionListener.java
deleted file mode 100644
index f0e65a459..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ExceptionListener.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import io.netty.channel.ChannelHandlerContext;
-
-import java.util.List;
-
-import com.fr.third.socketio.SocketIOClient;
-
-public interface ExceptionListener {
-
- void onEventException(Exception e, List args, SocketIOClient client);
-
- void onDisconnectException(Exception e, SocketIOClient client);
-
- void onConnectException(Exception e, SocketIOClient client);
-
- void onPingException(Exception e, SocketIOClient client);
-
- boolean exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception;
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ExceptionListenerAdapter.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/ExceptionListenerAdapter.java
deleted file mode 100644
index dbf07edf7..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/ExceptionListenerAdapter.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import io.netty.channel.ChannelHandlerContext;
-
-import java.util.List;
-
-import com.fr.third.socketio.SocketIOClient;
-
-/**
- * Base callback exceptions listener
- *
- *
- */
-public abstract class ExceptionListenerAdapter implements ExceptionListener {
-
- @Override
- public void onEventException(Exception e, List data, SocketIOClient client) {
- }
-
- @Override
- public void onDisconnectException(Exception e, SocketIOClient client) {
- }
-
- @Override
- public void onConnectException(Exception e, SocketIOClient client) {
- }
-
- @Override
- public boolean exceptionCaught(ChannelHandlerContext ctx, Throwable e) throws Exception {
- return false;
- }
-
- @Override
- public void onPingException(Exception e, SocketIOClient client) {
-
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/MultiTypeEventListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/MultiTypeEventListener.java
deleted file mode 100644
index d750f70ac..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/MultiTypeEventListener.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import com.fr.third.socketio.MultiTypeArgs;
-
-/**
- * Multi type args event listener
- *
- */
-public interface MultiTypeEventListener extends DataListener {
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/PingListener.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/PingListener.java
deleted file mode 100644
index c9f33d6b5..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/PingListener.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.listener;
-
-import com.fr.third.socketio.SocketIOClient;
-
-public interface PingListener {
-
- void onPing(SocketIOClient client);
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/interceptor/EventInterceptor.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/interceptor/EventInterceptor.java
deleted file mode 100644
index 4970b0ea8..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/interceptor/EventInterceptor.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.fr.third.socketio.listener.interceptor;
-
-import com.fr.third.socketio.AckRequest;
-import com.fr.third.socketio.SocketIOClient;
-
-import java.util.List;
-
-/**
- * Desc
- *
- * @author Elijah
- * created on 2021-04-26
- */
-public interface EventInterceptor extends Interceptor {
- default void before(SocketIOClient client, List params, AckRequest ackRequest){
- before(client);
- }
-
- default void after(SocketIOClient client, List params, AckRequest ackRequest){
- after(client);
- }
-
- default boolean accept(String eventName, SocketIOClient client, List param){
- return accept(client);
- }
-
-}
\ No newline at end of file
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/listener/interceptor/Interceptor.java b/fine-socketio/src/main/java/com/fr/third/socketio/listener/interceptor/Interceptor.java
deleted file mode 100644
index 501a9825f..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/listener/interceptor/Interceptor.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.fr.third.socketio.listener.interceptor;
-
-import com.fr.third.socketio.SocketIOClient;
-
-/**
- * Desc
- *
- * @author Elijah
- * created on 2021-05-06
- */
-public interface Interceptor {
- default void before(SocketIOClient client){
-
- }
-
- default void after(SocketIOClient client){
-
- }
-
- default boolean accept(SocketIOClient client){
- return true;
- }
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/messages/HttpErrorMessage.java b/fine-socketio/src/main/java/com/fr/third/socketio/messages/HttpErrorMessage.java
deleted file mode 100644
index 7be5e8639..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/messages/HttpErrorMessage.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.messages;
-
-import java.util.Map;
-
-public class HttpErrorMessage extends HttpMessage {
-
- private final Map data;
-
- public HttpErrorMessage(Map data) {
- super(null, null);
- this.data = data;
- }
-
- public Map getData() {
- return data;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/messages/HttpMessage.java b/fine-socketio/src/main/java/com/fr/third/socketio/messages/HttpMessage.java
deleted file mode 100644
index 5c9858e40..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/messages/HttpMessage.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.messages;
-
-import java.util.UUID;
-
-public abstract class HttpMessage {
-
- private final String origin;
- private final UUID sessionId;
-
- public HttpMessage(String origin, UUID sessionId) {
- this.origin = origin;
- this.sessionId = sessionId;
- }
-
- public String getOrigin() {
- return origin;
- }
-
- public UUID getSessionId() {
- return sessionId;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/messages/OutPacketMessage.java b/fine-socketio/src/main/java/com/fr/third/socketio/messages/OutPacketMessage.java
deleted file mode 100644
index 363cf55a1..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/messages/OutPacketMessage.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.messages;
-
-import com.fr.third.socketio.Transport;
-import com.fr.third.socketio.handler.ClientHead;
-
-public class OutPacketMessage extends HttpMessage {
-
- private final ClientHead clientHead;
- private final Transport transport;
-
- public OutPacketMessage(ClientHead clientHead, Transport transport) {
- super(clientHead.getOrigin(), clientHead.getSessionId());
-
- this.clientHead = clientHead;
- this.transport = transport;
- }
-
- public Transport getTransport() {
- return transport;
- }
-
- public ClientHead getClientHead() {
- return clientHead;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/messages/PacketsMessage.java b/fine-socketio/src/main/java/com/fr/third/socketio/messages/PacketsMessage.java
deleted file mode 100644
index 7a98e6211..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/messages/PacketsMessage.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.messages;
-
-import io.netty.buffer.ByteBuf;
-
-import com.fr.third.socketio.Transport;
-import com.fr.third.socketio.handler.ClientHead;
-
-public class PacketsMessage {
-
- private final ClientHead client;
- private final ByteBuf content;
- private final Transport transport;
-
- public PacketsMessage(ClientHead client, ByteBuf content, Transport transport) {
- this.client = client;
- this.content = content;
- this.transport = transport;
- }
-
- public Transport getTransport() {
- return transport;
- }
-
- public ClientHead getClient() {
- return client;
- }
-
- public ByteBuf getContent() {
- return content;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/messages/XHROptionsMessage.java b/fine-socketio/src/main/java/com/fr/third/socketio/messages/XHROptionsMessage.java
deleted file mode 100644
index bacc716bb..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/messages/XHROptionsMessage.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.messages;
-
-import java.util.UUID;
-
-public class XHROptionsMessage extends XHRPostMessage {
-
- public XHROptionsMessage(String origin, UUID sessionId) {
- super(origin, sessionId);
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/messages/XHRPostMessage.java b/fine-socketio/src/main/java/com/fr/third/socketio/messages/XHRPostMessage.java
deleted file mode 100644
index 54e5129bb..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/messages/XHRPostMessage.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.messages;
-
-import java.util.UUID;
-
-public class XHRPostMessage extends HttpMessage {
-
- public XHRPostMessage(String origin, UUID sessionId) {
- super(origin, sessionId);
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/misc/CompositeIterable.java b/fine-socketio/src/main/java/com/fr/third/socketio/misc/CompositeIterable.java
deleted file mode 100644
index 76fedc7a3..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/misc/CompositeIterable.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.misc;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public class CompositeIterable implements Iterable {
-
- private List> iterablesList;
- private Iterable[] iterables;
-
- public CompositeIterable(List> iterables) {
- this.iterablesList = iterables;
- }
-
- public CompositeIterable(Iterable ... iterables) {
- this.iterables = iterables;
- }
-
- public CompositeIterable(CompositeIterable iterable) {
- this.iterables = iterable.iterables;
- this.iterablesList = iterable.iterablesList;
- }
-
- @Override
- public Iterator iterator() {
- List> iterators = new ArrayList>();
- if (iterables != null) {
- for (Iterable iterable : iterables) {
- iterators.add(iterable.iterator());
- }
- } else {
- for (Iterable iterable : iterablesList) {
- iterators.add(iterable.iterator());
- }
- }
- return new CompositeIterator(iterators.iterator());
- }
-
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/misc/CompositeIterator.java b/fine-socketio/src/main/java/com/fr/third/socketio/misc/CompositeIterator.java
deleted file mode 100644
index f891c2670..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/misc/CompositeIterator.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.misc;
-
-import java.util.Iterator;
-
-public class CompositeIterator implements Iterator {
-
- private Iterator> listIterator;
- private Iterator currentIterator;
-
- public CompositeIterator(Iterator> listIterator) {
- this.currentIterator = null;
- this.listIterator = listIterator;
- }
-
- @Override
- public boolean hasNext() {
- if (currentIterator == null || !currentIterator.hasNext()) {
- while (listIterator.hasNext()) {
- Iterator iterator = listIterator.next();
- if (iterator.hasNext()) {
- currentIterator = iterator;
- return true;
- }
- }
- return false;
- }
- return currentIterator.hasNext();
- }
-
- @Override
- public T next() {
- hasNext();
- return currentIterator.next();
- }
-
- @Override
- public void remove() {
- currentIterator.remove();
- }
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/misc/IterableCollection.java b/fine-socketio/src/main/java/com/fr/third/socketio/misc/IterableCollection.java
deleted file mode 100644
index ef65dabc5..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/misc/IterableCollection.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.misc;
-
-import java.util.AbstractCollection;
-import java.util.Iterator;
-
-public class IterableCollection extends AbstractCollection {
-
- private final CompositeIterable iterable;
-
- public IterableCollection(Iterable iterable) {
- this(new CompositeIterable(iterable));
- }
-
- public IterableCollection(CompositeIterable iterable) {
- this.iterable = iterable;
- }
-
- @Override
- public Iterator iterator() {
- return new CompositeIterable(iterable).iterator();
- }
-
- @Override
- public int size() {
- Iterator iterator = new CompositeIterable(iterable).iterator();
- int count = 0;
- while (iterator.hasNext()) {
- iterator.next();
- count++;
- }
- return count;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/namespace/EventEntry.java b/fine-socketio/src/main/java/com/fr/third/socketio/namespace/EventEntry.java
deleted file mode 100644
index ba9e8dcf3..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/namespace/EventEntry.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.namespace;
-
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import com.fr.third.socketio.listener.DataListener;
-
-public class EventEntry {
-
- private final Queue> listeners = new ConcurrentLinkedQueue>();;
-
- public EventEntry() {
- super();
- }
-
- public void addListener(DataListener listener) {
- listeners.add(listener);
- }
-
- public Queue> getListeners() {
- return listeners;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/namespace/Namespace.java b/fine-socketio/src/main/java/com/fr/third/socketio/namespace/Namespace.java
deleted file mode 100644
index a8fa9b5f0..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/namespace/Namespace.java
+++ /dev/null
@@ -1,431 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.namespace;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ConcurrentMap;
-
-import com.fr.third.socketio.AckMode;
-import com.fr.third.socketio.AckRequest;
-import com.fr.third.socketio.BroadcastOperations;
-import com.fr.third.socketio.Configuration;
-import com.fr.third.socketio.MultiTypeArgs;
-import com.fr.third.socketio.SingleRoomBroadcastOperations;
-import com.fr.third.socketio.SocketIOClient;
-import com.fr.third.socketio.SocketIONamespace;
-import com.fr.third.socketio.annotation.ScannerEngine;
-import com.fr.third.socketio.listener.interceptor.EventInterceptor;
-import com.fr.third.socketio.listener.interceptor.Interceptor;
-import com.fr.third.socketio.protocol.JsonSupport;
-import com.fr.third.socketio.protocol.Packet;
-import com.fr.third.socketio.store.StoreFactory;
-import com.fr.third.socketio.store.pubsub.JoinLeaveMessage;
-import com.fr.third.socketio.store.pubsub.PubSubType;
-import com.fr.third.socketio.transport.NamespaceClient;
-
-import com.fr.third.socketio.listener.ConnectListener;
-import com.fr.third.socketio.listener.DataListener;
-import com.fr.third.socketio.listener.DisconnectListener;
-import com.fr.third.socketio.listener.ExceptionListener;
-import com.fr.third.socketio.listener.MultiTypeEventListener;
-import com.fr.third.socketio.listener.PingListener;
-import io.netty.util.internal.PlatformDependent;
-
-/**
- * Hub object for all clients in one namespace.
- * Namespace shares by different namespace-clients.
- *
- * @see NamespaceClient
- */
-public class Namespace implements SocketIONamespace {
-
- public static final String DEFAULT_NAME = "";
-
- private final ScannerEngine engine = new ScannerEngine();
- private final ConcurrentMap> eventListeners = PlatformDependent.newConcurrentHashMap();
- private final Queue connectListeners = new ConcurrentLinkedQueue();
- private final Queue disconnectListeners = new ConcurrentLinkedQueue();
- private final Queue pingListeners = new ConcurrentLinkedQueue();
-
- private final Map allClients = PlatformDependent.newConcurrentHashMap();
- private final ConcurrentMap> roomClients = PlatformDependent.newConcurrentHashMap();
- private final ConcurrentMap> clientRooms = PlatformDependent.newConcurrentHashMap();
-
- private final String name;
- private final AckMode ackMode;
- private final JsonSupport jsonSupport;
- private final StoreFactory storeFactory;
- private final ExceptionListener exceptionListener;
- private final Configuration configuration;
-
- public Namespace(String name, Configuration configuration) {
- super();
- this.name = name;
- this.jsonSupport = configuration.getJsonSupport();
- this.storeFactory = configuration.getStoreFactory();
- this.exceptionListener = configuration.getExceptionListener();
- this.ackMode = configuration.getAckMode();
- this.configuration = configuration;
- }
-
- public void addClient(SocketIOClient client) {
- allClients.put(client.getSessionId(), client);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public void addMultiTypeEventListener(String eventName, MultiTypeEventListener listener,
- Class>... eventClass) {
- EventEntry entry = eventListeners.get(eventName);
- if (entry == null) {
- entry = new EventEntry();
- EventEntry> oldEntry = eventListeners.putIfAbsent(eventName, entry);
- if (oldEntry != null) {
- entry = oldEntry;
- }
- }
- entry.addListener(listener);
- jsonSupport.addEventMapping(name, eventName, eventClass);
- }
-
- @Override
- public void removeAllListeners(String eventName) {
- EventEntry> entry = eventListeners.remove(eventName);
- if (entry != null) {
- jsonSupport.removeEventMapping(name, eventName);
- }
- }
-
- @Override
- @SuppressWarnings({"unchecked", "rawtypes"})
- public void addEventListener(String eventName, Class eventClass, DataListener listener) {
- EventEntry entry = eventListeners.get(eventName);
- if (entry == null) {
- entry = new EventEntry();
- EventEntry> oldEntry = eventListeners.putIfAbsent(eventName, entry);
- if (oldEntry != null) {
- entry = oldEntry;
- }
- }
- entry.addListener(listener);
- jsonSupport.addEventMapping(name, eventName, eventClass);
- }
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- public void onEvent(NamespaceClient client, String eventName, List args, AckRequest ackRequest) {
- EventEntry entry = eventListeners.get(eventName);
- if (entry == null) {
- return;
- }
- for (EventInterceptor eventInterceptor: configuration.getEventInterceptors()) {
- try {
- //不影响后续执行
- if (eventInterceptor.accept(eventName, client, args)) {
- eventInterceptor.before(client, args, ackRequest);
- }
- } catch (Exception e) {
- exceptionListener.onEventException(e, args, client);
- }
- }
- try {
- Queue listeners = entry.getListeners();
- for (DataListener dataListener : listeners) {
- Object data = getEventData(args, dataListener);
- dataListener.onData(client, data, ackRequest);
- }
- } catch (Exception e) {
- exceptionListener.onEventException(e, args, client);
- if (ackMode == AckMode.AUTO_SUCCESS_ONLY) {
- return;
- }
- } finally {
- for (EventInterceptor eventInterceptor: configuration.getEventInterceptors()) {
- try {
- //不影响后续执行
- if (eventInterceptor.accept(eventName, client, args)) {
- eventInterceptor.after(client, args, ackRequest);
- }
- } catch (Exception e) {
- exceptionListener.onEventException(e, args, client);
- }
- }
- }
-
- sendAck(ackRequest);
- }
-
- private void sendAck(AckRequest ackRequest) {
- if (ackMode == AckMode.AUTO || ackMode == AckMode.AUTO_SUCCESS_ONLY) {
- // send ack response if it not executed
- // during {@link DataListener#onData} invocation
- ackRequest.sendAckData(Collections.emptyList());
- }
- }
-
- private Object getEventData(List args, DataListener> dataListener) {
- if (dataListener instanceof MultiTypeEventListener) {
- return new MultiTypeArgs(args);
- } else {
- if (!args.isEmpty()) {
- return args.get(0);
- }
- }
- return null;
- }
-
- @Override
- public void addDisconnectListener(DisconnectListener listener) {
- disconnectListeners.add(listener);
- }
-
- public void onDisconnect(SocketIOClient client) {
- Set joinedRooms = client.getAllRooms();
- allClients.remove(client.getSessionId());
-
- // client must leave all rooms and publish the leave msg one by one on disconnect.
- for (String joinedRoom : joinedRooms) {
- leave(roomClients, joinedRoom, client.getSessionId());
- storeFactory.pubSubStore().publish(PubSubType.LEAVE, new JoinLeaveMessage(client.getSessionId(), joinedRoom, getName()));
- }
- clientRooms.remove(client.getSessionId());
-
- callInterceptor(client, false, true);
- try {
- for (DisconnectListener listener : disconnectListeners) {
- listener.onDisconnect(client);
- }
- } catch (Exception e) {
- exceptionListener.onDisconnectException(e, client);
- } finally {
- callInterceptor(client, false, false);
- }
- }
-
- @Override
- public void addConnectListener(ConnectListener listener) {
- connectListeners.add(listener);
- }
-
- public void onConnect(SocketIOClient client) {
- join(getName(), client.getSessionId());
- storeFactory.pubSubStore().publish(PubSubType.JOIN, new JoinLeaveMessage(client.getSessionId(), getName(), getName()));
-
- callInterceptor(client, true, true);
- try {
- for (ConnectListener listener : connectListeners) {
- listener.onConnect(client);
- }
- } catch (Exception e) {
- exceptionListener.onConnectException(e, client);
- } finally {
- callInterceptor(client, true, false);
- }
- }
-
- private void callInterceptor(SocketIOClient client, boolean connect, boolean before) {
- List interceptors = connect ? configuration.getConnectInterceptors() : configuration.getDisconnectInterceptors();
- for (Interceptor interceptor: interceptors) {
- try{
- if (interceptor.accept(client)) {
- if (before) {
- interceptor.before(client);
- } else {
- interceptor.after(client);
- }
- }
- } catch (Exception e) {
- if (connect) {
- exceptionListener.onConnectException(e, client);
- } else {
- exceptionListener.onDisconnectException(e, client);
- }
- }
-
- }
- }
- @Override
- public void addPingListener(PingListener listener) {
- pingListeners.add(listener);
- }
-
- public void onPing(SocketIOClient client) {
- try {
- for (PingListener listener : pingListeners) {
- listener.onPing(client);
- }
- } catch (Exception e) {
- exceptionListener.onPingException(e, client);
- }
- }
-
- @Override
- public BroadcastOperations getBroadcastOperations() {
- return new SingleRoomBroadcastOperations(getName(), getName(), allClients.values(), storeFactory);
- }
-
- @Override
- public BroadcastOperations getRoomOperations(String room) {
- return new SingleRoomBroadcastOperations(getName(), room, getRoomClients(room), storeFactory);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Namespace other = (Namespace) obj;
- if (name == null) {
- if (other.name != null)
- return false;
- } else if (!name.equals(other.name))
- return false;
- return true;
- }
-
- @Override
- public void addListeners(Object listeners) {
- addListeners(listeners, listeners.getClass());
- }
-
- @Override
- public void addListeners(Object listeners, Class> listenersClass) {
- engine.scan(this, listeners, listenersClass);
- }
-
- public void joinRoom(String room, UUID sessionId) {
- join(room, sessionId);
- storeFactory.pubSubStore().publish(PubSubType.JOIN, new JoinLeaveMessage(sessionId, room, getName()));
- }
-
- public void dispatch(String room, Packet packet) {
- Iterable clients = getRoomClients(room);
-
- for (SocketIOClient socketIOClient : clients) {
- socketIOClient.send(packet);
- }
- }
-
- private void join(ConcurrentMap> map, K key, V value) {
- Set clients = map.get(key);
- if (clients == null) {
- clients = Collections.newSetFromMap(PlatformDependent.newConcurrentHashMap());
- Set oldClients = map.putIfAbsent(key, clients);
- if (oldClients != null) {
- clients = oldClients;
- }
- }
- clients.add(value);
- // object may be changed due to other concurrent call
- if (clients != map.get(key)) {
- // re-join if queue has been replaced
- join(map, key, value);
- }
- }
-
- public void join(String room, UUID sessionId) {
- join(roomClients, room, sessionId);
- join(clientRooms, sessionId, room);
- }
-
- public void leaveRoom(String room, UUID sessionId) {
- leave(room, sessionId);
- storeFactory.pubSubStore().publish(PubSubType.LEAVE, new JoinLeaveMessage(sessionId, room, getName()));
- }
-
- private void leave(ConcurrentMap> map, K room, V sessionId) {
- Set clients = map.get(room);
- if (clients == null) {
- return;
- }
- clients.remove(sessionId);
-
- if (clients.isEmpty()) {
- map.remove(room, Collections.emptySet());
- }
- }
-
- public void leave(String room, UUID sessionId) {
- leave(roomClients, room, sessionId);
- leave(clientRooms, sessionId, room);
- }
-
- public Set getRooms(SocketIOClient client) {
- Set res = clientRooms.get(client.getSessionId());
- if (res == null) {
- return Collections.emptySet();
- }
- return Collections.unmodifiableSet(res);
- }
-
- public Set getRooms() {
- return roomClients.keySet();
- }
-
- public Iterable getRoomClients(String room) {
- Set sessionIds = roomClients.get(room);
-
- if (sessionIds == null) {
- return Collections.emptyList();
- }
-
- List result = new ArrayList();
- for (UUID sessionId : sessionIds) {
- SocketIOClient client = allClients.get(sessionId);
- if(client != null) {
- result.add(client);
- }
- }
- return result;
- }
-
- @Override
- public Collection getAllClients() {
- return Collections.unmodifiableCollection(allClients.values());
- }
-
- public JsonSupport getJsonSupport() {
- return jsonSupport;
- }
-
- @Override
- public SocketIOClient getClient(UUID uuid) {
- return allClients.get(uuid);
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/namespace/NamespacesHub.java b/fine-socketio/src/main/java/com/fr/third/socketio/namespace/NamespacesHub.java
deleted file mode 100644
index 6ba5b5ed3..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/namespace/NamespacesHub.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.namespace;
-
-import io.netty.util.internal.PlatformDependent;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.ConcurrentMap;
-
-import com.fr.third.socketio.Configuration;
-import com.fr.third.socketio.SocketIOClient;
-import com.fr.third.socketio.SocketIONamespace;
-import com.fr.third.socketio.misc.CompositeIterable;
-
-public class NamespacesHub {
-
- private final ConcurrentMap namespaces = PlatformDependent.newConcurrentHashMap();
- private final Configuration configuration;
-
- public NamespacesHub(Configuration configuration) {
- this.configuration = configuration;
- }
-
- public Namespace create(String name) {
- Namespace namespace = (Namespace) namespaces.get(name);
- if (namespace == null) {
- namespace = new Namespace(name, configuration);
- Namespace oldNamespace = (Namespace) namespaces.putIfAbsent(name, namespace);
- if (oldNamespace != null) {
- namespace = oldNamespace;
- }
- }
- return namespace;
- }
-
- public Iterable getRoomClients(String room) {
- List> allClients = new ArrayList>();
- for (SocketIONamespace namespace : namespaces.values()) {
- Iterable clients = ((Namespace)namespace).getRoomClients(room);
- allClients.add(clients);
- }
- return new CompositeIterable(allClients);
- }
-
- public Namespace get(String name) {
- return (Namespace) namespaces.get(name);
- }
-
- public void remove(String name) {
- SocketIONamespace namespace = namespaces.remove(name);
- if (namespace != null) {
- namespace.getBroadcastOperations().disconnect();
- }
- }
-
- public Collection getAllNamespaces() {
- return namespaces.values();
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/AckArgs.java b/fine-socketio/src/main/java/com/fr/third/socketio/protocol/AckArgs.java
deleted file mode 100644
index e04542821..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/AckArgs.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.protocol;
-
-import java.util.List;
-
-public class AckArgs {
-
- private List args;
-
- public AckArgs(List args) {
- super();
- this.args = args;
- }
-
- public List getArgs() {
- return args;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/AuthPacket.java b/fine-socketio/src/main/java/com/fr/third/socketio/protocol/AuthPacket.java
deleted file mode 100644
index 5192ee43d..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/AuthPacket.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.protocol;
-
-import java.util.UUID;
-
-
-public class AuthPacket {
-
- private final UUID sid;
- private final String[] upgrades;
- private final int pingInterval;
- private final int pingTimeout;
-
- public AuthPacket(UUID sid, String[] upgrades, int pingInterval, int pingTimeout) {
- super();
- this.sid = sid;
- this.upgrades = upgrades;
- this.pingInterval = pingInterval;
- this.pingTimeout = pingTimeout;
- }
-
- public int getPingInterval() {
- return pingInterval;
- }
-
- public int getPingTimeout() {
- return pingTimeout;
- }
-
- public UUID getSid() {
- return sid;
- }
-
- public String[] getUpgrades() {
- return upgrades;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/Event.java b/fine-socketio/src/main/java/com/fr/third/socketio/protocol/Event.java
deleted file mode 100644
index 7a2ba2adf..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/Event.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.protocol;
-
-import java.util.List;
-
-public class Event {
-
- private String name;
- private List args;
-
- public Event() {
- }
-
- public Event(String name, List args) {
- super();
- this.name = name;
- this.args = args;
- }
-
- public List getArgs() {
- return args;
- }
-
- public String getName() {
- return name;
- }
-
-}
diff --git a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/JacksonJsonSupport.java b/fine-socketio/src/main/java/com/fr/third/socketio/protocol/JacksonJsonSupport.java
deleted file mode 100644
index f4be84adf..000000000
--- a/fine-socketio/src/main/java/com/fr/third/socketio/protocol/JacksonJsonSupport.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/**
- * Copyright (c) 2012-2019 Nikita Koksharov
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.fr.third.socketio.protocol;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-import com.fr.third.slf4j.Logger;
-import com.fr.third.slf4j.LoggerFactory;
-
-import com.fr.third.socketio.AckCallback;
-import com.fr.third.socketio.MultiTypeAckCallback;
-import com.fr.third.socketio.namespace.Namespace;
-import com.fr.third.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fr.third.fasterxml.jackson.core.JsonGenerationException;
-import com.fr.third.fasterxml.jackson.core.JsonGenerator;
-import com.fr.third.fasterxml.jackson.core.JsonParser;
-import com.fr.third.fasterxml.jackson.core.JsonProcessingException;
-import com.fr.third.fasterxml.jackson.core.JsonToken;
-import com.fr.third.fasterxml.jackson.databind.BeanDescription;
-import com.fr.third.fasterxml.jackson.databind.DeserializationContext;
-import com.fr.third.fasterxml.jackson.databind.DeserializationFeature;
-import com.fr.third.fasterxml.jackson.databind.JavaType;
-import com.fr.third.fasterxml.jackson.databind.JsonMappingException;
-import com.fr.third.fasterxml.jackson.databind.JsonNode;
-import com.fr.third.fasterxml.jackson.databind.JsonSerializer;
-import com.fr.third.fasterxml.jackson.databind.Module;
-import com.fr.third.fasterxml.jackson.databind.ObjectMapper;
-import com.fr.third.fasterxml.jackson.databind.SerializationConfig;
-import com.fr.third.fasterxml.jackson.databind.SerializationFeature;
-import com.fr.third.fasterxml.jackson.databind.SerializerProvider;
-import com.fr.third.fasterxml.jackson.databind.deser.std.StdDeserializer;
-import com.fr.third.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor;
-import com.fr.third.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes;
-import com.fr.third.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
-import com.fr.third.fasterxml.jackson.databind.jsontype.TypeSerializer;
-import com.fr.third.fasterxml.jackson.databind.module.SimpleModule;
-import com.fr.third.fasterxml.jackson.databind.node.ObjectNode;
-import com.fr.third.fasterxml.jackson.databind.ser.BeanSerializerModifier;
-import com.fr.third.fasterxml.jackson.databind.ser.std.StdSerializer;
-import com.fr.third.fasterxml.jackson.databind.type.ArrayType;
-
-import io.netty.buffer.ByteBufInputStream;
-import io.netty.buffer.ByteBufOutputStream;
-import io.netty.util.internal.PlatformDependent;
-
-public class JacksonJsonSupport implements JsonSupport {
-
- private class AckArgsDeserializer extends StdDeserializer {
-
- private static final long serialVersionUID = 7810461017389946707L;
-
- protected AckArgsDeserializer() {
- super(AckArgs.class);
- }
-
- @Override
- public AckArgs deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
- JsonProcessingException {
- List args = new ArrayList();
- AckArgs result = new AckArgs(args);
-
- ObjectMapper mapper = (ObjectMapper) jp.getCodec();
- JsonNode root = mapper.readTree(jp);
- AckCallback> callback = currentAckClass.get();
- Iterator iter = root.iterator();
- int i = 0;
- while (iter.hasNext()) {
- Object val;
-
- Class> clazz = callback.getResultClass();
- if (callback instanceof MultiTypeAckCallback) {
- MultiTypeAckCallback multiTypeAckCallback = (MultiTypeAckCallback) callback;
- clazz = multiTypeAckCallback.getResultClasses()[i];
- }
-
- JsonNode arg = iter.next();
- if (arg.isTextual() || arg.isBoolean()) {
- clazz = Object.class;
- }
-
- val = mapper.treeToValue(arg, clazz);
- args.add(val);
- i++;
- }
- return result;
- }
-
- }
-
- public static class EventKey {
-
- private String namespaceName;
- private String eventName;
-
- public EventKey(String namespaceName, String eventName) {
- super();
- this.namespaceName = namespaceName;
- this.eventName = eventName;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((eventName == null) ? 0 : eventName.hashCode());
- result = prime * result + ((namespaceName == null) ? 0 : namespaceName.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- EventKey other = (EventKey) obj;
- if (eventName == null) {
- if (other.eventName != null)
- return false;
- } else if (!eventName.equals(other.eventName))
- return false;
- if (namespaceName == null) {
- if (other.namespaceName != null)
- return false;
- } else if (!namespaceName.equals(other.namespaceName))
- return false;
- return true;
- }
-
- }
-
- private class EventDeserializer extends StdDeserializer {
-
- private static final long serialVersionUID = 8178797221017768689L;
-
- final Map>> eventMapping = PlatformDependent.newConcurrentHashMap();
-
-
- protected EventDeserializer() {
- super(Event.class);
- }
-
- @Override
- public Event deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
- JsonProcessingException {
- ObjectMapper mapper = (ObjectMapper) jp.getCodec();
- String eventName = jp.nextTextValue();
-
- EventKey ek = new EventKey(namespaceClass.get(), eventName);
- if (!eventMapping.containsKey(ek)) {
- ek = new EventKey(Namespace.DEFAULT_NAME, eventName);
- if (!eventMapping.containsKey(ek)) {
- return new Event(eventName, Collections.emptyList());
- }
- }
-
- List eventArgs = new ArrayList();
- Event event = new Event(eventName, eventArgs);
- List> eventClasses = eventMapping.get(ek);
- int i = 0;
- while (true) {
- JsonToken token = jp.nextToken();
- if (token == JsonToken.END_ARRAY) {
- break;
- }
- if (i > eventClasses.size() - 1) {
- log.debug("Event {} has more args than declared in handler: {}", eventName, null);
- break;
- }
- Class> eventClass = eventClasses.get(i);
- Object arg = mapper.readValue(jp, eventClass);
- eventArgs.add(arg);
- i++;
- }
- return event;
- }
-
- }
-
- public static class ByteArraySerializer extends StdSerializer
- {
-
- private static final long serialVersionUID = 3420082888596468148L;
-
- private final ThreadLocal> arrays = new ThreadLocal>() {
- @Override
- protected List initialValue() {
- return new ArrayList();
- };
- };
-
- public ByteArraySerializer() {
- super(byte[].class);
- }
-
- @Override
- public boolean isEmpty(byte[] value) {
- return (value == null) || (value.length == 0);
- }
-
- @Override
- public void serialize(byte[] value, JsonGenerator jgen, SerializerProvider provider)
- throws IOException, JsonGenerationException
- {
- Map