KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > poa > EventMulticaster


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library 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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.poa;
22
23 import org.omg.PortableServer.Servant JavaDoc;
24 import org.jacorb.orb.dsi.ServerRequest;
25
26 /**
27  * This class will manage an structure of a chain of poa event listeners
28  * and will dispatch events to those listeners.
29  *
30  * @version 1.01, 06/20/99, RT
31  */

32 public class EventMulticaster
33     implements AOMListener, RequestQueueListener, RPPoolManagerListener, POAListener, EventListener {
34     protected EventListener one, two;
35     protected EventMulticaster(EventListener _one, EventListener _two) {
36         one = _one;
37         two = _two;
38     }
39     protected static AOMListener add(AOMListener _one, AOMListener _two) {
40         return (AOMListener) add_(_one, _two);
41     }
42     protected static POAListener add(POAListener _one, POAListener _two) {
43         return (POAListener) add_(_one, _two);
44     }
45     protected static RequestQueueListener add(RequestQueueListener _one, RequestQueueListener _two) {
46         return (RequestQueueListener) add_(_one, _two);
47     }
48     protected static RPPoolManagerListener add(RPPoolManagerListener _one, RPPoolManagerListener _two) {
49         return (RPPoolManagerListener) add_(_one, _two);
50     }
51     protected static EventListener add_(EventListener _one, EventListener _two) {
52         if (_one == null) return _two;
53         if (_two == null) return _one;
54         return new EventMulticaster(_one, _two);
55     }
56     public void objectActivated(byte[] oid, Servant JavaDoc servant, int size) {
57         ((AOMListener)one).objectActivated(oid, servant, size);
58         ((AOMListener)two).objectActivated(oid, servant, size);
59     }
60     public void objectDeactivated(byte[] oid, Servant JavaDoc servant, int size) {
61         ((AOMListener)one).objectDeactivated(oid, servant, size);
62         ((AOMListener)two).objectDeactivated(oid, servant, size);
63     }
64     public void poaCreated(POA poa) {
65         ((POAListener)one).poaCreated(poa);
66         ((POAListener)two).poaCreated(poa);
67     }
68     public void poaStateChanged(POA poa, int new_state) {
69         ((POAListener)one).poaStateChanged(poa, new_state);
70         ((POAListener)two).poaStateChanged(poa, new_state);
71     }
72     public void processorAddedToPool(RequestProcessor processor, int pool_count, int pool_size) {
73         ((RPPoolManagerListener)one).processorAddedToPool(processor, pool_count, pool_size);
74         ((RPPoolManagerListener)two).processorAddedToPool(processor, pool_count, pool_size);
75     }
76     public void processorRemovedFromPool(RequestProcessor processor, int pool_count, int pool_size) {
77         ((RPPoolManagerListener)one).processorRemovedFromPool(processor, pool_count, pool_size);
78         ((RPPoolManagerListener)two).processorRemovedFromPool(processor, pool_count, pool_size);
79     }
80     public void referenceCreated(org.omg.CORBA.Object JavaDoc object) {
81         ((POAListener)one).referenceCreated(object);
82         ((POAListener)two).referenceCreated(object);
83     }
84     protected static AOMListener remove(AOMListener l, AOMListener old) {
85         return (AOMListener) remove_(l, old);
86     }
87     protected EventListener remove(EventListener l) {
88         if (l == one) return two;
89         if (l == two) return one;
90         EventListener a = remove_(one, l);
91         EventListener b = remove_(two, l);
92         if (a == one && b == two) {
93             return this;
94         }
95         return add_(a, b);
96     }
97     protected static POAListener remove(POAListener l, POAListener old) {
98         return (POAListener) remove_(l, old);
99     }
100     protected static RequestQueueListener remove(RequestQueueListener l, RequestQueueListener old) {
101         return (RequestQueueListener) remove_(l, old);
102     }
103     protected static RPPoolManagerListener remove(RPPoolManagerListener l, RPPoolManagerListener old) {
104         return (RPPoolManagerListener) remove_(l, old);
105     }
106     protected static EventListener remove_(EventListener l, EventListener old) {
107         if (l == old || l == null) {
108             return null;
109         } else if (l instanceof EventMulticaster) {
110             return ((EventMulticaster) l).remove(old);
111         } else {
112             return l;
113         }
114     }
115     public void requestAddedToQueue(ServerRequest request, int queue_size) {
116         ((RequestQueueListener)one).requestAddedToQueue(request, queue_size);
117         ((RequestQueueListener)two).requestAddedToQueue(request, queue_size);
118     }
119     public void requestRemovedFromQueue(ServerRequest request, int queue_size) {
120         ((RequestQueueListener)one).requestRemovedFromQueue(request, queue_size);
121         ((RequestQueueListener)two).requestRemovedFromQueue(request, queue_size);
122     }
123     public void servantEtherialized(byte[] oid, Servant JavaDoc servant) {
124         ((AOMListener)one).servantEtherialized(oid, servant);
125         ((AOMListener)two).servantEtherialized(oid, servant);
126     }
127     public void servantIncarnated(byte[] oid, Servant JavaDoc servant) {
128         ((AOMListener)one).servantIncarnated(oid, servant);
129         ((AOMListener)two).servantIncarnated(oid, servant);
130     }
131 }
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Popular Tags