commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters PublicationAdapter.java
Date Fri, 22 Mar 2002 22:51:37 GMT
hammant     02/03/22 14:51:37

  Modified:    altrmi/src/java/org/apache/commons/altrmi/client/impl
                        BaseServedObject.java
               altrmi/src/java/org/apache/commons/altrmi/generator
                        ProxyGeneratorImpl.java
               altrmi/src/java/org/apache/commons/altrmi/server
                        AltrmiPublisher.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl
                        AbstractServer.java
                        DefaultMethodInvocationHandler.java
               altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters
                        PublicationAdapter.java
  Log:
  Bug fix from Vinay to allow 'three way' scenarios to work a bit better.
  
  Revision  Changes    Path
  1.13      +56 -17    jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/BaseServedObject.java
  
  Index: BaseServedObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/client/impl/BaseServedObject.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- BaseServedObject.java	19 Mar 2002 22:12:36 -0000	1.12
  +++ BaseServedObject.java	22 Mar 2002 22:51:37 -0000	1.13
  @@ -31,7 +31,8 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.12 $
  + * @author Vinay Chandrasekharan <a href="mailto:vinay_chandran@users.sourceforge.net">vinay_chandran@users.sourceforge.net</a>
  + * @version $Revision: 1.13 $
    */
   public final class BaseServedObject {
   
  @@ -95,18 +96,17 @@
               String methodSignature, Object[] args, String objectName) throws Throwable
{
   
           boolean arrayRetVal = objectName.endsWith("[]");
  -        String objNameWithoutArray = objectName.substring(0,objectName.length()-2);
  -
  +        String objNameWithoutArray = objectName.substring(0, objectName.length() - 2);
           MethodFacadeRequest request;
   
           if (arrayRetVal) {
               request = new MethodFacadeRequest(mPublishedServiceName, mObjectName,
  -                            methodSignature, args, mReferenceID,
  -                            objNameWithoutArray, mSession);
  +                                              methodSignature, args, mReferenceID,
  +                                              objNameWithoutArray, mSession);
           } else {
               request = new MethodFacadeRequest(mPublishedServiceName, mObjectName,
  -                            methodSignature, args, mReferenceID,
  -                            objectName, mSession);
  +                                              methodSignature, args, mReferenceID, objectName,
  +                                              mSession);
           }
   
           AltrmiReply reply = mInvocationHandler.handleInvocation(request);
  @@ -137,25 +137,32 @@
               }
           } else if (reply.getReplyCode() == AltrmiReply.METHODFACADEARRAYREPLY) {
               MethodFacadeArrayReply mfar = (MethodFacadeArrayReply) reply;
  -            Class clazz = mAltrmiFactory.getFacadeClass(mPublishedServiceName, objNameWithoutArray,
  -                                                                  mAltrmiFactory.isBeanOnly());
  +            Class clazz = mAltrmiFactory.getFacadeClass(mPublishedServiceName,
  +                                                        objNameWithoutArray,
  +                                                        mAltrmiFactory.isBeanOnly());
               Long[] refs = mfar.getReferenceIDs();
               Object[] implBeans = (Object[]) Array.newInstance(clazz, refs.length);
   
               for (int i = 0; i < refs.length; i++) {
                   Long ref = refs[i];
  +
                   if (ref == null) {
                       implBeans[i] = null;
                   } else {
                       implBeans[i] = mAltrmiFactory.getImplObj(ref);
  +
                       if (implBeans[i] == null) {
  -                        BaseServedObject bo2 = new BaseServedObject(mAltrmiFactory, mInvocationHandler,
  -                                                                mPublishedServiceName,
objNameWithoutArray,
  -                                                                refs[i], mSession);
  +                        BaseServedObject bo2 = new BaseServedObject(mAltrmiFactory,
  +                                                                    mInvocationHandler,
  +                                                                    mPublishedServiceName,
  +                                                                    objNameWithoutArray,
refs[i],
  +                                                                    mSession);
                           Object retFacade = null;
  +
                           try {
  -                            retFacade = mAltrmiFactory.getInstance(mPublishedServiceName,
objNameWithoutArray,
  -                                                                      bo2, mAltrmiFactory.isBeanOnly());
  +                            retFacade = mAltrmiFactory.getInstance(mPublishedServiceName,
  +                                                                   objNameWithoutArray,
bo2,
  +                                                                   mAltrmiFactory.isBeanOnly());
                           } catch (Exception e) {
                               System.out.println("objNameWithoutArray=" + objNameWithoutArray);
                               System.out.flush();
  @@ -163,10 +170,12 @@
                           }
   
                           bo2.registerImplObject(retFacade);
  +
                           implBeans[i] = retFacade;
                       }
                   }
               }
  +
               return implBeans;
           } else if (reply.getReplyCode() == AltrmiReply.EXCEPTIONREPLY) {
               ExceptionReply er = (ExceptionReply) reply;
  @@ -190,8 +199,9 @@
        * @throws Throwable
        *
        */
  -    public Object processObjectRequest(String methodSignature, Object[] args)
  -            throws Throwable {
  +    public Object processObjectRequest(String methodSignature, Object[] args) throws Throwable
{
  +
  +        marshallCorrection(args);
   
           MethodRequest request = new MethodRequest(mPublishedServiceName, mObjectName,
                                                     methodSignature, args, mReferenceID,
mSession);
  @@ -243,15 +253,30 @@
           }
       }
   
  -    public void processVoidRequestWithRedirect(String methodSignature, Object[] args) throws
Throwable {
  +    /**
  +     * Method processVoidRequestWithRedirect
  +     *
  +     *
  +     * @param methodSignature
  +     * @param args
  +     *
  +     * @throws Throwable
  +     *
  +     */
  +    public void processVoidRequestWithRedirect(String methodSignature, Object[] args)
  +            throws Throwable {
  +
           Object[] newArgs = new Object[args.length];
  +
           for (int i = 0; i < args.length; i++) {
               if (args[i] instanceof AltrmiProxy) {
  +
                   //TODO somehow get the reference details and put a redirect place holder
here
               } else {
                   newArgs[i] = args[i];
               }
           }
  +
           processVoidRequest(methodSignature, newArgs);
       }
   
  @@ -279,6 +304,20 @@
   
               System.out.println("i = " + i + " class= " + args[i].getClass().getName() +
" "
                                  + args[i].toString());
  +        }
  +    }
  +
  +    private void marshallCorrection(Object[] args) {
  +
  +        for (int i = 0; i < args.length; i++) {
  +
  +            //check whether its one of those remote ref that we got from the server
  +            //TODO : todo
  +            if (mAltrmiFactory.getReferenceID(args[i]) != null) {
  +                String objName = args[i].getClass().getName().substring(16);
  +
  +                args[i] = makeFacadeRefHolder(args[i], objName);
  +            }
           }
       }
   }
  
  
  
  1.9       +3 -3      jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/ProxyGeneratorImpl.java
  
  Index: ProxyGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/generator/ProxyGeneratorImpl.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ProxyGeneratorImpl.java	19 Mar 2002 22:12:36 -0000	1.8
  +++ ProxyGeneratorImpl.java	22 Mar 2002 22:51:37 -0000	1.9
  @@ -33,7 +33,7 @@
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
    * @author Mike Miller of www.gac.com
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
   public class ProxyGeneratorImpl extends AbstractMethodHandler implements ProxyGenerator
{
   
  @@ -454,10 +454,10 @@
               mClassSource.println("    args[" + i + "] = new Boolean(v" + i + ");");
           } else if (cn.equals("byte")) {
               mClassSource.println("    args[" + i + "] = new Byte(v" + i + ");");
  -        } else if (isAdditionalFacade(clazz)) {
  +        } /*else if (isAdditionalFacade(clazz)) {
               mClassSource.println("    args[" + i + "] = mBaseServedObject.makeFacadeRefHolder(v"
                                    + i + ",\"" + super.encodeClassName(cn) + "\");");
  -        } else {
  +        } */else {
               mClassSource.println("    args[" + i + "] = v" + i + ";");
           }
       }
  
  
  
  1.6       +13 -1     jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiPublisher.java
  
  Index: AltrmiPublisher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/AltrmiPublisher.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AltrmiPublisher.java	24 Feb 2002 11:04:32 -0000	1.5
  +++ AltrmiPublisher.java	22 Mar 2002 22:51:37 -0000	1.6
  @@ -18,7 +18,8 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version * $Revision: 1.5 $
  + * @author Vinay Chandrasekharan <a href="mailto:vinay_chandran@users.sourceforge.net">vinay_chandran@users.sourceforge.net</a>
  + * @version * $Revision: 1.6 $
    */
   public interface AltrmiPublisher {
   
  @@ -79,4 +80,15 @@
        *
        */
       MethodInvocationHandler getMethodInvocationHandler(MethodRequest mr, String objectName);
  +
  +    /**
  +     * Method getMethodInvocationHandler
  +     *
  +     *
  +     * @param publishedName
  +     *
  +     * @return
  +     *
  +     */
  +    MethodInvocationHandler getMethodInvocationHandler(String publishedName);
   }
  
  
  
  1.22      +15 -1     jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/AbstractServer.java
  
  Index: AbstractServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/AbstractServer.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- AbstractServer.java	12 Mar 2002 17:05:19 -0000	1.21
  +++ AbstractServer.java	22 Mar 2002 22:51:37 -0000	1.22
  @@ -29,7 +29,8 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.21 $
  + * @author Vinay Chandrasekharan <a href="mailto:vinay_chandran@users.sourceforge.net">vinay_chandran@users.sourceforge.net</a>
  + * @version $Revision: 1.22 $
    */
   public abstract class AbstractServer extends AbstractMethodHandler
           implements AltrmiServer, LogEnabled {
  @@ -228,6 +229,19 @@
       public MethodInvocationHandler getMethodInvocationHandler(MethodRequest mr,
                                                                 String objectName) {
           return mInovcationHandlerAdapter.getMethodInvocationHandler(mr, objectName);
  +    }
  +
  +    /**
  +     * Method getMethodInvocationHandler
  +     *
  +     *
  +     * @param publishedName
  +     *
  +     * @return
  +     *
  +     */
  +    public MethodInvocationHandler getMethodInvocationHandler(String publishedName) {
  +        return mInovcationHandlerAdapter.getMethodInvocationHandler(publishedName);
       }
   
   }
  
  
  
  1.5       +27 -7     jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/DefaultMethodInvocationHandler.java
  
  Index: DefaultMethodInvocationHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/DefaultMethodInvocationHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultMethodInvocationHandler.java	9 Mar 2002 06:46:33 -0000	1.4
  +++ DefaultMethodInvocationHandler.java	22 Mar 2002 22:51:37 -0000	1.5
  @@ -38,7 +38,8 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.4 $
  + * @author Vinay Chandrasekharan <a href="mailto:vinay_chandran@users.sourceforge.net">vinay_chandran@users.sourceforge.net</a>
  + * @version $Revision: 1.5 $
    */
   public class DefaultMethodInvocationHandler implements MethodInvocationHandler {
   
  @@ -53,12 +54,14 @@
        * Constructor DefaultMethodInvocationHandler
        *
        *
  -     * @param bean
  +     *
  +     * @param altrmiPublisher
  +     * @param publishedThing
        * @param methodMap
        *
        */
       public DefaultMethodInvocationHandler(AltrmiPublisher altrmiPublisher, String publishedThing,
  -                                       HashMap methodMap) {
  +                                          HashMap methodMap) {
   
           mAltrmiPublisher = altrmiPublisher;
           mPublishedThing = publishedThing;
  @@ -124,15 +127,14 @@
           Long ref = (Long) mBeanRefs.get(implBean);
   
           if (ref == null) {
  +
               //ref = new Long((long) ((long) mNextReference++ << 32)
               //               + (long) Math.round(Math.random()));
               ref = new Long(NEXT_REFERENCE++);
   
               //mBeanRefs.put(implBean, ref);
               //mRefBeans.put(ref, implBean);
  -
               addImplementationBean(ref, implBean);
  -
           }
   
           return ref;
  @@ -165,6 +167,7 @@
   
               if (beanImpl == null) {
                   System.out.println("Missin for " + mr.getReferenceID());
  +
                   return new NoSuchReferenceReply(mr.getReferenceID());
               }
   
  @@ -173,6 +176,7 @@
               correctArgs(mr, args);
   
               Object replyVal = method.invoke(beanImpl, mr.getArgs());
  +
               return new MethodReply(replyVal);
           } catch (InvocationTargetException ite) {
               Throwable t = ite.getTargetException();
  @@ -187,6 +191,8 @@
                           "Exception was not serializable :" + t.getClass().getName()));
               }
           } catch (Throwable t) {
  +            System.out.flush();
  +            t.printStackTrace();
   
               return new ExceptionReply(
                   new AltrmiInvocationException(
  @@ -202,11 +208,25 @@
               if (args[i] instanceof FacadeRefHolder) {
                   FacadeRefHolder frh = (FacadeRefHolder) args[i];
                   DefaultMethodInvocationHandler asih =
  -                    (DefaultMethodInvocationHandler) mAltrmiPublisher.getMethodInvocationHandler(mr,
  -                        frh.getObjectName());
  +                    (DefaultMethodInvocationHandler) mAltrmiPublisher
  +                        .getMethodInvocationHandler(frh.getObjectName());
   
                   args[i] = asih.mRefBeans.get(frh.getReferenceID());
               }
           }
  +    }
  +
  +    private void debug(Object[] args) {
  +
  +        System.out.println("*************************");
  +
  +        for (int i = 0; i < args.length; i++) {
  +            Object arg = args[i];
  +
  +            System.out.println("i = " + i + " class= " + args[i].getClass().getName() +
" "
  +                               + args[i].toString());
  +        }
  +
  +        System.out.println("*************************");
       }
   }
  
  
  
  1.3       +41 -16    jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters/PublicationAdapter.java
  
  Index: PublicationAdapter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/altrmi/src/java/org/apache/commons/altrmi/server/impl/adapters/PublicationAdapter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PublicationAdapter.java	24 Feb 2002 11:04:33 -0000	1.2
  +++ PublicationAdapter.java	22 Mar 2002 22:51:37 -0000	1.3
  @@ -1,3 +1,4 @@
  +
   /*
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
  @@ -7,6 +8,8 @@
    */
   package org.apache.commons.altrmi.server.impl.adapters;
   
  +
  +
   import org.apache.commons.altrmi.server.AltrmiPublisher;
   import org.apache.commons.altrmi.server.PublicationException;
   import org.apache.commons.altrmi.server.MethodInvocationHandler;
  @@ -16,8 +19,17 @@
   import org.apache.commons.altrmi.common.MethodRequest;
   
   import java.util.HashMap;
  +
   import java.lang.reflect.Method;
   
  +
  +/**
  + * Class PublicationAdapter
  + *
  + *
  + * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  + * @version $Revision: 1.3 $
  + */
   public class PublicationAdapter extends AbstractMethodHandler implements AltrmiPublisher
{
   
       protected HashMap mPublishedObjects = new HashMap();
  @@ -33,10 +45,11 @@
        */
       public void publish(Object impl, String asName, Class classOrInterfaceToExpose)
               throws PublicationException {
  -        publish(impl, asName, new PublicationDescription( new Class[] { classOrInterfaceToExpose
}, new Class[0]));
  -    }
  -
   
  +        publish(impl, asName,
  +                new PublicationDescription(new Class[]{ classOrInterfaceToExpose },
  +                                           new Class[0]));
  +    }
   
       /**
        * Method publish
  @@ -47,11 +60,11 @@
        * @param publicationDescription
        *
        */
  -    public void publish(
  -            Object impl, String asName, PublicationDescription publicationDescription)
  -                throws PublicationException {
  +    public void publish(Object impl, String asName, PublicationDescription publicationDescription)
  +            throws PublicationException {
   
  -        Class[] classesOrInterfacesToExpose = publicationDescription.getClassesOrInterfacesToExpose();
  +        Class[] classesOrInterfacesToExpose =
  +            publicationDescription.getClassesOrInterfacesToExpose();
           Class[] additionalFacades = publicationDescription.getAdditionalFacades();
   
           if (mPublishedObjects.containsKey(asName + "_Main")) {
  @@ -66,7 +79,8 @@
   
           // add method maps for main lookup-able service.
           HashMap mainMethodMap = new HashMap();
  -        MethodInvocationHandler mainAsih = new DefaultMethodInvocationHandler(this, asName
+ "_Main", mainMethodMap);
  +        MethodInvocationHandler mainAsih = new DefaultMethodInvocationHandler(this,
  +                                               asName + "_Main", mainMethodMap);
   
           mainAsih.addImplementationBean(new Long(0), impl);
   
  @@ -91,7 +105,8 @@
               Method methods[] = additionalFacades[x].getMethods();
               String encodedClassName = encodeClassName(additionalFacades[x].getName());
               HashMap methodMap = new HashMap();
  -            MethodInvocationHandler asih = new DefaultMethodInvocationHandler(this, asName
+ "_" + encodedClassName, methodMap);
  +            MethodInvocationHandler asih = new DefaultMethodInvocationHandler(this,
  +                                               asName + "_" + encodedClassName, methodMap);
   
               for (int y = 0; y < methods.length; y++) {
                   Method method = methods[y];
  @@ -139,13 +154,12 @@
               throw new PublicationException("Service '" + asName + "' not published");
           }
   
  -        MethodInvocationHandler asih =
  -            (MethodInvocationHandler) mPublishedObjects.get(asName + "_Main");
  +        MethodInvocationHandler asih = (MethodInvocationHandler) mPublishedObjects.get(asName
  +                                           + "_Main");
   
           asih.replaceImplementationBean(oldImpl, withImpl);
       }
   
  -
       /**
        * Method getServerInvocationHandler
        *
  @@ -157,10 +171,21 @@
        *
        */
       public MethodInvocationHandler getMethodInvocationHandler(MethodRequest mr,
  -                                                                    String objectName)
{
  -        return (MethodInvocationHandler) mPublishedObjects.get(mr.getPublishedServiceName()
  -                                                                     + "_" + objectName);
  +                                                              String objectName) {
  +        return (MethodInvocationHandler) mPublishedObjects.get(mr.getPublishedServiceName()
+ "_"
  +                                                               + objectName);
       }
   
  -
  +    /**
  +     * Method getMethodInvocationHandler
  +     *
  +     *
  +     * @param publishedName
  +     *
  +     * @return
  +     *
  +     */
  +    public MethodInvocationHandler getMethodInvocationHandler(String publishedName) {
  +        return (MethodInvocationHandler) mPublishedObjects.get(publishedName);
  +    }
   }
  
  
  

--
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