Code cleanups.

This commit is contained in:
Simone Bordet 2016-05-31 18:23:51 +02:00
parent f6e460fc35
commit 2e21234328
3 changed files with 37 additions and 40 deletions

View File

@ -94,7 +94,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
this.incomingHandler = websocket;
this.connection.getIOState().addListener(this);
this.policy = containerScope.getPolicy();
addBean(this.connection);
addBean(this.websocket);
}
@ -134,7 +134,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
{
executor.execute(runnable);
}
@Override
protected void doStart() throws Exception
{
@ -143,7 +143,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
super.doStart();
}
@Override
protected void doStop() throws Exception
{
@ -163,7 +163,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
}
super.doStop();
}
@Override
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();
}
public ClassLoader getClassLoader()
{
return this.getClass().getClassLoader();
@ -321,7 +321,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
{
return this.upgradeResponse;
}
@Override
public WebSocketSession getWebSocketSession()
@ -409,12 +409,12 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
{
incomingError(cause);
}
@Override
public void onClosed(Connection connection)
{
}
@Override
public void onOpened(Connection connection)
{
@ -460,7 +460,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
break;
}
}
/**
* Open/Activate the session
*/
@ -474,17 +474,17 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
// already opened
return;
}
try(ThreadClassLoaderScope scope = new ThreadClassLoaderScope(classLoader))
try(ThreadClassLoaderScope scope = new ThreadClassLoaderScope(classLoader))
{
// Upgrade success
connection.getIOState().onConnected();
// Connect remote
remote = new WebSocketRemoteEndpoint(connection,outgoingHandler,getBatchMode());
if(LOG_OPEN.isDebugEnabled())
LOG_OPEN.debug("[{}] {}.open() remote={}",policy.getBehavior(),this.getClass().getSimpleName(),remote);
// Open WebSocket
websocket.openSession(this);
@ -514,7 +514,7 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Web
close(statusCode,t.getMessage());
}
}
public void setExtensionFactory(ExtensionFactory extensionFactory)
{
this.extensionFactory = extensionFactory;

View File

@ -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}.
*/
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
{
@ -190,7 +190,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
return countOnFillableEvents.get();
}
}
private static enum ReadMode
{
PARSE,
@ -267,7 +267,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
* <p> fillInterested();
* This can result in a close handshake over the network, or a simple local abnormal close
*
*
* @param statusCode
* the WebSocket status code.
* @param reason
@ -341,7 +341,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
* Get the list of extensions in use.
* <p>
* This list is negotiated during the WebSocket Upgrade Request/Response handshake.
*
*
* @return the list of negotiated extensions in use.
*/
public List<ExtensionConfig> getExtensions()
@ -353,7 +353,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
{
return generator;
}
@Override
public String getId()
{
@ -437,7 +437,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
{
if (LOG_CLOSE.isDebugEnabled())
LOG_CLOSE.debug("{} Connection State Change: {}",policy.getBehavior(),state);
switch (state)
{
case OPEN:
@ -493,9 +493,9 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
if (LOG.isDebugEnabled())
LOG.debug("{} onFillable()",policy.getBehavior());
stats.countOnFillableEvents.incrementAndGet();
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),true);
try
{
isFilling = true;
@ -503,7 +503,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
if(readMode == ReadMode.PARSE)
{
readMode = readParse(buffer);
}
}
else
{
readMode = readDiscard(buffer);
@ -524,8 +524,6 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
}
}
@Override
protected void onFillInterestedFailed(Throwable cause)
{
@ -548,12 +546,12 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
}
prefillBuffer = prefilled;
}
private void notifyError(Throwable t)
{
getParser().getIncomingFramesHandler().incomingError(t);
}
@Override
public void onOpen()
{
@ -646,7 +644,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
return ReadMode.DISCARD;
}
}
private ReadMode readParse(ByteBuffer buffer)
{
EndPoint endPoint = getEndPoint();
@ -667,7 +665,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
// Done reading, wait for next onFillable
return ReadMode.PARSE;
}
if (LOG.isDebugEnabled())
{
LOG.debug("Filled {} bytes - {}",filled,BufferUtil.toDetailString(buffer));
@ -695,7 +693,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
return ReadMode.DISCARD;
}
}
@Override
public void resume()
{
@ -709,7 +707,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
* Get the list of extensions in use.
* <p>
* This list is negotiated during the WebSocket Upgrade Request/Response handshake.
*
*
* @param extensions
* the list of negotiated extensions in use.
*/
@ -764,7 +762,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
{
final int prime = 31;
int result = 1;
EndPoint endp = getEndPoint();
if(endp != null)
{

View File

@ -44,7 +44,7 @@ public class IOState
/**
* The source of a close handshake. (ie: who initiated it).
*/
private static enum CloseHandshakeSource
private enum CloseHandshakeSource
{
/** No close handshake initiated (yet) */
NONE,
@ -53,7 +53,7 @@ public class IOState
/** Remote side initiated the close handshake */
REMOTE,
/** An abnormal close situation (disconnect, timeout, etc...) */
ABNORMAL;
ABNORMAL
}
public static interface ConnectionStateListener
@ -65,17 +65,17 @@ public class IOState
private ConnectionState state;
private final List<ConnectionStateListener> listeners = new CopyOnWriteArrayList<>();
/**
/**
* Is input on websocket available (for reading frames).
* Used to determine close handshake completion, and track half-close states
*/
private boolean inputAvailable;
/**
/**
* Is output on websocket available (for writing frames).
* Used to determine close handshake completion, and track half-closed states.
*/
private boolean outputAvailable;
/**
/**
* Initiator of the close handshake.
* Used to determine who initiated a close handshake for reply reasons.
*/
@ -294,8 +294,7 @@ public class IOState
if (event != null)
{
notifyStateListeners(event);
if(abnormalEvent != null)
if (abnormalEvent != null)
{
notifyStateListeners(abnormalEvent);
}
@ -406,7 +405,7 @@ public class IOState
{
if(LOG.isDebugEnabled())
LOG.debug(" onOpened()");
ConnectionState event = null;
synchronized (this)
{