geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578523 - in /geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote: request/ transport/ transport/base/ util/
Date Sat, 22 Sep 2007 23:13:56 GMT
Author: jdillon
Date: Sat Sep 22 16:13:54 2007
New Revision: 578523

URL: http://svn.apache.org/viewvc?rev=578523&view=rev
Log:
Renamed TimeValue to Duration and hooked it up as the preferred container for timeout duration
data, also hooked it up to our marshalling muck

Added:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/Duration.java
  (contents, props changed)
      - copied, changed from r578519, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java
Removed:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java
Modified:
    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/Requestor.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java

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=578523&r1=578522&r2=578523&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
Sat Sep 22 16:13:54 2007
@@ -32,6 +32,7 @@
 import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
 import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
 import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.util.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -50,18 +51,22 @@
 
     private final Message message;
 
-    private final long timeout;
-
-    private final TimeUnit timeoutUnit;
+    private final Duration timeout;
 
     private volatile boolean endOfResponses;
 
     private volatile boolean signaled;
 
-    public Request(final Message message, long timeout, final TimeUnit timeoutUnit) {
+    public Request(final Message message, final Duration timeout) {
+        assert message != null;
+        assert timeout != null;
+
         this.message = message;
         this.timeout = timeout;
-        this.timeoutUnit = timeoutUnit;
+    }
+
+    public Request(final Message message, long timeout, final TimeUnit timeoutUnit) {
+        this(message, new Duration(timeout, timeoutUnit));
     }
 
     public int hashCode() {
@@ -100,12 +105,8 @@
         return getMessage().getId();
     }
 
-    public long getTimeout() {
+    public Duration getTimeout() {
         return timeout;
-    }
-
-    public TimeUnit getTimeoutUnit() {
-        return timeoutUnit;
     }
 
     public boolean hasResponse() {

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=578523&r1=578522&r2=578523&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
Sat Sep 22 16:13:54 2007
@@ -33,13 +33,14 @@
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.geronimo.gshell.remote.session.SessionAttributeBinder;
 import org.apache.geronimo.gshell.remote.util.NamedThreadFactory;
+import org.apache.geronimo.gshell.remote.util.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * ???
  *
- * @version $Rev$ $Date$
+ * @version $Rev: 578446 $ $Date: 2007-09-22 07:24:23 -0700 (Sat, 22 Sep 2007) $
  */
 public class RequestManager
 {
@@ -264,7 +265,9 @@
                     }
                 };
 
-                timeoutFuture = scheduler.schedule(task, request.getTimeout(), request.getTimeoutUnit());
+                Duration timeout = request.getTimeout();
+
+                timeoutFuture = scheduler.schedule(task, timeout.getValue(), timeout.getUnit());
 
                 state = RegistrationState.ACTIVE;
             }

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=578523&r1=578522&r2=578523&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
Sat Sep 22 16:13:54 2007
@@ -23,6 +23,7 @@
 
 import org.apache.geronimo.gshell.remote.message.Message;
 import org.apache.geronimo.gshell.remote.transport.Transport;
+import org.apache.geronimo.gshell.remote.util.Duration;
 import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -36,34 +37,29 @@
  */
 public class Requestor
 {
-    public static final long DEFAULT_TIMEOUT = 10;
-
-    public static final TimeUnit DEFAULT_TIMEOUT_UNIT = TimeUnit.SECONDS;
+    public static final Duration DEFAULT_TIMEOUT = new Duration(10, TimeUnit.SECONDS);
 
     private final Logger log = LoggerFactory.getLogger(getClass());
     
     private final IoSession session;
 
-    private final long timeout;
-
-    private final TimeUnit unit;
+    private final Duration timeout;
 
-    private Requestor(final IoSession session, final long timeout, final TimeUnit unit) {
+    public Requestor(final IoSession session, final Duration timeout) {
         this.session = session;
         this.timeout = timeout;
-        this.unit = unit;
     }
 
     public Requestor(final IoSession session) {
-        this(session, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT_UNIT);
+        this(session, DEFAULT_TIMEOUT);
     }
 
     public Requestor(final Transport transport, final long timeout, final TimeUnit unit)
{
-        this(transport.getSession(), timeout, unit);
+        this(transport.getSession(), new Duration(timeout, unit));
     }
 
     public Requestor(final Transport transport) {
-        this(transport, DEFAULT_TIMEOUT, DEFAULT_TIMEOUT_UNIT);
+        this(transport.getSession(), DEFAULT_TIMEOUT);
     }
 
     public RequestWriteFuture submit(final Message msg, final long timeout, final TimeUnit
unit) throws Exception {
@@ -76,8 +72,12 @@
         return new RequestWriteFuture(wf, req);
     }
 
+    public RequestWriteFuture submit(final Message msg, final Duration timeout) throws Exception
{
+        return submit(msg, timeout.getValue(), timeout.getUnit());
+    }
+
     public RequestWriteFuture submit(final Message msg) throws Exception {
-        return submit(msg, timeout, unit);
+        return submit(msg, timeout.getValue(), timeout.getUnit());
     }
 
     public Message request(final Message msg, final long timeout, final TimeUnit unit) throws
Exception {
@@ -92,8 +92,12 @@
         return resp.getMessage();
     }
 
+    public Message request(final Message msg, final Duration timeout) throws Exception {
+        return request(msg, timeout.getValue(), timeout.getUnit());
+    }
+
     public Message request(final Message msg) throws Exception {
-        return request(msg, timeout, unit);
+        return request(msg, timeout.getValue(), timeout.getUnit());
     }
     
     //

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java?rev=578523&r1=578522&r2=578523&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/Transport.java
Sat Sep 22 16:13:54 2007
@@ -25,6 +25,7 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.geronimo.gshell.remote.message.Message;
+import org.apache.geronimo.gshell.remote.util.Duration;
 import org.apache.mina.common.IoService;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.common.WriteFuture;
@@ -51,6 +52,8 @@
     void close();
     
     WriteFuture send(Object msg) throws Exception;
+
+    Message request(Message msg, Duration timeout) throws Exception;
 
     Message request(Message msg, long timeout, TimeUnit unit) throws Exception;
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java?rev=578523&r1=578522&r2=578523&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/transport/base/BaseTransport.java
Sat Sep 22 16:13:54 2007
@@ -34,6 +34,7 @@
 import org.apache.geronimo.gshell.remote.stream.SessionInputStream;
 import org.apache.geronimo.gshell.remote.stream.SessionOutputStream;
 import org.apache.geronimo.gshell.remote.transport.Transport;
+import org.apache.geronimo.gshell.remote.util.Duration;
 import org.apache.mina.common.CloseFuture;
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoConnector;
@@ -148,6 +149,14 @@
         return session;
     }
 
+    public InputStream getInputStream() {
+        return SessionInputStream.BINDER.lookup(session);
+    }
+
+    public OutputStream getOutputStream() {
+        return SessionOutputStream.BINDER.lookup(session);
+    }
+
     public WriteFuture send(final Object msg) throws Exception {
         assert msg != null;
 
@@ -162,19 +171,19 @@
         return requestor.request(msg);
     }
 
-    public Message request(final Message msg, final long timeout, final TimeUnit unit) throws
Exception {
+    public Message request(final Message msg, final Duration timeout) throws Exception {
         assert msg != null;
 
         Requestor requestor = new Requestor(this);
 
-        return requestor.request(msg, timeout, unit);
+        return requestor.request(msg, timeout);
     }
 
-    public InputStream getInputStream() {
-        return SessionInputStream.BINDER.lookup(session);
-    }
+    public Message request(final Message msg, final long timeout, final TimeUnit unit) throws
Exception {
+        assert msg != null;
 
-    public OutputStream getOutputStream() {
-        return SessionOutputStream.BINDER.lookup(session);
+        Requestor requestor = new Requestor(this);
+
+        return requestor.request(msg, timeout, unit);
     }
 }

Copied: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/Duration.java
(from r578519, geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java)
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/Duration.java?p2=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/Duration.java&p1=geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java&r1=578519&r2=578523&rev=578523&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/TimeValue.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/Duration.java
Sat Sep 22 16:13:54 2007
@@ -19,58 +19,92 @@
 
 package org.apache.geronimo.gshell.remote.util;
 
+import java.io.Serializable;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.geronimo.gshell.common.tostring.ToStringBuilder;
+import org.apache.geronimo.gshell.common.tostring.ToStringStyle;
+import org.apache.geronimo.gshell.remote.marshall.MarshalAware;
+import org.apache.geronimo.gshell.remote.marshall.Marshaller;
+import org.apache.mina.common.ByteBuffer;
 
 /**
- * ???
- *
+ * A representaion of a duration of time.
+ * 
  * @version $Rev$ $Date$
  */
-public class TimeValue
+public class Duration
+    implements MarshalAware, Serializable
 {
-    public final long time;
+    public static final TimeUnit DEFAULT_UNIT = TimeUnit.MILLISECONDS;
 
-    public final TimeUnit unit;
+    private long value;
 
-    public TimeValue(final long time, final TimeUnit unit) {
-        this.time = time;
-        this.unit = unit;
+    private TimeUnit unit;
+
+    public Duration(final long value, final TimeUnit unit) {
+        this.value = value;
+
+        if (unit == null) {
+            this.unit = DEFAULT_UNIT;
+        }
+        else {
+            this.unit = unit;
+        }
+    }
+
+    public Duration(final long value) {
+        this(value, DEFAULT_UNIT);
     }
 
-    public long getTime() {
-        return time;
+    public long getValue() {
+        return value;
     }
 
     public TimeUnit getUnit() {
         return unit;
     }
-
+    
     public String toString() {
-        return new ToStringBuilder(this)
-                .append("time", time)
+        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+                .append("value", value)
                 .append("unit", unit)
                 .toString();
     }
 
-    public boolean equals(Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-
-        TimeValue timeValue = (TimeValue) o;
+    public boolean equals(final Object obj) {
+        if (this == obj) return true;
+        if (obj == null || getClass() != obj.getClass()) return false;
 
-        if (time != timeValue.time) return false;
+        Duration duration = (Duration) obj;
 
-        return unit == timeValue.unit;
+        return value == duration.value && unit == duration.unit;
     }
 
     public int hashCode() {
         int result;
 
-        result = (int) (time ^ (time >>> 32));
+        result = (int) (value ^ (value >>> 32));
         result = 31 * result + (unit != null ? unit.hashCode() : 0);
 
         return result;
+    }
+
+    public void writeExternal(final ByteBuffer out) throws Exception {
+        assert out != null;
+        
+        out.putLong(value);
+
+        Marshaller.writeEnum(out, unit);
+    }
+
+    public void readExternal(final ByteBuffer in) throws Exception {
+        assert in != null;
+
+        value = in.getLong();
+
+        unit = Marshaller.readEnum(in, TimeUnit.class);
+
+        assert unit != null;
     }
 }

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

Propchange: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/util/Duration.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/util/Duration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message