001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ComponentRegistry.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.framework;
030:
031: import com.sun.jbi.ComponentInfo;
032: import com.sun.jbi.ComponentQuery;
033: import com.sun.jbi.ComponentState;
034: import com.sun.jbi.ComponentType;
035:
036: import java.util.ArrayList;
037: import java.util.Collection;
038: import java.util.HashMap;
039: import java.util.Iterator;
040: import java.util.List;
041: import java.util.logging.Logger;
042:
043: import com.sun.jbi.management.registry.Registry;
044: import com.sun.jbi.management.registry.RegistryException;
045: import com.sun.jbi.management.registry.Updater;
046:
047: /**
048: * This is the implementation of the Component Registry, which provides
049: * for registration of Shared Libraries, Binding Components, and Service
050: * Engines within the JBI environment.
051: *
052: * @author Sun Microsystems, Inc.
053: */
054: public class ComponentRegistry implements com.sun.jbi.ServiceLifecycle,
055: com.sun.jbi.ServiceUnitRegistration {
056: /**
057: * Local handle to the EnvironmentContext
058: */
059: private EnvironmentContext mContext;
060:
061: /**
062: * Local flag for start/stop checking
063: */
064: private Boolean mStarted = null;
065:
066: /**
067: * Cache for Binding Components and Service Engines.
068: */
069: private HashMap mComponentCache;
070:
071: /**
072: * Cache for Shared Libraries.
073: */
074: private HashMap mSharedLibraryCache;
075:
076: /**
077: * Logger for the component registry service.
078: */
079: private Logger mLog;
080:
081: /**
082: * Framework Statistics.
083: */
084: private FrameworkStatistics mStats;
085:
086: /**
087: * Local handle to the StringTranslator for the package
088: */
089: private StringTranslator mTranslator;
090:
091: /**
092: * Local handle to the registry's query implementation.
093: */
094: private ComponentQuery mComponentQuery;
095:
096: /**
097: * Local handle to the registry's updater implementation.
098: */
099: private Updater mRegistryUpdater;
100:
101: //------------------------- ServiceLifecycle methods --------------------------
102:
103: /**
104: * Initialize the Component Registry service.
105: * @param context The JBI environment context created by the JBI framework.
106: * @throws javax.jbi.JBIException if an error occurs
107: */
108: public void initService(com.sun.jbi.EnvironmentContext context)
109: throws javax.jbi.JBIException {
110: mContext = (EnvironmentContext) context;
111: mTranslator = (StringTranslator) context
112: .getStringTranslatorFor(this );
113:
114: if (null != mStarted) {
115: throw new java.lang.IllegalStateException(
116: mTranslator
117: .getString(
118: LocalStringKeys.SERVICE_ALREADY_INITIALIZED,
119: mTranslator
120: .getString(LocalStringKeys.CR_NAME)));
121: }
122: mStarted = mStarted.FALSE;
123: mComponentCache = new HashMap();
124: mSharedLibraryCache = new HashMap();
125: mStats = mContext.getFrameworkStatistics();
126: mLog = mContext.getLogger();
127: mLog.fine(mTranslator.getString(
128: LocalStringKeys.SERVICE_INITIALIZED, mTranslator
129: .getString(LocalStringKeys.CR_NAME)));
130: }
131:
132: /**
133: * Start the Component Registry service.
134: * @throws javax.jbi.JBIException if an error occurs
135: */
136: public void startService() throws javax.jbi.JBIException {
137: if (mStarted.booleanValue()) {
138: throw new java.lang.IllegalStateException(
139: mTranslator
140: .getString(
141: LocalStringKeys.SERVICE_ALREADY_STARTED,
142: mTranslator
143: .getString(LocalStringKeys.CR_NAME)));
144: }
145:
146: // Get instances of the persistent registry query and updater.
147:
148: mComponentQuery = ((Registry) mContext.getJustRegistry())
149: .getComponentQuery();
150: mRegistryUpdater = ((Registry) mContext.getJustRegistry())
151: .getUpdater();
152:
153: // Reload the component registry cache from the persistent registry
154: // information saved by the previous execution of the JBI framework.
155:
156: reloadRegistry();
157:
158: // Indicate that the Component Registry is now stared.
159:
160: mStarted = mStarted.TRUE;
161: mLog.fine(mTranslator.getString(
162: LocalStringKeys.SERVICE_STARTED, mTranslator
163: .getString(LocalStringKeys.CR_NAME)));
164: }
165:
166: /**
167: * Stop the Component Registry service.
168: * @throws javax.jbi.JBIException if an error occurs
169: */
170: public void stopService() throws javax.jbi.JBIException {
171: if (!mStarted.booleanValue()) {
172: throw new java.lang.IllegalStateException(
173: mTranslator
174: .getString(
175: LocalStringKeys.SERVICE_ALREADY_STOPPED,
176: mTranslator
177: .getString(LocalStringKeys.CR_NAME)));
178: }
179:
180: mStarted = null;
181: mContext = null;
182: mComponentCache = null;
183: mSharedLibraryCache = null;
184: mStats = null;
185: mComponentQuery = null;
186: mRegistryUpdater = null;
187:
188: mLog.fine(mTranslator.getString(
189: LocalStringKeys.SERVICE_STOPPED, mTranslator
190: .getString(LocalStringKeys.CR_NAME)));
191:
192: mLog = null;
193: mTranslator = null;
194: }
195:
196: //--------------------- ServiceUnitRegistration methods -----------------------
197:
198: /**
199: * Check to see if a Service Unit with the specified name is registered to
200: * the specified BC or SE.
201: * @param componentName is the unique name of the BC or SE to check.
202: * @param serviceUnitName is the unique name of the Service Unit to check
203: * for.
204: * @return boolean is true if the Service Unit is registered, false if not.
205: * @throws javax.jbi.JBIException if no component exists with the specified
206: * component name.
207: */
208: public boolean isServiceUnitRegistered(String componentName,
209: String serviceUnitName) throws javax.jbi.JBIException {
210: if (null == serviceUnitName) {
211: String msg = mTranslator.getString(
212: LocalStringKeys.NULL_ARGUMENT, "serviceUnitName");
213: mLog.severe(msg);
214: throw new java.lang.IllegalArgumentException(msg);
215: }
216: if (null == componentName) {
217: String msg = mTranslator.getString(
218: LocalStringKeys.NULL_ARGUMENT, "componentName");
219: mLog.severe(msg);
220: throw new java.lang.IllegalArgumentException(msg);
221: }
222: Component comp = getComponent(componentName);
223: if (null != comp) {
224: return comp.isServiceUnitRegistered(serviceUnitName);
225: } else {
226: String msg = mTranslator.getString(
227: LocalStringKeys.CR_COMPONENT_NOT_REGISTERED,
228: componentName);
229: mLog.warning(msg);
230: throw new javax.jbi.JBIException(msg);
231: }
232: }
233:
234: /**
235: * Register a Service Unit that has been deployed to a particular BC or
236: * SE. This is done after a successful deployment operation.
237: * @param componentName The unique name of the BC or SE.
238: * @param serviceAssemblyName The unique name of the Service Assembly.
239: * @param serviceUnitName The unique name of the Service Unit.
240: * @param serviceUnitFilePath The fully-qualified path to the Service Unit
241: * deployment descriptor.
242: * @throws javax.jbi.JBIException if no component exists with the specified
243: * component name or if there is already a Service Unit with the specified
244: * service unit name registered to the component.
245: */
246: public synchronized void registerServiceUnit(String componentName,
247: String serviceAssemblyName, String serviceUnitName,
248: String serviceUnitFilePath) throws javax.jbi.JBIException {
249: if (null == componentName) {
250: String msg = mTranslator.getString(
251: LocalStringKeys.NULL_ARGUMENT, "componentName");
252: mLog.severe(msg);
253: throw new java.lang.IllegalArgumentException(msg);
254: }
255: if (null == serviceAssemblyName) {
256: String msg = mTranslator.getString(
257: LocalStringKeys.NULL_ARGUMENT,
258: "serviceAssemblyName");
259: mLog.severe(msg);
260: throw new java.lang.IllegalArgumentException(msg);
261: }
262: if (null == serviceUnitName) {
263: String msg = mTranslator.getString(
264: LocalStringKeys.NULL_ARGUMENT, "serviceUnitName");
265: mLog.severe(msg);
266: throw new java.lang.IllegalArgumentException(msg);
267: }
268: if (null == serviceUnitFilePath) {
269: String msg = mTranslator.getString(
270: LocalStringKeys.NULL_ARGUMENT,
271: "serviceUnitFilePath");
272: mLog.severe(msg);
273: throw new java.lang.IllegalArgumentException(msg);
274: }
275:
276: Component comp = getComponent(componentName);
277: if (null != comp) {
278: ServiceUnit su = new ServiceUnit(serviceAssemblyName,
279: serviceUnitName, serviceUnitFilePath, componentName);
280: mRegistryUpdater.addServiceUnitToComponent(componentName,
281: su);
282: comp.addServiceUnit(su);
283: } else {
284: String msg = mTranslator.getString(
285: LocalStringKeys.CR_COMPONENT_NOT_REGISTERED,
286: componentName);
287: mLog.warning(msg);
288: throw new javax.jbi.JBIException(msg);
289: }
290: }
291:
292: /**
293: * Unregister a Service Unit that has been undeployed from a particular BC
294: * or SE. This is done after a successful undeployment operation.
295: * @param componentName The unique name of the BC or SE.
296: * @param serviceUnitName The unique name of the Service Unit.
297: * @throws javax.jbi.JBIException if no component exists with the specified
298: * component name or if there is no Service Unit with the specified
299: * service unit name registered to the component.
300: */
301: public void unregisterServiceUnit(String componentName,
302: String serviceUnitName) throws javax.jbi.JBIException {
303: if (null == componentName) {
304: String msg = mTranslator.getString(
305: LocalStringKeys.NULL_ARGUMENT, "componentName");
306: mLog.severe(msg);
307: throw new java.lang.IllegalArgumentException(msg);
308: }
309: if (null == serviceUnitName) {
310: String msg = mTranslator.getString(
311: LocalStringKeys.NULL_ARGUMENT, "serviceUnitName");
312: mLog.severe(msg);
313: throw new java.lang.IllegalArgumentException(msg);
314: }
315: Component comp = getComponent(componentName);
316: if (null != comp) {
317: mRegistryUpdater.removeServiceUnitFromComponent(
318: componentName, serviceUnitName);
319: comp.removeServiceUnit(serviceUnitName);
320: } else {
321: String msg = mTranslator.getString(
322: LocalStringKeys.CR_COMPONENT_NOT_REGISTERED,
323: componentName);
324: mLog.warning(msg);
325: throw new javax.jbi.JBIException(msg);
326: }
327: }
328:
329: //--------------------------- Package-only methods ----------------------------
330:
331: /**
332: * Commit a Binding Component or a Service Engine. This causes the component
333: * to be permanently registered in the persistent registry after installation
334: * is complete.
335: * @param componentName the unique component name.
336: * @throws javax.jbi.JBIException if any error occurs.
337: */
338: void commitComponent(String componentName)
339: throws javax.jbi.JBIException {
340: if (null == componentName) {
341: String msg = mTranslator.getString(
342: LocalStringKeys.NULL_ARGUMENT, "componentName");
343: mLog.severe(msg);
344: throw new java.lang.IllegalArgumentException(msg);
345: }
346:
347: mLog
348: .finer("Permanently registering component "
349: + componentName);
350: Component component = getComponent(componentName);
351:
352: if (null == component) {
353: String msg = mTranslator
354: .getString(
355: LocalStringKeys.CR_PERMANENT_REGISTRATION_NOT_FOUND,
356: componentName);
357: mLog.warning(msg);
358: throw new javax.jbi.JBIException(msg);
359: }
360:
361: List<String> registeredComps = mComponentQuery
362: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
363: if (!registeredComps.contains(component.getName())) {
364: mRegistryUpdater.addComponent((ComponentInfo) component);
365: mLog.fine("Component " + component.getName()
366: + " registered");
367: } else {
368: String msg = mTranslator.getString(
369: LocalStringKeys.CR_COMPONENT_ALREADY_REGISTERED,
370: component.getName());
371: mLog.warning(msg);
372: throw new javax.jbi.JBIException(msg);
373: }
374: }
375:
376: /**
377: * Get a list of all installed Components (Binding Components and Service
378: * Engines).
379: * @return A list of Component instances.
380: */
381: List getAllComponents() {
382: return new ArrayList(mComponentCache.values());
383: }
384:
385: /**
386: * Get a list of all installed Shared Libraries.
387: * @return A list of SharedLibrary instances.
388: */
389: List getAllSharedLibraries() {
390: return new ArrayList(mSharedLibraryCache.values());
391: }
392:
393: /**
394: * Look up a component (Binding Component or Service Engine) using its
395: * unique name.
396: * @param componentName is the unique name of the BC or SE.
397: * @return Component contains all runtime information about the component
398: * or null if no BC or SE was found with the specified name.
399: * @throws java.lang.IllegalArgumentException if the componentName parameter
400: * is null.
401: */
402: Component getComponent(String componentName) {
403: if (null == componentName) {
404: String msg = mTranslator.getString(
405: LocalStringKeys.NULL_ARGUMENT, "componentName");
406: mLog.severe(msg);
407: throw new java.lang.IllegalArgumentException(msg);
408: }
409:
410: mLog.finest("Looking up component " + componentName
411: + " in cache");
412:
413: // Get the Component from the Cache which is loaded at startup time.
414:
415: Component theComponent = (Component) mComponentCache
416: .get(componentName);
417:
418: if (null != theComponent) {
419: mLog.finest("Component " + componentName
420: + " found in cache");
421: } else {
422: mLog.finest("Component " + componentName
423: + " not found in cache");
424: }
425: return theComponent;
426: }
427:
428: /**
429: * Get a list of component IDs of the specified type, with the
430: * specified status.
431: * @param type The type of component for which the IDs are requested.
432: * @param status The status for which the IDs are requested.
433: * @return A list of Strings containing the component IDs. If no components
434: * were found, the list is empty.
435: */
436: List<String> getComponentIdsFromCache(ComponentType type,
437: ComponentState status) {
438:
439: List<String> ids = new ArrayList();
440:
441: // First search the Component cache if this call is to list anything
442: // other than just Shared Libraries.
443:
444: if (ComponentType.SHARED_LIBRARY != type) {
445: Collection values = mComponentCache.values();
446: Iterator i = values.iterator();
447: Component comp;
448: ComponentType ct;
449:
450: while (i.hasNext()) {
451: comp = (Component) i.next();
452: ct = comp.getComponentType();
453: switch (type) {
454: case ALL:
455: break;
456: case BINDINGS_AND_ENGINES:
457: if (ct != ComponentType.BINDING
458: && ct != ComponentType.ENGINE) {
459: continue;
460: }
461: break;
462: case BINDING:
463: case ENGINE:
464: if (ct != type) {
465: continue;
466: }
467: break;
468: default:
469: break;
470: }
471: if (null == status || status == comp.getStatus()) {
472: ids.add(comp.getName());
473: }
474: }
475: }
476:
477: // Now search the SharedLibrary cache if this call is to list everything
478: // or just Shared Libraries.
479:
480: if (ComponentType.ALL == type
481: || ComponentType.SHARED_LIBRARY == type) {
482: Collection values = mSharedLibraryCache.values();
483: Iterator i = values.iterator();
484: SharedLibrary sl;
485: while (i.hasNext()) {
486: sl = (SharedLibrary) i.next();
487: if (null == status || status == sl.getStatus()) {
488: ids.add(sl.getName());
489: }
490: }
491: }
492:
493: return ids;
494: }
495:
496: /**
497: * Return a list of all components dependent upon the specified Shared
498: * Library.
499: * @param sharedLibraryName - the name of the Shared Library.
500: * @return A list containing the Component instances of all components
501: * that depend upon the Shared Library.
502: */
503: List getDependents(String sharedLibraryName) {
504: boolean isDependent = false;
505: List depList = getAllComponents();
506: Iterator d = depList.iterator();
507: Component comp = null;
508: while (d.hasNext()) {
509: comp = (Component) d.next();
510: List sharedLibraryList = comp.getSharedLibraryNames();
511: if (null == sharedLibraryList) {
512: d.remove();
513: } else {
514: Iterator s = sharedLibraryList.iterator();
515: String sl = null;
516: while (s.hasNext()) {
517: sl = (String) s.next();
518: if (sl.equals(sharedLibraryName)) {
519: isDependent = true;
520: break;
521: }
522: }
523: if (!isDependent) {
524: d.remove();
525: } else {
526: isDependent = false;
527: }
528: }
529: }
530: return depList;
531: }
532:
533: /**
534: * Look up a SharedLibrary object using its assigned name.
535: * @param sharedLibraryName The unique name of the Shared Library.
536: * @return The SharedLibrary instance, or null if no Shared Library was
537: * found with the specified name.
538: */
539: SharedLibrary getSharedLibrary(String sharedLibraryName) {
540: if (null == sharedLibraryName) {
541: String msg = mTranslator.getString(
542: LocalStringKeys.NULL_ARGUMENT, "sharedLibraryName");
543: mLog.severe(msg);
544: throw new java.lang.IllegalArgumentException(msg);
545: }
546:
547: mLog.finer("Looking up Shared Library " + sharedLibraryName
548: + " in cache");
549:
550: SharedLibrary sl = (SharedLibrary) mSharedLibraryCache
551: .get(sharedLibraryName);
552:
553: if (null != sl) {
554: mLog.finer("Shared Library " + sharedLibraryName
555: + " found in cache");
556: } else {
557: mLog.finer("Shared Library " + sharedLibraryName
558: + " not found in cache");
559: }
560: return sl;
561: }
562:
563: /**
564: * Get the current state of a Binding Component or Service Engine. The
565: * returned value is one of the component state values defined in the
566: * com.sun.jbi.ComponentState enumerator: LOADED, SHUTDOWN, STOPPED, or
567: * or STARTED.
568: * @param componentName the unique component name assigned to the BC or SE.
569: * @return the current state of the BC or SE.
570: * @throws javax.jbi.JBIException if the component name is not found.
571: */
572: public ComponentState getStatus(String componentName)
573: throws javax.jbi.JBIException {
574: Component comp = getComponent(componentName);
575: if (null != comp) {
576: return comp.getStatus();
577: } else {
578: String msg = mTranslator.getString(
579: LocalStringKeys.CR_COMPONENT_NOT_REGISTERED,
580: componentName);
581: mLog.warning(msg);
582: throw new javax.jbi.JBIException(msg);
583: }
584: }
585:
586: /**
587: * Check to see if a component with the specified name is registered.
588: * @param componentName is the component name to check for.
589: * @return boolean is true if the component is registered, false if not.
590: * @throws javax.jbi.JBIException if any error occurs.
591: */
592: boolean isComponentRegistered(String componentName)
593: throws javax.jbi.JBIException {
594: if (null == componentName) {
595: String msg = mTranslator.getString(
596: LocalStringKeys.NULL_ARGUMENT, "componentName");
597: mLog.severe(msg);
598: throw new java.lang.IllegalArgumentException(msg);
599: }
600:
601: if (mComponentCache.containsKey(componentName)) {
602: mLog
603: .finest("Component " + componentName
604: + " is registered");
605: return true;
606: } else {
607: mLog.finest("Component " + componentName
608: + " is not registered");
609: return false;
610: }
611: }
612:
613: /**
614: * Check to see if a Shared Library with the specified name is registered.
615: * @param sharedLibraryName is the Shared Library to check for.
616: * @return boolean is true if the Shared Library is registered, false if not.
617: * @throws javax.jbi.JBIException if any error occurs.
618: */
619: boolean isSharedLibraryRegistered(String sharedLibraryName)
620: throws javax.jbi.JBIException {
621: if (null == sharedLibraryName) {
622: String msg = mTranslator.getString(
623: LocalStringKeys.NULL_ARGUMENT, "sharedLibraryName");
624: mLog.severe(msg);
625: throw new java.lang.IllegalArgumentException(msg);
626: }
627:
628: if (mSharedLibraryCache.containsKey(sharedLibraryName)) {
629: mLog.finest("Shared Library " + sharedLibraryName
630: + " is registered");
631: return true;
632: } else {
633: mLog.finest("Shared Library " + sharedLibraryName
634: + " is not registered");
635: return false;
636: }
637: }
638:
639: /**
640: * Register a Binding Component or a Service Engine.
641: * @param component contains the component runtime information.
642: * @throws javax.jbi.JBIException if any error occurs.
643: */
644: void registerComponent(Component component)
645: throws javax.jbi.JBIException {
646: if (null == component) {
647: String msg = mTranslator.getString(
648: LocalStringKeys.NULL_ARGUMENT, "component");
649: mLog.severe(msg);
650: throw new java.lang.IllegalArgumentException(msg);
651: }
652:
653: mLog.finer("Registering new component " + component.getName()
654: + " in cache");
655:
656: synchronized (mComponentCache) {
657: if (!mComponentCache.containsKey(component.getName())) {
658: mComponentCache.put(component.getName(), component);
659: mStats.incrementRegistryAdds();
660: mLog.fine("Component " + component.getName()
661: + " registered in cache");
662: } else {
663: String msg = mTranslator
664: .getString(
665: LocalStringKeys.CR_COMPONENT_ALREADY_REGISTERED,
666: component.getName());
667: mLog.warning(msg);
668: throw new javax.jbi.JBIException(msg);
669: }
670: }
671: }
672:
673: /**
674: * Register the unique name and class path for a Shared Library.
675: * @param sharedLib The Shared Library instance.
676: * @throws javax.jbi.JBIException if any error occurs.
677: */
678: void registerSharedLibrary(SharedLibrary sharedLib)
679: throws javax.jbi.JBIException {
680: if (null == sharedLib) {
681: String msg = mTranslator.getString(
682: LocalStringKeys.NULL_ARGUMENT, "sharedLib");
683: mLog.severe(msg);
684: throw new java.lang.IllegalArgumentException(msg);
685: }
686:
687: mLog.finer("Registering new Shared Library "
688: + sharedLib.getName() + " in cache");
689:
690: List<String> installedSLs = mComponentQuery
691: .getComponentIds(ComponentType.SHARED_LIBRARY);
692: if (!installedSLs.contains(sharedLib.getName())) {
693: synchronized (mSharedLibraryCache) {
694: if (!mSharedLibraryCache.containsKey(sharedLib
695: .getName())) {
696: mSharedLibraryCache.put(sharedLib.getName(),
697: sharedLib);
698: } else {
699: String msg = mTranslator.getString(
700: LocalStringKeys.CR_SL_ALREADY_REGISTERED,
701: sharedLib.getName());
702: mLog.warning(msg);
703: throw new javax.jbi.JBIException(msg);
704: }
705: }
706: mRegistryUpdater
707: .addSharedLibrary((ComponentInfo) sharedLib);
708: mStats.incrementRegistryAdds();
709: mLog.fine("Shared Library " + sharedLib.getName()
710: + " registered in cache");
711: } else {
712: String msg = mTranslator.getString(
713: LocalStringKeys.CR_SL_ALREADY_REGISTERED, sharedLib
714: .getName());
715: mLog.warning(msg);
716: throw new javax.jbi.JBIException(msg);
717: }
718: }
719:
720: /**
721: * Remove a Binding Component or a Service Engine from the registry after
722: * a failed installation This is used when the registry entry has not yet
723: * been propagated to the persistent registry.
724: * @param componentName the unique name of the BC or SE.
725: * @throws javax.jbi.JBIException if any error occurs.
726: */
727: void removeComponent(String componentName)
728: throws javax.jbi.JBIException {
729: if (null == componentName) {
730: String msg = mTranslator.getString(
731: LocalStringKeys.NULL_ARGUMENT, "componentName");
732: mLog.severe(msg);
733: throw new java.lang.IllegalArgumentException(msg);
734: }
735:
736: synchronized (mComponentCache) {
737: mComponentCache.remove(componentName);
738: }
739: mRegistryUpdater.removeComponent(componentName);
740: mStats.incrementRegistryDeletes();
741:
742: }
743:
744: /**
745: * Unregister a Binding Component or a Service Engine.
746: * @param componentName the unique name of the BC or SE.
747: * @throws javax.jbi.JBIException if any error occurs.
748: */
749: void unregisterComponent(String componentName)
750: throws javax.jbi.JBIException {
751: if (null == componentName) {
752: String msg = mTranslator.getString(
753: LocalStringKeys.NULL_ARGUMENT, "componentName");
754: mLog.severe(msg);
755: throw new java.lang.IllegalArgumentException(msg);
756: }
757:
758: mLog.finer("Unregistering component " + componentName);
759:
760: synchronized (mComponentCache) {
761: if (mComponentCache.containsKey(componentName)) {
762: mComponentCache.remove(componentName);
763: mRegistryUpdater.removeComponent(componentName);
764: mStats.incrementRegistryDeletes();
765: mLog.fine("Component " + componentName
766: + " unregistered");
767: } else {
768: String msg = mTranslator.getString(
769: LocalStringKeys.CR_COMPONENT_NOT_REGISTERED,
770: componentName);
771: mLog.warning(msg);
772: throw new javax.jbi.JBIException(msg);
773: }
774: }
775: }
776:
777: /**
778: * Unregister a Shared Library.
779: * @param sharedLibraryName is the name of the Shared Library.
780: * @throws javax.jbi.JBIException if any error occurs.
781: */
782: void unregisterSharedLibrary(String sharedLibraryName)
783: throws javax.jbi.JBIException {
784: if (null == sharedLibraryName) {
785: String msg = mTranslator.getString(
786: LocalStringKeys.NULL_ARGUMENT, "sharedLibraryName");
787: mLog.severe(msg);
788: throw new java.lang.IllegalArgumentException(msg);
789: }
790:
791: mLog.fine("Unregistering Shared Library " + sharedLibraryName);
792:
793: synchronized (mSharedLibraryCache) {
794: if (mSharedLibraryCache.containsKey(sharedLibraryName)) {
795: mSharedLibraryCache.remove(sharedLibraryName);
796: mRegistryUpdater.removeSharedLibrary(sharedLibraryName);
797: mStats.incrementRegistryDeletes();
798: mLog.fine("Shared Library " + sharedLibraryName
799: + " unregistered");
800: } else {
801: String msg = mTranslator.getString(
802: LocalStringKeys.CR_SL_NOT_REGISTERED,
803: sharedLibraryName);
804: mLog.warning(msg);
805: throw new javax.jbi.JBIException(msg);
806: }
807: }
808: }
809:
810: //----------------------------- Private methods -------------------------------
811:
812: /**
813: * Reload the registry cache from the persistent registry.
814: * @throws javax.jbi.JBIException if any error occurs.
815: */
816: private synchronized void reloadRegistry()
817: throws javax.jbi.JBIException {
818: // Get the persisted registry.
819: // Load the Components from jbi-registry.xml
820: List<String> compList = mComponentQuery
821: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
822:
823: for (String compName : compList) {
824: ComponentInfo info = mComponentQuery
825: .getComponentInfo(compName);
826:
827: String id = info.getName();
828: switch (info.getComponentType()) {
829: case BINDING:
830: case ENGINE: {
831: Component comp = new Component(info);
832: mComponentCache.put(id, comp);
833: mStats.incrementRegistryAdds();
834: mLog.finer(comp.getComponentTypeAsString() + " " + id
835: + " restored to cache");
836: break;
837: }
838: default: {
839: mLog.warning(mTranslator.getString(
840: LocalStringKeys.CR_RELOAD_BAD_COMPONENT_TYPE,
841: info.getComponentType().toString(), id));
842: continue;
843: }
844: }
845: }
846:
847: List<String> slList = mComponentQuery
848: .getComponentIds(ComponentType.SHARED_LIBRARY);
849:
850: for (String slName : slList) {
851: ComponentInfo slInfo = mComponentQuery
852: .getSharedLibraryInfo(slName);
853:
854: String id = slInfo.getName();
855: switch (slInfo.getComponentType()) {
856: case SHARED_LIBRARY: {
857: SharedLibrary sl = new SharedLibrary(slInfo);
858: mSharedLibraryCache.put(id, sl);
859: mStats.incrementRegistryAdds();
860: mLog.finer("Shared Library " + id
861: + " restored to cache");
862: break;
863: }
864: default: {
865: mLog.warning(mTranslator.getString(
866: LocalStringKeys.CR_RELOAD_BAD_COMPONENT_TYPE,
867: slInfo.getComponentType().toString(), id));
868: continue;
869: }
870: }
871: }
872: }
873:
874: }
|