package nl.nn.adapterframework.util;

/**
 * Utility class to support run-state management
 * @version Id
 *
 *
 * @author Gerrit van Brakel
 */
public class RunStateManager  {
	public static final String version="$Id: RunStateManager.java,v 1.3 2004-03-26 10:42:39 NNVZNL01#L180564 Exp $";
	
	private RunStateEnum runState = RunStateEnum.STOPPED;

/**
 * Constructor
 */
public RunStateManager() {
	super();
}
public synchronized RunStateEnum getRunState() {
	return runState;
}
	public synchronized boolean isInState(RunStateEnum state) {
		return runState.equals(state);
	}
public synchronized void setRunState(RunStateEnum newRunState) {
	runState = newRunState;
	notifyAll();
}
/**
 * Performs a <code>wait()</code> until the object is in the requested state.
 * @param requestedRunState    the RunStateEnum requested
 * @throws InterruptedException when interruption occurs
 */
public synchronized void waitForRunState(RunStateEnum requestedRunState)
    throws InterruptedException {
    while (!runState.equals(requestedRunState)) {
        wait();
    }
}
}

@@ -31,16 +31,49 @@
 .util;%0A%0A
+import org.apache.log4j.Logger;%0A%0A
 /**%0A * U
@@ -200,17 +200,16 @@
 Manager 
- 
 %7B%0A%09publi
@@ -237,17 +237,21 @@
  version
-=
+ =%0A%09%09
 %22$Id: Ru
@@ -277,56 +277,120 @@
 v 1.
-3
+4
  2004-0
-3-26 10:42:39 NNVZNL01#L180564 Exp $%22;%0A%09
+8-19 07:14:55 a1909356#db2admin Exp $%22;%0A%09%0A%09private Logger log = Logger.getLogger(RunStateManager.class);
 %0A%09pr
@@ -442,20 +442,22 @@
 OPPED;%0A%0A
+%09
 /**%0A
+%09
  * Const
@@ -463,20 +463,22 @@
 tructor%0A
+%09
  */%0A
+%09
 public R
@@ -496,16 +496,17 @@
 ger() %7B%0A
+%09
 %09super()
@@ -507,18 +507,20 @@
 uper();%0A
+%09
 %7D%0A
+%09
 public s
@@ -560,16 +560,17 @@
 ate() %7B%0A
+%09
 %09return 
@@ -579,16 +579,17 @@
 nState;%0A
+%09
 %7D%0A%09publi
@@ -679,16 +679,17 @@
 te);%0A%09%7D%0A
+%09
 public s
@@ -745,16 +745,173 @@
 tate) %7B%0A
+%09%09if (! runState.equals(newRunState)) %7B%0A%09%09%09if (log.isDebugEnabled())%0A%09%09%09%09log.debug(%22Runstate %5B%22 + this + %22%5D set from %22 + runState + %22 to %22 + newRunState);%0A%09%09
 %09runStat
@@ -927,16 +927,18 @@
 nState;%0A
+%09%09
 %09notifyA
@@ -947,14 +947,21 @@
 ();%0A
-%7D%0A
+%09%09%7D%0A%09%7D%0A%09
 /**%0A
+%09
  * P
@@ -1034,16 +1034,17 @@
  state.%0A
+%09
  * @para
@@ -1093,16 +1093,17 @@
 quested%0A
+%09
  * @thro
@@ -1151,20 +1151,22 @@
  occurs%0A
+%09
  */%0A
+%09
 public s
@@ -1230,20 +1230,18 @@
 nState)%0A
-    
+%09%09
 throws I
@@ -1262,20 +1262,18 @@
 ption %7B%0A
-    
+%09%09
 while (!
@@ -1314,30 +1314,455 @@
 ) %7B%0A
-        wait();%0A    %7D%0A%7D
+%09%09%09wait();%0A%09%09%7D%0A%09%7D%0A%09%0A%09public boolean waitForRunState(RunStateEnum state, long maxWait) throws InterruptedException %7B%0A%09%09long cts = System.currentTimeMillis();%0A%09%09RunStateEnum newState = null;%0A%09%09synchronized(this) %7B%0A%09%09%09while (! (newState = getRunState()).equals(state)) %7B%0A%09%09%09%09long togo = maxWait - (System.currentTimeMillis() - cts);%0A%09%09%09%09if (togo %3E 0) %7B%0A%09%09%09%09%09wait(togo);%0A%09%09%09%09%7D%0A%09%09%09%09else %7B%0A%09%09%09%09%09break;%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return newState.equals(state);%0A%09%7D%0A%09
 %0A%7D%0A

Add logging