KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > Speedo


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  * Authors: S.Chassande-Barrioz.
25  *
26  */

27 package org.objectweb.speedo;
28
29 import java.util.Arrays JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.Collections JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.Properties JavaDoc;
36
37 import javax.jdo.JDOUserException;
38 import javax.jdo.PersistenceManager;
39 import javax.jdo.PersistenceManagerFactory;
40 import javax.jdo.datastore.DataStoreCache;
41 import javax.jdo.listener.InstanceLifecycleListener;
42 import javax.naming.InitialContext JavaDoc;
43 import javax.naming.NamingException JavaDoc;
44
45 import org.objectweb.fractal.adl.Factory;
46 import org.objectweb.fractal.adl.FactoryFactory;
47 import org.objectweb.fractal.api.Component;
48 import org.objectweb.fractal.api.Interface;
49 import org.objectweb.fractal.api.control.BindingController;
50 import org.objectweb.fractal.api.control.ContentController;
51 import org.objectweb.fractal.jmx.comm.CommunicatorAttributes;
52 import org.objectweb.fractal.util.Fractal;
53 import org.objectweb.jorm.api.PMapper;
54 import org.objectweb.jorm.mapper.rdb.lib.ConnectionSpecJDBC;
55 import org.objectweb.perseus.cache.api.CacheAttributeController;
56 import org.objectweb.perseus.concurrency.pessimistic.PessimisticConcurrencyManagerAC;
57 import org.objectweb.perseus.dependency.api.DependencyGraph;
58 import org.objectweb.perseus.pool.api.PoolAttributes;
59 import org.objectweb.speedo.api.Debug;
60 import org.objectweb.speedo.api.SpeedoException;
61 import org.objectweb.speedo.api.SpeedoProperties;
62 import org.objectweb.speedo.api.SpeedoVersion;
63 import org.objectweb.speedo.api.TransactionListener;
64 import org.objectweb.speedo.jmx.JMXConfigurator;
65 import org.objectweb.speedo.lib.FractalHelper;
66 import org.objectweb.speedo.mapper.api.JormFactoryAttributes;
67 import org.objectweb.speedo.mapper.api.MapperAttributes;
68 import org.objectweb.speedo.mapper.rdb.JDBCMapperAttributes;
69 import org.objectweb.speedo.pm.api.ProxyManager;
70 import org.objectweb.speedo.pm.api.ProxyManagerFactory;
71 import org.objectweb.speedo.query.api.QueryManagerAttribute;
72 import org.objectweb.speedo.sequence.api.SequenceManager;
73 import org.objectweb.speedo.workingset.lib.SpeedoTransaction;
74 import org.objectweb.util.monolog.Monolog;
75 import org.objectweb.util.monolog.api.BasicLevel;
76 import org.objectweb.util.monolog.api.Loggable;
77 import org.objectweb.util.monolog.api.Logger;
78 import org.objectweb.util.monolog.api.LoggerFactory;
79
80 /**
81  * This class is a client helper which permits to create a new speedo
82  * PersistentManagerFactory. Due to the JDO constraint the persistence manager
83  * factory implementation must have a public empty contructor. But the use of
84  * the fractal component (www.objectweb.org/fractal) needs to use a
85  * fractal implementation to initialize components. Then this class is an
86  * implementation of the PersistentManagerFactory interface which delegates all
87  * calls on a persistent manager factory delegate. The constructor of this class
88  * make the components creation and their initialization via Julia (fractal
89  * implementation).
90  *
91  * @author S.Chassande-Barrioz
92  */

93 public class Speedo implements PersistenceManagerFactory, ProxyManagerFactory {
94
95     public final static String JavaDoc CONNECTION_SPEC_FACTORY =
96         "org.objectweb.speedo.connectionSpecFactory";
97
98     private final static String JavaDoc LOGGER_NAME = SpeedoProperties.LOGGER_NAME + ".init";
99     private final static String JavaDoc SPEEDO_TEMPLATE = "org.objectweb.speedo.Speedo";
100     private final static String JavaDoc SPEEDO_JMX_TEMPLATE = "org.objectweb.speedo.SpeedoJMX";
101     private final static String JavaDoc OPTIMISTIC_CONCURRENCY_TEMPLATE =
102         "org.objectweb.perseus.persistence.concurrency.POptimisticConcurrencyManager";
103     private final static String JavaDoc PESSIMISTIC_CONCURRENCY_TEMPLATE =
104         "org.objectweb.perseus.persistence.concurrency.PPessimisticConcurrencyManager";
105     private final static String JavaDoc DBDELEGATE_CONCURRENCY_TEMPLATE =
106         "org.objectweb.perseus.persistence.concurrency.PDbDelegateConcurrencyManager";
107     public final static String JavaDoc PM_POOL_PATH = "proxy-manager-pool";
108     public final static String JavaDoc MEMORY_CACHE_PATH = "tpm.cache-manager";
109     public final static String JavaDoc DEPENDENCY_GRAPH_PATH = "tpm.dependency-graph";
110     public final static String JavaDoc QUERY_CACHE_PATH = "compiled-query-cache";
111     public final static String JavaDoc QUERY_MANAGER = "query-manager";
112     public final static String JavaDoc CONNECTION_POOL_PATH = "mapper.pool";
113     public final static String JavaDoc MONOLOG_FACTORY_PATH = "monolog-factory";
114     public final static String JavaDoc PRIMITIVE_MAPPER_PATH = "mapper.mapper";
115     public final static String JavaDoc JORM_FACTORY_PATH = "mapper.jorm-factory";
116     public final static String JavaDoc PMF_PATH = "proxy-manager-factory";
117     public final static String JavaDoc JMX_AGENT_PATH = "agent";
118     public final static String JavaDoc HTML_JMX_AGENT_PATH = JMX_AGENT_PATH + ".html";
119
120
121     private static Map JavaDoc INSTANCES = new HashMap JavaDoc();
122     private final static String JavaDoc FRACTAL_PROVIDER = "fractal.provider";
123     private final static String JavaDoc DEFAULT_FRACTAL_PROVIDER
124             = "org.objectweb.fractal.julia.Julia";
125
126     private final static String JavaDoc JULIA_LOADER = "julia.loader";
127     private final static String JavaDoc DEFAULT_JULIA_LOADER
128             = "org.objectweb.fractal.julia.loader.DynamicLoader";
129
130     private final static String JavaDoc JULIA_CONFIG = "julia.config";
131     private final static String JavaDoc DEFAULT_JULIA_CONFIG = "julia.cfg";
132     
133     private static Factory factory = null;
134     private static Component speedoTemplate = null;
135
136     // method called by the JDOHelper.getPersistenceManagerFactory method
137
public static PersistenceManagerFactory getPersistenceManagerFactory(
138             Properties JavaDoc props) throws Throwable JavaDoc {
139         return getPersistenceManagerFactory((Map JavaDoc) props);
140     }
141     // method called by the JDOHelper.getPersistenceManagerFactory method
142
public static PersistenceManagerFactory getPersistenceManagerFactory(
143             Map JavaDoc m) throws Throwable JavaDoc {
144         Object JavaDoc instance;
145         synchronized (INSTANCES) {
146             instance = INSTANCES.get(m);
147             if (instance == null) {
148                 instance = new Speedo(m);
149                 INSTANCES.put(m, instance);
150             }
151         }
152         return (PersistenceManagerFactory) instance;
153     }
154
155     public static void clearInstances() {
156         INSTANCES.clear();
157     }
158
159     /**
160      * The persistence manager factory delegate
161      */

162     private PersistenceManagerFactory delegate = null;
163     ProxyManagerFactory pmfComponent = null;
164     private Logger logger = null;
165     private Component speedo = null;
166     boolean isPropertiesInitialized = false;
167
168     public Speedo() throws Throwable JavaDoc {
169         getSpeedoComponent(null);
170         isPropertiesInitialized = false;
171     }
172     /**
173      * It creates and initializes a real SpeedoProxyManagerFactory with
174      * Julia (Fractal implementation).
175      */

176     public Speedo(Map JavaDoc props) throws Throwable JavaDoc {
177         try {
178             init(getSpeedoComponent(props), props);
179             isPropertiesInitialized = true;
180         } catch(Throwable JavaDoc e) {
181             System.err.println("Error during the instanciation of the Speedo " +
182                     "persistence manager factory:");
183             e.printStackTrace(System.err);
184             throw e;
185         }
186     }
187
188     public ProxyManagerFactory getPMFComponent() throws Exception JavaDoc {
189         return pmfComponent;
190     }
191
192     private Factory getADLFactory () throws Exception JavaDoc {
193         if (factory == null) {
194             factory = FactoryFactory.getFactory(FactoryFactory.FRACTAL_BACKEND);
195         }
196         return factory;
197     }
198     
199     private static Object JavaDoc getProperty(Map JavaDoc m, String JavaDoc propName) {
200         return m.get(propName);
201     }
202
203     private static String JavaDoc getProperty(Map JavaDoc m, String JavaDoc propName, String JavaDoc defaultValue) {
204         Object JavaDoc res = m.get(propName);
205         if (res instanceof String JavaDoc) {
206             return (String JavaDoc) res;
207         } else {
208             return defaultValue;
209         }
210     }
211     private Component getSpeedoComponent(Map JavaDoc props) throws Throwable JavaDoc {
212         
213         if (speedo == null) {
214             //use Julia as Fractal implementation
215
System.setProperty(FRACTAL_PROVIDER, DEFAULT_FRACTAL_PROVIDER);
216             System.setProperty(JULIA_LOADER, DEFAULT_JULIA_LOADER);
217             System.setProperty(JULIA_CONFIG, DEFAULT_JULIA_CONFIG);
218
219             //Allocate a Logger through the LoggerFactory component
220

221             Monolog.initialize();
222
223             LoggerFactory loggerFactory = Monolog.monologFactory;
224             logger = loggerFactory.getLogger(LOGGER_NAME);
225             String JavaDoc templateName = SPEEDO_TEMPLATE;
226             if (props != null
227                     && isTrue(getProperty(props, SpeedoProperties.JMX, "false"))) {
228                 templateName = SPEEDO_JMX_TEMPLATE;
229             }
230             //instanciate the Speedo component
231
try {
232                 if (speedoTemplate == null) {
233                     speedoTemplate = (Component)getADLFactory().newComponent(
234                             templateName,
235                             Collections.singletonMap("template", "true"));
236                 }
237                 //speedo = (Component)getADLFactory().newComponent(SPEEDO_TEMPLATE, null);
238
speedo = Fractal.getFactory(speedoTemplate).newFcInstance();
239             } catch (Throwable JavaDoc e) {
240                 System.err.println("Error during the template loading or the " +
241                         "component instanciation '" + SPEEDO_TEMPLATE + "': ");
242                 throw e;
243             }
244             Fractal.getNameController(speedo).setFcName("org.objectweb.speedo");
245             delegate = (PersistenceManagerFactory) speedo.getFcInterface("persistence-manager-factory");
246         }
247         return speedo;
248     }
249     
250     public void init(Component speedo, Map JavaDoc pmfProps) throws Throwable JavaDoc {
251         logger.log(BasicLevel.INFO, "Speedo " + SpeedoVersion.SPEEDO_VERSION
252                 + " is starting ...");
253
254         //Manage properties of the PersistenceManagerFactory
255
//--------------------------------------------------
256
Map JavaDoc props = new HashMap JavaDoc();
257         props.putAll(pmfProps);
258         String JavaDoc strval;
259
260         props.remove(SpeedoProperties.JDO_PERSISTENCE_MANAGER_FACTORY_CLASS);
261
262         strval = getProperty(props, SpeedoProperties.IMRICATED_PM_ALLOWED, "false");
263         props.remove(SpeedoProperties.IMRICATED_PM_ALLOWED);
264         boolean imbricatedPM = Boolean.valueOf(strval).booleanValue();
265         if (imbricatedPM) {
266             logger.log(BasicLevel.INFO, "PM reused on imbricated PMF.getPM()");
267         }
268         
269         //Debug Mode
270
strval = getProperty(props, SpeedoProperties.DEBUG, null);
271         props.remove(SpeedoProperties.DEBUG);
272         if (strval != null) {
273             Debug.ON = Boolean.valueOf(strval).booleanValue();
274             logger.log(BasicLevel.INFO, SpeedoProperties.DEBUG + ": " + Debug.ON);
275         }
276
277         boolean useConnectionFactory = configureMapper(speedo, props);
278         configurePool(getSubComponent(speedo, PM_POOL_PATH),
279                 "PersistenceManager pool: ",
280                 SpeedoProperties.PM_POOL_MIN,
281                 SpeedoProperties.PM_POOL_MAX,
282                 SpeedoProperties.PM_POOL_TTL,
283                 SpeedoProperties.PM_POOL_INACTIVETTL,
284                 SpeedoProperties.PM_POOL_TIMEOUT,
285                 props);
286         configureCache(getSubComponent(speedo, MEMORY_CACHE_PATH),
287                 "Persistent objects cache: ",
288                 SpeedoProperties.CACHE_SIZE,
289                 SpeedoProperties.CACHE_AUTO_CLEAN_SIZE,
290                 SpeedoProperties.CACHE_AUTO_CLEAN_THRESHOLD,
291                 SpeedoProperties.CACHE_REPLCAEMENT,
292                 props);
293         configureCache(getSubComponent(speedo, QUERY_CACHE_PATH),
294                 "Compiled query cache: ",
295                 SpeedoProperties.COMPILED_QUERY_CACHE_SIZE,
296                 SpeedoProperties.COMPILED_QUERY_CACHE_AUTO_CLEAN_SIZE,
297                 SpeedoProperties.COMPILED_QUERY_CACHE_AUTO_CLEAN_THRESHOLD,
298                 SpeedoProperties.COMPILED_QUERY_CACHE_POLICY,
299                 props);
300
301         //deprecated properties
302
final String JavaDoc TM_NAME_old = "org.objectweb.perseus.connector.ra.jdo.TMName";
303         strval = getProperty(props, TM_NAME_old, "");
304         if (strval.length()>0) {
305             logger.log(BasicLevel.WARN, "Property " + TM_NAME_old
306                     + " is deprecated, you must use " + SpeedoProperties.TM_NAME);
307             props.remove(TM_NAME_old);
308             pmfProps.remove(TM_NAME_old);
309             if (getProperty(props, SpeedoProperties.TM_NAME) == null) {
310                 props.put(SpeedoProperties.TM_NAME, strval);
311                 pmfProps.put(SpeedoProperties.TM_NAME, strval);
312             }
313         }
314
315         // Transaction managed by an application server
316
strval = getProperty(props, SpeedoProperties.MANAGED, "");
317         if (strval.length()>0) {
318             boolean b = isTrue(strval);
319             if (!useConnectionFactory && b) {
320                 String JavaDoc msg = "In a managed environnement, a connection factory is required";
321                 logger.log(BasicLevel.ERROR, msg);
322                 throw new JDOUserException(msg);
323             }
324             logger.log(BasicLevel.INFO, SpeedoProperties.MANAGED + ": Speedo is used "
325                     + (b
326                     ? "in a managed environnement"
327                     : "in stand alone"));
328
329             //TransactionManager JNDI name
330
strval = getProperty(props, SpeedoProperties.TM_NAME, "");
331             props.remove(SpeedoProperties.TM_NAME);
332             logger.log(BasicLevel.INFO, SpeedoProperties.TM_NAME + ": "
333                     + (strval.length()>0
334                     ? strval
335                     : ": no value specified, use a well known application server"));
336         } else {
337             props.remove(SpeedoProperties.TM_NAME);
338         }
339
340         //Listener of Transaction life cycle (statistic)
341
strval = getProperty(props, SpeedoProperties.TX_LISTENER, "");
342         if (strval.length()>0) {
343             try {
344                 SpeedoTransaction.txListener = (TransactionListener)
345                         Class.forName(strval).newInstance();
346                 if (SpeedoTransaction.txListener instanceof Loggable) {
347                     ((Loggable) SpeedoTransaction.txListener)
348                             .setLoggerFactory(Monolog.monologFactory);
349                 }
350                 logger.log(BasicLevel.INFO, "Transaction listener: " + strval);
351             } catch (Exception JavaDoc e) {
352                 logger.log(BasicLevel.WARN,
353                         "Impossible to instanciate the TransactionListener specified '"
354                         + strval + "': ", e);
355             }
356         }
357
358         configurePrefetching(speedo, props);
359         configureConcurrencyManager(speedo, props);
360         boolean jmxOn = configureJMX(speedo, props);
361         
362         //managed other properties
363
for (Iterator JavaDoc it = props.entrySet().iterator(); it.hasNext();) {
364             Map.Entry JavaDoc me = (Map.Entry JavaDoc) it.next();
365             String JavaDoc key = (String JavaDoc) me.getKey();
366             String JavaDoc value = (String JavaDoc) me.getValue();
367             boolean knownProperty = true;
368             if (SpeedoProperties.JDO_OPTION_RETAIN_VALUES.equals(key)) {
369                 delegate.setRetainValues(Boolean.valueOf(value).booleanValue());
370
371             } else if (SpeedoProperties.JDO_OPTION_RESTORE_VALUES.equals(key)) {
372                 delegate.setRestoreValues(Boolean.valueOf(value).booleanValue());
373
374             } else if (SpeedoProperties.JDO_OPTION_IGNORE_CACHE.equals(key)) {
375                 delegate.setIgnoreCache(Boolean.valueOf(value).booleanValue());
376
377             } else if (SpeedoProperties.JDO_OPTION_NON_TRANSACTIONAL_READ.equals(key)) {
378                 delegate.setNontransactionalRead(Boolean.valueOf(value).booleanValue());
379
380             } else if (SpeedoProperties.JDO_OPTION_NON_TRANSACTIONAL_WRITE.equals(key)) {
381                 delegate.setNontransactionalWrite(Boolean.valueOf(value).booleanValue());
382
383             } else if (SpeedoProperties.JDO_OPTION_MULTITREADED.equals(key)) {
384                 delegate.setMultithreaded(Boolean.valueOf(value).booleanValue());
385
386             } else {
387                 knownProperty = false;
388             }
389             if (knownProperty) {
390                 logger.log(BasicLevel.INFO, key + ": " + value);
391                 it.remove();
392             }
393         }
394
395         //Warn the unknwon properties
396
for (Iterator JavaDoc it = props.entrySet().iterator(); it.hasNext();) {
397             Map.Entry JavaDoc me = (Map.Entry JavaDoc) it.next();
398             String JavaDoc key = (String JavaDoc) me.getKey();
399             if (key.startsWith(SpeedoProperties.CACHE_CLASS_POLICY+"(")
400                     || key.startsWith(SpeedoProperties.USER_CACHE_CLASS_POLICY+"(")
401                     || key.startsWith(SpeedoProperties.PREFETCH_ON_GENCLASS+"(")
402                     || key.startsWith(SpeedoProperties.PREFETCH_ON_QUERY+"(")
403                     || key.startsWith(SpeedoProperties.PREFETCH_ON_EXTENT+"(")
404                     ) {
405                 continue;
406             }
407             String JavaDoc value = (String JavaDoc) me.getValue();
408             logger.log(BasicLevel.WARN, "The (" + key + ", " + value
409                 + ") property is not managed");
410         }
411
412         delegate.getProperties().putAll(pmfProps);
413         Fractal.getLifeCycleController(speedo).startFc();
414         pmfComponent = (ProxyManagerFactory) getSubComponent(
415                 ((Interface) delegate).getFcItfOwner(), PMF_PATH)
416                 .getFcInterface("proxy-manager-factory");
417         if (jmxOn) {
418             new JMXConfigurator(speedo, logger).init();
419         }
420     }
421     private Component getSubComponent(Component parent,
422             String JavaDoc path) throws Exception JavaDoc {
423         return FractalHelper.getSubComponent(parent, path, logger);
424     }
425
426     private void configurePool(Component pool,
427                                String JavaDoc poolLabel,
428                                String JavaDoc minProp,
429                                String JavaDoc maxProp,
430                                String JavaDoc ttlProp,
431                                String JavaDoc inactivettlProp,
432                                String JavaDoc timeoutProp,
433                                Map JavaDoc props) throws Exception JavaDoc {
434         String JavaDoc strval = null;
435         int poolMinSize = -2;
436         int poolMaxSize = -2;
437         long poolTTL = -2;
438         long poolInactiveTTL = -2;
439         long poolTimeout = -2;
440         boolean conf = false;
441         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(poolLabel);
442         final String JavaDoc sep = ", ";
443         if (minProp != null) {
444             strval = getProperty(props, minProp, "");
445             if (strval.length() > 0) {
446                 props.remove(minProp);
447                 poolMinSize = Integer.parseInt(strval);
448                 if (conf) {
449                     sb.append(sep);
450                 }
451                 sb.append("min=" + strval);
452                 conf = true;
453             }
454         }
455         if (maxProp != null) {
456             strval = getProperty(props, maxProp, "");
457             if (strval.length() > 0) {
458                 props.remove(maxProp);
459                 if (strval.equalsIgnoreCase("nolimit")) {
460                     poolMaxSize = -1;
461                 } else {
462                     poolMaxSize = Integer.parseInt(strval);
463                 }
464                 if (conf) {
465                     sb.append(sep);
466                 }
467                 sb.append("max=" + strval);
468                 conf = true;
469             }
470         }
471         if (ttlProp != null) {
472             strval = getProperty(props, ttlProp, "");
473             if (strval.length() > 0) {
474                 props.remove(ttlProp);
475                 try {
476                     poolTTL = 1000 * Long.parseLong(strval);
477                 } catch (NumberFormatException JavaDoc e) {
478                     poolTTL = -1;
479                     strval = "NOTTL";
480                 }
481                 if (conf) {
482                     sb.append(sep);
483                 }
484                 sb.append("ttl=" + strval);
485                 conf = true;
486             }
487         }
488         if (inactivettlProp != null) {
489             strval = getProperty(props, inactivettlProp, "");
490             if (strval.length() > 0) {
491                 props.remove(inactivettlProp);
492                 try {
493                     poolInactiveTTL = 1000 * Long.parseLong(strval);
494                 } catch (NumberFormatException JavaDoc e) {
495                     poolInactiveTTL = -1;
496                     strval = "NOTTL";
497                 }
498                 if (conf) {
499                     sb.append(sep);
500                 }
501                 sb.append("inactivettlProp=" + strval);
502                 conf = true;
503             }
504         }
505         if (timeoutProp != null) {
506             strval = getProperty(props, timeoutProp, "");
507             if (strval.length() > 0) {
508                 props.remove(timeoutProp);
509                 try {
510                     poolTimeout = Long.parseLong(strval);
511                 } catch (NumberFormatException JavaDoc e) {
512                     poolTimeout = -1;
513                     strval = "WAIT";
514                 }
515                 if (conf) {
516                     sb.append(sep);
517                 }
518                 sb.append("timeout=" + strval);
519                 conf = true;
520             }
521         }
522         if (conf) {
523             logger.log(BasicLevel.INFO, sb.toString());
524               PoolAttributes poolAttr;
525               try {
526                 poolAttr = (PoolAttributes)
527                             Fractal.getAttributeController(pool);
528               } catch (Exception JavaDoc e) {
529                 Component[] children = Fractal.getContentController(speedo).getFcSubComponents();
530                 String JavaDoc[] strs= new String JavaDoc[children.length];
531                 for (int i = 0; i < strs.length; ++i) {
532                   strs[i] = Fractal.getNameController(children[i]).getFcName();
533                 }
534                 throw new RuntimeException JavaDoc("" + Arrays.asList(strs));
535               }
536             if (poolMaxSize > -2) {
537                 poolAttr.setMaxSize(poolMaxSize);
538             }
539             if (poolMinSize > -2) {
540                 poolAttr.setMinSize(poolMinSize);
541             }
542             if (poolTTL > -2) {
543                 poolAttr.setTTL(poolTTL);
544             }
545             if (poolInactiveTTL > -2) {
546                 poolAttr.setInactiveTTL(poolInactiveTTL);
547             }
548             if (poolTimeout > -2) {
549                 poolAttr.setTimeout(poolTimeout);
550             }
551         }
552     }
553
554     /**
555      * Configures the memory cache.
556      * @param speedo is the speedo composite component
557      * @param props is the speedo initialisation properties
558      */

559     private void configureCache(Component cm,
560             String JavaDoc cacheLabel,
561             String JavaDoc sizeProp,
562             String JavaDoc autoCleanSizeProp,
563             String JavaDoc autoCleanThresholdProp,
564             String JavaDoc policyProp,
565             Map JavaDoc props)
566             throws Exception JavaDoc {
567         int cacheSize = -2;
568         String JavaDoc autoCleanSize = null;
569         String JavaDoc autoCleanThreshold = null;
570         String JavaDoc policy = null;
571         //configure the cache size
572
StringBuffer JavaDoc sb = new StringBuffer JavaDoc(cacheLabel);
573         final String JavaDoc sep = ", ";
574         boolean conf = false;
575         String JavaDoc strval = getProperty(props, sizeProp, "");
576         if (strval.length()>0) {
577             props.remove(sizeProp);
578             if (strval.equalsIgnoreCase("nolimit")) {
579                 cacheSize = CacheAttributeController.NO_LIMIT;
580             } else {
581                 cacheSize = Integer.parseInt(strval);
582             }
583             if (conf) {
584                 sb.append(sep);
585             }
586             sb.append("max size=" + strval);
587             conf = true;
588         }
589
590         //configure the cache auto clean size
591
strval = getProperty(props, autoCleanSizeProp, "");
592         if (strval.length() > 0) {
593             props.remove(autoCleanSizeProp);
594             autoCleanSize = strval;
595             if (conf) {
596                 sb.append(sep);
597             }
598             sb.append("auto replacement size=" + strval);
599             conf = true;
600         }
601
602         //configure the cache auto clean size
603
strval = getProperty(props, autoCleanThresholdProp, "");
604         if (strval.length() > 0) {
605             props.remove(autoCleanThresholdProp);
606             autoCleanThreshold = strval;
607             if (conf) {
608                 sb.append(sep);
609             }
610             sb.append("auto replacement threshold=" + strval);
611             conf = true;
612         }
613
614         //configure the replacement policy of the cache (Replacement manager)
615
strval = getProperty(props, policyProp, "");
616         if (strval.length() > 0) {
617             props.remove(policyProp);
618             policy = strval;
619             if (conf) {
620                 sb.append(sep);
621             }
622             sb.append("replacement policy=" + strval);
623             conf = true;
624         }
625         if (!conf) {
626             return;
627         }
628         logger.log(BasicLevel.INFO, sb.toString());
629         Component cmC = getSubComponent(cm, "cache-manager");
630         CacheAttributeController cacheAttr = (CacheAttributeController)
631             Fractal.getAttributeController(cmC);
632         if (cacheSize > -2) {
633             cacheAttr.setMaxObjects(cacheSize);
634         }
635         if (autoCleanSize != null) {
636             cacheAttr.setAutoCleanSize(autoCleanSize);
637         }
638         if (autoCleanThreshold != null) {
639             cacheAttr.setAutoCleanThreshold(autoCleanThreshold);
640         }
641         if (policy != null) {
642             String JavaDoc tempName = null;
643             if (SpeedoProperties.CACHE_REPLCAEMENT_LRU.equalsIgnoreCase(policy)) {
644             } else if (SpeedoProperties.CACHE_REPLCAEMENT_MRU.equalsIgnoreCase(policy)) {
645                 tempName = "org.objectweb.perseus.cache.replacement.lib.MRUReplacementManager";
646             } else if (SpeedoProperties.CACHE_REPLCAEMENT_FIFO.equalsIgnoreCase(policy)) {
647                 tempName = "org.objectweb.perseus.cache.replacement.lib.FIFOReplacementManager";
648             } else {
649                 logger.log(BasicLevel.ERROR, new SpeedoException(
650                         "Unmanaged cache replacement policy: " + policy));
651             }
652             if (tempName != null) {
653                 //unbind the rm from the composite
654
Fractal.getBindingController(cm).unbindFc("replacement-manager");
655                 //unbind the rm from the primitive cm
656
Fractal.getBindingController(cmC).unbindFc("replacement-manager");
657                 //unbind the primitive cm from the old rm
658
Fractal.getBindingController(
659                         getSubComponent(cm, "replacement-manager"))
660                         .unbindFc("unbind-manager");
661
662                 //remove the old rm from the composite
663
Fractal.getContentController(cm).removeFcSubComponent(
664                         getSubComponent(cm, "replacement-manager"));
665
666                 //instanciate the new component
667
Component new_rm = (Component)getADLFactory().newComponent(tempName, null);
668                 Fractal.getNameController(new_rm).setFcName("replacement-manager");
669
670                 //Add the new rm in the composite
671
Fractal.getContentController(cm).addFcSubComponent(new_rm);
672
673                 Object JavaDoc rm = new_rm.getFcInterface("replacement-manager");
674                 //bind the rm to the composite
675
Fractal.getBindingController(cm).bindFc("replacement-manager", rm);
676                 //bind the rm to the primitive cm
677
Fractal.getBindingController(cmC).bindFc("replacement-manager", rm);
678                 //bind the primitive cm to the new rm
679
Fractal.getBindingController(new_rm).bindFc("unbind-manager",
680                         cmC.getFcInterface("unbind-manager"));
681             }
682         }
683     }
684
685
686     private void configureConcurrencyManager(Component speedo,
687                                              Map JavaDoc props)
688             throws Exception JavaDoc {
689         String JavaDoc tempName;
690         String JavaDoc concurrencyMode;
691         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Transaction/Concurrency management: ");
692         String JavaDoc strval = getProperty(props, SpeedoProperties.JDO_OPTION_OPTIMISTIC, "false");
693         boolean optimistic = isTrue(strval);
694         sb.append("mode=").append((optimistic ? "Optimistic" : "Pessimitic"));
695         strval = getProperty(props, SpeedoProperties.TRANSACTION_LOCKING,
696                 SpeedoProperties.SPEEDO_TRANSACTION_LOCKING);
697         props.remove(SpeedoProperties.TRANSACTION_LOCKING);
698         //fetch the composite TPM
699
Component composite_tpm = getSubComponent(speedo, "tpm");
700         Component cm = getSubComponent(composite_tpm, "concurrency-manager");
701         if (strval.equals(SpeedoProperties.DB_TRANSACTION_LOCKING)) {
702             tempName = DBDELEGATE_CONCURRENCY_TEMPLATE;
703             sb.append(", delegated to database");
704         } else {
705             sb.append(", managed by Speedo");
706             if (!optimistic) {
707                 //Configure the pessimistic concurrency manager
708

709                 //policy= mutex | rw-fifo | rw-reader
710
strval = getProperty(props,
711                         SpeedoProperties.TRANSACTION_LOCKING_PESSIMISTIC_POLICY,
712                         SpeedoProperties.TRANSACTION_LOCKING_PESSIMISTIC_POLICY_RW_FIFO);
713                 props.remove(SpeedoProperties.TRANSACTION_LOCKING_PESSIMISTIC_POLICY);
714                 PessimisticConcurrencyManagerAC pcmAC = null;
715                 if (!strval.equals(SpeedoProperties.TRANSACTION_LOCKING_PESSIMISTIC_POLICY_RW_FIFO)) {
716                     pcmAC = (PessimisticConcurrencyManagerAC)
717                         Fractal.getAttributeController(cm);
718                     pcmAC.setPolicy(strval);
719                     sb.append(", locking policy=").append(strval);
720                 }
721
722                 //locking level = instance | field
723
strval = getProperty(props,
724                         SpeedoProperties.TRANSACTION_LOCKING_LEVEL_ENABLETHIN,
725                         "false");
726                 props.remove(SpeedoProperties.TRANSACTION_LOCKING_LEVEL_ENABLETHIN);
727                 boolean b = isTrue(strval);
728                 if (b) {
729                     logger.log(BasicLevel.INFO, "Speedo pessimistic thin locking level: enabled");
730                     pcmAC = (PessimisticConcurrencyManagerAC)
731                         Fractal.getAttributeController(cm);
732                     pcmAC.setThinkLockAllowed(true);
733                     sb.append(", With thin locking level");
734                 }
735                 logger.log(BasicLevel.INFO, sb.toString());
736                 return;
737             }
738             tempName = OPTIMISTIC_CONCURRENCY_TEMPLATE;
739         }
740         logger.log(BasicLevel.INFO, sb.toString());
741         props.remove(SpeedoProperties.JDO_OPTION_OPTIMISTIC);
742
743         ContentController tpmCC = Fractal.getContentController(composite_tpm);
744         //fetch the primitive concurrency manager
745
BindingController tpmBC = Fractal.getBindingController(
746                 getSubComponent(composite_tpm, "transactional-persistence-manager"));
747         tpmBC.unbindFc("concurrency-manager");
748
749         //Remove the old concurrency manager
750
BindingController cmBC = Fractal.getBindingController(cm);
751         cmBC.unbindFc("state-manager");
752         cmBC.unbindFc("storage-manager");
753         cmBC.unbindFc("dependency-graph");
754         tpmCC.removeFcSubComponent(cm);
755
756
757         //instanciate the new ConcurrencyManager
758
cm = (Component)getADLFactory().newComponent(tempName, null);
759         //Add the new concurrency manager into the composite
760
tpmCC.addFcSubComponent(cm);
761         //bind the server interface of the new concurrency manager
762
cmBC = Fractal.getBindingController(cm);
763         cmBC.bindFc("state-manager",
764                 tpmCC.getFcInternalInterface("state-manager"));
765         cmBC.bindFc("storage-manager",
766                 tpmCC.getFcInternalInterface("storage-manager"));
767         cmBC.bindFc("dependency-graph",
768                 getSubComponent(composite_tpm, "dependency-graph").getFcInterface("dependency-graph"));
769
770         //bind the client interface of the new ConcurrencyManager
771
tpmBC.bindFc("concurrency-manager", cm.getFcInterface("concurrency-manager"));
772     }
773
774     private void configurePrefetching(Component speedo,
775                                       Map JavaDoc props) throws Throwable JavaDoc {
776         //Data prefetching on queries
777
boolean prefetch = true;
778         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("Data prefetching: ");
779         String JavaDoc strval = getProperty(props, SpeedoProperties.PREFETCH, "");
780         if (strval.length()>0) {
781             prefetch = !isFalse(strval);
782             props.remove(SpeedoProperties.PREFETCH);
783         }
784         Component qm = getSubComponent(speedo, QUERY_MANAGER);
785         QueryManagerAttribute qma = ((QueryManagerAttribute) Fractal.getAttributeController(qm));
786         if (!prefetch) {
787             qma.setPrefetchActivatedOnQuery(false);
788             qma.setPrefetchActivatedOnExtent(false);
789             logger.log(BasicLevel.INFO, sb.append("NONE").toString());
790             return;
791         }
792         boolean prefetchOnQuery = qma.getPrefetchActivatedOnQuery();
793         boolean prefetchOnExtent = qma.getPrefetchActivatedOnExtent();
794         boolean prefetchOnGenClass = true;
795         String JavaDoc sep = ", ";
796
797         boolean oneOf = false;
798         strval = getProperty(props, SpeedoProperties.PREFETCH_ON_QUERY, "");
799         if (strval.length()>0) {
800             prefetchOnQuery = !isFalse(strval);
801             props.remove(SpeedoProperties.PREFETCH_ON_QUERY);
802         }
803         if (prefetchOnQuery) {
804             if (oneOf) {
805                 sb.append(sep);
806             }
807             sb.append("QUERY");
808         }
809         oneOf |= prefetchOnQuery;
810         qma.setPrefetchActivatedOnQuery(prefetchOnQuery);
811
812         strval = getProperty(props, SpeedoProperties.PREFETCH_ON_EXTENT, "");
813         if (strval.length()>0) {
814             prefetchOnExtent = !isFalse(strval);
815             props.remove(SpeedoProperties.PREFETCH_ON_EXTENT);
816         }
817         if (prefetchOnExtent) {
818             if (oneOf) {
819                 sb.append(sep);
820             }
821             sb.append("EXTENT");
822         }
823         oneOf |= prefetchOnExtent;
824         qma.setPrefetchActivatedOnExtent(prefetchOnExtent);
825
826         strval = getProperty(props, SpeedoProperties.PREFETCH_ON_GENCLASS, "");
827         if (strval.length()>0) {
828             prefetchOnGenClass= !isFalse(strval);
829             props.remove(SpeedoProperties.PREFETCH_ON_GENCLASS);
830         }
831         if (prefetchOnGenClass) {
832             if (oneOf) {
833                 sb.append(sep);
834             }
835             sb.append("COLLECTION");
836         }
837         oneOf |= prefetchOnGenClass;
838         
839         logger.log(BasicLevel.INFO, sb.toString());
840     }
841
842     /**
843      * Configures the mapper component
844      * @param speedo is the Speedo component
845      * @param props is the properties of Speedo
846      * @return true if a connection factory is used, false if the JDBC driver is
847      * used directly.
848      * @throws Throwable if an error or an exception occurs
849      */

850     private boolean configureMapper(Component speedo,
851                                  Map JavaDoc props) throws Throwable JavaDoc {
852         boolean useConnectionFactory;
853         String JavaDoc mapperName = getProperty(props, SpeedoProperties.MAPPER_NAME, "rdb.automatic");
854         props.remove(SpeedoProperties.MAPPER_NAME);
855
856         Component component = getSubComponent(speedo, PRIMITIVE_MAPPER_PATH);
857         String JavaDoc strval = null;
858         //Choose the mapper in according to the connection factory (JCA or JDBC)
859
String JavaDoc cfName = getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_FACTORY_NAME, null);
860         props.remove(SpeedoProperties.JDO_OPTION_CONNECTION_FACTORY_NAME);
861         useConnectionFactory = cfName != null && cfName.length() > 0;
862         MapperAttributes ma = (MapperAttributes) Fractal.getAttributeController(component);
863         if (useConnectionFactory) {
864             Object JavaDoc cf = null;
865             //There is a connection factory
866
try {
867                 InitialContext JavaDoc ic = new InitialContext JavaDoc();
868                 cf = ic.lookup(cfName);
869             } catch (NamingException JavaDoc e) {
870                 throw new SpeedoException(
871                         "Problem to get the connection factory in JNDI ("
872                         + cfName + ")", e);
873             }
874             if (cf == null) {
875                 throw new SpeedoException(
876                         "No connection factory registered in JNDI with the name "
877                         + cfName);
878             } else if (cf instanceof ConnectionSpecJDBC) {
879                 // Use the JDBC Mapper ==> nothing to do
880
} else if (cf instanceof javax.sql.DataSource JavaDoc) {
881                 // Use the JDBC Mapper ==> nothing to do
882
} else if (cf instanceof javax.resource.cci.ConnectionFactory JavaDoc) {
883                 System.out.println("The connection is JCA compliant: " + cf);
884                 throw new SpeedoException("JCA datasource no yet supported");
885             } else {
886                 throw new SpeedoException("The connection factory registered "
887                         + "in JNDI is not supported by Speedo " + cfName + " => "
888                         + cf);
889             }
890             boolean ignoring = removeProps(props, new String JavaDoc[]{
891                     SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old,
892                     SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old2,
893                     SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME,
894                     SpeedoProperties.JDO_OPTION_CONNECTION_URL,
895                     SpeedoProperties.JDO_OPTION_CONNECTION_USER_NAME,
896                     SpeedoProperties.JDO_OPTION_CONNECTION_PASSWORD});
897             if (ignoring) {
898                 logger.log(BasicLevel.WARN,
899                         "Ignoring direct JDBC access information (driver, url, user, password)");
900             }
901             ignoring = removeProps(props, new String JavaDoc[]{
902                     SpeedoProperties.CONNECTION_POOL_MIN,
903                     SpeedoProperties.CONNECTION_POOL_MAX,
904                     SpeedoProperties.CONNECTION_POOL_TTL,
905                     SpeedoProperties.CONNECTION_POOL_TIMEOUT});
906             if (ignoring) {
907                 logger.log(BasicLevel.WARN,
908                         "Ignoring connection pool configuration(min, max, ttl, timeout)");
909             }
910
911             //Assign the connection factory to the mapper
912
logger.log(BasicLevel.INFO, "Data source access through a connection factory found in JNDI:"
913                     + "\n\tjndi name: " + cfName
914                     + "\n\tconnection factory found: " + cf
915                     + "\n\tmapper name: " + mapperName);
916             PMapper mapper = (PMapper) component.getFcInterface("mapper");
917             mapper.setMapperName(mapperName);
918             mapper.setConnectionFactory(cf);
919
920         } else {
921             JDBCMapperAttributes jdbcma = (JDBCMapperAttributes) ma;
922
923             //deprecated properties
924
strval = getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old, "");
925             if (strval.length()>0) {
926                 logger.log(BasicLevel.WARN, "Property " + SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old
927                         + " is deprecated, you must use " + SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME);
928                 props.remove(SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old);
929                 
930                 if (getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME) == null) {
931                     props.put(SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME, strval);
932                 }
933             }
934             strval = getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old2, "");
935             if (strval.length()>0) {
936                 logger.log(BasicLevel.WARN, "Property " + SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old2
937                         + " is deprecated, you must use " + SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME);
938                 props.remove(SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME_old);
939                 
940                 if (getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME) == null) {
941                     props.put(SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME, strval);
942                 }
943             }
944             String JavaDoc jdbcDriverCN = getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME, null);
945             props.remove(SpeedoProperties.JDO_OPTION_CONNECTION_DRIVER_NAME);
946             String JavaDoc jdbcUser = getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_USER_NAME, null);
947             props.remove(SpeedoProperties.JDO_OPTION_CONNECTION_USER_NAME);
948             String JavaDoc jdbcUrl = getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_URL, null);
949             props.remove(SpeedoProperties.JDO_OPTION_CONNECTION_URL);
950             String JavaDoc jdbcPass = getProperty(props, SpeedoProperties.JDO_OPTION_CONNECTION_PASSWORD, null);
951             props.remove(SpeedoProperties.JDO_OPTION_CONNECTION_PASSWORD);
952             logger.log(BasicLevel.INFO, "Data source access through a jdbc driver:"
953                     + "\n\tdriver= " + jdbcDriverCN
954                     + "\n\turl= " + jdbcUrl
955                     + "\n\tuser= " + jdbcUser
956                     + "\n\tmapper name: " + mapperName);
957             jdbcma.setMapperName(mapperName);
958             jdbcma.setDriverClassName(jdbcDriverCN);
959             jdbcma.setURL(jdbcUrl);
960             jdbcma.setUserName(jdbcUser);
961             jdbcma.setPassword(jdbcPass);
962             jdbcma.setPoolConnection(true);
963
964             //configure the pool of connection
965
configurePool(getSubComponent(speedo, CONNECTION_POOL_PATH),
966                     "Connection pool: ",
967                     SpeedoProperties.CONNECTION_POOL_MIN,
968                     SpeedoProperties.CONNECTION_POOL_MAX,
969                     SpeedoProperties.CONNECTION_POOL_TTL,
970                     SpeedoProperties.CONNECTION_POOL_INACTIVETTL,
971                     SpeedoProperties.CONNECTION_POOL_TIMEOUT,
972                     props);
973         }
974         strval = (String JavaDoc) props.remove(SpeedoProperties.CONNECTION_CHECK);
975         if (strval != null) {
976             boolean v = isTrue(strval);
977             ma.setCheckConnectivityAtStartup(v);
978             if (!v) {
979                 logger.log(BasicLevel.INFO, "No connection checking at start up !");
980             }
981         }
982
983         //initialize the JormFactory with the mappingStructureRule attribute
984
byte mappingStructureRule = JormFactoryAttributes.CREATE_IF_REQUIRED;
985         strval = getProperty(props, SpeedoProperties.MAPPING_STRUCTURE, "");
986         if (strval.length()>0) {
987             props.remove(SpeedoProperties.MAPPING_STRUCTURE);
988             mappingStructureRule = getMappingStructure(strval);
989             if (mappingStructureRule == -1) {
990                 mappingStructureRule = JormFactoryAttributes.CREATE_IF_REQUIRED;
991                 logger.log(BasicLevel.WARN, "Unexpected value for the property '"
992                         + SpeedoProperties.MAPPING_STRUCTURE
993                         + "', found: '" + strval + "', expected ["
994                         + SpeedoProperties.MAPPING_STRUCTURE_DN
995                         + " | " + SpeedoProperties.MAPPING_STRUCTURE_DD
996                         + " | " + SpeedoProperties.MAPPING_STRUCTURE_CIR
997                         + " | " + SpeedoProperties.MAPPING_STRUCTURE_FC
998                         + "]");
999             }
1000        }
1001        component = getSubComponent(speedo, JORM_FACTORY_PATH);
1002        JormFactoryAttributes jfa = (JormFactoryAttributes)
1003                    Fractal.getAttributeController(component);
1004        jfa.setMappingStructureRule(mappingStructureRule);
1005        logger.log(BasicLevel.INFO, "Data Structure: "
1006                + getMappingStructureString(mappingStructureRule));
1007
1008        Properties JavaDoc jormFactoryProperties = new Properties JavaDoc();
1009        for (Iterator JavaDoc it = props.entrySet().iterator(); it.hasNext();) {
1010            Map.Entry JavaDoc me = (Map.Entry JavaDoc) it.next();
1011            String JavaDoc key = (String JavaDoc) me.getKey();
1012            String JavaDoc value = (String JavaDoc) me.getValue();
1013            boolean knownProperty = true;
1014            if (key.indexOf('(') != -1) {
1015                jormFactoryProperties.put(key, value);
1016            } else {
1017                knownProperty = false;
1018            }
1019            if (knownProperty) {
1020                logger.log(BasicLevel.INFO, key + ": " + value);
1021                it.remove();
1022            }
1023        }
1024        jfa.setSpeedoProperties(jormFactoryProperties);
1025        
1026        return useConnectionFactory;
1027    }
1028
1029    private boolean configureJMX(Component speedo,
1030             Map JavaDoc props) throws Throwable JavaDoc {
1031        String JavaDoc val = (String JavaDoc) props.remove(SpeedoProperties.JMX);
1032        if (val == null || !isTrue(val)) {
1033            return false;
1034        }
1035        //JMX must me configured
1036
if (Monolog.monologFactory.getLogger(SpeedoProperties.JMX)
1037                .isLoggable(BasicLevel.DEBUG)) {
1038            //active MX4J logging
1039
System.setProperty("mx4j.log.priority", "debug");
1040        }
1041        val = (String JavaDoc) props.remove(SpeedoProperties.JMX_HTTP_PORT);
1042        int port = 0;
1043        if (val != null) {
1044            try {
1045                port = Integer.parseInt(val);
1046            } catch (NumberFormatException JavaDoc e) {
1047                logger.log(BasicLevel.WARN, "Bad HTTP port for the administration console: " + val);
1048                port = -1;
1049            }
1050        }
1051        Component component = getSubComponent(speedo, HTML_JMX_AGENT_PATH);
1052        if (port < 0) {
1053            //unbind the html sub component
1054
Fractal.getBindingController(component).unbindFc("adminAtt");
1055            // remove the html sub component from the agent component.
1056
Fractal.getContentController(
1057                    getSubComponent(speedo, JMX_AGENT_PATH))
1058                        .removeFcSubComponent(component);
1059            logger.log(BasicLevel.INFO, "JMX activated");
1060        } else {
1061            if (port == 0) {
1062                //TODO: find a port
1063
port = 8000;
1064            }
1065            //Assign the port to the component
1066
CommunicatorAttributes att = (CommunicatorAttributes)
1067                Fractal.getAttributeController(component);
1068            att.setPort(port);
1069            logger.log(BasicLevel.INFO, "JMX and HTTP console on port '" + port + "' activated");
1070        }
1071        return true;
1072    }
1073    
1074    private boolean removeProps(Map JavaDoc props, String JavaDoc[] wanted) {
1075        boolean found = false;
1076        for (int i = 0; i < wanted.length; i++) {
1077            found |= props.remove(wanted[i]) != null;
1078        }
1079        return found;
1080    }
1081    
1082    private boolean isFalse(String JavaDoc val) {
1083        return "false".equalsIgnoreCase(val)
1084                || "off".equalsIgnoreCase(val)
1085                || "no".equalsIgnoreCase(val)
1086                || "non".equalsIgnoreCase(val)
1087                || "n".equalsIgnoreCase(val);
1088    }
1089
1090    private boolean isTrue(String JavaDoc val) {
1091        return "true".equalsIgnoreCase(val)
1092                || "on".equalsIgnoreCase(val)
1093                || "yes".equalsIgnoreCase(val)
1094                || "oui".equalsIgnoreCase(val)
1095                || "y".equalsIgnoreCase(val)
1096                || "o".equalsIgnoreCase(val);
1097    }
1098
1099    public static String JavaDoc getMappingStructureString(byte b) {
1100        switch(b) {
1101        case JormFactoryAttributes.DO_NOTHING:
1102            return SpeedoProperties.MAPPING_STRUCTURE_DN;
1103        case JormFactoryAttributes.DELETE_DATA:
1104            return SpeedoProperties.MAPPING_STRUCTURE_DD;
1105        case JormFactoryAttributes.FORCE_CREATE:
1106            return SpeedoProperties.MAPPING_STRUCTURE_FC;
1107        case JormFactoryAttributes.CREATE_IF_REQUIRED:
1108            return SpeedoProperties.MAPPING_STRUCTURE_CIR;
1109        default:
1110            return "UNKNOWN";
1111        }
1112    }
1113    
1114    public static byte getMappingStructure(String JavaDoc strval) {
1115        if (SpeedoProperties.MAPPING_STRUCTURE_DN.equals(strval)) {
1116            return JormFactoryAttributes.DO_NOTHING;
1117        } else if (SpeedoProperties.MAPPING_STRUCTURE_DD.equals(strval)) {
1118            return JormFactoryAttributes.DELETE_DATA;
1119        } else if (SpeedoProperties.MAPPING_STRUCTURE_CIR.equals(strval)) {
1120            return JormFactoryAttributes.CREATE_IF_REQUIRED;
1121        } else if (SpeedoProperties.MAPPING_STRUCTURE_FC.equals(strval)) {
1122            return JormFactoryAttributes.FORCE_CREATE;
1123        } else {
1124            return -1;
1125        }
1126        
1127    }
1128
1129    public Object JavaDoc getConcurrencyManagerComponent() throws Exception JavaDoc {
1130        return getSubComponent(speedo, "tpm.concurrency-manager");
1131    }
1132    
1133    public DependencyGraph getDependencyGraph() throws Exception JavaDoc {
1134        Component cmC = (Component) getConcurrencyManagerComponent();
1135        Object JavaDoc dg = Fractal.getBindingController(cmC).lookupFc("dependency-graph");
1136        return (DependencyGraph) dg;
1137    }
1138    
1139    public Collection JavaDoc getMemoryCacheEntries() throws Exception JavaDoc {
1140        Component cm = getSubComponent(speedo, MEMORY_CACHE_PATH);
1141        Component cmC = getSubComponent(cm, "cache-manager");
1142        CacheAttributeController cacheAttr = (CacheAttributeController)
1143            Fractal.getAttributeController(cmC);
1144        return cacheAttr.getCurrentEntryIdentifiers();
1145    }
1146    
1147    // IMPLEMENTATION OF THE PersistenceManagerFactory INTERFACE //
1148
//-----------------------------------------------------------//
1149

1150    public PersistenceManager getPersistenceManager() {
1151        if (!isPropertiesInitialized) {
1152            try {
1153                Properties JavaDoc p = getProperties();
1154                init(getSpeedoComponent(p), p);
1155            } catch(Throwable JavaDoc e) {
1156                System.err.println("Error during the initilization of the Speedo " +
1157                "persistence manager factory:");
1158                e.printStackTrace(System.err);
1159                return null;
1160            }
1161        }
1162        
1163        return delegate.getPersistenceManager();
1164    }
1165
1166    public PersistenceManager getPersistenceManager(String JavaDoc s, String JavaDoc s1) {
1167        if (!isPropertiesInitialized) {
1168            try {
1169                Properties JavaDoc p = getProperties();
1170                init(getSpeedoComponent(p), p);
1171            } catch(Throwable JavaDoc e) {
1172                System.err.println("Error during the initilization of the Speedo " +
1173                "persistence manager factory:");
1174                e.printStackTrace(System.err);
1175                return null;
1176            }
1177        }
1178        return delegate.getPersistenceManager(s, s1);
1179    }
1180
1181    public void setConnectionUserName(String JavaDoc s) {
1182        delegate.setConnectionUserName(s);
1183    }
1184
1185    public String JavaDoc getConnectionUserName() {
1186        return delegate.getConnectionUserName();
1187    }
1188
1189    public void setConnectionPassword(String JavaDoc s) {
1190        delegate.setConnectionPassword(s);
1191    }
1192
1193    public void setConnectionURL(String JavaDoc s) {
1194        delegate.setConnectionURL(s);
1195    }
1196
1197    public String JavaDoc getConnectionURL() {
1198        return delegate.getConnectionURL();
1199    }
1200
1201    public void setConnectionDriverName(String JavaDoc s) {
1202        delegate.setConnectionDriverName(s);
1203    }
1204
1205    public String JavaDoc getConnectionDriverName() {
1206        return delegate.getConnectionDriverName();
1207    }
1208
1209    public void setConnectionFactoryName(String JavaDoc s) {
1210        delegate.setConnectionFactoryName(s);
1211    }
1212
1213    public String JavaDoc getConnectionFactoryName() {
1214        return delegate.getConnectionFactoryName();
1215    }
1216
1217    public void setConnectionFactory(Object JavaDoc o) {
1218        delegate.setConnectionFactory(o);
1219    }
1220
1221    public Object JavaDoc getConnectionFactory() {
1222        return delegate.getConnectionFactory();
1223    }
1224
1225    public void setConnectionFactory2Name(String JavaDoc s) {
1226        delegate.setConnectionFactory2Name(s);
1227    }
1228
1229    public String JavaDoc getConnectionFactory2Name() {
1230        return delegate.getConnectionFactory2Name();
1231    }
1232
1233    public void setConnectionFactory2(Object JavaDoc o) {
1234        delegate.setConnectionFactory2(o);
1235    }
1236
1237    public Object JavaDoc getConnectionFactory2() {
1238        return delegate.getConnectionFactory2();
1239    }
1240
1241    public void setMultithreaded(boolean b) {
1242        delegate.setMultithreaded(b);
1243    }
1244
1245    public boolean getMultithreaded() {
1246        return delegate.getMultithreaded();
1247    }
1248
1249    public void setOptimistic(boolean b) {
1250        delegate.setOptimistic(b);
1251    }
1252
1253    public boolean getOptimistic() {
1254        return delegate.getOptimistic();
1255    }
1256
1257    public void setRetainValues(boolean b) {
1258        delegate.setRetainValues(b);
1259    }
1260
1261    public boolean getRetainValues() {
1262        return delegate.getRetainValues();
1263    }
1264
1265    public void setRestoreValues(boolean b) {
1266        delegate.setRestoreValues(b);
1267    }
1268
1269    public boolean getRestoreValues() {
1270        return delegate.getRestoreValues();
1271    }
1272
1273    public void setNontransactionalRead(boolean b) {
1274        delegate.setNontransactionalRead(b);
1275    }
1276
1277    public boolean getNontransactionalRead() {
1278        return delegate.getNontransactionalRead();
1279    }
1280
1281    public void setNontransactionalWrite(boolean b) {
1282        delegate.setNontransactionalWrite(b);
1283    }
1284
1285    public boolean getNontransactionalWrite() {
1286        return delegate.getNontransactionalWrite();
1287    }
1288
1289    public void setIgnoreCache(boolean b) {
1290        delegate.setIgnoreCache(b);
1291    }
1292
1293    public boolean getIgnoreCache() {
1294        return delegate.getIgnoreCache();
1295    }
1296
1297    public Properties JavaDoc getProperties() {
1298        return delegate.getProperties();
1299    }
1300
1301    public Collection JavaDoc supportedOptions() {
1302        return delegate.supportedOptions();
1303    }
1304
1305    public PersistenceManagerFactory getDelegate() {
1306        return delegate;
1307    }
1308
1309    public ProxyManager lookup() {
1310        return pmfComponent.lookup();
1311    }
1312
1313    public SequenceManager getSequenceManager() {
1314        return pmfComponent.getSequenceManager();
1315    }
1316    
1317    public void setSequenceManager(SequenceManager sequenceManager) {
1318        pmfComponent.setSequenceManager(sequenceManager);
1319    }
1320    
1321    public void unbindPM() {
1322        pmfComponent.unbindPM();
1323    }
1324
1325    public void bindPM2Thread(ProxyManager pm) {
1326        pmfComponent.bindPM2Thread(pm);
1327    }
1328
1329    public void proxyManagerClosed(ProxyManager pr) {
1330        pmfComponent.proxyManagerClosed(pr);
1331    }
1332
1333    public void close() {
1334        pmfComponent.close();
1335    }
1336    
1337    public DataStoreCache getDataStoreCache() {
1338        return pmfComponent.getDataStoreCache();
1339    }
1340
1341    public String JavaDoc getMapping() {
1342        return pmfComponent.getMapping();
1343    }
1344
1345    public boolean isClosed() {
1346        return pmfComponent.isClosed();
1347    }
1348
1349    public void setMapping(String JavaDoc arg0) {
1350        pmfComponent.setMapping(arg0);
1351    }
1352
1353    public void evict(Object JavaDoc arg0) {
1354        pmfComponent.evict(arg0);
1355    }
1356
1357    public void evictAll() {
1358        pmfComponent.evictAll();
1359    }
1360    
1361    public void evictAll(Class JavaDoc arg0, boolean arg1) {
1362        pmfComponent.evictAll(arg0, arg1);
1363    }
1364
1365    public void evictAll(Collection JavaDoc arg0) {
1366        pmfComponent.evictAll(arg0);
1367    }
1368
1369    public void evictAll(Object JavaDoc[] arg0) {
1370        pmfComponent.evictAll(arg0);
1371    }
1372    public void pin(Object JavaDoc arg0) {
1373        pmfComponent.pin(arg0);
1374    }
1375
1376    public void pinAll(Class JavaDoc arg0, boolean arg1) {
1377        pmfComponent.pinAll(arg0, arg1);
1378    }
1379
1380    public void pinAll(Collection JavaDoc arg0) {
1381        pmfComponent.pinAll(arg0);
1382    }
1383
1384    public void pinAll(Object JavaDoc[] arg0) {
1385        pmfComponent.pinAll(arg0);
1386    }
1387
1388    public void unpin(Object JavaDoc arg0) {
1389        pmfComponent.unpin(arg0);
1390    }
1391
1392    public void unpinAll(Class JavaDoc arg0, boolean arg1) {
1393        pmfComponent.unpinAll(arg0, arg1);
1394    }
1395
1396    public void unpinAll(Collection JavaDoc arg0) {
1397        pmfComponent.unpinAll(arg0);
1398    }
1399
1400    public void unpinAll(Object JavaDoc[] arg0) {
1401        pmfComponent.unpinAll(arg0);
1402    }
1403    
1404    public void addInstanceLifecycleListener(
1405            InstanceLifecycleListener arg0,
1406            Class JavaDoc[] arg1) {
1407        pmfComponent.addInstanceLifecycleListener(arg0, arg1);
1408    }
1409    public void removeInstanceLifecycleListener(InstanceLifecycleListener arg0) {
1410        pmfComponent.removeInstanceLifecycleListener(arg0);
1411    }
1412}
1413
Popular Tags