commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test DirectTest.java PipeTest.java RmiServerTest.java SocketServerTest.java
Date Mon, 14 Jan 2002 16:36:08 GMT
hammant     02/01/14 08:36:08

  Modified:    altrmi   altrmi-tests.xml
               altrmi/src/java/org/apache/commons/altrmi/generator
                        SecondarySourceGenerator.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl
                        AbstractServer.java
               altrmi/src/java/org/apache/commons/altrmi/test
                        DirectTest.java PipeTest.java RmiServerTest.java
                        SocketServerTest.java
  Added:       altrmi/src/java/org/apache/commons/altrmi/server/impl/classretrievers
                        BaseMobileClass.java BaseMobileClassRetriever.java
                        JarFileClassRetriever.java NoClassRetriever.java
                        PlainClassRetriever.java
  Removed:     altrmi/src/java/org/apache/commons/altrmi/server/impl
                        BaseMobileClass.java BaseMobileClassRetriever.java
                        JarFileClassRetriever.java NoClassRetriever.java
  Log:
  new class retriever and new package for all
  
  Revision  Changes    Path
  1.3       +6 -1      jakarta-commons-sandbox/altrmi/altrmi-tests.xml
  
  Index: altrmi-tests.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/altrmi-tests.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- altrmi-tests.xml	13 Jan 2002 00:13:52 -0000	1.2
  +++ altrmi-tests.xml	14 Jan 2002 16:36:07 -0000	1.3
  @@ -3,7 +3,7 @@
   
   <!--
           "Alt (to) RMI" component of the Jakarta Commons Subproject
  -        $Id: altrmi-tests.xml,v 1.2 2002/01/13 00:13:52 hammant Exp $
  +        $Id: altrmi-tests.xml,v 1.3 2002/01/14 16:36:07 hammant Exp $
   -->
   
   
  @@ -121,6 +121,7 @@
     <target name="test1a-serve">
       <java classname="org.apache.commons.altrmi.test.SocketServerTest" fork="true">
         <classpath refid="testA.classpath"/>
  +      <arg value="C"/>
       </java>      
     </target>
     
  @@ -141,6 +142,7 @@
     <target name="test3a-serve">
       <java classname="org.apache.commons.altrmi.test.RmiServerTest" fork="true">
         <classpath refid="testA.classpath"/>
  +      <arg value="C"/>
       </java>      
     </target>
     
  @@ -161,6 +163,7 @@
     <target name="test1b-serve">
       <java classname="org.apache.commons.altrmi.test.SocketServerTest" fork="true">
         <classpath refid="testB1.classpath"/>
  +      <arg value="S"/>
       </java>      
     </target>
     
  @@ -181,6 +184,7 @@
     <target name="test3b-serve">
       <java classname="org.apache.commons.altrmi.test.RmiServerTest" fork="true">
         <classpath refid="testB1.classpath"/>
  +      <arg value="S"/>
       </java>      
     </target>
     
  @@ -201,6 +205,7 @@
     <target name="test4c" depends="generate">
       <java classname="org.apache.commons.altrmi.test.DirectTestC" fork="true">
         <classpath refid="testA.classpath"/>
  +      <arg value="S"/>
       </java>      
     </target>
   
  
  
  
  1.3       +2 -2      jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/SecondarySourceGenerator.java
  
  Index: SecondarySourceGenerator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/SecondarySourceGenerator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SecondarySourceGenerator.java	13 Jan 2002 00:13:53 -0000	1.2
  +++ SecondarySourceGenerator.java	14 Jan 2002 16:36:07 -0000	1.3
  @@ -21,7 +21,7 @@
    *
    *
    * @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 SecondarySourceGenerator extends AbstractMethodHandler {
   
  @@ -105,7 +105,7 @@
   
           mClassSource
               .println("public final class BaseMobile" + genName
  -                   + " extends org.apache.commons.altrmi.server.impl.BaseMobileClass {
");
  +                   + " extends org.apache.commons.altrmi.server.impl.classretrievers.BaseMobileClass
{ ");
           mClassSource.println("  public byte[] getClassBytes() { ");
           mClassSource.println("    return new byte[] { ");
           mClassSource.print("      ");
  
  
  
  1.3       +4 -2      jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/AbstractServer.java
  
  Index: AbstractServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/AbstractServer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractServer.java	13 Jan 2002 00:13:53 -0000	1.2
  +++ AbstractServer.java	14 Jan 2002 16:36:07 -0000	1.3
  @@ -33,6 +33,8 @@
   import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
   import org.apache.commons.altrmi.server.ClassRetriever;
   import org.apache.commons.altrmi.server.AltrmiServerInvocationHandler;
  +import org.apache.commons.altrmi.server.impl.classretrievers.BaseMobileClassRetriever;
  +import org.apache.commons.altrmi.server.impl.classretrievers.NoClassRetriever;
   
   import java.lang.reflect.Method;
   
  @@ -46,14 +48,14 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.2 $
  + * @version $Revision: 1.3 $
    */
   public abstract class AbstractServer extends AbstractMethodHandler implements AltrmiServer
{
   
       private HashMap mPublishedObjects = new HashMap();
       private boolean mSuspend = false;
       private Vector mConnections = new Vector();
  -    private ClassRetriever mClassRetriever = new BaseMobileClassRetriever();
  +    private ClassRetriever mClassRetriever = new NoClassRetriever();
   
       protected static final int SHUTTINGDOWN = 11;
       protected static final int STARTED = 22;
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/classretrievers/BaseMobileClass.java
  
  Index: BaseMobileClass.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.classretrievers;
  
  public abstract class BaseMobileClass {
  
      public abstract byte[] getClassBytes();
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/classretrievers/BaseMobileClassRetriever.java
  
  Index: BaseMobileClassRetriever.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.classretrievers;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
  import org.apache.commons.altrmi.server.ClassRetriever;
  import org.apache.commons.altrmi.server.impl.AbstractClassRetriever;
  
  
  /**
   * Class BaseMobileClassRetriever
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class BaseMobileClassRetriever extends AbstractClassRetriever {
  
      protected byte[] getThingBytes(String thingName) throws AltrmiClassRetrievalException
{
  
          try {
              Class clazz = Class.forName("BaseMobile" + thingName);
              BaseMobileClass bmc = (BaseMobileClass) clazz.newInstance();
  
              return bmc.getClassBytes();
          } catch (ClassNotFoundException cnfe) {
              throw new AltrmiClassRetrievalException("Generated class not found during lookup
: "
                                                      + cnfe.getMessage());
          } catch (InstantiationException ie) {
              throw new AltrmiClassRetrievalException(
                  "Generated class not instantiable during lookup : " + ie.getMessage());
          } catch (IllegalAccessException iae) {
              throw new AltrmiClassRetrievalException(
                  "Illegal access to generated class during lookup : " + iae.getMessage());
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/classretrievers/JarFileClassRetriever.java
  
  Index: JarFileClassRetriever.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.classretrievers;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
  import org.apache.commons.altrmi.server.ClassRetriever;
  import org.apache.commons.altrmi.server.impl.AbstractClassRetriever;
  
  import java.net.URLClassLoader;
  import java.net.URL;
  import java.net.MalformedURLException;
  
  import java.io.File;
  import java.io.InputStream;
  import java.io.ByteArrayInputStream;
  
  
  /**
   * Class JarFileClassRetriever
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class JarFileClassRetriever extends AbstractClassRetriever {
  
      private URLClassLoader mURLClassLoader;
  
      /**
       * Constructor JarFileClassRetriever
       *
       *
       * @param urlOfJarFile
       *
       */
      public JarFileClassRetriever(URL urlOfJarFile) {
          mURLClassLoader = new URLClassLoader(new URL[]{ urlOfJarFile });
      }
  
      /**
       * Constructor JarFileClassRetriever
       *
       *
       * @param urlsOfJarFiles
       *
       */
      public JarFileClassRetriever(URL[] urlsOfJarFiles) {
          mURLClassLoader = new URLClassLoader(urlsOfJarFiles);
      }
  
      /**
       * Constructor JarFileClassRetriever
       *
       *
       * @param pathsOfJarFiles
       *
       * @throws MalformedURLException
       *
       */
      public JarFileClassRetriever(String[] pathsOfJarFiles) throws MalformedURLException
{
  
          URL[] urls = new URL[pathsOfJarFiles.length];
  
          for (int i = 0; i < pathsOfJarFiles.length; i++) {
              urls[i] = new File(pathsOfJarFiles[i]).toURL();
          }
  
          mURLClassLoader = new URLClassLoader(urls);
      }
  
      /**
       * Constructor JarFileClassRetriever
       *
       *
       * @param pathOfJarFile
       *
       * @throws MalformedURLException
       *
       */
      public JarFileClassRetriever(String pathOfJarFile) throws MalformedURLException {
          mURLClassLoader = new URLClassLoader(new URL[]{ new File(pathOfJarFile).toURL()
});
      }
  
      /**
       * Method getThingBytes
       *
       *
       * @param thingName
       *
       * @return
       *
       * @throws AltrmiClassRetrievalException
       *
       */
      public byte[] getThingBytes(String thingName) throws AltrmiClassRetrievalException {
  
          try {
              URL rsc = mURLClassLoader.findResource(thingName);
              InputStream is = rsc.openStream();
              byte[] bytes = new byte[is.available()];
  
              is.read(bytes);
  
              return bytes;
          } catch (java.io.IOException e) {
              throw new AltrmiClassRetrievalException("Generated class not found in Jar on
server");
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/classretrievers/NoClassRetriever.java
  
  Index: NoClassRetriever.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.classretrievers;
  
  import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
  import org.apache.commons.altrmi.server.ClassRetriever;
  import org.apache.commons.altrmi.server.impl.AbstractClassRetriever;
  
  
  /**
   * Class NoClassRetriever
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class NoClassRetriever extends AbstractClassRetriever {
  
      protected byte[] getThingBytes(String thingName) throws AltrmiClassRetrievalException
{
          throw new AltrmiClassRetrievalException("This AltRMI server does not support class
forwarding");
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/classretrievers/PlainClassRetriever.java
  
  Index: PlainClassRetriever.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.classretrievers;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
  import org.apache.commons.altrmi.server.ClassRetriever;
  import org.apache.commons.altrmi.server.impl.AbstractClassRetriever;
  
  import java.io.InputStream;
  import java.io.ByteArrayOutputStream;
  import java.io.IOException;
  
  
  /**
   * Class PlainClassRetriever
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PlainClassRetriever extends AbstractClassRetriever {
  
      private ClassLoader mClassLoader;
  
      /**
       * Constructor PlainClassRetriever
       *
       *
       */
      public PlainClassRetriever() {
          mClassLoader = this.getClass().getClassLoader();
      }
  
      /**
       * Constructor PlainClassRetriever
       *
       *
       * @param cl
       *
       */
      public PlainClassRetriever(ClassLoader cl) {
          mClassLoader = cl;
      }
  
      protected byte[] getThingBytes(String thingName) throws AltrmiClassRetrievalException
{
  
          InputStream is = null;
  
          try {
              is = mClassLoader.getResourceAsStream(thingName);
          } catch (Exception e) {
              throw new AltrmiClassRetrievalException(
                  "Generated class not found in classloader specified : " + e.getMessage());
          }
  
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          int i = 0;
  
          try {
              while (-1 != (i = is.read())) {
                  baos.write(i);
              }
  
              is.close();
          } catch (IOException e) {
              throw new AltrmiClassRetrievalException("Error retrieving generated class bytes
: "
                                                      + e.getMessage());
          }
  
          return baos.toByteArray();
      }
  }
  
  
  
  1.3       +6 -2      jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/DirectTest.java
  
  Index: DirectTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/DirectTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DirectTest.java	14 Jan 2002 12:11:07 -0000	1.2
  +++ DirectTest.java	14 Jan 2002 16:36:08 -0000	1.3
  @@ -11,6 +11,7 @@
   
   import org.apache.commons.altrmi.server.impl.direct.DirectServer;
   import org.apache.commons.altrmi.server.impl.direct.DirectAltrmiInovcationAdapter;
  +import org.apache.commons.altrmi.server.impl.classretrievers.BaseMobileClassRetriever;
   import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
   import org.apache.commons.altrmi.common.AltrmiConnectionException;
   import org.apache.commons.altrmi.client.AltrmiHostContext;
  @@ -25,7 +26,7 @@
    *
    *
    * @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 DirectTest {
   
  @@ -47,6 +48,9 @@
           mServerOrClientFactory = args[0];
   
           DirectServer ds = new DirectServer();
  +        if (mServerOrClientFactory.equals("S")) {
  +            ds.setClassRetriever(new BaseMobileClassRetriever());
  +        }
           TestInterfaceImpl ti = new TestInterfaceImpl();
   
           ds.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
  @@ -63,7 +67,7 @@
        *
        *
        * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  -     * @version $Revision: 1.2 $
  +     * @version $Revision: 1.3 $
        */
       static class DirectTestClient implements Runnable {
   
  
  
  
  1.4       +6 -2      jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/PipeTest.java
  
  Index: PipeTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/PipeTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- PipeTest.java	14 Jan 2002 12:11:07 -0000	1.3
  +++ PipeTest.java	14 Jan 2002 16:36:08 -0000	1.4
  @@ -10,6 +10,7 @@
   
   
   import org.apache.commons.altrmi.server.impl.piped.PipedServer;
  +import org.apache.commons.altrmi.server.impl.classretrievers.BaseMobileClassRetriever;
   import org.apache.commons.altrmi.client.AltrmiHostContext;
   import org.apache.commons.altrmi.client.impl.socket.SocketObjectStreamHostContext;
   import org.apache.commons.altrmi.client.AltrmiFactory;
  @@ -26,7 +27,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.3 $
  + * @version $Revision: 1.4 $
    */
   public class PipeTest {
   
  @@ -48,6 +49,9 @@
           mServerOrClientFactory = args[0];
   
           PipedServer ps = new PipedServer();
  +        if (mServerOrClientFactory.equals("S")) {
  +            ps.setClassRetriever(new BaseMobileClassRetriever());
  +        }
           TestInterfaceImpl ti = new TestInterfaceImpl();
   
           ps.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
  @@ -64,7 +68,7 @@
        *
        *
        * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  -     * @version $Revision: 1.3 $
  +     * @version $Revision: 1.4 $
        */
       static class PipedTestClient implements Runnable {
   
  
  
  
  1.2       +5 -1      jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/RmiServerTest.java
  
  Index: RmiServerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/RmiServerTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RmiServerTest.java	9 Jan 2002 19:25:56 -0000	1.1
  +++ RmiServerTest.java	14 Jan 2002 16:36:08 -0000	1.2
  @@ -10,6 +10,7 @@
   
   
   import org.apache.commons.altrmi.server.impl.rmi.RmiServer;
  +import org.apache.commons.altrmi.server.impl.classretrievers.BaseMobileClassRetriever;
   
   import java.io.IOException;
   
  @@ -19,7 +20,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 RmiServerTest {
   
  @@ -37,6 +38,9 @@
           System.out.println("AltRMI over RMI Server");
   
           RmiServer rs = new RmiServer("127.0.0.1", 4321);
  +        if (args[0].equals("S")) {
  +            rs.setClassRetriever(new BaseMobileClassRetriever());
  +        }
           TestInterfaceImpl ti = new TestInterfaceImpl();
   
           rs.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
  
  
  
  1.3       +8 -4      jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/SocketServerTest.java
  
  Index: SocketServerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/SocketServerTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SocketServerTest.java	10 Jan 2002 00:08:59 -0000	1.2
  +++ SocketServerTest.java	14 Jan 2002 16:36:08 -0000	1.3
  @@ -10,6 +10,7 @@
   
   
   import org.apache.commons.altrmi.server.impl.socket.CompleteSocketObjectStreamServer;
  +import org.apache.commons.altrmi.server.impl.classretrievers.BaseMobileClassRetriever;
   
   import java.io.IOException;
   
  @@ -19,7 +20,7 @@
    *
    *
    * @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 SocketServerTest {
   
  @@ -36,10 +37,13 @@
   
           System.out.println("Stream over Socket Server");
   
  -        CompleteSocketObjectStreamServer pss = new CompleteSocketObjectStreamServer(1234);
  +        CompleteSocketObjectStreamServer csoss = new CompleteSocketObjectStreamServer(1234);
  +        if (args[0].equals("S")) {
  +            csoss.setClassRetriever(new BaseMobileClassRetriever());
  +        }
           TestInterfaceImpl ti = new TestInterfaceImpl();
   
  -        pss.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
  -        pss.start();
  +        csoss.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
  +        csoss.start();
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message