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/test/org/apache/geronimo/messaging/admin/deployment MultiProgressObjectTest.java
Date Tue, 01 Jun 2004 12:44:22 GMT
gdamour     2004/06/01 05:44:22

  Modified:    sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment
                        AdminServer.java DeploymentReplacerResolver.java
  Added:       sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment
                        MultiProgressObject.java DeploymentStatusImpl.java
               sandbox/messaging/src/test/org/apache/geronimo/messaging/admin/deployment
                        MultiProgressObjectTest.java
  Log:
  o Refactor AdminServer: the nested Class MultiProgressObject is now
  a Class;
  o Implements the getDeploymentStatus of this latter;
  o Adds a serializable DeploymentStatus.
  
  Revision  Changes    Path
  1.3       +1 -56     incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/AdminServer.java
  
  Index: AdminServer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/AdminServer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AdminServer.java	27 May 2004 15:46:54 -0000	1.2
  +++ AdminServer.java	1 Jun 2004 12:44:22 -0000	1.3
  @@ -31,11 +31,7 @@
   import javax.enterprise.deploy.shared.ModuleType;
   import javax.enterprise.deploy.spi.Target;
   import javax.enterprise.deploy.spi.TargetModuleID;
  -import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
   import javax.enterprise.deploy.spi.exceptions.TargetException;
  -import javax.enterprise.deploy.spi.status.ClientConfiguration;
  -import javax.enterprise.deploy.spi.status.DeploymentStatus;
  -import javax.enterprise.deploy.spi.status.ProgressListener;
   import javax.enterprise.deploy.spi.status.ProgressObject;
   
   import org.apache.geronimo.deployment.ConfigurationBuilder;
  @@ -381,58 +377,7 @@
           }
           
       }
  -    
  -
  -    private static class MultiProgressObject implements ProgressObject {
  -
  -        private final Collection progressObjects = new ArrayList();        
  -
  -        private void consolidate() {
  -            
  -        }
  -        
  -        private void addProgressObject(ProgressObject aProgObject) {
  -            synchronized(progressObjects) {
  -                progressObjects.add(aProgObject);
  -            }
  -        }
  -
  -        public DeploymentStatus getDeploymentStatus() {
  -            return null;
  -        }
  -
  -        public TargetModuleID[] getResultTargetModuleIDs() {
  -            return null;
  -        }
  -
  -        public ClientConfiguration getClientConfiguration(TargetModuleID id) {
  -            return null;
  -        }
   
  -        public boolean isCancelSupported() {
  -            return false;
  -        }
  -
  -        public void cancel() throws OperationUnsupportedException {
  -            throw new OperationUnsupportedException("Not supported");
  -        }
  -
  -        public boolean isStopSupported() {
  -            return false;
  -        }
  -
  -        public void stop() throws OperationUnsupportedException {
  -            throw new OperationUnsupportedException("Not supported");
  -        }
  -
  -        public void addProgressListener(ProgressListener pol) {
  -        }
  -
  -        public void removeProgressListener(ProgressListener pol) {
  -        }
  -        
  -    }
  -    
       private static class ServerInfo {
           private DeploymentServer server;
           private Target target;
  
  
  
  1.2       +6 -1      incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/DeploymentReplacerResolver.java
  
  Index: DeploymentReplacerResolver.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/DeploymentReplacerResolver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DeploymentReplacerResolver.java	27 May 2004 14:45:59 -0000	1.1
  +++ DeploymentReplacerResolver.java	1 Jun 2004 12:44:22 -0000	1.2
  @@ -20,6 +20,7 @@
   import java.io.IOException;
   
   import javax.enterprise.deploy.shared.ModuleType;
  +import javax.enterprise.deploy.spi.status.DeploymentStatus;
   
   import org.apache.geronimo.deployment.plugin.TargetImpl;
   import org.apache.geronimo.messaging.io.AbstractReplacerResolver;
  @@ -37,6 +38,10 @@
               return new TargetImpl2((TargetImpl) obj);
           } else if ( obj instanceof ModuleType ) {
               return new ModuleTypeWrapper((ModuleType) obj);
  +        } else if ( obj instanceof DeploymentStatus ) {
  +            DeploymentStatus status = (DeploymentStatus) obj;
  +            return new DeploymentStatusImpl(status.getCommand(),
  +                status.getAction(), status.getState(), status.getMessage());
           }
           return null;
       }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/MultiProgressObject.java
  
  Index: MultiProgressObject.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.admin.deployment;
  
  import java.util.ArrayList;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Iterator;
  
  import javax.enterprise.deploy.shared.ActionType;
  import javax.enterprise.deploy.shared.CommandType;
  import javax.enterprise.deploy.shared.StateType;
  import javax.enterprise.deploy.spi.TargetModuleID;
  import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
  import javax.enterprise.deploy.spi.status.ClientConfiguration;
  import javax.enterprise.deploy.spi.status.DeploymentStatus;
  import javax.enterprise.deploy.spi.status.ProgressListener;
  import javax.enterprise.deploy.spi.status.ProgressObject;
  
  
  /**
   * A ProgressObject which consolidates multiple ProgressObjects.
   *
   * @version $Revision: 1.1 $ $Date: 2004/06/01 12:44:22 $
   */
  public class MultiProgressObject implements ProgressObject {
  
      /**
       * ProgressObjects to be consolidated.
       */
      private Collection progressObjects = new ArrayList();        
  
      /**
       * Consolidates the ProgressObject registered until now.
       * <BR>
       * ProgressObjects can no more be added.
       */
      public void consolidate() {
          progressObjects =
              Collections.unmodifiableCollection(progressObjects);
      }
  
      /**
       * Adds a ProgressObject. 
       * 
       * @param aProgObject Progress to be added.
       */
      public void addProgressObject(ProgressObject aProgObject) {
          synchronized(progressObjects) {
              progressObjects.add(aProgObject);
          }
      }
  
      /**
       * Gets the deployment status.
       * <BR>
       * If one of the contained ProgressObjects is failed, then the status is
       * considered as failed.<BR>
       * If the contained ProgressObjects are completed, then the status is
       * completed.<BR>
       * In all the other cases, the status is running.
       * 
       * @return Deployment status.
       */
      public DeploymentStatus getDeploymentStatus() {
          StringBuffer message = new StringBuffer();
          CommandType commandType = null;
          ActionType actionType = null;
          boolean completed = true;
          boolean failed = false;
          for (Iterator iter = progressObjects.iterator(); iter.hasNext();) {
              ProgressObject progress = (ProgressObject) iter.next();
              DeploymentStatus status = progress.getDeploymentStatus();
              CommandType curCommandType = status.getCommand();
              ActionType curActionType = status.getAction();
              if ( null == commandType ) {
                  commandType = curCommandType;
                  actionType = curActionType;
              } else if ( commandType != curCommandType ) {
                  throw new AssertionError("Heterogeneous CommandType");
              } else if ( actionType != curActionType ) {
                  throw new AssertionError("Heterogeneous ActionType");
              }
              message.append(status.getMessage() + "\n");
              if ( StateType.FAILED == status.getState() ) {
                  failed = true;
              } else if ( StateType.COMPLETED != status.getState() ) {
                  completed = false;
              }
              commandType = status.getCommand();
              actionType = status.getAction();
          }
          if ( failed ) {
              return new DeploymentStatusImpl(commandType, actionType,
                  StateType.FAILED, message.toString());
          } else if ( completed ) {
              return new DeploymentStatusImpl(commandType, actionType,
                  StateType.COMPLETED, message.toString());
          }
          return new DeploymentStatusImpl(commandType, actionType,
              StateType.RUNNING, message.toString());
      }
  
      public TargetModuleID[] getResultTargetModuleIDs() {
          return null;
      }
  
      public ClientConfiguration getClientConfiguration(TargetModuleID id) {
          return null;
      }
  
      public boolean isCancelSupported() {
          return false;
      }
  
      public void cancel() throws OperationUnsupportedException {
          throw new OperationUnsupportedException("Not supported");
      }
  
      public boolean isStopSupported() {
          return false;
      }
  
      public void stop() throws OperationUnsupportedException {
          throw new OperationUnsupportedException("Not supported");
      }
  
      public void addProgressListener(ProgressListener pol) {
      }
  
      public void removeProgressListener(ProgressListener pol) {
      }
      
  }
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/java/org/apache/geronimo/messaging/admin/deployment/DeploymentStatusImpl.java
  
  Index: DeploymentStatusImpl.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.admin.deployment;
  
  import java.io.Serializable;
  
  import javax.enterprise.deploy.shared.ActionType;
  import javax.enterprise.deploy.shared.CommandType;
  import javax.enterprise.deploy.shared.StateType;
  import javax.enterprise.deploy.spi.status.DeploymentStatus;
  
  /**
   * A Serializable DeploymentStatus implementation.
   *
   * @version $Revision: 1.1 $ $Date: 2004/06/01 12:44:22 $
   */
  public class DeploymentStatusImpl
      implements DeploymentStatus, Serializable
  {
  
      private final int commandType;
      private final int actionType;
      private final int stateType;
      private final String message;
      
      public DeploymentStatusImpl(CommandType aCommand, ActionType anAction,
          StateType aState, String aMessage) {
          if ( null == aCommand ) {
              throw new IllegalArgumentException("Command is required");
          } else if ( null == anAction ) {
              throw new IllegalArgumentException("Action is required");
          } else if ( null == aState ) {
              throw new IllegalArgumentException("State is required");
          }
          commandType = aCommand.getValue();
          actionType = anAction.getValue();
          stateType = aState.getValue();
          message = aMessage;
      }
      
      public StateType getState() {
          return StateType.getStateType(stateType);
      }
  
      public CommandType getCommand() {
          return CommandType.getCommandType(commandType);
      }
  
      public ActionType getAction() {
          return ActionType.getActionType(actionType);
      }
  
      public String getMessage() {
          return message;
      }
  
      public boolean isCompleted() {
          return StateType.COMPLETED == getState();
      }
  
      public boolean isFailed() {
          return StateType.FAILED == getState();
      }
  
      public boolean isRunning() {
          return StateType.RUNNING == getState();
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/sandbox/messaging/src/test/org/apache/geronimo/messaging/admin/deployment/MultiProgressObjectTest.java
  
  Index: MultiProgressObjectTest.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.admin.deployment;
  
  import javax.enterprise.deploy.shared.ActionType;
  import javax.enterprise.deploy.shared.CommandType;
  import javax.enterprise.deploy.shared.StateType;
  import javax.enterprise.deploy.spi.TargetModuleID;
  import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException;
  import javax.enterprise.deploy.spi.status.ClientConfiguration;
  import javax.enterprise.deploy.spi.status.DeploymentStatus;
  import javax.enterprise.deploy.spi.status.ProgressListener;
  import javax.enterprise.deploy.spi.status.ProgressObject;
  
  import junit.framework.TestCase;
  
  /**
   *
   * @version $Revision: 1.1 $ $Date: 2004/06/01 12:44:22 $
   */
  public class MultiProgressObjectTest extends TestCase
  {
  
      public void testGetDeploymentStatus1() throws Exception {
          MultiProgressObject progressObject = new MultiProgressObject();
          MockProgressObject mockProgressObject = new MockProgressObject();
          mockProgressObject.status =
              new DeploymentStatusImpl(CommandType.DISTRIBUTE,
                  ActionType.EXECUTE, StateType.RUNNING, null);
          progressObject.addProgressObject(mockProgressObject);
          mockProgressObject = new MockProgressObject();
          mockProgressObject.status =
              new DeploymentStatusImpl(CommandType.DISTRIBUTE,
                  ActionType.EXECUTE, StateType.RUNNING, null);
          progressObject.addProgressObject(mockProgressObject);
          progressObject.consolidate();
          DeploymentStatus status = progressObject.getDeploymentStatus();
          assertEquals(StateType.RUNNING, status.getState());
      }
  
      public void testGetDeploymentStatus2() throws Exception {
          MultiProgressObject progressObject = new MultiProgressObject();
          MockProgressObject mockProgressObject = new MockProgressObject();
          mockProgressObject.status =
              new DeploymentStatusImpl(CommandType.DISTRIBUTE,
                  ActionType.EXECUTE, StateType.RUNNING, null);
          progressObject.addProgressObject(mockProgressObject);
          mockProgressObject = new MockProgressObject();
          mockProgressObject.status =
              new DeploymentStatusImpl(CommandType.DISTRIBUTE,
                  ActionType.EXECUTE, StateType.FAILED, null);
          progressObject.addProgressObject(mockProgressObject);
          progressObject.consolidate();
          DeploymentStatus status = progressObject.getDeploymentStatus();
          assertEquals(StateType.FAILED, status.getState());
      }
      
      public void testGetDeploymentStatus3() throws Exception {
          MultiProgressObject progressObject = new MultiProgressObject();
          MockProgressObject mockProgressObject = new MockProgressObject();
          mockProgressObject.status =
              new DeploymentStatusImpl(CommandType.DISTRIBUTE,
                  ActionType.EXECUTE, StateType.COMPLETED, null);
          progressObject.addProgressObject(mockProgressObject);
          mockProgressObject = new MockProgressObject();
          mockProgressObject.status =
              new DeploymentStatusImpl(CommandType.DISTRIBUTE,
                  ActionType.EXECUTE, StateType.COMPLETED, null);
          progressObject.addProgressObject(mockProgressObject);
          progressObject.consolidate();
          DeploymentStatus status = progressObject.getDeploymentStatus();
          assertEquals(StateType.COMPLETED, status.getState());
      }
      
      private static class MockProgressObject implements ProgressObject {
          private DeploymentStatus status;
          public DeploymentStatus getDeploymentStatus() {
              return status;
          }
          public TargetModuleID[] getResultTargetModuleIDs() {
              return null;
          }
          public ClientConfiguration getClientConfiguration(TargetModuleID id) {
              return null;
          }
          public boolean isCancelSupported() {
              return false;
          }
          public void cancel() throws OperationUnsupportedException {
          }
          public boolean isStopSupported() {
              return false;
          }
          public void stop() throws OperationUnsupportedException {
          }
          public void addProgressListener(ProgressListener pol) {
          }
          public void removeProgressListener(ProgressListener pol) {
          }
      }
      
  }
  
  
  

Mime
View raw message