commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl AbstractServer.java DefaultInvocationHandler.java
Date Wed, 02 Jan 2002 12:11:56 GMT
hammant     02/01/02 04:11:56

  Modified:    armi     PROPOSAL
               armi/src/java/org/apache/commons/armi/server ArmiServer.java
               armi/src/java/org/apache/commons/armi/server/impl
                        AbstractServer.java DefaultInvocationHandler.java
  Added:       armi/src/java/org/apache/commons/armi/server
                        ArmiPublicationException.java
  Log:
  unpublish() and republish() completed.
  
  Revision  Changes    Path
  1.8       +7 -7      jakarta-commons-sandbox/armi/PROPOSAL
  
  Index: PROPOSAL
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/armi/PROPOSAL,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PROPOSAL	1 Jan 2002 23:47:47 -0000	1.7
  +++ PROPOSAL	2 Jan 2002 12:11:55 -0000	1.8
  @@ -65,6 +65,12 @@
       terminated connections will by default try to be reconnected, the 
       listener can decide if, how many, and how often the retries occur.
   
  +9) 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.
  +
   Limitations:
   
   1) Pass by value only.
  @@ -92,13 +98,7 @@
   
   3) Startable API for Server
   
  -  - The server needs to implement and act upon start() and stop() APIs.
  -  
  -4) unpublish() methods in Server.
  -  
  -  - The server needs to be able to unpublish a service.  There is a 
  -    possibility that in conjuction with suspend()/resume() a service
  -    could be republished, upgraded etc whilst in use.
  +  - The server needs to implement and act upon start() and stop() APIs.  
   
   Initial commiters:
   
  
  
  
  1.3       +30 -8     jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java
  
  Index: ArmiServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ArmiServer.java	31 Dec 2001 12:48:42 -0000	1.2
  +++ ArmiServer.java	2 Jan 2002 12:11:56 -0000	1.3
  @@ -1,8 +1,8 @@
   
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java,v
1.2 2001/12/31 12:48:42 hammant Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/12/31 12:48:42 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiServer.java,v
1.3 2002/01/02 12:11:56 hammant Exp $
  + * $Revision: 1.3 $
  + * $Date: 2002/01/02 12:11:56 $
    *
    * ====================================================================
    *
  @@ -72,7 +72,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.2 $
  + * @version * $Revision: 1.3 $
    */
   public interface ArmiServer {
   
  @@ -81,22 +81,44 @@
        *
        *
        * @param impl
  -     * @param as
  +     * @param asName
        * @param interfaceToExpose
        *
        */
  -    void publish(Object impl, String as, Class interfaceToExpose);
  +    void publish(Object impl, String asName, Class interfaceToExpose) throws ArmiPublicationException;
   
       /**
        * Method publish
        *
        *
        * @param impl
  -     * @param as
  +     * @param asName
        * @param interfacesToExpose
        *
        */
  -    void publish(Object impl, String as, Class[] interfacesToExpose);
  +    void publish(Object impl, String asName, Class[] interfacesToExpose) throws ArmiPublicationException;
  +
  +    /**
  +     * Method unPublish
  +     *
  +     *
  +     * @param impl
  +     * @param asName
  +     *
  +     */
  +    void unPublish(Object impl, String asName) throws ArmiPublicationException;
  +
  +    /**
  +     * Method replacePublished
  +     *
  +     *
  +     * @param oldImpl
  +     * @param asName
  +     * @param withImpl
  +     *
  +     */
  +    void replacePublished(Object oldImpl, String asName, Object withImpl) throws ArmiPublicationException;
  +
   
       /**
        * Method processRequest
  
  
  
  1.1                  jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiPublicationException.java
  
  Index: ArmiPublicationException.java
  ===================================================================
  
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/ArmiPublicationException.java,v
1.1 2002/01/02 12:11:56 hammant Exp $
   * $Revision: 1.1 $
   * $Date: 2002/01/02 12:11:56 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  package org.apache.commons.armi.server;
  
  
  
  /**
   * Class ArmiPublicationException
   *
   *
   * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
   * @version $Revision: 1.1 $
   */
  public class ArmiPublicationException extends Exception {
  
      /**
       * Constructor ArmiPublicationException
       *
       *
       * @param s
       *
       */
      public ArmiPublicationException(String s) {
          super(s);
      }
  }
  
  
  
  1.6       +58 -11    jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java
  
  Index: AbstractServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractServer.java	1 Jan 2002 17:53:06 -0000	1.5
  +++ AbstractServer.java	2 Jan 2002 12:11:56 -0000	1.6
  @@ -1,8 +1,8 @@
   
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java,v
1.5 2002/01/01 17:53:06 hammant Exp $
  - * $Revision: 1.5 $
  - * $Date: 2002/01/01 17:53:06 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/AbstractServer.java,v
1.6 2002/01/02 12:11:56 hammant Exp $
  + * $Revision: 1.6 $
  + * $Date: 2002/01/02 12:11:56 $
    *
    * ====================================================================
    *
  @@ -64,6 +64,7 @@
   
   
   import org.apache.commons.armi.server.ArmiServer;
  +import org.apache.commons.armi.server.ArmiPublicationException;
   import org.apache.commons.armi.common.ArmiInvocationHandler;
   import org.apache.commons.armi.common.ArmiRequest;
   import org.apache.commons.armi.common.ArmiReply;
  @@ -89,7 +90,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class AbstractServer extends AbstractMethodHandler implements ArmiServer {
   
  @@ -101,12 +102,12 @@
        *
        *
        * @param impl
  -     * @param as
  +     * @param asName
        * @param interfaceToExpose
        *
        */
  -    public void publish(Object impl, String as, Class interfaceToExpose) {
  -        publish(impl, as, new Class[]{ interfaceToExpose });
  +    public void publish(Object impl, String asName, Class interfaceToExpose) throws ArmiPublicationException{
  +        publish(impl, asName, new Class[]{ interfaceToExpose });
       }
   
       /**
  @@ -114,11 +115,15 @@
        *
        *
        * @param impl
  -     * @param as
  +     * @param asName
        * @param interfacesToExpose
        *
        */
  -    public void publish(Object impl, String as, Class[] interfacesToExpose) {
  +    public void publish(Object impl, String asName, Class[] interfacesToExpose) throws
ArmiPublicationException{
  +
  +        if (mPublishedObjects.containsKey(asName)) {
  +            throw new ArmiPublicationException("Service '"+asName+"' already published");
  +        }
   
           String[] interfaceNames = new String[interfacesToExpose.length];
   
  @@ -129,8 +134,6 @@
           HashMap methodMap = new HashMap();
           DefaultInvocationHandler dih = new DefaultInvocationHandler(impl, methodMap);
   
  -        mPublishedObjects.put(as, dih);
  -
           for (int x = 0; x < interfacesToExpose.length; x++) {
               Method methods[] = interfacesToExpose[x].getMethods();
   
  @@ -143,6 +146,50 @@
                   }
               }
           }
  +
  +        mPublishedObjects.put(asName, dih);
  +
  +    }
  +
  +    /**
  +     * Method unPublish
  +     *
  +     *
  +     * @param impl
  +     * @param asName
  +     *
  +     */
  +    public void unPublish(Object impl, String asName) throws ArmiPublicationException {
  +
  +        if (!mPublishedObjects.containsKey(asName)) {
  +            throw new ArmiPublicationException("Service '"+asName+"' not published");
  +        }
  +
  +    }
  +
  +    /**
  +     * Method replacePublished
  +     *
  +     *
  +     * @param oldImpl
  +     * @param asName
  +     * @param withImpl
  +     *
  +     */
  +    public void replacePublished(Object oldImpl, String asName, Object withImpl) throws
ArmiPublicationException {
  +
  +        if (!mPublishedObjects.containsKey(asName)) {
  +            throw new ArmiPublicationException("Service '"+asName+"' not published");
  +        }
  +
  +        DefaultInvocationHandler dih = (DefaultInvocationHandler) mPublishedObjects.get(asName);
  +
  +        if (!dih.isImplementaion(oldImpl)) {
  +            throw new ArmiPublicationException("Service '"+asName+"' is currently publishing
a different implementation to the one you want to replace.");
  +        }
  +
  +        dih.setImplementationBean(withImpl);
  +
       }
   
       /**
  
  
  
  1.2       +36 -9     jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/DefaultInvocationHandler.java
  
  Index: DefaultInvocationHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/DefaultInvocationHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultInvocationHandler.java	28 Dec 2001 18:08:38 -0000	1.1
  +++ DefaultInvocationHandler.java	2 Jan 2002 12:11:56 -0000	1.2
  @@ -1,8 +1,8 @@
   
   /*
  - * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/DefaultInvocationHandler.java,v
1.1 2001/12/28 18:08:38 hammant Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/12/28 18:08:38 $
  + * $Header: /home/cvs/jakarta-commons-sandbox/armi/src/java/org/apache/commons/armi/server/impl/DefaultInvocationHandler.java,v
1.2 2002/01/02 12:11:56 hammant Exp $
  + * $Revision: 1.2 $
  + * $Date: 2002/01/02 12:11:56 $
    *
    * ====================================================================
    *
  @@ -84,12 +84,12 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class DefaultInvocationHandler implements ArmiInvocationHandler {
   
  -    protected Object mBean;
  -    protected HashMap mMethodMap;
  +    private Object mImplBean;
  +    private HashMap mMethodMap;
   
       /**
        * Constructor DefaultInvocationHandler
  @@ -99,11 +99,38 @@
        * @param methodMap
        *
        */
  -    public DefaultInvocationHandler(Object bean, HashMap methodMap) {
  -        mBean = bean;
  +    protected DefaultInvocationHandler(Object implBean, HashMap methodMap) {
  +        mImplBean = implBean;
           mMethodMap = methodMap;
       }
   
  +
  +    /**
  +     * Method setImplementationBean
  +     *
  +     *
  +     * @param implBean
  +     *
  +     */
  +    protected void setImplementationBean(Object implBean) {
  +        mImplBean = implBean;
  +    }
  +
  +
  +    /**
  +     * Method isImplementaion
  +     *
  +     *
  +     * @param implBean
  +     *
  +     * @return if the param matches the bean that is the current impl.
  +     *
  +     */
  +    protected boolean isImplementaion(Object implBean) {
  +        return (implBean == mImplBean);
  +    }
  +
  +
       /**
        * Method handleInvocation
        *
  @@ -126,7 +153,7 @@
           Object rv = null;
   
           try {
  -            return new MethodReply(method.invoke(mBean, mr.getArgs()));
  +            return new MethodReply(method.invoke(mImplBean, mr.getArgs()));
           } catch (InvocationTargetException ite) {
               Throwable t = ite.getTargetException();
   
  
  
  

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


Mime
View raw message