001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.poa;
022:
023: import org.omg.PortableServer.Servant;
024: import org.jacorb.orb.dsi.ServerRequest;
025:
026: /**
027: * This class will manage an structure of a chain of poa event listeners
028: * and will dispatch events to those listeners.
029: *
030: * @version 1.01, 06/20/99, RT
031: */
032: public class EventMulticaster implements AOMListener,
033: RequestQueueListener, RPPoolManagerListener, POAListener,
034: EventListener {
035: protected EventListener one, two;
036:
037: protected EventMulticaster(EventListener _one, EventListener _two) {
038: one = _one;
039: two = _two;
040: }
041:
042: protected static AOMListener add(AOMListener _one, AOMListener _two) {
043: return (AOMListener) add_(_one, _two);
044: }
045:
046: protected static POAListener add(POAListener _one, POAListener _two) {
047: return (POAListener) add_(_one, _two);
048: }
049:
050: protected static RequestQueueListener add(
051: RequestQueueListener _one, RequestQueueListener _two) {
052: return (RequestQueueListener) add_(_one, _two);
053: }
054:
055: protected static RPPoolManagerListener add(
056: RPPoolManagerListener _one, RPPoolManagerListener _two) {
057: return (RPPoolManagerListener) add_(_one, _two);
058: }
059:
060: protected static EventListener add_(EventListener _one,
061: EventListener _two) {
062: if (_one == null)
063: return _two;
064: if (_two == null)
065: return _one;
066: return new EventMulticaster(_one, _two);
067: }
068:
069: public void objectActivated(byte[] oid, Servant servant, int size) {
070: ((AOMListener) one).objectActivated(oid, servant, size);
071: ((AOMListener) two).objectActivated(oid, servant, size);
072: }
073:
074: public void objectDeactivated(byte[] oid, Servant servant, int size) {
075: ((AOMListener) one).objectDeactivated(oid, servant, size);
076: ((AOMListener) two).objectDeactivated(oid, servant, size);
077: }
078:
079: public void poaCreated(POA poa) {
080: ((POAListener) one).poaCreated(poa);
081: ((POAListener) two).poaCreated(poa);
082: }
083:
084: public void poaStateChanged(POA poa, int new_state) {
085: ((POAListener) one).poaStateChanged(poa, new_state);
086: ((POAListener) two).poaStateChanged(poa, new_state);
087: }
088:
089: public void processorAddedToPool(RequestProcessor processor,
090: int pool_count, int pool_size) {
091: ((RPPoolManagerListener) one).processorAddedToPool(processor,
092: pool_count, pool_size);
093: ((RPPoolManagerListener) two).processorAddedToPool(processor,
094: pool_count, pool_size);
095: }
096:
097: public void processorRemovedFromPool(RequestProcessor processor,
098: int pool_count, int pool_size) {
099: ((RPPoolManagerListener) one).processorRemovedFromPool(
100: processor, pool_count, pool_size);
101: ((RPPoolManagerListener) two).processorRemovedFromPool(
102: processor, pool_count, pool_size);
103: }
104:
105: public void referenceCreated(org.omg.CORBA.Object object) {
106: ((POAListener) one).referenceCreated(object);
107: ((POAListener) two).referenceCreated(object);
108: }
109:
110: protected static AOMListener remove(AOMListener l, AOMListener old) {
111: return (AOMListener) remove_(l, old);
112: }
113:
114: protected EventListener remove(EventListener l) {
115: if (l == one)
116: return two;
117: if (l == two)
118: return one;
119: EventListener a = remove_(one, l);
120: EventListener b = remove_(two, l);
121: if (a == one && b == two) {
122: return this ;
123: }
124: return add_(a, b);
125: }
126:
127: protected static POAListener remove(POAListener l, POAListener old) {
128: return (POAListener) remove_(l, old);
129: }
130:
131: protected static RequestQueueListener remove(
132: RequestQueueListener l, RequestQueueListener old) {
133: return (RequestQueueListener) remove_(l, old);
134: }
135:
136: protected static RPPoolManagerListener remove(
137: RPPoolManagerListener l, RPPoolManagerListener old) {
138: return (RPPoolManagerListener) remove_(l, old);
139: }
140:
141: protected static EventListener remove_(EventListener l,
142: EventListener old) {
143: if (l == old || l == null) {
144: return null;
145: } else if (l instanceof EventMulticaster) {
146: return ((EventMulticaster) l).remove(old);
147: } else {
148: return l;
149: }
150: }
151:
152: public void requestAddedToQueue(ServerRequest request,
153: int queue_size) {
154: ((RequestQueueListener) one).requestAddedToQueue(request,
155: queue_size);
156: ((RequestQueueListener) two).requestAddedToQueue(request,
157: queue_size);
158: }
159:
160: public void requestRemovedFromQueue(ServerRequest request,
161: int queue_size) {
162: ((RequestQueueListener) one).requestRemovedFromQueue(request,
163: queue_size);
164: ((RequestQueueListener) two).requestRemovedFromQueue(request,
165: queue_size);
166: }
167:
168: public void servantEtherialized(byte[] oid, Servant servant) {
169: ((AOMListener) one).servantEtherialized(oid, servant);
170: ((AOMListener) two).servantEtherialized(oid, servant);
171: }
172:
173: public void servantIncarnated(byte[] oid, Servant servant) {
174: ((AOMListener) one).servantIncarnated(oid, servant);
175: ((AOMListener) two).servantIncarnated(oid, servant);
176: }
177: }
|