Code cleanups.
This commit is contained in:
parent
f6e460fc35
commit
2e21234328
|
@ -94,7 +94,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
this.incomingHandler = websocket;
|
this.incomingHandler = websocket;
|
||||||
this.connection.getIOState().addListener(this);
|
this.connection.getIOState().addListener(this);
|
||||||
this.policy = containerScope.getPolicy();
|
this.policy = containerScope.getPolicy();
|
||||||
|
|
||||||
addBean(this.connection);
|
addBean(this.connection);
|
||||||
addBean(this.websocket);
|
addBean(this.websocket);
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
{
|
{
|
||||||
executor.execute(runnable);
|
executor.execute(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStart() throws Exception
|
protected void doStart() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -143,7 +143,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
|
|
||||||
super.doStart();
|
super.doStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doStop() throws Exception
|
protected void doStop() throws Exception
|
||||||
{
|
{
|
||||||
|
@ -163,7 +163,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
}
|
}
|
||||||
super.doStop();
|
super.doStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dump(Appendable out, String indent) throws IOException
|
public void dump(Appendable out, String indent) throws IOException
|
||||||
{
|
{
|
||||||
|
@ -223,7 +223,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
{
|
{
|
||||||
return this.connection.getBufferPool();
|
return this.connection.getBufferPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassLoader getClassLoader()
|
public ClassLoader getClassLoader()
|
||||||
{
|
{
|
||||||
return this.getClass().getClassLoader();
|
return this.getClass().getClassLoader();
|
||||||
|
@ -321,7 +321,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
{
|
{
|
||||||
return this.upgradeResponse;
|
return this.upgradeResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WebSocketSession getWebSocketSession()
|
public WebSocketSession getWebSocketSession()
|
||||||
|
@ -409,12 +409,12 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
{
|
{
|
||||||
incomingError(cause);
|
incomingError(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClosed(Connection connection)
|
public void onClosed(Connection connection)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpened(Connection connection)
|
public void onOpened(Connection connection)
|
||||||
{
|
{
|
||||||
|
@ -460,7 +460,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open/Activate the session
|
* Open/Activate the session
|
||||||
*/
|
*/
|
||||||
|
@ -474,17 +474,17 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
// already opened
|
// already opened
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try(ThreadClassLoaderScope scope = new ThreadClassLoaderScope(classLoader))
|
try(ThreadClassLoaderScope scope = new ThreadClassLoaderScope(classLoader))
|
||||||
{
|
{
|
||||||
// Upgrade success
|
// Upgrade success
|
||||||
connection.getIOState().onConnected();
|
connection.getIOState().onConnected();
|
||||||
|
|
||||||
// Connect remote
|
// Connect remote
|
||||||
remote = new WebSocketRemoteEndpoint(connection,outgoingHandler,getBatchMode());
|
remote = new WebSocketRemoteEndpoint(connection,outgoingHandler,getBatchMode());
|
||||||
if(LOG_OPEN.isDebugEnabled())
|
if(LOG_OPEN.isDebugEnabled())
|
||||||
LOG_OPEN.debug("[{}] {}.open() remote={}",policy.getBehavior(),this.getClass().getSimpleName(),remote);
|
LOG_OPEN.debug("[{}] {}.open() remote={}",policy.getBehavior(),this.getClass().getSimpleName(),remote);
|
||||||
|
|
||||||
// Open WebSocket
|
// Open WebSocket
|
||||||
websocket.openSession(this);
|
websocket.openSession(this);
|
||||||
|
|
||||||
|
@ -514,7 +514,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
|
||||||
close(statusCode,t.getMessage());
|
close(statusCode,t.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setExtensionFactory(ExtensionFactory extensionFactory)
|
public void setExtensionFactory(ExtensionFactory extensionFactory)
|
||||||
{
|
{
|
||||||
this.extensionFactory = extensionFactory;
|
this.extensionFactory = extensionFactory;
|
||||||
|
|
|
@ -58,7 +58,7 @@ import org.eclipse.jetty.websocket.common.io.IOState.ConnectionStateListener;
|
||||||
/**
|
/**
|
||||||
* Provides the implementation of {@link LogicalConnection} within the framework of the new {@link org.eclipse.jetty.io.Connection} framework of {@code jetty-io}.
|
* Provides the implementation of {@link LogicalConnection} within the framework of the new {@link org.eclipse.jetty.io.Connection} framework of {@code jetty-io}.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractWebSocketConnection extends AbstractConnection implements LogicalConnection, Connection.UpgradeTo, ConnectionStateListener, Dumpable
|
public abstract class AbstractWebSocketConnection extends AbstractConnection implements LogicalConnection, Connection.UpgradeTo, ConnectionStateListener, Dumpable
|
||||||
{
|
{
|
||||||
private class Flusher extends FrameFlusher
|
private class Flusher extends FrameFlusher
|
||||||
{
|
{
|
||||||
|
@ -190,7 +190,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
return countOnFillableEvents.get();
|
return countOnFillableEvents.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static enum ReadMode
|
private static enum ReadMode
|
||||||
{
|
{
|
||||||
PARSE,
|
PARSE,
|
||||||
|
@ -267,7 +267,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
* <p> fillInterested();
|
* <p> fillInterested();
|
||||||
|
|
||||||
* This can result in a close handshake over the network, or a simple local abnormal close
|
* This can result in a close handshake over the network, or a simple local abnormal close
|
||||||
*
|
*
|
||||||
* @param statusCode
|
* @param statusCode
|
||||||
* the WebSocket status code.
|
* the WebSocket status code.
|
||||||
* @param reason
|
* @param reason
|
||||||
|
@ -341,7 +341,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
* Get the list of extensions in use.
|
* Get the list of extensions in use.
|
||||||
* <p>
|
* <p>
|
||||||
* This list is negotiated during the WebSocket Upgrade Request/Response handshake.
|
* This list is negotiated during the WebSocket Upgrade Request/Response handshake.
|
||||||
*
|
*
|
||||||
* @return the list of negotiated extensions in use.
|
* @return the list of negotiated extensions in use.
|
||||||
*/
|
*/
|
||||||
public List<ExtensionConfig> getExtensions()
|
public List<ExtensionConfig> getExtensions()
|
||||||
|
@ -353,7 +353,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
{
|
{
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId()
|
public String getId()
|
||||||
{
|
{
|
||||||
|
@ -437,7 +437,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
{
|
{
|
||||||
if (LOG_CLOSE.isDebugEnabled())
|
if (LOG_CLOSE.isDebugEnabled())
|
||||||
LOG_CLOSE.debug("{} Connection State Change: {}",policy.getBehavior(),state);
|
LOG_CLOSE.debug("{} Connection State Change: {}",policy.getBehavior(),state);
|
||||||
|
|
||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case OPEN:
|
case OPEN:
|
||||||
|
@ -493,9 +493,9 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
LOG.debug("{} onFillable()",policy.getBehavior());
|
LOG.debug("{} onFillable()",policy.getBehavior());
|
||||||
stats.countOnFillableEvents.incrementAndGet();
|
stats.countOnFillableEvents.incrementAndGet();
|
||||||
|
|
||||||
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true);
|
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
isFilling = true;
|
isFilling = true;
|
||||||
|
@ -503,7 +503,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
if(readMode == ReadMode.PARSE)
|
if(readMode == ReadMode.PARSE)
|
||||||
{
|
{
|
||||||
readMode = readParse(buffer);
|
readMode = readParse(buffer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
readMode = readDiscard(buffer);
|
readMode = readDiscard(buffer);
|
||||||
|
@ -524,8 +524,6 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFillInterestedFailed(Throwable cause)
|
protected void onFillInterestedFailed(Throwable cause)
|
||||||
{
|
{
|
||||||
|
@ -548,12 +546,12 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
}
|
}
|
||||||
prefillBuffer = prefilled;
|
prefillBuffer = prefilled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyError(Throwable t)
|
private void notifyError(Throwable t)
|
||||||
{
|
{
|
||||||
getParser().getIncomingFramesHandler().incomingError(t);
|
getParser().getIncomingFramesHandler().incomingError(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpen()
|
public void onOpen()
|
||||||
{
|
{
|
||||||
|
@ -646,7 +644,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
return ReadMode.DISCARD;
|
return ReadMode.DISCARD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ReadMode readParse(ByteBuffer buffer)
|
private ReadMode readParse(ByteBuffer buffer)
|
||||||
{
|
{
|
||||||
EndPoint endPoint = getEndPoint();
|
EndPoint endPoint = getEndPoint();
|
||||||
|
@ -667,7 +665,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
// Done reading, wait for next onFillable
|
// Done reading, wait for next onFillable
|
||||||
return ReadMode.PARSE;
|
return ReadMode.PARSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LOG.isDebugEnabled())
|
if (LOG.isDebugEnabled())
|
||||||
{
|
{
|
||||||
LOG.debug("Filled {} bytes - {}",filled,BufferUtil.toDetailString(buffer));
|
LOG.debug("Filled {} bytes - {}",filled,BufferUtil.toDetailString(buffer));
|
||||||
|
@ -695,7 +693,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
return ReadMode.DISCARD;
|
return ReadMode.DISCARD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resume()
|
public void resume()
|
||||||
{
|
{
|
||||||
|
@ -709,7 +707,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
* Get the list of extensions in use.
|
* Get the list of extensions in use.
|
||||||
* <p>
|
* <p>
|
||||||
* This list is negotiated during the WebSocket Upgrade Request/Response handshake.
|
* This list is negotiated during the WebSocket Upgrade Request/Response handshake.
|
||||||
*
|
*
|
||||||
* @param extensions
|
* @param extensions
|
||||||
* the list of negotiated extensions in use.
|
* the list of negotiated extensions in use.
|
||||||
*/
|
*/
|
||||||
|
@ -764,7 +762,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
||||||
{
|
{
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
|
|
||||||
EndPoint endp = getEndPoint();
|
EndPoint endp = getEndPoint();
|
||||||
if(endp != null)
|
if(endp != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class IOState
|
||||||
/**
|
/**
|
||||||
* The source of a close handshake. (ie: who initiated it).
|
* The source of a close handshake. (ie: who initiated it).
|
||||||
*/
|
*/
|
||||||
private static enum CloseHandshakeSource
|
private enum CloseHandshakeSource
|
||||||
{
|
{
|
||||||
/** No close handshake initiated (yet) */
|
/** No close handshake initiated (yet) */
|
||||||
NONE,
|
NONE,
|
||||||
|
@ -53,7 +53,7 @@ public class IOState
|
||||||
/** Remote side initiated the close handshake */
|
/** Remote side initiated the close handshake */
|
||||||
REMOTE,
|
REMOTE,
|
||||||
/** An abnormal close situation (disconnect, timeout, etc...) */
|
/** An abnormal close situation (disconnect, timeout, etc...) */
|
||||||
ABNORMAL;
|
ABNORMAL
|
||||||
}
|
}
|
||||||
|
|
||||||
public static interface ConnectionStateListener
|
public static interface ConnectionStateListener
|
||||||
|
@ -65,17 +65,17 @@ public class IOState
|
||||||
private ConnectionState state;
|
private ConnectionState state;
|
||||||
private final List<ConnectionStateListener> listeners = new CopyOnWriteArrayList<>();
|
private final List<ConnectionStateListener> listeners = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is input on websocket available (for reading frames).
|
* Is input on websocket available (for reading frames).
|
||||||
* Used to determine close handshake completion, and track half-close states
|
* Used to determine close handshake completion, and track half-close states
|
||||||
*/
|
*/
|
||||||
private boolean inputAvailable;
|
private boolean inputAvailable;
|
||||||
/**
|
/**
|
||||||
* Is output on websocket available (for writing frames).
|
* Is output on websocket available (for writing frames).
|
||||||
* Used to determine close handshake completion, and track half-closed states.
|
* Used to determine close handshake completion, and track half-closed states.
|
||||||
*/
|
*/
|
||||||
private boolean outputAvailable;
|
private boolean outputAvailable;
|
||||||
/**
|
/**
|
||||||
* Initiator of the close handshake.
|
* Initiator of the close handshake.
|
||||||
* Used to determine who initiated a close handshake for reply reasons.
|
* Used to determine who initiated a close handshake for reply reasons.
|
||||||
*/
|
*/
|
||||||
|
@ -294,8 +294,7 @@ public class IOState
|
||||||
if (event != null)
|
if (event != null)
|
||||||
{
|
{
|
||||||
notifyStateListeners(event);
|
notifyStateListeners(event);
|
||||||
|
if (abnormalEvent != null)
|
||||||
if(abnormalEvent != null)
|
|
||||||
{
|
{
|
||||||
notifyStateListeners(abnormalEvent);
|
notifyStateListeners(abnormalEvent);
|
||||||
}
|
}
|
||||||
|
@ -406,7 +405,7 @@ public class IOState
|
||||||
{
|
{
|
||||||
if(LOG.isDebugEnabled())
|
if(LOG.isDebugEnabled())
|
||||||
LOG.debug(" onOpened()");
|
LOG.debug(" onOpened()");
|
||||||
|
|
||||||
ConnectionState event = null;
|
ConnectionState event = null;
|
||||||
synchronized (this)
|
synchronized (this)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue