1 64 65 package com.jcorporate.expresso.kernel.management; 66 67 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 68 import com.jcorporate.expresso.kernel.RootContainerInterface; 69 70 import java.util.Map ; 71 72 81 82 public final class ExpressoRuntimeMap { 83 84 87 private static Map runtimeMap = new ConcurrentReaderHashMap(); 88 89 92 private static RootContainerInterface defaultRuntime = null; 93 94 97 private static Object DefaultRuntimeLock = new Object (); 98 99 102 public ExpressoRuntimeMap() { 103 } 104 105 113 public synchronized static void registerRuntime(String name, RootContainerInterface expressoRuntime) { 114 if (expressoRuntime == null) { 115 throw new IllegalArgumentException ("Cannot pass in a null Root Container"); 116 } 117 118 if (name != null && name.length() > 0) { 119 runtimeMap.put(name, expressoRuntime); 120 } 121 122 synchronized (DefaultRuntimeLock) { 123 if (defaultRuntime == null || name == null || name.length() == 0) { 124 defaultRuntime = expressoRuntime; 125 } 126 } 127 } 128 129 137 public static RootContainerInterface getRuntime(String name) { 138 if (name == null || name.length() == 0) { 139 synchronized (DefaultRuntimeLock) { 140 return defaultRuntime; 141 } 142 } else { 143 return (RootContainerInterface) runtimeMap.get(name); 144 } 145 } 146 147 152 public static synchronized RootContainerInterface getDefaultRuntime() { 153 synchronized (DefaultRuntimeLock) { 154 return defaultRuntime; 155 } 156 } 157 158 164 public static synchronized void unregisterRuntime(String name) { 165 if (name == null || name.length() == 0) { 166 synchronized (DefaultRuntimeLock) { 167 defaultRuntime = null; 168 } 169 return; 170 } 171 172 runtimeMap.remove(name); 173 } 174 175 } | Popular Tags |