Source Code Cross Referenced for ActiveMQManagerGBean.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » activemq » management » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.activemq.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *   Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.activemq.management;
017:
018:        import java.util.ArrayList;
019:        import java.util.Iterator;
020:        import java.util.List;
021:        import java.util.Set;
022:
023:        import org.apache.commons.logging.Log;
024:        import org.apache.commons.logging.LogFactory;
025:
026:        import org.apache.geronimo.activemq.ActiveMQBroker;
027:        import org.apache.geronimo.activemq.ActiveMQConnector;
028:        import org.apache.geronimo.activemq.ActiveMQManager;
029:        import org.apache.geronimo.activemq.TransportConnectorGBeanImpl;
030:        import org.apache.geronimo.gbean.AbstractName;
031:        import org.apache.geronimo.gbean.AbstractNameQuery;
032:        import org.apache.geronimo.gbean.GBeanData;
033:        import org.apache.geronimo.gbean.GBeanInfo;
034:        import org.apache.geronimo.gbean.GBeanInfoBuilder;
035:        import org.apache.geronimo.gbean.ReferencePatterns;
036:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
037:        import org.apache.geronimo.kernel.GBeanNotFoundException;
038:        import org.apache.geronimo.kernel.Kernel;
039:        import org.apache.geronimo.kernel.config.ConfigurationUtil;
040:        import org.apache.geronimo.kernel.config.EditableConfigurationManager;
041:        import org.apache.geronimo.kernel.config.InvalidConfigException;
042:        import org.apache.geronimo.kernel.proxy.ProxyManager;
043:        import org.apache.geronimo.management.geronimo.JMSBroker;
044:        import org.apache.geronimo.management.geronimo.JMSConnector;
045:        import org.apache.geronimo.management.geronimo.NetworkConnector;
046:
047:        /**
048:         * Implementation of the ActiveMQ management interface.  These are the ActiveMQ
049:         * management features available at runtime.
050:         *
051:         * @version $Rev: 519774 $ $Date: 2007-03-18 18:01:01 -0700 (Sun, 18 Mar 2007) $
052:         */
053:        public class ActiveMQManagerGBean implements  ActiveMQManager {
054:            private static final Log log = LogFactory
055:                    .getLog(ActiveMQManagerGBean.class.getName());
056:            private Kernel kernel;
057:            private String objectName;
058:
059:            public ActiveMQManagerGBean(Kernel kernel, String objectName) {
060:                this .kernel = kernel;
061:                this .objectName = objectName;
062:            }
063:
064:            public String getProductName() {
065:                return "ActiveMQ";
066:            }
067:
068:            public String getObjectName() {
069:                return objectName;
070:            }
071:
072:            public boolean isEventProvider() {
073:                return false;
074:            }
075:
076:            public boolean isStateManageable() {
077:                return true;
078:            }
079:
080:            public boolean isStatisticsProvider() {
081:                return false;
082:            }
083:
084:            public Object[] getContainers() {
085:                ProxyManager proxyManager = kernel.getProxyManager();
086:                AbstractNameQuery query = new AbstractNameQuery(
087:                        ActiveMQBroker.class.getName());
088:                Set names = kernel.listGBeans(query);
089:                ActiveMQBroker[] results = new ActiveMQBroker[names.size()];
090:                int i = 0;
091:                for (Iterator it = names.iterator(); it.hasNext(); i++) {
092:                    AbstractName name = (AbstractName) it.next();
093:                    results[i] = (ActiveMQBroker) proxyManager.createProxy(
094:                            name, ActiveMQBroker.class.getClassLoader());
095:                }
096:                return results;
097:            }
098:
099:            public String[] getSupportedProtocols() {
100:                // see files in modules/core/src/conf/META-INF/services/org/activemq/transport/server/
101:                return new String[] { "tcp", "stomp", "vm", "peer", "udp",
102:                        "multicast", "failover" };
103:            }
104:
105:            public NetworkConnector[] getConnectors() {
106:                ProxyManager proxyManager = kernel.getProxyManager();
107:                AbstractNameQuery query = new AbstractNameQuery(
108:                        ActiveMQConnector.class.getName());
109:                Set names = kernel.listGBeans(query);
110:                ActiveMQConnector[] results = new ActiveMQConnector[names
111:                        .size()];
112:                int i = 0;
113:                for (Iterator it = names.iterator(); it.hasNext(); i++) {
114:                    AbstractName name = (AbstractName) it.next();
115:                    results[i] = (ActiveMQConnector) proxyManager.createProxy(
116:                            name, ActiveMQConnector.class.getClassLoader());
117:                }
118:                return results;
119:            }
120:
121:            public NetworkConnector[] getConnectors(String protocol) {
122:                if (protocol == null) {
123:                    return getConnectors();
124:                }
125:                List result = new ArrayList();
126:                ProxyManager proxyManager = kernel.getProxyManager();
127:                AbstractNameQuery query = new AbstractNameQuery(
128:                        ActiveMQConnector.class.getName());
129:                Set names = kernel.listGBeans(query);
130:                for (Iterator it = names.iterator(); it.hasNext();) {
131:                    AbstractName name = (AbstractName) it.next();
132:                    try {
133:                        if (kernel.getAttribute(name, "protocol").equals(
134:                                protocol)) {
135:                            result.add(proxyManager.createProxy(name,
136:                                    ActiveMQConnector.class.getClassLoader()));
137:                        }
138:                    } catch (Exception e) {
139:                        log.error(
140:                                "Unable to check the protocol for a connector",
141:                                e);
142:                    }
143:                }
144:                return (ActiveMQConnector[]) result
145:                        .toArray(new ActiveMQConnector[names.size()]);
146:            }
147:
148:            public NetworkConnector[] getConnectorsForContainer(Object broker) {
149:                AbstractName containerName = kernel.getAbstractNameFor(broker);
150:                ProxyManager mgr = kernel.getProxyManager();
151:                try {
152:                    List results = new ArrayList();
153:                    AbstractNameQuery query = new AbstractNameQuery(
154:                            ActiveMQConnector.class.getName());
155:                    Set set = kernel.listGBeans(query); // all Jetty connectors
156:                    for (Iterator it = set.iterator(); it.hasNext();) {
157:                        AbstractName name = (AbstractName) it.next(); // a single Jetty connector
158:                        GBeanData data = kernel.getGBeanData(name);
159:                        ReferencePatterns refs = data
160:                                .getReferencePatterns("brokerService");
161:                        if (containerName.equals(refs.getAbstractName())) {
162:                            results.add(mgr.createProxy(name,
163:                                    ActiveMQConnector.class.getClassLoader()));
164:                        }
165:                    }
166:                    return (ActiveMQConnector[]) results
167:                            .toArray(new ActiveMQConnector[results.size()]);
168:                } catch (Exception e) {
169:                    throw (IllegalArgumentException) new IllegalArgumentException(
170:                            "Unable to look up connectors for ActiveMQ broker '"
171:                                    + containerName).initCause(e);
172:                }
173:            }
174:
175:            public NetworkConnector[] getConnectorsForContainer(Object broker,
176:                    String protocol) {
177:                if (protocol == null) {
178:                    return getConnectorsForContainer(broker);
179:                }
180:                AbstractName containerName = kernel.getAbstractNameFor(broker);
181:                ProxyManager mgr = kernel.getProxyManager();
182:                try {
183:                    List results = new ArrayList();
184:                    AbstractNameQuery query = new AbstractNameQuery(
185:                            ActiveMQConnector.class.getName());
186:                    Set set = kernel.listGBeans(query); // all Jetty connectors
187:                    for (Iterator it = set.iterator(); it.hasNext();) {
188:                        AbstractName name = (AbstractName) it.next(); // a single Jetty connector
189:                        GBeanData data = kernel.getGBeanData(name);
190:                        ReferencePatterns refs = data
191:                                .getReferencePatterns("brokerService");
192:                        if (containerName.equals(refs.getAbstractName())) {
193:                            try {
194:                                String testProtocol = (String) kernel
195:                                        .getAttribute(name, "protocol");
196:                                if (testProtocol != null
197:                                        && testProtocol.equals(protocol)) {
198:                                    results.add(mgr.createProxy(name,
199:                                            ActiveMQConnector.class
200:                                                    .getClassLoader()));
201:                                }
202:                            } catch (Exception e) {
203:                                log.error(
204:                                        "Unable to look up protocol for connector '"
205:                                                + name + "'", e);
206:                            }
207:                            break;
208:                        }
209:                    }
210:                    return (ActiveMQConnector[]) results
211:                            .toArray(new ActiveMQConnector[results.size()]);
212:                } catch (Exception e) {
213:                    throw (IllegalArgumentException) new IllegalArgumentException(
214:                            "Unable to look up connectors for ActiveMQ broker '"
215:                                    + containerName + "': ").initCause(e);
216:                }
217:            }
218:
219:            /**
220:             * Returns a new JMSConnector.  Note that
221:             * the connector may well require further customization before being fully
222:             * functional (e.g. SSL settings for a secure connector).
223:             */
224:            public JMSConnector addConnector(JMSBroker broker,
225:                    String uniqueName, String protocol, String host, int port) {
226:                AbstractName brokerAbstractName = kernel
227:                        .getAbstractNameFor(broker);
228:                AbstractName name = kernel.getNaming().createChildName(
229:                        brokerAbstractName, uniqueName,
230:                        NameFactory.GERONIMO_SERVICE);
231:                GBeanData connector = new GBeanData(name,
232:                        TransportConnectorGBeanImpl.GBEAN_INFO);
233:                //todo: if SSL is supported, need to add more properties or use a different GBean?
234:                connector.setAttribute("protocol", protocol);
235:                connector.setAttribute("host", host);
236:                connector.setAttribute("port", new Integer(port));
237:                connector.setReferencePattern("brokerService",
238:                        brokerAbstractName);
239:                EditableConfigurationManager mgr = ConfigurationUtil
240:                        .getEditableConfigurationManager(kernel);
241:                if (mgr != null) {
242:                    try {
243:                        mgr.addGBeanToConfiguration(brokerAbstractName
244:                                .getArtifact(), connector, false);
245:                        return (JMSConnector) kernel.getProxyManager()
246:                                .createProxy(
247:                                        name,
248:                                        ActiveMQConnector.class
249:                                                .getClassLoader());
250:                    } catch (InvalidConfigException e) {
251:                        log.error("Unable to add GBean", e);
252:                        return null;
253:                    } finally {
254:                        ConfigurationUtil.releaseConfigurationManager(kernel,
255:                                mgr);
256:                    }
257:                } else {
258:                    log
259:                            .warn("The ConfigurationManager in the kernel does not allow editing");
260:                    return null;
261:                }
262:            }
263:
264:            public void removeConnector(AbstractName connectorName) {
265:                try {
266:                    GBeanInfo info = kernel.getGBeanInfo(connectorName);
267:                    boolean found = false;
268:                    Set intfs = info.getInterfaces();
269:                    for (Iterator it = intfs.iterator(); it.hasNext();) {
270:                        String intf = (String) it.next();
271:                        if (intf.equals(ActiveMQConnector.class.getName())) {
272:                            found = true;
273:                        }
274:                    }
275:                    if (!found) {
276:                        throw new GBeanNotFoundException(connectorName);
277:                    }
278:                    EditableConfigurationManager mgr = ConfigurationUtil
279:                            .getEditableConfigurationManager(kernel);
280:                    if (mgr != null) {
281:                        try {
282:                            mgr.removeGBeanFromConfiguration(connectorName
283:                                    .getArtifact(), connectorName);
284:                        } catch (InvalidConfigException e) {
285:                            log.error("Unable to add GBean", e);
286:                        } finally {
287:                            ConfigurationUtil.releaseConfigurationManager(
288:                                    kernel, mgr);
289:                        }
290:                    } else {
291:                        log
292:                                .warn("The ConfigurationManager in the kernel does not allow editing");
293:                    }
294:                } catch (GBeanNotFoundException e) {
295:                    log.warn("No such GBean '" + connectorName + "'"); //todo: what if we want to remove a failed GBean?
296:                } catch (Exception e) {
297:                    log.error(e);
298:                }
299:            }
300:
301:            public static final GBeanInfo GBEAN_INFO;
302:
303:            static {
304:                GBeanInfoBuilder infoFactory = new GBeanInfoBuilder(
305:                        "ActiveMQ Manager", ActiveMQManagerGBean.class);
306:                infoFactory.addAttribute("kernel", Kernel.class, false);
307:                infoFactory.addAttribute("objectName", String.class, false);
308:                infoFactory.addInterface(ActiveMQManager.class);
309:                infoFactory.setConstructor(new String[] { "kernel",
310:                        "objectName" });
311:                GBEAN_INFO = infoFactory.getBeanInfo();
312:            }
313:
314:            public static GBeanInfo getGBeanInfo() {
315:                return GBEAN_INFO;
316:            }
317:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.