geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578309 - /geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/
Date Fri, 21 Sep 2007 22:45:32 GMT
Author: jdillon
Date: Fri Sep 21 15:45:29 2007
New Revision: 578309

URL: http://svn.apache.org/viewvc?rev=578309&view=rev
Log:
Tidy up exceptions and logging, added more javadoc

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/InvalidRequestMappingException.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/MissingRequestTimeoutException.java
  (with props)
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
      - copied, changed from r578264, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportException.java
Modified:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/package-info.java

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/DuplicateRequestException.java
Fri Sep 21 15:45:29 2007
@@ -20,7 +20,7 @@
 package org.apache.geronimo.gshell.remote.request;
 
 /**
- * ???
+ * Thrown to indicate an operation was attempted for a duplicate request.
  *
  * @version $Rev$ $Date$
  */
@@ -28,6 +28,6 @@
     extends RequestException
 {
     public DuplicateRequestException(final Request req) {
-        super("Duplicate request for ID: " + req.getId(), req);
+        super("Duplicate request: " + req.getId());
     }
 }

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/InvalidRequestMappingException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/InvalidRequestMappingException.java?rev=578309&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/InvalidRequestMappingException.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/InvalidRequestMappingException.java
Fri Sep 21 15:45:29 2007
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+/**
+ * Thrown to indicate that an operation was attempted for an invalid request mapping.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidRequestMappingException
+    extends RequestException
+{
+    public InvalidRequestMappingException(final Object id) {
+        super("Invalid request mapping: " + id);
+    }
+}
\ No newline at end of file

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

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

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

Added: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/MissingRequestTimeoutException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/MissingRequestTimeoutException.java?rev=578309&view=auto
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/MissingRequestTimeoutException.java
(added)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/MissingRequestTimeoutException.java
Fri Sep 21 15:45:29 2007
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.gshell.remote.request;
+
+/**
+ * Thrown to indicate that a timeout operation was attempted for a request with no timeout
scheduled.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MissingRequestTimeoutException
+    extends RequestException
+{
+    public MissingRequestTimeoutException(final Object id) {
+        super("Missing request timeout: " + id);
+    }
+}
\ No newline at end of file

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

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

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

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Request.java
Fri Sep 21 15:45:29 2007
@@ -23,7 +23,6 @@
 // NOTE: Snatched and massaged from Apache Mina
 //
 
-import java.util.NoSuchElementException;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -35,7 +34,7 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * ???
+ * Represents a request message.
  *
  * @version $Rev$ $Date$
  */
@@ -55,12 +54,9 @@
 
     private volatile boolean endOfResponses;
 
-    private boolean signaled;
+    private volatile boolean signaled;
 
     public Request(final Message message, long timeout, final TimeUnit timeoutUnit) {
-        assert message != null;
-        assert timeoutUnit != null;
-
         this.message = message;
         this.timeout = timeout;
         this.timeoutUnit = timeoutUnit;
@@ -113,11 +109,11 @@
     public Response awaitResponse() throws RequestTimeoutException, InterruptedException
{
         chechEndOfResponses();
 
-        log.debug("Waiting for the response...");
+        log.debug("Waiting for response");
 
         Response resp = decodeResponse(responses.take());
 
-        log.debug("Got response: {}", resp);
+        log.trace("Got response: {}", resp);
 
         return resp;
     }
@@ -125,15 +121,17 @@
     public Response awaitResponse(final long timeout, final TimeUnit unit) throws RequestTimeoutException,
InterruptedException {
         chechEndOfResponses();
 
-        log.debug("Polling for the response...");
+        log.debug("Polling for response");
 
         Response resp = decodeResponse(responses.poll(timeout, unit));
 
-        if (resp != null) {
-            log.debug("Got response: {}", resp);
-        }
-        else {
-            log.debug("Operation timed out before the response was signaled");
+        if (log.isTraceEnabled()) {
+            if (resp != null) {
+                log.trace("Got response: {}", resp);
+            }
+            else {
+                log.trace("Operation timed out before the response was signaled");
+            }
         }
 
         return resp;
@@ -165,7 +163,7 @@
 
     private void chechEndOfResponses() {
         if (endOfResponses && responses.isEmpty()) {
-            throw new NoSuchElementException("All responses has been retrieved already.");
+            throw new IllegalStateException("All responses has been retrieved already");
         }
     }
 
@@ -197,7 +195,7 @@
         assert e != null;
 
         synchronized (mutex) {
-            log.debug("Signal timeout: " + e, e);
+            log.debug("Signal timeout: {}", e);
 
             setResponse(e);
 

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
(from r578264, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportException.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportException.java&r1=578264&r2=578309&rev=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/TransportException.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestException.java
Fri Sep 21 15:45:29 2007
@@ -17,31 +17,31 @@
  * under the License.
  */
 
-package org.apache.geronimo.gshell.remote.transport;
+package org.apache.geronimo.gshell.remote.request;
 
 /**
- * ???
+ * Thrown to indicate a request operation failed.
  *
  * @version $Rev$ $Date$
  */
-public class TransportException
+public class RequestException
     extends RuntimeException
 {
     private static final long serialVersionUID = 1;
 
-    public TransportException(final String msg, final Throwable cause) {
+    public RequestException(final String msg, final Throwable cause) {
         super(msg, cause);
     }
 
-    public TransportException(final String msg) {
+    public RequestException(final String msg) {
         super(msg);
     }
 
-    public TransportException(final Throwable cause) {
+    public RequestException(final Throwable cause) {
         super(cause);
     }
 
-    public TransportException() {
+    public RequestException() {
         super();
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestManager.java
Fri Sep 21 15:45:29 2007
@@ -31,7 +31,7 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * ???
+ * Manages per-session state and timeouts for requests.
  *
  * @version $Rev$ $Date$
  */
@@ -49,42 +49,52 @@
     // TODO: Lock on Request.getMutex()
     //
 
+    /**
+     * Helper to make sure that when calling methods that take an Object for the request
ID that the requst object is not given by accident.
+     */
+    private void ensureValidRequestId(final Object obj) {
+        if (obj instanceof Request) {
+            throw new IllegalArgumentException("Expecting a request ID, not a request");
+        }
+    }
+
     public boolean contains(final Object id) {
         assert id != null;
 
-        if (id instanceof Request) {
-            throw new IllegalArgumentException("Expecting a request ID, not a request");
-        }
+        ensureValidRequestId(id);
 
         return requests.containsKey(id);
     }
 
-    public boolean contains(final Request req) {
-        assert req != null;
+    public boolean contains(final Request request) {
+        assert request != null;
 
-        return contains(req.getId());
+        return contains(request.getId());
     }
 
-    public void add(final Request req) {
-        assert req != null;
+    public void add(final Request request) {
+        assert request != null;
 
-        if (contains(req)) {
-            throw new DuplicateRequestException(req);
+        if (contains(request)) {
+            throw new DuplicateRequestException(request);
         }
 
-        Object id = req.getId();
+        Object id = request.getId();
 
-        log.debug("Adding request for ID: {}", id);
+        if (log.isTraceEnabled()) {
+            log.trace("Adding: {}", request);
+        }
+        else {
+            log.debug("Adding: {}", id);
+        }
 
-        requests.put(id, req);
+        requests.put(id, request);
     }
 
     public Request get(final Object id) {
         assert id != null;
 
-        if (id instanceof Request) {
-            throw new IllegalArgumentException("Expecting a request ID, not a request");
-        }
+        ensureValidRequestId(id);
 
         return requests.get(id);
     }
@@ -92,11 +102,9 @@
     public Request remove(final Object id) {
         assert id != null;
 
-        if (id instanceof Request) {
-            throw new IllegalArgumentException("Expecting a request ID, not a request");
-        }
+        ensureValidRequestId(id);
 
-        log.debug("Removing request for ID: {}", id);
+        log.debug("Removing: {}", id);
 
         return requests.remove(id);
     }
@@ -107,7 +115,7 @@
         l = requests.size();
 
         if (l > 0) {
-            log.warn("Clearing requests; purging " + l + " request(s)");
+            log.warn("Purging " + l + " request(s)");
         }
 
         requests.clear();
@@ -115,7 +123,7 @@
         l = timeouts.size();
 
         if (l > 0) {
-            log.warn("Clearing timeouts; purging " + l + " timeouts(s)");
+            log.warn("Purging " + l + " timeouts(s)");
         }
 
         timeouts.clear();
@@ -135,10 +143,15 @@
         Object id = request.getId();
 
         if (request != get(id)) {
-            throw new IllegalStateException("Found invalid request mapping for ID: " + id);
+            throw new InvalidRequestMappingException(id);
         }
 
-        log.debug("Scheduling timeout for request ID: {}", id);
+        if (log.isTraceEnabled()) {
+            log.trace("Scheduling: {}", request);
+        }
+        else {
+            log.debug("Scheduling: {}", id);
+        }
 
         TimeoutTask task = new TimeoutTask(request);
 
@@ -157,14 +170,19 @@
         TimeoutTask task = timeouts.remove(request);
 
         if (task == null) {
-            throw new IllegalStateException("Request ID has no timeout bound: " + id);
+            throw new MissingRequestTimeoutException(id);
         }
 
         if (remove(id) != request) {
-            throw new IllegalStateException("Found invalid request mapping for ID: " + id);
+            throw new InvalidRequestMappingException(id);
         }
 
-        log.debug("Canceling timeout for request ID: {}", id);
+        if (log.isTraceEnabled()) {
+            log.trace("Canceling: {}", request);
+        }
+        else {
+            log.debug("Canceling: {}", id);
+        }
 
         ScheduledFuture<?> sf = task.getTimeoutFuture();
 
@@ -178,20 +196,23 @@
 
         Object id = request.getId();
 
-        log.debug("Triggering timeout for request ID: {}", id);
+        if (log.isTraceEnabled()) {
+            log.trace("Triggering: {}", request);
+        }
+        else {
+            log.debug("Triggering: {}", id);
+        }
 
         TimeoutTask task = timeouts.remove(request);
 
         if (task == null) {
-            throw new IllegalStateException("Request ID has no timeout bound: " + id);
+            throw new MissingRequestTimeoutException(id);
         }
 
         if (remove(id) != request) {
-            throw new IllegalStateException("Found invalid request mapping for ID: " + id);
+            throw new InvalidRequestMappingException(id);
         }
 
-        log.debug("Canceling timeout for request ID: {}", id);
-
         // If the request has not been signaled, then its a timeout :-(
         if (!request.isSignaled()) {
             // noinspection ThrowableInstanceNeverThrown
@@ -199,9 +220,9 @@
         }
     }
 
-    public void timeoutAll() {
-        log.debug("Timing out all pending tasks");
-
+    private void timeoutAll() {
+        log.debug("Timing out all pending requests");
+        
         Request[] requests = timeouts.keySet().toArray(new Request[timeouts.size()]);
 
         for (Request request : requests) {
@@ -210,8 +231,6 @@
     }
 
     public void close() {
-        log.debug("Closing");
-
         timeoutAll();
         clear();
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestResponseFilter.java
Fri Sep 21 15:45:29 2007
@@ -29,7 +29,7 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * ???
+ * Provides synchronous request/response messaging.
  *
  * @version $Rev$ $Date$
  */
@@ -50,24 +50,32 @@
         this(Executors.newCachedThreadPool());
     }
 
-    public void sessionCreated(NextFilter nextFilter, IoSession session) throws Exception
{
-        log.debug("Creating request manager");
-
+    /**
+     * Set up the request manager instance for the session.
+     */
+    @Override
+    public void sessionCreated(final NextFilter nextFilter, final IoSession session) throws
Exception {
         RequestManager.bind(session, new RequestManager());
 
         nextFilter.sessionCreated(session);
     }
 
+    /**
+     * Close the request manager instance for the session.
+     */
+    @Override
     public void sessionClosed(final NextFilter nextFilter, final IoSession session) throws
Exception {
-        log.debug("Closing request manager");
-
-        final RequestManager manager = RequestManager.unbind(session);
+        RequestManager manager = RequestManager.unbind(session);
 
         manager.close();
         
         nextFilter.sessionClosed(session);
     }
 
+    /**
+     * When a request is sent, register it with the request manager.
+     */
+    @Override
     public void filterWrite(final NextFilter nextFilter, final IoSession session, final WriteRequest
writeRequest) throws Exception {
         Object message = writeRequest.getMessage();
 
@@ -82,6 +90,10 @@
         nextFilter.filterWrite(session, writeRequest);
     }
 
+    /**
+     * When a response message has been received, cancel its timeout and signal the request.
+     */
+    @Override
     public void messageReceived(final NextFilter nextFilter, final IoSession session, final
Object message) throws Exception {
         Message msg = null;
 
@@ -121,26 +133,11 @@
         }
     }
 
-    /*
-    public void messageSent(final NextFilter nextFilter, final IoSession session, final WriteRequest
writeRequest) throws Exception {
-        if (writeRequest instanceof RequestWriteRequest) {
-            // Setup a timeout for the request now that its been sent
-            RequestWriteRequest wr = (RequestWriteRequest) writeRequest;
-            Request request = wr.getRequest();
-
-            RequestManager manager = RequestManager.lookup(session);
-            manager.schedule(request);
-
-            // And forward the original write request
-            nextFilter.messageSent(session, wr.getWriteRequest());
-        }
-        else {
-            nextFilter.messageSent(session, writeRequest);
-        }
-    }
-    */
-
-    public void messageSent(NextFilter nextFilter, IoSession session, Object message) throws
Exception {
+    /**
+     * Once the reqeust message has been sent, schedule a timeout.
+     */
+    @Override
+    public void messageSent(final NextFilter nextFilter, final IoSession session, final Object
message) throws Exception {
         if (message instanceof Request) {
             Request request = (Request) message;
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/RequestTimeoutException.java
Fri Sep 21 15:45:29 2007
@@ -19,12 +19,8 @@
 
 package org.apache.geronimo.gshell.remote.request;
 
-//
-// NOTE: Snatched and massaged from Apache Mina
-//
-
 /**
- * ???
+ * Thrown to indicate that a request has been timed out.
  *
  * @version $Rev$ $Date$
  */
@@ -33,7 +29,7 @@
 {
     private static final long serialVersionUID = 1;
 
-    public RequestTimeoutException(final Request request) {
-        super("Request timed out: " + request, request);
+    public RequestTimeoutException(final Request req) {
+        super("Request timed out for ID: " + req.getId());
     }
 }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Requestor.java
Fri Sep 21 15:45:29 2007
@@ -30,7 +30,7 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * ???
+ * Provides support to send a request and receive it's response.
  *
  * @version $Rev$ $Date$
  */
@@ -49,8 +49,6 @@
     private final TimeUnit unit;
 
     private Requestor(final MessageWriter writer, final long timeout, final TimeUnit unit)
{
-        assert writer != null;
-
         this.writer = writer;
         this.timeout = timeout;
         this.unit = unit;
@@ -93,20 +91,8 @@
 
         Request req = wf.getRequest();
 
-        //
-        // HACK:
-        //
-        
-        Response resp = req.awaitResponse(30, TimeUnit.SECONDS);
-
-        //
-        // HACK:
-        //
-        
-        if (resp == null) {
-            throw new IllegalStateException("Failed to read response");
-        }
-        
+        Response resp = req.awaitResponse();
+
         return resp.getMessage();
     }
 
@@ -118,6 +104,9 @@
     // MessageWriter
     //
 
+    /**
+     * An abstraction to allow an {@link IoSession} or {@link Transport} instance to be used
to send messages.
+     */
     private static interface MessageWriter
     {
         WriteFuture write(Object message) throws Exception;
@@ -128,11 +117,11 @@
     {
         private final IoSession session;
 
-        public SessionMessageWriter(IoSession session) {
+        public SessionMessageWriter(final IoSession session) {
             this.session = session;
         }
 
-        public WriteFuture write(Object message) throws Exception {
+        public WriteFuture write(final Object message) throws Exception {
             return session.write(message);
         }
     }
@@ -142,11 +131,11 @@
     {
         private final Transport transport;
 
-        public TransportMessageWriter(Transport transport) {
+        public TransportMessageWriter(final Transport transport) {
             this.transport = transport;
         }
 
-        public WriteFuture write(Object message) throws Exception {
+        public WriteFuture write(final Object message) throws Exception {
             return transport.send(message);
         }
     }
@@ -163,9 +152,6 @@
         private final Request request;
 
         public RequestWriteFuture(final WriteFuture wf, final Request req) {
-            assert wf != null;
-            assert req != null;
-
             this.delegate = wf;
             this.request = req;
         }
@@ -174,15 +160,11 @@
             return request;
         }
 
-        //
-        // WriteFuture
-        //
-
         public boolean isWritten() {
             return delegate.isWritten();
         }
 
-        public void setWritten(boolean written) {
+        public void setWritten(final boolean written) {
             delegate.setWritten(written);
         }
 
@@ -194,19 +176,19 @@
             delegate.join();
         }
 
-        public boolean join(long timeoutInMillis) {
-            return delegate.join(timeoutInMillis);
+        public boolean join(final long timeout) {
+            return delegate.join(timeout);
         }
 
         public boolean isReady() {
             return delegate.isReady();
         }
 
-        public void addListener(IoFutureListener listener) {
+        public void addListener(final IoFutureListener listener) {
             delegate.addListener(listener);
         }
 
-        public void removeListener(IoFutureListener listener) {
+        public void removeListener(final IoFutureListener listener) {
             delegate.removeListener(listener);
         }
     }

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/Response.java
Fri Sep 21 15:45:29 2007
@@ -28,7 +28,7 @@
 //
 
 /**
- * ???
+ * Represents a response message.
  *
  * @version $Rev$ $Date$
  */
@@ -41,27 +41,11 @@
     private final Message message;
 
     public Response(final Request request, final Message message, final Type type) {
-        assert request != null;
-        assert message != null;
-        assert type != null;
-
         this.request = request;
         this.type = type;
         this.message = message;
     }
 
-    public Request getRequest() {
-        return request;
-    }
-
-    public Type getType() {
-        return type;
-    }
-
-    public Message getMessage() {
-        return message;
-    }
-
     public int hashCode() {
         return getRequest().getId().hashCode();
     }
@@ -80,11 +64,22 @@
         Response resp = (Response) obj;
 
         return getRequest().equals(resp.getRequest()) && getType().equals(resp.getType());
-
     }
 
     public String toString() {
         return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+    }
+
+    public Request getRequest() {
+        return request;
+    }
+
+    public Type getType() {
+        return type;
+    }
+
+    public Message getMessage() {
+        return message;
     }
 
     //

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/package-info.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/package-info.java?rev=578309&r1=578308&r2=578309&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/package-info.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/request/package-info.java
Fri Sep 21 15:45:29 2007
@@ -18,7 +18,7 @@
  */
 
 /**
- * Request response support for messages.
+ * Provides support for synchronous request/response messaging.
  *
  * @version $Rev$ $Date$
  */



Mime
View raw message