geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdam...@apache.org
Subject cvs commit: incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/reference ReferenceFactory.java
Date Thu, 20 May 2004 13:37:12 GMT
gdamour     2004/05/20 06:37:12

  Modified:    sandbox/messaging/src/java/org/apache/geronimo/messaging
                        NodeImpl.java Node.java AbstractEndPoint.java
                        RequestSender.java
               sandbox/messaging/src/java/org/apache/geronimo/messaging/replication
                        ReplicationMemberImpl.java
               sandbox/messaging/src/test/org/apache/geronimo/messaging
                        MockNode.java
               sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote
                        RemoteUseCaseTest.java
               sandbox/messaging/src/java/org/apache/geronimo/messaging/reference
                        ReferenceFactory.java
  Added:       sandbox/messaging/src/java/org/apache/geronimo/messaging/proxy
                        EndPointProxyInfo.java EndPointProxyFactory.java
                        EndPointProxyFactoryImpl.java EndPointProxy.java
                        HOPPFilter.java EndPointCallback.java
               sandbox/messaging/src/test/org/apache/geronimo/messaging/proxy
                        EndPointProxyFactoryTest.java
  Removed:     sandbox/messaging/src/java/org/apache/geronimo/messaging/util
                        EndPointCallback.java ProxyFactory.java
               sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote
                        GFileManagerClient.java
               sandbox/messaging/src/test/org/apache/geronimo/messaging/util
                        ProxyFactoryTest.java
  Log:
  o Remove the ProxyFactory notion; it was a bad idea.
  o Implement an EndPoint in charge of creating EndPoint proxies, namely
  EndPointProxyFactory. This EndPoint is automatically registered by a 
  Node.
  o Two new contracts have been added to Node: factoryEndPointProxy
  and releaseEndPointProxy. They can be used to obtain a proxy for an
  EndPoint running on a set of Nodes and to release its resources
  respectively.
  o Migrate the remote implementation of datastore to leverage the
  EndPoint proxy feature.
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/proxy/EndPointProxyInfo.java
  
  Index: EndPointProxyInfo.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.proxy;
  
  import org.apache.geronimo.messaging.NodeInfo;
  
  /**
   * EndPoint proxy meta-data.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/20 13:37:11 $
   */
  public class EndPointProxyInfo
  {
      
      /**
       * EndPoint identifier.
       */
      private final Object endPointID;
      
      /**
       * Interfaces implemented by the EndPoint.
       */
      private final Class[] interfaces;
      
      /**
       * Nodes hosting the EndPoint.
       */
      private final NodeInfo[] targets;
      
      /**
       * Creates the meta-data of an EndPoint proxy.  
       * 
       * @param anEndPointID EndPoint identifier.
       * @param anInterfaces Interfaces of the EndPoint proxy.
       * @param aTargets Nodes hosting the EndPoint.
       */
      public EndPointProxyInfo(Object anEndPointID, Class[] anInterfaces,
          NodeInfo[] aTargets) {
          if ( null == anEndPointID ) {
              throw new IllegalArgumentException("EndPointID is required.");
          } else if ( null == anInterfaces || 0 == anInterfaces.length ) {
              throw new IllegalArgumentException("Interfaces is required");
          } else if ( null == aTargets || 0 == aTargets.length ) {
              throw new IllegalArgumentException("Targets is required");
          }
          endPointID = anEndPointID;
          interfaces = anInterfaces;
          targets = aTargets;
      }
      
      /**
       * Gets the EndPoint identifier.
       * 
       * @return EndPoint id.
       */
      public Object getEndPointID() {
          return endPointID;
      }
      
      /**
       * Gets the interfaces of the EndPoint.
       * 
       * @return EndPoint interfaces.
       */
      public Class[] getInterfaces() {
          return interfaces;
      }
      
      /**
       * Gets the Nodes hosting the EndPoint.
       * 
       * @return Hosting nodes.
       */
      public NodeInfo[] getTargets() {
          return targets;
      }
      
  }
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/proxy/EndPointProxyFactory.java
  
  Index: EndPointProxyFactory.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.proxy;
  
  import org.apache.geronimo.messaging.EndPoint;
  
  /**
   * Factory of EndPoint proxies.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/20 13:37:11 $
   */
  public interface EndPointProxyFactory
      extends EndPoint
  {
      
      /**
       * Creates a proxy for the EndPoint defined by anInfo.
       * 
       * @param anInfo EndPoint meta-data.
       * @return A proxy for the EndPoint defined by anInfo. This proxy implements
       * all the EndPoint interfaces plus the EndPointProxy interface.
       */
      public Object factory(EndPointProxyInfo anInfo);
      
      /**
       * Releases the resources of the specified EndPoint proxy.
       * <BR>
       * From this point, the proxy can no more be used.
       * 
       * @param aProxy EndPoint proxy.
       * @exception IllegalArgumentException Indicates that the provided instance
       * is not a proxy.
       */
      public void releaseProxy(Object aProxy);
      
  }
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/proxy/EndPointProxyFactoryImpl.java
  
  Index: EndPointProxyFactoryImpl.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.proxy;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Iterator;
  
  import net.sf.cglib.proxy.Callback;
  import net.sf.cglib.proxy.Enhancer;
  import net.sf.cglib.proxy.LazyLoader;
  import net.sf.cglib.proxy.MethodInterceptor;
  
  import org.apache.geronimo.gbean.WaitingException;
  import org.apache.geronimo.messaging.AbstractEndPoint;
  import org.apache.geronimo.messaging.Node;
  import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
  
  /**
   * EndPointProxyFactory implementation.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/20 13:37:11 $
   */
  public class EndPointProxyFactoryImpl
      extends AbstractEndPoint
      implements EndPointProxyFactory
  {
  
      /**
       * EndPoint call-backs of the proxies created by this factory. They are
       * tracked in order to update their Msg output when the factory is started
       * or stopped.
       */
      private final Collection endPointCallbacks;
      
      /**
       * Creates a factory mounted by the specified node and having the specified
       * identifier.
       * 
       * @param aNode Hosting Node.
       * @param anID EndPoint identifier.
       */
      public EndPointProxyFactoryImpl(Node aNode, Object anID) {
          super(aNode, anID);
          endPointCallbacks = new ArrayList();
      }
  
      /**
       * Creates a proxy for the EndPoint defined by anInfo.
       * 
       * @param anInfo EndPoint meta-data.
       * @return A proxy for the EndPoint defined by anInfo. This proxy implements
       * all the EndPoint interfaces plus the EndPointProxy interface.
       */
      public Object factory(EndPointProxyInfo anInfo) {
          if ( null == anInfo ) {
              throw new IllegalArgumentException("Info is required");
          }
          
          final EndPointCallback endPointCB = new EndPointCallback(sender);
          endPointCB.setEndPointId(anInfo.getEndPointID());
          endPointCB.setTargets(anInfo.getTargets());
          endPointCB.setOut(out);
          
          // Injects the EndPointProxy interface.
          Class[] endPointItf = anInfo.getInterfaces();
          Class[] interfaces = new Class[endPointItf.length + 1];
          for (int i = 0; i < endPointItf.length; i++) {
              interfaces[i] = endPointItf[i];
          }
          interfaces[interfaces.length - 1] = EndPointProxy.class;
  
          Enhancer enhancer = new Enhancer();
          enhancer.setInterfaces(interfaces);
          enhancer.setCallbackTypes(
              new Class[] {MethodInterceptor.class, LazyLoader.class});
          enhancer.setUseFactory(false);
          enhancer.setCallbacks(new Callback[] {endPointCB,
              new LazyLoader() {
                  public Object loadObject() throws Exception {
                      return new HalfObjectLocal(endPointCB);
                  }
              }});
          enhancer.setCallbackFilter(new HOPPFilter(anInfo.getInterfaces()));
          Object opaque = enhancer.create();
          
          synchronized(endPointCallbacks) {
              endPointCallbacks.add(endPointCB);
          }
          
          return opaque;
      }
  
      /**
       * Releases the resources of the specified EndPoint proxy.
       * <BR>
       * From this point, the proxy can no more be used.
       * 
       * @param aProxy EndPoint proxy.
       * @exception IllegalArgumentException Indicates that the provided instance
       * is not a proxy.
       */
      public void releaseProxy(Object aProxy) {
          if ( false == aProxy instanceof EndPointProxy ) {
              throw new IllegalArgumentException("Not an EndPointProxy");
          }
          ((EndPointProxy) aProxy).release();
      }
      
      public void setMsgProducerOut(MsgOutInterceptor aMsgOut) {
          super.setMsgProducerOut(aMsgOut);
          // When the factory is started or stopped, one also updates the
          // Msg output of the endpoint call-backs.
          synchronized(endPointCallbacks) {
              for (Iterator iter = endPointCallbacks.iterator(); iter.hasNext();) {
                  EndPointCallback callback = (EndPointCallback) iter.next();
                  callback.setOut(out);
              }
          }
      }
      
      public void doStop() throws WaitingException, Exception {
          super.doStop();
          synchronized(endPointCallbacks) {
              // Does not need to reset the Msg output of the call-backs as this
              // is already done via setMsgProducerOut.
              endPointCallbacks.clear();
          }
      }
  
      public void doFail() {
          super.doFail();
          synchronized(endPointCallbacks) {
              endPointCallbacks.clear();
          }
      }
      
      /**
       * Implements the local half of an EndPoint proxy. 
       */
      private class HalfObjectLocal implements EndPointProxy {
          private final EndPointCallback endPointCallback;
          private HalfObjectLocal(EndPointCallback anEndPointCallback) {
              endPointCallback = anEndPointCallback;
          }
          public void release() {
              endPointCallback.setOut(null);
              synchronized(endPointCallbacks) {
                  endPointCallbacks.remove(endPointCallback);
              }
          }
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/proxy/EndPointProxy.java
  
  Index: EndPointProxy.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.proxy;
  
  
  /**
   * EndPointProxyFactory creates EndPoint proxies, which automatically implement
   * this interface.
   * <BR>
   * Clients should not use the contracts of this interface.
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/20 13:37:11 $
   */
  interface EndPointProxy
  {
      
      /**
       * Releases the EndPoint proxy resources.
       */
      public void release();
      
  }
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/proxy/HOPPFilter.java
  
  Index: HOPPFilter.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.proxy;
  
  import java.lang.reflect.Method;
  
  import net.sf.cglib.proxy.CallbackFilter;
  
  
  /**
   * Maps the methods defined by the specified interfaces to the first Callback
   * of an Enhancer.
   * <BR>
   * The other methods are mapped to the second one.
   * 
   * @version $Revision: 1.1 $ $Date: 2004/05/20 13:37:11 $
   */
  public class HOPPFilter
      implements CallbackFilter
  {
      
      private final Class[] interfaces;
  
      /**
       * @param anInterfaces Interfaces whose methods should be handled by the
       * first Callback of an Enhancer.
       */
      public HOPPFilter(Class[] anInterfaces) {
          interfaces = anInterfaces;
      }
      
      public int accept(Method arg0) {
          Class declaringClass = arg0.getDeclaringClass(); 
          for (int i = 0; i < interfaces.length; i++) {
              if ( interfaces[i].equals(declaringClass) ) {
                  return 0;
              }
          }
          return 1;  
      }
      
  }
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/proxy/EndPointCallback.java
  
  Index: EndPointCallback.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.proxy;
  
  import java.lang.reflect.Method;
  
  import net.sf.cglib.proxy.MethodInterceptor;
  import net.sf.cglib.proxy.MethodProxy;
  
  import org.apache.geronimo.messaging.NodeInfo;
  import org.apache.geronimo.messaging.Request;
  import org.apache.geronimo.messaging.RequestSender;
  import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
  
  /**
   * This Callback sends Request to an EndPoint hosted by a set of Nodes. 
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/20 13:37:11 $
   */
  public class EndPointCallback
      implements MethodInterceptor
  {
  
      /**
       * To send request Msgs.
       */
      private final RequestSender sender;
  
      /**
       * Transport bus. 
       */
      private MsgOutInterceptor out;
      
      /**
       * Nodes to which the Msgs are to be sent.
       */
      private NodeInfo[] targets;
  
      /**
       * EndPoint identifier.
       */
      private Object id;
  
      /**
       * @param aSender RequestSender to be used to send Request to the
       * associated EndPoint.
       */
      public EndPointCallback(RequestSender aSender) {
          if ( null == aSender ) {
              throw new IllegalArgumentException("Sender is required.");
          }
          sender = aSender;
      }
  
      /**
       * Gets the target EndPoint identifier.
       * 
       * @return Returns the id.
       */
      public Object getEndPointId() {
          return id;
      }
  
      /**
       * Sets the identifier of the target EndPoint.
       * 
       * @param anID The id to set.
       */
      public void setEndPointId(Object anID) {
          id = anID;
      }
  
      /**
       * Gets the Msg transport used to sent Requests.
       * 
       * @return Returns the out.
       */
      public MsgOutInterceptor getOut() {
          return out;
      }
  
      /**
       * Sets the Msg output to be used to sent Requests. 
       * 
       * @param anOut The out to set.
       */
      public void setOut(MsgOutInterceptor anOut) {
          out = anOut;
      }
  
      /**
       * Gets the Nodes hosting the target EndPoint.
       * 
       * @return Returns the targets.
       */
      public NodeInfo[] getTargets() {
          return targets;
      }
  
      /**
       * Sets the Nodes hosting the target EndPoints.
       * 
       * @param aTargets The targets to set.
       */
      public void setTargets(NodeInfo[] aTargets) {
          targets = aTargets;
      }
      
      public Object intercept(Object arg0, Method arg1,
                              Object[] arg2, MethodProxy arg3) throws Throwable {
          if ( null == out ) {
              throw new IllegalStateException("No Msg out is defined");
          } else if ( null == id ) {
              throw new IllegalStateException("No EndPoint id is defined");
          } else if ( null == targets ) {
              throw new IllegalStateException("No target nodes is defined");
          }
          try {
              Object opaque = sender.sendSyncRequest(
                      new Request(arg1.getName(), arg2), out, id, targets);
              return opaque;
          } catch (RuntimeException e) {
              Throwable nested = e.getCause();
              if ( null == nested ) {
                  throw e;
              }
              // unwrap the exceptions raised by the actual method.
              Class[] exceptions = arg1.getExceptionTypes();
              for (int i = 0; i < exceptions.length; i++) {
                  if ( exceptions[i].isInstance(nested) ) {
                      throw nested;
                  }
              }
              throw e;
          }
      }
  
  }
  
  
  
  1.2       +27 -11    incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/NodeImpl.java
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/NodeImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NodeImpl.java	11 May 2004 12:06:41 -0000	1.1
  +++ NodeImpl.java	20 May 2004 13:37:11 -0000	1.2
  @@ -33,6 +33,9 @@
   import org.apache.geronimo.messaging.io.ReplacerResolver;
   import org.apache.geronimo.messaging.io.StreamManager;
   import org.apache.geronimo.messaging.io.StreamManagerImpl;
  +import org.apache.geronimo.messaging.proxy.EndPointProxyFactory;
  +import org.apache.geronimo.messaging.proxy.EndPointProxyFactoryImpl;
  +import org.apache.geronimo.messaging.proxy.EndPointProxyInfo;
   import org.apache.geronimo.messaging.reference.ReferenceableManager;
   import org.apache.geronimo.messaging.reference.ReferenceableManagerImpl;
   import org.apache.geronimo.messaging.remotenode.LogicalCompression;
  @@ -72,6 +75,11 @@
       private final ReferenceableManager referenceableManager;
       
       /**
  +     * Used to create/release EndPoint proxies.
  +     */
  +    private final EndPointProxyFactory endPointProxyFactory;
  +    
  +    /**
        * Used to replace or resolve objects during the Serialization of
        * instances sent to remote nodes. 
        */
  @@ -119,6 +127,7 @@
           replacerResolver = new NullReplacerResolver();
           streamManager = newStreamManager();
           referenceableManager = newReferenceableManager();
  +        endPointProxyFactory = newEndPointProxyFactory();
           
           compression = new LogicalCompression();
           IOContext ioContext = new IOContext();
  @@ -172,10 +181,19 @@
           inDispatcher.unregister(id);
       }
       
  +    public Object factoryEndPointProxy(EndPointProxyInfo anInfo) {
  +        return endPointProxyFactory.factory(anInfo);
  +    }
  +    
  +    public void releaseEndPointProxy(Object aProxy) {
  +        endPointProxyFactory.releaseProxy(aProxy);
  +    }
  +    
       public void setGBeanContext(GBeanContext aContext) {
       }
   
       public void doStart() throws WaitingException, Exception {
  +        endPointProxyFactory.doStart();
           referenceableManager.doStart();
           streamManager.doStart();
           nodeManager.start();
  @@ -186,6 +204,7 @@
           nodeManager.stop();
           streamManager.doStop();
           referenceableManager.doStop();
  +        endPointProxyFactory.doStop();
       }
   
       public void doFail() {
  @@ -194,16 +213,9 @@
           } catch (NodeException e) {
               log.error("Can not stop node manager.", e);
           }
  -        try {
  -            streamManager.doStop();
  -        } catch (Exception e) {
  -            log.error("Can not stop stream manager.", e);
  -        }
  -        try {
  -            referenceableManager.doStop();
  -        } catch (Exception e) {
  -            log.error("Can not stop referenceable manager.", e);
  -        }
  +        streamManager.doFail();
  +        referenceableManager.doFail();
  +        endPointProxyFactory.doFail();
       }
       
       public String toString() {
  @@ -226,6 +238,10 @@
        */
       protected ReferenceableManager newReferenceableManager() {
           return new ReferenceableManagerImpl(this, "ReferenceableManager");
  +    }
  +    
  +    protected EndPointProxyFactory newEndPointProxyFactory() {
  +        return new EndPointProxyFactoryImpl(this, "EndPointProxyFactory");
       }
       
       private MsgOutInterceptor newOutboundMsgProviderOut() {
  
  
  
  1.2       +22 -1     incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/Node.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Node.java	11 May 2004 12:06:41 -0000	1.1
  +++ Node.java	20 May 2004 13:37:11 -0000	1.2
  @@ -19,6 +19,7 @@
   
   import org.apache.geronimo.gbean.GBean;
   import org.apache.geronimo.messaging.io.ReplacerResolver;
  +import org.apache.geronimo.messaging.proxy.EndPointProxyInfo;
   
   /**
    * Abstract a node in a clustered deployment.
  @@ -89,5 +90,25 @@
        * @param anEndPoint EndPoint to be deregistered.
        */
       public void removeEndPoint(EndPoint anEndPoint);
  +
  +    /**
  +     * Creates a proxy for the EndPoint defined by anInfo.
  +     * 
  +     * @param anInfo EndPoint meta-data.
  +     * @return A proxy for the EndPoint defined by anInfo. This proxy implements
  +     * all the EndPoint interfaces plus the EndPointProxy interface.
  +     */
  +    public Object factoryEndPointProxy(EndPointProxyInfo anInfo);
  +    
  +    /**
  +     * Releases the resources of the specified EndPoint proxy.
  +     * <BR>
  +     * From this point, the proxy can no more be used.
  +     * 
  +     * @param aProxy EndPoint proxy.
  +     * @exception IllegalArgumentException Indicates that the provided instance
  +     * is not a proxy.
  +     */
  +    public void releaseEndPointProxy(Object aProxy);
       
   }
  
  
  
  1.2       +2 -3      incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/AbstractEndPoint.java
  
  Index: AbstractEndPoint.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/AbstractEndPoint.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractEndPoint.java	11 May 2004 12:06:41 -0000	1.1
  +++ AbstractEndPoint.java	20 May 2004 13:37:11 -0000	1.2
  @@ -119,8 +119,7 @@
       protected void handleResponse(Msg aMsg) {
           MsgBody body = aMsg.getBody();
           MsgHeader header = aMsg.getHeader();
  -        Result result;
  -        result = (Result) body.getContent();
  +        Result result = (Result) body.getContent();
           sender.setResponse(
               header.getHeader(MsgHeaderConstants.CORRELATION_ID),
               result);
  
  
  
  1.2       +5 -2      incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/RequestSender.java
  
  Index: RequestSender.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/RequestSender.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestSender.java	11 May 2004 12:06:41 -0000	1.1
  +++ RequestSender.java	20 May 2004 13:37:11 -0000	1.2
  @@ -45,7 +45,7 @@
       /**
        * Number of milliseconds to wait for a response.
        */
  -    private static final long WAIT_RESPONSE = 1000;
  +    private static final long WAIT_RESPONSE = 5000;
       
       /**
        * Used to generate request identifiers.
  @@ -95,6 +95,9 @@
        */
       public Object sendSyncRequest(Object anOpaque, MsgOutInterceptor anOut,
           Object aTargetID, NodeInfo[] aTargetNodes) {
  +        if ( null == anOut ) {
  +            throw new IllegalArgumentException("Msg out is not required");
  +        }
           Msg msg = new Msg();
           
           MsgHeader header = msg.getHeader();
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/proxy/EndPointProxyFactoryTest.java
  
  Index: EndPointProxyFactoryTest.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   *  Unless required by applicable law or agreed to in writing, software
   *  distributed under the License is distributed on an "AS IS" BASIS,
   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *  See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  
  package org.apache.geronimo.messaging.proxy;
  
  import java.net.InetAddress;
  import java.util.List;
  
  import junit.framework.TestCase;
  
  import org.apache.geronimo.messaging.MockEndPoint;
  import org.apache.geronimo.messaging.MockEndPointImpl;
  import org.apache.geronimo.messaging.MockNode;
  import org.apache.geronimo.messaging.MsgHeaderConstants;
  import org.apache.geronimo.messaging.NodeInfo;
  import org.apache.geronimo.messaging.Request;
  import org.apache.geronimo.messaging.interceptors.HeaderOutInterceptor;
  import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/05/20 13:37:11 $
   */
  public class EndPointProxyFactoryTest
      extends TestCase
  {
  
      private NodeInfo[] targets;
      private Object proxy;
      private EndPointProxyFactory factory;
      
      protected void setUp() throws Exception {
          InetAddress address = InetAddress.getLocalHost();
          targets = new NodeInfo[] {new NodeInfo("dummy", address, 8081)};
          
          factory = new EndPointProxyFactoryImpl(new MockNode(), "Factory");
          
          EndPointProxyInfo proxyInfo =
              new EndPointProxyInfo("", new Class[] {MockEndPoint.class},
                  targets);
          proxy = factory.factory(proxyInfo);
      }
      
      public void testTypes() throws Exception {
          assertTrue(proxy instanceof MockEndPoint);
          assertTrue(proxy instanceof EndPointProxy);
      }
  
      public void testInvoke() throws Exception {
          MockEndPoint actual = new MockEndPointImpl(new MockNode(), "", targets);
          
          MsgOutInterceptor out =
              new HeaderOutInterceptor(
                  MsgHeaderConstants.SRC_NODE, "",
                  new HeaderOutInterceptor(
                      MsgHeaderConstants.SRC_ENDPOINT, "",
                      actual.getMsgConsumerOut()));
          factory.setMsgProducerOut(out);
  
          out =
              new HeaderOutInterceptor(
                  MsgHeaderConstants.SRC_NODE, "",
                  new HeaderOutInterceptor(
                      MsgHeaderConstants.SRC_ENDPOINT, "",
                      factory.getMsgConsumerOut()));
          actual.setMsgProducerOut(out);
          
          MockEndPoint endPoint = (MockEndPoint) proxy;
          Object opaque = new Object();
          endPoint.sendRawObject(opaque);
          List received = actual.getReceived();
          assertEquals(1, received.size());
          assertEquals(opaque, ((Request)received.get(0)).getParameters()[0]);
      }
  
      public void testRelease() throws Exception {
          factory.releaseProxy(proxy);
          try {
              ((MockEndPoint) proxy).sendRawObject(null);
              fail("Proxy has been released. Can not use anymore.");
          } catch (IllegalStateException e1) {
          }
          
          try {
              factory.releaseProxy(new Object());
              fail("Not a proxy.");
          } catch (IllegalArgumentException e) {
          }
      }
      
  }
  
  
  
  1.2       +25 -13    incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/replication/ReplicationMemberImpl.java
  
  Index: ReplicationMemberImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/replication/ReplicationMemberImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReplicationMemberImpl.java	11 May 2004 12:06:40 -0000	1.1
  +++ ReplicationMemberImpl.java	20 May 2004 13:37:11 -0000	1.2
  @@ -26,6 +26,8 @@
   import java.util.Map;
   
   import net.sf.cglib.proxy.Callback;
  +import net.sf.cglib.proxy.Enhancer;
  +import net.sf.cglib.proxy.LazyLoader;
   import net.sf.cglib.proxy.MethodInterceptor;
   
   import org.apache.geronimo.gbean.GAttributeInfo;
  @@ -37,8 +39,8 @@
   import org.apache.geronimo.messaging.Node;
   import org.apache.geronimo.messaging.NodeInfo;
   import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
  -import org.apache.geronimo.messaging.util.EndPointCallback;
  -import org.apache.geronimo.messaging.util.ProxyFactory;
  +import org.apache.geronimo.messaging.proxy.EndPointCallback;
  +import org.apache.geronimo.messaging.proxy.HOPPFilter;
   
   /**
    * ReplicationMember implementation.
  @@ -63,7 +65,7 @@
       /**
        * EndPointCallback used under the cover by otherMembers.
        */
  -    private final EndPointCallback endPointCallback;
  +    private final EndPointCallback endPointCB;
       
       /**
        * Creates a replication group member.
  @@ -82,14 +84,24 @@
           
           idToReplicant = new HashMap();
           
  -        endPointCallback = new EndPointCallback(sender);
  -        endPointCallback.setEndPointId(anID);
  -        endPointCallback.setTargets(aTargetNodes);
  -        ProxyFactory factory =
  -            new ProxyFactory(new Class[] {ReplicationMember.class},
  -                new Callback[] {endPointCallback},
  -                new Class[] {MethodInterceptor.class}, null);
  -        otherMembers = (ReplicationMember) factory.getProxy();
  +        endPointCB = new EndPointCallback(sender);
  +        endPointCB.setEndPointId(anID);
  +        endPointCB.setTargets(aTargetNodes);
  +        
  +        Class[] interfaces = new Class[] {ReplicationMember.class};
  +        Enhancer enhancer = new Enhancer();
  +        enhancer.setInterfaces(interfaces);
  +        enhancer.setCallbackTypes(
  +            new Class[] {MethodInterceptor.class, LazyLoader.class});
  +        enhancer.setUseFactory(false);
  +        enhancer.setCallbacks(new Callback[] {endPointCB,
  +            new LazyLoader() {
  +                public Object loadObject() throws Exception {
  +                    throw new UnsupportedOperationException("Empty local half.");
  +                }
  +            }});
  +        enhancer.setCallbackFilter(new HOPPFilter(interfaces));
  +        otherMembers = (ReplicationMember) enhancer.create();
       }
       
       public Object getReplicationGroupID() {
  @@ -98,7 +110,7 @@
       
       public void setMsgProducerOut(MsgOutInterceptor aMsgOut) {
           super.setMsgProducerOut(aMsgOut);
  -        endPointCallback.setOut(out);
  +        endPointCB.setOut(out);
       }
       
       public void fireUpdateEvent(UpdateEvent anEvent)
  
  
  
  1.2       +9 -1      incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/MockNode.java
  
  Index: MockNode.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/MockNode.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MockNode.java	11 May 2004 12:06:41 -0000	1.1
  +++ MockNode.java	20 May 2004 13:37:11 -0000	1.2
  @@ -21,6 +21,7 @@
   import org.apache.geronimo.gbean.WaitingException;
   import org.apache.geronimo.messaging.io.NullReplacerResolver;
   import org.apache.geronimo.messaging.io.ReplacerResolver;
  +import org.apache.geronimo.messaging.proxy.EndPointProxyInfo;
   
   /**
    *
  @@ -69,6 +70,13 @@
       }
   
       public void doFail() {
  +    }
  +
  +    public Object factoryEndPointProxy(EndPointProxyInfo anInfo) {
  +        return null;
  +    }
  +
  +    public void releaseEndPointProxy(Object aProxy) {
       }
   
   }
  
  
  
  1.6       +7 -3      incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/RemoteUseCaseTest.java
  
  Index: RemoteUseCaseTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote/RemoteUseCaseTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- RemoteUseCaseTest.java	11 May 2004 12:24:59 -0000	1.5
  +++ RemoteUseCaseTest.java	20 May 2004 13:37:11 -0000	1.6
  @@ -33,6 +33,7 @@
   import org.apache.geronimo.messaging.NodeTopology.PathWeight;
   import org.apache.geronimo.messaging.remotenode.MessagingTransportFactory;
   import org.apache.geronimo.messaging.remotenode.network.NetworkTransportFactory;
  +import org.apache.geronimo.messaging.proxy.EndPointProxyInfo;
   import org.apache.geronimo.network.SelectorManager;
   import org.apache.geronimo.system.ClockPool;
   import org.apache.geronimo.system.ThreadPool;
  @@ -87,9 +88,12 @@
           ctx2.init("Node2");
           ctx2.start();
           node2 = new NodeImpl(nodeInfo2, ctx2.tp, ctx2.factoryTransport());
  -        fileManager = new GFileManagerClient(node2, fileSystem, nodeInfo1);
  +        EndPointProxyInfo proxyInfo =
  +            new EndPointProxyInfo(fileSystem,
  +                new Class[] {GFileManager.class},
  +                new NodeInfo[] {nodeInfo1});
  +        fileManager = (GFileManager) node2.factoryEndPointProxy(proxyInfo);
           node2.doStart();
  -        fileManager.doStart();
           node2.join(nodeInfo1);
           
           NodeTopology topology = new NodeTopology();
  
  
  
  1.2       +24 -48    incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/reference/ReferenceFactory.java
  
  Index: ReferenceFactory.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/reference/ReferenceFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ReferenceFactory.java	11 May 2004 12:06:42 -0000	1.1
  +++ ReferenceFactory.java	20 May 2004 13:37:11 -0000	1.2
  @@ -17,18 +17,16 @@
   
   package org.apache.geronimo.messaging.reference;
   
  -import java.lang.reflect.Method;
  -
   import net.sf.cglib.proxy.Callback;
  -import net.sf.cglib.proxy.CallbackFilter;
  +import net.sf.cglib.proxy.Enhancer;
  +import net.sf.cglib.proxy.LazyLoader;
   import net.sf.cglib.proxy.MethodInterceptor;
  -import net.sf.cglib.proxy.MethodProxy;
   
   import org.apache.geronimo.messaging.NodeInfo;
   import org.apache.geronimo.messaging.RequestSender;
   import org.apache.geronimo.messaging.interceptors.MsgOutInterceptor;
  -import org.apache.geronimo.messaging.util.EndPointCallback;
  -import org.apache.geronimo.messaging.util.ProxyFactory;
  +import org.apache.geronimo.messaging.proxy.EndPointCallback;
  +import org.apache.geronimo.messaging.proxy.HOPPFilter;
   
   /**
    * Factory of Referenceable proxies.
  @@ -75,12 +73,11 @@
        * @param aReferenceInfo Referenceable meta-data.
        * @return A Referenceable proxy.
        */
  -    public Object factory(ReferenceableInfo aReferenceInfo) {
  -        EndPointCallback endPointCallback = new EndPointCallback(sender);
  -        endPointCallback.setEndPointId(aReferenceInfo.getID());
  -        endPointCallback.setOut(out);
  -        endPointCallback.setTargets(
  -            new NodeInfo[] {aReferenceInfo.getHostingNode()});
  +    public Object factory(final ReferenceableInfo aReferenceInfo) {
  +        EndPointCallback endPointCB = new EndPointCallback(sender);
  +        endPointCB.setEndPointId(aReferenceInfo.getID());
  +        endPointCB.setOut(out);
  +        endPointCB.setTargets(new NodeInfo[] {aReferenceInfo.getHostingNode()});
   
           Class[] refIntfs = aReferenceInfo.getRefClass();
           // Automatically adds the Reference interface to this array of
  @@ -91,20 +88,25 @@
           }
           interfaces[interfaces.length - 1] = Reference.class;
           
  -        HalfObjectLocal halfObjLocal = new HalfObjectLocal(aReferenceInfo);
  -        ProxyFactory factory =
  -            new ProxyFactory(interfaces,
  -                new Callback[] {endPointCallback, halfObjLocal},
  -                new Class[] {MethodInterceptor.class, MethodInterceptor.class},
  -                new HOPPFilter(refIntfs));
  -        return factory.getProxy();
  +        Enhancer enhancer = new Enhancer();
  +        enhancer.setInterfaces(interfaces);
  +        enhancer.setCallbackTypes(
  +            new Class[] {MethodInterceptor.class, LazyLoader.class});
  +        enhancer.setUseFactory(false);
  +        enhancer.setCallbacks(new Callback[] {endPointCB,
  +            new LazyLoader() {
  +                public Object loadObject() throws Exception {
  +                    return new HalfObjectLocal(aReferenceInfo);
  +                }
  +            }});
  +        enhancer.setCallbackFilter(new HOPPFilter(refIntfs));
  +        return enhancer.create();
       }
       
       /**
        * Implements the local half of a Referenceable proxy. 
        */
  -    private static class HalfObjectLocal
  -        implements Reference, MethodInterceptor {
  +    private static class HalfObjectLocal implements Reference {
           private ReferenceableInfo referenceInfo;
           private HalfObjectLocal(ReferenceableInfo aReferenceInfo) {
               referenceInfo = aReferenceInfo;
  @@ -118,32 +120,6 @@
           }
           public ReferenceableInfo getReferenceableInfo() {
               return referenceInfo;
  -        }
  -        public Object intercept(Object arg0, Method arg1, Object[] arg2,
  -            MethodProxy arg3) throws Throwable {
  -            return arg3.invoke(this, arg2);
  -        }
  -    }
  -    
  -    /**
  -     * Maps the methods defined by the Referenceable interfaces to the first
  -     * Callback of a ProxyFactory.
  -     * <BR>
  -     * The other methods are mapped to the second one.
  -     */
  -    private class HOPPFilter implements CallbackFilter {
  -        private final Class[] interfaces;
  -        private HOPPFilter(Class[] anInterfaces) {
  -            interfaces = anInterfaces;
  -        }
  -        public int accept(Method arg0) {
  -            Class declaringClass = arg0.getDeclaringClass(); 
  -            for (int i = 0; i < interfaces.length; i++) {
  -                if ( interfaces[i].equals(declaringClass) ) {
  -                    return 0;
  -                }
  -            }
  -            return 1;  
           }
       }
       
  
  
  

Mime
View raw message