geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r580691 - /geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/
Date Sun, 30 Sep 2007 10:36:38 GMT
Author: jdillon
Date: Sun Sep 30 03:36:37 2007
New Revision: 580691

URL: http://svn.apache.org/viewvc?rev=580691&view=rev
Log:
Fixed a bug in resp handling, rename Request -> RequestHandle, Response -> ResponseHandle
to be clear these aren't really messages, just holders

Added:
    geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java
  (contents, props changed)
      - copied, changed from r580231, geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java
    geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java
  (contents, props changed)
      - copied, changed from r580231, geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Response.java
Removed:
    geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java
    geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Response.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
    geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
    geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java

Copied: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java
(from r580231, geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java?p2=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java&p1=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java&r1=580231&r2=580691&rev=580691&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Request.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java
Sun Sep 30 03:36:37 2007
@@ -37,7 +37,7 @@
  *
  * @version $Rev$ $Date$
  */
-public class Request
+public class RequestHandle
 {
     private final Logger log = LoggerFactory.getLogger(getClass());
 
@@ -53,7 +53,7 @@
 
     private volatile boolean signaled;
 
-    public Request(final Message message, final Duration timeout) {
+    public RequestHandle(final Message message, final Duration timeout) {
         assert message != null;
         assert timeout != null;
 
@@ -61,7 +61,7 @@
         this.timeout = timeout;
     }
 
-    public Request(final Message message, long timeout, final TimeUnit timeoutUnit) {
+    public RequestHandle(final Message message, long timeout, final TimeUnit timeoutUnit)
{
         this(message, new Duration(timeout, timeoutUnit));
     }
 
@@ -76,11 +76,11 @@
         else if (obj == null) {
             return false;
         }
-        else if (!(obj instanceof Request)) {
+        else if (!(obj instanceof RequestHandle)) {
             return false;
         }
 
-        Request request = (Request) obj;
+        RequestHandle request = (RequestHandle) obj;
 
         return getId().equals(request.getId());
     }
@@ -109,24 +109,24 @@
         return !responses.isEmpty();
     }
 
-    public Response awaitResponse() throws RequestTimeoutException, InterruptedException
{
+    public ResponseHandle awaitResponse() throws RequestTimeoutException, InterruptedException
{
         chechEndOfResponses();
 
         log.debug("Waiting for response");
 
-        Response resp = decodeResponse(responses.take());
+        ResponseHandle resp = decodeResponse(responses.take());
 
         log.trace("Received response: {}", resp);
 
         return resp;
     }
 
-    public Response awaitResponse(final long timeout, final TimeUnit unit) throws RequestTimeoutException,
InterruptedException {
+    public ResponseHandle awaitResponse(final long timeout, final TimeUnit unit) throws RequestTimeoutException,
InterruptedException {
         chechEndOfResponses();
 
         log.debug("Polling for response");
 
-        Response resp = decodeResponse(responses.poll(timeout, unit));
+        ResponseHandle resp = decodeResponse(responses.poll(timeout, unit));
 
         if (log.isTraceEnabled()) {
             if (resp != null) {
@@ -140,7 +140,7 @@
         return resp;
     }
 
-    public Response awaitResponseUninterruptibly() throws RequestTimeoutException {
+    public ResponseHandle awaitResponseUninterruptibly() throws RequestTimeoutException {
         while (true) {
             try {
                 return awaitResponse();
@@ -149,9 +149,9 @@
         }
     }
 
-    private Response decodeResponse(final Object obj) {
-        if (obj instanceof Response) {
-            return (Response) obj;
+    private ResponseHandle decodeResponse(final Object obj) {
+        if (obj instanceof ResponseHandle) {
+            return (ResponseHandle) obj;
         }
         else if (obj == null) {
             return null;
@@ -176,7 +176,7 @@
         responses.add(answer);
     }
 
-    void signal(final Response response) {
+    void signal(final ResponseHandle response) {
         assert response != null;
 
         lock.lock();
@@ -191,7 +191,7 @@
 
             queueResponse(response);
 
-            if (response.getType() != Response.Type.PARTIAL) {
+            if (response.getType() != ResponseHandle.Type.PARTIAL) {
                 endOfResponses = true;
             }
         }

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestHandle.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java?rev=580691&r1=580690&r2=580691&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestManager.java
Sun Sep 30 03:36:37 2007
@@ -88,7 +88,18 @@
         return reg;
     }
 
-    public void register(final Request request) {
+    public boolean contains(final Message.ID id) {
+        lock.lock();
+
+        try {
+            return registrations.containsKey(id);
+        }
+        finally {
+            lock.unlock();
+        }
+    }
+
+    public void register(final RequestHandle request) {
         assert request != null;
 
         lock.lock();
@@ -111,7 +122,7 @@
         }
     }
 
-    public Request lookup(final Message.ID id) {
+    public RequestHandle lookup(final Message.ID id) {
         assert id != null;
 
         lock.lock();
@@ -126,7 +137,7 @@
         }
     }
 
-    public Request deregister(final Message.ID id) {
+    public RequestHandle deregister(final Message.ID id) {
         assert id != null;
 
         lock.lock();
@@ -158,6 +169,7 @@
             log.debug("Activated: {}", reg);
         }
         catch (NotRegisteredException e) {
+            // Sometimes we receive responses to requests faster than we can register them
             log.debug("Ignoring activation; request not registered: {}", id);
         }
         finally {
@@ -242,13 +254,13 @@
 
     private class Registration
     {
-        public final Request request;
+        public final RequestHandle request;
 
         public RegistrationState state = RegistrationState.PENDING;
 
         private ScheduledFuture<?> timeoutFuture;
 
-        public Registration(final Request request) {
+        public Registration(final RequestHandle request) {
             assert request != null;
 
             this.request = request;

Modified: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java?rev=580691&r1=580690&r2=580691&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/RequestResponseFilter.java
Sun Sep 30 03:36:37 2007
@@ -64,8 +64,8 @@
     public void filterWrite(final NextFilter nextFilter, final IoSession session, WriteRequest
writeRequest) throws Exception {
         Object message = writeRequest.getMessage();
 
-        if (message instanceof Request) {
-            Request request = (Request) message;
+        if (message instanceof RequestHandle) {
+            RequestHandle request = (RequestHandle) message;
 
             RequestManager manager = RequestManager.BINDER.lookup(session);
 
@@ -93,14 +93,14 @@
             id = msg.getCorrelationId();
         }
 
-        // If we have a correlation id, then we can process the response
-        if (id != null) {
-            RequestManager manager = RequestManager.BINDER.lookup(session);
+        RequestManager manager = RequestManager.BINDER.lookup(session);
 
-            Request request = manager.deregister(id);
+        // If we have a correlation id and its been registered, then we can process the response
+        if (id != null && manager.contains(id)) {
+            RequestHandle request = manager.deregister(id);
 
             // Setup the response and signal the request
-            Response response = new Response(request, msg, Response.Type.WHOLE);
+            ResponseHandle response = new ResponseHandle(request, msg, ResponseHandle.Type.WHOLE);
 
             request.signal(response);
 
@@ -117,8 +117,8 @@
      */
     @Override
     public void messageSent(final NextFilter nextFilter, final IoSession session, final Object
message) throws Exception {
-        if (message instanceof Request) {
-            Request request = (Request) message;
+        if (message instanceof RequestHandle) {
+            RequestHandle request = (RequestHandle) message;
 
             RequestManager manager = RequestManager.BINDER.lookup(session);
 

Modified: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java?rev=580691&r1=580690&r2=580691&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Requestor.java
Sun Sep 30 03:36:37 2007
@@ -72,7 +72,7 @@
         assert msg != null;
         assert timeout != null;
 
-        Request req = new Request(msg, timeout.getValue(), timeout.getUnit());
+        RequestHandle req = new RequestHandle(msg, timeout.getValue(), timeout.getUnit());
 
         WriteFuture wf = session.write(req);
 
@@ -86,9 +86,9 @@
     public Message request(final Message msg, final Duration timeout) throws Exception {
         RequestWriteFuture wf = submit(msg, timeout);
 
-        Request req = wf.getRequest();
+        RequestHandle req = wf.getRequest();
 
-        Response resp = req.awaitResponse();
+        ResponseHandle resp = req.awaitResponse();
 
         return resp.getMessage();
     }
@@ -106,14 +106,14 @@
     {
         private final WriteFuture delegate;
 
-        private final Request request;
+        private final RequestHandle request;
 
-        public RequestWriteFuture(final WriteFuture wf, final Request req) {
+        public RequestWriteFuture(final WriteFuture wf, final RequestHandle req) {
             this.delegate = wf;
             this.request = req;
         }
 
-        public Request getRequest() {
+        public RequestHandle getRequest() {
             return request;
         }
 

Copied: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java
(from r580231, geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Response.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java?p2=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java&p1=geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Response.java&r1=580231&r2=580691&rev=580691&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/Response.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java
Sun Sep 30 03:36:37 2007
@@ -32,15 +32,15 @@
  *
  * @version $Rev$ $Date$
  */
-public class Response
+public class ResponseHandle
 {
-    private final Request request;
+    private final RequestHandle request;
 
     private final Type type;
 
     private final Message message;
 
-    public Response(final Request request, final Message message, final Type type) {
+    public ResponseHandle(final RequestHandle request, final Message message, final Type
type) {
         this.request = request;
         this.type = type;
         this.message = message;
@@ -57,11 +57,11 @@
         else if (obj == null) {
             return false;
         }
-        else if (!(obj instanceof Response)) {
+        else if (!(obj instanceof ResponseHandle)) {
             return false;
         }
 
-        Response resp = (Response) obj;
+        ResponseHandle resp = (ResponseHandle) obj;
 
         return getRequest().equals(resp.getRequest()) && getType().equals(resp.getType());
     }
@@ -74,7 +74,7 @@
                 .toString();
     }
 
-    public Request getRequest() {
+    public RequestHandle getRequest() {
         return request;
     }
 

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/gshell/trunk/gshell-whisper/src/main/java/org/apache/geronimo/gshell/whisper/request/ResponseHandle.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message