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: * @(#)MessageRegistry.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.binding.jms;
030:
031: import java.util.HashMap;
032: import java.util.Iterator;
033: import java.util.Set;
034:
035: /**
036: * This is a registry which maintains the exchnage Id and the servicelist
037: * runtime object so that responses can be correlated.
038: *
039: * @author Sun Microsystems Inc.
040: */
041: public final class MessageRegistry implements JMSBindingResources {
042: /**
043: * Singleton reference.
044: */
045: private static MessageRegistry sMe;
046:
047: /**
048: * List of all registered exchanges.
049: */
050: private HashMap mExchanges;
051:
052: /**
053: * Private constructor.
054: */
055: public MessageRegistry() {
056: mExchanges = new HashMap();
057: }
058:
059: /**
060: * Chesks if there any active message exchanges.
061: *
062: * @return true if no exchanges are active.
063: */
064: public boolean isEmpty() {
065: return mExchanges.isEmpty();
066: }
067:
068: /**
069: * Retrieves the servicelist runtime object corresponding to each exchange
070: * ID.
071: *
072: * @param exchangeId message xchnage.
073: *
074: * @return servicelist bean object.
075: */
076: public Object getObject(String exchangeId) {
077: Object l;
078: l = mExchanges.get(exchangeId);
079:
080: return l;
081: }
082:
083: /**
084: * Removes all the entries from the registry.
085: */
086: public void clearRegistry() {
087: if (mExchanges == null) {
088: return;
089: }
090:
091: mExchanges = new HashMap();
092: }
093:
094: /**
095: * Removes an exchange from the registry.
096: *
097: * @param exchangeId exchange id.
098: */
099: public synchronized void deregisterExchange(String exchangeId) {
100: Object l = mExchanges.remove(exchangeId);
101: }
102:
103: /**
104: * List all the active exchanges.
105: *
106: * @return iterator iterator.
107: */
108: public Iterator listActiveExchanges() {
109: if (mExchanges == null) {
110: return null;
111: }
112:
113: Set tmp = mExchanges.keySet();
114:
115: if (tmp == null) {
116: return null;
117: }
118:
119: return tmp.iterator();
120: }
121:
122: /**
123: * Registers a message Exchange.
124: *
125: * @param exchnageId exchnage id.
126: * @param artifact servicelist.
127: */
128: public synchronized void registerExchange(String exchnageId,
129: Object artifact) {
130: mExchanges.put(exchnageId, artifact);
131: }
132: }
|