Updated Branches: refs/heads/master 6e655dacb -> f4dce2239
WICKET-5423 Create IResource based implementation of Native Web Sockets Move IWebSocketConnectionRegistry to **.api.registry package Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/f4dce223 Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/f4dce223 Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/f4dce223 Branch: refs/heads/master Commit: f4dce22390f1f00c1464b96b51c418262d1f69b7 Parents: 6e655da Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Fri Nov 22 12:13:34 2013 +0200 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Fri Nov 22 12:13:34 2013 +0200 ---------------------------------------------------------------------- .../wicket/protocol/ws/IWebSocketSettings.java | 2 +- .../wicket/protocol/ws/WebSocketSettings.java | 4 +- .../ws/api/AbstractWebSocketProcessor.java | 1 + .../ws/api/IWebSocketConnectionRegistry.java | 74 ---------- .../api/SimpleWebSocketConnectionRegistry.java | 140 ------------------- .../ws/api/WebSocketPushBroadcaster.java | 1 + .../protocol/ws/api/WebSocketResponse.java | 3 +- .../wicket/protocol/ws/api/registry/IKey.java | 2 +- .../registry/IWebSocketConnectionRegistry.java | 75 ++++++++++ .../SimpleWebSocketConnectionRegistry.java | 140 +++++++++++++++++++ .../ws/javax/app/charts/ChartUpdater.java | 2 +- 11 files changed, 224 insertions(+), 220 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/IWebSocketSettings.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/IWebSocketSettings.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/IWebSocketSettings.java index b3a3833..bcc35ea 100644 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/IWebSocketSettings.java +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/IWebSocketSettings.java @@ -19,7 +19,7 @@ package org.apache.wicket.protocol.ws; import org.apache.wicket.Application; import org.apache.wicket.MetaDataKey; -import org.apache.wicket.protocol.ws.api.IWebSocketConnectionRegistry; +import org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry; import org.apache.wicket.protocol.ws.concurrent.Executor; /** http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java index 3c7180d..1b5ea56 100644 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/WebSocketSettings.java @@ -18,8 +18,8 @@ package org.apache.wicket.protocol.ws; import java.util.concurrent.Callable; -import org.apache.wicket.protocol.ws.api.IWebSocketConnectionRegistry; -import org.apache.wicket.protocol.ws.api.SimpleWebSocketConnectionRegistry; +import org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry; +import org.apache.wicket.protocol.ws.api.registry.SimpleWebSocketConnectionRegistry; import org.apache.wicket.protocol.ws.concurrent.Executor; import org.apache.wicket.util.lang.Args; http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java index 2dade93..b704303 100644 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/AbstractWebSocketProcessor.java @@ -45,6 +45,7 @@ import org.apache.wicket.protocol.ws.api.message.IWebSocketMessage; import org.apache.wicket.protocol.ws.api.message.IWebSocketPushMessage; import org.apache.wicket.protocol.ws.api.message.TextMessage; import org.apache.wicket.protocol.ws.api.registry.IKey; +import org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry; import org.apache.wicket.protocol.ws.api.registry.PageIdKey; import org.apache.wicket.protocol.ws.api.registry.ResourceNameKey; import org.apache.wicket.request.Url; http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/IWebSocketConnectionRegistry.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/IWebSocketConnectionRegistry.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/IWebSocketConnectionRegistry.java deleted file mode 100644 index 8fc47b7..0000000 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/IWebSocketConnectionRegistry.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.wicket.protocol.ws.api; - -import java.util.Collection; -import org.apache.wicket.Application; -import org.apache.wicket.protocol.ws.api.registry.IKey; - -/** - * Tracks all currently connected WebSocket clients - * - * @since 6.0 - */ -public interface IWebSocketConnectionRegistry -{ - /** - * @param application - * the web application to look in - * @param sessionId - * the web socket client session id - * @param key - * the web socket client key - * @return the web socket connection used by a client from the specified coordinates - */ - IWebSocketConnection getConnection(Application application, String sessionId, IKey key); - - - /** - * @param application - * the web application to look in - * @return collection of web socket connection used by any client connected to specified application - */ - Collection<IWebSocketConnection> getConnections(Application application); - - /** - * Adds a new connection into the registry at the specified coordinates (application+session+page) - * - * @param application - * the web application to look in - * @param sessionId - * the web socket client session id - * @param key - * the web socket client key - * @param connection - * the web socket connection to add - */ - void setConnection(Application application, String sessionId, IKey key, IWebSocketConnection connection); - - /** - * Removes a web socket connection from the registry at the specified coordinates (application+session+page) - * - * @param application - * the web application to look in - * @param sessionId - * the web socket client session id - * @param key - * the web socket client key - */ - void removeConnection(Application application, String sessionId, IKey key); -} http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/SimpleWebSocketConnectionRegistry.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/SimpleWebSocketConnectionRegistry.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/SimpleWebSocketConnectionRegistry.java deleted file mode 100644 index ab3652b..0000000 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/SimpleWebSocketConnectionRegistry.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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 org.apache.wicket.protocol.ws.api; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.concurrent.ConcurrentMap; - -import org.apache.wicket.Application; -import org.apache.wicket.MetaDataKey; -import org.apache.wicket.protocol.ws.api.registry.IKey; -import org.apache.wicket.util.lang.Args; -import org.apache.wicket.util.lang.Generics; - -/** - * A registry that keeps all currently opened web socket connections in - * maps in Application's meta data. - * - * TODO remove the synchronizations below and use ConcurrentMap#putIfAbsent() - * - * @since 6.0 - */ -public class SimpleWebSocketConnectionRegistry implements IWebSocketConnectionRegistry -{ - private static final MetaDataKey<ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>>> KEY = - new MetaDataKey<ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>>>() - { - }; - - @Override - public IWebSocketConnection getConnection(Application application, String sessionId, IKey key) - { - Args.notNull(application, "application"); - Args.notNull(sessionId, "sessionId"); - Args.notNull(key, "key"); - - IWebSocketConnection connection = null; - ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY); - if (connectionsBySession != null) - { - ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId); - if (connectionsByPage != null) - { - connection = connectionsByPage.get(key); - } - } - return connection; - } - - /** - * Returns a collection of currently active websockets. The connections might close at any time. - * - * @param application - * @return - */ - public Collection<IWebSocketConnection> getConnections(Application application) - { - Args.notNull(application, "application"); - - Collection<IWebSocketConnection> connections = new ArrayList<>(); - ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY); - if (connectionsBySession != null) - { - for (ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage : connectionsBySession.values()) - { - connections.addAll(connectionsByPage.values()); - } - } - return connections; - } - - @Override - public void setConnection(Application application, String sessionId, IKey key, IWebSocketConnection connection) - { - Args.notNull(application, "application"); - Args.notNull(sessionId, "sessionId"); - Args.notNull(key, "key"); - - ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY); - if (connectionsBySession == null) - { - synchronized (KEY) - { - connectionsBySession = application.getMetaData(KEY); - if (connectionsBySession == null) - { - connectionsBySession = Generics.newConcurrentHashMap(); - application.setMetaData(KEY, connectionsBySession); - } - } - } - - ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId); - if (connectionsByPage == null && connection != null) - { - synchronized (connectionsBySession) - { - connectionsByPage = connectionsBySession.get(sessionId); - if (connectionsByPage == null) - { - connectionsByPage = Generics.newConcurrentHashMap(); - connectionsBySession.put(sessionId, connectionsByPage); - } - } - } - - if (connection != null) - { - connectionsByPage.put(key, connection); - } - else if (connectionsByPage != null) - { - connectionsByPage.remove(key); - if (connectionsByPage.isEmpty()) - { - connectionsBySession.remove(sessionId); - } - } - } - - @Override - public void removeConnection(Application application, String sessionId, IKey key) - { - setConnection(application, sessionId, key, null); - } -} http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketPushBroadcaster.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketPushBroadcaster.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketPushBroadcaster.java index 24e4056..cbe2daf 100644 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketPushBroadcaster.java +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketPushBroadcaster.java @@ -25,6 +25,7 @@ import org.apache.wicket.protocol.ws.IWebSocketSettings; import org.apache.wicket.protocol.ws.api.message.ConnectedMessage; import org.apache.wicket.protocol.ws.api.message.IWebSocketPushMessage; import org.apache.wicket.protocol.ws.api.registry.IKey; +import org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry; import org.apache.wicket.protocol.ws.concurrent.Executor; import org.apache.wicket.util.lang.Args; http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java index 7faa195..d5f36bf 100644 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/WebSocketResponse.java @@ -32,7 +32,8 @@ import org.slf4j.LoggerFactory; * when Wicket thread locals are available. * * When the thread locals are not available then you can write directly to the {@link IWebSocketConnection} - * taken from {@link IWebSocketConnectionRegistry}. In this case the response wont be cached. + * taken from {@link org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry}. + * In this case the response wont be cached. * * @since 6.0 */ http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IKey.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IKey.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IKey.java index cecda06..e05e76e 100644 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IKey.java +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IKey.java @@ -18,7 +18,7 @@ package org.apache.wicket.protocol.ws.api.registry; /** * A marker interface for keys that are used to find a web socket - * connection in {@link org.apache.wicket.protocol.ws.api.IWebSocketConnectionRegistry} + * connection in {@link IWebSocketConnectionRegistry} */ public interface IKey {} http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IWebSocketConnectionRegistry.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IWebSocketConnectionRegistry.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IWebSocketConnectionRegistry.java new file mode 100644 index 0000000..e62ea4f --- /dev/null +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/IWebSocketConnectionRegistry.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.wicket.protocol.ws.api.registry; + +import java.util.Collection; + +import org.apache.wicket.Application; +import org.apache.wicket.protocol.ws.api.IWebSocketConnection; + +/** + * Tracks all currently connected WebSocket clients + * + * @since 6.0 + */ +public interface IWebSocketConnectionRegistry +{ + /** + * @param application + * the web application to look in + * @param sessionId + * the web socket client session id + * @param key + * the web socket client key + * @return the web socket connection used by a client from the specified coordinates + */ + IWebSocketConnection getConnection(Application application, String sessionId, IKey key); + + + /** + * @param application + * the web application to look in + * @return collection of web socket connection used by any client connected to specified application + */ + Collection<IWebSocketConnection> getConnections(Application application); + + /** + * Adds a new connection into the registry at the specified coordinates (application+session+page) + * + * @param application + * the web application to look in + * @param sessionId + * the web socket client session id + * @param key + * the web socket client key + * @param connection + * the web socket connection to add + */ + void setConnection(Application application, String sessionId, IKey key, IWebSocketConnection connection); + + /** + * Removes a web socket connection from the registry at the specified coordinates (application+session+page) + * + * @param application + * the web application to look in + * @param sessionId + * the web socket client session id + * @param key + * the web socket client key + */ + void removeConnection(Application application, String sessionId, IKey key); +} http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/SimpleWebSocketConnectionRegistry.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/SimpleWebSocketConnectionRegistry.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/SimpleWebSocketConnectionRegistry.java new file mode 100644 index 0000000..8e6d46d --- /dev/null +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-core/src/main/java/org/apache/wicket/protocol/ws/api/registry/SimpleWebSocketConnectionRegistry.java @@ -0,0 +1,140 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.wicket.protocol.ws.api.registry; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.ConcurrentMap; + +import org.apache.wicket.Application; +import org.apache.wicket.MetaDataKey; +import org.apache.wicket.protocol.ws.api.IWebSocketConnection; +import org.apache.wicket.util.lang.Args; +import org.apache.wicket.util.lang.Generics; + +/** + * A registry that keeps all currently opened web socket connections in + * maps in Application's meta data. + * + * TODO remove the synchronizations below and use ConcurrentMap#putIfAbsent() + * + * @since 6.0 + */ +public class SimpleWebSocketConnectionRegistry implements IWebSocketConnectionRegistry +{ + private static final MetaDataKey<ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>>> KEY = + new MetaDataKey<ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>>>() + { + }; + + @Override + public IWebSocketConnection getConnection(Application application, String sessionId, IKey key) + { + Args.notNull(application, "application"); + Args.notNull(sessionId, "sessionId"); + Args.notNull(key, "key"); + + IWebSocketConnection connection = null; + ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY); + if (connectionsBySession != null) + { + ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId); + if (connectionsByPage != null) + { + connection = connectionsByPage.get(key); + } + } + return connection; + } + + /** + * Returns a collection of currently active websockets. The connections might close at any time. + * + * @param application + * @return + */ + public Collection<IWebSocketConnection> getConnections(Application application) + { + Args.notNull(application, "application"); + + Collection<IWebSocketConnection> connections = new ArrayList<>(); + ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY); + if (connectionsBySession != null) + { + for (ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage : connectionsBySession.values()) + { + connections.addAll(connectionsByPage.values()); + } + } + return connections; + } + + @Override + public void setConnection(Application application, String sessionId, IKey key, IWebSocketConnection connection) + { + Args.notNull(application, "application"); + Args.notNull(sessionId, "sessionId"); + Args.notNull(key, "key"); + + ConcurrentMap<String, ConcurrentMap<IKey, IWebSocketConnection>> connectionsBySession = application.getMetaData(KEY); + if (connectionsBySession == null) + { + synchronized (KEY) + { + connectionsBySession = application.getMetaData(KEY); + if (connectionsBySession == null) + { + connectionsBySession = Generics.newConcurrentHashMap(); + application.setMetaData(KEY, connectionsBySession); + } + } + } + + ConcurrentMap<IKey, IWebSocketConnection> connectionsByPage = connectionsBySession.get(sessionId); + if (connectionsByPage == null && connection != null) + { + synchronized (connectionsBySession) + { + connectionsByPage = connectionsBySession.get(sessionId); + if (connectionsByPage == null) + { + connectionsByPage = Generics.newConcurrentHashMap(); + connectionsBySession.put(sessionId, connectionsByPage); + } + } + } + + if (connection != null) + { + connectionsByPage.put(key, connection); + } + else if (connectionsByPage != null) + { + connectionsByPage.remove(key); + if (connectionsByPage.isEmpty()) + { + connectionsBySession.remove(sessionId); + } + } + } + + @Override + public void removeConnection(Application application, String sessionId, IKey key) + { + setConnection(application, sessionId, key, null); + } +} http://git-wip-us.apache.org/repos/asf/wicket/blob/f4dce223/wicket-experimental/wicket-native-websocket/wicket-native-websocket-javax/src/test/java/org/apache/wicket/protocol/ws/javax/app/charts/ChartUpdater.java ---------------------------------------------------------------------- diff --git a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-javax/src/test/java/org/apache/wicket/protocol/ws/javax/app/charts/ChartUpdater.java b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-javax/src/test/java/org/apache/wicket/protocol/ws/javax/app/charts/ChartUpdater.java index de3be73..86a8bb0 100644 --- a/wicket-experimental/wicket-native-websocket/wicket-native-websocket-javax/src/test/java/org/apache/wicket/protocol/ws/javax/app/charts/ChartUpdater.java +++ b/wicket-experimental/wicket-native-websocket/wicket-native-websocket-javax/src/test/java/org/apache/wicket/protocol/ws/javax/app/charts/ChartUpdater.java @@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit; import org.apache.wicket.Application; import org.apache.wicket.protocol.ws.IWebSocketSettings; import org.apache.wicket.protocol.ws.api.IWebSocketConnection; -import org.apache.wicket.protocol.ws.api.IWebSocketConnectionRegistry; +import org.apache.wicket.protocol.ws.api.registry.IWebSocketConnectionRegistry; import org.apache.wicket.protocol.ws.api.message.ConnectedMessage; import org.apache.wicket.protocol.ws.api.registry.IKey;
