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 2002/01/09 20:25:56 UTC

cvs commit: jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test DirectTest.java PipeTest.java RmiClientTest.java RmiServerTest.java SocketClientTest.java SocketServerTest.java TestClient.java TestInterface.java TestInterface2.java TestInterface2Impl.java TestInterfaceImpl.java

hammant     02/01/09 11:25:56

  Added:       altrmi   LICENSE PROPOSAL README.txt altrmi-tests.xml
                        build.xml
               altrmi/src/java/org/apache/commons/altrmi/client
                        AltrmiConnectionListener.java AltrmiFactory.java
                        AltrmiHostContext.java
               altrmi/src/java/org/apache/commons/altrmi/client/impl
                        AbstractAltrmiFactory.java
                        AbstractAltrmiHostContext.java
                        AltrmiClientInvocationHandler.java
                        BaseServedObject.java ClientClassAltrmiFactory.java
                        DefaultAltrmiConnectionListener.java
                        ObjectStreamInvocationHandler.java
                        ServerClassAltrmiFactory.java
                        TransportedClassLoader.java
               altrmi/src/java/org/apache/commons/altrmi/client/impl/direct
                        DirectAltrmiHostContext.java
                        DirectInvocationHandler.java
               altrmi/src/java/org/apache/commons/altrmi/client/impl/piped
                        PipedAltrmiHostContext.java
                        PipedInvocationHandler.java
               altrmi/src/java/org/apache/commons/altrmi/client/impl/rmi
                        RmiAltrmiHostContext.java RmiInvocationHandler.java
               altrmi/src/java/org/apache/commons/altrmi/client/impl/socket
                        PlainSocketAltrmiHostContext.java
                        PlainSocketInvocationHandler.java
               altrmi/src/java/org/apache/commons/altrmi/common
                        AbstractMethodHandler.java
                        AltrmiConnectionException.java
                        AltrmiInvocationException.java
                        AltrmiInvocationHandler.java
                        AltrmiPipeConnector.java AltrmiReply.java
                        AltrmiRequest.java ClassReply.java
                        ClassRequest.java EndConnectionReply.java
                        ExceptionReply.java FacadeRefHolder.java
                        LookupReply.java LookupRequest.java
                        MethodFacadeReply.java MethodFacadeRequest.java
                        MethodReply.java MethodRequest.java
                        NoSuchReferenceReply.java
                        NotPublishedException.java NotPublishedReply.java
                        NotSuchReferenceException.java
                        PublishedNameRequest.java RequestFailedReply.java
                        RmiAltrmiInvocationHandler.java SuspendedReply.java
                        TryLaterReply.java
               altrmi/src/java/org/apache/commons/altrmi/generator
                        PrimarySourceGenerator.java
                        SecondarySourceGenerator.java
                        SourceGenerationException.java
               altrmi/src/java/org/apache/commons/altrmi/generator/ant
                        AltrmiClassInternTask.java AltrmiInterfaceTask.java
               altrmi/src/java/org/apache/commons/altrmi/server
                        AltrmiClassRetrievalException.java
                        AltrmiPublicationException.java
                        AltrmiPublisher.java AltrmiServer.java
                        AltrmiServerConnection.java
                        AltrmiServerException.java
                        AltrmiServerInvocationHandler.java
                        ClassRetriever.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl
                        AbstractServer.java BaseMobileClass.java
                        BaseMobileClassRetriever.java
                        DefaultInvocationHandler.java
                        JarFileClassRetriever.java
                        ObjectStreamServerConnection.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl/direct
                        DirectAltrmiInovcationAdapter.java
                        DirectServer.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl/piped
                        PipedObjectStreamServerConnection.java
                        PipedServer.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl/rmi
                        RmiAltrmiInovcationAdapter.java RmiServer.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl/socket
                        PlainSocketServer.java
                        SocketObjectStreamServerConnection.java
               altrmi/src/java/org/apache/commons/altrmi/test
                        DirectTest.java PipeTest.java RmiClientTest.java
                        RmiServerTest.java SocketClientTest.java
                        SocketServerTest.java TestClient.java
                        TestInterface.java TestInterface2.java
                        TestInterface2Impl.java TestInterfaceImpl.java
  Log:
  ARMI renamed to AltRMI
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/altrmi/LICENSE
  
  Index: LICENSE
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 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/>.
   */
  
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/PROPOSAL
  
  Index: PROPOSAL
  ===================================================================
  --------------------------------------------------------------------------
    JAKARTA COMMONS  -  ALTERNATE (TO) REMOTE METHOD INVOCATION - "ARMI"
  --------------------------------------------------------------------------
  
  Abstract:
  
  The ARMI package provides an alternative to Java's RMI.  Apart from simply 
  being an alternative it provides the following features:
  
  1) Any interface publishing
  
    - no forcing of extension of java.rmi.Remote
    - no forced declarations of "throws RemoteException"
    
    * These two features are part of the reason why Graham Glass's 'Glue'
      product is so successful. His API goes several stages futher in that
      it pubishes APIs via SOAP so that any language in any location can
      use Glue published Java services.
    
  2) Multiple transports
  
    - Plain Sockets / ObjectStream
    - via RMI
    - Piped with same VM / ObjectStream
    - Direct within same VM
    - SOAP (planned)
        - Might require additional undynamic "toWSDL()" step.
    - CORBA (planned)
        - Might require additional undynamic "toIDL()" step.
    - Plain sockets / custom messaging (planned)
    - JMS (planned)
    
  3) Speed  
  
    - Using the ARMI over RMI transport as a baseline.  Measuring 100,000 
      method invocations after discarding the first for the purposes of 
      timing, ObjStream over sockets is three times faster, ObjStream over 
      Pipe is eleven times faster, Direct is a thousand times faster. Granted
      there could be less of an advantage if compared to a proper RMI solution
      (not layered), or one that is in the same VM with different threads.
  
  4) Interface/Impl separated design.
  
    - ARMI can be build easily into any application or application framework.  
      Individual aspects can be reimplemented (or overridden) as the need 
      arises.
  
  5) Choice of location of generated Proxy class.
  
    - Classes providing client side implementation of the transported 
      interface(s) can be either on the client side or the server side (and 
      duly transported) at time of lookup.
      
  6) Choice of castability of generated proxy class.
  
    - To suit remote facilities that are happy with refection and do 
      not need to cast to an interface to use a bean (I am thinking of 
      beanshell) the proxy class can be generated without specifying
      that it implements the interface(s).
  
  7) Suspendable/Resumable service.
  
    - The Server supports suspend() and resume().  With the current impl this 
      replies in a timely fashion to the client that the client should try
      later.  The client waits for the notified amount of time and seamlessly
      trys the requets again.  A server could cycle through suspended and back
      to resumed will not affect the client except for the a delay.
  
  8) Recovering transport
  
    - ARMI tries to recover its transports should they fail.  The recovery 
      is pluggable in that the developer can choose when/how/if the connection
      handler tries to recover the connection.  Any inprogress, but
      disconnected method invocation will attempt to be recoved and just return
      as normal, albeit after a longer than normal delay.
    
  9) Event API
  
    - For suspensions, abnormal ends of connection etc, there is a listener 
      that can be set that will allow actions to be taken.  Abnormally 
      terminated connections will by default try to be reconnected, the 
      listener can decide if, how many, and how often the retries occur.
  
  10) Unpublishable and republishable API
    
    - The server is able to unpublish a service.  In conjuction with 
      suspend()/resume() a service can be republished, upgraded etc
      whilst in use, or just offlined.
  
  11) Startable API for Server
  
    - The server implements and acts upon start() and stop() methods.
  
  12) No just pass by value.
  
    - ARMI started life as 'pass by value' only.  In now supports return 
      types and parameters wrapped in another ARMI Facade.
      
  13) No duplicate instances.
  
    - If you call Person p = getPerson("Fred") twice you will get the same instance 
      on the client side is it is the same instance on the server side.
  
  Limitations:
   
  1) Use in EJB 
  
    - This is not of any use for EJB Home/Remote interfaces.  The container 
      maker chooses the transport for use that container, not the bean coder.
      This is intended for other client server solutions.  Beside RMI over IIOP
      is Sun specified.
  
  Todo:
  
  1) BCEL for generated proxy class.
  
    - The current impl writes java source then compiles it.  We could do this
      inline with BCEL.  This as an heavier, but more design perfect 
      alternative to the current server side impl.
       
  2) Client and Server code for secure conversations.
  
  3) Authentication and Authorisation on lookup(..).
  
  Initial committers:
  
  Paul Hammant (hammant)
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/README.txt
  
  Index: README.txt
  ===================================================================
  --------------------------------------------------------------------------
    JAKARTA  COMMONS  -  ALTERNATE (TO) REMOTE METHOD INVOCATION - "ALTRMI"
  --------------------------------------------------------------------------
  
  o Building
  
  To build, you must have ant installed.  Just type 'ant' -- the default
  target will compile the classes (no jars at present)
  
  o Demonstration of transport (see test package)
  
  To test ObjectStream over Socket transport:
  
    In DOS shell #1 - "ant -buildfile altrmi-tests.xml test1a-serve"
    In DOS shell #2 - "ant -buildfile altrmi-tests.xml test1a-client" 
    
  To test ObjectStream Piped transport
  
    In DOS shell #1 - "ant -buildfile altrmi-tests.xml test2a"
    
  To test (AltRMI over) RMI transport:  
  
    In DOS shell #1 - "ant -buildfile altrmi-tests.xml test3a-serve"
    In DOS shell #2 - "ant -buildfile altrmi-tests.xml test3a-client" 
    
  To test Direct transport
  
    In DOS shell #1 - "ant -buildfile altrmi-tests.xml test4a"  
  
  To test with class definition forwarding (from server to client), 
  same as above four tests, but with "b" instead of "a" in the target name.
  
  o Use in your application
  
  To-be-advised
  
  
  1.1                  jakarta-commons-sandbox/altrmi/altrmi-tests.xml
  
  Index: altrmi-tests.xml
  ===================================================================
  <project name="Alt (to) RMI" default="generate" basedir=".">
  
  
  <!--
          "Alt (to) RMI" component of the Jakarta Commons Subproject
          $Id: altrmi-tests.xml,v 1.1 2002/01/09 19:25:53 hammant Exp $
  -->
  
  
  <!-- ========== Initialize Properties ===================================== -->
  
  
    <property file="build.properties"/>                <!-- Component local   -->
    <property file="../build.properties"/>             <!-- Commons local     -->
    <property file="${user.home}/build.properties"/>   <!-- User local        -->
   
  
  <!-- ========== Component Declarations ==================================== -->
  
  
    <!-- The base directory for compilation targets -->
    <property name="build.home"              value="build"/>
  
  
  <!-- ========== Compiler Defaults ========================================= -->
  
  
    <!-- Should Java compilations set the 'debug' compiler option? -->
    <property name="compile.debug"           value="true"/>
  
    <!-- Should Java compilations set the 'deprecation' compiler option? -->
    <property name="compile.deprecation"     value="true"/>
  
    <!-- Should Java compilations set the 'optimize' compiler option? -->
    <property name="compile.optimize"        value="true"/>
  
    <!-- Construct compile classpath -->
    <path id="compile.classpath">
      <pathelement location="${build.home}/classes"/>
    </path>
    
    <!-- For running of tests -->
    <path id="testA.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${build.home}/classes2"/>
      <pathelement location="lib/bcel.jar"/>
    </path>  
    
    <path id="testB1.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${build.home}/classes3"/>
    </path>    
      
    <path id="testB2.classpath">
      <pathelement location="${build.home}/classes"/>
    </path>    
    
    
  
    <taskdef name="altrmiinterfaces" classname="org.apache.commons.altrmi.generator.ant.AltrmiInterfaceTask">
      <classpath refid="compile.classpath" />
    </taskdef>
    
    <taskdef name="altrmiclassintern" classname="org.apache.commons.altrmi.generator.ant.AltrmiClassInternTask">
      <classpath refid="compile.classpath" />
    </taskdef>
  
  
  <!-- ========== Executable Targets ======================================== -->
  
    <target name="prepare"
     description="Prepare build directory">
      <mkdir dir="${build.home}"/>
      <mkdir dir="${build.home}/classes2"/>  
      <delete>
        <fileset dir="${build.home}/classes2" includes="*" defaultexcludes="no"/>
      </delete>
      <mkdir dir="${build.home}/genjava"/>
      <delete>
        <fileset dir="${build.home}/genjava" includes="*" defaultexcludes="no"/>
      </delete>
      <mkdir dir="${build.home}/genjava2"/>
      <delete>
        <fileset dir="${build.home}/genjava2" includes="*" defaultexcludes="no"/>
      </delete>
      <mkdir dir="${build.home}/classes3"/>  
      <delete>
        <fileset dir="${build.home}/classes3" includes="*" defaultexcludes="no"/>
      </delete>
    </target>
  
    <target name="generate" depends="prepare">
       
      <altrmiinterfaces genname="Hello" gendir="${build.home}/genjava" 
          classesorinterfaces="org.apache.commons.altrmi.test.TestInterface" 
          additionalfacades="org.apache.commons.altrmi.test.TestInterface2"/>
  
      <javac  srcdir="${build.home}/genjava"
                 destdir="${build.home}/classes2"
                   debug="${compile.debug}"
             deprecation="${compile.deprecation}"
                optimize="${compile.optimize}">
            <classpath refid="compile.classpath"/>
      </javac>
    
      <altrmiclassintern gendir="${build.home}/genjava2" 
          sourceclassdir="${build.home}/classes2/"
          sourceclassfilestem="AltrmiGeneratedHello" />  
  
      <javac  srcdir="${build.home}/genjava2"
                 destdir="${build.home}/classes3"
                   debug="${compile.debug}"
             deprecation="${compile.deprecation}"
                optimize="${compile.optimize}">
            <classpath refid="compile.classpath"/>
      </javac>
  
    
    </target>
  
    <target name="test1a-serve">
      <java classname="org.apache.commons.altrmi.test.SocketServerTest" fork="true">
        <classpath refid="testA.classpath"/>
      </java>      
    </target>
    
    <target name="test1a-client" depends="generate">
      <java classname="org.apache.commons.altrmi.test.SocketClientTest" fork="true">
        <classpath refid="testA.classpath"/>
        <arg value="C"/>
      </java>      
    </target>
  
    <target name="test2a" depends="generate">
      <java classname="org.apache.commons.altrmi.test.PipeTest" fork="true">
        <classpath refid="testA.classpath"/>
        <arg value="C"/>
      </java>      
    </target>
  
    <target name="test3a-serve">
      <java classname="org.apache.commons.altrmi.test.RmiServerTest" fork="true">
        <classpath refid="testA.classpath"/>
      </java>      
    </target>
    
    <target name="test3a-client" depends="generate">
      <java classname="org.apache.commons.altrmi.test.RmiClientTest" fork="true">
        <classpath refid="testA.classpath"/>
        <arg value="C"/>
      </java>      
    </target>
  
    <target name="test4a" depends="generate">
      <java classname="org.apache.commons.altrmi.test.DirectTest" fork="true">
        <classpath refid="testA.classpath"/>
        <arg value="C"/>
      </java>      
    </target>
  
    <target name="test1b-serve">
      <java classname="org.apache.commons.altrmi.test.SocketServerTest" fork="true">
        <classpath refid="testB1.classpath"/>
      </java>      
    </target>
    
    <target name="test1b-client" depends="generate">
      <java classname="org.apache.commons.altrmi.test.SocketClientTest" fork="true">
        <classpath refid="testB2.classpath"/>
        <arg value="S"/>
      </java>      
    </target>
  
    <target name="test2b" depends="generate">
      <java classname="org.apache.commons.altrmi.test.PipeTest" fork="true">
        <classpath refid="testB1.classpath"/>
        <arg value="S"/>
      </java>      
    </target>
  
    <target name="test3b-serve">
      <java classname="org.apache.commons.altrmi.test.RmiServerTest" fork="true">
        <classpath refid="testB1.classpath"/>
      </java>      
    </target>
    
    <target name="test3b-client" depends="generate">
      <java classname="org.apache.commons.altrmi.test.RmiClientTest" fork="true">
        <classpath refid="testB2.classpath"/>
        <arg value="S"/>
      </java>      
    </target>
  
    <target name="test4b" depends="generate">
      <java classname="org.apache.commons.altrmi.test.DirectTest" fork="true">
        <classpath refid="testB1.classpath"/>
        <arg value="S"/>
      </java>      
    </target>
  
    <target name="test4c" depends="generate">
      <java classname="org.apache.commons.altrmi.test.DirectTestC" fork="true">
        <classpath refid="testA.classpath"/>
      </java>      
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/build.xml
  
  Index: build.xml
  ===================================================================
  <project name="Alternative (to) RMI" default="compile" basedir=".">
  
  
  <!--
          "Alternative (to) RMI" component of the Jakarta Commons Subproject
          $Id: build.xml,v 1.1 2002/01/09 19:25:53 hammant Exp $
  -->
  
  
  <!-- ========== Initialize Properties ===================================== -->
  
  
    <property file="build.properties"/>                <!-- Component local   -->
    <property file="../build.properties"/>             <!-- Commons local     -->
    <property file="${user.home}/build.properties"/>   <!-- User local        -->
  
  
  <!-- ========== External Dependencies ===================================== -->
  
  
    <!-- The home directory for the Commons collection classes distribution -->
    <property name="commons-collections.home" value="../collections/dist"/>
  
    <!-- The directory containing your binary distribution of JUnit,
         version 3.7 or later -->
    <property name="junit.home"              value="/usr/local/junit3.7"/>
   
  
  <!-- ========== Derived Values ============================================ -->
  
  
    <!-- The pathname of the collections classes JAR file -->
    <property name="commons-collections.jar" value="${commons-collections.home}/commons-collections.jar"/>
  
    <!-- The pathname of the "junit.jar" JAR file -->
    <property name="junit.jar"               value="${junit.home}/junit.jar"/>
  
  
  <!-- ========== Component Declarations ==================================== -->
  
  
    <!-- The name of this component -->
    <property name="component.name"          value="altrmi"/>
  
    <!-- The primary package name of this component -->
    <property name="component.package"       value="org.apache.commons.altrmi"/>
  
    <!-- The title of this component -->
    <property name="component.title"         value="Alternative to RMI"/>
  
    <!-- The current version number of this component -->
    <property name="component.version"       value="1.0-dev"/>
  
    <!-- The base directory for compilation targets -->
    <property name="build.home"              value="build"/>
  
  
    <!-- The base directory for distribution targets -->
    <property name="dist.home"               value="dist"/>
  
    <!-- The base directory for component sources -->
    <property name="source.home"             value="src/java"/>
  
    <!-- The base directory for unit test sources -->
    <property name="test.home"               value="src/test"/>
  
  
  <!-- ========== Compiler Defaults ========================================= -->
  
  
    <!-- Should Java compilations set the 'debug' compiler option? -->
    <property name="compile.debug"           value="true"/>
  
    <!-- Should Java compilations set the 'deprecation' compiler option? -->
    <property name="compile.deprecation"     value="true"/>
  
    <!-- Should Java compilations set the 'optimize' compiler option? -->
    <property name="compile.optimize"        value="true"/>
  
    <!-- Construct compile classpath -->
    <path id="compile.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${commons-collections.jar}"/>
    </path>
  
  <!-- ========== Test Execution Defaults =================================== -->
  
  
    <!-- Construct unit test classpath -->
    <path id="test.classpath">
      <pathelement location="${build.home}/classes"/>
      <pathelement location="${build.home}/tests"/>
      <pathelement location="${commons-collections.jar}"/>
      <pathelement location="${junit.jar}"/>    
    </path>
  
    <!-- Should all tests fail if one does? -->
    <property name="test.failonerror"        value="true"/>
  
    <!-- The test runner to execute -->
    <property name="test.runner"             value="junit.textui.TestRunner"/>
  
  
  <!-- ========== Executable Targets ======================================== -->
  
  
    <target name="init"
     description="Initialize and evaluate conditionals">
      <echo message="-------- ${component.name} ${component.version} --------"/>
      <filter  token="name"                  value="${component.name}"/>
      <filter  token="package"               value="${component.package}"/>
      <filter  token="version"               value="${component.version}"/>
    </target>
  
  
    <target name="prepare" depends="init"
     description="Prepare build directory">
      <mkdir dir="${build.home}"/>
      <mkdir dir="${build.home}/classes"/>
      <mkdir dir="${build.home}/classes2"/>  
      <delete>
        <fileset dir="${build.home}/classes2" includes="*" defaultexcludes="no"/>
      </delete>     
      <mkdir dir="${build.home}/genjava"/>
      <delete>
        <fileset dir="${build.home}/genjava" includes="*" defaultexcludes="no"/>
      </delete>     
      <mkdir dir="${build.home}/conf"/>
      <mkdir dir="${build.home}/tests"/>
    </target>
  
  
    <target name="compile" depends="prepare" description="Compile shareable components">
  
      <javac  srcdir="${source.home}"
             destdir="${build.home}/classes"
               debug="${compile.debug}"
         deprecation="${compile.deprecation}"
            optimize="${compile.optimize}">
        <classpath refid="compile.classpath"/>
      </javac>
      
      <rmic base="${build.home}/classes"
            includes="org/apache/commons/altrmi/server/impl/rmi/RmiAltrmiInovcationAdapter.class">
          <classpath refid="compile.classpath" />    
      </rmic>    
      
    </target>
  
    <target name="clean"
     description="Clean build and distribution directories">
      <delete    dir="${build.home}"/>
      <delete    dir="${dist.home}"/>
    </target>
  
  
    <target name="all" depends="clean,compile"
     description="Clean and compile all components"/>
  
  
    <target name="javadoc" depends="compile"
     description="Create component Javadoc documentation">
      <mkdir      dir="${dist.home}"/>
      <mkdir      dir="${dist.home}/docs"/>
      <mkdir      dir="${dist.home}/docs/api"/>
      <javadoc sourcepath="${source.home}"
                  destdir="${dist.home}/docs/api"
             packagenames="org.apache.commons.*"
                   author="true"
                  private="true"
                  version="true"
                 doctitle="&lt;h1&gt;${component.title}&lt;/h1&gt;"
              windowtitle="${component.title} (Version ${component.version})"
                   bottom="Copyright (c) 2001 - Apache Software Foundation"/>
    </target>
  
  
    <target name="dist" depends="compile,javadoc"
     description="Create binary distribution">
      <mkdir      dir="${dist.home}"/>
      <copy      file="../LICENSE"
                todir="${dist.home}"/>
  
      <jar    jarfile="${dist.home}/commons-${component.name}-common.jar"
              basedir="${build.home}/classes"
             manifest="src/conf/MANIFEST.MF">
        <include name="org/apache/commons/altrmi/common/**"/>
      </jar>
                
      <jar    jarfile="${dist.home}/commons-${component.name}-client-interfaces.jar"
              basedir="${build.home}/classes"
             manifest="src/conf/MANIFEST.MF">
        <include name="org/apache/commons/altrmi/client/*"/>
      </jar>
      
      <jar    jarfile="${dist.home}/commons-${component.name}-client-impl.jar"
              basedir="${build.home}/classes"
             manifest="src/conf/MANIFEST.MF">
        <include name="org/apache/commons/altrmi/client/impl/**"/>
      </jar>    
      
      <jar    jarfile="${dist.home}/commons-${component.name}-server-interfaces.jar"
              basedir="${build.home}/classes"
             manifest="src/conf/MANIFEST.MF">
        <include name="org/apache/commons/altrmi/server/*"/>
      </jar>    
      
      <jar    jarfile="${dist.home}/commons-${component.name}-server-impl.jar"
              basedir="${build.home}/classes"
             manifest="src/conf/MANIFEST.MF">
        <include name="org/apache/commons/altrmi/server/impl/**"/>
      </jar>    
  
      
      <jar    jarfile="${dist.home}/commons-${component.name}-generator.jar"
              basedir="${build.home}/classes"
             manifest="src/conf/MANIFEST.MF">
        <include name="org/apache/commons/altrmi/generator/**"/>
      </jar>    
      
    </target>
  
  </project>
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/AltrmiConnectionListener.java
  
  Index: AltrmiConnectionListener.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  
  
  /**
   * Interface AltrmiConnectionListener
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface AltrmiConnectionListener {
  
      /**
       * Method methodCalled
       *
       *
       * @return
       *
       */
      void methodCalled(String methodSignature, long duration);
  
  
      /**
       * Method methodLogging tests if the implementing class intends to do method logging.
       *
       *
       * @return
       *
       */
      boolean methodLogging();
  
      /**
       * Method serviceSuspended
       *
       *
       * @return
       *
       */
      void serviceSuspended(AltrmiRequest altrmiRequest, int attempt, int suggestedWaitMillis);
  
      /**
       * Method serviceAbend
       *
       *
       * @return
       *
       */
      void serviceAbend(int attempt);
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/AltrmiFactory.java
  
  Index: AltrmiFactory.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;
  
  
  
  import org.apache.commons.altrmi.client.impl.ClientClassAltrmiFactory;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  
  /**
   * Interface AltrmiFactory
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public interface AltrmiFactory {
  
  
      /**
       * Method lookup
       *
       *
       * @param publishedServiceName
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      Object lookup(String publishedServiceName) throws AltrmiConnectionException;
  
      /**
       * Method setHostContext
       *
       *
       * @param hostContext
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      void setHostContext(AltrmiHostContext hostContext);
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/AltrmiHostContext.java
  
  Index: AltrmiHostContext.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  
  
  /**
   * Interface AltrmiHostContext
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface AltrmiHostContext {
  
      /**
       * Method getInvocationHandler
       *
       *
       * @return
       *
       */
      AltrmiInvocationHandler getInvocationHandler();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/AbstractAltrmiFactory.java
  
  Index: AbstractAltrmiFactory.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;
  
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.client.AltrmiHostContext;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  import java.util.HashMap;
  
  /**
   * Class AbstractAltrmiFactory
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AbstractAltrmiFactory implements AltrmiFactory {
  
      protected AltrmiHostContext mHostContext;
      protected HashMap mObjRefs = new HashMap();
      protected HashMap mRefObjs = new HashMap();
  
  
      /**
       * Method setHostContext
       *
       *
       * @param hostContext
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      public void setHostContext(AltrmiHostContext hostContext) {
          if (mHostContext == null) {
              mHostContext = hostContext;
          }
      }
  
      /**
       * Method getInstance
       *
       *
       * @param publishedServiceName
       * @param String objectName
       * @param BaseServedObject baseServedObject
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      protected abstract Object getInstance(String publishedServiceName, String objectName, BaseServedObject baseServedObject) throws AltrmiConnectionException;
  
      /**
       * Method registerReferenceObject
       *
       *
       * @param ojb
       * @param String referenceID
       *
       * @return
       *
       *
       */
      public void registerReferenceObject(Object obj, String referenceID) {
          mObjRefs.put(obj, referenceID);
          mRefObjs.put(referenceID, obj);
      }
  
      public String getReferenceID(Object obj) {
          return (String) mObjRefs.get(obj);
      }
  
      public Object getImplObj(String referenceID) {
          return mRefObjs.get(referenceID);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/AbstractAltrmiHostContext.java
  
  Index: AbstractAltrmiHostContext.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.client.AltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiConnectionListener;
  
  
  /**
   * Class AbstractAltrmiHostContext
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AbstractAltrmiHostContext implements AltrmiHostContext {
  
      private final AltrmiClientInvocationHandler mAltrmiClientInvocationHandler;
  
      /**
       * Constructor AbstractAltrmiHostContext
       *
       *
       * @param altrmiInvocationHandler
       *
       */
      public AbstractAltrmiHostContext(AltrmiClientInvocationHandler altrmiClientInvocationHandler) {
          this.mAltrmiClientInvocationHandler = altrmiClientInvocationHandler;
      }
  
      /**
       * Method getInvocationHandler
       *
       *
       * @return
       *
       */
      public AltrmiInvocationHandler getInvocationHandler() {
          return mAltrmiClientInvocationHandler;
      }
  
      /**
       * Method setAltrmiConnectionListener
       *
       *
       * @param altrmiInvocationHandler
       * @return
       *
       */
      public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener) {
          mAltrmiClientInvocationHandler.setAltrmiConnectionListener(altrmiConnectionListener);
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/AltrmiClientInvocationHandler.java
  
  Index: AltrmiClientInvocationHandler.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.client.AltrmiConnectionListener;
  
  
  /**
   * Class AltrmiClientInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AltrmiClientInvocationHandler implements AltrmiInvocationHandler {
  
      protected AltrmiConnectionListener mAltrmiConnectionListener =
          new DefaultAltrmiConnectionListener();
  
      /**
       * Method setAltrmiConnectionListener
       *
       *
       * @param altrmiConnectionListener
       *
       */
      public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener) {
          mAltrmiConnectionListener = altrmiConnectionListener;
      }
  
      protected abstract boolean tryReconnect();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/BaseServedObject.java
  
  Index: BaseServedObject.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;
  
  
  
  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.MethodReply;
  import org.apache.commons.altrmi.common.MethodRequest;
  import org.apache.commons.altrmi.common.ExceptionReply;
  import org.apache.commons.altrmi.common.AltrmiInvocationException;
  import org.apache.commons.altrmi.common.MethodFacadeReply;
  import org.apache.commons.altrmi.common.MethodFacadeRequest;
  import org.apache.commons.altrmi.common.FacadeRefHolder;
  
  
  /**
   * Class BaseServedObject
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class BaseServedObject {
  
      private final AbstractAltrmiFactory mAltrmiFactory;
      private final AltrmiInvocationHandler mInvocationHandler;
      private final String mPublishedServiceName;
      private final String mObjectName;
      private final String mReferenceID;
  
      public BaseServedObject(AbstractAltrmiFactory altrmiFactory, AltrmiInvocationHandler invocationHandler, String pubishedServiceName, String objectName, String referenceID) {
          mAltrmiFactory = altrmiFactory;
          mInvocationHandler = invocationHandler;
          mPublishedServiceName = pubishedServiceName;
          mObjectName = objectName;
          mReferenceID = referenceID;
      }
  
      /**
       * Method registerImplObject
       *
       *
       * @param implBean
       *
       */
      public void registerImplObject(Object implBean) {
          mAltrmiFactory.registerReferenceObject(implBean,mReferenceID);
      }
  
      /**
       * Method altrmiProcessObjectRequest
       *
       *
       * @param methodSignature
       * @param args
       *
       * @return
       *
       * @throws Throwable
       *
       */
      public Object altrmiProcessObjectRequestGettingFacade(String methodSignature, Object[] args, String objectName)
         throws Throwable {
  
          MethodFacadeRequest request = new MethodFacadeRequest(mPublishedServiceName, mObjectName, methodSignature, args, mReferenceID, objectName);
  
          AltrmiReply reply = mInvocationHandler.handleInvocation(request);
  
          if (reply.getReplyCode() == AltrmiReply.METHODFACADEREPLY) {
              MethodFacadeReply mfr = (MethodFacadeReply) reply;
  
              String ref = mfr.getReferenceID();
              Object implBean = mAltrmiFactory.getImplObj(ref);
              if (implBean == null) {
                  BaseServedObject bo2 = new BaseServedObject(mAltrmiFactory, mInvocationHandler, mPublishedServiceName, objectName, ref);
                  Object retFacade = mAltrmiFactory.getInstance(mPublishedServiceName, objectName ,bo2);
                  bo2.registerImplObject(retFacade);
                  return retFacade;
              } else {
                  return implBean;
              }
          } else if (reply.getReplyCode() == AltrmiReply.EXCEPTIONREPLY) {
              ExceptionReply er = (ExceptionReply) reply;
              throw er.getReplyException();
          } else {
              throw new AltrmiInvocationException("Internal Error : Unknown reply type :"
                                                + reply.getClass().getName());
          }
      }
  
      /**
       * Method altrmiProcessObjectRequest
       *
       *
       * @param methodSignature
       * @param args
       *
       * @return
       *
       * @throws Throwable
       *
       */
      public Object altrmiProcessObjectRequest(String methodSignature, Object[] args)
              throws Throwable {
  
  
          MethodRequest request = new MethodRequest(mPublishedServiceName, mObjectName, methodSignature, args, mReferenceID);
  
          AltrmiReply reply = mInvocationHandler.handleInvocation(request);
  
          if (reply.getReplyCode() == AltrmiReply.METHODREPLY) {
              MethodReply or = (MethodReply) reply;
              return or.getReplyObject();
          } else if (reply.getReplyCode() == AltrmiReply.EXCEPTIONREPLY) {
              ExceptionReply er = (ExceptionReply) reply;
              throw er.getReplyException();
          } else {
              throw new AltrmiInvocationException("Internal Error : Unknown reply type :"
                                                + reply.getClass().getName());
          }
      }
  
      /**
       * Method altrmiProcessVoidRequest
       *
       *
       * @param methodSignature
       * @param args
       *
       * @throws Throwable
       *
       */
      public void altrmiProcessVoidRequest(String methodSignature, Object[] args) throws Throwable {
  
          MethodRequest request = new MethodRequest(mPublishedServiceName, mObjectName, methodSignature, args, mReferenceID);
  
          AltrmiReply reply = mInvocationHandler.handleInvocation(request);
  
          if (reply.getReplyCode() == AltrmiReply.METHODREPLY) {
              MethodReply or = (MethodReply) reply;
  
              return;
          } else if (reply.getReplyCode() == AltrmiReply.EXCEPTIONREPLY) {
              ExceptionReply er = (ExceptionReply) reply;
  
              throw er.getReplyException();
          } else {
              throw new AltrmiInvocationException("Internal Error : Unknown reply type :"
                                                + reply.getClass().getName());
          }
  
      }
  
      public FacadeRefHolder makeFacadeRefHolder(Object obj, String objectName) {
          String refID = mAltrmiFactory.getReferenceID(obj);
          return new FacadeRefHolder(refID,objectName);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/ClientClassAltrmiFactory.java
  
  Index: ClientClassAltrmiFactory.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;
  
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.client.AltrmiHostContext;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.common.LookupReply;
  import org.apache.commons.altrmi.common.LookupRequest;
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.NotPublishedReply;
  
  import java.lang.reflect.Constructor;
  import java.lang.reflect.InvocationTargetException;
  
  /**
   * Class ClientClassAltrmiFactory
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class ClientClassAltrmiFactory extends AbstractAltrmiFactory {
  
      /**
       * Method lookup
       *
       *
       * @param publishedServiceName
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      public Object lookup(String publishedServiceName)
              throws AltrmiConnectionException {
          AltrmiReply ar = mHostContext.getInvocationHandler().handleInvocation(new LookupRequest(publishedServiceName));
          if (ar.getReplyCode() >= AltrmiReply.PROBLEMREPLY) {
              if (ar instanceof NotPublishedReply) {
                  throw new AltrmiConnectionException("Service " + publishedServiceName + " not published");
              } else {
                  throw new AltrmiConnectionException("Problem doing lookup on service");
              }
          }
          LookupReply lr = (LookupReply) ar;
          BaseServedObject bo = new BaseServedObject(this, mHostContext.getInvocationHandler(), publishedServiceName, "Main", lr.getReferenceID());
          Object retVal = getInstance(publishedServiceName, "Main", bo);
          bo.registerImplObject(retVal);
          return retVal;
      }
  
      /**
       * Method getInstance
       *
       *
       * @param publishedServiceName
       * @param objectName
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      protected Object getInstance(String publishedServiceName, String objectName, BaseServedObject baseServedObject) throws AltrmiConnectionException {
          try {
              Class clazz = Class.forName("AltrmiGenerated" + publishedServiceName + "_" +objectName);
              Constructor[] constructors = clazz.getConstructors();
              Object retVal = constructors[0].newInstance(new Object[] { baseServedObject });
              return retVal;
          } catch (InvocationTargetException ite) {
              throw new AltrmiConnectionException("Generated class not instantiated : "
                                                + ite.getTargetException().getMessage());
          } catch (ClassNotFoundException cnfe) {
              throw new AltrmiConnectionException("Generated class not found during lookup : "
                                                + cnfe.getMessage());
          } catch (InstantiationException ie) {
              throw new AltrmiConnectionException("Generated class not instantiable during lookup : "
                                                + ie.getMessage());
          } catch (IllegalAccessException iae) {
              throw new AltrmiConnectionException("Illegal access to generated class during lookup : "
                                                + iae.getMessage());
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/DefaultAltrmiConnectionListener.java
  
  Index: DefaultAltrmiConnectionListener.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiInvocationException;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  import org.apache.commons.altrmi.client.AltrmiConnectionListener;
  
  
  /**
   * Interface AltrmiConnectionListener
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public class DefaultAltrmiConnectionListener implements AltrmiConnectionListener {
  
      /**
       * Method methodCalled
       *
       *
       * @return
       *
       */
      public void methodCalled(final String methodSignature, final long duration) {
          // do mothing in default impl, could do logging.
      }
  
      /**
       * Method methodLogging tests if the implementing class intends to do method logging.
       *
       *
       * @return
       *
       */
      public boolean methodLogging() {
          return false;
      }
  
      /**
       * Method serviceSuspended
       *
       *
       * @return
       *
       */
      public void serviceSuspended(final AltrmiRequest altrmiRequest, final int attempt, final int suggestedWaitMillis) {
          // Lets say that ten retries is too many.
          if (attempt == 10) {
              throw new AltrmiInvocationException("Too many retries on suspended service");
          }
          System.out.println("AltRMI service suspended, Trying to reconnect (attempt "+attempt+", waiting for "+suggestedWaitMillis/1000+" seconds)");
          // We are quite happy with the recommended wait time.
          try {
              Thread.sleep(suggestedWaitMillis);
          } catch (InterruptedException ie) {
              // TODO ?
          }
      }
  
      /**
       * Method serviceAbend
       *
       *
       * @return
       *
       */
      public void serviceAbend(int attempt) {
          // Lets say that ten retries is too many.
          if (attempt == 3) {
              throw new AltrmiInvocationException("Too many retries on abended service");
          }
          System.out.println("AltRMI service abnormally ended, Trying to reconnect (attempt "+attempt+")");
          // Increasing wait time.
          try {
              Thread.sleep((2^attempt) * 500);
          } catch (InterruptedException ie) {
              // TODO ?
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/ObjectStreamInvocationHandler.java
  
  Index: ObjectStreamInvocationHandler.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;
  
  
  
  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.MethodRequest;
  import org.apache.commons.altrmi.common.AltrmiInvocationException;
  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.NoSuchReferenceReply;
  import org.apache.commons.altrmi.common.NotSuchReferenceException;
  import org.apache.commons.altrmi.client.AltrmiConnectionListener;
  
  import java.io.IOException;
  import java.io.ObjectOutputStream;
  import java.io.ObjectInputStream;
  import java.net.SocketException;
  
  
  /**
   * Class ObjectStreamInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class ObjectStreamInvocationHandler extends AltrmiClientInvocationHandler {
  
      private ObjectInputStream mOIS;
      private ObjectOutputStream mOOS;
      private boolean mMethodLogging = false;
  
      /**
       * Method setAltrmiConnectionListener
       *
       *
       * @param altrmiConnectionListener
       *
       */
      public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener) {
          super.setAltrmiConnectionListener(altrmiConnectionListener);
          mMethodLogging = altrmiConnectionListener.methodLogging();
      }
  
      /**
       * Method setObjectInputStream
       *
       *
       * @param is
       *
       */
      public void setObjectInputStream(ObjectInputStream is) {
          mOIS = is;
      }
  
      /**
       * Method setObjectOutputStream
       *
       *
       * @param os
       *
       */
      public void setObjectOutputStream(ObjectOutputStream os) {
          mOOS = os;
      }
  
      protected void requestWritten() {}
  
      /**
       * Method handleInvocation
       *
       *
       * @param request
       *
       * @return
       *
       */
      public synchronized AltrmiReply handleInvocation(AltrmiRequest request) {
  
          try {
              while (true) {
                  boolean again = true;
                  AltrmiReply reply = null;
                  int tries = 0;
                  long start = 0;
                  if (mMethodLogging) {
                      start = System.currentTimeMillis();
                  }
                  while (again) {
                      tries++;
                      again = false;
                      try {
                          long t1 = System.currentTimeMillis();
                          mOOS.writeObject(request);
                          mOOS.flush();
                          reply = (AltrmiReply) mOIS.readObject();
                          long t2 = System.currentTimeMillis();
                          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());
                              }
                          }
                      } catch (IOException ioe) {
                          if (ioe instanceof SocketException) {
                              int retryConnectTries = 0;
                              while (!tryReconnect()) {
                                  mAltrmiConnectionListener.serviceAbend(retryConnectTries);
                                  retryConnectTries++;
                              }
                          } else {
                              throw new AltrmiInvocationException("IO Exception during invocation to server"
                                                + ioe.getMessage());
                          }
                      }
                  }
                  if (mMethodLogging) {
                      if (request instanceof MethodRequest) {
                          mAltrmiConnectionListener.methodCalled(((MethodRequest) request).getMethodSignature(), System.currentTimeMillis() - start);
                      }
                  }
                  return reply;
              }
          } catch (ClassNotFoundException e) {
              throw new AltrmiInvocationException("Class definition missing on Deserialization"
                                                + e.getMessage());
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/ServerClassAltrmiFactory.java
  
  Index: ServerClassAltrmiFactory.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;
  
  
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.client.AltrmiHostContext;
  import org.apache.commons.altrmi.common.ClassReply;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.common.ClassRequest;
  import org.apache.commons.altrmi.common.NotPublishedException;
  import org.apache.commons.altrmi.common.LookupReply;
  import org.apache.commons.altrmi.common.LookupRequest;
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.NotPublishedReply;
  import org.apache.commons.altrmi.common.RequestFailedReply;
  
  import java.util.HashMap;
  import java.lang.reflect.Constructor;
  import java.lang.reflect.InvocationTargetException;
  
  
  /**
   * Class ServerClassAltrmiFactory
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class ServerClassAltrmiFactory extends AbstractAltrmiFactory {
  
      private HashMap mPublishedServiceClassLoaders = new HashMap();
  
      /**
       * Method lookup
       *
       *
       * @param publishedServiceName
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      public Object lookup(String publishedServiceName)
              throws AltrmiConnectionException {
  
          AltrmiReply ar = mHostContext.getInvocationHandler().handleInvocation(new LookupRequest(publishedServiceName));
          if (ar.getReplyCode() >= AltrmiReply.PROBLEMREPLY) {
              if (ar instanceof NotPublishedReply) {
                  throw new AltrmiConnectionException("Service " + publishedServiceName + " not published");
              } else {
                  throw new AltrmiConnectionException("Problem doing lookup on service");
              }
          }
          LookupReply lr = (LookupReply) ar;
          BaseServedObject bo = new BaseServedObject(this, mHostContext.getInvocationHandler(), publishedServiceName, "Main", lr.getReferenceID());
          Object retVal =  getInstance(publishedServiceName, "Main", bo);
          bo.registerImplObject(retVal);
          return retVal;
      }
  
      /**
       * Method getInstance
       *
       *
       * @param publishedServiceName
       * @param objectName
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      protected Object getInstance(String publishedServiceName, String objectName, BaseServedObject baseServedObject) throws AltrmiConnectionException {
          try {
              TransportedClassLoader tcl = null;
  
              String className = "AltrmiGenerated" + publishedServiceName + "_" + objectName;
  
              if (mPublishedServiceClassLoaders.containsKey(className)) {
                  tcl = (TransportedClassLoader) mPublishedServiceClassLoaders.get(className);
              } else {
                  ClassReply cr = null;
                  try {
                      AltrmiReply ar = mHostContext.getInvocationHandler().handleInvocation(new ClassRequest(publishedServiceName, objectName));
                      if (ar.getReplyCode() >= AltrmiReply.PROBLEMREPLY) {
                          if (ar instanceof RequestFailedReply) {
                              throw new AltrmiConnectionException(((RequestFailedReply) ar).getFailureReason());
                          } //TODO others.
                      }
                      cr = (ClassReply) ar;
                  } catch (NotPublishedException npe) {
                      throw new AltrmiConnectionException("Service " + publishedServiceName + " not published on Server");
                  }
                  tcl = new TransportedClassLoader(className, cr.getClassBytes());
                  tcl.initialize();
                  mPublishedServiceClassLoaders.put(className, tcl);
              }
              Class clazz = tcl.loadClass(className);
              Constructor[] constructors = clazz.getConstructors();
              Object retVal = constructors[0].newInstance(new Object[] { baseServedObject });
              return retVal;
          } catch (InvocationTargetException ite) {
              throw new AltrmiConnectionException("Generated class not instantiated : "
                                                + ite.getTargetException().getMessage());
          } catch (ClassNotFoundException cnfe) {
              throw new AltrmiConnectionException("Generated class not found during lookup : "
                                                + cnfe.getMessage());
          } catch (InstantiationException ie) {
              throw new AltrmiConnectionException("Generated class not instantiable during lookup : "
                                                + ie.getMessage());
          } catch (IllegalAccessException iae) {
              throw new AltrmiConnectionException("Illegal access to generated class during lookup : "
                                                + iae.getMessage());
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/TransportedClassLoader.java
  
  Index: TransportedClassLoader.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;
  
  import java.util.HashMap;
  
  public final class TransportedClassLoader extends ClassLoader {
  
      private final transient byte[] mClassBytes;
      private final transient String mClassName;
  
      public TransportedClassLoader(String className, byte[] classBytes) {
          mClassBytes = classBytes;
          mClassName = className;
      }
  
      public void initialize() {
          this.defineClass(mClassName, mClassBytes, 0, mClassBytes.length);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectAltrmiHostContext.java
  
  Index: DirectAltrmiHostContext.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.AbstractAltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiConnectionListener;
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  
  /**
   * Class DirectAltrmiHostContext
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class DirectAltrmiHostContext extends AbstractAltrmiHostContext {
  
      /**
       * Constructor DirectAltrmiHostContext
       *
       *
       * @param altrmiInvocationHandler
       *
       * @throws AltrmiConnectionException
       *
       */
      public DirectAltrmiHostContext(AltrmiInvocationHandler altrmiInvocationHandler)
              throws AltrmiConnectionException {
          super(new DirectInvocationHandler(altrmiInvocationHandler));
      }
  
      //public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener) {
      //}
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/direct/DirectInvocationHandler.java
  
  Index: DirectInvocationHandler.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.AltrmiClientInvocationHandler;
  import org.apache.commons.altrmi.client.AltrmiConnectionListener;
  
  
  /**
   * Class DirectInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class DirectInvocationHandler extends AltrmiClientInvocationHandler {
  
      private AltrmiInvocationHandler mAltrmiInvocationHandler;
      private boolean mMethodLogging = false;
  
      /**
       * Constructor DirectInvocationHandler
       *
       *
       * @param altrmiInvocationHandler
       *
       * @throws AltrmiConnectionException
       *
       */
      public DirectInvocationHandler(AltrmiInvocationHandler altrmiInvocationHandler)
              throws AltrmiConnectionException {
          mAltrmiInvocationHandler = altrmiInvocationHandler;
      }
  
      /**
       * 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) {
          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.");
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/piped/PipedAltrmiHostContext.java
  
  Index: PipedAltrmiHostContext.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.piped;
  
  
  
  import org.apache.commons.altrmi.client.impl.AbstractAltrmiHostContext;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.server.impl.piped.PipedServer;
  
  
  /**
   * Class PipedAltrmiHostContext
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PipedAltrmiHostContext extends AbstractAltrmiHostContext {
  
      /**
       * Constructor PipedAltrmiHostContext
       *
       *
       * @param pipedServer
       *
       * @throws AltrmiConnectionException
       *
       */
      public PipedAltrmiHostContext(PipedServer pipedServer) throws AltrmiConnectionException {
          super(new PipedInvocationHandler(pipedServer));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/piped/PipedInvocationHandler.java
  
  Index: PipedInvocationHandler.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.piped;
  
  
  
  import org.apache.commons.altrmi.client.impl.ObjectStreamInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.common.AltrmiPipeConnector;
  import org.apache.commons.altrmi.common.AltrmiInvocationException;
  
  import java.io.PipedOutputStream;
  import java.io.PipedInputStream;
  import java.io.ObjectOutputStream;
  import java.io.ObjectInputStream;
  import java.io.IOException;
  
  
  /**
   * Class PipedInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class PipedInvocationHandler extends ObjectStreamInvocationHandler {
  
      /**
       * Constructor PipedInvocationHandler
       *
       *
       * @param apc
       *
       * @throws AltrmiConnectionException
       *
       */
      public PipedInvocationHandler(AltrmiPipeConnector apc) throws AltrmiConnectionException {
  
          try {
              PipedOutputStream pOS = new PipedOutputStream();
              PipedInputStream pIS = apc.connect(pOS);
              ObjectOutputStream oOS = new ObjectOutputStream(pOS);
              ObjectInputStream oIS = new ObjectInputStream(pIS);
  
              setObjectInputStream(oIS);
              setObjectOutputStream(oOS);
          } catch (IOException ioe) {
              throw new AltrmiConnectionException("Cannot bind the pipes together :"
                                                + ioe.getMessage());
          }
      }
  
      protected boolean tryReconnect() {
          // blimey how do we reconnect this?
          throw new AltrmiInvocationException("Piped connection broken, unable to reconnect.");
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/rmi/RmiAltrmiHostContext.java
  
  Index: RmiAltrmiHostContext.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.rmi;
  
  
  
  import org.apache.commons.altrmi.client.impl.AbstractAltrmiHostContext;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  
  /**
   * Class RmiAltrmiHostContext
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class RmiAltrmiHostContext extends AbstractAltrmiHostContext {
  
      /**
       * Constructor RmiAltrmiHostContext
       *
       *
       * @param host
       * @param port
       *
       * @throws AltrmiConnectionException
       *
       */
      public RmiAltrmiHostContext(String host, int port) throws AltrmiConnectionException {
          super(new RmiInvocationHandler(host, port));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/rmi/RmiInvocationHandler.java
  
  Index: RmiInvocationHandler.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.rmi;
  
  import org.apache.commons.altrmi.client.impl.AltrmiClientInvocationHandler;
  import org.apache.commons.altrmi.client.AltrmiConnectionListener;
  import org.apache.commons.altrmi.common.RmiAltrmiInvocationHandler;
  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 java.rmi.Naming;
  import java.rmi.NotBoundException;
  import java.rmi.RemoteException;
  import java.rmi.ConnectIOException;
  import java.rmi.ConnectException;
  import java.net.MalformedURLException;
  
  
  /**
   * Class RmiInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class RmiInvocationHandler extends AltrmiClientInvocationHandler {
  
      private RmiAltrmiInvocationHandler mRmiAltrmiInvocationHandler;
      private String mURL;
      private boolean mMethodLogging = false;
  
      /**
       * Constructor RmiInvocationHandler
       *
       *
       * @param host
       * @param port
       *
       * @throws AltrmiConnectionException
       *
       */
      public RmiInvocationHandler(String host, int port) throws AltrmiConnectionException {
  
          mURL = "rmi://" + host + ":" + port + "/"
                       + RmiAltrmiInvocationHandler.class.getName();
  
          try {
              mRmiAltrmiInvocationHandler = (RmiAltrmiInvocationHandler) Naming.lookup(mURL);
          } catch (NotBoundException nbe) {
              throw new AltrmiConnectionException(
                  "Cannot bind to the remote RMI service.  Either an IP or RMI issue.");
          } catch (MalformedURLException mfue) {
              throw new AltrmiConnectionException("Malformed URL, host/port (" + host + "/" + port
                                                + ") must be wrong: " + mfue.getMessage());
          } catch (RemoteException re) {
              throw new AltrmiConnectionException("Unknown Remote Exception : " + re.getMessage());
          }
      }
  
      /**
       * Method setAltrmiConnectionListener
       *
       *
       * @param altrmiConnectionListener
       *
       */
      public void setAltrmiConnectionListener(AltrmiConnectionListener altrmiConnectionListener) {
          super.setAltrmiConnectionListener(altrmiConnectionListener);
          mMethodLogging = altrmiConnectionListener.methodLogging();
      }
  
      /**
       * Method tryReconnect
       *
       * @return
       *
       */
      protected boolean tryReconnect() {
          try {
              mRmiAltrmiInvocationHandler = (RmiAltrmiInvocationHandler) Naming.lookup(mURL);
              return true;
          } catch (Exception e) {
              return false;
          }
      }
  
      /**
       * Method handleInvocation
       *
       *
       * @param request
       *
       * @return
       *
       */
      public synchronized AltrmiReply handleInvocation(AltrmiRequest request) {
  
          boolean again = true;
          AltrmiReply reply = null;
          int tries = 0;
          long start = 0;
          if (mMethodLogging) {
              start = System.currentTimeMillis();
          }
          while (again) {
              tries++;
              again = false;
              try {
  
                  reply = mRmiAltrmiInvocationHandler.handleInvocation(request);
                  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());
                      }
                  }
              } catch (RemoteException re) {
                  if (re instanceof ConnectException | re instanceof  ConnectIOException) {
                      int retryConnectTries = 0;
                      mRmiAltrmiInvocationHandler = null;
                      while (!tryReconnect()) {
                          mAltrmiConnectionListener.serviceAbend(retryConnectTries);
                          retryConnectTries++;
                      }
                  } else {
                      throw new AltrmiInvocationException("Unknown RMI problem : " + re.getMessage());
                  }
              }
          }
          if (mMethodLogging) {
              if (request instanceof MethodRequest) {
                  mAltrmiConnectionListener.methodCalled(((MethodRequest) request).getMethodSignature(), System.currentTimeMillis() - start);
              }
          }
          return reply;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/socket/PlainSocketAltrmiHostContext.java
  
  Index: PlainSocketAltrmiHostContext.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.socket;
  
  
  
  import org.apache.commons.altrmi.client.impl.AbstractAltrmiHostContext;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  import java.net.Socket;
  
  
  /**
   * Class PlainSocketAltrmiHostContext
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PlainSocketAltrmiHostContext extends AbstractAltrmiHostContext {
  
      /**
       * Constructor PlainSocketAltrmiHostContext
       *
       *
       * @param host
       * @param port
       *
       * @throws AltrmiConnectionException
       *
       */
      public PlainSocketAltrmiHostContext(String host, int port) throws AltrmiConnectionException {
          super(new PlainSocketInvocationHandler(host, port));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/socket/PlainSocketInvocationHandler.java
  
  Index: PlainSocketInvocationHandler.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.socket;
  
  import org.apache.commons.altrmi.client.impl.ObjectStreamInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  import java.net.Socket;
  import java.io.ObjectOutputStream;
  import java.io.ObjectInputStream;
  import java.io.IOException;
  
  
  /**
   * Class PlainSocketInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class PlainSocketInvocationHandler extends ObjectStreamInvocationHandler {
  
      private String mHost;
      private int mPort;
  
      /**
       * Constructor PlainSocketInvocationHandler
       *
       *
       * @param host
       * @param port
       *
       * @throws AltrmiConnectionException
       *
       */
      public PlainSocketInvocationHandler(String host, int port) throws AltrmiConnectionException {
          mHost = host;
          mPort = port;
          try {
              Socket socket = new Socket(host, port);
              ObjectOutputStream oOS = new ObjectOutputStream(socket.getOutputStream());
              ObjectInputStream oIS = new ObjectInputStream(socket.getInputStream());
              setObjectInputStream(oIS);
              setObjectOutputStream(oOS);
          } catch (IOException ioe) {
              throw new AltrmiConnectionException("Cannot open Stream(s) for socket");
          }
  
  
      }
  
      /**
       * Method tryReconnect
       *
       *
       * @return connected or not.
       */
      protected boolean tryReconnect() {
          try {
              Socket socket = new Socket(mHost, mPort);
              ObjectOutputStream oOS = new ObjectOutputStream(socket.getOutputStream());
              ObjectInputStream oIS = new ObjectInputStream(socket.getInputStream());
  
              setObjectInputStream(oIS);
              setObjectOutputStream(oOS);
              return true;
          } catch (IOException ioe) {
              return false;
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AbstractMethodHandler.java
  
  Index: AbstractMethodHandler.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;
  
  
  
  import java.lang.reflect.Method;
  
  import java.util.HashMap;
  
  
  /**
   * Class AbstractMethodHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AbstractMethodHandler {
  
      protected String getMethodSignature(Method method) {
  
          StringBuffer methodSignature = new StringBuffer();
  
          methodSignature.append(method.getName()).append("(");
  
          Class[] params = method.getParameterTypes();
  
          for (int i = 0; i < params.length; i++) {
              methodSignature.append(params[i].getName());
  
              if (i + 1 < params.length) {
                  methodSignature.append(", ");
              }
          }
  
          methodSignature.append(")");
  
          return methodSignature.toString().intern();
      }
  
      protected String encodeClassName(String className) {
          StringBuffer sb = new StringBuffer();
          for (int i = 0; i < className.length(); i++) {
            char ch = className.charAt(i);
            if (Character.isLetter(ch) | Character.isDigit(ch)) {
                sb.append(ch);
            }
          }
          return sb.toString();
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AltrmiConnectionException.java
  
  Index: AltrmiConnectionException.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;
  
  
  
  /**
   * Class AltrmiConnectionException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AltrmiConnectionException extends Exception {
  
      /**
       * Constructor AltrmiConnectionException
       *
       *
       * @param s
       *
       */
      public AltrmiConnectionException(String s) {
          super(s);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AltrmiInvocationException.java
  
  Index: AltrmiInvocationException.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;
  
  
  
  import java.io.Serializable;
  
  
  /**
   * Class AltrmiInvocationException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AltrmiInvocationException extends RuntimeException implements Serializable {
  
      /**
       * Constructor AltrmiInvocationException
       *
       *
       * @param s
       *
       */
      public AltrmiInvocationException(String s) {
          super(s);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AltrmiInvocationHandler.java
  
  Index: AltrmiInvocationHandler.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;
  
  
  
  import java.io.IOException;
  
  
  /**
   * Interface AltrmiInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface AltrmiInvocationHandler {
  
      /**
       * Method handleInvocation
       *
       *
       * @param request
       *
       * @return
       *
       */
      AltrmiReply handleInvocation(AltrmiRequest request);
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AltrmiPipeConnector.java
  
  Index: AltrmiPipeConnector.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;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiServerException;
  
  import java.io.PipedInputStream;
  import java.io.PipedOutputStream;
  
  
  /**
   * Interface AltrmiPipeConnector
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface AltrmiPipeConnector {
  
      /**
       * Method connect
       *
       *
       * @param clientPOS
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      PipedInputStream connect(PipedOutputStream clientPOS) throws AltrmiConnectionException;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AltrmiReply.java
  
  Index: AltrmiReply.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;
  
  
  
  import java.io.Serializable;
  
  
  /**
   * Class AltrmiReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AltrmiReply implements Serializable {
  
      // 'good' replies after 100
  
      public static final int CLASSREPLY = 1;
      public static final int METHODREPLY = 2;
      public static final int EXCEPTIONREPLY = 3;
      public static final int LOOKUPREPLY = 4;
      public static final int METHODFACADEREPLY = 5;
  
      // 'bad' replies after 100
  
      public static final int PROBLEMREPLY = 100;
      public static final int NOTPUBLISHEDREPLY = 102;
      public static final int REQUESTFAILEDREPLY = 103;
      public static final int SUSPENDEDREPLY = 104;
      public static final int ENDCONNECTIONREPLY = 105;
      public static final int NOSUCHREFERENCEREPLY = 106;
  
  
  
      /**
       * Constructor AltrmiReply
       *
       *
       */
      AltrmiReply() {}
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public abstract int getReplyCode();
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/AltrmiRequest.java
  
  Index: AltrmiRequest.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;
  
  
  
  import java.io.Serializable;
  
  
  /**
   * Class AltrmiRequest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class AltrmiRequest implements Serializable {
  
      public static final int CLASSREQUEST = 301;
      public static final int METHODREQUEST = 302;
      public static final int METHODFACADEREQUEST = 303;
      public static final int LOOKUPREQUEST = 304;
  
      /**
       * Constructor AltrmiRequest
       *
       *
       */
      AltrmiRequest() {}
  
      /**
       * Method getRequestCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public abstract int getRequestCode();
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/ClassReply.java
  
  Index: ClassReply.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;
  
  
  
  /**
   * Class ClassReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class ClassReply extends AltrmiReply {
  
      private final byte[] mClassBytes;
  
      /**
       * Constructor ClassReply
       *
       *
       * @param classBytes
       *
       */
      public ClassReply(byte[] classBytes) {
          this.mClassBytes = classBytes;
      }
  
      /**
       * Method getClassBytes
       *
       *
       * @return
       *
       */
      public byte[] getClassBytes() {
          return mClassBytes;
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return CLASSREPLY;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/ClassRequest.java
  
  Index: ClassRequest.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;
  
  
  /**
   * Class ClassRequest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class ClassRequest extends PublishedNameRequest {
  
      /**
       * Constructor ClassRequest
       *
       *
       * @param publishedServiceName
       * @param objectName*
       *
       */
      public ClassRequest(String publishedServiceName, String objectName) {
          super(publishedServiceName, objectName);
      }
  
      /**
       * Method getRequestCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getRequestCode() {
          return CLASSREQUEST;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/EndConnectionReply.java
  
  Index: EndConnectionReply.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;
  
  /**
   * Class EndConnectionReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class EndConnectionReply extends AltrmiReply {
  
  
      /**
       * Constructor EndConnectionReply
       *
       */
      public EndConnectionReply() {
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return ENDCONNECTIONREPLY;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/ExceptionReply.java
  
  Index: ExceptionReply.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;
  
  
  
  /**
   * Class ExceptionReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class ExceptionReply extends AltrmiReply {
  
      private final Throwable mReplyExcpt;
  
      /**
       * Constructor ExceptionReply
       *
       *
       * @param replyExcpt
       *
       */
      public ExceptionReply(Throwable replyExcpt) {
          this.mReplyExcpt = replyExcpt;
      }
  
      /**
       * Method getReplyException
       *
       *
       * @return
       *
       */
      public Throwable getReplyException() {
          return mReplyExcpt;
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return EXCEPTIONREPLY;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/FacadeRefHolder.java
  
  Index: FacadeRefHolder.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;
  
  import java.io.Serializable;
  
  
  /**
   * Class FacadeRefHolder
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class FacadeRefHolder implements Serializable {
  
      private String mReferenceID;
      private String mObjectName;
  
  
      /**
       * Constructor FacadeRefHolder
       *
       *
       * @param referenceID
       * @param objectName
       *
       */
      public FacadeRefHolder(String referenceID, String objectName) {
          mReferenceID = referenceID;
          mObjectName = objectName;
      }
  
      /**
       * Method getReferenceID
       *
       *
       */
      public String getReferenceID() {
          return mReferenceID;
      }
  
      /**
       * Method getObjectName
       *
       *
       */
      public String getObjectName() {
          return mObjectName;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/LookupReply.java
  
  Index: LookupReply.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;
  
  
  
  /**
   * Class LookupReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class LookupReply extends AltrmiReply {
  
      private final String mReferenceID;
  
      /**
       * Constructor LookupReply
       *
       *
       * @param referenceID
       *
       */
      public LookupReply(String referenceID) {
          this.mReferenceID = referenceID;
      }
  
  
      /**
       * Method getReferenceID.
       *
       *
       * @return
       *
       */
      public String getReferenceID() {
          return mReferenceID;
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return LOOKUPREPLY;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/LookupRequest.java
  
  Index: LookupRequest.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;
  
  
  
  /**
   * Class LookupRequest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class LookupRequest extends PublishedNameRequest {
  
      /**
       * Constructor LookupRequest
       *
       *
       * @param publishedServiceName
       *
       */
      public LookupRequest(String publishedServiceName) {
          super(publishedServiceName, "Main");
      }
  
      /**
       * Method getRequestCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getRequestCode() {
          return LOOKUPREQUEST;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/MethodFacadeReply.java
  
  Index: MethodFacadeReply.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;
  
  
  
  /**
   * Class MethodFacadeReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class MethodFacadeReply extends AltrmiReply {
  
      private final String mReferenceID;
  
      /**
       * Constructor MethodFacadeReply
       *
       *
       * @param referenceID
       *
       */
      public MethodFacadeReply(String referenceID) {
          this.mReferenceID = referenceID;
      }
  
      /**
       * Method getReference
       *
       *
       * @return
       *
       */
      public String getReferenceID() {
          return mReferenceID;
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return METHODFACADEREPLY;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/MethodFacadeRequest.java
  
  Index: MethodFacadeRequest.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;
  
  
  
  /**
   * Class MethodFacadeRequest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class MethodFacadeRequest extends MethodRequest {
  
      private String mReturnClassNameEncoded;
  
      /**
       * Constructor MethodFacadeRequest
       *
       *
       * @param publishedServiceName
       * @param objectName
       * @param methodSignature
       * @param args
       * @param referenceID
       * @param returnClassNameEncoded
       *
       */
      public MethodFacadeRequest(String publishedServiceName, String objectName, String methodSignature, Object[] args, String referenceID, String returnClassNameEncoded) {
          super(publishedServiceName, objectName, methodSignature, args, referenceID);
          mReturnClassNameEncoded = returnClassNameEncoded;
      }
  
      /**
       * Method getRequestCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getRequestCode() {
          return METHODFACADEREQUEST;
      }
  
      /**
       * Method getReturnClassNameEncoded.
       *
       *
       * @return
       *
       */
      public String getReturnClassNameEncoded() {
          return mReturnClassNameEncoded;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/MethodReply.java
  
  Index: MethodReply.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;
  
  
  
  /**
   * Class MethodReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class MethodReply extends AltrmiReply {
  
      private final Object mReplyObj;
  
      /**
       * Constructor MethodReply
       *
       *
       * @param replyObj
       *
       */
      public MethodReply(Object replyObj) {
          this.mReplyObj = replyObj;
      }
  
      /**
       * Method getReplyObject
       *
       *
       * @return
       *
       */
      public Object getReplyObject() {
          return mReplyObj;
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return METHODREPLY;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/MethodRequest.java
  
  Index: MethodRequest.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;
  
  
  
  /**
   * Class MethodRequest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class MethodRequest extends PublishedNameRequest {
  
      private final String mMethodSignature;
      private final Object[] mArgs;
      private final String mRferenceID;
  
      /**
       * Constructor MethodRequest
       *
       *
       * @param publishedServiceName
       * @param objectName
       * @param methodSignature
       * @param args
       * @param referenceID
       *
       */
      public MethodRequest(String publishedServiceName, String objectName, String methodSignature, Object[] args, String referenceID) {
          super(publishedServiceName, objectName);
          mMethodSignature = methodSignature;
          mArgs = args;
          mRferenceID = referenceID;
      }
  
      /**
       * Method getMethodSignature
       *
       *
       * @return
       *
       */
      public String getMethodSignature() {
          return mMethodSignature;
      }
  
      /**
       * Method getArgs
       *
       *
       * @return
       *
       */
      public Object[] getArgs() {
          return mArgs;
      }
  
      /**
       * Method getReferenceID
       *
       *
       * @return
       *
       */
      public String getReferenceID() {
          return mRferenceID;
      }
  
      /**
       * Method getRequestCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getRequestCode() {
          return METHODREQUEST;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/NoSuchReferenceReply.java
  
  Index: NoSuchReferenceReply.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;
  
  /**
   * Class NoSuchReferenceReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class NoSuchReferenceReply extends NotPublishedReply {
  
  
      /**
       * Constructor NoSuchReferenceReply
       *
       */
      public NoSuchReferenceReply() {
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return NOSUCHREFERENCEREPLY;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/NotPublishedException.java
  
  Index: NotPublishedException.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;
  
  
  
  import java.io.Serializable;
  
  
  /**
   * Class NotPublishedException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class NotPublishedException extends AltrmiInvocationException {
  
  
      /**
       * Constructor NotPublishedException
       *
       *
       * @param publishedServiceName
       * @param objectName
       *
       */
      public NotPublishedException(String publishedServiceName, String objectName) {
          super("Service '" + publishedServiceName + "' object '" + objectName +"' not published by server");
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/NotPublishedReply.java
  
  Index: NotPublishedReply.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;
  
  /**
   * Class NotPublishedReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class NotPublishedReply extends AltrmiReply {
  
  
      /**
       * Constructor NotPublishedReply
       *
       */
      public NotPublishedReply() {
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return NOTPUBLISHEDREPLY;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/NotSuchReferenceException.java
  
  Index: NotSuchReferenceException.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;
  
  
  
  import java.io.Serializable;
  
  
  /**
   * Class NotSuchReferenceException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class NotSuchReferenceException extends AltrmiInvocationException {
  
  
      /**
       * Constructor NotSuchReferenceException
       *
       *
       * @param publishedServiceName
       * @param objectName
       *
       */
      public NotSuchReferenceException() {
          super("The Instance on theserver mapped to a referenceID for transport does not exist.");
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/PublishedNameRequest.java
  
  Index: PublishedNameRequest.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;
  
  
  /**
   * Class PublishedNameRequest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class PublishedNameRequest extends AltrmiRequest {
  
      private final String mPublishedServiceName;
      private final String mObjectName;
  
      /**
       * Constructor PublishedNameRequest
       *
       *
       * @param publishedObjectName
       *
       */
      public PublishedNameRequest(String publishedServiceName, String objectName) {
          mPublishedServiceName = publishedServiceName;
          mObjectName = objectName;
      }
  
      /**
       * Method getPublishedServiceName
       *
       *
       * @return
       *
       */
      public String getPublishedServiceName() {
          return mPublishedServiceName;
      }
  
      /**
       * Method getObjectName
       *
       *
       * @return
       *
       */
      public String getObjectName() {
          return mObjectName;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/RequestFailedReply.java
  
  Index: RequestFailedReply.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;
  
  
  
  /**
   * Class RequestFailedReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class RequestFailedReply extends AltrmiReply {
  
      private final String mFailureReason;
  
      /**
       * Constructor RequestFailedReply
       *
       *
       * @param failureReason
       *
       */
      public RequestFailedReply(String failureReason) {
          this.mFailureReason = failureReason;
      }
  
      /**
       * Method getFailureReason
       *
       *
       * @return
       *
       */
      public String getFailureReason() {
          return mFailureReason;
      }
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return REQUESTFAILEDREPLY;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/RmiAltrmiInvocationHandler.java
  
  Index: RmiAltrmiInvocationHandler.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;
  
  
  
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  
  /**
   * Interface RmiAltrmiInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface RmiAltrmiInvocationHandler extends Remote {
  
      /**
       * Method handleInvocation
       *
       *
       * @param request
       *
       * @return
       *
       * @throws RemoteException
       *
       */
      AltrmiReply handleInvocation(AltrmiRequest request) throws RemoteException;
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/SuspendedReply.java
  
  Index: SuspendedReply.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;
  
  
  /**
   * Class SuspendedReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public final class SuspendedReply extends TryLaterReply {
  
      /**
       * Method getReplyCode.  This is quicker than instanceof for type checking.
       *
       *
       * @return
       *
       */
      public int getReplyCode() {
          return SUSPENDEDREPLY;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/common/TryLaterReply.java
  
  Index: TryLaterReply.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;
  
  
  
  /**
   * Class TryLaterReply
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class TryLaterReply extends AltrmiReply {
  
      private final int mSuggestedDelayMillis;
  
      /**
       * Constructor TryLaterReply
       *
       */
      public TryLaterReply() {
          mSuggestedDelayMillis = 5 * 1000; // ten seconds.
      }
  
  
      /**
       * Constructor TryLaterReply
       *
       *
       * @param delayMillis
       *
       */
      public TryLaterReply(int suggestedDelayMillis) {
          mSuggestedDelayMillis = suggestedDelayMillis;
      }
  
      /**
       * Method getDelayMillis
       *
       *
       * @return
       *
       */
      public int getSuggestedDelayMillis() {
          return mSuggestedDelayMillis;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/PrimarySourceGenerator.java
  
  Index: PrimarySourceGenerator.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.generator;
  
  
  
  import org.apache.commons.altrmi.common.AbstractMethodHandler;
  import org.apache.commons.altrmi.test.TestInterface;
  
  import java.lang.reflect.Method;
  
  import java.util.Vector;
  
  import java.io.PrintWriter;
  import java.io.FileOutputStream;
  import java.io.FileNotFoundException;
  import java.io.Serializable;
  
  
  /**
   * Class PrimarySourceGenerator
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PrimarySourceGenerator extends AbstractMethodHandler {
  
      private String[] mClassesOrInterfacesToExpose;
      private String[] mAdditionalFacades;
      private String mGenDir;
      private String mGenName;
      private PrintWriter mClassSource;
  
      /**
       * Method setClassOrInterfacesToExpose
       *
       *
       * @param classesOrInterfacesToExpose
       *
       */
      public void setClassOrInterfacesToExpose(String[] classesOrInterfacesToExpose) {
          mClassesOrInterfacesToExpose = classesOrInterfacesToExpose;
      }
  
      /**
       * Method setClassOrInterfacesToExpose
       *
       *
       * @param classesOrInterfacesToExpose
       *
       */
      public void setAdditionalfacades(String[] additionalFacades) {
          mAdditionalFacades = additionalFacades;
      }
  
      /**
       * Method setGenDir
       *
       *
       * @param genDir
       *
       */
      public void setGenDir(String genDir) {
          mGenDir = genDir;
      }
  
      /**
       * Method setGenName
       *
       *
       * @param genName
       *
       */
      public void setGenName(String genName) {
          this.mGenName = genName;
      }
  
      /**
       * Method generate
       *
       * @param withImplInterfaces to indicate whether the resulting
       * bean should be castable to the prescribed interfaces or not.
       *
       */
      public void generate(boolean beanOnly) throws SourceGenerationException {
  
          // The lookupable service class source.
          makeSource(beanOnly, "Main", mClassesOrInterfacesToExpose);
  
          for (int i = 0; i < mAdditionalFacades.length; i++) {
              String facade = mAdditionalFacades[i];
              makeSource(beanOnly, encodeClassName(facade), new String[] { facade } );
          }
  
      }
  
  
      public void makeSource(boolean beanOnly, String name, String[] classOrInterfacesToExpose) throws SourceGenerationException {
  
          // methdos could be in more than one interface.
          Vector methodsDone = new Vector();
  
          try {
              mClassSource = new PrintWriter(new FileOutputStream(mGenDir + "\\AltrmiGenerated"
                                                                  + mGenName + "_" + name + ".java"));
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
  
          mClassSource
              .print("public final class AltrmiGenerated" + mGenName + "_" + name);
          if (!beanOnly) {
              mClassSource.print(" implements ");
              generateInterfaceList(classOrInterfacesToExpose);
          }
          mClassSource.println(" { ");
  
          mClassSource.println("  private transient org.apache.commons.altrmi.client.impl.BaseServedObject mBaseServedObject;");
          mClassSource.println("  public AltrmiGenerated" + mGenName + "_" + name + " (org.apache.commons.altrmi.client.impl.BaseServedObject baseServedObject) {");
          mClassSource.println("      mBaseServedObject = baseServedObject;");
          mClassSource.println("  }");
          for (int x = 0; x < classOrInterfacesToExpose.length; x++) {
              Class clazz = null;
  
              try {
                  clazz = Class.forName(classOrInterfacesToExpose[x]);
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              }
  
              Method[] methods = clazz.getMethods();
  
              for (int y = 0; y < methods.length; y++) {
                  Method method = methods[y];
                  String methodSignature = getMethodSignature(method);
  
                  if (!methodsDone.contains(methodSignature)) {
                      methodsDone.add(methodSignature);
  
                      String rClass = method.getReturnType().getName();
                      if (!(method.getReturnType() instanceof Serializable)) {
                          throw new SourceGenerationException("Return type " + rClass + " must be serializable");
                      }
                      String mName = method.getName();
  
                      mClassSource.print("  public " + rClass + " " + mName + " (");
  
                      Class[] argTypes = method.getParameterTypes();
  
                      for (int i = 0; i < argTypes.length; i++) {
                          String cn = argTypes[i].getName();
                          if (!(argTypes[i] instanceof Serializable)) {
                              throw new SourceGenerationException("Argument type " + cn + " must be serializable");
                          }
                          generateParameter(cn, argTypes, i);
                      }
  
                      mClassSource.print(") ");
  
                      Class[] throwsTypes = method.getExceptionTypes();
  
                      for (int i = 0; i < throwsTypes.length; i++) {
                          generateThrows(i, throwsTypes);
                      }
  
                      mClassSource.println("{");
                      mClassSource.println("    Object[] args = new Object[" + argTypes.length
                                           + "];");
  
                      for (int i = 0; i < argTypes.length; i++) {
                          String cn = argTypes[i].getName();
  
                          generateAssignLine(cn, i);
                      }
  
                      mClassSource.println("    try {");
  
  
                      if (rClass.equals("void")) {
                          mClassSource.println("      mBaseServedObject.altrmiProcessVoidRequest(\""
                                               + methodSignature.toString() + "\",args);");
                      } else {
  
                          boolean isFacadeRetVal = isAdditionalFacade(method.getReturnType().getName());
  
                          if (isFacadeRetVal) {
                              mClassSource.println("      Object retVal = mBaseServedObject.altrmiProcessObjectRequestGettingFacade(\""
                                               + methodSignature.toString() + "\",args,\"" + encodeClassName(rClass)+ "\");");
                              mClassSource.println("      return (" + rClass + ") retVal;");
                          } else {
                              mClassSource.println("      Object retVal = mBaseServedObject.altrmiProcessObjectRequest(\""
                                               + methodSignature.toString() + "\",args);");
                              generateReturnLine(rClass);
                          }
                      }
  
                      mClassSource.println("    } catch (Throwable t) {");
  
                      throwsTypes = method.getExceptionTypes();
  
                      for (int i = 0; i < throwsTypes.length; i++) {
                          generateThrowHandler(i, throwsTypes);
                      }
  
                      mClassSource.println("      if (t instanceof RuntimeException) { ");
                      mClassSource.println("        throw (RuntimeException) t;");
                      mClassSource.println("      } else if (t instanceof Error) { ");
                      mClassSource.println("        throw (Error) t;");
                      mClassSource.println("      } else { ");
                      mClassSource.println(
                          "        throw new org.apache.commons.altrmi.common.AltrmiInvocationException(\"Should never get here\" + t.getMessage()); ");
                      mClassSource.println("      }");
                      mClassSource.println("    }");
                      mClassSource.println("  }");
                  }
              }
          }
  
          mClassSource.print("}");
          mClassSource.close();
      }
  
      private void generateThrowHandler(int i, Class[] throwsTypes) {
  
          if (i == 0) {
              mClassSource.println("      if (t instanceof " + throwsTypes[i].getName() + ") { ");
          } else {
              mClassSource.println("      } else if (t instanceof " + throwsTypes[i].getName()
                                   + ") { ");
          }
  
          mClassSource.println("        throw (" + throwsTypes[i].getName() + ") t;");
  
          if (i + 1 == throwsTypes.length) {
              mClassSource.print("      } else");
          }
      }
  
      private void generateThrows(int i, Class[] throwsTypes) {
  
          if (i == 0) {
              mClassSource.print("throws ");
          }
  
          mClassSource.print(throwsTypes[i].getName());
  
          if (i + 1 < throwsTypes.length) {
              mClassSource.print(", ");
          }
      }
  
      private void generateInterfaceList(String[] classOrInterfacesToExpose) {
  
          for (int x = 0; x < classOrInterfacesToExpose.length; x++) {
              mClassSource.print(classOrInterfacesToExpose[x]);
  
              if (x + 1 < classOrInterfacesToExpose.length) {
                  mClassSource.print(", ");
              }
          }
      }
  
      private void generateParameter(String cn, Class[] argTypes, int i) {
  
          if (cn.startsWith("L")) {
              mClassSource.print(argTypes[i].getName());
          } else if (cn.startsWith("[L")) {
              mClassSource.print(argTypes[i].getName() + "[]");
          } else if (cn.equals("[B")) {
              mClassSource.print("byte[]");
          } else if (cn.equals("[C")) {
              mClassSource.print("char[]");
          } else if (cn.equals("[D")) {
              mClassSource.print("double[]");
          } else if (cn.equals("[F")) {
              mClassSource.print("float[]");
          } else if (cn.equals("[I")) {
              mClassSource.print("int[]");
          } else if (cn.equals("[J")) {
              mClassSource.print("long[]");
          } else if (cn.equals("[S")) {
              mClassSource.print("short[]");
          } else if (cn.equals("[Z")) {
              mClassSource.print("boolean[]");
          } else {
              mClassSource.print(cn);
          }
  
          mClassSource.print(" v" + i);
  
          if (i + 1 < argTypes.length) {
              mClassSource.print(", ");
          }
      }
  
      private void generateAssignLine(String cn, int i) {
  
          if (cn.equals("int")) {
              mClassSource.println("    args[" + i + "] = new Integer(v" + i + ");");
          } else if (cn.equals("short")) {
              mClassSource.println("    args[" + i + "] = new Short(v" + i + ");");
          } else if (cn.equals("float")) {
              mClassSource.println("    args[" + i + "] = new Float(v" + i + ");");
          } else if (cn.equals("double")) {
              mClassSource.println("    args[" + i + "] = new Double(v" + i + ");");
          } else if (cn.equals("long")) {
              mClassSource.println("    args[" + i + "] = new Long(v" + i + ");");
          } else if (cn.equals("char")) {
              mClassSource.println("    args[" + i + "] = new Character(v" + i + ");");
          } else if (cn.equals("boolean")) {
              mClassSource.println("    args[" + i + "] = new Boolean(v" + i + ");");
          } else if (cn.equals("byte")) {
              mClassSource.println("    args[" + i + "] = new Byte(v" + i + ");");
          } else if (isAdditionalFacade(cn)) {
              mClassSource.println("    args[" + i + "] = mBaseServedObject.makeFacadeRefHolder(v" + i + ",\"" + super.encodeClassName(cn)+ "\");");
          } else {
              mClassSource.println("    args[" + i + "] = v" + i + ";");
          }
      }
  
      private void generateReturnLine(String rClass) {
  
          if (rClass.equals("boolean")) {
              mClassSource.println("      return ((Boolean) retVal).booleanValue();");
          } else if (rClass.equals("integer")) {
              mClassSource.println("      return ((Integer) retVal).intValue();");
          } else if (rClass.equals("short")) {
              mClassSource.println("      return ((Short) retVal).shortValue();");
          } else if (rClass.equals("float")) {
              mClassSource.println("      return ((Float) retVal).floatValue();");
          } else if (rClass.equals("double")) {
              mClassSource.println("      return ((Double) retVal).doubleValue();");
          } else if (rClass.equals("long")) {
              mClassSource.println("      return ((Long) retVal).longValue();");
          } else if (rClass.equals("char")) {
              mClassSource.println("      return ((Character) retVal).charValue();");
          } else if (rClass.equals("byte")) {
              mClassSource.println("      return ((Byte) retVal).byteValue();");
          } else {
              mClassSource.println("      return (" + rClass + ") retVal;");
          }
      }
  
      private boolean isAdditionalFacade(String className) {
          for (int p = 0; p < mAdditionalFacades.length; p++) {
              if (className.equals(mAdditionalFacades[p])) {
                  return true;
              }
          }
          return false;
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/SecondarySourceGenerator.java
  
  Index: SecondarySourceGenerator.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.generator;
  
  import org.apache.commons.altrmi.common.AbstractMethodHandler;
  
  import java.io.File;
  import java.io.PrintWriter;
  import java.io.IOException;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  
  
  /**
   * Class SecondarySourceGenerator
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class SecondarySourceGenerator extends AbstractMethodHandler {
  
      private File mSourceClassDir;
      private String mSourceClassFileStem;
      private String mGenDir;
      private PrintWriter mClassSource;
  
      /**
       * Method setSourceClassDir
       *
       *
       * @param sourceClassDir
       *
       */
      public void setSourceClassDir(File sourceClassDir) {
          mSourceClassDir = sourceClassDir;
      }
  
      /**
       * Method setSourceClassFileStem
       *
       *
       * @param sourceClassFileStem
       *
       */
      public void setSourceClassFileStem(String sourceClassFileStem) {
          mSourceClassFileStem = sourceClassFileStem;
      }
  
      /**
       * Method setGenDir
       *
       *
       * @param genDir
       *
       */
      public void setGenDir(String genDir) {
          mGenDir = genDir;
      }
  
      /**
       * Method generate
       *
       *
       */
      public void generate() {
          String[] files = mSourceClassDir.list();
          for (int i = 0; i < files.length; i++) {
              File file = new File(mSourceClassDir, files[i]);
              String filename = file.getName();
              if (filename.startsWith(mSourceClassFileStem)) {
                  if (filename.endsWith(".class")) {
                      String name = filename.substring(0,filename.length() - 6);
                      makeSource(name, file);
                  }
              }
          }
      }
  
      public void makeSource(String genName, File sourceFile) {
  
          byte[] clazzbytes = null;
  
          try {
              mClassSource = new PrintWriter(new FileOutputStream(mGenDir + File.separator
                                                                  + genName + ".java"));
  
              FileInputStream fis = new FileInputStream(sourceFile);
              int size = fis.available();
              clazzbytes = new byte[size];
              fis.read(clazzbytes);
              fis.close();
  
          } catch (IOException ioe) {
              ioe.printStackTrace();
          }
  
          mClassSource
              .println("public final class " + genName
                     + " extends org.apache.commons.altrmi.server.impl.BaseMobileClass { ");
          mClassSource.println("  public byte[] getClassBytes() { ");
          mClassSource.println("    return new byte[] { ");
          mClassSource.print("      ");
          for (int x = 0; x < clazzbytes.length; x++) {
              mClassSource.print("(byte) "+byteToHexString(clazzbytes[x]));
              if (x+1 < clazzbytes.length) {
                  mClassSource.print(",");
              }
              if (x % 5 == 1) {
                  mClassSource.print("\n      ");
              }
          }
          mClassSource.println("");
          mClassSource.println("    };");
          mClassSource.println("  }");
          mClassSource.print("}");
          mClassSource.close();
      }
  
      public String byteToHexString(byte b) {
          int i = (int) b;
          String st = Integer.toHexString( i < 0 ? i + 256 : i ).toUpperCase();
          if(st.length() == 1) {
              return "0x0" + st;
          } else {
             return "0x" + st;
          }
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/SourceGenerationException.java
  
  Index: SourceGenerationException.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.generator;
  
  public class SourceGenerationException extends Exception {
      public SourceGenerationException(String s) {
          super(s);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/ant/AltrmiClassInternTask.java
  
  Index: AltrmiClassInternTask.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.generator.ant;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.BuildException;
  import org.apache.commons.altrmi.generator.SecondarySourceGenerator;
  
  import java.io.File;
  import java.io.IOException;
  
  public class AltrmiClassInternTask extends Task {
  
      private String mGenDir;
      private String mSourceClassDir;
      private String mSourceClassFileStem;
  
      public AltrmiClassInternTask() {
      }
  
      public void setSourceclassdir(String sourceClassDir) {
          mSourceClassDir = sourceClassDir;
      }
  
      public void setSourceclassfilestem(String sourceClassFileStem) {
          mSourceClassFileStem = sourceClassFileStem;
      }
  
      public void setGendir(String genDir) {
          mGenDir = genDir;
      }
  
      public void execute() throws BuildException {
          if (mGenDir == null) {
              throw new BuildException("Specify the directory to generate Java source in");
          }
          if (mSourceClassDir == null) {
              throw new BuildException("Specify the directories of the class 'source' files");
          }
          if (mSourceClassFileStem == null) {
              throw new BuildException("Specify the stem name of class 'source' files");
          }
          SecondarySourceGenerator sg = new SecondarySourceGenerator();
          sg.setGenDir(mGenDir);
          sg.setSourceClassDir( new File(mSourceClassDir));
          sg.setSourceClassFileStem(mSourceClassFileStem);
          sg.generate();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/ant/AltrmiInterfaceTask.java
  
  Index: AltrmiInterfaceTask.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.generator.ant;
  
  import org.apache.tools.ant.Task;
  import org.apache.tools.ant.BuildException;
  import org.apache.tools.ant.util.FileUtils;
  import org.apache.commons.altrmi.generator.PrimarySourceGenerator;
  import org.apache.commons.altrmi.generator.SourceGenerationException;
  
  import java.util.StringTokenizer;
  import java.util.Vector;
  
  public class AltrmiInterfaceTask extends Task {
  
      private String[] mClassOrInterfacesToExpose;
      private String[] mAdditionalFacades;
      private String mGenDir;
      private String mGenName;
      private boolean mBeanOnly;
  
      public AltrmiInterfaceTask() {
      }
  
      public void setClassesorinterfaces(String classOrInterfacesToExpose) {
          StringTokenizer st = new StringTokenizer(classOrInterfacesToExpose, ",");
          Vector strings = new Vector();
          while (st.hasMoreTokens()) {
              strings.add(st.nextToken().trim());
          }
          mClassOrInterfacesToExpose = new String[strings.size()];
          strings.copyInto(mClassOrInterfacesToExpose);
      }
  
      public void setAdditionalfacades(String additionalfacades) {
          StringTokenizer st = new StringTokenizer(additionalfacades, ",");
          Vector strings = new Vector();
          while (st.hasMoreTokens()) {
              strings.add(st.nextToken().trim());
          }
          mAdditionalFacades = new String[strings.size()];
          strings.copyInto(mAdditionalFacades);
      }
  
      public void setGendir(String genDir) {
          mGenDir = genDir;
      }
  
      public void setBeanonly(String yesNo) {
          mBeanOnly = yesNo.equals("yes");
      }
  
      public void setGenname(String genName) {
          this.mGenName = genName;
      }
  
  
      public void execute() throws BuildException {
          if (mClassOrInterfacesToExpose == null) {
              throw new BuildException("Specify at least one interface to expose");
          }
          if (mGenDir == null) {
              throw new BuildException("Specify the directory to generate Java source in");
          }
          if (mGenName == null) {
              throw new BuildException("Specify the name to use for lookup");
          }
          PrimarySourceGenerator sg = new PrimarySourceGenerator();
          sg.setGenDir(mGenDir);
          sg.setGenName(mGenName);
          sg.setClassOrInterfacesToExpose(mClassOrInterfacesToExpose);
          sg.setAdditionalfacades(mAdditionalFacades);
          try {
              sg.generate(mBeanOnly);
          } catch (SourceGenerationException sge) {
              throw new BuildException(sge.getMessage());
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiClassRetrievalException.java
  
  Index: AltrmiClassRetrievalException.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;
  
  
  
  import java.io.Serializable;
  
  
  /**
   * Class AltrmiClassRetrievalException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AltrmiClassRetrievalException extends Exception {
  
  
      /**
       * Constructor AltrmiClassRetrievalException
       *
       *
       * @param s
       *
       */
      public AltrmiClassRetrievalException(String reason) {
          super(reason);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiPublicationException.java
  
  Index: AltrmiPublicationException.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;
  
  
  
  /**
   * Class AltrmiPublicationException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AltrmiPublicationException extends Exception {
  
      /**
       * Constructor AltrmiPublicationException
       *
       *
       * @param s
       *
       */
      public AltrmiPublicationException(String s) {
          super(s);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiPublisher.java
  
  Index: AltrmiPublisher.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  
  
  /**
   * Interface AltrmiServer
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface AltrmiPublisher {
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classOrInterfaceToExpose
       *
       */
      void publish(Object impl, String asName, Class classOrInterfaceToExpose) throws AltrmiPublicationException;
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classOrInterfaceToExpose
       * @param additionalFacade
       *
       */
      void publish(Object impl, String asName, Class classOrInterfaceToExpose, Class additionalFacade) throws AltrmiPublicationException;
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classOrInterfaceToExpose
       * @param additionalFacades
       *
       */
      void publish(Object impl, String asName, Class classOrInterfaceToExpose, Class[] additionalFacades) throws AltrmiPublicationException;
  
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classesOrInterfacesToExpose
       *
       */
      void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose) throws AltrmiPublicationException;
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classesOrInterfacesToExpose
       * @param additionalFacades
       *
       */
      void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose, Class[] additionalFacades) throws AltrmiPublicationException;
  
  
      /**
       * Method unPublish
       *
       *
       * @param impl
       * @param asName
       *
       */
      void unPublish(Object impl, String asName) throws AltrmiPublicationException;
  
      /**
       * Method replacePublished
       *
       *
       * @param oldImpl
       * @param asName
       * @param withImpl
       *
       */
      void replacePublished(Object oldImpl, String asName, Object withImpl) throws AltrmiPublicationException;
  
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiServer.java
  
  Index: AltrmiServer.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  
  
  /**
   * Interface AltrmiServer
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface AltrmiServer extends AltrmiPublisher {
  
      /**
       * Method setClassRetriever
       *
       *
       * @param classRetriever
       *
       * @return
       *
       */
      void setClassRetriever(ClassRetriever classRetriever);
  
      /**
       * Method processRequest
       *
       *
       * @param request
       *
       * @return
       *
       */
      AltrmiReply processRequest(AltrmiRequest request);
  
      /**
       * Method suspend
       *
       */
      void suspend();
  
      /**
       * Method resume
       *
       */
      void resume();
  
      /**
       * Method start
       *
       */
      void start() throws AltrmiServerException ;
  
      /**
       * Method stop
       *
       */
      void stop();
  
  
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiServerConnection.java
  
  Index: AltrmiServerConnection.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;
  
  public interface AltrmiServerConnection {
  
      void endConnection();
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiServerException.java
  
  Index: AltrmiServerException.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;
  
  
  
  /**
   * Class AltrmiServerException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class AltrmiServerException extends Exception {
  
      /**
       * Constructor AltrmiServerException
       *
       *
       * @param s
       *
       */
      public AltrmiServerException(String s) {
          super(s);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiServerInvocationHandler.java
  
  Index: AltrmiServerInvocationHandler.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;
  
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  
  /**
   * Class AltrmiServerInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public interface AltrmiServerInvocationHandler extends AltrmiInvocationHandler {
  
      /**
       * Method addImplementationBean
       *
       *
       * @param referenceID
       * @param beanImpl
       *
       */
     void addImplementationBean(String referenceID, Object beanImpl);
  
      /**
       * Method replaceImplementationBean
       *
       *
       * @param implBean
       * @param withImplBean
       *
       */
     void replaceImplementationBean(Object implBean, Object withImplBean);
  
      /**
       * Method getOrMakeReferenceIDForBean
       *
       *
       * @param implBean
       *
       */
     String getOrMakeReferenceIDForBean(Object implBean);
  
  
  }
  
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/ClassRetriever.java
  
  Index: ClassRetriever.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;
  
  
  public interface ClassRetriever {
  
      byte[] getBytes(String publishedName) throws AltrmiClassRetrievalException;
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/AbstractServer.java
  
  Index: AbstractServer.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;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiServer;
  import org.apache.commons.altrmi.server.AltrmiPublicationException;
  import org.apache.commons.altrmi.server.AltrmiServerConnection;
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.AbstractMethodHandler;
  import org.apache.commons.altrmi.common.MethodRequest;
  import org.apache.commons.altrmi.common.ExceptionReply;
  import org.apache.commons.altrmi.common.ClassRequest;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.common.ClassReply;
  import org.apache.commons.altrmi.common.RequestFailedReply;
  import org.apache.commons.altrmi.common.TryLaterReply;
  import org.apache.commons.altrmi.common.NotPublishedReply;
  import org.apache.commons.altrmi.common.SuspendedReply;
  import org.apache.commons.altrmi.common.LookupRequest;
  import org.apache.commons.altrmi.common.LookupReply;
  import org.apache.commons.altrmi.common.MethodFacadeRequest;
  import org.apache.commons.altrmi.common.MethodFacadeReply;
  import org.apache.commons.altrmi.common.MethodReply;
  import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
  import org.apache.commons.altrmi.server.ClassRetriever;
  import org.apache.commons.altrmi.server.AltrmiServerInvocationHandler;
  
  import java.lang.reflect.Method;
  
  import java.util.HashMap;
  import java.util.Vector;
  import java.util.Iterator;
  
  
  /**
   * Class AbstractServer
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  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();
  
      protected static final int SHUTTINGDOWN = 11;
      protected static final int STARTED = 22;
      protected static final int STOPPED = 33;
      protected static final int UNSTARTED = 44;
  
      protected int mState = UNSTARTED;
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classOrInterfaceToExpose
       *
       */
      public void publish(Object impl, String asName, Class classOrInterfaceToExpose) throws AltrmiPublicationException{
          publish(impl, asName, new Class[]{ classOrInterfaceToExpose }, new Class[0]);
      }
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classOrInterfaceToExpose
       * @param additionalFacade
       *
       */
      public void publish(Object impl, String asName, Class classOrInterfaceToExpose, Class additionalFacade) throws AltrmiPublicationException {
          publish(impl, asName, new Class[]{ classOrInterfaceToExpose }, new Class[] { additionalFacade });
      }
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classOrInterfaceToExpose
       * @param additionalFacades
       *
       */
      public void publish(Object impl, String asName, Class classOrInterfaceToExpose, Class[] additionalFacades) throws AltrmiPublicationException {
          publish(impl, asName, new Class[]{ classOrInterfaceToExpose }, additionalFacades );
      }
  
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classesOrInterfacesToExpose
       *
       */
      public void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose) throws AltrmiPublicationException{
          publish(impl, asName, classesOrInterfacesToExpose , new Class[0]);
      }
  
      /**
       * Method publish
       *
       *
       * @param impl
       * @param asName
       * @param classesOrInterfacesToExpose
       * @param additionalFacades
       *
       */
  
      public void publish(Object impl, String asName, Class[] classesOrInterfacesToExpose, Class[] additionalFacades) throws AltrmiPublicationException{
  
          if (mPublishedObjects.containsKey(asName + "_Main")) {
              throw new AltrmiPublicationException("Service '"+asName+"' already published");
          }
  
          String[] interfaceNames = new String[classesOrInterfacesToExpose.length];
  
          for (int i = 0; i < classesOrInterfacesToExpose.length; i++) {
              interfaceNames[i] = classesOrInterfacesToExpose[i].getName();
          }
  
          // add method maps for main lookup-able service.
  
          HashMap mainMethodMap = new HashMap();
          AltrmiServerInvocationHandler mainAsih = new DefaultInvocationHandler(this, asName + "_Main", mainMethodMap);
          mainAsih.addImplementationBean("<MAIN>", impl);
  
  
          for (int x = 0; x < classesOrInterfacesToExpose.length; x++) {
              Method methods[] = classesOrInterfacesToExpose[x].getMethods();
  
              for (int y = 0; y < methods.length; y++) {
                  Method method = methods[y];
                  String methodSignature = getMethodSignature(method);
  
                  if (!mainMethodMap.containsKey(methodSignature.toString())) {
                      mainMethodMap.put(methodSignature.toString(), methods[y]);
                  }
              }
          }
  
          // as the main service is lookup-able, it has a prexisting impl.
  
          mPublishedObjects.put(asName + "_Main", mainAsih);
  
          // add method maps for all the additional facades.
  
          for (int x = 0; x < additionalFacades.length; x++) {
              Method methods[] = additionalFacades[x].getMethods();
              String encodedClassName = encodeClassName(additionalFacades[x].getName());
  
              HashMap methodMap = new HashMap();
              AltrmiServerInvocationHandler asih = new DefaultInvocationHandler(this, asName + "_" + encodedClassName, methodMap);
  
              for (int y = 0; y < methods.length; y++) {
                  Method method = methods[y];
                  String methodSignature = getMethodSignature(method);
  
                  if (!methodMap.containsKey(methodSignature.toString())) {
                      methodMap.put(methodSignature.toString(), methods[y]);
                  }
              }
  
              mPublishedObjects.put(asName + "_" + encodedClassName, asih);
  
          }
  
  
      }
  
      /**
       * Method unPublish
       *
       *
       * @param impl
       * @param asName
       *
       */
      public void unPublish(Object impl, String asName) throws AltrmiPublicationException {
  
          if (!mPublishedObjects.containsKey(asName + "_Main")) {
              throw new AltrmiPublicationException("Service '"+asName+"' not published");
          }
          mPublishedObjects.remove(asName + "_Main");
      }
  
      /**
       * Method replacePublished
       *
       *
       * @param oldImpl
       * @param asName
       * @param withImpl
       *
       */
      public void replacePublished(Object oldImpl, String asName, Object withImpl) throws AltrmiPublicationException {
  
          if (!mPublishedObjects.containsKey(asName + "_Main")) {
              throw new AltrmiPublicationException("Service '"+asName+"' not published");
          }
  
          AltrmiServerInvocationHandler asih = (AltrmiServerInvocationHandler) mPublishedObjects.get(asName + "_Main");
  
          asih.replaceImplementationBean(oldImpl, withImpl);
  
      }
  
      /**
       * Method setClassRetriever
       *
       *
       * @param classRetriever
       *
       * @return
       *
       */
      public void setClassRetriever(ClassRetriever classRetriever) {
          mClassRetriever = classRetriever;
      }
  
  
      /**
       * Method processRequest
       *
       *
       * @param request
       *
       * @return
       *
       */
      public AltrmiReply processRequest(AltrmiRequest request) {
  
          if (mSuspend == true) {
              return new SuspendedReply();
          }
  
          if (request.getRequestCode() == AltrmiRequest.METHODREQUEST) {
              MethodRequest mr = (MethodRequest) request;
              String publishedThing = mr.getPublishedServiceName() + "_" + mr.getObjectName();
              if (!mPublishedObjects.containsKey(publishedThing)) {
                  System.out.flush();
                  return new NotPublishedReply();
              }
              AltrmiInvocationHandler ih = (AltrmiInvocationHandler) mPublishedObjects.get(publishedThing);
              return ih.handleInvocation(mr);
          } else if (request.getRequestCode() == AltrmiRequest.METHODFACADEREQUEST) {
              MethodFacadeRequest mr = (MethodFacadeRequest) request;
              String publishedThing = mr.getPublishedServiceName() + "_" + mr.getObjectName();
              if (!mPublishedObjects.containsKey(publishedThing)) {
                  System.out.flush();
                  return new NotPublishedReply();
              }
  
              AltrmiServerInvocationHandler asih = (AltrmiServerInvocationHandler) mPublishedObjects.get(publishedThing);
              AltrmiReply ar = asih.handleInvocation(mr);
              if (ar.getReplyCode() == AltrmiReply.EXCEPTIONREPLY ) {
                  return ar;
              } else if (ar.getReplyCode() >= AltrmiReply.PROBLEMREPLY ) {
                  return ar;
              } else if (ar.getReplyCode() != AltrmiReply.METHODREPLY ) {
                  return new RequestFailedReply("TODO");
              }
              Object beanImpl = ((MethodReply) ar).getReplyObject();
              AltrmiServerInvocationHandler asih2 = (AltrmiServerInvocationHandler) mPublishedObjects.get(mr.getPublishedServiceName() + "_" + mr.getReturnClassNameEncoded());
              if (asih2 == null) {
                  return new NotPublishedReply();
              }
              String newRef = asih2.getOrMakeReferenceIDForBean(beanImpl);
              String newRef2 = asih2.getOrMakeReferenceIDForBean(beanImpl);
              return new MethodFacadeReply(newRef);
          } else if (request.getRequestCode() == AltrmiRequest.LOOKUPREQUEST) {
              LookupRequest lr = (LookupRequest) request;
              //TODO
              return new LookupReply("<MAIN>");
          } else if (request.getRequestCode() == AltrmiRequest.CLASSREQUEST) {
              try {
                  ClassRequest cr = (ClassRequest) request;
                  String publishedThing = cr.getPublishedServiceName() + "_" + cr.getObjectName();
                  return new ClassReply(mClassRetriever.getBytes(publishedThing));
              } catch (AltrmiClassRetrievalException e) {
  
                  return new RequestFailedReply(e.getMessage());
              }
          } else {
              return new RequestFailedReply("Unknown request :" + request.getClass().getName());
          }
      }
  
      /**
       * Method suspend
       *
       */
      public void suspend() {
          mSuspend = true;
      }
  
      /**
       * Method resume
       *
       */
      public void resume() {
          mSuspend = false;
      }
  
      /**
       * Method connectionStart
       *
       */
      protected void connectionStart(AltrmiServerConnection altrmiConnection) {
          mConnections.add(altrmiConnection);
      }
  
      /**
       * Method connectionCompleted
       *
       */
      protected void connectionCompleted(AltrmiServerConnection altrmiConnection) {
          mConnections.remove(altrmiConnection);
      }
  
      protected void killAllConnections() {
          Iterator it = mConnections.iterator();
          while (it.hasNext()) {
              AltrmiServerConnection asc = (AltrmiServerConnection) it.next();
              asc.endConnection();
          }
      }
  
      public AltrmiServerInvocationHandler getServerInvocationHandler(MethodRequest mr, String objectName) {
          return (AltrmiServerInvocationHandler) mPublishedObjects.get(mr.getPublishedServiceName() + "_" + objectName);
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/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;
  
  public abstract class BaseMobileClass {
  
      public abstract byte[] getClassBytes();
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/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;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
  import org.apache.commons.altrmi.server.ClassRetriever;
  
  
  /**
   * Class BaseMobileClassRetriever
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class BaseMobileClassRetriever implements ClassRetriever {
  
      /**
       * Method getBytes
       *
       *
       * @param publishedName
       *
       * @return
       *
       * @throws AltrmiClassRetrievalException
       *
       */
      public byte[] getBytes(String publishedName) throws AltrmiClassRetrievalException {
  
          try {
              Class clazz = Class.forName("AltrmiGenerated" + publishedName);
              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/DefaultInvocationHandler.java
  
  Index: DefaultInvocationHandler.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.common.MethodReply;
  import org.apache.commons.altrmi.common.ExceptionReply;
  import org.apache.commons.altrmi.common.MethodRequest;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  import org.apache.commons.altrmi.common.AltrmiInvocationException;
  import org.apache.commons.altrmi.common.NoSuchReferenceReply;
  import org.apache.commons.altrmi.common.FacadeRefHolder;
  import org.apache.commons.altrmi.server.AltrmiServerInvocationHandler;
  
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Collection;
  
  import java.lang.reflect.Method;
  import java.lang.reflect.InvocationTargetException;
  
  import java.io.Serializable;
  
  
  /**
   * Class DefaultInvocationHandler
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class DefaultInvocationHandler implements AltrmiServerInvocationHandler {
  
      private HashMap mRefBeans = new HashMap();
      private HashMap mBeanRefs = new HashMap();
      private HashMap mMethodMap;
      private long mNextReference = 1;
      private AbstractServer mAbstractServer;
      private String mPublishedThing;
  
      /**
       * Constructor DefaultInvocationHandler
       *
       *
       * @param bean
       * @param methodMap
       *
       */
      protected DefaultInvocationHandler(AbstractServer abstractServer, String publishedThing, HashMap methodMap) {
          mAbstractServer = abstractServer;
          mPublishedThing = publishedThing;
          mMethodMap = methodMap;
      }
  
      public String toString() {
          return "DIH:" + mPublishedThing;
      }
  
  
      /**
       * Method addImplementationBean
       *
       *
       * @param referenceID
       * @param beanImpl
       *
       */
      public void addImplementationBean(String referenceID, Object beanImpl) {
          mRefBeans.put(referenceID, beanImpl);
          mBeanRefs.put(beanImpl, referenceID);
      }
  
      /**
       * Method replaceImplementationBean
       *
       *
       * @param implBean
       * @param withImplBean
       *
       */
      public void replaceImplementationBean(Object implBean, Object withImplBean) {
          Collection coll = mRefBeans.keySet();
          for (Iterator iterator = coll.iterator(); iterator.hasNext();) {
              String ref = (String) iterator.next();
              if (mRefBeans.get(ref).equals(implBean)) {
                  mRefBeans.put(ref, withImplBean);
                  mBeanRefs.remove(implBean);
                  mBeanRefs.put(withImplBean, ref);
              }
          }
      }
  
      /**
       * Method getOrMakeReferenceIDForBean
       *
       *
       * @param implBean
       *
       */
      public String getOrMakeReferenceIDForBean(Object implBean) {
          String ref = (String) mBeanRefs.get(implBean);
          if (ref == null) {
              ref = (mNextReference++ + "_" + Math.random()).intern(); // guarantees no spoofing.
              mBeanRefs.put(implBean, ref);
              mRefBeans.put(ref,implBean);
          }
          return ref;
      }
  
      /**
       * Method handleInvocation
       *
       *
       * @param request
       *
       * @return
       *
       */
      public AltrmiReply handleInvocation(AltrmiRequest request) {
          MethodRequest mr = (MethodRequest) request;
          String methodSignature = mr.getMethodSignature();
  
          if (!mMethodMap.containsKey(methodSignature)) {
              return new ExceptionReply(new AltrmiInvocationException("Method not present in impl"));
          }
  
          Method method = (Method) mMethodMap.get(methodSignature);
          Object rv = null;
  
          try {
  
              Object beanImpl = mRefBeans.get(mr.getReferenceID());
              if (beanImpl == null) {
                  return new NoSuchReferenceReply();
              }
              Object[] args = mr.getArgs();
              correctArgs(mr, args);
              return new MethodReply(method.invoke(beanImpl, mr.getArgs()));
          } catch (InvocationTargetException ite) {
              Throwable t = ite.getTargetException();
  
              if (t instanceof Serializable) {
                  return new ExceptionReply(t);
              } else {
                  return new ExceptionReply(
                      new AltrmiInvocationException(
                          "Exception was not serializable :" + t.getClass().getName()));
              }
          } catch (Throwable t) {
              t.printStackTrace();
              return new ExceptionReply(
                  new AltrmiInvocationException(
                      "Some ServerSide exception problem :" + t.getMessage()));
          }
      }
  
      private void correctArgs(MethodRequest mr, Object[] args) {
          for (int i = 0; i < args.length; i++) {
              // TODO find a faster way to do this....
              if(args[i] instanceof FacadeRefHolder) {
                  FacadeRefHolder frh = (FacadeRefHolder) args[i];
                  DefaultInvocationHandler asih = (DefaultInvocationHandler) mAbstractServer.getServerInvocationHandler(mr, frh.getObjectName());
                  args[i] = asih.mRefBeans.get(frh.getReferenceID());
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/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;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiClassRetrievalException;
  import org.apache.commons.altrmi.server.ClassRetriever;
  
  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 implements ClassRetriever {
  
      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 getBytes
       *
       *
       * @param publishedName
       *
       * @return
       *
       * @throws AltrmiClassRetrievalException
       *
       */
      public byte[] getBytes(String publishedName) throws AltrmiClassRetrievalException {
  
          try {
              URL rsc = mURLClassLoader.findResource(publishedName);
              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/ObjectStreamServerConnection.java
  
  Index: ObjectStreamServerConnection.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;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiRequest;
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.EndConnectionReply;
  import org.apache.commons.altrmi.server.AltrmiServerConnection;
  
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.IOException;
  import java.io.OutputStream;
  import java.io.InputStream;
  
  import java.net.Socket;
  import java.net.SocketException;
  
  
  /**
   * Class ObjectStreamServerConnection
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public abstract class ObjectStreamServerConnection implements Runnable, AltrmiServerConnection {
  
      private InputStream mInputStream;
      private OutputStream mOutputStream;
      private AbstractServer mAbstractServer;
      private boolean mEndConnection = false;
  
      /**
       * Constructor ObjectStreamServerConnection
       *
       *
       * @param abstractServer
       * @param inputStream
       * @param outputStream
       *
       */
      public ObjectStreamServerConnection(AbstractServer abstractServer, InputStream inputStream,
                                          OutputStream outputStream) {
  
          mAbstractServer = abstractServer;
          mInputStream = inputStream;
          mOutputStream = outputStream;
      }
  
      /**
       * Method run
       *
       *
       */
      public void run() {
  
          mAbstractServer.connectionStart(this);
  
          try {
              ObjectInputStream oIS = new ObjectInputStream(mInputStream);
              ObjectOutputStream oOS = new ObjectOutputStream(mOutputStream);
              boolean more = true;
  
              while (more) {
                  try {
                      AltrmiRequest request = (AltrmiRequest) oIS.readObject();
                      AltrmiReply reply = mAbstractServer.processRequest(request);
                      oOS.writeObject(reply);
                      oOS.flush();
  
                      if (mEndConnection) {
                          oOS.writeObject(new EndConnectionReply());
                          oOS.flush();
                          more = false;
                      }
  
                  } catch (IOException ioe) {
                      // pipe closed?
                      more = false;
                  }
              }
          } catch (IOException e) {
              e.printStackTrace();
          } catch (ClassNotFoundException e) {
              e.printStackTrace();
          }
  
          mAbstractServer.connectionCompleted(this);
      }
  
      /**
       * Method endConnection
       *
       *
       */
      public void endConnection() {
          mEndConnection = true;
      }
  
      /**
       * Method killConnection
       *
       *
       */
      protected abstract void killConnection();
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/direct/DirectAltrmiInovcationAdapter.java
  
  Index: DirectAltrmiInovcationAdapter.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.server.AltrmiServer;
  
  
  /**
   * Class DirectAltrmiInovcationAdapter
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class DirectAltrmiInovcationAdapter implements AltrmiInvocationHandler {
  
      private AltrmiServer mServer;
  
      /**
       * Constructor DirectAltrmiInovcationAdapter
       *
       *
       * @param server
       *
       */
      public DirectAltrmiInovcationAdapter(AltrmiServer server) {
          mServer = server;
      }
  
      /**
       * Method handleInvocation
       *
       *
       * @param request
       *
       * @return
       *
       */
      public AltrmiReply handleInvocation(AltrmiRequest request) {
          return mServer.processRequest(request);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/direct/DirectServer.java
  
  Index: DirectServer.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:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class DirectServer 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/server/impl/piped/PipedObjectStreamServerConnection.java
  
  Index: PipedObjectStreamServerConnection.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.piped;
  
  
  
  import org.apache.commons.altrmi.server.impl.ObjectStreamServerConnection;
  import org.apache.commons.altrmi.server.impl.AbstractServer;
  
  import java.net.Socket;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.IOException;
  import java.io.PipedInputStream;
  import java.io.PipedOutputStream;
  
  
  /**
   * Class PipedObjectStreamServerConnection
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PipedObjectStreamServerConnection extends ObjectStreamServerConnection {
  
      private PipedInputStream mPipedIn;
      private PipedOutputStream mPipedOut;
  
      /**
       * Constructor PipedObjectStreamServerConnection
       *
       *
       * @param abstractServer
       * @param socket
       *
       * @throws IOException
       *
       */
      public PipedObjectStreamServerConnection(AbstractServer abstractServer, PipedInputStream pipedIn, PipedOutputStream pipedOut)
              throws IOException {
  
          super(abstractServer, pipedIn, pipedOut);
  
          mPipedIn = pipedIn;
          mPipedOut = pipedOut;
      }
  
      protected void killConnection() {
          try {
              mPipedIn.close();
              mPipedOut.close();
          } catch (IOException e) {}
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/piped/PipedServer.java
  
  Index: PipedServer.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.piped;
  
  
  
  import org.apache.commons.altrmi.server.impl.AbstractServer;
  import org.apache.commons.altrmi.server.impl.ObjectStreamServerConnection;
  import org.apache.commons.altrmi.common.AltrmiPipeConnector;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  
  import java.io.PipedInputStream;
  import java.io.PipedOutputStream;
  import java.io.IOException;
  
  
  /**
   * Class PipedServer
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PipedServer extends AbstractServer implements AltrmiPipeConnector {
  
      /**
       * Method connect
       *
       *
       * @param clientPOS
       *
       * @return
       *
       * @throws AltrmiConnectionException
       *
       */
      public PipedInputStream connect(PipedOutputStream clientPOS) throws AltrmiConnectionException {
  
          if (mState == UNSTARTED) {
              throw new AltrmiConnectionException("Server not started yet");
          } else if (mState == SHUTTINGDOWN) {
              throw new AltrmiConnectionException("Server is Shutting down");
          }
  
          try {
              PipedInputStream pIS = new PipedInputStream();
  
              pIS.connect(clientPOS);
  
              PipedOutputStream pOS = new PipedOutputStream();
              PipedInputStream clientPIS = new PipedInputStream();
  
              clientPIS.connect(pOS);
  
              PipedObjectStreamServerConnection ossc = new PipedObjectStreamServerConnection(this, pIS, pOS);
              Thread thread = new Thread(ossc);
  
              thread.start();
  
              return clientPIS;
          } catch (IOException pe) {
              throw new AltrmiConnectionException("Some problem setting up server : "
                                                + pe.getMessage());
          }
      }
  
      /**
       * Method start
       *
       */
      public void start() {
          mState = STARTED;
      }
  
      /**
       * Method stop
       *
       */
      public void stop() {
          mState = SHUTTINGDOWN;
          killAllConnections();
          mState = STOPPED;
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/rmi/RmiAltrmiInovcationAdapter.java
  
  Index: RmiAltrmiInovcationAdapter.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.rmi;
  
  
  
  import org.apache.commons.altrmi.common.AltrmiReply;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.common.RmiAltrmiInvocationHandler;
  import org.apache.commons.altrmi.server.impl.AbstractServer;
  
  import java.rmi.RemoteException;
  
  
  /**
   * Class RmiAltrmiInovcationAdapter
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class RmiAltrmiInovcationAdapter implements RmiAltrmiInvocationHandler {
  
      private AbstractServer mAbstractServer;
  
      /**
       * Constructor RmiAltrmiInovcationAdapter
       *
       *
       * @param abstractServer
       *
       */
      public RmiAltrmiInovcationAdapter(AbstractServer abstractServer) {
          mAbstractServer = abstractServer;
      }
  
      /**
       * Method handleInvocation
       *
       *
       * @param request
       *
       * @return
       *
       * @throws RemoteException
       *
       */
      public AltrmiReply handleInvocation(AltrmiRequest request) throws RemoteException {
          return mAbstractServer.processRequest(request);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/rmi/RmiServer.java
  
  Index: RmiServer.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.rmi;
  
  
  
  import org.apache.commons.altrmi.server.impl.AbstractServer;
  import org.apache.commons.altrmi.server.AltrmiServerException;
  import org.apache.commons.altrmi.common.RmiAltrmiInvocationHandler;
  
  import java.rmi.server.UnicastRemoteObject;
  import java.rmi.registry.LocateRegistry;
  import java.rmi.registry.Registry;
  import java.rmi.RemoteException;
  import java.rmi.NotBoundException;
  
  
  /**
   * Class RmiServer
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class RmiServer extends AbstractServer {
  
      private RmiAltrmiInovcationAdapter mRmiAltrmiInovcationAdapter;
  
      private String mHost;
      private int mPort;
      private Registry mRegistry;
  
      /**
       * Constructor RmiServer
       *
       *
       * @param host
       * @param port
       *
       * @throws AltrmiServerException
       *
       */
      public RmiServer(String host, int port) throws AltrmiServerException {
  
          mHost = host;
          mPort = port;
  
      }
  
      /**
       * Method start
       *
       */
      public void start() throws AltrmiServerException {
          mState = STARTED;
          try {
              mRmiAltrmiInovcationAdapter = new RmiAltrmiInovcationAdapter(this);
  
              UnicastRemoteObject.exportObject(mRmiAltrmiInovcationAdapter);
  
              mRegistry = LocateRegistry.createRegistry(mPort);
  
              mRegistry.rebind(RmiAltrmiInvocationHandler.class.getName(), mRmiAltrmiInovcationAdapter);
          } catch (RemoteException re) {
              throw new AltrmiServerException("Some problem setting up server : " + re.getMessage());
          }
  
      }
  
      /**
       * Method stop
       *
       */
      public void stop() {
          mState = SHUTTINGDOWN;
          killAllConnections();
          try {
              mRegistry.unbind(RmiAltrmiInvocationHandler.class.getName());
          } catch (RemoteException re) {
          } catch (NotBoundException nbe) {
              //TODO ?
          }
          mState = STOPPED;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/socket/PlainSocketServer.java
  
  Index: PlainSocketServer.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.socket;
  
  
  
  import org.apache.commons.altrmi.server.AltrmiServer;
  import org.apache.commons.altrmi.server.AltrmiServerException;
  import org.apache.commons.altrmi.server.impl.AbstractServer;
  import org.apache.commons.altrmi.server.impl.ObjectStreamServerConnection;
  import org.apache.commons.altrmi.common.AltrmiRequest;
  import org.apache.commons.altrmi.common.AltrmiReply;
  
  import java.net.ServerSocket;
  import java.net.Socket;
  
  import java.io.IOException;
  
  
  /**
   * Class PlainSocketServer
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PlainSocketServer extends AbstractServer implements Runnable {
  
      private ServerSocket mServerSocket;
  
      private Thread mThread;
  
      /**
       * Constructor PlainSocketServer
       *
       *
       * @param port
       *
       * @throws AltrmiServerException
       *
       */
      public PlainSocketServer(int port) throws AltrmiServerException {
  
          try {
              mServerSocket = new ServerSocket(port);
          } catch (IOException ioe) {
              throw new AltrmiServerException("Some problem setting up server : " + ioe.getMessage());
          }
      }
  
      /**
       * Method run
       *
       *
       */
      public void run() {
  
          try {
              while (mState == STARTED) {
                  Socket sock = mServerSocket.accept();
                  SocketObjectStreamServerConnection ossc = new SocketObjectStreamServerConnection(this, sock,
                          sock.getInputStream(), sock.getOutputStream());
                  Thread thread = new Thread(ossc);
  
                  thread.start();
              }
          } catch (IOException ioe) {
              System.err.println("Some problem connecting client via sockets.");
          }
      }
  
      /**
       * Method start
       *
       */
      public void start() {
          mState = STARTED;
          getThread().start();
      }
  
      /**
       * Method stop
       *
       */
      public void stop() {
          mState = SHUTTINGDOWN;
          killAllConnections();
          getThread().interrupt();
          mState = STOPPED;
      }
  
      private Thread getThread() {
          if (mThread == null) {
              mThread = new Thread(this);
          }
          return mThread;
      }
  
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/socket/SocketObjectStreamServerConnection.java
  
  Index: SocketObjectStreamServerConnection.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.socket;
  
  
  
  import org.apache.commons.altrmi.server.impl.ObjectStreamServerConnection;
  import org.apache.commons.altrmi.server.impl.AbstractServer;
  
  import java.net.Socket;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.IOException;
  
  
  /**
   * Class SocketObjectStreamServerConnection
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class SocketObjectStreamServerConnection extends ObjectStreamServerConnection {
  
      private Socket mSocket;
  
      /**
       * Constructor SocketObjectStreamServerConnection
       *
       *
       * @param abstractServer
       * @param socket
       *
       * @throws IOException
       *
       */
      public SocketObjectStreamServerConnection(final AbstractServer abstractServer, final Socket socket, InputStream inStream, OutputStream outStream)
              throws IOException {
  
          super(abstractServer, inStream, outStream);
  
          mSocket = socket;
      }
  
      protected void killConnection() {
          try {
             mSocket.close();
          } catch (IOException e) {}
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/DirectTest.java
  
  Index: DirectTest.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.DirectAltrmiInovcationAdapter;
  import org.apache.commons.altrmi.common.AltrmiInvocationHandler;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.client.AltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.client.impl.direct.DirectAltrmiHostContext;
  import org.apache.commons.altrmi.client.impl.ServerClassAltrmiFactory;
  import org.apache.commons.altrmi.client.impl.ClientClassAltrmiFactory;
  
  
  /**
   * Class DirectTest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class DirectTest {
  
      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];
  
          DirectServer ds = new DirectServer();
          TestInterfaceImpl ti = new TestInterfaceImpl();
  
          ds.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
          ds.start();
  
          DirectTestClient dtc = new DirectTestClient(new DirectAltrmiInovcationAdapter(ds));
          Thread thread = new Thread(dtc);
  
          thread.start();
      }
  
      /**
       * Class DirectTestClient
       *
       *
       * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
       * @version $Revision: 1.1 $
       */
      static class DirectTestClient implements Runnable {
  
          private AltrmiInvocationHandler mInvocationHandler;
  
          /**
           * Constructor DirectTestClient
           *
           *
           * @param ih
           *
           */
          public DirectTestClient(AltrmiInvocationHandler ih) {
              mInvocationHandler = ih;
          }
  
          /**
           * Method run
           *
           *
           */
          public void run() {
  
              try {
                  AltrmiHostContext arhc = new DirectAltrmiHostContext(mInvocationHandler);
                  AltrmiFactory af = null;
  
                  if (mServerOrClientFactory.equals("S")) {
                      af = new ServerClassAltrmiFactory();
                  } else {
                      af = new ClientClassAltrmiFactory();
                  }
  
                  af.setHostContext(arhc);
  
                  TestInterface ti = (TestInterface) af.lookup("Hello");
                  TestClient tc = new TestClient(ti);
              } catch (AltrmiConnectionException ace) {
                  System.err.println("Some problem during connection to server : "
                                     + ace.getMessage());
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/PipeTest.java
  
  Index: PipeTest.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.piped.PipedServer;
  import org.apache.commons.altrmi.client.AltrmiHostContext;
  import org.apache.commons.altrmi.client.impl.socket.PlainSocketAltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.client.impl.piped.PipedAltrmiHostContext;
  import org.apache.commons.altrmi.client.impl.ServerClassAltrmiFactory;
  import org.apache.commons.altrmi.client.impl.ClientClassAltrmiFactory;
  
  import java.io.IOException;
  
  
  /**
   * Class PipeTest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class PipeTest {
  
      private static String mServerOrClientFactory;
  
      /**
       * Method main
       *
       *
       * @param args
       *
       * @throws Exception
       *
       */
      public static void main(String[] args) throws Exception {
  
          System.out.println("Piped Test");
  
          mServerOrClientFactory = args[0];
  
          PipedServer ps = new PipedServer();
          TestInterfaceImpl ti = new TestInterfaceImpl();
  
          ps.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
          ps.start();
  
          PipedTestClient ptc = new PipedTestClient(ps);
          Thread thread = new Thread(ptc);
  
          thread.start();
      }
  
      /**
       * Class PipedTestClient
       *
       *
       * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
       * @version $Revision: 1.1 $
       */
      static class PipedTestClient implements Runnable {
  
          private PipedServer mPipedServer;
  
          /**
           * Constructor PipedTestClient
           *
           *
           * @param pipedServer
           *
           */
          public PipedTestClient(PipedServer pipedServer) {
              mPipedServer = pipedServer;
          }
  
          /**
           * Method run
           *
           *
           */
          public void run() {
  
              try {
                  AltrmiHostContext arhc = new PipedAltrmiHostContext(mPipedServer);
                  AltrmiFactory af = null;
  
                  if (mServerOrClientFactory.equals("S")) {
                      af = new ServerClassAltrmiFactory();
                  } else {
                      af = new ClientClassAltrmiFactory();
                  }
  
                  af.setHostContext(arhc);
  
                  TestInterface ti = (TestInterface) af.lookup("Hello");
                  TestClient tc = new TestClient(ti);
              } catch (AltrmiConnectionException ace) {
                  System.err.println("Some problem during connection to server : "
                                     + ace.getMessage());
              }
          }
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/RmiClientTest.java
  
  Index: RmiClientTest.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.client.AltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.client.impl.rmi.RmiAltrmiHostContext;
  import org.apache.commons.altrmi.client.impl.ServerClassAltrmiFactory;
  import org.apache.commons.altrmi.client.impl.ClientClassAltrmiFactory;
  
  
  /**
   * Class RmiClientTest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class RmiClientTest {
  
      /**
       * Method main
       *
       *
       * @param args
       *
       * @throws Exception
       *
       */
      public static void main(String[] args) throws Exception {
  
          System.out.println("AltRMI over RMI Client");
  
          AltrmiHostContext arhc = new RmiAltrmiHostContext("127.0.0.1", 4321);
          AltrmiFactory af = null;
  
          if (args[0].equals("S")) {
              af = new ServerClassAltrmiFactory();
          } else {
              af = new ClientClassAltrmiFactory();
          }
  
          af.setHostContext(arhc);
  
          TestInterface ti = (TestInterface) af.lookup("Hello");
  
          new TestClient(ti);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/RmiServerTest.java
  
  Index: RmiServerTest.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.rmi.RmiServer;
  
  import java.io.IOException;
  
  
  /**
   * Class RmiServerTest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class RmiServerTest {
  
      /**
       * Method main
       *
       *
       * @param args
       *
       * @throws Exception
       *
       */
      public static void main(String[] args) throws Exception {
  
          System.out.println("AltRMI over RMI Server");
  
          RmiServer rs = new RmiServer("127.0.0.1", 4321);
          TestInterfaceImpl ti = new TestInterfaceImpl();
  
          rs.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
          rs.start();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/SocketClientTest.java
  
  Index: SocketClientTest.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.client.AltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiFactory;
  import org.apache.commons.altrmi.common.AltrmiConnectionException;
  import org.apache.commons.altrmi.client.impl.socket.PlainSocketAltrmiHostContext;
  import org.apache.commons.altrmi.client.impl.ServerClassAltrmiFactory;
  import org.apache.commons.altrmi.client.impl.ClientClassAltrmiFactory;
  
  import java.io.IOException;
  
  
  /**
   * Class SocketClientTest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class SocketClientTest {
  
      /**
       * Method main
       *
       *
       * @param args
       *
       * @throws Exception
       *
       */
      public static void main(String[] args) throws Exception {
  
          System.out.println("Stream over Socket Client");
  
          AltrmiHostContext arhc = new PlainSocketAltrmiHostContext("127.0.0.1", 1234);
          AltrmiFactory af = null;
  
          if (args[0].equals("S")) {
              af = new ServerClassAltrmiFactory();
          } else {
              af = new ClientClassAltrmiFactory();
          }
  
          af.setHostContext(arhc);
  
          TestInterface ti = (TestInterface) af.lookup("Hello");
  
          new TestClient(ti);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/SocketServerTest.java
  
  Index: SocketServerTest.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.socket.PlainSocketServer;
  
  import java.io.IOException;
  
  
  /**
   * Class SocketServerTest
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class SocketServerTest {
  
      /**
       * Method main
       *
       *
       * @param args
       *
       * @throws Exception
       *
       */
      public static void main(String[] args) throws Exception {
  
          System.out.println("Stream over Socket Server");
  
          PlainSocketServer pss = new PlainSocketServer(1234);
          TestInterfaceImpl ti = new TestInterfaceImpl();
  
          pss.publish(ti, "Hello", TestInterface.class, TestInterface2.class);
          pss.start();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestClient.java
  
  Index: TestClient.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.client.AltrmiHostContext;
  import org.apache.commons.altrmi.client.impl.socket.PlainSocketAltrmiHostContext;
  import org.apache.commons.altrmi.client.AltrmiFactory;
  
  import java.io.IOException;
  
  import java.beans.PropertyVetoException;
  
  
  /**
   * Class TestClient
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class TestClient {
  
      /**
       * Constructor TestClient
       *
       *
       * @param ti
       *
       */
      public TestClient(TestInterface ti) {
  
          // it is your choice whether you catch AltrmiInvocationException or not.
          // If you do, you could have several strategies:
          // 1) around each ti. invocation.
          // 2) around the whole contents of the constructor
          // 3) in the methods that instantiate TestClient
          ti.hello("howdie partner");
          ti.hello2(1234);
          ti.hello2(1235);
          ti.hello2(1236);
  
          try {
              ti.hello3((short) 222);
          } catch (PropertyVetoException e) {
              System.out.println("CLT: Client PropertyVetoException Caught " + e.getMessage());
          } catch (IOException e) {
              System.out.println("CLT: Client IOException Caught " + e.getMessage());
          }
  
          System.out.println("CLT: " + ti.hello4((float) 1.3, 2.1));
          System.out.println("CLT: Other Facade tests");
  
          TestInterface2 ti2One = ti.makeTestInterface2("One");
          TestInterface2 ti2Two = ti.makeTestInterface2("Two");
  
          System.out.println("CLT: One name = '" + ti2One.getName() + "'");
          System.out.println("CLT: Two name = '" + ti2Two.getName() + "'");
          System.out.println("CLT: Changing name for One to '111'");
          ti2One.setName("111");
          System.out.println("CLT: One name = '" + ti2One.getName() + "'");
          System.out.println("CLT: Two name = '" + ti2Two.getName() + "'");
          System.out.println("CLT: Morphing Two's name via TestInterface");
          ti.morphName(ti2Two);
          System.out.println("CLT: One name = '" + ti2One.getName() + "'");
          System.out.println("CLT: Two name = '" + ti2Two.getName() + "'");
          System.out
              .println("CLT: using findByName method to find the 'One' ... actually '111' now");
  
          TestInterface2 ti2OneB = ti.findTestInterface2ByName("111");
  
          System.out.println("CLT: One name = '" + ti2One.getName() + "'");
          System.out.println("CLT: Two name = '" + ti2Two.getName() + "'");
          System.out.println("CLT: One (by finder) name = '" + ti2OneB.getName() + "'");
          System.out.println("CLT: new object == (instance equality) to '111' obj ? -> "
                             + (ti2One == ti2OneB));
          System.out.println("CLT: Two timings about to start, please stand by...");
          ti.testSpeed();    // to ignore for timing
  
          long start = System.currentTimeMillis();
  
          for (int i = 0; i < 100000; i++) {
              ti.testSpeed();
          }
  
          long end = System.currentTimeMillis();
  
          System.out.println("CLT: Total time take for 100,000 simple calls (millis) = "
                             + (end - start));
  
          String rv = ti.testSpeed2("toIgnoreForTiming");
  
          start = System.currentTimeMillis();
  
          for (int i = 0; i < 100000; i++) {
              rv = ti.testSpeed2("qwerty");
          }
  
          end = System.currentTimeMillis();
  
          System.out.println("CLT: Total time take for 100,000 retval/param calls (millis) = "
                             + (end - start));
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterface.java
  
  Index: TestInterface.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 java.beans.PropertyVetoException;
  
  import java.io.IOException;
  
  
  /**
   * Interface TestInterface
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface TestInterface {
  
      /**
       * Method hello
       *
       *
       * @param greeting
       *
       */
      void hello(String greeting);
  
      /**
       * Method hello2
       *
       *
       * @param greeting
       *
       */
      void hello2(int greeting);
  
      /**
       * Method hello3
       *
       *
       * @param greeting
       *
       * @return
       *
       * @throws IOException
       * @throws PropertyVetoException
       *
       */
      boolean hello3(short greeting) throws PropertyVetoException, IOException;
  
      /**
       * Method hello4
       *
       *
       * @param greeting1
       * @param greeting2
       *
       * @return
       *
       */
      StringBuffer hello4(float greeting1, double greeting2);
  
      /**
       * Method testSpeed
       *
       *
       */
      void testSpeed();
  
      /**
       * Method testSpeed2
       *
       *
       * @param string
       *
       * @return
       *
       */
      String testSpeed2(String string);
  
      /**
       * Method makeTestInterface2
       *
       *
       * @param thingName
       *
       * @return
       *
       */
      TestInterface2 makeTestInterface2(String thingName);
  
      /**
       * Method morphName
       *
       *
       * @param forThisImpl
       *
       */
      void morphName(TestInterface2 forThisImpl);
  
      /**
       * Method findTestInterface2ByName
       *
       *
       * @param nameToFind
       *
       * @return
       *
       */
      TestInterface2 findTestInterface2ByName(String nameToFind);
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterface2.java
  
  Index: TestInterface2.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 java.beans.PropertyVetoException;
  
  import java.io.IOException;
  
  
  /**
   * Interface TestInterface
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public interface TestInterface2 {
  
      /**
       * Method setName
       *
       *
       * @param newThingName
       *
       */
      void setName(String newThingName);
  
      /**
       * Method getName
       *
       *
       *
       * @return
       *
       */
      String getName();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterface2Impl.java
  
  Index: TestInterface2Impl.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;
  
  
  
  /**
   * Class TestInterface2Impl
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version * $Revision: 1.1 $
   */
  public class TestInterface2Impl implements TestInterface2 {
  
      private String mName;
  
      /**
       * Constructor TestInterface2Impl
       *
       *
       * @param name
       *
       */
      public TestInterface2Impl(String name) {
  
          System.out.println("SVR: Object " + this + " created with name: '" + name + "'");
  
          mName = name;
      }
  
      /**
       * Method setName
       *
       *
       * @param newThingName
       *
       */
      public void setName(String newThingName) {
  
          mName = newThingName;
  
          System.out.println("SVR: Object " + this + " name changed to: '" + newThingName + "'");
      }
  
      /**
       * Method getName
       *
       *
       *
       * @return
       *
       */
      public String getName() {
          return mName;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/test/TestInterfaceImpl.java
  
  Index: TestInterfaceImpl.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 java.beans.PropertyVetoException;
  
  import java.io.IOException;
  
  import java.util.Vector;
  
  
  /**
   * Class TestInterfaceImpl
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class TestInterfaceImpl implements TestInterface {
  
      Vector ti2Holder = new Vector();
  
      /**
       * Method hello
       *
       *
       * @param greeting
       *
       */
      public void hello(String greeting) {
          System.out.println("SVR: Greeting (string) : " + greeting);
      }
  
      /**
       * Method hello2
       *
       *
       * @param greeting
       *
       */
      public void hello2(int greeting) {
          System.out.println("SVR: Greeting2 (int)   : " + greeting);
      }
  
      /**
       * Method hello3
       *
       *
       * @param greeting
       *
       * @return
       *
       * @throws IOException
       * @throws PropertyVetoException
       *
       */
      public boolean hello3(short greeting) throws PropertyVetoException, IOException {
  
          String str = new Double(Math.random()).toString();
  
          if (str.startsWith("0.1") | str.startsWith("0.2") | str.startsWith("0.3")
                  | str.startsWith("0.4")) {
              throw new IOException("Whoa - forced test of exception passing.");
          }
  
          System.out.println("SVR: Greeting3 (short)   : " + greeting);
  
          return true;
      }
  
      /**
       * Method hello4
       *
       *
       * @param greeting1
       * @param greeting2
       *
       * @return
       *
       */
      public StringBuffer hello4(float greeting1, double greeting2) {
  
          StringBuffer sb = new StringBuffer("Greeting4 (float, double)   : ");
  
          sb.append(greeting1).append(" ").append(greeting2);
          System.out.println("SVR: " + sb.toString());
  
          return sb;
      }
  
      /**
       * Method testSpeed
       *
       *
       */
      public void testSpeed() {}
  
      /**
       * Method testSpeed2
       *
       *
       * @param string
       *
       * @return
       *
       */
      public String testSpeed2(String string) {
          return "abc123";
      }
  
      /**
       * Method makeTestInterface2
       *
       *
       * @param thingName
       *
       * @return
       *
       */
      public TestInterface2 makeTestInterface2(String thingName) {
  
          TestInterface2 ti2 = new TestInterface2Impl(thingName);
  
          ti2Holder.add(ti2);
  
          return ti2;
      }
  
      /**
       * Method morphName
       *
       *
       * @param forThisImpl
       *
       */
      public void morphName(TestInterface2 forThisImpl) {
  
          String name = forThisImpl.getName();
          StringBuffer sb = new StringBuffer();
  
          for (int i = 0; i < name.length(); i++) {
              sb.append(name.substring(i, i + 1).toUpperCase());
              sb.append("_");
          }
  
          forThisImpl.setName(sb.toString());
      }
  
      /**
       * Method findTestInterface2ByName
       *
       *
       * @param nameToFind
       *
       * @return
       *
       */
      public TestInterface2 findTestInterface2ByName(String nameToFind) {
  
          for (int i = 0; i < ti2Holder.size(); i++) {
              TestInterface2 ti2 = (TestInterface2) ti2Holder.elementAt(i);
  
              if (ti2.getName().equals(nameToFind)) {
                  return ti2;
              }
          }
  
          return new TestInterface2Impl("Not Found");
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>