1 24 package org.objectweb.jalisto.se.impl.factory; 25 26 import org.objectweb.jalisto.se.api.JalistoProperties; 27 import org.objectweb.jalisto.se.api.Session; 28 import org.objectweb.jalisto.se.api.cache.JalistoCache; 29 import org.objectweb.jalisto.se.api.internal.*; 30 import org.objectweb.jalisto.se.api.physical.PluggablePhysicalFileAccess; 31 import org.objectweb.jalisto.se.api.remote.ClientCommunicationAgent; 32 import org.objectweb.jalisto.se.api.remote.CommunicationFactory; 33 import org.objectweb.jalisto.se.api.remote.JalistoServer; 34 import org.objectweb.jalisto.se.exception.JalistoException; 35 import org.objectweb.jalisto.se.impl.cache.GenericCacheImplEmpty; 36 import org.objectweb.jalisto.se.impl.client.InternalMetaRepositoryClientImpl; 37 import org.objectweb.jalisto.se.impl.client.JalistoPropertiesClientImpl; 38 import org.objectweb.jalisto.se.impl.client.SessionClientImpl; 39 import org.objectweb.jalisto.se.impl.server.IdentityProvider; 40 import org.objectweb.jalisto.se.impl.trace.Trace; 41 import org.objectweb.jalisto.se.impl.trace.TraceContext; 42 43 import java.util.*; 44 45 public class InternalRemoteFactory extends InternalFactoryImpl { 46 47 protected Map sessions; 48 49 public static InternalFactory getInstance() { 50 if (instance == null) { 51 instance = new InternalRemoteFactory(); 52 instance.init(); 53 } 54 return instance; 55 } 56 57 public void init() { 58 super.init(); 59 sessions = new Hashtable(); 60 } 61 62 public synchronized JalistoProperties getProperties(String path) { 63 if (!jalistoProperties.containsKey(path)) { 64 JalistoPropertiesClientImpl p = new JalistoPropertiesClientImpl(path); 65 jalistoProperties.put(path, p); 66 } 67 return (JalistoProperties) jalistoProperties.get(path); 68 } 69 70 public synchronized Trace getTracer(JalistoProperties properties) { 71 String path = properties.getServerPropertiesPath(); 72 if (!tracers.containsKey(path)) { 73 TraceContext traceContext = new TraceContext(properties.isTraceEnable(), properties.getTraceModuleNames()); 74 Trace trace = traceContext.getTracer(); 75 tracers.put(path, trace); 76 } 77 return (Trace) tracers.get(path); 78 } 79 80 public synchronized Session getSession(JalistoProperties properties) { 81 Session session = new SessionClientImpl(properties); 82 sessions.put(session.getInternalSession().getSessionId(), session); 83 return session; 84 } 85 86 public synchronized InternalMetaRepository getMetaRepository(JalistoProperties properties, 87 ClientCommunicationAgent connexion) { 88 String path = properties.getServerPropertiesPath(); 89 if (!metaRepositories.containsKey(path)) { 90 metaRepositories.put(path, new InternalMetaRepositoryClientImpl(properties, connexion)); 91 } 92 return (InternalMetaRepositoryClientImpl) metaRepositories.get(path); 93 } 94 95 public synchronized Map getCache(JalistoProperties properties, int size, String name) { 96 if (size > 0) { 97 String className = properties.getProperty(JalistoProperties.CACHE_IMPLEMENTATION_KEY); 98 try { 99 JalistoCache cache = (JalistoCache) Class.forName(className).newInstance(); 100 cache.init(size, name, properties.getCacheClearPourcent()); 101 cache.setTrace(getTracer(properties)); 102 return cache; 103 } catch (InstantiationException e) { 104 throw new JalistoException("cannot instanciate cache", e); 105 } catch (IllegalAccessException e) { 106 throw new JalistoException("cannot initialize cache", e); 107 } catch (ClassNotFoundException e) { 108 throw new JalistoException("cannot find internal cache", e); 109 } 110 } else if (size == 0) { 111 return new GenericCacheImplEmpty(); 112 } else { 113 return new HashMap(); 114 } 115 } 116 117 public synchronized ClientCommunicationAgent 118 getClientCommunicationAgent(JalistoProperties properties) { 119 String className = properties.getCommunicationFactoryClassName(); 120 try { 121 CommunicationFactory communicationFactory = (CommunicationFactory) Class.forName(className).newInstance(); 122 return communicationFactory.getCommunicationAgentClient(properties); 123 } catch (InstantiationException e) { 124 throw new JalistoException("cannot instanciate CommunicationFactory", e); 125 } catch (IllegalAccessException e) { 126 throw new JalistoException("cannot initialize CommunicationFactory", e); 127 } catch (ClassNotFoundException e) { 128 throw new JalistoException("cannot find internal CommunicationFactory", e); 129 } 130 } 131 132 public synchronized JalistoServer getJalistoServer(String communicationFactoryClassName) { 133 try { 134 CommunicationFactory communicationFactory = 135 (CommunicationFactory) Class.forName(communicationFactoryClassName).newInstance(); 136 return communicationFactory.getJalistoServer(); 137 } catch (InstantiationException e) { 138 throw new JalistoException("cannot instanciate CommunicationFactory", e); 139 } catch (IllegalAccessException e) { 140 throw new JalistoException("cannot initialize CommunicationFactory", e); 141 } catch (ClassNotFoundException e) { 142 throw new JalistoException("cannot find internal CommunicationFactory", e); 143 } 144 } 145 146 public void cleanFactory() { 147 Iterator sessionsIt = sessions.values().iterator(); 148 while (sessionsIt.hasNext()) { 149 SessionInternal session = (SessionInternal) sessionsIt.next(); 150 if (session.currentTransaction().isActive()) { 151 throw new JalistoException("cannot clean factory : session " + session.getSessionId() + " is active"); 152 } 153 if (session.isOpen()) { 154 throw new JalistoException("cannot clean factory : session " + session.getSessionId() + " is open"); 155 } 156 } 157 sessions.clear(); 158 super.cleanFactory(); 159 } 160 161 public synchronized InTransactionBaseImage getAInTransactionBaseImage(PluggablePhysicalFileAccess physicalAccess, 162 JalistoProperties properties) { 163 throw new UnsupportedOperationException (); 164 } 165 166 public PluggablePhysicalFileAccess getPhysicalAccess(JalistoProperties properties) { 167 throw new UnsupportedOperationException (); 168 } 169 170 public synchronized IdentityProvider getIdentityProvider(JalistoProperties properties) { 171 throw new UnsupportedOperationException (); 172 } 173 174 public synchronized LogicalSystemPageAccess getLogicalAccess(JalistoProperties properties) { 175 throw new UnsupportedOperationException (); 176 } 177 178 public synchronized InternalMetaRepository getMetaRepository(JalistoProperties properties) { 179 throw new UnsupportedOperationException (); 180 } 181 182 public synchronized Object getSessionId(JalistoProperties properties, Session session) { 183 throw new UnsupportedOperationException (); 184 } 185 186 public void launchMBeanHtmlServer(JalistoProperties props) { 187 throw new UnsupportedOperationException (); 188 } 189 190 } 191 | Popular Tags |