You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ha...@apache.org on 2001/12/31 13:48:42 UTC
cvs commit: jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl AbstractServer.java
hammant 01/12/31 04:48:42
Modified: armi/src/java/org/apache/commons/armi/client/impl
ObjectStreamInvocationHandler.java
armi/src/java/org/apache/commons/armi/client/impl/direct
DirectInvocationHandler.java
armi/src/java/org/apache/commons/armi/client/impl/rmi
RmiInvocationHandler.java
armi/src/java/org/apache/commons/armi/server ArmiServer.java
armi/src/java/org/apache/commons/armi/server/impl
AbstractServer.java
Added: armi/src/java/org/apache/commons/armi/common
TryLaterReply.java
Log:
suspend() & resume() functionality added
Revision Changes Path
1.2 +20 -9 jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/ObjectStreamInvocationHandler.java
Index: ObjectStreamInvocationHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/ObjectStreamInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ObjectStreamInvocationHandler.java 28 Dec 2001 18:08:37 -0000 1.1
+++ ObjectStreamInvocationHandler.java 31 Dec 2001 12:48:41 -0000 1.2
@@ -1,8 +1,8 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/ObjectStreamInvocationHandler.java,v 1.1 2001/12/28 18:08:37 hammant Exp $
- * $Revision: 1.1 $
- * $Date: 2001/12/28 18:08:37 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/ObjectStreamInvocationHandler.java,v 1.2 2001/12/31 12:48:41 hammant Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/12/31 12:48:41 $
*
* ====================================================================
*
@@ -68,6 +68,7 @@
import org.apache.commons.armi.common.ArmiRequest;
import org.apache.commons.armi.common.MethodRequest;
import org.apache.commons.armi.common.ArmiInvocationException;
+import org.apache.commons.armi.common.TryLaterReply;
import java.io.IOException;
import java.io.ObjectOutputStream;
@@ -79,7 +80,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public class ObjectStreamInvocationHandler implements ArmiInvocationHandler {
@@ -123,11 +124,21 @@
try {
while (true) {
- mOOS.writeObject(request);
- mOOS.flush();
-
- ArmiReply reply = (ArmiReply) mOIS.readObject();
-
+ boolean again = true;
+ ArmiReply reply = null;
+ while (again) {
+ again = false;
+ mOOS.writeObject(request);
+ mOOS.flush();
+ reply = (ArmiReply) mOIS.readObject();
+ if (reply instanceof TryLaterReply) {
+ int millis = ((TryLaterReply) reply).getDelayMillis();
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException ie) {}
+ again = true;
+ }
+ }
return reply;
}
} catch (IOException e) {
1.2 +19 -5 jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/direct/DirectInvocationHandler.java
Index: DirectInvocationHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/direct/DirectInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DirectInvocationHandler.java 28 Dec 2001 18:08:37 -0000 1.1
+++ DirectInvocationHandler.java 31 Dec 2001 12:48:42 -0000 1.2
@@ -1,8 +1,8 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/direct/DirectInvocationHandler.java,v 1.1 2001/12/28 18:08:37 hammant Exp $
- * $Revision: 1.1 $
- * $Date: 2001/12/28 18:08:37 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/direct/DirectInvocationHandler.java,v 1.2 2001/12/31 12:48:42 hammant Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/12/31 12:48:42 $
*
* ====================================================================
*
@@ -67,6 +67,7 @@
import org.apache.commons.armi.common.ArmiConnectionException;
import org.apache.commons.armi.common.ArmiReply;
import org.apache.commons.armi.common.ArmiRequest;
+import org.apache.commons.armi.common.TryLaterReply;
/**
@@ -74,7 +75,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public final class DirectInvocationHandler implements ArmiInvocationHandler {
@@ -104,6 +105,19 @@
*
*/
public ArmiReply handleInvocation(ArmiRequest request) {
- return mArmiInvocationHandler.handleInvocation(request);
+ boolean again = true;
+ ArmiReply reply = null;
+ while (again) {
+ again = false;
+ reply = mArmiInvocationHandler.handleInvocation(request);
+ if (reply instanceof TryLaterReply) {
+ int millis = ((TryLaterReply) reply).getDelayMillis();
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException ie) {}
+ again = true;
+ }
+ }
+ return reply;
}
}
1.2 +22 -7 jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/rmi/RmiInvocationHandler.java
Index: RmiInvocationHandler.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/rmi/RmiInvocationHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RmiInvocationHandler.java 28 Dec 2001 18:08:38 -0000 1.1
+++ RmiInvocationHandler.java 31 Dec 2001 12:48:42 -0000 1.2
@@ -1,8 +1,8 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/rmi/RmiInvocationHandler.java,v 1.1 2001/12/28 18:08:38 hammant Exp $
- * $Revision: 1.1 $
- * $Date: 2001/12/28 18:08:38 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/client/impl/rmi/RmiInvocationHandler.java,v 1.2 2001/12/31 12:48:42 hammant Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/12/31 12:48:42 $
*
* ====================================================================
*
@@ -69,6 +69,7 @@
import org.apache.commons.armi.common.ArmiRequest;
import org.apache.commons.armi.common.ArmiInvocationException;
import org.apache.commons.armi.common.ArmiConnectionException;
+import org.apache.commons.armi.common.TryLaterReply;
import java.rmi.Naming;
import java.rmi.RemoteException;
@@ -82,11 +83,11 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public final class RmiInvocationHandler implements ArmiInvocationHandler {
- RmiArmiInvocationHandler mServer;
+ RmiArmiInvocationHandler mRmiArmiInvocationHandler;
/**
* Constructor RmiInvocationHandler
@@ -104,7 +105,7 @@
+ RmiArmiInvocationHandler.class.getName();
try {
- mServer = (RmiArmiInvocationHandler) Naming.lookup(url);
+ mRmiArmiInvocationHandler = (RmiArmiInvocationHandler) Naming.lookup(url);
} catch (NotBoundException nbe) {
throw new ArmiConnectionException(
"Cannot bind to the remote RMI service. Either an IP or RMI issue.");
@@ -128,8 +129,22 @@
public ArmiReply handleInvocation(ArmiRequest request) {
try {
- return mServer.handleInvocation(request);
+ boolean again = true;
+ ArmiReply reply = null;
+ while (again) {
+ again = false;
+ reply = mRmiArmiInvocationHandler.handleInvocation(request);
+ if (reply instanceof TryLaterReply) {
+ int millis = ((TryLaterReply) reply).getDelayMillis();
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException ie) {}
+ again = true;
+ }
+ }
+ return reply;
} catch (RemoteException re) {
+ // should impl so automagic try again here (for n times at least).
throw new ArmiInvocationException("Unknown RMI problem : " + re.getMessage());
}
}
1.1 jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/common/TryLaterReply.java
Index: TryLaterReply.java
===================================================================
/*
* $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/common/TryLaterReply.java,v 1.1 2001/12/31 12:48:42 hammant Exp $
* $Revision: 1.1 $
* $Date: 2001/12/31 12:48:42 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.armi.common;
/**
* Class TryLaterReply
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
* @version $Revision: 1.1 $
*/
public class TryLaterReply extends ArmiReply {
private final int mDelayMillis;
/**
* Constructor TryLaterReply
*
*/
public TryLaterReply() {
mDelayMillis = 5 * 1000; // ten seconds.
}
/**
* Constructor TryLaterReply
*
*
* @param delayMillis
*
*/
public TryLaterReply(int delayMillis) {
mDelayMillis = delayMillis;
}
/**
* Method getDelayMillis
*
*
* @return
*
*/
public int getDelayMillis() {
return mDelayMillis;
}
}
1.2 +17 -4 jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java
Index: ArmiServer.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ArmiServer.java 28 Dec 2001 18:08:38 -0000 1.1
+++ ArmiServer.java 31 Dec 2001 12:48:42 -0000 1.2
@@ -1,8 +1,8 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java,v 1.1 2001/12/28 18:08:38 hammant Exp $
- * $Revision: 1.1 $
- * $Date: 2001/12/28 18:08:38 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java,v 1.2 2001/12/31 12:48:42 hammant Exp $
+ * $Revision: 1.2 $
+ * $Date: 2001/12/31 12:48:42 $
*
* ====================================================================
*
@@ -72,7 +72,7 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version * $Revision: 1.1 $
+ * @version * $Revision: 1.2 $
*/
public interface ArmiServer {
@@ -108,4 +108,17 @@
*
*/
ArmiReply processRequest(ArmiRequest request);
+
+ /**
+ * Method suspend
+ *
+ */
+ void suspend();
+
+ /**
+ * Method resume
+ *
+ */
+ void resume();
+
}
1.3 +26 -4 jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java
Index: AbstractServer.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractServer.java 30 Dec 2001 00:42:10 -0000 1.2
+++ AbstractServer.java 31 Dec 2001 12:48:42 -0000 1.3
@@ -1,8 +1,8 @@
/*
- * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java,v 1.2 2001/12/30 00:42:10 hammant Exp $
- * $Revision: 1.2 $
- * $Date: 2001/12/30 00:42:10 $
+ * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java,v 1.3 2001/12/31 12:48:42 hammant Exp $
+ * $Revision: 1.3 $
+ * $Date: 2001/12/31 12:48:42 $
*
* ====================================================================
*
@@ -74,6 +74,7 @@
import org.apache.commons.armi.common.ArmiConnectionException;
import org.apache.commons.armi.common.ClassReply;
import org.apache.commons.armi.common.RequestFailedReply;
+import org.apache.commons.armi.common.TryLaterReply;
import org.apache.commons.armi.client.impl.BaseServedObject;
import java.lang.reflect.Method;
@@ -87,11 +88,12 @@
*
*
* @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class AbstractServer extends AbstractMethodHandler implements ArmiServer {
private HashMap publishedObjects = new HashMap();
+ private boolean mSuspend = false;
/**
* Method publish
@@ -153,6 +155,10 @@
*/
public ArmiReply processRequest(ArmiRequest request) {
+ if (mSuspend == true) {
+ return new TryLaterReply();
+ }
+
if (request instanceof MethodRequest) {
MethodRequest mr = (MethodRequest) request;
String as = mr.getPublishedObjectName();
@@ -178,5 +184,21 @@
} else {
return new RequestFailedReply("Unknown request :" + request.getClass().getName());
}
+ }
+
+ /**
+ * Method suspend
+ *
+ */
+ public void suspend() {
+ mSuspend = true;
+ }
+
+ /**
+ * Method resume
+ *
+ */
+ public void resume() {
+ mSuspend = false;
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>