Coverage Report - org.mule.registry.impl.AbstractAssembly
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractAssembly
0%
0/70
0%
0/18
2.6
 
 1  
 /*
 2  
  * $Id: AbstractAssembly.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.registry.impl;
 12  
 
 13  
 import org.mule.registry.Assembly;
 14  
 import org.mule.registry.Registry;
 15  
 import org.mule.registry.RegistryDescriptor;
 16  
 import org.mule.registry.RegistryException;
 17  
 import org.mule.registry.Unit;
 18  
 import org.mule.util.FileUtils;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 public abstract class AbstractAssembly extends AbstractEntry implements Assembly
 26  
 {
 27  
 
 28  
     protected List units;
 29  
     protected boolean isTransient;
 30  
     protected RegistryDescriptor descriptor;
 31  
 
 32  
     protected AbstractAssembly(Registry registry)
 33  
     {
 34  0
         super(registry);
 35  0
         this.units = new ArrayList();
 36  0
     }
 37  
 
 38  
     public Unit getUnit(String name)
 39  
     {
 40  0
         for (Iterator it = this.units.iterator(); it.hasNext();)
 41  
         {
 42  0
             AbstractUnit u = (AbstractUnit)it.next();
 43  0
             if (u.getName().equals(name))
 44  
             {
 45  0
                 return u;
 46  
             }
 47  
         }
 48  0
         return null;
 49  
     }
 50  
 
 51  
     public void addUnit(Unit unit)
 52  
     {
 53  0
         this.units.add(unit);
 54  0
     }
 55  
 
 56  
     public void removeUnit(Unit unit)
 57  
     {
 58  0
         this.units.remove(unit);
 59  0
     }
 60  
 
 61  
     /*
 62  
      * (non-Javadoc)
 63  
      * 
 64  
      * @see org.mule.jbi.registry.Assembly#getUnits()
 65  
      */
 66  
     public Unit[] getUnits()
 67  
     {
 68  0
         Collection c = this.units;
 69  0
         return (Unit[])c.toArray(new Unit[c.size()]);
 70  
     }
 71  
 
 72  
     /*
 73  
      * (non-Javadoc)
 74  
      * 
 75  
      * @see org.mule.jbi.registry.mule.AbstractEntry#checkDescriptor()
 76  
      */
 77  
     protected void checkDescriptor() throws RegistryException
 78  
     {
 79  0
         super.checkDescriptor();
 80  
         // Check that it is a service assembly
 81  0
         if (!getDescriptor().isServiceAssembly())
 82  
         {
 83  0
             throw new RegistryException("service-assembly should be set");
 84  
         }
 85  0
     }
 86  
 
 87  
     /*
 88  
      * (non-Javadoc)
 89  
      * 
 90  
      * @see org.mule.jbi.registry.Assembly#start()
 91  
      */
 92  
     public synchronized String start() throws RegistryException
 93  
     {
 94  0
         if (getCurrentState().equals(UNKNOWN))
 95  
         {
 96  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 97  
         }
 98  0
         if (!getCurrentState().equals(RUNNING))
 99  
         {
 100  0
             Unit[] units = getUnits();
 101  0
             for (int i = 0; i < units.length; i++)
 102  
             {
 103  0
                 units[i].start();
 104  
             }
 105  0
             setCurrentState(RUNNING);
 106  
         }
 107  
         // TODO
 108  0
         return "";
 109  
     }
 110  
 
 111  
     /*
 112  
      * (non-Javadoc)
 113  
      * 
 114  
      * @see org.mule.jbi.registry.Assembly#stop()
 115  
      */
 116  
     public synchronized String stop() throws RegistryException
 117  
     {
 118  0
         if (getCurrentState().equals(UNKNOWN) || getCurrentState().equals(SHUTDOWN))
 119  
         {
 120  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 121  
         }
 122  0
         if (!getCurrentState().equals(STOPPED))
 123  
         {
 124  0
             Unit[] units = getUnits();
 125  0
             for (int i = 0; i < units.length; i++)
 126  
             {
 127  0
                 units[i].stop();
 128  
             }
 129  0
             setCurrentState(STOPPED);
 130  
         }
 131  
         // TODO
 132  0
         return "";
 133  
     }
 134  
 
 135  
     /*
 136  
      * (non-Javadoc)
 137  
      * 
 138  
      * @see org.mule.jbi.registry.Assembly#shutDown()
 139  
      */
 140  
     public synchronized String shutDown() throws RegistryException
 141  
     {
 142  0
         if (getCurrentState().equals(UNKNOWN))
 143  
         {
 144  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 145  
         }
 146  0
         if (!getCurrentState().equals(SHUTDOWN))
 147  
         {
 148  0
             stop();
 149  0
             Unit[] units = getUnits();
 150  0
             for (int i = 0; i < units.length; i++)
 151  
             {
 152  0
                 units[i].shutDown();
 153  
             }
 154  0
             setCurrentState(SHUTDOWN);
 155  
         }
 156  
         // TODO
 157  0
         return "";
 158  
     }
 159  
 
 160  
     /*
 161  
      * (non-Javadoc)
 162  
      * 
 163  
      * @see org.mule.jbi.registry.Assembly#undeploy()
 164  
      */
 165  
     public synchronized String undeploy() throws RegistryException
 166  
     {
 167  0
         if (!getCurrentState().equals(SHUTDOWN) && !getCurrentState().equals(UNKNOWN))
 168  
         {
 169  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 170  
         }
 171  0
         Unit[] units = getUnits();
 172  0
         for (int i = 0; i < units.length; i++)
 173  
         {
 174  0
             units[i].undeploy();
 175  
             // TODO: read output from undeploy() to analyse result
 176  
         }
 177  0
         FileUtils.deleteTree(FileUtils.newFile(getInstallRoot()));
 178  0
         getRegistry().removeAssembly(this);
 179  0
         setCurrentState(UNKNOWN);
 180  
         // TODO: return info
 181  0
         return null;
 182  
     }
 183  
 
 184  
     /*
 185  
      * (non-Javadoc)
 186  
      * 
 187  
      * @see org.mule.jbi.registry.Assembly#isTransient()
 188  
      */
 189  
     public boolean isTransient()
 190  
     {
 191  0
         return isTransient;
 192  
     }
 193  
 
 194  
     public void setTransient(boolean isTransient)
 195  
     {
 196  0
         this.isTransient = isTransient;
 197  0
     }
 198  
 
 199  
     /*
 200  
      * (non-Javadoc)
 201  
      * 
 202  
      * @see org.mule.jbi.registry.Assembly#restoreState()
 203  
      */
 204  
     public void restoreState() throws RegistryException
 205  
     {
 206  0
         Unit[] units = getUnits();
 207  0
         for (int i = 0; i < units.length; i++)
 208  
         {
 209  0
             units[i].init();
 210  0
             if (units[i].getStateAtShutdown().equals(Unit.RUNNING))
 211  
             {
 212  0
                 units[i].start();
 213  
             }
 214  0
             else if (units[i].getStateAtShutdown().equals(Unit.SHUTDOWN))
 215  
             {
 216  0
                 units[i].shutDown();
 217  
             }
 218  
         }
 219  0
     }
 220  
 
 221  
     /*
 222  
      * (non-Javadoc)
 223  
      * 
 224  
      * @see org.mule.jbi.registry.Assembly#saveAndShutdown()
 225  
      */
 226  
     public void saveAndShutdown() throws RegistryException
 227  
     {
 228  0
         Unit[] units = getUnits();
 229  0
         for (int i = 0; i < units.length; i++)
 230  
         {
 231  0
             units[i].setStateAtShutdown(units[i].getCurrentState());
 232  0
             units[i].shutDown();
 233  
         }
 234  0
     }
 235  
 
 236  
     public void setDescriptor(RegistryDescriptor descriptor)
 237  
     {
 238  0
         this.descriptor = descriptor;
 239  0
     }
 240  
 
 241  
 }