hammant 02/01/26 07:22:17 Modified: altrmi PROPOSAL tests.xml altrmi/src/java/org/apache/commons/altrmi/client/impl/direct DirectHostContext.java DirectInvocationHandler.java altrmi/src/java/org/apache/commons/altrmi/client/impl/stream ClientCustomStreamReadWriter.java altrmi/src/java/org/apache/commons/altrmi/server/impl ServerCustomStreamReadWriter.java Added: altrmi/src/java/org/apache/commons/altrmi/client/impl/direct AbstractDirectInvocationHandler.java DirectMarshalledHostContext.java DirectMarshalledInvocationHandler.java altrmi/src/java/org/apache/commons/altrmi/common AltrmiMarshalledInvocationHandler.java SerializationHelper.java altrmi/src/java/org/apache/commons/altrmi/server/impl/direct DirectMarshalledInovcationAdapter.java DirectMarshalledServer.java altrmi/src/java/org/apache/commons/altrmi/test DirectMarshalledTest.java Log: new direct-marshalled transport type Revision Changes Path 1.12 +10 -7 jakarta-commons-sandbox/altrmi/PROPOSAL Index: PROPOSAL =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/PROPOSAL,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- PROPOSAL 25 Jan 2002 16:40:13 -0000 1.11 +++ PROPOSAL 26 Jan 2002 15:22:16 -0000 1.12 @@ -59,13 +59,16 @@ interfaces etc.. e) ObjectStream over Pipe #2 12095 4.48 - f) ObjectStream over Pipe #1 61166 22.64 - g) Direct #3 2391498 885.08 + f) Direct Marshalled #3 20759 7.68 + g) ObjectStream over Pipe #1 61166 22.64 + h) Direct Unmarshalled # 2391498 885.08 #1 Without calling reset() as workaround to the ObjectStream bug #2 With calling reset() as workaround to the ObjectStream bug - #3 Marshalled but not streamed. Still as good as DynamicProxy - for separation. + #3 Completely separates classloaders of client and server. Requires + a thread for each though. + #4 Good as DynamicProxy for separation. Does not separate classloaders + of client and server. Non AltRMI types ---------------- @@ -74,10 +77,10 @@ branches of classloader for these three. The same interfaces etc must be visible to both impl and proxy. - h) DyanmicProxy #4 + i) DyanmicProxy #5 (copied from Excalibur) 20282070 7506.32 - i) Hand-coded proxy #4 41214422 15253.30 - j) No Proxy #4 42384804 15686.46 + j) Hand-coded proxy #5 41214422 15253.30 + k) No Proxy #5 42384804 15686.46 #4 - For all of these three, the actual timing may slow down the test. 1.4 +8 -1 jakarta-commons-sandbox/altrmi/tests.xml Index: tests.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/tests.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- tests.xml 26 Jan 2002 13:51:34 -0000 1.3 +++ tests.xml 26 Jan 2002 15:22:16 -0000 1.4 @@ -3,7 +3,7 @@ <!-- "Alt (to) RMI" component of the Jakarta Commons Subproject - $Id: tests.xml,v 1.3 2002/01/26 13:51:34 hammant Exp $ + $Id: tests.xml,v 1.4 2002/01/26 15:22:16 hammant Exp $ --> @@ -170,6 +170,13 @@ <target name="directa" depends="generate" description="Direct Server and Client (client side classes)"> <java classname="org.apache.commons.altrmi.test.DirectTest" fork="true"> + <classpath refid="testA.classpath"/> + <arg value="C"/> + </java> + </target> + + <target name="directmarshalled" depends="generate" description="Direct Marshalled Server and Client (client side classes)"> + <java classname="org.apache.commons.altrmi.test.DirectMarshalledTest" fork="true"> <classpath refid="testA.classpath"/> <arg value="C"/> </java> 1.2 +0 -1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectHostContext.java Index: DirectHostContext.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectHostContext.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- DirectHostContext.java 21 Jan 2002 15:38:20 -0000 1.1 +++ DirectHostContext.java 26 Jan 2002 15:22:16 -0000 1.2 @@ -10,7 +10,6 @@ import org.apache.commons.altrmi.client.impl.AbstractHostContext; -import org.apache.commons.altrmi.client.AltrmiConnectionListener; import org.apache.commons.altrmi.common.AltrmiInvocationHandler; import org.apache.commons.altrmi.common.AltrmiConnectionException; @@ -20,7 +19,7 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class DirectHostContext extends AbstractHostContext { 1.6 +4 -96 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectInvocationHandler.java Index: DirectInvocationHandler.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectInvocationHandler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- DirectInvocationHandler.java 21 Jan 2002 15:38:20 -0000 1.5 +++ DirectInvocationHandler.java 26 Jan 2002 15:22:16 -0000 1.6 @@ -33,14 +33,11 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ -public final class DirectInvocationHandler extends AbstractClientInvocationHandler { +public final class DirectInvocationHandler extends AbstractDirectInvocationHandler { private AltrmiInvocationHandler mAltrmiInvocationHandler; - private boolean mMethodLogging = false; - private long mLastRealRequest = System.currentTimeMillis(); - /** * Constructor DirectInvocationHandler @@ -56,96 +53,7 @@ mAltrmiInvocationHandler = altrmiInvocationHandler; } - /** - * Method setAltrmiConnectionListener - * - * - * @param altrmiConnectionListener - * - */ - public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener) { - - super.setAltrmiConnectionListener(altrmiConnectionListener); - - mMethodLogging = altrmiConnectionListener.methodLogging(); + protected AltrmiReply performInvocation(AltrmiRequest request) throws IOException{ + return mAltrmiInvocationHandler.handleInvocation(request); } - - - /** - * Method handleInvocation - * - * - * @param request - * - * @return - * - */ - public AltrmiReply handleInvocation(AltrmiRequest request) { - - if (request.getRequestCode() != AltrmiRequest.PINGREQUEST) { - mLastRealRequest = System.currentTimeMillis(); - } - - boolean again = true; - AltrmiReply reply = null; - int tries = 0; - long start = 0; - - if (mMethodLogging) { - start = System.currentTimeMillis(); - } - - while (again) { - tries++; - - again = false; - reply = mAltrmiInvocationHandler.handleInvocation(request); - - //if ((reply instanceof ProblemReply)) { // slower by 11% - if (reply.getReplyCode() >= 100) { - if (reply instanceof TryLaterReply) { - int millis = ((TryLaterReply) reply).getSuggestedDelayMillis(); - - mAltrmiConnectionListener.serviceSuspended(request, tries, millis); - - again = true; - } else if (reply instanceof NoSuchReferenceReply) { - throw new NotSuchReferenceException(); - } else if (reply instanceof NotPublishedReply) { - PublishedNameRequest pnr = (PublishedNameRequest) request; - - throw new NotPublishedException(pnr.getPublishedServiceName(), - pnr.getObjectName()); - } - } - } - - if (mMethodLogging) { - if (request instanceof MethodRequest) { - mAltrmiConnectionListener.methodCalled( - ((MethodRequest) request).getMethodSignature(), - System.currentTimeMillis() - start); - } - } - - return reply; - } - - protected boolean tryReconnect() { - - // blimey how do we reconnect this? - throw new AltrmiInvocationException("Direct connection broken, unable to reconnect."); - } - - /** - * Method getLastRealRequest - * - * - * @return - * - */ - public long getLastRealRequest() { - return mLastRealRequest; - } - } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/AbstractDirectInvocationHandler.java Index: AbstractDirectInvocationHandler.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.commons.altrmi.client.impl.direct; import org.apache.commons.altrmi.common.AltrmiInvocationHandler; import org.apache.commons.altrmi.common.AltrmiConnectionException; import org.apache.commons.altrmi.common.AltrmiReply; import org.apache.commons.altrmi.common.AltrmiRequest; import org.apache.commons.altrmi.common.TryLaterReply; import org.apache.commons.altrmi.common.NotPublishedReply; import org.apache.commons.altrmi.common.NotPublishedException; import org.apache.commons.altrmi.common.PublishedNameRequest; import org.apache.commons.altrmi.common.AltrmiInvocationException; import org.apache.commons.altrmi.common.MethodRequest; import org.apache.commons.altrmi.common.NoSuchReferenceReply; import org.apache.commons.altrmi.common.NotSuchReferenceException; import org.apache.commons.altrmi.client.impl.AbstractClientInvocationHandler; import org.apache.commons.altrmi.client.AltrmiConnectionListener; import java.io.IOException; /** * Class DirectInvocationHandler * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision: 1.1 $ */ public abstract class AbstractDirectInvocationHandler extends AbstractClientInvocationHandler { protected boolean mMethodLogging = false; protected long mLastRealRequest = System.currentTimeMillis(); /** * Method setAltrmiConnectionListener * * * @param altrmiConnectionListener * */ public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener) { super.setAltrmiConnectionListener(altrmiConnectionListener); mMethodLogging = altrmiConnectionListener.methodLogging(); } /** * Method handleInvocation * * * @param request * * @return * */ public AltrmiReply handleInvocation(AltrmiRequest request) { if (request.getRequestCode() != AltrmiRequest.PINGREQUEST) { mLastRealRequest = System.currentTimeMillis(); } boolean again = true; AltrmiReply reply = null; int tries = 0; long start = 0; if (mMethodLogging) { start = System.currentTimeMillis(); } while (again) { tries++; again = false; try { reply = performInvocation(request); } catch (IOException ioe) { ioe.printStackTrace(); } //if ((reply instanceof ProblemReply)) { // slower by 11% if (reply.getReplyCode() >= 100) { if (reply instanceof TryLaterReply) { int millis = ((TryLaterReply) reply).getSuggestedDelayMillis(); mAltrmiConnectionListener.serviceSuspended(request, tries, millis); again = true; } else if (reply instanceof NoSuchReferenceReply) { throw new NotSuchReferenceException(); } else if (reply instanceof NotPublishedReply) { PublishedNameRequest pnr = (PublishedNameRequest) request; throw new NotPublishedException(pnr.getPublishedServiceName(), pnr.getObjectName()); } } } if (mMethodLogging) { if (request instanceof MethodRequest) { mAltrmiConnectionListener.methodCalled( ((MethodRequest) request).getMethodSignature(), System.currentTimeMillis() - start); } } return reply; } protected boolean tryReconnect() { // blimey how do we reconnect this? throw new AltrmiInvocationException("Direct connection broken, unable to reconnect."); } /** * Method getLastRealRequest * * * @return * */ public long getLastRealRequest() { return mLastRealRequest; } protected abstract AltrmiReply performInvocation(AltrmiRequest request) throws IOException; } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectMarshalledHostContext.java Index: DirectMarshalledHostContext.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.commons.altrmi.client.impl.direct; import org.apache.commons.altrmi.client.impl.AbstractHostContext; import org.apache.commons.altrmi.common.AltrmiConnectionException; import org.apache.commons.altrmi.common.AltrmiMarshalledInvocationHandler; /** * Class DirectHostContext * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision: 1.1 $ */ public class DirectMarshalledHostContext extends AbstractHostContext { /** * Constructor DirectHostContext * * * @param altrmiInvocationHandler * * @throws AltrmiConnectionException * */ public DirectMarshalledHostContext(AltrmiMarshalledInvocationHandler altrmiInvocationHandler) throws AltrmiConnectionException { super(new DirectMarshalledInvocationHandler(altrmiInvocationHandler)); } } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectMarshalledInvocationHandler.java Index: DirectMarshalledInvocationHandler.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.commons.altrmi.client.impl.direct; import org.apache.commons.altrmi.common.AltrmiInvocationHandler; import org.apache.commons.altrmi.common.AltrmiConnectionException; import org.apache.commons.altrmi.common.AltrmiReply; import org.apache.commons.altrmi.common.AltrmiRequest; import org.apache.commons.altrmi.common.TryLaterReply; import org.apache.commons.altrmi.common.NotPublishedReply; import org.apache.commons.altrmi.common.NotPublishedException; import org.apache.commons.altrmi.common.PublishedNameRequest; import org.apache.commons.altrmi.common.AltrmiInvocationException; import org.apache.commons.altrmi.common.MethodRequest; import org.apache.commons.altrmi.common.NoSuchReferenceReply; import org.apache.commons.altrmi.common.NotSuchReferenceException; import org.apache.commons.altrmi.common.AltrmiMarshalledInvocationHandler; import org.apache.commons.altrmi.common.SerializationHelper; import org.apache.commons.altrmi.client.impl.AbstractClientInvocationHandler; import org.apache.commons.altrmi.client.AltrmiConnectionListener; import java.io.IOException; /** * Class DirectInvocationHandler * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision: 1.1 $ */ public final class DirectMarshalledInvocationHandler extends AbstractDirectInvocationHandler { private AltrmiMarshalledInvocationHandler mAltrmiInvocationHandler; /** * Constructor DirectInvocationHandler * * * @param altrmiInvocationHandler * * @throws AltrmiConnectionException * */ public DirectMarshalledInvocationHandler(AltrmiMarshalledInvocationHandler altrmiInvocationHandler) throws AltrmiConnectionException { mAltrmiInvocationHandler = altrmiInvocationHandler; } protected AltrmiReply performInvocation(AltrmiRequest request) throws IOException { byte[] serRequest = SerializationHelper.getBytesFromInstance(request); byte[] serReply = mAltrmiInvocationHandler.handleInvocation(serRequest); return (AltrmiReply) SerializationHelper.getInstanceFromBytes(serReply); } } 1.2 +7 -25 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/stream/ClientCustomStreamReadWriter.java Index: ClientCustomStreamReadWriter.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/stream/ClientCustomStreamReadWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ClientCustomStreamReadWriter.java 20 Jan 2002 00:13:40 -0000 1.1 +++ ClientCustomStreamReadWriter.java 26 Jan 2002 15:22:16 -0000 1.2 @@ -8,19 +8,14 @@ */ package org.apache.commons.altrmi.client.impl.stream; - - -import org.apache.commons.altrmi.common.AltrmiRequest; import org.apache.commons.altrmi.common.AltrmiReply; +import org.apache.commons.altrmi.common.AltrmiRequest; +import org.apache.commons.altrmi.common.SerializationHelper; -import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.io.IOException; import java.io.BufferedOutputStream; @@ -30,7 +25,7 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class ClientCustomStreamReadWriter extends ClientStreamReadWriter { @@ -63,18 +58,8 @@ private void writeRequest(AltrmiRequest altrmiRequest) throws IOException { - ByteArrayOutputStream bAOS = new ByteArrayOutputStream(); - ObjectOutputStream objectOutputStream; - - objectOutputStream = new ObjectOutputStream(bAOS); + byte[] aBytes = SerializationHelper.getBytesFromInstance(altrmiRequest); - objectOutputStream.writeObject(altrmiRequest); - objectOutputStream.flush(); - - byte[] aBytes = bAOS.toByteArray(); - - objectOutputStream.close(); - bAOS.close(); mDataOutputStream.writeInt(aBytes.length); mDataOutputStream.write(aBytes); mDataOutputStream.flush(); @@ -87,9 +72,6 @@ mDataInputStream.read(byteArray); - ByteArrayInputStream bAIS = new ByteArrayInputStream(byteArray); - ObjectInputStream oOs = new ObjectInputStream(bAIS); - - return (AltrmiReply) oOs.readObject(); + return (AltrmiReply) SerializationHelper.getInstanceFromBytes(byteArray); } } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AltrmiMarshalledInvocationHandler.java Index: AltrmiMarshalledInvocationHandler.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.commons.altrmi.common; /** * Interface AltrmiMarshalledInvocationHandler * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version * $Revision: 1.1 $ */ public interface AltrmiMarshalledInvocationHandler { /** * Method handleInvocation * * * @param request * * @return * */ byte[] handleInvocation(byte[] request); } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/SerializationHelper.java Index: SerializationHelper.java =================================================================== /* * Created by IntelliJ IDEA. * User: Administrator * Date: Jan 26, 2002 * Time: 2:36:56 PM * To change template for new class use * Code Style | Class Templates options (Tools | IDE Options). */ package org.apache.commons.altrmi.common; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.io.IOException; import java.io.ByteArrayInputStream; import java.io.ObjectInputStream; public class SerializationHelper { public static byte[] getBytesFromInstance(Object instance) throws IOException { ByteArrayOutputStream bAOS = new ByteArrayOutputStream(); ObjectOutputStream oOs; oOs = new ObjectOutputStream(bAOS); oOs.writeObject(instance); oOs.flush(); byte[] aBytes = bAOS.toByteArray(); oOs.close(); bAOS.close(); return aBytes; } public static Object getInstanceFromBytes(byte[] byteArray) throws IOException, ClassNotFoundException { ByteArrayInputStream bAIS = new ByteArrayInputStream(byteArray); ObjectInputStream oIs = new ObjectInputStream(bAIS); Object obj = oIs.readObject(); oIs.close(); return obj; } } 1.5 +4 -21 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/ServerCustomStreamReadWriter.java Index: ServerCustomStreamReadWriter.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/ServerCustomStreamReadWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServerCustomStreamReadWriter.java 18 Jan 2002 09:58:13 -0000 1.4 +++ ServerCustomStreamReadWriter.java 26 Jan 2002 15:22:17 -0000 1.5 @@ -12,13 +12,8 @@ import org.apache.commons.altrmi.common.AltrmiRequest; import org.apache.commons.altrmi.common.AltrmiReply; +import org.apache.commons.altrmi.common.SerializationHelper; -import java.io.ObjectOutputStream; -import java.io.ObjectInputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; @@ -30,7 +25,7 @@ * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ */ public class ServerCustomStreamReadWriter extends ServerStreamReadWriter { @@ -54,15 +49,7 @@ private void writeReply(AltrmiReply altrmiReply) throws IOException { - ByteArrayOutputStream bAOS = new ByteArrayOutputStream(); - ObjectOutputStream objectOutputStream; - - objectOutputStream = new ObjectOutputStream(bAOS); - - objectOutputStream.writeObject(altrmiReply); - objectOutputStream.flush(); - - byte[] aBytes = bAOS.toByteArray(); + byte[] aBytes = SerializationHelper.getBytesFromInstance(altrmiReply); mDataOutputStream.writeInt(aBytes.length); mDataOutputStream.write(aBytes); @@ -76,10 +63,6 @@ mDataInputStream.read(byteArray); - ByteArrayInputStream bAIS = new ByteArrayInputStream(byteArray); - ObjectInputStream oOs = new ObjectInputStream(bAIS); - AltrmiRequest ar = (AltrmiRequest) oOs.readObject(); - - return ar; + return (AltrmiRequest) SerializationHelper.getInstanceFromBytes(byteArray); } } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/direct/DirectMarshalledInovcationAdapter.java Index: DirectMarshalledInovcationAdapter.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.commons.altrmi.server.impl.direct; import org.apache.commons.altrmi.common.AltrmiInvocationHandler; import org.apache.commons.altrmi.common.AltrmiReply; import org.apache.commons.altrmi.common.AltrmiRequest; import org.apache.commons.altrmi.common.AltrmiMarshalledInvocationHandler; import org.apache.commons.altrmi.common.SerializationHelper; import org.apache.commons.altrmi.server.AltrmiServer; import java.io.IOException; /** * Class DirectInovcationAdapter * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision: 1.1 $ */ public class DirectMarshalledInovcationAdapter implements AltrmiMarshalledInvocationHandler { private AltrmiServer mServer; /** * Constructor DirectInovcationAdapter * * * @param server * */ public DirectMarshalledInovcationAdapter(AltrmiServer server) { mServer = server; } /** * Method handleInvocation * * * @param request * * @return * */ public byte[] handleInvocation(byte[] request) { try { AltrmiRequest ar = (AltrmiRequest) SerializationHelper.getInstanceFromBytes(request); AltrmiReply reply = mServer.processRequest(ar); return SerializationHelper.getBytesFromInstance(reply); } catch (IOException e) { e.printStackTrace(); return null; } catch (ClassNotFoundException e) { e.printStackTrace(); return null; } } } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/direct/DirectMarshalledServer.java Index: DirectMarshalledServer.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.commons.altrmi.server.impl.direct; import org.apache.commons.altrmi.server.impl.AbstractServer; import org.apache.commons.altrmi.server.AltrmiServerException; import org.apache.commons.altrmi.common.AltrmiReply; import org.apache.commons.altrmi.common.AltrmiRequest; import org.apache.commons.altrmi.common.AltrmiInvocationException; /** * Class DirectServer * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision: 1.1 $ */ public class DirectMarshalledServer extends AbstractServer { /** * Method start * */ public void start() { mState = STARTED; } /** * Method stop * */ public void stop() { mState = SHUTTINGDOWN; killAllConnections(); mState = STOPPED; } /** * Method processRequest * * * @param request * * @return * */ public AltrmiReply processRequest(AltrmiRequest request) { if (mState == STARTED) { return super.processRequest(request); } else { throw new AltrmiInvocationException("Service is not started"); } } } 1.1 jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/DirectMarshalledTest.java Index: DirectMarshalledTest.java =================================================================== /* * Copyright (C) The Apache Software Foundation. All rights reserved. * * This software is published under the terms of the Apache Software License * version 1.1, a copy of which has been included with this distribution in * the LICENSE.txt file. */ package org.apache.commons.altrmi.test; import org.apache.commons.altrmi.server.impl.direct.DirectServer; import org.apache.commons.altrmi.server.impl.direct.DirectInovcationAdapter; import org.apache.commons.altrmi.server.impl.direct.DirectMarshalledServer; import org.apache.commons.altrmi.server.impl.direct.DirectMarshalledInovcationAdapter; import org.apache.commons.altrmi.server.impl.classretrievers.JarFileClassRetriever; import org.apache.commons.altrmi.common.AltrmiInvocationHandler; import org.apache.commons.altrmi.common.AltrmiConnectionException; import org.apache.commons.altrmi.common.AltrmiMarshalledInvocationHandler; import org.apache.commons.altrmi.client.AltrmiHostContext; import org.apache.commons.altrmi.client.AltrmiFactory; import org.apache.commons.altrmi.client.impl.direct.DirectHostContext; import org.apache.commons.altrmi.client.impl.direct.DirectMarshalledHostContext; import org.apache.commons.altrmi.client.impl.ServerClassAltrmiFactory; import org.apache.commons.altrmi.client.impl.ClientClassAltrmiFactory; import java.io.IOException; /** * Class DirectTest * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision: 1.1 $ */ public class DirectMarshalledTest { private static String mServerOrClientFactory; /** * Method main * * * @param args * * @throws Exception * */ public static void main(String[] args) throws Exception { System.out.println("Direct Test"); mServerOrClientFactory = args[0]; DirectMarshalledServer ds = new DirectMarshalledServer(); if (mServerOrClientFactory.equals("S")) { ds.setClassRetriever(new JarFileClassRetriever("build/classes2")); } TestInterfaceImpl ti = new TestInterfaceImpl(); ds.publish(ti, "Hello", TestInterface.class, TestInterface2.class); ds.start(); DirectMarshalledTestClient dtc = new DirectMarshalledTestClient(new DirectMarshalledInovcationAdapter(ds)); Thread thread = new Thread(dtc); thread.start(); } /** * Class DirectTestClient * * * @author Paul Hammant <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @version $Revision: 1.1 $ */ static class DirectMarshalledTestClient implements Runnable { private AltrmiMarshalledInvocationHandler mInvocationHandler; /** * Constructor DirectTestClient * * * @param ih * */ public DirectMarshalledTestClient(AltrmiMarshalledInvocationHandler ih) { mInvocationHandler = ih; } /** * Method run * * */ public void run() { try { AltrmiHostContext arhc = new DirectMarshalledHostContext(mInvocationHandler); AltrmiFactory af = null; if (mServerOrClientFactory.equals("S")) { af = new ServerClassAltrmiFactory(false); } else { af = new ClientClassAltrmiFactory(false); } af.setHostContext(arhc); TestInterface ti = (TestInterface) af.lookup("Hello"); TestClient tc = new TestClient(ti); af.close(); } catch (IOException ioe) { System.err.println("Some problem during connection to server : " + ioe.getMessage()); } catch (AltrmiConnectionException ace) { System.err.println("Some problem during connection to server : " + ace.getMessage()); } } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>