1 24 package org.objectweb.jalisto.se.impl.factory; 25 26 import org.objectweb.jalisto.se.api.internal.*; 27 import org.objectweb.jalisto.se.api.internal.multi.LockTable; 28 import org.objectweb.jalisto.se.api.JalistoProperties; 29 import org.objectweb.jalisto.se.api.Session; 30 import org.objectweb.jalisto.se.api.remote.ClientCommunicationAgent; 31 import org.objectweb.jalisto.se.api.remote.JalistoServer; 32 import org.objectweb.jalisto.se.api.internal.InternalPhysicalFileAccess; 33 import org.objectweb.jalisto.se.api.physical.PluggablePhysicalFileAccess; 34 import org.objectweb.jalisto.se.api.cache.JalistoCache; 35 import org.objectweb.jalisto.se.api.jmx.JalistoMBeanServer; 36 import org.objectweb.jalisto.se.impl.lock.AccessController; 37 import org.objectweb.jalisto.se.impl.server.*; 38 import org.objectweb.jalisto.se.impl.trace.Trace; 39 import org.objectweb.jalisto.se.impl.trace.TraceContext; 40 import org.objectweb.jalisto.se.impl.meta.InternalMetaRepositoryImpl; 41 import org.objectweb.jalisto.se.impl.cache.GenericCacheImplEmpty; 42 import org.objectweb.jalisto.se.impl.JalistoPropertiesImpl; 43 import org.objectweb.jalisto.se.exception.JalistoException; 44 45 import java.util.Hashtable ; 46 import java.util.Map ; 47 import java.util.HashMap ; 48 49 public class InternalFactoryImpl implements InternalFactory { 50 51 protected Map jalistoProperties; 52 protected Map logicals; 53 protected Map metaRepositories; 54 protected Map oidProviders; 55 protected Map oidTables; 56 protected Map physicals; 57 protected Map sessionIdMap; 58 protected Map tracers; 59 60 protected JalistoMBeanServer mbeanServer; 61 62 protected static InternalFactory instance; 63 64 65 66 public void setSelfInstance() { 67 if (InternalFactoryImpl.instance == null) { 68 InternalFactoryImpl.instance = this; 69 } 70 } 71 72 public void init() { 73 jalistoProperties = new Hashtable (); 74 logicals = new Hashtable (); 75 metaRepositories = new Hashtable (); 76 oidProviders = new Hashtable (); 77 oidTables = new Hashtable (); 78 physicals = new Hashtable (); 79 sessionIdMap = new Hashtable (); 80 tracers = new Hashtable (); 81 } 82 83 public void cleanFactory() { 84 System.out.println("CLEANING FACTORY"); 85 jalistoProperties.clear(); 86 logicals.clear(); 87 metaRepositories.clear(); 88 oidProviders.clear(); 89 oidTables.clear(); 90 physicals.clear(); 91 sessionIdMap.clear(); 92 tracers.clear(); 93 94 System.gc(); 95 } 96 97 public synchronized JalistoProperties getProperties(String path) { 98 if (!jalistoProperties.containsKey(path)) { 99 JalistoProperties p = new JalistoPropertiesImpl(path); 100 jalistoProperties.put(path, p); 101 } 102 return (JalistoProperties) jalistoProperties.get(path); 103 } 104 105 public synchronized Object getSessionId(JalistoProperties properties, Session session) { 106 String name = properties.getName(); 107 if (!sessionIdMap.containsKey(name)) { 108 Object id = new Integer (0); 109 sessionIdMap.put(name, id); 110 return name + id; 111 } 112 Integer oldId = (Integer ) sessionIdMap.get(name); 113 Integer newId = new Integer (oldId.intValue() + 1); 114 sessionIdMap.put(name, newId); 115 return name + newId; 116 } 117 118 public synchronized InternalMetaRepository getMetaRepository(JalistoProperties properties) { 119 String path = properties.getDbFileFullName(); 120 if (!metaRepositories.containsKey(path)) { 121 InternalMetaRepositoryImpl metaRepository = InternalMetaRepositoryImpl.getAnMetaRepository(properties); 122 metaRepositories.put(path, metaRepository); 123 } 124 InternalMetaRepositoryImpl result = (InternalMetaRepositoryImpl) metaRepositories.get(path); 125 return result; 126 } 127 128 public synchronized IdentityProvider getIdentityProvider(JalistoProperties properties) { 129 String path = properties.getDbFileFullName(); 130 if (!oidProviders.containsKey(path)) { 131 InternalPhysicalFileAccess physicalAccess = getInternalPhysicalAccess(properties); 132 IdentityProvider oidProvider = IdentityProvider.getAnIdentityProvider(physicalAccess); 133 oidProviders.put(path, oidProvider); 134 } 135 return (IdentityProvider) oidProviders.get(path); 136 } 137 138 public PluggablePhysicalFileAccess getPhysicalAccess(JalistoProperties properties) { 139 PluggablePhysicalFileAccess internalAccess; 140 String className = properties.getProperty(JalistoProperties.PHYSICAL_ACCESS_CLASS_KEY); 141 try { 142 internalAccess = (PluggablePhysicalFileAccess) Class.forName(className).newInstance(); 143 } catch (InstantiationException e) { 144 throw new JalistoException("cannot instanciate internal access", e); 145 } catch (IllegalAccessException e) { 146 throw new JalistoException("cannot initialize internal access", e); 147 } catch (ClassNotFoundException e) { 148 throw new JalistoException("cannot find internal access class", e); 149 } 150 internalAccess.init(properties); 151 return internalAccess; 152 } 153 154 public synchronized Trace getTracer(JalistoProperties properties) { 155 String path = properties.getDbFileFullName(); 156 if (!tracers.containsKey(path)) { 157 TraceContext traceContext = new TraceContext(properties.isTraceEnable(), properties.getTraceModuleNames()); 158 Trace trace = traceContext.getTracer(); 159 tracers.put(path, trace); 160 } 161 return (Trace) tracers.get(path); 162 } 163 164 public synchronized Session getSession(String propertiesFilePath) { 165 JalistoProperties properties = getProperties(propertiesFilePath); 166 return getSession(properties); 167 } 168 169 public synchronized InTransactionBaseImage getAInTransactionBaseImage( 170 PluggablePhysicalFileAccess physicalAccess, JalistoProperties properties) { 171 return InTransactionBaseImageImpl.getInTransactionBaseImageInstance(physicalAccess, properties); 172 } 173 174 public synchronized LogicalSystemPageAccess getLogicalAccess(JalistoProperties properties) { 175 String path = properties.getDbFileFullName(); 176 if (!logicals.containsKey(path)) { 177 logicals.put(path, new LogicalPageAccessImpl(properties)); 178 } 179 return (LogicalSystemPageAccess) logicals.get(path); 180 } 181 182 public DataWrapper getNewDataWrapper(JalistoProperties properties, Object [] arrayOfObjects) { 183 return DataWrapperImpl.newInstance(arrayOfObjects); 184 } 185 186 public synchronized Map getCache(JalistoProperties properties, int size, String name) { 187 if (size > 0) { 188 String className = properties.getProperty(JalistoProperties.CACHE_IMPLEMENTATION_KEY); 189 try { 190 JalistoCache cache = (JalistoCache) Class.forName(className).newInstance(); 191 cache.init(size, name, properties.getCacheClearPourcent()); 192 cache.setTrace(getTracer(properties)); 193 return cache; 194 } catch (InstantiationException e) { 195 throw new JalistoException("cannot instanciate cache", e); 196 } catch (IllegalAccessException e) { 197 throw new JalistoException("cannot initialize cache", e); 198 } catch (ClassNotFoundException e) { 199 throw new JalistoException("cannot find internal cache", e); 200 } 201 } else if (size == 0) { 202 return new GenericCacheImplEmpty(); 203 } else { 204 return new HashMap (); 205 } 206 } 207 208 public void launchMBeanHtmlServer(JalistoProperties props) { 209 if ((mbeanServer == null) || (!mbeanServer.isAlive())) { 210 try { 211 String className = props.getProperty(JalistoProperties.MBEAN_SERVER_CLASS_KEY); 212 mbeanServer = (JalistoMBeanServer) Class.forName(className).newInstance(); 213 mbeanServer.init(props.getPropertiesPath()); 214 mbeanServer.run(); 215 } catch (InstantiationException e) { 216 throw new JalistoException("cannot instanciate internal access", e); 217 } catch (IllegalAccessException e) { 218 throw new JalistoException("cannot initialize internal access", e); 219 } catch (ClassNotFoundException e) { 220 throw new JalistoException("cannot find internal access class", e); 221 } 222 } else { 223 mbeanServer.addSession(props.getPropertiesPath()); 224 } 225 } 226 227 public AccessController getAccessController(JalistoProperties properties) { 228 throw new UnsupportedOperationException (); 229 } 230 231 public LockTable getLockTable(JalistoProperties properties) { 232 throw new UnsupportedOperationException (); 233 } 234 235 public Object getSessionById(Object sessionId) { 236 throw new UnsupportedOperationException (); 237 } 238 239 public OidTable getOidTable(JalistoProperties properties) { 240 throw new UnsupportedOperationException (); 241 } 242 243 public InternalPhysicalFileAccess getInternalPhysicalAccess(JalistoProperties properties) { 244 throw new UnsupportedOperationException (); 245 } 246 247 public Session getSession(JalistoProperties properties) { 248 throw new UnsupportedOperationException (); 249 } 250 251 public ClientCommunicationAgent getClientCommunicationAgent(JalistoProperties properties) { 252 throw new UnsupportedOperationException (); 253 } 254 255 public JalistoServer getJalistoServer(String communicationFactoryClassName) { 256 throw new UnsupportedOperationException (); 257 } 258 259 public InternalMetaRepository getMetaRepository(JalistoProperties properties, ClientCommunicationAgent connexion) { 260 throw new UnsupportedOperationException (); 261 } 262 263 } 264 | Popular Tags |