KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > remoting > ServerInterceptorChain


1
2 /*
3  * JBoss, the OpenSource J2EE webOS
4  *
5  * Distributable under LGPL license.
6  * See terms of license at gnu.org.
7  *
8  */

9
10 package org.jboss.remoting;
11
12 import org.jboss.remoting.transport.Connector;
13
14 import javax.management.MBeanRegistration JavaDoc;
15 import javax.management.MBeanServer JavaDoc;
16 import javax.management.ObjectName JavaDoc;
17 import java.util.ArrayList JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21
22
23 /**
24  * ServerInterceptorChain.java
25  *
26  *
27  * Created: Fri May 2 10:36:51 2003
28  *
29  * @author <a HREF="mailto:d_jencks@users.sourceforge.net">David Jencks</a>
30  * @version 1.0
31  *
32  * @jmx.mbean description="ServerInvocationHandler that represents a chain of ServerInterceptors"
33  *
34  * @jboss.xmbean
35  */

36 public class ServerInterceptorChain
37    implements MBeanRegistration JavaDoc, ServerInvocationHandler
38 {
39
40    private MBeanServer JavaDoc server;
41
42    private Connector connector;
43    private ObjectName JavaDoc connectorName;
44    private String JavaDoc subsystem;
45    private List JavaDoc interceptorNames;
46    private List JavaDoc interceptors;
47
48    public ServerInterceptorChain()
49    {
50
51    } // ServerInterceptorChain constructor
52

53
54    /**
55     * Get the Connector value.
56     * @return the Connector value.
57     * not managed
58     */

59    public Connector getConnector()
60    {
61       return connector;
62    }
63
64    /**
65     * Set the Connector value.
66     * @param newConnector The new Connector value.
67     * not managed
68     */

69    public void setConnector(Connector newConnector)
70    {
71       this.connector = newConnector;
72    }
73
74
75    /**
76     * Get the ConnectorName value.
77     * @return the ConnectorName value.
78     *
79     * @jmx.managed-attribute description="Object name of the Connector we register with"
80     * type="ObjectName"
81     * access="read-write"
82     */

83    public ObjectName JavaDoc getConnectorName()
84    {
85       return connectorName;
86    }
87
88    /**
89     * Set the ConnectorName value.
90     * @param newConnectorName The new ConnectorName value.
91     *
92     * @jmx.managed-attribute
93     */

94    public void setConnectorName(ObjectName JavaDoc newConnectorName)
95    {
96       this.connectorName = newConnectorName;
97    }
98
99
100    /**
101     * Get the Subsystem value.
102     * @return the Subsystem value.
103     * @jmx.managed-attribute description="Name of the subsystem we work for"
104     * type="String"
105     * access="read-write"
106     */

107    public String JavaDoc getSubsystem()
108    {
109       return subsystem;
110    }
111
112    /**
113     * Set the Subsystem value.
114     * @param newSubsystem The new Subsystem value.
115     *
116     * @jmx.managed-attribute
117     */

118    public void setSubsystem(String JavaDoc newSubsystem)
119    {
120       this.subsystem = newSubsystem;
121    }
122
123
124    /**
125     * Get the Interceptors value.
126     * @return the Interceptors value.
127     * not managed
128     */

129    public List JavaDoc getInterceptors()
130    {
131       return interceptors;
132    }
133
134    /**
135     * Set the Interceptors value.
136     * @param newInterceptors The new Interceptors value.
137     * not managed
138     */

139    public void setInterceptors(List JavaDoc newInterceptors)
140    {
141       this.interceptors = newInterceptors;
142    }
143
144
145    /**
146     * Get the InterceptorName value.
147     * @return the InterceptorName value.
148     * @jmx.managed-attribute description="List of object names of the ServerInterceptors we delegate to"
149     * type="List"
150     * access="read-write"
151     */

152    public List JavaDoc getInterceptorNames()
153    {
154       return interceptorNames;
155    }
156
157    /**
158     * Set the InterceptorName value.
159     * @param newInterceptorName The new InterceptorName value.
160     *
161     * @jmx.managed-attribute
162     */

163    public void setInterceptorNames(List JavaDoc newInterceptorNames)
164    {
165       this.interceptorNames = newInterceptorNames;
166    }
167
168
169    // Implementation of javax.management.MBeanRegistration
170

171    /**
172     * The <code>preRegister</code> method
173     *
174     * @param MBeanServer a <code>MBeanServer</code> value
175     * @param objectName an <code>ObjectName</code> value
176     * @return an <code>ObjectName</code> value
177     * @exception Exception if an error occurs
178     */

179    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc objectName) throws Exception JavaDoc
180    {
181       this.server = server;
182       return objectName;
183    }
184
185    /**
186     * The <code>postRegister</code> method
187     *
188     */

189    public void postRegister(Boolean JavaDoc success)
190    {
191
192    }
193
194    /**
195     * The <code>preDeregister</code> method
196     *
197     * @exception Exception if an error occurs
198     */

199    public void preDeregister() throws Exception JavaDoc
200    {
201
202    }
203
204    /**
205     * The <code>postDeregister</code> method
206     *
207     */

208    public void postDeregister()
209    {
210
211    }
212
213    //JBoss lifecycle methods
214
/**
215     * The <code>start</code> method
216     *
217     * @exception Exception if an error occurs
218     *
219     * @jmx.managed-operation description="JBoss lifecycle method to set up the interceptor chain from the list of interceptor object names"
220     */

221    public void start() throws Exception JavaDoc
222    {
223       List JavaDoc interceptors = new ArrayList JavaDoc();
224       for (Iterator JavaDoc i = interceptorNames.iterator(); i.hasNext(); )
225       {
226          ObjectName JavaDoc iname = (ObjectName JavaDoc)i.next();
227          ServerInterceptor si = (ServerInterceptor)server.getAttribute(iname, "Instance");
228          interceptors.add(si);
229       } // end of for ()
230
this.interceptors = interceptors;
231
232       //register with connector
233
if (connector != null)
234       {
235          connector.addInvocationHandler(subsystem, this);
236       } // end of if ()
237
else
238       {
239          server.invoke(connectorName,
240                        "addInvocationHandler",
241                        new Object JavaDoc[] {subsystem, this},
242                        new String JavaDoc[] {String JavaDoc.class.getName(), ServerInvocationHandler.class.getName()});
243       } // end of else
244

245
246    }
247
248    /**
249     * The <code>stop</code> method
250     *
251     * @exception Exception if an error occurs
252     *
253     * @jmx.managed-operation description="JBoss lifecycle method to tear down the list of interceptors"
254     */

255    public void stop() throws Exception JavaDoc
256    {
257       //register with connector
258
if (connector != null)
259       {
260          connector.removeInvocationHandler(subsystem);
261       } // end of if ()
262
else
263       {
264          server.invoke(connectorName,
265                        "removeInvocationHandler",
266                        new Object JavaDoc[] {subsystem},
267                        new String JavaDoc[] {String JavaDoc.class.getName()});
268       } // end of else
269
interceptors.clear();//???????
270
}
271
272
273    // Implementation of org.jboss.remoting.ServerInvocationHandler
274

275    /**
276     * The <code>addListener</code> method
277     *
278     * @param invokerCallbackHandler an <code>InvokerCallbackHandler</code> value
279     */

280    public void addListener(InvokerCallbackHandler invokerCallbackHandler)
281    {
282
283    }
284
285    /**
286     * The <code>removeListener</code> method
287     *
288     * @param invokerCallbackHandler an <code>InvokerCallbackHandler</code> value
289     */

290    public void removeListener(InvokerCallbackHandler invokerCallbackHandler)
291    {
292
293    }
294
295    /**
296     * The <code>setMBeanServer</code> method
297     *
298     * @param MBeanServer a <code>MBeanServer</code> value
299     */

300    public void setMBeanServer(MBeanServer JavaDoc MBeanServer)
301    {
302
303    }
304
305    /**
306     * The <code>invoke</code> method
307     *
308     * @param invocationRequest an <code>InvocationRequest</code> value
309     * @return an <code>Object</code> value
310     * @exception Throwable if an error occurs
311     */

312    public Object JavaDoc invoke(InvocationRequest invocation) throws Throwable JavaDoc
313    {
314       InterceptorIterator iterator = new InterceptorIterator(interceptors.iterator(), invocation);
315       return iterator.invokeNext();
316    }
317
318    /**
319     * The <code>setInvoker</code> method
320     *
321     * @param serverInvoker a <code>ServerInvoker</code> value
322     */

323    public void setInvoker(ServerInvoker serverInvoker)
324    {
325
326    }
327
328    public static class InterceptorIterator
329    {
330       private final Iterator JavaDoc iterator;
331       private final InvocationRequest invocation;
332
333       public InterceptorIterator(final Iterator JavaDoc iterator, final InvocationRequest invocation)
334       {
335          this.iterator = iterator;
336          this.invocation = invocation;
337       }
338
339       public Object JavaDoc invokeNext() throws Throwable JavaDoc
340       {
341          return ((ServerInterceptor)iterator.next()).invoke(this, invocation);
342       }
343
344    }
345
346 } // ServerInterceptorChain
347
Popular Tags