KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc name) {
96         if (size > 0) {
97             String JavaDoc 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 JavaDoc e) {
104                 throw new JalistoException("cannot instanciate cache", e);
105             } catch (IllegalAccessException JavaDoc e) {
106                 throw new JalistoException("cannot initialize cache", e);
107             } catch (ClassNotFoundException JavaDoc 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 JavaDoc className = properties.getCommunicationFactoryClassName();
120         try {
121             CommunicationFactory communicationFactory = (CommunicationFactory) Class.forName(className).newInstance();
122             return communicationFactory.getCommunicationAgentClient(properties);
123         } catch (InstantiationException JavaDoc e) {
124             throw new JalistoException("cannot instanciate CommunicationFactory", e);
125         } catch (IllegalAccessException JavaDoc e) {
126             throw new JalistoException("cannot initialize CommunicationFactory", e);
127         } catch (ClassNotFoundException JavaDoc e) {
128             throw new JalistoException("cannot find internal CommunicationFactory", e);
129         }
130     }
131
132     public synchronized JalistoServer getJalistoServer(String JavaDoc communicationFactoryClassName) {
133         try {
134             CommunicationFactory communicationFactory =
135                     (CommunicationFactory) Class.forName(communicationFactoryClassName).newInstance();
136             return communicationFactory.getJalistoServer();
137         } catch (InstantiationException JavaDoc e) {
138             throw new JalistoException("cannot instanciate CommunicationFactory", e);
139         } catch (IllegalAccessException JavaDoc e) {
140             throw new JalistoException("cannot initialize CommunicationFactory", e);
141         } catch (ClassNotFoundException JavaDoc 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 JavaDoc();
164     }
165
166     public PluggablePhysicalFileAccess getPhysicalAccess(JalistoProperties properties) {
167         throw new UnsupportedOperationException JavaDoc();
168     }
169
170     public synchronized IdentityProvider getIdentityProvider(JalistoProperties properties) {
171         throw new UnsupportedOperationException JavaDoc();
172     }
173
174     public synchronized LogicalSystemPageAccess getLogicalAccess(JalistoProperties properties) {
175         throw new UnsupportedOperationException JavaDoc();
176     }
177
178     public synchronized InternalMetaRepository getMetaRepository(JalistoProperties properties) {
179         throw new UnsupportedOperationException JavaDoc();
180     }
181
182     public synchronized Object JavaDoc getSessionId(JalistoProperties properties, Session session) {
183         throw new UnsupportedOperationException JavaDoc();
184     }
185
186     public void launchMBeanHtmlServer(JalistoProperties props) {
187         throw new UnsupportedOperationException JavaDoc();
188     }
189
190 }
191
Popular Tags