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/webdav/src/java/org/apache/geronimo/datastore GFileManager.java
Date Wed, 03 Mar 2004 13:10:07 GMT
gdamour     2004/03/03 05:10:07

  Modified:    sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore
                        GFileStub.java GFileManagerClient.java
                        GFileManagerProxy.java
               sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging
                        ServerNode.java StreamManagerImpl.java
                        StreamOutputStream.java ServerProcessors.java
                        RequestSender.java StreamInputStream.java
                        HeaderReactor.java MetaConnection.java
               sandbox/webdav/src/test/org/apache/geronimo/datastore/impl/remote
                        RemoteUseCaseTest.java
               sandbox/webdav/src/java/org/apache/geronimo/datastore/impl
                        AbstractGFileManager.java
               sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/local
                        LocalGFileManager.java
               sandbox/webdav/src/java/org/apache/geronimo/datastore
                        GFileManager.java
  Added:       sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging
                        CommandResult.java CommandRequest.java
  Removed:     sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore
                        GFileCommand.java CommandResult.java
                        ProxyCommand.java CommandWithProxy.java
  Log:
  A round of refactoring:
  
  o ServerNode contains now a ThreadedServer and does not extend it
  anymore;
  o Only two classes, CommandRequest and CommandResult, are used to
  pass around an invokation on a remote object and its result;
  o InputStreams are now replaced automatically during serialization
  and deserialization; and
  o GBean have been GBeanified (they provide the required GBeanInfo).
  
  Revision  Changes    Path
  1.2       +29 -35    incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileStub.java
  
  Index: GFileStub.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileStub.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GFileStub.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ GFileStub.java	3 Mar 2004 13:10:06 -0000	1.2
  @@ -27,6 +27,7 @@
   
   
   import org.apache.geronimo.datastore.GFile;
  +import org.apache.geronimo.datastore.impl.remote.messaging.CommandRequest;
   import org.apache.geronimo.datastore.impl.remote.messaging.GInputStream;
   import org.apache.geronimo.datastore.impl.remote.messaging.StreamInputStream;
   import org.apache.geronimo.datastore.impl.remote.messaging.StreamOutputStream;
  @@ -113,26 +114,26 @@
   
       public boolean exists() throws IOException {
           return ((Boolean)
  -            client.sendSyncRequest(
  -                new GFileCommand(id, "exists", null))).booleanValue();
  +            client.sendGFileRequest(this,
  +                new CommandRequest("exists", null))).booleanValue();
       }
   
       public boolean isDirectory() throws IOException {
           return ((Boolean)
  -            client.sendSyncRequest(
  -                new GFileCommand(id, "isDirectory", null))).booleanValue();
  +            client.sendGFileRequest(this,
  +                new CommandRequest("isDirectory", null))).booleanValue();
       }
   
       public boolean isFile() throws IOException {
           return ((Boolean)
  -            client.sendSyncRequest(
  -                new GFileCommand(id, "isFile", null))).booleanValue();
  +            client.sendGFileRequest(this,
  +                new CommandRequest("isFile", null))).booleanValue();
       }
   
       public String[] listFiles() throws IOException {
           return (String[])
  -            client.sendSyncRequest(
  -                new GFileCommand(id, "listFiles", null));
  +            client.sendGFileRequest(this,
  +                new CommandRequest("listFiles", null));
       }
   
       public void lock() throws IOException {
  @@ -143,43 +144,43 @@
   
       public Map getProperties() throws IOException {
           return (Map)
  -            client.sendSyncRequest(
  -                new GFileCommand(id, "getProperties", null));
  +            client.sendGFileRequest(this,
  +                new CommandRequest("getProperties", null));
       }
   
       public void setContent(InputStream anIn) {
  -        client.sendSyncRequest(
  -                new GFileCommand(id, "setContent",
  +        client.sendGFileRequest(this,
  +                new CommandRequest("setContent",
                       new Object[]{new GInputStream(anIn)}));
       }
   
       public InputStream getContent() {
  -        return (InputStream) client.sendSyncRequest(
  -                new GFileCommand(id, "getContent", null));
  +        return (InputStream) client.sendGFileRequest(this, 
  +                new CommandRequest("getContent", null));
       }
   
       public InputStream getInputStream() throws IOException {
  -        return (InputStream) client.sendSyncRequest(
  -                new GFileCommand(id, "getInputStream", null));
  +        return (InputStream) client.sendGFileRequest(this,
  +                new CommandRequest("getInputStream", null));
       }
   
       public Map getPropertiesByName(Collection aCollOfNames) throws IOException {
           return (Map)
  -            client.sendSyncRequest(
  -                new GFileCommand(id, "getPropertiesByName",
  -                new Object[] {aCollOfNames}));
  +            client.sendGFileRequest(this,
  +                new CommandRequest("getPropertiesByName",
  +                    new Object[] {aCollOfNames}));
       }
   
       public void addProperty(String aName, String aValue) throws IOException {
  -        client.sendSyncRequest(
  -            new GFileCommand(id, "addProperty",
  -            new Object[] {aName, aValue}));
  +        client.sendGFileRequest(this,
  +            new CommandRequest("addProperty",
  +                new Object[] {aName, aValue}));
       }
   
       public void removeProperty(String aName) throws IOException {
  -        client.sendSyncRequest(
  -            new GFileCommand(id, "removeProperty",
  -            new Object[] {aName}));
  +        client.sendGFileRequest(this,
  +            new CommandRequest("removeProperty",
  +                new Object[] {aName}));
       }
   
       /**
  @@ -188,15 +189,12 @@
        * ObjectOutput.
        */
       public void writeExternal(ObjectOutput out) throws IOException {
  -        if ( !(out instanceof StreamOutputStream.CustomObjectOutputStream) ) {
  -            throw new IOException("Must be serialized by a StreamOutputStream.");
  -        }
           StreamOutputStream.CustomObjectOutputStream objOut =
               (StreamOutputStream.CustomObjectOutputStream) out;
           objOut.writeObject(id);
           objOut.writeUTF(path);
           objOut.writeObject(properties);
  -        objOut.writeObject(new GInputStream(content));
  +        objOut.writeObject(content);
       }
   
       /**
  @@ -204,16 +202,12 @@
        */
       public void readExternal(ObjectInput in) throws IOException,
           ClassNotFoundException {
  -        if ( !(in instanceof StreamInputStream.CustomObjectInputStream) ) {
  -            throw new IOException("Must be deserialized by a StreamInputStream.");
  -        }
           StreamInputStream.CustomObjectInputStream objIn =
               (StreamInputStream.CustomObjectInputStream) in;
           id = (Integer) objIn.readObject();
           path = objIn.readUTF();
           properties = (Map) objIn.readObject();
  -        GInputStream stream = (GInputStream) objIn.readObject();
  -        content = stream.getRawInputStream();
  +        content = (InputStream) objIn.readObject();
       }
       
   }
  
  
  
  1.3       +50 -10    incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerClient.java
  
  Index: GFileManagerClient.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerClient.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GFileManagerClient.java	1 Mar 2004 13:20:18 -0000	1.2
  +++ GFileManagerClient.java	3 Mar 2004 13:10:06 -0000	1.3
  @@ -22,6 +22,8 @@
   import org.apache.geronimo.datastore.GFile;
   import org.apache.geronimo.datastore.GFileManager;
   import org.apache.geronimo.datastore.GFileManagerException;
  +import org.apache.geronimo.datastore.impl.remote.messaging.CommandRequest;
  +import org.apache.geronimo.datastore.impl.remote.messaging.CommandResult;
   import org.apache.geronimo.datastore.impl.remote.messaging.Connector;
   import org.apache.geronimo.datastore.impl.remote.messaging.HeaderOutInterceptor;
   import org.apache.geronimo.datastore.impl.remote.messaging.Msg;
  @@ -32,6 +34,8 @@
   import org.apache.geronimo.datastore.impl.remote.messaging.RequestSender;
   import org.apache.geronimo.gbean.GBean;
   import org.apache.geronimo.gbean.GBeanContext;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.WaitingException;
   
   /**
  @@ -45,7 +49,7 @@
       private static final Log log = LogFactory.getLog(GFileManagerClient.class);
   
       /**
  -     * Name of the proxy to be mirrorer. 
  +     * Name of the proxy to be mirrored. 
        */
       private final String name;
       
  @@ -93,34 +97,34 @@
       }
       
       public void start() {
  -        sender.sendSyncRequest(new ProxyCommand("start", null), out);
  +        sender.sendSyncRequest(new CommandRequest("start", null), out);
       }
   
       public GFile factoryGFile(String aPath) {
           GFileStub result = (GFileStub)
               sender.sendSyncRequest(
  -                new ProxyCommand("factoryGFile", new Object[] {aPath}), out);
  +                new CommandRequest("factoryGFile", new Object[] {aPath}), out);
           result.setGFileManagerClient(this);
           return result;
       }
       
       public void persistNew(GFile aFile) {
           sender.sendSyncRequest(
  -            new ProxyCommand("persistNew", new Object[] {aFile}), out);
  +            new CommandRequest("persistNew", new Object[] {aFile}), out);
       }
   
       public void persistUpdate(GFile aFile) {
           sender.sendSyncRequest(
  -            new ProxyCommand("persistUpdate", new Object[] {aFile}), out);
  +            new CommandRequest("persistUpdate", new Object[] {aFile}), out);
       }
   
       public void persistDelete(GFile aFile) {
           sender.sendSyncRequest(
  -            new ProxyCommand("persistDelete", new Object[] {aFile}), out);
  +            new CommandRequest("persistDelete", new Object[] {aFile}), out);
       }
   
       public void end() throws GFileManagerException {
  -        sender.sendSyncRequest(new ProxyCommand("end", null), out);
  +        sender.sendSyncRequest(new CommandRequest("end", null), out);
       }
       
       public void setGBeanContext(GBeanContext aContext) {
  @@ -160,8 +164,44 @@
               header.getHeader(MsgHeaderConstants.CORRELATION_ID), result);
       }
       
  -    protected Object sendSyncRequest(Object anOpaque) {
  -        return sender.sendSyncRequest(anOpaque, out);
  +    /**
  +     * Used by GFileStubs to send request to their corresponding GFile on the
  +     * proxy side.
  +     * 
  +     * @param aStub GFileStub sending the request.
  +     * @param aRequest Request.
  +     * @return Request result.
  +     */
  +    protected Object sendGFileRequest(GFileStub aStub, CommandRequest aRequest) {
  +        CommandResult result = (CommandResult) 
  +            sender.sendSyncRequest(new CommandRequest("executeOnGFile",
  +                new Object[] {aStub.getID(), aRequest}), out);
  +        if ( result.isSuccess() ) {
  +            return result.getResult();
  +        }
  +        throw new RuntimeException(result.getException());
  +    }
  +    
  +    public static final GBeanInfo GBEAN_INFO;
  +
  +    static {
  +        GBeanInfoFactory factory = new GBeanInfoFactory(GFileManagerClient.class);
  +        factory.setConstructor(
  +            new String[] {"Name", "NodeName"},
  +            new Class[] {String.class, String.class});
  +        factory.addAttribute("Name", true);
  +        factory.addAttribute("NodeName", true);
  +        factory.addOperation("start");
  +        factory.addOperation("factoryGFile", new Class[]{String.class});
  +        factory.addOperation("persistNew", new Class[]{GFile.class});
  +        factory.addOperation("persistUpdate", new Class[]{GFile.class});
  +        factory.addOperation("persistDelete", new Class[]{GFile.class});
  +        factory.addOperation("end");
  +        GBEAN_INFO = factory.getBeanInfo();
  +    }
  +
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
       }
       
   }
  
  
  
  1.2       +40 -8     incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerProxy.java
  
  Index: GFileManagerProxy.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/datastore/GFileManagerProxy.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GFileManagerProxy.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ GFileManagerProxy.java	3 Mar 2004 13:10:06 -0000	1.2
  @@ -25,7 +25,8 @@
   import org.apache.geronimo.datastore.GFile;
   import org.apache.geronimo.datastore.GFileManager;
   import org.apache.geronimo.datastore.GFileManagerException;
  -import org.apache.geronimo.datastore.impl.AbstractGFileManager;
  +import org.apache.geronimo.datastore.impl.remote.messaging.CommandRequest;
  +import org.apache.geronimo.datastore.impl.remote.messaging.CommandResult;
   import org.apache.geronimo.datastore.impl.remote.messaging.Connector;
   import org.apache.geronimo.datastore.impl.remote.messaging.HeaderOutInterceptor;
   import org.apache.geronimo.datastore.impl.remote.messaging.Msg;
  @@ -35,6 +36,8 @@
   import org.apache.geronimo.datastore.impl.remote.messaging.MsgOutInterceptor;
   import org.apache.geronimo.gbean.GBean;
   import org.apache.geronimo.gbean.GBeanContext;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.WaitingException;
   
   /**
  @@ -57,7 +60,7 @@
       /**
        * Proxied GFileManager.
        */
  -    private final AbstractGFileManager fileManager;
  +    private final GFileManager fileManager;
   
       /**
        * Output to be used by the proxy to communicate with the clients mirroring
  @@ -78,8 +81,7 @@
        * @param aFileManager GFileManager to be proxied by this instance.
        */
       public GFileManagerProxy(GFileManager aFileManager) {
  -        // TODO refactor to avoid a cast.
  -        fileManager = (AbstractGFileManager) aFileManager;
  +        fileManager = aFileManager;
           gFiles = new HashMap();
           gFileSeq = 0;
       }
  @@ -132,11 +134,25 @@
       public void end() throws GFileManagerException {
           fileManager.end();
       }
  -
  +    
       public void setOutput(MsgOutInterceptor anOut) {
           out = anOut;
       }
       
  +    /**
  +     * Execute a request on the GFile identified by anID.
  +     * 
  +     * @param anID GFile identifier.
  +     * @param aRequest Request to be executed against the GFile identified by
  +     * anID.
  +     * @return Request result. 
  +     */
  +    public CommandResult executeOnGFile(Integer anID, CommandRequest aRequest) {
  +        GFile gFile = retrieveGFile(anID);
  +        aRequest.setTarget(gFile);
  +        return aRequest.execute();
  +    }
  +    
       public void deliver(Msg aMsg) {
           MsgHeader header = aMsg.getHeader();
           MsgBody body = aMsg.getBody();
  @@ -144,9 +160,9 @@
           Object id = header.getHeader(MsgHeaderConstants.CORRELATION_ID);
           Object node = header.getHeader(MsgHeaderConstants.SRC_NODE);
   
  -        CommandWithProxy command = (CommandWithProxy) body.getContent();
  +        CommandRequest command = (CommandRequest) body.getContent();
   
  -        command.setProxyGFileManager(this);
  +        command.setTarget(this);
           
           CommandResult result = command.execute();
           Msg msg = new Msg();
  @@ -197,6 +213,22 @@
                   "} is not registered.");
           }
           return gFile;
  +    }
  +    
  +    public static final GBeanInfo GBEAN_INFO;
  +
  +    static {
  +        GBeanInfoFactory factory = new GBeanInfoFactory(GFileManagerProxy.class);
  +        factory.setConstructor(
  +            new String[] {"Client"},
  +            new Class[] {GFileManager.class});
  +        factory.addReference("Client", GFileManager.class);
  +        factory.addAttribute("Name", true);
  +        GBEAN_INFO = factory.getBeanInfo();
  +    }
  +
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
       }
       
   }
  
  
  
  1.3       +94 -55    incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/ServerNode.java
  
  Index: ServerNode.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/ServerNode.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServerNode.java	1 Mar 2004 13:16:35 -0000	1.2
  +++ ServerNode.java	3 Mar 2004 13:10:07 -0000	1.3
  @@ -29,6 +29,8 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.gbean.GBean;
   import org.apache.geronimo.gbean.GBeanContext;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.WaitingException;
   import org.mortbay.util.ThreadedServer;
   
  @@ -52,10 +54,9 @@
    * @version $Revision$ $Date$
    */
   public class ServerNode
  -    extends ThreadedServer
       implements GBean
   {
  -    
  +
       private static final Log log = LogFactory.getLog(ServerNode.class);
   
       /**
  @@ -74,6 +75,11 @@
       private final StreamManager streamManager;
       
       /**
  +     * Server listening for connections to be made.
  +     */
  +    private final InternalServer server;
  +    
  +    /**
        * Inbound Msg queue. This queue is filled by Msgs coming directly
        * from the network connections.
        */
  @@ -112,30 +118,22 @@
       /**
        * Creates a server.
        * 
  -     * @param aName Name of this server.
  +     * @param aNodeInfo NodeInfo identifying uniquely this node on the network.
        * @param aCollOfConnectors Collection of Connectors to be registered by 
        * this server.
  -     * @param anAddress Listening address of this server.
  -     * @param aPort Listening port of this server.
  -     * @param aMaxRequest Maximum number of concurrent requests, which can be
  -     * processed by this server.
  -     */
  -    public ServerNode(NodeInfo aNodeInfo, Collection aCollOfConnectors,
  -        int aMaxRequest) {
  -        super(aNodeInfo.getAddress(), aNodeInfo.getPort());
  -        
  +     */
  +    public ServerNode(NodeInfo aNodeInfo, Collection aCollOfConnectors) {
           nodeInfo = aNodeInfo;
  -        metaConnection = new MetaConnection(this);
  +        server = new InternalServer();
           
  -        // No socket timeout.
  -        setMaxIdleTimeMs(0);
  +        metaConnection = new MetaConnection(this);
           
  -        streamManager = new StreamManagerImpl(getName());
  +        streamManager = new StreamManagerImpl(nodeInfo.getName());
           
           processors = new ServerProcessors(this);
           
  -        queueIn = new MsgQueue(getName() + " Inbound");
  -        queueOut = new MsgQueue(getName() + " Outbound");
  +        queueIn = new MsgQueue(nodeInfo.getName() + " Inbound");
  +        queueOut = new MsgQueue(nodeInfo.getName() + " Outbound");
           
           connections = new HashMap();
           
  @@ -152,8 +150,7 @@
               new HeaderOutInterceptor(
                   MsgHeaderConstants.SRC_CONNECTOR,
                   StreamManager.NAME,
  -                new QueueOutInterceptor(queueOut)
  -                ));
  +                new QueueOutInterceptor(queueOut)));
           
           connectors = new HashMap();
           // Registers the Connectors.
  @@ -165,13 +162,6 @@
       }
   
       /**
  -     * Gets the name of this node.
  -     */
  -    public String getName() {
  -        return nodeInfo.getName();
  -    }
  -    
  -    /**
        * Gets the NodeInfo of this node.
        * 
        * @return NodeInfo.
  @@ -221,7 +211,7 @@
        * @param aServantName Node name.
        * @return Output to be used to communicate with the specified node.
        */
  -    public MsgOutInterceptor getOutForNode(String aNodeName)
  +    protected MsgOutInterceptor getOutForNode(String aNodeName)
           throws CommunicationException {
           return metaConnection.getOutForNode(aNodeName);
       }
  @@ -231,7 +221,7 @@
        * 
        * @param aConnector Connector to be registered.
        */
  -    public void addConnector(Connector aConnector) {
  +    private void addConnector(Connector aConnector) {
           String pName = aConnector.getName();
           // Connectors write to the outbound Msg queue.
           aConnector.setOutput(
  @@ -251,7 +241,7 @@
        * 
        * @param aConnector Connector to be deregistered.
        */
  -    public void removeConnector(Connector aConnector) {
  +    private void removeConnector(Connector aConnector) {
           String pName = aConnector.getName();
           aConnector.setOutput(null);
           inReactor.unregister(pName);
  @@ -260,43 +250,22 @@
           }
       }
       
  -    /**
  -     * Handles a new connection.
  -     */
  -    protected void handleConnection(InputStream anIn,OutputStream anOut) {
  -        try {
  -            metaConnection.joined(anIn, anOut);
  -        } catch (IOException e) {
  -            log.error(e);
  -        } catch (CommunicationException e) {
  -            log.error(e);
  -        }
  -    }
  -    
       public void setGBeanContext(GBeanContext aContext) {
           context = aContext;
       }
   
       public void doStart() throws WaitingException, Exception {
  -        // Start the thread pool.
  -        start();
  -        
  +        server.start();
           processors.start();
       }
   
       public void doStop() throws WaitingException, Exception {
  -        stop();
  -        
  +        server.stop();
           processors.stop();
       }
   
       public void doFail() {
  -        try {
  -            stop();
  -        } catch (InterruptedException e) {
  -            log.error("Exception when stopping server", e);
  -        }
  -
  +        server.stop();
           processors.stop();
       }
       
  @@ -304,4 +273,74 @@
           return "Node {" + nodeInfo + "}";
       }
   
  +    /**
  +     * Socket server listening for connections to be made to this node.
  +     */
  +    private class InternalServer extends ThreadedServer {
  +        
  +        public InternalServer() {
  +            super(nodeInfo.getAddress(), nodeInfo.getPort());
  +            // No socket timeout.
  +            setMaxIdleTimeMs(0);
  +        }
  +        
  +        /**
  +         * Handles a new connection.
  +         */
  +        protected void handleConnection(InputStream anIn,OutputStream anOut) {
  +            try {
  +                metaConnection.joined(anIn, anOut);
  +            } catch (IOException e) {
  +                log.error(e);
  +            } catch (CommunicationException e) {
  +                log.error(e);
  +            }
  +        }
  +        
  +        public void start() {
  +            try {
  +                super.start();
  +            } catch (Exception e) {
  +                log.error(e);
  +                context.fail();
  +            }
  +        }
  +        
  +        public void stop() {
  +            try {
  +                super.stop();
  +            } catch (InterruptedException e) {
  +                log.error(e);
  +                context.fail();
  +            }
  +        }
  +        
  +        public void fail() {
  +            try {
  +                super.stop();
  +            } catch (InterruptedException e) {
  +                log.error(e);
  +            }
  +        }
  +    }
  +    
  +    public static final GBeanInfo GBEAN_INFO;
  +
  +    static {
  +        GBeanInfoFactory factory = new GBeanInfoFactory(ServerNode.class);
  +        factory.setConstructor(
  +            new String[] {"NodeInfo", "Connectors"},
  +            new Class[] {NodeInfo.class, Collection.class});
  +        factory.addAttribute("NodeInfo", true);
  +        factory.addReference("Connectors", Connector.class);
  +        factory.addAttribute("StreamManager", false);
  +        factory.addOperation("join", new Class[]{NodeInfo.class});
  +        factory.addOperation("leave", new Class[]{NodeInfo.class});
  +        GBEAN_INFO = factory.getBeanInfo();
  +    }
  +
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
  +    }
  +    
   }
  
  
  
  1.2       +8 -33     incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/StreamManagerImpl.java
  
  Index: StreamManagerImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/StreamManagerImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StreamManagerImpl.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ StreamManagerImpl.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -25,7 +25,6 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.geronimo.datastore.impl.remote.datastore.CommandResult;
   
   /**
    * StreamManager implementation.
  @@ -164,7 +163,9 @@
                           StreamManager.NAME,
                           out)));
           byte[] result = (byte[])
  -            sender.sendSyncRequest(new CommandWithStreamManager(anID), reqOut); 
  +            sender.sendSyncRequest(
  +                new CommandRequest("retrieveLocalNext", new Object[] {anID}),
  +                reqOut); 
           return result;
           
       }
  @@ -190,10 +191,10 @@
           MsgHeader header = aMsg.getHeader();
           Object sourceNode = header.getHeader(MsgHeaderConstants.SRC_NODE);
           Object id = header.getHeader(MsgHeaderConstants.CORRELATION_ID);
  -        CommandWithStreamManager command;
  +        CommandRequest command;
           String gateway;
  -        command = (CommandWithStreamManager) body.getContent();
  -        command.setStreamManager(this);
  +        command = (CommandRequest) body.getContent();
  +        command.setTarget(this);
           CommandResult result = command.execute();
           Msg msg = new Msg();
           body = msg.getBody();
  @@ -308,32 +309,6 @@
               return id.sequence == sequence &&
               managerName.equals(id.managerName) ;
           }
  -    }
  -
  -    public static class CommandWithStreamManager
  -        implements Serializable {
  -
  -        private final Object id;
  -        private byte[] content;
  -        private StreamManager streamManager;
  -
  -        public CommandWithStreamManager(Object anId) {
  -            id = anId;
  -        }
  -        
  -        public void setStreamManager(StreamManager aManager) {
  -            streamManager = aManager;
  -        }
  -        
  -        public CommandResult execute() {
  -            try {
  -                content = streamManager.retrieveLocalNext(id);
  -            } catch (IOException e) {
  -                return new CommandResult(false, e);
  -            }
  -            return new CommandResult(true, content);
  -        }
  -        
       }
       
   }
  
  
  
  1.2       +9 -1      incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/StreamOutputStream.java
  
  Index: StreamOutputStream.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/StreamOutputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StreamOutputStream.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ StreamOutputStream.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -66,10 +66,18 @@
   
           public CustomObjectOutputStream() throws IOException, SecurityException {
               super(StreamOutputStream.this);
  +            enableReplaceObject(true);
           }
   
           public void writeStream(InputStream aStream) throws IOException {
               StreamOutputStream.this.writeStream(aStream);
  +        }
  +        
  +        protected Object replaceObject(Object obj) throws IOException {
  +            if ( obj instanceof InputStream ) {
  +                return new GInputStream((InputStream) obj);
  +            }
  +            return obj;
           }
           
       }
  
  
  
  1.3       +2 -2      incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/ServerProcessors.java
  
  Index: ServerProcessors.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/ServerProcessors.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ServerProcessors.java	1 Mar 2004 13:16:35 -0000	1.2
  +++ ServerProcessors.java	3 Mar 2004 13:10:07 -0000	1.3
  @@ -52,7 +52,7 @@
        */
       public ServerProcessors(ServerNode aServer) {
           server = aServer;
  -        processors = new Processors(aServer.getName(), 2, 10);
  +        processors = new Processors(aServer.getNodeInfo().getName(), 2, 10);
           streamManager = aServer.getStreamManager();
       }
       
  
  
  
  1.2       +2 -3      incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/RequestSender.java
  
  Index: RequestSender.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/RequestSender.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RequestSender.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ RequestSender.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -23,7 +23,6 @@
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  -import org.apache.geronimo.datastore.impl.remote.datastore.CommandResult;
   
   import EDU.oswego.cs.dl.util.concurrent.FutureResult;
   import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
  @@ -76,7 +75,7 @@
           anOut.push(msg);
           
           CommandResult result = waitResponse(id, WAIT_RESPONSE);
  -        if ( !result.isSucess() ) {
  +        if ( !result.isSuccess() ) {
               throw new RuntimeException(result.getException());
           }
           return result.getResult();
  
  
  
  1.2       +8 -1      incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/StreamInputStream.java
  
  Index: StreamInputStream.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/StreamInputStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StreamInputStream.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ StreamInputStream.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -98,12 +98,19 @@
   
           public CustomObjectInputStream() throws IOException, SecurityException {
               super(StreamInputStream.this);
  +            enableResolveObject(true);
           }
           
           public InputStream readInputStream() throws IOException {
               return StreamInputStream.this.readInputStream();
           }
           
  +        protected Object resolveObject(Object obj) throws IOException {
  +            if ( obj instanceof GInputStream ) {
  +                return ((GInputStream)obj).getRawInputStream();
  +            }
  +            return obj;
  +        }
       }
       
   }
  
  
  
  1.2       +2 -2      incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/HeaderReactor.java
  
  Index: HeaderReactor.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/HeaderReactor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HeaderReactor.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ HeaderReactor.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -110,7 +110,7 @@
       /**
        * Dispatches Msgs to the relevant Connector.
        */
  -    public void dispatch() {
  +    private void dispatch() {
           final Msg msg = actualIn.pop();
           Object opaque = actualIn.getHeader();
           final Connector connector;
  
  
  
  1.2       +4 -4      incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/MetaConnection.java
  
  Index: MetaConnection.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/MetaConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MetaConnection.java	1 Mar 2004 13:16:35 -0000	1.1
  +++ MetaConnection.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -88,7 +88,7 @@
           
           if ( null == connection ) {
               throw new CommunicationException("Node {" + aNodeName +
  -                "} is not know by {" + node.getName() + "}");
  +                "} is not know by {" + node.getNodeInfo().getName() + "}");
           }
           
           return connection.out;
  @@ -272,7 +272,7 @@
               out =
                   new HeaderOutInterceptor(
                       MsgHeaderConstants.SRC_NODE,
  -                    node.getName(),
  +                    node.getNodeInfo().getName(),
                       new StreamOutInterceptor(rawOut, node.getStreamManager()));
               listener = new MsgCopier.NullCopierListener() {
                   public void onFailure() {
  @@ -301,7 +301,7 @@
               out =
                   new HeaderOutInterceptor(
                       MsgHeaderConstants.SRC_NODE,
  -                    node.getName(),
  +                    node.getNodeInfo().getName(),
                       new StreamOutInterceptor(rawOut, node.getStreamManager()));
               listener = new MsgCopier.NullCopierListener() {
                   public void onFailure() {
  
  
  
  1.1                  incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/CommandResult.java
  
  Index: CommandResult.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.datastore.impl.remote.messaging;
  
  import java.io.Serializable;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/03/03 13:10:07 $
   */
  public class CommandResult implements Serializable
  {
  
      private final boolean isSuccess;
      
      private final Object opaque;
      
      public CommandResult(boolean anIsSuccess, Object anOpaque) {
          isSuccess = anIsSuccess;
          if ( !isSuccess && !(anOpaque instanceof Exception) ) {
              throw new IllegalArgumentException(
                  "If failure, opaque must be an Exception");
          }
          opaque = anOpaque;
      }
      
      public boolean isSuccess() {
          return isSuccess;
      }
      
      public Exception getException() {
          return (Exception) opaque; 
      }
      
      public Object getResult() {
          return opaque;
      }
      
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/remote/messaging/CommandRequest.java
  
  Index: CommandRequest.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.datastore.impl.remote.messaging;
  
  import java.io.Serializable;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  
  import javax.naming.OperationNotSupportedException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/03/03 13:10:07 $
   */
  public class CommandRequest
      implements Serializable
  {
  
      private static final Log log = LogFactory.getLog(CommandRequest.class);
      
      private transient Object target;
      private final String methodName;
      private final Object[] parameters;
      
      public CommandRequest(String aMethodName, Object[] anArrOfParams) {
          methodName = aMethodName;
          parameters = anArrOfParams;
      }
      
      public void setTarget(Object aTarget) {
          target = aTarget;
      }
      
      public CommandResult execute() {
          Class clazz = target.getClass();
          Method[] methods = clazz.getMethods();
          for (int i = 0; i < methods.length; i++) {
              Method method = methods[i];
              if ( method.getName().equals(methodName) ) {
                  return invokeMethod(method);
              }
          }
          return new CommandResult(false,
              new OperationNotSupportedException("Method {" + methodName + 
                  "} does not exist."));
      }
      
      private CommandResult invokeMethod(Method aMethod) {
          CommandResult result;
          try {
              Object opaque = aMethod.invoke(target, parameters);
              return new CommandResult(true, opaque);
          } catch (IllegalArgumentException e) {
              return new CommandResult(false, e);
          } catch (IllegalAccessException e) {
              return new CommandResult(false, e);
          } catch (InvocationTargetException e) {
              return new CommandResult(false, e);
          }
      }
  
  }
  
  
  
  1.3       +8 -5      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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RemoteUseCaseTest.java	1 Mar 2004 13:16:36 -0000	1.2
  +++ RemoteUseCaseTest.java	3 Mar 2004 13:10:07 -0000	1.3
  @@ -21,7 +21,6 @@
   import java.net.InetAddress;
   import java.util.Collections;
   
  -
   import org.apache.geronimo.datastore.GFileManager;
   import org.apache.geronimo.datastore.Util;
   import org.apache.geronimo.datastore.impl.LockManager;
  @@ -31,6 +30,7 @@
   import org.apache.geronimo.datastore.impl.remote.datastore.GFileManagerProxy;
   import org.apache.geronimo.datastore.impl.remote.messaging.NodeInfo;
   import org.apache.geronimo.datastore.impl.remote.messaging.ServerNode;
  +import org.apache.geronimo.kernel.Kernel;
   
   /**
    * This is a remote use-case.
  @@ -39,32 +39,35 @@
    */
   public class RemoteUseCaseTest extends AbstractUseCaseTest {
   
  +    private Kernel kernel;
  +    
       /**
        * In this set-up one initializes two nodes, namely Node1 and Node2. A
        * local GFileManager is mounted by Node1. A client GFileManager is mounted
        * by Node2. Node2 joins Node1.
        */
       protected void setUp() throws Exception {
  -        LockManager lockManager = new LockManager();
           File root = new File(System.getProperty("java.io.tmpdir"),
                   "GFileManager");
           Util.recursiveDelete(root);
           root.mkdir();
           
  +        LockManager lockManager = new LockManager();
  +
           GFileManager delegate;
           delegate = new LocalGFileManager("test", root, lockManager);
           InetAddress address = InetAddress.getLocalHost();
           GFileManagerProxy proxy = new GFileManagerProxy(delegate);
           NodeInfo nodeInfo1 = new NodeInfo("Node1", address, 8080);
           ServerNode server1 = new ServerNode(nodeInfo1,
  -            Collections.singleton(proxy), 10);
  +            Collections.singleton(proxy));
           server1.doStart();
           proxy.doStart();
   
           fileManager = new GFileManagerClient("test", "Node1");
           NodeInfo nodeInfo2 = new NodeInfo("Node2", address, 8082);
           ServerNode server2 = new ServerNode(nodeInfo2,
  -            Collections.singleton(fileManager), 10);
  +            Collections.singleton(fileManager));
           server2.doStart();
           ((GFileManagerClient) fileManager).doStart();
           
  
  
  
  1.2       +34 -3     incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/AbstractGFileManager.java
  
  Index: AbstractGFileManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/AbstractGFileManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractGFileManager.java	25 Feb 2004 13:36:16 -0000	1.1
  +++ AbstractGFileManager.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -27,6 +27,10 @@
   import org.apache.geronimo.datastore.GFile;
   import org.apache.geronimo.datastore.GFileManager;
   import org.apache.geronimo.datastore.GFileManagerException;
  +import org.apache.geronimo.gbean.GBeanContext;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
  +import org.apache.geronimo.gbean.WaitingException;
   
   
   /**
  @@ -138,7 +142,7 @@
       public void end() throws GFileManagerException {
           checkState(true);
           try {
  -            doEnd();
  +            doInternalEnd();
           } finally {
               synchronized(stateManagers) {
                   stateManagers.clear();
  @@ -166,7 +170,7 @@
        * @throws GFileManagerException Indicates that a StateManager is not able
        * to flush its state.
        */
  -    private void doEnd() throws GFileManagerException {
  +    private void doInternalEnd() throws GFileManagerException {
           List flushedManagers = new ArrayList();
           try {
               // Prepare all the state to be flushed.
  @@ -237,4 +241,31 @@
           }
       }
   
  +    public void setGBeanContext(GBeanContext context) {}
  +
  +    public void doStart() throws WaitingException, Exception{}
  +
  +    public void doStop() throws WaitingException, Exception {}
  +
  +    public void doFail() {};
  +    
  +    public static final GBeanInfo GBEAN_INFO;
  +
  +    static {
  +        GBeanInfoFactory factory = new GBeanInfoFactory(AbstractGFileManager.class);
  +        factory.addAttribute("Name", true);
  +        factory.addAttribute("LockManager", true);
  +        factory.addOperation("start");
  +        factory.addOperation("factoryGFile", new Class[]{String.class});
  +        factory.addOperation("persistNew", new Class[]{GFile.class});
  +        factory.addOperation("persistUpdate", new Class[]{GFile.class});
  +        factory.addOperation("persistDelete", new Class[]{GFile.class});
  +        factory.addOperation("end");
  +        GBEAN_INFO = factory.getBeanInfo();
  +    }
  +
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
  +    }
  +    
   }
  
  
  
  1.2       +28 -1     incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/local/LocalGFileManager.java
  
  Index: LocalGFileManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/impl/local/LocalGFileManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalGFileManager.java	25 Feb 2004 13:36:15 -0000	1.1
  +++ LocalGFileManager.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -28,6 +28,8 @@
   import org.apache.geronimo.datastore.impl.DAOException;
   import org.apache.geronimo.datastore.impl.GFileDAO;
   import org.apache.geronimo.datastore.impl.LockManager;
  +import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
   
   /**
    * GFileManager using a LocalGFileDAO to interact with the data store.
  @@ -89,6 +91,15 @@
       public void writeRoot(Writer aWriter) throws IOException {
           aWriter.write(IDENTIFIER + ":");
       }
  +
  +    /**
  +     * Gets the root of this local filesystem manager.
  +     * 
  +     * @return Root. Path are resolved based on this root.
  +     */
  +    public File getRoot() {
  +        return root;
  +    }
       
       /**
        * Plug-in the LocalGFileDAO implementation.
  @@ -139,6 +150,22 @@
           FileWriter writer = new FileWriter(rootFile);
           writeRoot(writer);
           writer.close();
  +    }
  +
  +    public static final GBeanInfo GBEAN_INFO;
  +
  +    static {
  +        GBeanInfoFactory factory =
  +            new GBeanInfoFactory(LocalGFileManager.class.getName(), AbstractGFileManager.GBEAN_INFO);
  +        factory.setConstructor(
  +            new String[] {"Name", "Root", "LockManager"},
  +            new Class[] {String.class, File.class, LockManager.class});
  +        factory.addAttribute("Root", true);
  +        GBEAN_INFO = factory.getBeanInfo();
  +    }
  +
  +    public static GBeanInfo getGBeanInfo() {
  +        return GBEAN_INFO;
       }
       
   }
  
  
  
  1.2       +4 -2      incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/GFileManager.java
  
  Index: GFileManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/webdav/src/java/org/apache/geronimo/datastore/GFileManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GFileManager.java	25 Feb 2004 13:36:16 -0000	1.1
  +++ GFileManager.java	3 Mar 2004 13:10:07 -0000	1.2
  @@ -17,6 +17,8 @@
   
   package org.apache.geronimo.datastore;
   
  +import org.apache.geronimo.gbean.GBean;
  +
   /**
    * GFile manager. It allows to retrieve files from the data store and perform
    * CRUD operations against them in the context of a single interaction.
  @@ -25,7 +27,7 @@
    *
    * @version $Revision$ $Date$
    */
  -public interface GFileManager
  +public interface GFileManager extends GBean
   {
   
       /**
  
  
  

Mime
View raw message