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: * @(#)ServiceInfo.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.proxy;
030:
031: import com.sun.jbi.binding.proxy.RegistrationInfo;
032:
033: import com.sun.jbi.binding.proxy.connection.Event;
034: import com.sun.jbi.binding.proxy.connection.EventInfo;
035:
036: import java.util.ArrayList;
037: import java.util.HashMap;
038: import java.util.Iterator;
039: import java.util.ListIterator;
040:
041: import javax.jbi.servicedesc.ServiceEndpoint;
042:
043: import javax.xml.namespace.QName;
044:
045: /**
046: * Represents information about a service. A service may be exported from mulitple instances.
047: *
048: * @author Sun Microsystems, Inc
049: */
050: public class ServiceInfo {
051: class Entry {
052: RegistrationInfo mRegInfo;
053: int mActiveCount;
054: int mTotalCount;
055: }
056:
057: private ServiceEndpoint mEndpoint;
058: private ArrayList mInstances;
059: private HashMap mMap;
060: private int mNext;
061: int mTotalCount;
062: int mDepth;
063:
064: /** Creates a new instance of ServiceInfo */
065: public ServiceInfo(ServiceEndpoint endpoint) {
066: mEndpoint = endpoint;
067: mMap = new HashMap();
068: mInstances = new ArrayList();
069: mNext = -1;
070: }
071:
072: public ServiceEndpoint getServiceEndpoint() {
073: return (mEndpoint);
074: }
075:
076: public void addInstance(RegistrationInfo ri) {
077: Entry e = new Entry();
078: e.mRegInfo = ri;
079: e.mActiveCount = 0;
080: e.mTotalCount = 0;
081: mInstances.add(e);
082: mMap.put(ri.getInstanceId(), e);
083: }
084:
085: public int getInstanceCount() {
086: return (mInstances.size());
087: }
088:
089: public boolean removeInstance(String instance) {
090: for (Iterator i = mInstances.iterator(); i.hasNext();) {
091: Entry e = (Entry) i.next();
092:
093: if (e.mRegInfo.getInstanceId().equals(instance)) {
094: i.remove();
095: mMap.remove(instance);
096: break;
097: }
098: }
099: return (mInstances.isEmpty());
100: }
101:
102: public String getInstance() {
103: Entry e;
104:
105: if (++mNext >= mInstances.size()) {
106: mNext = 0;
107: }
108: e = (Entry) mInstances.get(mNext);
109: e.mActiveCount++;
110: e.mTotalCount++;
111: mDepth++;
112: mTotalCount++;
113:
114: return (e.mRegInfo.getInstanceId());
115: }
116:
117: public void returnInstance(String instanceId) {
118: Entry e;
119:
120: e = (Entry) mMap.get(instanceId);
121: if (e != null) {
122: e.mActiveCount--;
123: mDepth--;
124: }
125: }
126:
127: public String toString() {
128: StringBuffer sb = new StringBuffer();
129:
130: sb.append(" ServiceInfo Service(");
131: sb.append(mEndpoint.getServiceName().toString());
132: sb.append(")\n Endpoint (");
133: sb.append(mEndpoint.getEndpointName());
134: sb.append(")\n Instances Count (");
135: sb.append(mInstances.size());
136: sb.append(") Next(");
137: sb.append(mNext);
138: sb.append(") TotalCount(");
139: sb.append(mTotalCount);
140: sb.append(") Depth(");
141: sb.append(mDepth);
142: sb.append(")\n");
143: for (ListIterator i = mInstances.listIterator(); i.hasNext();) {
144: Entry e = (Entry) i.next();
145: sb.append(e.mRegInfo.toString());
146: sb.append(" TotalCount(");
147: sb.append(e.mTotalCount);
148: sb.append(") Depth(");
149: sb.append(e.mActiveCount);
150: sb.append(")\n");
151: }
152: return (sb.toString());
153: }
154: }
|