Skip to main content

[tyrus~code:fd16b7ef] copyright check

  • From:
  • To:
  • Subject: [tyrus~code:fd16b7ef] copyright check
  • Date: Wed, 7 Aug 2013 09:12:03 +0000

Project:    tyrus
Repository: code
Revision:   fd16b7efe47cf1e5d985f43c00e51dea7a1737d8
Author:     jerseyrobot
Date:       2013-08-06 21:54:18 UTC
Link:       

Log Message:
------------
TYRUS-153: Removing static map in TyrusRemoteEndpoint, related refactoring

TYRUS-153: Adding javadoc

copyright check



Revisions:
----------
e0179dadbe1442a1ccf1ca3cf14bce4defa70683
39cfb9de4822fae3937975ae66a34b48f6e4598e
fd16b7efe47cf1e5d985f43c00e51dea7a1737d8


Modified Paths:
---------------
containers/servlet/src/main/java/org/glassfish/tyrus/servlet/TyrusHttpUpgradeHandler.java
core/src/main/java/org/glassfish/tyrus/core/TyrusEndpoint.java
core/src/main/java/org/glassfish/tyrus/core/TyrusRemoteEndpoint.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocket.java
protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocketApplication.java
protocol/websocket/src/test/java/org/glassfish/tyrus/websockets/uri/TestWebSocketApplication.java
tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/MockWebSocketClient.java
core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java
docs/jsr/websocket-jsr-proposal.html
etc/config/copyright-exclude
pom.xml


Added Paths:
------------
core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java


Diffs:
------
--- 
a/containers/servlet/src/main/java/org/glassfish/tyrus/servlet/TyrusHttpUpgradeHandler.java
+++ 
b/containers/servlet/src/main/java/org/glassfish/tyrus/servlet/TyrusHttpUpgradeHandler.java
@@ -53,8 +53,8 @@ import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpUpgradeHandler;
 import javax.servlet.http.WebConnection;
 
+import org.glassfish.tyrus.core.TyrusWebSocket;
 import org.glassfish.tyrus.websockets.DataFrame;
-import org.glassfish.tyrus.websockets.DefaultWebSocket;
 import org.glassfish.tyrus.websockets.FramingException;
 import org.glassfish.tyrus.websockets.WebSocket;
 import org.glassfish.tyrus.websockets.WebSocketEngine;
@@ -263,7 +263,7 @@ public class TyrusHttpUpgradeHandler implements 
HttpUpgradeHandler, ReadListener
     private void httpSessionForcedClose(ClosingFrame closingFrame) {
         if (!closed) {
             try {
-                ((DefaultWebSocket)webSocketHolder.webSocket).setClosed();
+                ((TyrusWebSocket)webSocketHolder.webSocket).setClosed();
                 webSocketHolder.webSocket.onClose(closingFrame);
                 closed = true;
                 wc.close();--- 
a/core/src/main/java/org/glassfish/tyrus/core/TyrusEndpoint.java
+++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusEndpoint.java
@@ -61,7 +61,6 @@ import javax.websocket.server.ServerEndpointConfig;
 
 import org.glassfish.tyrus.spi.SPIEndpoint;
 import org.glassfish.tyrus.spi.SPIRegisteredEndpoint;
-import org.glassfish.tyrus.websockets.DefaultWebSocket;
 import org.glassfish.tyrus.websockets.ProtocolHandler;
 import org.glassfish.tyrus.websockets.WebSocket;
 import org.glassfish.tyrus.websockets.WebSocketApplication;
@@ -113,7 +112,7 @@ public class TyrusEndpoint extends WebSocketApplication 
implements SPIRegistered
         final List<Extension> extensions = 
TyrusExtension.fromString(webSocketRequest.getHeaders().get(WebSocketEngine.SEC_WS_EXTENSIONS_HEADER));
         temporaryNegotiatedExtensions = 
endpoint.getNegotiatedExtensions(extensions);
 
-        return endpoint.checkHandshake(webSocketRequest instanceof 
RequestContext ? (RequestContext)webSocketRequest : null);
+        return endpoint.checkHandshake(webSocketRequest instanceof 
RequestContext ? (RequestContext) webSocketRequest : null);
     }
 
     @Override
@@ -124,20 +123,18 @@ public class TyrusEndpoint extends WebSocketApplication 
implements SPIRegistered
     @Override
     public WebSocket createSocket(final ProtocolHandler handler, final 
WebSocketListener... listeners) {
         handler.setContainer(endpoint.getWebSocketContainer());
-        return new DefaultWebSocket(handler, listeners);
+        return new TyrusWebSocket(handler, listeners);
     }
 
     @Override
     public void onConnect(WebSocket socket) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
-        this.endpoint.onConnect(gs, temporaryNegotiatedProtocol, 
temporaryNegotiatedExtensions);
+        this.endpoint.onConnect(new TyrusRemoteEndpoint(socket), 
temporaryNegotiatedProtocol, temporaryNegotiatedExtensions);
     }
 
     @Override
     public void onFragment(WebSocket socket, String fragment, boolean last) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
         try {
-            this.endpoint.onPartialMessage(gs, fragment, last);
+            this.endpoint.onPartialMessage(new TyrusRemoteEndpoint(socket), 
fragment, last);
         } catch (Throwable t) {
             Logger.getLogger(TyrusEndpoint.class.getName()).severe("Error 
!!!" + t);
             t.printStackTrace();
@@ -146,9 +143,8 @@ public class TyrusEndpoint extends WebSocketApplication 
implements SPIRegistered
 
     @Override
     public void onFragment(WebSocket socket, byte[] fragment, boolean last) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
         try {
-            this.endpoint.onPartialMessage(gs, ByteBuffer.wrap(fragment), 
last);
+            this.endpoint.onPartialMessage(new TyrusRemoteEndpoint(socket), 
ByteBuffer.wrap(fragment), last);
         } catch (Throwable t) {
             Logger.getLogger(TyrusEndpoint.class.getName()).severe("Error 
!!!" + t);
             t.printStackTrace();
@@ -157,33 +153,33 @@ public class TyrusEndpoint extends WebSocketApplication 
implements SPIRegistered
 
     @Override
     public void onMessage(WebSocket socket, String messageString) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
-        this.endpoint.onMessage(gs, messageString);
+        this.endpoint.onMessage(new TyrusRemoteEndpoint(socket), 
messageString);
     }
 
     @Override
     public void onMessage(WebSocket socket, byte[] bytes) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
-        this.endpoint.onMessage(gs, ByteBuffer.wrap(bytes));
+        this.endpoint.onMessage(new TyrusRemoteEndpoint(socket), 
ByteBuffer.wrap(bytes));
     }
 
     @Override
     public void onClose(WebSocket socket, ClosingFrame frame) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
         CloseReason closeReason = null;
 
         if (frame != null) {
             closeReason = new 
CloseReason(CloseReason.CloseCodes.getCloseCode(frame.getCode()), 
frame.getReason() == null ? "" : frame.getReason());
         }
 
-        this.endpoint.onClose(gs, closeReason);
-        TyrusRemoteEndpoint.remove(socket);
+        this.endpoint.onClose(new TyrusRemoteEndpoint(socket), closeReason);
+    }
+
+    @Override
+    public void onPing(WebSocket socket, byte[] bytes) {
+        this.endpoint.onPing(new TyrusRemoteEndpoint(socket), 
ByteBuffer.wrap(bytes));
     }
 
     @Override
     public void onPong(WebSocket socket, byte[] bytes) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
-        this.endpoint.onPong(gs, ByteBuffer.wrap(bytes));
+        this.endpoint.onPong(new TyrusRemoteEndpoint(socket), 
ByteBuffer.wrap(bytes));
     }
 
     @Override
@@ -236,12 +232,6 @@ public class TyrusEndpoint extends WebSocketApplication 
implements SPIRegistered
     }
 
     @Override
-    public void onPing(WebSocket socket, byte[] bytes) {
-        TyrusRemoteEndpoint gs = TyrusRemoteEndpoint.get(socket);
-        this.endpoint.onPing(gs, ByteBuffer.wrap(bytes));
-    }
-
-    @Override
     public void onHandShakeResponse(WebSocketRequest request, 
WebSocketResponse response) {
         final EndpointConfig configuration = 
this.endpoint.getEndpointConfig();
 
@@ -256,8 +246,8 @@ public class TyrusEndpoint extends WebSocketApplication 
implements SPIRegistered
             for (Map.Entry<String, List<String>> headerEntry : 
handshakeResponse.getHeaders().entrySet()) {
                 StringBuilder finalHeaderValue = new StringBuilder();
 
-                for(String headerValue : headerEntry.getValue()) {
-                    if(finalHeaderValue.length() != 0) {
+                for (String headerValue : headerEntry.getValue()) {
+                    if (finalHeaderValue.length() != 0) {
                         finalHeaderValue.append(", ");
                     }
 
@@ -270,7 +260,7 @@ public class TyrusEndpoint extends WebSocketApplication 
implements SPIRegistered
     }
 
     private HandshakeRequest createHandshakeRequest(final WebSocketRequest 
webSocketRequest) {
-        if(webSocketRequest instanceof RequestContext) {
+        if (webSocketRequest instanceof RequestContext) {
             final RequestContext requestContext = (RequestContext) 
webSocketRequest;
             // TYRUS-208; spec requests headers to be read only when passed 
to ServerEndpointConfig.Configurator#modifyHandshake.
             // TYRUS-211; spec requests parameterMap to be read only when 
passed to ServerEndpointConfig.Configurator#modifyHandshake.--- 
a/core/src/main/java/org/glassfish/tyrus/core/TyrusRemoteEndpoint.java
+++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusRemoteEndpoint.java
@@ -41,7 +41,6 @@ package org.glassfish.tyrus.core;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Future;
 
 import javax.websocket.CloseReason;
@@ -54,13 +53,14 @@ import org.glassfish.tyrus.websockets.WebSocket;
  * {@link SPIRemoteEndpoint} implementation.
  *
  * @author Danny Coward (danny.coward at oracle.com)
+ * @author Pavel Bucek (pavel.bucek at oracle.com)
  */
 public class TyrusRemoteEndpoint extends SPIRemoteEndpoint {
+
     private final WebSocket socket;
-    private final static ConcurrentHashMap<WebSocket, TyrusRemoteEndpoint> 
sockets = new ConcurrentHashMap<WebSocket, TyrusRemoteEndpoint>();
 
     /**
-     * Create remote endpoint. Used directly on client side to represent 
server endpoint.
+     * Create remote endpoint.
      *
      * @param socket to be used for sending messages.
      */
@@ -68,34 +68,6 @@ public class TyrusRemoteEndpoint extends SPIRemoteEndpoint 
{
         this.socket = socket;
     }
 
-    /**
-     * Get {@link TyrusRemoteEndpoint} instance. Used on server side for 
managing multiple connected clients.
-     *
-     * @param socket {@link WebSocket} instance used for lookup.
-     * @return Corresponding {@link TyrusRemoteEndpoint}.
-     */
-    public static TyrusRemoteEndpoint get(WebSocket socket) {
-        synchronized (sockets) {
-            TyrusRemoteEndpoint s = sockets.get(socket);
-            if (s == null) {
-                s = new TyrusRemoteEndpoint(socket);
-                sockets.put(socket, s);
-            }
-            return s;
-        }
-    }
-
-    /**
-     * Remove socket.
-     *
-     * @param socket socket instance to be removed.
-     */
-    public static void remove(WebSocket socket) {
-        synchronized (sockets) {
-            sockets.remove(socket);
-        }
-    }
-
     @Override
     public Future<DataFrame> sendText(String text) throws IOException {
         return this.socket.send(text);
@@ -136,4 +108,21 @@ public class TyrusRemoteEndpoint extends 
SPIRemoteEndpoint {
     public void setWriteTimeout(long timeoutMs) {
         socket.setWriteTimeout(timeoutMs);
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof TyrusRemoteEndpoint)) return false;
+
+        TyrusRemoteEndpoint that = (TyrusRemoteEndpoint) o;
+
+        if (!socket.equals(that.socket)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return socket.hashCode();
+    }
 }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/DefaultWebSocket.java
+++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java
@@ -38,7 +38,7 @@
  * holder.
  */
 
-package org.glassfish.tyrus.websockets;
+package org.glassfish.tyrus.core;
 
 import java.util.EnumSet;
 import java.util.Queue;
@@ -47,11 +47,20 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Future;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.glassfish.tyrus.websockets.DataFrame;
+import org.glassfish.tyrus.websockets.ProtocolHandler;
+import org.glassfish.tyrus.websockets.WebSocket;
+import org.glassfish.tyrus.websockets.WebSocketListener;
 import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
 import org.glassfish.tyrus.websockets.frametypes.PingFrameType;
 import org.glassfish.tyrus.websockets.frametypes.PongFrameType;
 
-public class DefaultWebSocket implements WebSocket {
+/**
+ * Tyrus implementation of {@link WebSocket}.
+ *
+ * Instance of this class represents one bi-directional websocket connection.
+ */
+public class TyrusWebSocket implements WebSocket {
     private final Queue<WebSocketListener> listeners = new 
ConcurrentLinkedQueue<WebSocketListener>();
     private final ProtocolHandler protocolHandler;
 
@@ -64,8 +73,14 @@ public class DefaultWebSocket implements WebSocket {
     private final EnumSet<State> connected = EnumSet.range(State.CONNECTED, 
State.CLOSING);
     private final AtomicReference<State> state = new 
AtomicReference<State>(State.NEW);
 
-    public DefaultWebSocket(final ProtocolHandler protocolHandler,
-                            final WebSocketListener... listeners) {
+    /**
+     * TODO.
+     *
+     * @param protocolHandler
+     * @param listeners
+     */
+    public TyrusWebSocket(final ProtocolHandler protocolHandler,
+                          final WebSocketListener... listeners) {
         this.protocolHandler = protocolHandler;
         for (WebSocketListener listener : listeners) {
             add(listener);
@@ -239,5 +254,4 @@ public class DefaultWebSocket implements WebSocket {
             throw new RuntimeException("Socket is not connected.");
         }
     }
-
 }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocket.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocket.java
@@ -305,5 +305,4 @@ public interface WebSocket {
      * @param timeoutMs timeout in milliseconds.
      */
     public abstract void setWriteTimeout(long timeoutMs);
-
 }--- 
a/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocketApplication.java
+++ 
b/protocol/websocket/src/main/java/org/glassfish/tyrus/websockets/WebSocketApplication.java
@@ -42,6 +42,7 @@ package org.glassfish.tyrus.websockets;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 import org.glassfish.tyrus.websockets.draft06.ClosingFrame;
@@ -58,7 +59,7 @@ public abstract class WebSocketApplication implements 
WebSocketListener {
     /*
      * WebSockets registered with this application.
      */
-    private final ConcurrentHashMap<WebSocket, Boolean> sockets =
+    private final Map<WebSocket, Boolean> sockets =
             new ConcurrentHashMap<WebSocket, Boolean>();
 
     private final List<Extension> supportedExtensions = new 
ArrayList<Extension>();
@@ -74,11 +75,8 @@ public abstract class WebSocketApplication implements 
WebSocketListener {
      *                      {@link WebSocket}.
      * @return TODO
      */
-    public WebSocket createSocket(final ProtocolHandler handler,
-                                  final WebSocketListener... listeners) {
-        return new DefaultWebSocket(handler, listeners);
-
-    }
+    public abstract WebSocket createSocket(final ProtocolHandler handler,
+                                  final WebSocketListener... listeners);
 
     /**
      * When a {@link 
WebSocket#onClose(org.glassfish.tyrus.websockets.draft06.ClosingFrame)} is 
invoked, the {@link WebSocket}--- 
a/protocol/websocket/src/test/java/org/glassfish/tyrus/websockets/uri/TestWebSocketApplication.java
+++ 
b/protocol/websocket/src/test/java/org/glassfish/tyrus/websockets/uri/TestWebSocketApplication.java
@@ -39,8 +39,10 @@
  */
 package org.glassfish.tyrus.websockets.uri;
 
+import org.glassfish.tyrus.websockets.ProtocolHandler;
 import org.glassfish.tyrus.websockets.WebSocket;
 import org.glassfish.tyrus.websockets.WebSocketApplication;
+import org.glassfish.tyrus.websockets.WebSocketListener;
 import org.glassfish.tyrus.websockets.WebSocketRequest;
 import org.glassfish.tyrus.websockets.WebSocketResponse;
 
@@ -65,6 +67,11 @@ public class TestWebSocketApplication extends 
WebSocketApplication {
     }
 
     @Override
+    public WebSocket createSocket(ProtocolHandler handler, 
WebSocketListener... listeners) {
+        return null;
+    }
+
+    @Override
     public String getPath() {
         return path;
     }--- 
a/tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/MockWebSocketClient.java
+++ 
b/tests/e2e/src/test/java/org/glassfish/tyrus/test/e2e/MockWebSocketClient.java
@@ -155,9 +155,6 @@ class MockWebSocketClient implements WebSocket {
     }
 
     @Override
-    public void setWriteTimeout(long timeoutMs) {}
-
-    public void connect() {
-        listener.onConnect(this);
+    public void setWriteTimeout(long timeoutMs) {
     }
 }

--- a/core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java
+++ b/core/src/main/java/org/glassfish/tyrus/core/TyrusWebSocket.java
@@ -74,10 +74,10 @@ public class TyrusWebSocket implements WebSocket {
     private final AtomicReference<State> state = new 
AtomicReference<State>(State.NEW);
 
     /**
-     * TODO.
+     * Create new instance, set {@link ProtocolHandler} and register {@link 
WebSocketListener WebSocketListeners}.
      *
-     * @param protocolHandler
-     * @param listeners
+     * @param protocolHandler used for writing data (sending).
+     * @param listeners notifies registered endpoints about incoming events.
      */
     public TyrusWebSocket(final ProtocolHandler protocolHandler,
                           final WebSocketListener... listeners) {

--- a/docs/jsr/websocket-jsr-proposal.html
+++ b/docs/jsr/websocket-jsr-proposal.html
@@ -3,7 +3,7 @@
 
     DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
-    Copyright (c) 2011-2012 Oracle and/or its affiliates. All rights 
reserved.
+    Copyright (c) 2011-2013 Oracle and/or its affiliates. All rights 
reserved.
 
     The contents of this file are subject to the terms of either the GNU
     General Public License Version 2 only ("GPL") or the Common 
Development--- a/etc/config/copyright-exclude
+++ b/etc/config/copyright-exclude
@@ -33,3 +33,4 @@ nbactions.xml
 /LICENSE.html
 /LICENSE.txt
 README.txt
+README.md--- a/pom.xml
+++ b/pom.xml
@@ -255,7 +255,7 @@
                     <configuration>
                         
<excludeFile>etc/config/copyright-exclude</excludeFile>
                         <!--svn|mercurial|git - defaults to svn-->
-                        <scm>svn</scm>
+                        <scm>git</scm>
                         <!-- turn on/off debugging -->
                         <debug>off</debug>
                         <!-- skip files not under SCM-->





[tyrus~code:fd16b7ef] copyright check

jerseyrobot 08/07/2013
 
 
Close
loading
Please Confirm
Close