01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.core.ivm;
17:
18: public class IntraVmCopyMonitor {
19: private static final ThreadLocal<IntraVmCopyMonitor> threadMonitor = new ThreadLocal<IntraVmCopyMonitor>();
20:
21: private boolean intraVmCopyOperation = false;
22:
23: private boolean statefulPassivationOperation = false;
24:
25: private boolean crossClassLoaderOperation = false;
26:
27: private IntraVmCopyMonitor() {
28: }
29:
30: public static boolean exists() {
31: return (threadMonitor.get() != null);
32: }
33:
34: public static void release() {
35: threadMonitor.set(null);
36: }
37:
38: private static IntraVmCopyMonitor getMonitor() {
39: IntraVmCopyMonitor monitor = threadMonitor.get();
40: if (monitor == null) {
41: monitor = new IntraVmCopyMonitor();
42: threadMonitor.set(monitor);
43: }
44: return monitor;
45: }
46:
47: public static void preCopyOperation() {
48: IntraVmCopyMonitor monitor = getMonitor();
49: monitor.intraVmCopyOperation = true;
50: }
51:
52: public static void postCopyOperation() {
53: IntraVmCopyMonitor monitor = getMonitor();
54: monitor.intraVmCopyOperation = false;
55: }
56:
57: public static void prePassivationOperation() {
58: IntraVmCopyMonitor monitor = getMonitor();
59: monitor.statefulPassivationOperation = true;
60: }
61:
62: public static void postPassivationOperation() {
63: IntraVmCopyMonitor monitor = getMonitor();
64: monitor.statefulPassivationOperation = false;
65: }
66:
67: public static void preCrossClassLoaderOperation() {
68: IntraVmCopyMonitor monitor = getMonitor();
69: monitor.crossClassLoaderOperation = true;
70: }
71:
72: public static void postCrossClassLoaderOperation() {
73: IntraVmCopyMonitor monitor = getMonitor();
74: monitor.crossClassLoaderOperation = false;
75: }
76:
77: public static boolean isIntraVmCopyOperation() {
78: IntraVmCopyMonitor monitor = getMonitor();
79: return monitor.intraVmCopyOperation;
80: }
81:
82: public static boolean isStatefulPassivationOperation() {
83: IntraVmCopyMonitor monitor = getMonitor();
84: return monitor.statefulPassivationOperation;
85: }
86:
87: public static boolean isCrossClassLoaderOperation() {
88: IntraVmCopyMonitor monitor = getMonitor();
89: return monitor.crossClassLoaderOperation;
90: }
91: }
|