Coverage Report - org.mule.registry.impl.AbstractUnit
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractUnit
0%
0/64
0%
0/9
2.688
 
 1  
 /*
 2  
  * $Id: AbstractUnit.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.RegistryComponent;
 16  
 import org.mule.registry.RegistryException;
 17  
 import org.mule.registry.Unit;
 18  
 
 19  
 /**
 20  
  * @author <a href="mailto:gnt@codehaus.org">Guillaume Nodet</a>
 21  
  */
 22  
 public abstract class AbstractUnit extends AbstractEntry implements Unit
 23  
 {
 24  
 
 25  
     private String assembly;
 26  
 
 27  
     protected AbstractUnit(Registry registry)
 28  
     {
 29  0
         super(registry);
 30  0
     }
 31  
 
 32  
     /*
 33  
      * (non-Javadoc)
 34  
      * 
 35  
      * @see org.mule.jbi.registry.Unit#getAssemblies()
 36  
      */
 37  
     public Assembly getAssembly()
 38  
     {
 39  0
         return getRegistry().getAssembly(this.assembly);
 40  
     }
 41  
 
 42  
     public void setAssembly(Assembly assembly)
 43  
     {
 44  0
         this.assembly = assembly.getName();
 45  0
     }
 46  
 
 47  
     /*
 48  
      * (non-Javadoc)
 49  
      * 
 50  
      * @see org.mule.jbi.registry.Unit#deploy()
 51  
      */
 52  
     public final synchronized String deploy() throws RegistryException
 53  
     {
 54  0
         if (!getCurrentState().equals(UNKNOWN))
 55  
         {
 56  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 57  
         }
 58  0
         String result = null;
 59  
         try
 60  
         {
 61  0
             result = doDeploy();
 62  
         }
 63  0
         catch (Exception e)
 64  
         {
 65  0
             throw new RegistryException(e);
 66  0
         }
 67  
         // TODO: analyse result
 68  0
         getRegistryComponent().addUnit(this);
 69  0
         ((AbstractAssembly)getAssembly()).addUnit(this);
 70  0
         setCurrentState(STOPPED);
 71  0
         return result;
 72  
     }
 73  
 
 74  
     public abstract String doDeploy() throws Exception;
 75  
 
 76  
     /*
 77  
      * (non-Javadoc)
 78  
      * 
 79  
      * @see org.mule.jbi.registry.Unit#init()
 80  
      */
 81  
     public final synchronized void init() throws RegistryException
 82  
     {
 83  0
         if (!getCurrentState().equals(UNKNOWN))
 84  
         {
 85  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 86  
         }
 87  
         try
 88  
         {
 89  0
             doInit();
 90  
         }
 91  0
         catch (Exception e)
 92  
         {
 93  0
             throw new RegistryException(e);
 94  0
         }
 95  0
         setCurrentState(STOPPED);
 96  0
     }
 97  
 
 98  
     protected abstract void doInit() throws Exception;
 99  
 
 100  
     /*
 101  
      * (non-Javadoc)
 102  
      * 
 103  
      * @see org.mule.jbi.registry.Unit#start()
 104  
      */
 105  
     public final synchronized void start() throws RegistryException
 106  
     {
 107  0
         if (getCurrentState().equals(UNKNOWN))
 108  
         {
 109  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 110  
         }
 111  0
         if (!getCurrentState().equals(RUNNING))
 112  
         {
 113  
             try
 114  
             {
 115  0
                 doStart();
 116  
             }
 117  0
             catch (Exception e)
 118  
             {
 119  0
                 throw new RegistryException(e);
 120  0
             }
 121  0
             setCurrentState(RUNNING);
 122  
         }
 123  0
     }
 124  
 
 125  
     protected abstract void doStart() throws Exception;
 126  
 
 127  
     /*
 128  
      * (non-Javadoc)
 129  
      * 
 130  
      * @see org.mule.jbi.registry.Unit#stop()
 131  
      */
 132  
     public final synchronized void stop() throws RegistryException
 133  
     {
 134  0
         if (getCurrentState().equals(UNKNOWN) || getCurrentState().equals(SHUTDOWN))
 135  
         {
 136  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 137  
         }
 138  0
         if (!getCurrentState().equals(STOPPED))
 139  
         {
 140  
             try
 141  
             {
 142  0
                 doStop();
 143  
             }
 144  0
             catch (Exception e)
 145  
             {
 146  0
                 throw new RegistryException(e);
 147  0
             }
 148  0
             setCurrentState(STOPPED);
 149  
         }
 150  0
     }
 151  
 
 152  
     protected abstract void doStop() throws Exception;
 153  
 
 154  
     /*
 155  
      * (non-Javadoc)
 156  
      * 
 157  
      * @see org.mule.jbi.registry.Unit#shutDown()
 158  
      */
 159  
     public final synchronized void shutDown() throws RegistryException
 160  
     {
 161  0
         if (getCurrentState().equals(UNKNOWN))
 162  
         {
 163  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 164  
         }
 165  0
         if (!getCurrentState().equals(SHUTDOWN))
 166  
         {
 167  0
             stop();
 168  
             try
 169  
             {
 170  0
                 doShutDown();
 171  
             }
 172  0
             catch (Exception e)
 173  
             {
 174  0
                 throw new RegistryException(e);
 175  0
             }
 176  0
             setCurrentState(SHUTDOWN);
 177  
         }
 178  0
     }
 179  
 
 180  
     protected abstract void doShutDown() throws Exception;
 181  
 
 182  
     /*
 183  
      * (non-Javadoc)
 184  
      * 
 185  
      * @see org.mule.jbi.registry.Unit#undeploy()
 186  
      */
 187  
     public synchronized String undeploy() throws RegistryException
 188  
     {
 189  0
         if (!getCurrentState().equals(SHUTDOWN))
 190  
         {
 191  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 192  
         }
 193  0
         String result = null;
 194  
         try
 195  
         {
 196  0
             result = doUndeploy();
 197  
         }
 198  0
         catch (Exception e)
 199  
         {
 200  0
             throw new RegistryException(e);
 201  0
         }
 202  
         // TODO: analyse result
 203  0
         getRegistryComponent().removeUnit(this);
 204  0
         ((AbstractAssembly)getAssembly()).removeUnit(this);
 205  0
         setCurrentState(UNKNOWN);
 206  0
         return result;
 207  
     }
 208  
 
 209  
     protected abstract String doUndeploy() throws Exception;
 210  
 
 211  
     public void setRegistryComponent(RegistryComponent component)
 212  
     {
 213  
         // nothing to do (yet?)
 214  0
     }
 215  
 
 216  
 }