Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2016-01-14 00:00:06 +0000
committerGreg Wilkins2016-01-14 00:00:06 +0000
commitc5cbc64e7799409101e6dd28c143dbea397724cf (patch)
tree6505450207f77caf51950534b5c5cfa22e7fae82 /jetty-websocket/websocket-common
parent122ac9c4459818313bed8bf1663680b6cc93f29d (diff)
parent6e85554aadf6bb0e4904a93f0841c9d23c346efc (diff)
downloadorg.eclipse.jetty.project-c5cbc64e7799409101e6dd28c143dbea397724cf.tar.gz
org.eclipse.jetty.project-c5cbc64e7799409101e6dd28c143dbea397724cf.tar.xz
org.eclipse.jetty.project-c5cbc64e7799409101e6dd28c143dbea397724cf.zip
Merge remote-tracking branch 'origin/jetty-9.3.x'
Diffstat (limited to 'jetty-websocket/websocket-common')
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/LogicalConnection.java11
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/SessionListener.java31
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java45
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java20
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java49
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java11
-rw-r--r--jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/WebSocketContainerScope.java16
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/LocalWebSocketConnection.java6
-rw-r--r--jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/DummyConnection.java6
9 files changed, 116 insertions, 79 deletions
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/LogicalConnection.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/LogicalConnection.java
index 4eda6fd797..944d6efd55 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/LogicalConnection.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/LogicalConnection.java
@@ -22,7 +22,6 @@ import java.net.InetSocketAddress;
import java.util.concurrent.Executor;
import org.eclipse.jetty.io.ByteBufferPool;
-import org.eclipse.jetty.websocket.api.StatusCode;
import org.eclipse.jetty.websocket.api.SuspendToken;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
import org.eclipse.jetty.websocket.api.extensions.IncomingFrames;
@@ -36,7 +35,7 @@ public interface LogicalConnection extends OutgoingFrames, SuspendToken
* <p>
* Basic usage: results in an non-blocking async write, then connection close.
*
- * @see StatusCode
+ * @see org.eclipse.jetty.websocket.api.StatusCode
* @see #close(int, String)
*/
public void close();
@@ -50,7 +49,7 @@ public interface LogicalConnection extends OutgoingFrames, SuspendToken
* the status code
* @param reason
* the (optional) reason. (can be null for no reason)
- * @see StatusCode
+ * @see org.eclipse.jetty.websocket.api.StatusCode
*/
public void close(int statusCode, String reason);
@@ -155,4 +154,10 @@ public interface LogicalConnection extends OutgoingFrames, SuspendToken
* @return the suspend token
*/
SuspendToken suspend();
+
+ /**
+ * Get Unique ID for the Connection
+ * @return the unique ID for the connection
+ */
+ public String getId();
}
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/SessionListener.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/SessionListener.java
deleted file mode 100644
index c62facef7c..0000000000
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/SessionListener.java
+++ /dev/null
@@ -1,31 +0,0 @@
-//
-// ========================================================================
-// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
-// ------------------------------------------------------------------------
-// All rights reserved. This program and the accompanying materials
-// are made available under the terms of the Eclipse Public License v1.0
-// and Apache License v2.0 which accompanies this distribution.
-//
-// The Eclipse Public License is available at
-// http://www.eclipse.org/legal/epl-v10.html
-//
-// The Apache License v2.0 is available at
-// http://www.opensource.org/licenses/apache2.0.php
-//
-// You may elect to redistribute this code under either of these licenses.
-// ========================================================================
-//
-
-package org.eclipse.jetty.websocket.common;
-
-/**
- * Basic listener interface for Session open/close.
- * <p>
- * Used primarily for tracking open sessions.
- */
-public interface SessionListener
-{
- public void onSessionOpened(WebSocketSession session);
-
- public void onSessionClosed(WebSocketSession session);
-}
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
index 33356b2f61..e32a52cb91 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java
@@ -67,7 +67,6 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
private final URI requestURI;
private final LogicalConnection connection;
private final EventDriver websocket;
- private final SessionListener[] sessionListeners;
private final Executor executor;
private ClassLoader classLoader;
private ExtensionFactory extensionFactory;
@@ -80,7 +79,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
private UpgradeRequest upgradeRequest;
private UpgradeResponse upgradeResponse;
- public WebSocketSession(WebSocketContainerScope containerScope, URI requestURI, EventDriver websocket, LogicalConnection connection, SessionListener... sessionListeners)
+ public WebSocketSession(WebSocketContainerScope containerScope, URI requestURI, EventDriver websocket, LogicalConnection connection)
{
Objects.requireNonNull(containerScope,"Container Scope cannot be null");
Objects.requireNonNull(requestURI,"Request URI cannot be null");
@@ -90,11 +89,11 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
this.requestURI = requestURI;
this.websocket = websocket;
this.connection = connection;
- this.sessionListeners = sessionListeners;
this.executor = connection.getExecutor();
this.outgoingHandler = connection;
this.incomingHandler = websocket;
this.connection.getIOState().addListener(this);
+ this.policy = containerScope.getPolicy();
addBean(this.connection);
addBean(this.websocket);
@@ -435,36 +434,28 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
CloseInfo close = ioState.getCloseInfo();
// confirmed close of local endpoint
notifyClose(close.getStatusCode(),close.getReason());
-
- // notify session listeners
- for (SessionListener listener : sessionListeners)
+ try
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{}.onSessionClosed()",containerScope.getClass().getSimpleName());
+ containerScope.onSessionClosed(this);
+ }
+ catch (Throwable t)
{
- try
- {
- if (LOG.isDebugEnabled())
- LOG.debug("{}.onSessionClosed()",listener.getClass().getSimpleName());
- listener.onSessionClosed(this);
- }
- catch (Throwable t)
- {
- LOG.ignore(t);
- }
+ LOG.ignore(t);
}
break;
case CONNECTED:
// notify session listeners
- for (SessionListener listener : sessionListeners)
+ try
+ {
+ if (LOG.isDebugEnabled())
+ LOG.debug("{}.onSessionOpened()",containerScope.getClass().getSimpleName());
+ containerScope.onSessionOpened(this);
+ }
+ catch (Throwable t)
{
- try
- {
- if (LOG.isDebugEnabled())
- LOG.debug("{}.onSessionOpen()", listener.getClass().getSimpleName());
- listener.onSessionOpened(this);
- }
- catch (Throwable t)
- {
- LOG.ignore(t);
- }
+ LOG.ignore(t);
}
break;
}
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java
index 8494a26507..e46a231325 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSessionFactory.java
@@ -31,26 +31,10 @@ import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
public class WebSocketSessionFactory implements SessionFactory
{
private final WebSocketContainerScope containerScope;
- private final SessionListener[] listeners;
- public WebSocketSessionFactory(WebSocketContainerScope containerScope, SessionListener... sessionListeners)
+ public WebSocketSessionFactory(WebSocketContainerScope containerScope)
{
this.containerScope = containerScope;
- if ((sessionListeners != null) && (sessionListeners.length > 0))
- {
- this.listeners = sessionListeners;
- }
- else
- {
- if (this.containerScope instanceof SessionListener)
- {
- this.listeners = new SessionListener[] { (SessionListener)containerScope };
- }
- else
- {
- this.listeners = new SessionListener[0];
- }
- }
}
@Override
@@ -62,6 +46,6 @@ public class WebSocketSessionFactory implements SessionFactory
@Override
public WebSocketSession createSession(URI requestURI, EventDriver websocket, LogicalConnection connection)
{
- return new WebSocketSession(containerScope, requestURI,websocket,connection,listeners);
+ return new WebSocketSession(containerScope, requestURI,websocket,connection);
}
}
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java
index a3a0ed3e97..027e8e65d9 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java
@@ -214,6 +214,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
private final WebSocketPolicy policy;
private final AtomicBoolean suspendToken;
private final FrameFlusher flusher;
+ private final String id;
private List<ExtensionConfig> extensions;
private boolean isFilling;
private ByteBuffer prefillBuffer;
@@ -224,6 +225,11 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
public AbstractWebSocketConnection(EndPoint endp, Executor executor, Scheduler scheduler, WebSocketPolicy policy, ByteBufferPool bufferPool)
{
super(endp,executor);
+ this.id = String.format("%s:%d->%s:%d",
+ endp.getLocalAddress().getAddress().getHostAddress(),
+ endp.getLocalAddress().getPort(),
+ endp.getRemoteAddress().getAddress().getHostAddress(),
+ endp.getRemoteAddress().getPort());
this.policy = policy;
this.bufferPool = bufferPool;
this.generator = new Generator(policy,bufferPool);
@@ -347,6 +353,12 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
{
return generator;
}
+
+ @Override
+ public String getId()
+ {
+ return id;
+ }
@Override
public long getIdleTimeout()
@@ -747,6 +759,43 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
return String.format("%s@%X{endp=%s,ios=%s,f=%s,g=%s,p=%s}",getClass().getSimpleName(),hashCode(),getEndPoint(),ioState,flusher,generator,parser);
}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+
+ EndPoint endp = getEndPoint();
+ if(endp != null)
+ {
+ result = prime * result + endp.getLocalAddress().hashCode();
+ result = prime * result + endp.getRemoteAddress().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;
+ AbstractWebSocketConnection other = (AbstractWebSocketConnection)obj;
+ EndPoint endp = getEndPoint();
+ EndPoint otherEndp = other.getEndPoint();
+ if (endp == null)
+ {
+ if (otherEndp != null)
+ return false;
+ }
+ else if (!endp.equals(otherEndp))
+ return false;
+ return true;
+ }
+
/**
* Extra bytes from the initial HTTP upgrade that need to
* be processed by the websocket parser before starting
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java
index a68574c47f..0e8e0dd74d 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/SimpleContainerScope.java
@@ -27,6 +27,7 @@ import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
+import org.eclipse.jetty.websocket.common.WebSocketSession;
public class SimpleContainerScope extends ContainerLifeCycle implements WebSocketContainerScope
{
@@ -105,4 +106,14 @@ public class SimpleContainerScope extends ContainerLifeCycle implements WebSocke
{
this.sslContextFactory = sslContextFactory;
}
+
+ @Override
+ public void onSessionOpened(WebSocketSession session)
+ {
+ }
+
+ @Override
+ public void onSessionClosed(WebSocketSession session)
+ {
+ }
}
diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/WebSocketContainerScope.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/WebSocketContainerScope.java
index 0717cfc871..aacaf85ab2 100644
--- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/WebSocketContainerScope.java
+++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/scopes/WebSocketContainerScope.java
@@ -24,6 +24,7 @@ import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.DecoratedObjectFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
+import org.eclipse.jetty.websocket.common.WebSocketSession;
/**
* Defined Scope for a WebSocketContainer.
@@ -64,4 +65,19 @@ public interface WebSocketContainerScope
* @return the SslContextFactory in use by the container (can be null if no SSL context is defined)
*/
public SslContextFactory getSslContextFactory();
+
+ /**
+ * A Session has been opened
+ *
+ * @param session the session that was opened
+ */
+ public void onSessionOpened(WebSocketSession session);
+
+ /**
+ * A Session has been closed
+ *
+ * @param session the session that was closed
+ */
+ public void onSessionClosed(WebSocketSession session);
+
}
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/LocalWebSocketConnection.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/LocalWebSocketConnection.java
index 71b8e3d7ff..9c067f5913 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/LocalWebSocketConnection.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/io/LocalWebSocketConnection.java
@@ -108,6 +108,12 @@ public class LocalWebSocketConnection implements LogicalConnection, IncomingFram
}
@Override
+ public String getId()
+ {
+ return this.id;
+ }
+
+ @Override
public long getIdleTimeout()
{
return 0;
diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/DummyConnection.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/DummyConnection.java
index a5a1ba6c21..b0ea466241 100644
--- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/DummyConnection.java
+++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/DummyConnection.java
@@ -71,6 +71,12 @@ public class DummyConnection implements LogicalConnection
}
@Override
+ public String getId()
+ {
+ return "dummy";
+ }
+
+ @Override
public long getIdleTimeout()
{
return 0;

Back to the top