1 package org.objectweb.celtix.application; 2 3 import java.util.ResourceBundle ; 4 import java.util.logging.Logger ; 5 6 import org.objectweb.celtix.common.i18n.BundleUtils; 7 import org.objectweb.celtix.common.i18n.Message; 8 import org.objectweb.celtix.plugins.PluginException; 9 10 11 public class PluginStateMachine { 12 13 private static final Logger LOG = Logger.getLogger(PluginStateMachine.class.getName()); 14 private static final ResourceBundle BUNDLE = BundleUtils.getBundle(PluginStateMachine.class); 15 16 public enum PluginState { UNLOADED, LOADING, LOADED }; 17 18 private PluginState state; 19 20 PluginStateMachine() { 21 this(PluginState.UNLOADED); 22 } 23 24 PluginStateMachine(PluginState initialState) { 25 state = initialState; 26 } 27 28 PluginState getCurrentState() { 29 return state; 30 } 31 32 synchronized void setNextState(PluginState nextState) throws PluginException { 33 if ((state == PluginState.UNLOADED && nextState == PluginState.LOADING) 34 || (state == PluginState.LOADING && nextState == PluginState.LOADED) 35 || (state == PluginState.LOADED && nextState == PluginState.UNLOADED)) { 36 LOG.fine("changing state from " + state + " to " + nextState); 37 state = nextState; 38 } else { 39 Message msg = new Message("INVALID_STATE_TRANSITION_EXC", BUNDLE, state, nextState); 40 throw new PluginException(msg); 41 } 42 notifyAll(); 43 } 44 45 synchronized void waitForState(PluginState awaitedState) { 46 while (state != awaitedState) { 47 LOG.fine("waiting for state so change from " + state + " to " + awaitedState); 48 try { 49 wait(); 50 } catch (InterruptedException ex) { 51 } 53 } 54 } 55 } 56 | Popular Tags |