summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-04 05:30:34 (EDT)
committerEike Stepper2007-08-04 05:30:34 (EDT)
commitde50f02e7eef796fcdf6ea325c27c554f15742e3 (patch)
tree885f05a13b8fc53298f7efd0f4b067f7ebd06f13
parenta3a93370427e1de918ddc119d06ad853524eba19 (diff)
downloadcdo-de50f02e7eef796fcdf6ea325c27c554f15742e3.zip
cdo-de50f02e7eef796fcdf6ea325c27c554f15742e3.tar.gz
cdo-de50f02e7eef796fcdf6ea325c27c554f15742e3.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java42
1 files changed, 34 insertions, 8 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java
index e23aae1..9563e19 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/lifecycle/Lifecycle.java
@@ -16,11 +16,12 @@ import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.ReflectUtil;
import org.eclipse.net4j.util.lifecycle.ILifecycle;
import org.eclipse.net4j.util.lifecycle.ILifecycleEvent;
+import org.eclipse.net4j.util.lifecycle.ILifecycleState;
/**
* @author Eike Stepper
*/
-public class Lifecycle extends Notifier implements ILifecycle
+public class Lifecycle extends Notifier implements ILifecycle.Introspection
{
public static boolean USE_LABEL = true;
@@ -28,7 +29,9 @@ public class Lifecycle extends Notifier implements ILifecycle
private static final ContextTracer DUMPER = new ContextTracer(OM.DEBUG_LIFECYCLE_DUMP, Lifecycle.class);
- private boolean active;
+ private static final boolean TRACE_IGNORING = false;
+
+ private ILifecycleState lifecycleState = ILifecycleState.INACTIVE;
protected Lifecycle()
{
@@ -36,26 +39,35 @@ public class Lifecycle extends Notifier implements ILifecycle
public final synchronized void activate() throws Exception
{
- if (!active)
+ if (lifecycleState == ILifecycleState.INACTIVE)
{
if (TRACER.isEnabled())
{
TRACER.trace("Activating " + this);//$NON-NLS-1$
}
+ lifecycleState = ILifecycleState.ACTIVATING;
doBeforeActivate();
fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.ABOUT_TO_ACTIVATE));
+
dump();
doActivate();
- active = true;
+ lifecycleState = ILifecycleState.ACTIVE;
fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.ACTIVATED));
}
+ else
+ {
+ if (TRACE_IGNORING && TRACER.isEnabled())
+ {
+ TRACER.format("Ignoring activation in state {0} for {1}", lifecycleState, this);//$NON-NLS-1$
+ }
+ }
}
public final synchronized Exception deactivate()
{
- if (active)
+ if (lifecycleState == ILifecycleState.ACTIVE)
{
if (TRACER.isEnabled())
{
@@ -64,8 +76,10 @@ public class Lifecycle extends Notifier implements ILifecycle
try
{
+ lifecycleState = ILifecycleState.DEACTIVATING;
doBeforeDeactivate();
fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.ABOUT_TO_DEACTIVATE));
+
doDeactivate();
fireEvent(new LifecycleEvent(this, ILifecycleEvent.Kind.DEACTIVATED));
}
@@ -81,16 +95,28 @@ public class Lifecycle extends Notifier implements ILifecycle
}
finally
{
- active = false;
+ lifecycleState = ILifecycleState.INACTIVE;
+ }
+ }
+ else
+ {
+ if (TRACE_IGNORING && TRACER.isEnabled())
+ {
+ TRACER.format("Ignoring deactivation in state {0} for {1}", lifecycleState, this);//$NON-NLS-1$
}
}
return null;
}
+ public final ILifecycleState getLifecycleState()
+ {
+ return lifecycleState;
+ }
+
public final boolean isActive()
{
- return active;
+ return lifecycleState == ILifecycleState.ACTIVE;
}
public void dump()
@@ -116,7 +142,7 @@ public class Lifecycle extends Notifier implements ILifecycle
protected void checkActive()
{
- if (!active)
+ if (lifecycleState != ILifecycleState.ACTIVE)
{
throw new IllegalStateException("Not active: " + this);
}