KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > factory > InternalFactoryImpl


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

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 JavaDoc;
46 import java.util.Map JavaDoc;
47 import java.util.HashMap JavaDoc;
48
49 public class InternalFactoryImpl implements InternalFactory {
50
51     protected Map JavaDoc jalistoProperties;
52     protected Map JavaDoc logicals;
53     protected Map JavaDoc metaRepositories;
54     protected Map JavaDoc oidProviders;
55     protected Map JavaDoc oidTables;
56     protected Map JavaDoc physicals;
57     protected Map JavaDoc sessionIdMap;
58     protected Map JavaDoc 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 JavaDoc();
74         logicals = new Hashtable JavaDoc();
75         metaRepositories = new Hashtable JavaDoc();
76         oidProviders = new Hashtable JavaDoc();
77         oidTables = new Hashtable JavaDoc();
78         physicals = new Hashtable JavaDoc();
79         sessionIdMap = new Hashtable JavaDoc();
80         tracers = new Hashtable JavaDoc();
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 JavaDoc 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 JavaDoc getSessionId(JalistoProperties properties, Session session) {
106         String JavaDoc name = properties.getName();
107         if (!sessionIdMap.containsKey(name)) {
108             Object JavaDoc id = new Integer JavaDoc(0);
109             sessionIdMap.put(name, id);
110             return name + id;
111         }
112         Integer JavaDoc oldId = (Integer JavaDoc) sessionIdMap.get(name);
113         Integer JavaDoc newId = new Integer JavaDoc(oldId.intValue() + 1);
114         sessionIdMap.put(name, newId);
115         return name + newId;
116     }
117
118     public synchronized InternalMetaRepository getMetaRepository(JalistoProperties properties) {
119         String JavaDoc 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 JavaDoc 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 JavaDoc className = properties.getProperty(JalistoProperties.PHYSICAL_ACCESS_CLASS_KEY);
141         try {
142             internalAccess = (PluggablePhysicalFileAccess) Class.forName(className).newInstance();
143         } catch (InstantiationException JavaDoc e) {
144             throw new JalistoException("cannot instanciate internal access", e);
145         } catch (IllegalAccessException JavaDoc e) {
146             throw new JalistoException("cannot initialize internal access", e);
147         } catch (ClassNotFoundException JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc[] arrayOfObjects) {
183         return DataWrapperImpl.newInstance(arrayOfObjects);
184     }
185
186     public synchronized Map JavaDoc getCache(JalistoProperties properties, int size, String JavaDoc name) {
187         if (size > 0) {
188             String JavaDoc 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 JavaDoc e) {
195                 throw new JalistoException("cannot instanciate cache", e);
196             } catch (IllegalAccessException JavaDoc e) {
197                 throw new JalistoException("cannot initialize cache", e);
198             } catch (ClassNotFoundException JavaDoc 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 JavaDoc();
205         }
206     }
207
208     public void launchMBeanHtmlServer(JalistoProperties props) {
209         if ((mbeanServer == null) || (!mbeanServer.isAlive())) {
210             try {
211                 String JavaDoc 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 JavaDoc e) {
216                 throw new JalistoException("cannot instanciate internal access", e);
217             } catch (IllegalAccessException JavaDoc e) {
218                 throw new JalistoException("cannot initialize internal access", e);
219             } catch (ClassNotFoundException JavaDoc 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 JavaDoc();
229     }
230
231     public LockTable getLockTable(JalistoProperties properties) {
232         throw new UnsupportedOperationException JavaDoc();
233     }
234
235     public Object JavaDoc getSessionById(Object JavaDoc sessionId) {
236         throw new UnsupportedOperationException JavaDoc();
237     }
238
239     public OidTable getOidTable(JalistoProperties properties) {
240         throw new UnsupportedOperationException JavaDoc();
241     }
242
243     public InternalPhysicalFileAccess getInternalPhysicalAccess(JalistoProperties properties) {
244         throw new UnsupportedOperationException JavaDoc();
245     }
246
247     public Session getSession(JalistoProperties properties) {
248         throw new UnsupportedOperationException JavaDoc();
249     }
250
251     public ClientCommunicationAgent getClientCommunicationAgent(JalistoProperties properties) {
252         throw new UnsupportedOperationException JavaDoc();
253     }
254
255     public JalistoServer getJalistoServer(String JavaDoc communicationFactoryClassName) {
256         throw new UnsupportedOperationException JavaDoc();
257     }
258
259     public InternalMetaRepository getMetaRepository(JalistoProperties properties, ClientCommunicationAgent connexion) {
260         throw new UnsupportedOperationException JavaDoc();
261     }
262
263 }
264
Popular Tags