Refactoring protected fields back to private with protected methods per discussion with Simone

This commit is contained in:
Joakim Erdfelt 2011-12-15 11:07:27 -07:00
parent ae8c8551fc
commit 5774c03e09
8 changed files with 81 additions and 51 deletions

View File

@ -38,13 +38,13 @@ public class WebSocketConnectionD00 extends AbstractConnection implements WebSoc
public final static byte LENGTH_FRAME=(byte)0x80;
public final static byte SENTINEL_FRAME=(byte)0x00;
final WebSocketParser _parser;
final WebSocketGenerator _generator;
final WebSocket _websocket;
final String _protocol;
String _key1;
String _key2;
ByteArrayBuffer _hixieBytes;
private final WebSocketParser _parser;
private final WebSocketGenerator _generator;
private final WebSocket _websocket;
private final String _protocol;
private String _key1;
private String _key2;
private ByteArrayBuffer _hixieBytes;
public WebSocketConnectionD00(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol)
throws IOException
@ -375,6 +375,19 @@ public class WebSocketConnectionD00 extends AbstractConnection implements WebSoc
return _protocol;
}
protected void onFrameHandshake()
{
if (_websocket instanceof OnFrame)
{
((OnFrame)_websocket).onHandshake(this);
}
}
protected void onWebsocketOpen()
{
_websocket.onOpen(this);
}
static class FrameHandlerD00 implements WebSocketParser.FrameHandler
{
final WebSocket _websocket;

View File

@ -70,12 +70,11 @@ public class WebSocketConnectionD06 extends AbstractConnection implements WebSoc
}
}
private final static byte[] MAGIC;
private final WebSocketParser _parser;
private final WebSocketGenerator _generator;
protected final WebSocket _webSocket;
protected final OnFrame _onFrame;
private final WebSocket _webSocket;
private final OnFrame _onFrame;
private final OnBinaryMessage _onBinaryMessage;
private final OnTextMessage _onTextMessage;
private final OnControl _onControl;
@ -98,7 +97,7 @@ public class WebSocketConnectionD06 extends AbstractConnection implements WebSoc
}
private final WebSocketParser.FrameHandler _frameHandler= new FrameHandlerD06();
protected final WebSocket.FrameConnection _connection = new FrameConnectionD06();
private final WebSocket.FrameConnection _connection = new FrameConnectionD06();
/* ------------------------------------------------------------ */
@ -281,8 +280,19 @@ public class WebSocketConnectionD06 extends AbstractConnection implements WebSoc
return Collections.emptyList();
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
protected void onFrameHandshake()
{
if (_onFrame!=null)
{
_onFrame.onHandshake(_connection);
}
}
protected void onWebSocketOpen()
{
_webSocket.onOpen(_connection);
}
/* ------------------------------------------------------------ */
private class FrameConnectionD06 implements WebSocket.FrameConnection
{

View File

@ -25,7 +25,6 @@ import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Utf8StringBuilder;
@ -74,13 +73,13 @@ public class WebSocketConnectionD08 extends AbstractConnection implements WebSoc
}
private final static byte[] MAGIC;
protected final List<Extension> _extensions;
private final List<Extension> _extensions;
private final WebSocketParserD08 _parser;
private final WebSocketParser.FrameHandler _inbound;
private final WebSocketGeneratorD08 _generator;
private final WebSocketGenerator _outbound;
protected final WebSocket _webSocket;
protected final OnFrame _onFrame;
private final WebSocket _webSocket;
private final OnFrame _onFrame;
private final OnBinaryMessage _onBinaryMessage;
private final OnTextMessage _onTextMessage;
private final OnControl _onControl;
@ -107,7 +106,7 @@ public class WebSocketConnectionD08 extends AbstractConnection implements WebSoc
}
private final WebSocketParser.FrameHandler _frameHandler= new WSFrameHandler();
protected final WebSocket.FrameConnection _connection = new WSFrameConnection();
private final WebSocket.FrameConnection _connection = new WSFrameConnection();
/* ------------------------------------------------------------ */
@ -371,8 +370,19 @@ public class WebSocketConnectionD08 extends AbstractConnection implements WebSoc
}
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
protected void onFrameHandshake()
{
if (_onFrame != null)
{
_onFrame.onHandshake(_connection);
}
}
protected void onWebSocketOpen()
{
_webSocket.onOpen(_connection);
}
/* ------------------------------------------------------------ */
private class WSFrameConnection implements WebSocket.FrameConnection
{

View File

@ -25,7 +25,6 @@ import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Utf8Appendable;
@ -103,12 +102,12 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
}
private final static byte[] MAGIC;
protected final List<Extension> _extensions;
private final List<Extension> _extensions;
private final WebSocketParserD13 _parser;
private final WebSocketGeneratorD13 _generator;
private final WebSocketGenerator _outbound;
protected final WebSocket _webSocket;
protected final OnFrame _onFrame;
private final WebSocket _webSocket;
private final OnFrame _onFrame;
private final OnBinaryMessage _onBinaryMessage;
private final OnTextMessage _onTextMessage;
private final OnControl _onControl;
@ -134,7 +133,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
}
}
protected final WebSocket.FrameConnection _connection = new WSFrameConnection();
private final WebSocket.FrameConnection _connection = new WSFrameConnection();
/* ------------------------------------------------------------ */
@ -394,8 +393,19 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
}
}
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
protected void onFrameHandshake()
{
if (_onFrame != null)
{
_onFrame.onHandshake(_connection);
}
}
protected void onWebSocketOpen()
{
_webSocket.onOpen(_connection);
}
/* ------------------------------------------------------------ */
private class WSFrameConnection implements WebSocket.FrameConnection
{

View File

@ -8,7 +8,6 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.websocket.WebSocket.OnFrame;
public class WebSocketServletConnectionD00 extends WebSocketConnectionD00 implements WebSocketServletConnection
{
@ -71,11 +70,9 @@ public class WebSocketServletConnectionD00 extends WebSocketConnectionD00 implem
}
response.sendError(101,"Web Socket Protocol Handshake");
response.flushBuffer();
if (_websocket instanceof OnFrame)
{
((OnFrame)_websocket).onHandshake(this);
}
_websocket.onOpen(this);
onFrameHandshake();
onWebsocketOpen();
}
}
}

View File

@ -30,10 +30,7 @@ public class WebSocketServletConnectionD06 extends WebSocketConnectionD06 implem
response.sendError(101);
if (_onFrame!=null)
{
_onFrame.onHandshake(_connection);
}
_webSocket.onOpen(_connection);
onFrameHandshake();
onWebSocketOpen();
}
}

View File

@ -35,17 +35,14 @@ public class WebSocketServletConnectionD08 extends WebSocketConnectionD08 implem
response.addHeader("Sec-WebSocket-Protocol",subprotocol);
}
for (Extension ext : _extensions)
for (Extension ext : getExtensions())
{
response.addHeader("Sec-WebSocket-Extensions",ext.getParameterizedName());
}
response.sendError(101);
if (_onFrame != null)
{
_onFrame.onHandshake(_connection);
}
_webSocket.onOpen(_connection);
onFrameHandshake();
onWebSocketOpen();
}
}

View File

@ -35,18 +35,14 @@ public class WebSocketServletConnectionD13 extends WebSocketConnectionD13 implem
response.addHeader("Sec-WebSocket-Protocol",subprotocol);
}
for (Extension ext : _extensions)
for (Extension ext : getExtensions())
{
response.addHeader("Sec-WebSocket-Extensions",ext.getParameterizedName());
}
response.sendError(101);
if (_onFrame != null)
{
_onFrame.onHandshake(_connection);
}
_webSocket.onOpen(_connection);
onFrameHandshake();
onWebSocketOpen();
}
}