tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dblev...@apache.org
Subject svn commit: r657174 - /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java
Date Fri, 16 May 2008 19:17:16 GMT
Author: dblevins
Date: Fri May 16 12:17:16 2008
New Revision: 657174

URL: http://svn.apache.org/viewvc?rev=657174&view=rev
Log:
Refactored to be enum based

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java?rev=657174&r1=657173&r2=657174&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ivm/IntraVmCopyMonitor.java
Fri May 16 12:17:16 2008
@@ -17,13 +17,27 @@
 package org.apache.openejb.core.ivm;
 
 public class IntraVmCopyMonitor {
-    private static final ThreadLocal<IntraVmCopyMonitor> threadMonitor = new ThreadLocal<IntraVmCopyMonitor>();
+    public static enum State {
+        NONE, COPY(true), CLASSLOADER_COPY(true), PASSIVATION;
+
+        private final boolean copy;
+
+        State() {
+           this.copy = false;
+        }
+
+        State(boolean copy) {
+           this.copy = copy;
+        }
 
-    private boolean intraVmCopyOperation = false;
+        public boolean isCopy() {
+            return copy;
+        }
+    }
 
-    private boolean statefulPassivationOperation = false;
+    private static final ThreadLocal<IntraVmCopyMonitor> threadMonitor = new ThreadLocal<IntraVmCopyMonitor>();
 
-    private boolean crossClassLoaderOperation = false;
+    private State state = State.NONE;
 
     private IntraVmCopyMonitor() {
     }
@@ -45,48 +59,51 @@
         return monitor;
     }
 
-    public static void preCopyOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        monitor.intraVmCopyOperation = true;
+    public static void pre(State state){
+        getMonitor().state = state;
     }
 
-    public static void postCopyOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        monitor.intraVmCopyOperation = false;
+    public static void post() {
+        pre(State.NONE);
+    }
+
+    public static State state(){
+        return getMonitor().state;
     }
 
     public static void prePassivationOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        monitor.statefulPassivationOperation = true;
+        pre(State.PASSIVATION);
     }
 
     public static void postPassivationOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        monitor.statefulPassivationOperation = false;
+        post();
     }
 
     public static void preCrossClassLoaderOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        monitor.crossClassLoaderOperation = true;
+        pre(State.CLASSLOADER_COPY);
     }
 
     public static void postCrossClassLoaderOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        monitor.crossClassLoaderOperation = false;
+        post();
+    }
+
+    public static void preCopyOperation() {
+        pre(State.COPY);
+    }
+
+    public static void postCopyOperation() {
+        post();
     }
 
     public static boolean isIntraVmCopyOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        return monitor.intraVmCopyOperation;
+        return state() == State.COPY;
     }
 
     public static boolean isStatefulPassivationOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        return monitor.statefulPassivationOperation;
+        return state() == State.PASSIVATION;
     }
 
     public static boolean isCrossClassLoaderOperation() {
-        IntraVmCopyMonitor monitor = getMonitor();
-        return monitor.crossClassLoaderOperation;
+        return state() == State.CLASSLOADER_COPY;
     }
 }



Mime
View raw message