01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.server.impl.invocation;
23:
24: import org.jboss.portal.jems.as.system.AbstractJBossService;
25:
26: import javax.management.ObjectName;
27:
28: /**
29: * Register an interceptor on a stack factory. The main usage is for dynamic registration of an interceptor when the
30: * interceptor cannot be specified in the stack factory dependencies.
31: *
32: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
33: * @version $Revision: 8784 $
34: */
35: public class JBossInterceptorRegistration extends AbstractJBossService {
36:
37: /** . */
38: private ObjectName interceptorName;
39:
40: /** . */
41: private ObjectName stackFactory;
42:
43: public ObjectName getInterceptorName() {
44: return interceptorName;
45: }
46:
47: public void setInterceptorName(ObjectName interceptorName) {
48: this .interceptorName = interceptorName;
49: }
50:
51: public ObjectName getStackFactory() {
52: return stackFactory;
53: }
54:
55: public void setStackFactory(ObjectName stackFactory) {
56: this .stackFactory = stackFactory;
57: }
58:
59: protected void startService() throws Exception {
60: try {
61: server.invoke(stackFactory, "addInterceptor",
62: new Object[] { interceptorName },
63: new String[] { ObjectName.class.getName() });
64: } finally {
65: rebuildStackFactory();
66: }
67: }
68:
69: protected void stopService() throws Exception {
70: try {
71: server.invoke(stackFactory, "removeInterceptor",
72: new Object[] { interceptorName },
73: new String[] { ObjectName.class.getName() });
74: } finally {
75: rebuildStackFactory();
76: }
77: }
78:
79: private void rebuildStackFactory() {
80: try {
81: server.invoke(stackFactory, "rebuild", new Object[0],
82: new String[0]);
83: } catch (Exception e) {
84: log.warn("Exception during rebuild of stack factory", e);
85: }
86: }
87: }
|