From 5774c03e09d8e8f853d3ead8c2166da98578dc04 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Thu, 15 Dec 2011 11:07:27 -0700 Subject: [PATCH] Refactoring protected fields back to private with protected methods per discussion with Simone --- .../websocket/WebSocketConnectionD00.java | 27 ++++++++++++++----- .../websocket/WebSocketConnectionD06.java | 22 ++++++++++----- .../websocket/WebSocketConnectionD08.java | 24 ++++++++++++----- .../websocket/WebSocketConnectionD13.java | 24 ++++++++++++----- .../WebSocketServletConnectionD00.java | 9 +++---- .../WebSocketServletConnectionD06.java | 7 ++--- .../WebSocketServletConnectionD08.java | 9 +++---- .../WebSocketServletConnectionD13.java | 10 +++---- 8 files changed, 81 insertions(+), 51 deletions(-) diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java index cd7ecec8782..3f550ddd8be 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD00.java @@ -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 @@ -374,6 +374,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 { diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java index 96c3415dd5a..da34dd17309 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD06.java @@ -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(); /* ------------------------------------------------------------ */ @@ -280,9 +279,20 @@ 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 { diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java index bbdb76a3123..e66cc83f8e2 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD08.java @@ -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 _extensions; + private final List _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(); /* ------------------------------------------------------------ */ @@ -370,9 +369,20 @@ public class WebSocketConnectionD08 extends AbstractConnection implements WebSoc ((AsyncEndPoint)_endp).scheduleWrite(); } } + + protected void onFrameHandshake() + { + if (_onFrame != null) + { + _onFrame.onHandshake(_connection); + } + } + + protected void onWebSocketOpen() + { + _webSocket.onOpen(_connection); + } - /* ------------------------------------------------------------ */ - /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ private class WSFrameConnection implements WebSocket.FrameConnection { diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java index c91c8376a13..cbf5910f6ab 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnectionD13.java @@ -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 _extensions; + private final List _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(); /* ------------------------------------------------------------ */ @@ -393,9 +392,20 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc ((AsyncEndPoint)_endp).scheduleWrite(); } } + + protected void onFrameHandshake() + { + if (_onFrame != null) + { + _onFrame.onHandshake(_connection); + } + } + + protected void onWebSocketOpen() + { + _webSocket.onOpen(_connection); + } - /* ------------------------------------------------------------ */ - /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ private class WSFrameConnection implements WebSocket.FrameConnection { diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD00.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD00.java index 3b9514e2696..f5b9ef4bb68 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD00.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD00.java @@ -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(); } } } diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD06.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD06.java index 74b71ccea11..b28caa01b43 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD06.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD06.java @@ -30,10 +30,7 @@ public class WebSocketServletConnectionD06 extends WebSocketConnectionD06 implem response.sendError(101); - if (_onFrame!=null) - { - _onFrame.onHandshake(_connection); - } - _webSocket.onOpen(_connection); + onFrameHandshake(); + onWebSocketOpen(); } } diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD08.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD08.java index bac9be7f0da..e96f7d4c27b 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD08.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD08.java @@ -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(); } } diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD13.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD13.java index a55a113b367..b2a7532fa6c 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD13.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketServletConnectionD13.java @@ -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(); } }