Source Code Cross Referenced for AdminService.java in  » ESB » open-esb » com » sun » jbi » management » system » 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 » ESB » open esb » com.sun.jbi.management.system 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * BEGIN_HEADER - DO NOT EDIT
0003:         *
0004:         * The contents of this file are subject to the terms
0005:         * of the Common Development and Distribution License
0006:         * (the "License").  You may not use this file except
0007:         * in compliance with the License.
0008:         *
0009:         * You can obtain a copy of the license at
0010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011:         * See the License for the specific language governing
0012:         * permissions and limitations under the License.
0013:         *
0014:         * When distributing Covered Code, include this CDDL
0015:         * HEADER in each file and include the License file at
0016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017:         * If applicable add the following below this CDDL HEADER,
0018:         * with the fields enclosed by brackets "[]" replaced with
0019:         * your own identifying information: Portions Copyright
0020:         * [year] [name of copyright owner]
0021:         */
0022:
0023:        /*
0024:         * @(#)AdminService.java
0025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026:         *
0027:         * END_HEADER - DO NOT EDIT
0028:         */
0029:        package com.sun.jbi.management.system;
0030:
0031:        import com.sun.jbi.VersionInfo;
0032:        import com.sun.jbi.management.ConfigurationCategory;
0033:        import com.sun.jbi.management.LocalStringKeys;
0034:        import com.sun.jbi.management.MBeanNames;
0035:        import com.sun.jbi.management.support.JbiNameInfo;
0036:
0037:        import java.net.InetAddress;
0038:        import java.util.ArrayList;
0039:        import java.util.Date;
0040:        import java.util.Iterator;
0041:        import java.util.Set;
0042:        import java.util.logging.Logger;
0043:
0044:        import javax.jbi.JBIException;
0045:        import javax.management.MBeanServerConnection;
0046:        import javax.management.Notification;
0047:        import javax.management.NotificationListener;
0048:        import javax.management.ObjectName;
0049:
0050:        /**
0051:         * AdminServiceMBean defines the Sun Extentions to AdminServiceMBean.
0052:         *
0053:         * The AdminService is responsible for bootstrapping the
0054:         * JBI Framework management layer for all other system services,
0055:         * starting and stoping the system, and providing information
0056:         * that remote clients can use to access other JBI Framework
0057:         * system services and installed components.
0058:         *
0059:         * @author Sun Microsystems, Inc.
0060:         */
0061:        public class AdminService extends ModelSystemService implements 
0062:                AdminServiceMBean, NotificationListener {
0063:
0064:            /**
0065:             * milliseconds between heartbeats
0066:             */
0067:            private long mHeartBeatInterval;
0068:
0069:            /**
0070:             * The heart beat interval notification id.
0071:             */
0072:            private Integer mNotificationId;
0073:
0074:            /**
0075:             * instance of the AutoAdminTask class
0076:             */
0077:            private static AutoAdminTask sAutoAdminTask = null;
0078:
0079:            /** JMX object names for all JBI system "service" lifecycle MBeans: */
0080:            private ObjectName mAdminServiceLifeCycleMBeanName;
0081:            private ObjectName mConfigServiceLifeCycleMBeanName;
0082:            private ObjectName mDeployServiceLifeCycleMBeanName;
0083:            private ObjectName mInstallServiceLifeCycleMBeanName;
0084:            private ObjectName mLoggingServiceLifeCycleMBeanName;
0085:            private ObjectName mMessageServiceLifeCycleMBeanName;
0086:
0087:            /** our immutable name: */
0088:            private final JbiNameInfo mJbiNameInfo = new JbiNameInfo(
0089:                    "AdminService");
0090:
0091:            /**
0092:             * Management context
0093:             */
0094:            private ManagementContext mContext = null;
0095:
0096:            /**
0097:             * Management Message Object
0098:             */
0099:            private BuildManagementMessageImpl mMMImpl = null;
0100:
0101:            /**
0102:             * The System Bootstrap instance.
0103:             */
0104:            private SystemBootstrap mEsbSys = null;
0105:
0106:            /**
0107:             * Constructs a AdminService.
0108:             * @param anEnv is the ManagementContext.
0109:             */
0110:            public AdminService(ManagementContext anEnv) {
0111:                mContext = anEnv;
0112:
0113:                /*
0114:                 * Local initialization of this service.
0115:                 * Local routine is responsible for calling super.initModelSystemService(..).
0116:                 */
0117:                initModelSystemService(anEnv.getEnvironmentContext());
0118:
0119:                mMMImpl = mContext.getManagementMessageObject();
0120:            }
0121:
0122:            /** local model init - called by constructor - create custom mbeans. */
0123:            protected void initModelSystemService(
0124:                    com.sun.jbi.EnvironmentContext anEnv) {
0125:                String loggerName = com.sun.jbi.management.config.LoggerConfigurationFactory.ADMIN_LOGGER;
0126:
0127:                Logger logger = Logger.getLogger(loggerName);
0128:
0129:                //initialize the super.
0130:                super .initModelSystemService(anEnv, logger, mJbiNameInfo);
0131:
0132:                //initialize system service lifecycle mbean names,
0133:                //needed by global startup/shutdown ops:
0134:                initSystemServiceLifeCycleMBeanNames();
0135:
0136:                //add AdminService MBean to START/STOP mbean set:
0137:                mStartMBeans.add(mAdminServiceMBeanName,
0138:                        com.sun.jbi.management.system.AdminServiceMBean.class,
0139:                        this );
0140:
0141:                // get the configured heartbeat interval 
0142:                Object interval = getConfigurationAttribute(
0143:                        ConfigurationCategory.System,
0144:                        com.sun.jbi.management.config.SystemConfigurationFactory.HEART_BEAT_INTERVAL);
0145:
0146:                mHeartBeatInterval = (interval == null ? 5500
0147:                        : ((Integer) interval).intValue());
0148:
0149:                mLogger.fine("JBI Admin Service heartbeat interval is "
0150:                        + mHeartBeatInterval + " ms.");
0151:            }
0152:
0153:            /**
0154:             * override model start() method. 
0155:             * @throws JBIException never
0156:             */
0157:            public synchronized void start() throws JBIException {
0158:                String statusMsg = mTranslator.getString(
0159:                        LocalStringKeys.AS_START_SERVICE,
0160:                        "AdminService.start()", "JBI Framework");
0161:                mLogger.fine(statusMsg);
0162:
0163:                // Auto admin tasks are only supported on the DAS
0164:                if (mEnv.getPlatformContext().isAdminServer()) {
0165:                    startAutoTasks();
0166:                }
0167:
0168:                //register mbean start set:
0169:                super .start();
0170:
0171:            }
0172:
0173:            /**
0174:             * override model stop() method. 
0175:             * @throws JBIException never
0176:             */
0177:            public synchronized void stop() throws JBIException {
0178:                if (sAutoAdminTask != null) {
0179:                    stopAutoTasks();
0180:                }
0181:
0182:                //unregister mbean start set:
0183:                super .stop();
0184:            }
0185:
0186:            /* methods inherited from NotificationListener */
0187:
0188:            /**
0189:             * Handle timer notifications.
0190:             * @param aNotification is the received (timer) notification
0191:             * @param anObject is the notification object (ignored)
0192:             */
0193:            public void handleNotification(Notification aNotification,
0194:                    Object anObject) {
0195:                heartBeat();
0196:
0197:                // Switch to a new heart beat if it has changed
0198:                checkHeartBeat();
0199:            }
0200:
0201:            /////////
0202:            //JSR 208 AdminServiceMBean Implementation:
0203:            /////////
0204:
0205:            /**
0206:             * Lookup a system service {@link LifeCycleMBean} by name. System services 
0207:             * are implementation-defined services which can administered through JMX,
0208:             * and have a life cycle.
0209:             * <p>
0210:             * System services are not related to service engines.
0211:             * 
0212:             * @param serviceName name of the system service; must be non-null and non-
0213:             *        empty; values are implementation-dependent
0214:             * @return JMX object name of the system service's LifeCycleMBean, or 
0215:             *         <code>null</code> if there is no system service with the given
0216:             *         <code>name</code>.
0217:             */
0218:            public ObjectName getSystemService(String serviceName) {
0219:                MBeanNames mbn = mContext.getMBeanNames();
0220:                String tmp = mbn.getJmxDomainName();
0221:
0222:                //see if the request is for a management system service:
0223:                String controltype = managementServiceControl(serviceName);
0224:
0225:                //for non-management system services (NMS, etc), lookup the lifecycle mbean:
0226:                if (controltype == null) {
0227:                    controltype = mbn.CONTROL_TYPE_LIFECYCLE;
0228:                }
0229:
0230:                tmp += ":" + mbn.SERVICE_NAME_KEY + "=" + serviceName;
0231:                tmp += "," + mbn.CONTROL_TYPE_KEY + "=" + controltype;
0232:                tmp += "," + mbn.COMPONENT_TYPE_KEY + "="
0233:                        + mbn.COMPONENT_TYPE_SYSTEM;
0234:                tmp += "," + mbn.INSTANCE_NAME_KEY + "="
0235:                        + mbn.getJbiInstanceName();
0236:                //wildcard goes at the end:
0237:                tmp += ",*";
0238:
0239:                //exec the query:
0240:                ObjectName[] names = queryHelper(tmp);
0241:
0242:                if (names.length >= 1) {
0243:                    if (names.length > 1) {
0244:                        String statusMsg = mTranslator
0245:                                .getString(
0246:                                        LocalStringKeys.AS_GETSYSTEMSERVICE_TOO_MANY_MBEANS,
0247:                                        tmp);
0248:
0249:                        mLogger.severe(statusMsg);
0250:                    }
0251:
0252:                    //always return the first mbean name, even if many:
0253:                    return names[0];
0254:                } else {
0255:                    String statusMsg = mTranslator.getString(
0256:                            LocalStringKeys.AS_GETSYSTEMSERVICE_LOOKUP_FAILED,
0257:                            tmp);
0258:
0259:                    mLogger.warning(statusMsg);
0260:                }
0261:
0262:                return null;
0263:            }
0264:
0265:            /**
0266:             * Looks up all JBI system services {@link LifeCycleMBean}'s currently 
0267:             * installed. System services are implementation-defined services which can 
0268:             * administered through JMX. System services are not related to service 
0269:             * engines.
0270:             * 
0271:             * @return array of LifecycleMBean JMX object names of system services 
0272:             *         currently installed in the JBI implementation; must be non-null;
0273:             *         may be empty
0274:             */
0275:            public ObjectName[] getSystemServices() {
0276:                MBeanNames mbn = mContext.getMBeanNames();
0277:                String tmp = mbn.getJmxDomainName();
0278:
0279:                tmp += ":" + mbn.COMPONENT_TYPE_KEY + "="
0280:                        + mbn.COMPONENT_TYPE_SYSTEM;
0281:                tmp += "," + mbn.INSTANCE_NAME_KEY + "="
0282:                        + mbn.getJbiInstanceName();
0283:                //wildcard goes at the end:
0284:                tmp += ",*";
0285:
0286:                //exec the query:
0287:
0288:                ObjectName[] names = queryHelper(tmp);
0289:
0290:                if (names.length >= 1) {
0291:                    ArrayList namelist = new ArrayList();
0292:                    String ctype;
0293:
0294:                    //filter out the "standard" controls:
0295:                    for (int ii = 0; ii < names.length; ii++) {
0296:                        ctype = names[ii].getKeyProperty(mbn.CONTROL_TYPE_KEY);
0297:                        if (ctype != null && ctype.endsWith("Service")) {
0298:                            namelist.add(names[ii]);
0299:                        }
0300:                    }
0301:
0302:                    if (namelist.size() > 0) {
0303:                        ObjectName[] newnames = new ObjectName[namelist.size()];
0304:                        Iterator itr;
0305:                        int ii;
0306:                        for (itr = namelist.iterator(), ii = 0; itr.hasNext(); ii++) {
0307:                            newnames[ii] = (ObjectName) itr.next();
0308:                        }
0309:
0310:                        return newnames;
0311:                    } else {
0312:                        String statusMsg = mTranslator
0313:                                .getString(LocalStringKeys.AS_GETSYSTEMSERVICE_NO_SERVICES);
0314:                        mLogger.severe(statusMsg);
0315:                    }
0316:                } else {
0317:                    String statusMsg = mTranslator.getString(
0318:                            LocalStringKeys.AS_GETSYSTEMSERVICE_LOOKUP_FAILED,
0319:                            tmp);
0320:                    mLogger.warning(statusMsg);
0321:                }
0322:
0323:                return (new ObjectName[0]);
0324:            }
0325:
0326:            /**
0327:             * Find the {@link ComponentLifeCycleMBean} of a JBI Installable Component 
0328:             * by its unique name.
0329:             * 
0330:             * @param name the name of the engine or binding component; must be non-
0331:             *        null and non-empty
0332:             * @return the JMX object name of the component's life cycle MBean, or 
0333:             *         <code>null</code> if there is no such component with the given 
0334:             *         <code>name</code>
0335:             */
0336:            public ObjectName getComponentByName(String name) {
0337:                /*
0338:                 * EXAMPLE:
0339:                com.sun.jbi:ComponentName=ABC,ControlType=Lifecycle,ComponentType=Installed,*
0340:                 */
0341:
0342:                com.sun.jbi.util.EnvironmentAccess.getContext()
0343:                        .isFrameworkReady(true);
0344:
0345:                MBeanNames mbn = mContext.getMBeanNames();
0346:                String tmp = mbn.getJmxDomainName();
0347:
0348:                tmp += ":" + mbn.COMPONENT_ID_KEY + "=" + name;
0349:                tmp += "," + mbn.CONTROL_TYPE_KEY + "="
0350:                        + mbn.CONTROL_TYPE_LIFECYCLE;
0351:                tmp += "," + mbn.COMPONENT_TYPE_KEY + "="
0352:                        + mbn.COMPONENT_TYPE_INSTALLED;
0353:                tmp += "," + mbn.INSTANCE_NAME_KEY + "="
0354:                        + mbn.getJbiInstanceName();
0355:                //wildcard goes at the end:
0356:                tmp += ",*";
0357:
0358:                //exec the query:
0359:                ObjectName[] names = queryHelper(tmp);
0360:
0361:                if (names.length >= 1) {
0362:                    if (names.length > 1) {
0363:                        String statusMsg = mTranslator
0364:                                .getString(
0365:                                        LocalStringKeys.AS_GETCOMPONENTBYID_TOO_MANY_MBEANS,
0366:                                        tmp);
0367:                        mLogger.severe(statusMsg);
0368:                    }
0369:
0370:                    //always return the first mbean name, even if many:
0371:                    return names[0];
0372:                } else {
0373:                    String statusMsg = mTranslator.getString(
0374:                            LocalStringKeys.AS_GETCOMPONENTBYID_LOOKUP_FAILED,
0375:                            tmp);
0376:                    mLogger.warning(statusMsg);
0377:                }
0378:
0379:                return null;
0380:            }
0381:
0382:            /**
0383:             * Get a list of {@link ComponentLifeCycleMBean}s for all binding components 
0384:             * currently installed in the JBI system.
0385:             * 
0386:             * @return array of JMX object names of component life cycle MBeans for all 
0387:             *         installed binding components; must be non-null; may be empty
0388:             */
0389:            public ObjectName[] getBindingComponents() {
0390:                MBeanNames mbn = mContext.getMBeanNames();
0391:                return getInstalledComponents(mbn.INSTALLED_TYPE_BINDING);
0392:            }
0393:
0394:            /**
0395:             * Get a list of {@link ComponentLifeCycleMBean}s for all service engines 
0396:             * currently installed in the JBI system.
0397:             * 
0398:             * @return array of JMX object names of component life cycle MBeans for all 
0399:             *         installed service engines; must be non-null; may be empty
0400:             */
0401:            public ObjectName[] getEngineComponents() {
0402:                MBeanNames mbn = mContext.getMBeanNames();
0403:                return getInstalledComponents(mbn.INSTALLED_TYPE_ENGINE);
0404:            }
0405:
0406:            /**
0407:             * Check if a given JBI component is a Binding Component.
0408:             * 
0409:             * @param componentName the unique name of the component; must be non-null
0410:             *        and non-empty
0411:             * @return <code>true</code> if the component is a binding component; 
0412:             *         <code>false</code> if the component is a service engine or if
0413:             *         there is no component with the given <code>componentName</code>
0414:             *         installed in the JBI system
0415:             */
0416:            public boolean isBinding(String componentName) {
0417:                MBeanNames mbn = mContext.getMBeanNames();
0418:                ObjectName compObj = this .getComponentByName(componentName);
0419:                if (null == compObj) {
0420:                    return false;
0421:                }
0422:                String compType = compObj
0423:                        .getKeyProperty(mbn.INSTALLED_TYPE_KEY);
0424:                return (mbn.INSTALLED_TYPE_BINDING.equals(compType));
0425:            }
0426:
0427:            /**
0428:             * Check if a given JBI component is a Service Engine.
0429:             * 
0430:             * @param componentName the unique name of the component; must be non-null
0431:             *        and non-empty
0432:             * @return <code>true</code> if the component is a service engine;
0433:             *         <code>false</code> if the component is a binding component, or if
0434:             *         there is no component with the given <code>componentName</code>
0435:             *         installed in the JBI system
0436:             */
0437:            public boolean isEngine(String componentName) {
0438:                MBeanNames mbn = mContext.getMBeanNames();
0439:                ObjectName compObj = this .getComponentByName(componentName);
0440:                if (null == compObj) {
0441:                    return false;
0442:                }
0443:                String compType = compObj
0444:                        .getKeyProperty(mbn.INSTALLED_TYPE_KEY);
0445:                return (mbn.INSTALLED_TYPE_ENGINE.equals(compType));
0446:            }
0447:
0448:            /**
0449:             * Return current version and other info about this JBI implementation. The 
0450:             * contents of the returned string are implementation dependent.
0451:             * 
0452:             * @return information string about the JBI implementation, including 
0453:             *         version information; must be non-null and non-empty
0454:             */
0455:            public String getSystemInfo() {
0456:                VersionInfo vers = mContext.getVersionInfo();
0457:
0458:                return (vers.fullProductName() + "\n" + vers.majorVersion()
0459:                        + "." + vers.minorVersion() + "(" + vers.buildNumber()
0460:                        + ")" + "\n" + vers.copyright() + "\n");
0461:            }
0462:
0463:            /////
0464:            //SUN extensions to JRS  208 AdminServiceMBean:
0465:            /////
0466:
0467:            /**
0468:             * Get the DeployerMBean for the <CODE>componentName</CODE> associated with
0469:             * <code>artifactUrl</code>.
0470:             *
0471:             * @return JMX object name of Component's DeployerMBean or null
0472:             */
0473:            public ObjectName[] getDeployerMBeanNames(String componentName) {
0474:                MBeanNames mbn = mContext.getMBeanNames();
0475:
0476:                String qhdr = mbn.getJmxDomainName();
0477:                qhdr += ":" + mbn.COMPONENT_ID_KEY + "=" + componentName;
0478:                qhdr += "," + mbn.COMPONENT_TYPE_KEY + "="
0479:                        + mbn.COMPONENT_TYPE_INSTALLED;
0480:                qhdr += "," + mbn.CONTROL_TYPE_KEY + "="
0481:                        + mbn.CONTROL_TYPE_DEPLOYER;
0482:                qhdr += "," + mbn.INSTANCE_NAME_KEY + "="
0483:                        + mbn.getJbiInstanceName();
0484:                //wildcard goes at the end:
0485:                qhdr += ",*";
0486:
0487:                //exec the query and return the result:
0488:                return queryHelper(qhdr);
0489:            }
0490:
0491:            /**
0492:             * Return the name of this JBI Framework runtime
0493:             *
0494:             * @return the instance name of this runtime.
0495:             */
0496:            public String getJbiInstanceName() {
0497:                MBeanNames mbn = mContext.getMBeanNames();
0498:                return mbn.getJbiInstanceName();
0499:            }
0500:
0501:            /**
0502:             * Lookup all active MBeans associated with <CODE>componentName</CODE>.
0503:             * @param componentName - is the name of the BC or SE.
0504:             * @return the array of JMX object names for the component.
0505:             */
0506:            public ObjectName[] getComponentMBeans(String componentName) {
0507:                MBeanNames mbn = mContext.getMBeanNames();
0508:                String tmp = mbn.getJmxDomainName();
0509:
0510:                tmp += ":" + mbn.COMPONENT_ID_KEY + "=" + componentName;
0511:                tmp += "," + mbn.COMPONENT_TYPE_KEY + "="
0512:                        + mbn.COMPONENT_TYPE_INSTALLED;
0513:                tmp += "," + mbn.INSTANCE_NAME_KEY + "="
0514:                        + mbn.getJbiInstanceName();
0515:                //wildcard goes at the end:
0516:                tmp += ",*";
0517:
0518:                //exec the query and return the result:
0519:                return queryHelper(tmp);
0520:            }
0521:
0522:            /**
0523:             * Return URL that can be used to upload and deploy a remote  
0524:             * Service Assembly.
0525:             * @return URL String
0526:             */
0527:            public String getRemoteFileUploadURL() throws Exception {
0528:                String uploadURL = null;
0529:                String aHttpServerIpAddr = null;
0530:                String aHttpServerPort = null;
0531:                ObjectName HTTPListenerConfig = null;
0532:
0533:                try {
0534:                    aHttpServerIpAddr = InetAddress.getLocalHost()
0535:                            .getHostAddress();
0536:
0537:                    HTTPListenerConfig = new ObjectName(
0538:                            "amx:j2eeType=X-HTTPListenerConfig"
0539:                                    + ",X-ConfigConfig=server-config"
0540:                                    + ",name=http-listener-1"
0541:                                    + ",X-HTTPServiceConfig=na");
0542:
0543:                    aHttpServerPort = mContext.getMBeanServer().getAttribute(
0544:                            HTTPListenerConfig, "Port").toString();
0545:
0546:                    uploadURL = "http://" + aHttpServerIpAddr + ":"
0547:                            + aHttpServerPort + "/JBIFileUpload/UploadServlet";
0548:                } catch (Exception e) {
0549:                    String statusMsg = mTranslator.getString(
0550:                            LocalStringKeys.AS_GETREMOVEFILEUPLOADURL_EXCEP, e
0551:                                    .toString());
0552:                    mLogger.severe(statusMsg);
0553:
0554:                    ManagementMessageHolder mmHolder = new ManagementMessageHolder(
0555:                            "EXCEPTION_MSG");
0556:                    mmHolder.setTaskName("getRemoteFileUploadURL");
0557:                    mmHolder.setExceptionObject(e);
0558:                    mmHolder.setLocMessage(1, statusMsg);
0559:                    mmHolder.setLocToken(1, "UNABLE_TO_GET_UPLOAD_URL");
0560:                    String jbiTaskStr = mMMImpl
0561:                            .buildCompleteExceptionMessage(mmHolder);
0562:
0563:                    /*
0564:                    String jbiTaskStr = mMMImpl.buildCompleteExceptionMessage(
0565:                                            "getRemoteFileUploadURL", e.getStackTrace(),
0566:                                            "UNABLE_TO_GET_UPLOAD_URL", statusMsg);
0567:                     */
0568:
0569:                    throw new Exception(jbiTaskStr);
0570:                }
0571:
0572:                return uploadURL;
0573:            }
0574:
0575:            /**
0576:             * @return the full product name.
0577:             */
0578:            public String getFullProductName() {
0579:                return (mContext.getVersionInfo().fullProductName());
0580:            }
0581:
0582:            /**
0583:             * @return the short product name.
0584:             */
0585:            public String getShortProductName() {
0586:                return (mContext.getVersionInfo().shortProductName());
0587:            }
0588:
0589:            /**
0590:             * @return the major version number.
0591:             */
0592:            public String getMajorVersion() {
0593:                return (mContext.getVersionInfo().majorVersion());
0594:            }
0595:
0596:            /**
0597:             * @return the minor version number.
0598:             */
0599:            public String getMinorVersion() {
0600:                return (mContext.getVersionInfo().minorVersion());
0601:            }
0602:
0603:            /**
0604:             * @return the build number for this version.
0605:             */
0606:            public String getBuildNumber() {
0607:                return (mContext.getVersionInfo().buildNumber());
0608:            }
0609:
0610:            /**
0611:             * @return the Copyright for this version.
0612:             */
0613:            public String getCopyright() {
0614:                return (mContext.getVersionInfo().copyright());
0615:            }
0616:
0617:            /**
0618:             * Start all Management service agents
0619:             * @return true if successful.
0620:             */
0621:            public boolean startManagementServices() {
0622:                mLogger.fine("JBI runtime management services starting");
0623:                //for each management LC MBean (except adminService), invoke start on it:
0624:                try {
0625:                    mMBeanServer.invoke(mConfigServiceLifeCycleMBeanName,
0626:                            "start", new Object[0], new String[0]);
0627:                    mMBeanServer.invoke(mDeployServiceLifeCycleMBeanName,
0628:                            "start", new Object[0], new String[0]);
0629:                    mMBeanServer.invoke(mInstallServiceLifeCycleMBeanName,
0630:                            "start", new Object[0], new String[0]);
0631:                    mMBeanServer.invoke(mLoggingServiceLifeCycleMBeanName,
0632:                            "start", new Object[0], new String[0]);
0633:                    mMBeanServer.invoke(mMessageServiceLifeCycleMBeanName,
0634:                            "start", new Object[0], new String[0]);
0635:                } catch (Exception e) {
0636:                    mLogger.severe(e.toString());
0637:                    return false;
0638:                }
0639:
0640:                mLogger
0641:                        .fine("JBI runtime management services startup complete");
0642:                return true;
0643:            }
0644:
0645:            /**
0646:             * Stop all Management service agents and deregister Service Mbeans.
0647:             * @return true if successful.
0648:             */
0649:            public boolean stopManagementServices() {
0650:                //for each management LC MBean (except adminService), invoke stop on it:
0651:                try {
0652:                    mMBeanServer.invoke(mConfigServiceLifeCycleMBeanName,
0653:                            "stop", new Object[0], new String[0]);
0654:                    mMBeanServer.invoke(mDeployServiceLifeCycleMBeanName,
0655:                            "stop", new Object[0], new String[0]);
0656:                    mMBeanServer.invoke(mInstallServiceLifeCycleMBeanName,
0657:                            "stop", new Object[0], new String[0]);
0658:                    mMBeanServer.invoke(mLoggingServiceLifeCycleMBeanName,
0659:                            "stop", new Object[0], new String[0]);
0660:                    mMBeanServer.invoke(mMessageServiceLifeCycleMBeanName,
0661:                            "stop", new Object[0], new String[0]);
0662:                } catch (Exception e) {
0663:                    mLogger.severe(e.toString());
0664:                    return false;
0665:                }
0666:                return true;
0667:            }
0668:
0669:            /**
0670:             * Shutdown all Management service agents and deregister all MBeans..
0671:             * @return true if successful.
0672:             */
0673:            public boolean shutdownManagementServices() {
0674:                int nerrors = 0;
0675:
0676:                //for each management LC MBean (except adminService), invoke shutdown on it:
0677:                try {
0678:                    mMBeanServer.invoke(mConfigServiceLifeCycleMBeanName,
0679:                            "shutDown", new Object[0], new String[0]);
0680:                    mMBeanServer.invoke(mDeployServiceLifeCycleMBeanName,
0681:                            "shutDown", new Object[0], new String[0]);
0682:                    mMBeanServer.invoke(mInstallServiceLifeCycleMBeanName,
0683:                            "shutDown", new Object[0], new String[0]);
0684:                    mMBeanServer.invoke(mLoggingServiceLifeCycleMBeanName,
0685:                            "shutDown", new Object[0], new String[0]);
0686:                    mMBeanServer.invoke(mMessageServiceLifeCycleMBeanName,
0687:                            "shutDown", new Object[0], new String[0]);
0688:                } catch (Exception e) {
0689:                    mLogger.severe(e.toString());
0690:                    ++nerrors;
0691:                }
0692:
0693:                //shutdown myself last:
0694:                try {
0695:                    mMBeanServer.invoke(mAdminServiceLifeCycleMBeanName,
0696:                            "shutDown", new Object[0], new String[0]);
0697:                } catch (Exception e2) {
0698:                    mLogger.severe(e2.toString());
0699:                    ++nerrors;
0700:                }
0701:
0702:                return (nerrors == 0);
0703:            }
0704:
0705:            /////////
0706:            //methods private to AdminService
0707:            /////////    
0708:            /**
0709:             * map a management system service name to the unique bean providing
0710:             * the managment services.
0711:             * @param svcName is the name of the management service to map.
0712:             * @return management service CONTROL_TYPE corresponding svcName.
0713:             */
0714:            private String managementServiceControl(String svcName) {
0715:                MBeanNames mbn = mContext.getMBeanNames();
0716:
0717:                if (mbn.SERVICE_NAME_ADMIN_SERVICE.equals(svcName)) {
0718:                    return mbn.CONTROL_TYPE_ADMIN_SERVICE;
0719:                } else if (mbn.SERVICE_NAME_CONFIG_SERVICE.equals(svcName)) {
0720:                    return mbn.CONTROL_TYPE_CONFIG_SERVICE;
0721:                } else if (mbn.SERVICE_NAME_DEPLOY_SERVICE.equals(svcName)) {
0722:                    return mbn.CONTROL_TYPE_DEPLOY_SERVICE;
0723:                } else if (mbn.SERVICE_NAME_INSTALL_SERVICE.equals(svcName)) {
0724:                    return mbn.CONTROL_TYPE_INSTALL_SERVICE;
0725:                } else if (mbn.SERVICE_NAME_LOGGING_SERVICE.equals(svcName)) {
0726:                    return mbn.CONTROL_TYPE_LOGGING_SERVICE;
0727:                } else if (mbn.SERVICE_NAME_MESSAGE_SERVICE.equals(svcName)) {
0728:                    return mbn.CONTROL_TYPE_MESSAGE_SERVICE;
0729:                }
0730:
0731:                return null;
0732:            }
0733:
0734:            /**
0735:             * Execute a query and return array of mbean object names with result.
0736:             * This form of queryHelper always executes in the local mbean server.
0737:             *
0738:             * @param qStr is a JMX formatted query string
0739:             * @return array of JMX object names, possibly of zero length.
0740:             */
0741:            public ObjectName[] queryHelper(String qStr) {
0742:                return queryHelper(qStr, mContext.getMBeanServer());
0743:            }
0744:
0745:            /**
0746:             * Execute a query and return array of mbean object names with result.
0747:             * @param qStr is a JMX formatted query string
0748:             * @return array of JMX object names, possibly of zero length.
0749:             */
0750:            public ObjectName[] queryHelper(String qStr,
0751:                    MBeanServerConnection rmbs) {
0752:                ObjectName mbpat = null;
0753:                Set result = null;
0754:
0755:                try {
0756:                    mbpat = new ObjectName(qStr);
0757:                } catch (Exception e) {
0758:                    String statusMsg = mTranslator.getString(
0759:                            LocalStringKeys.AS_QUERYHELPER_EXCEP,
0760:                            "AdminService.queryHelper", qStr);
0761:                    mLogger.severe(statusMsg);
0762:                    e.printStackTrace();
0763:                    return (new ObjectName[0]);
0764:                }
0765:
0766:                //next, query the mbean server for this component:
0767:                //signature: queryNames(ObjectName name, QueryExp query): Set
0768:                try {
0769:                    result = rmbs.queryNames(mbpat, null);
0770:                } catch (Exception e) {
0771:                    String statusMsg = mTranslator.getString(
0772:                            LocalStringKeys.AS_QUERYHELPER_EXCEP,
0773:                            "AdminService.queryHelper", qStr);
0774:                    mLogger.severe(statusMsg);
0775:                    e.printStackTrace();
0776:                    return (new ObjectName[0]);
0777:                }
0778:
0779:                if (result.size() >= 1) {
0780:                    //copy results into array (result.toArray() not working!! RT 4/21/04):
0781:                    ObjectName[] names = new ObjectName[result.size()];
0782:                    Iterator itr;
0783:                    int ii;
0784:                    for (itr = result.iterator(), ii = 0; itr.hasNext(); ii++) {
0785:                        names[ii] = (ObjectName) itr.next();
0786:                    }
0787:
0788:                    return (names);
0789:                }
0790:
0791:                return (new ObjectName[0]);
0792:            }
0793:
0794:            /**
0795:             * Helper to get the list of installed engines or bindings.
0796:             * @param ctype is the control type
0797:             * @return array of JMX object names or an empty array if
0798:             * there are no matching object names.
0799:             */
0800:            private ObjectName[] getInstalledComponents(String ctype) {
0801:                MBeanNames mbn = mContext.getMBeanNames();
0802:                String tmp = mbn.getJmxDomainName();
0803:
0804:                tmp += ":" + mbn.COMPONENT_TYPE_KEY + "="
0805:                        + mbn.COMPONENT_TYPE_INSTALLED;
0806:                tmp += "," + mbn.CONTROL_TYPE_KEY + "="
0807:                        + mbn.CONTROL_TYPE_LIFECYCLE;
0808:                tmp += "," + mbn.INSTALLED_TYPE_KEY + "=" + ctype;
0809:                tmp += "," + mbn.INSTANCE_NAME_KEY + "="
0810:                        + mbn.getJbiInstanceName();
0811:                //wildcard goes at the end:
0812:                tmp += ",*";
0813:
0814:                //exec the query:
0815:                ObjectName[] names = queryHelper(tmp);
0816:
0817:                if (names.length >= 1) {
0818:                    return names;
0819:                } else {
0820:                    String statusMsg = mTranslator.getString(
0821:                            LocalStringKeys.AS_GETINSTALLEDCOMPONENTS_FAILURE,
0822:                            tmp);
0823:                    mLogger.warning(statusMsg);
0824:                }
0825:
0826:                return (new ObjectName[0]);
0827:            }
0828:
0829:            private void startAutoTasks() {
0830:                ObjectName timerName;
0831:                Boolean isCAS;
0832:
0833:                mLogger.fine(mTranslator
0834:                        .getString(LocalStringKeys.AS_HEARTBEAT_START));
0835:
0836:                timerName = mContext.getMBeanNames().getSystemServiceMBeanName(
0837:                        "AdminService", "HeartBeat");
0838:
0839:                // initialize the auto admin infrastructure
0840:                sAutoAdminTask = new AutoAdminTask(mContext);
0841:
0842:                if (null == timerName) {
0843:                    mLogger.severe(mTranslator
0844:                            .getString(LocalStringKeys.AS_HEARTBEAT_NULL));
0845:                    return;
0846:                }
0847:
0848:                //Create HeartBeat MBean:
0849:                try {
0850:                    mContext.getMBeanServer().createMBean(
0851:                            "javax.management.timer.Timer", timerName);
0852:                    mContext.getMBeanServer().invoke(timerName, "start",
0853:                            new Object[] {}, new String[] {});
0854:
0855:                    // Schedule a heart beat every mHeartBeatInterval milliseconds
0856:                    mNotificationId = (Integer) mContext.getMBeanServer()
0857:                            .invoke(
0858:                                    timerName,
0859:                                    "addNotification",
0860:                                    new Object[] { "AdminService.HeartBeat",
0861:                                            "heartBeat", null, nextBeat(),
0862:                                            new Long(mHeartBeatInterval) },
0863:                                    new String[] { "java.lang.String",
0864:                                            "java.lang.String",
0865:                                            "java.lang.Object",
0866:                                            "java.util.Date", "long" });
0867:
0868:                    // Listen for timer notifications
0869:                    mContext.getMBeanServer().addNotificationListener(
0870:                            timerName, this , null, new Object());
0871:                } catch (Exception e) {
0872:                    /* throws:
0873:                     *    InstanceAlreadyExistsException,
0874:                     *    MBeanRegistrationException,
0875:                     *    NotCompliantMBeanException
0876:                     */
0877:                    e.printStackTrace();
0878:                }
0879:            }
0880:
0881:            private void heartBeat() {
0882:                try {
0883:                    // guard against race condition of shutdown during any phase --
0884:                    // the sAutoAdminTask can become null while we're performing something.
0885:                    if (null != sAutoAdminTask) {
0886:                        sAutoAdminTask.performAutoFunctions();
0887:                    }
0888:                } catch (Exception e) {
0889:                    /* throws:
0890:                     *    Exception
0891:                     */
0892:                    e.printStackTrace();
0893:                }
0894:            }
0895:
0896:            private Date nextBeat() {
0897:                return new Date(System.currentTimeMillis() + mHeartBeatInterval);
0898:            }
0899:
0900:            private void stopAutoTasks() {
0901:                String statusMsg = mTranslator
0902:                        .getString(LocalStringKeys.AS_HEARTBEAT_STOP);
0903:                mLogger.fine(statusMsg);
0904:
0905:                sAutoAdminTask = null;
0906:
0907:                MBeanNames mbn = mContext.getMBeanNames();
0908:                ObjectName timerName = mbn.getSystemServiceMBeanName(
0909:                        "AdminService", "HeartBeat");
0910:
0911:                if (null == timerName) {
0912:                    statusMsg = mTranslator
0913:                            .getString(LocalStringKeys.AS_HEARTBEAT_NULL);
0914:                    mLogger.severe(statusMsg);
0915:                    return;
0916:                }
0917:
0918:                //Create HeartBeat MBean:
0919:                try {
0920:                    // Stop listening for timer notifications
0921:                    mContext.getMBeanServer().removeNotificationListener(
0922:                            timerName, this );
0923:
0924:                    // and unregister the MBean.
0925:                    mContext.getMBeanServer().unregisterMBean(timerName);
0926:                } catch (Exception e) {
0927:                    /* throws:
0928:                     *    InstanceAlreadyExistsException,
0929:                     *    MBeanRegistrationException,
0930:                     *    NotCompliantMBeanException
0931:                     */
0932:                    e.printStackTrace();
0933:                }
0934:            }
0935:
0936:            /**
0937:             * create Object names for all System Service LifeCycle MBeans.
0938:             */
0939:            private void initSystemServiceLifeCycleMBeanNames() {
0940:                mAdminServiceLifeCycleMBeanName = mMBeanNames
0941:                        .getSystemServiceMBeanName(
0942:                                mMBeanNames.SERVICE_NAME_ADMIN_SERVICE,
0943:                                mMBeanNames.CONTROL_TYPE_LIFECYCLE);
0944:                mConfigServiceLifeCycleMBeanName = mMBeanNames
0945:                        .getSystemServiceMBeanName(
0946:                                mMBeanNames.SERVICE_NAME_CONFIG_SERVICE,
0947:                                mMBeanNames.CONTROL_TYPE_LIFECYCLE);
0948:                mDeployServiceLifeCycleMBeanName = mMBeanNames
0949:                        .getSystemServiceMBeanName(
0950:                                mMBeanNames.SERVICE_NAME_DEPLOY_SERVICE,
0951:                                mMBeanNames.CONTROL_TYPE_LIFECYCLE);
0952:                mInstallServiceLifeCycleMBeanName = mMBeanNames
0953:                        .getSystemServiceMBeanName(
0954:                                mMBeanNames.SERVICE_NAME_INSTALL_SERVICE,
0955:                                mMBeanNames.CONTROL_TYPE_LIFECYCLE);
0956:                mLoggingServiceLifeCycleMBeanName = mMBeanNames
0957:                        .getSystemServiceMBeanName(
0958:                                mMBeanNames.SERVICE_NAME_LOGGING_SERVICE,
0959:                                mMBeanNames.CONTROL_TYPE_LIFECYCLE);
0960:                mMessageServiceLifeCycleMBeanName = mMBeanNames
0961:                        .getSystemServiceMBeanName(
0962:                                mMBeanNames.SERVICE_NAME_MESSAGE_SERVICE,
0963:                                mMBeanNames.CONTROL_TYPE_LIFECYCLE);
0964:            }
0965:
0966:            /**
0967:             * Get the value of a configuration attribute
0968:             *
0969:             * @param category - configuration category the attribute is defined in
0970:             * @param attrName - name of the attribute
0971:             * @return the value of the requested configuration attribute
0972:             */
0973:            private Object getConfigurationAttribute(
0974:                    ConfigurationCategory category, String attrName) {
0975:
0976:                MBeanNames.ServiceType svcType = MBeanNames.ServiceType
0977:                        .valueOf(category.toString());
0978:
0979:                ObjectName configMBeanName = mMBeanNames
0980:                        .getSystemServiceMBeanName(
0981:                                MBeanNames.SERVICE_NAME_CONFIG_SERVICE,
0982:                                com.sun.jbi.management.config.ConfigurationBuilder
0983:                                        .getControlType(svcType));
0984:
0985:                Object attrValue = null;
0986:                try {
0987:                    if (mMBeanServer.isRegistered(configMBeanName)) {
0988:                        attrValue = mMBeanServer.getAttribute(configMBeanName,
0989:                                attrName);
0990:                    }
0991:                } catch (javax.management.JMException jmex) {
0992:                    mLogger.warning(jmex.toString());
0993:                }
0994:
0995:                return attrValue;
0996:            }
0997:
0998:            /**
0999:             * Move to a new beat if different from the current one.
1000:             */
1001:            private void checkHeartBeat() {
1002:
1003:                ObjectName timerName = mContext.getMBeanNames()
1004:                        .getSystemServiceMBeanName("AdminService", "HeartBeat");
1005:
1006:                Object interval = getConfigurationAttribute(
1007:                        ConfigurationCategory.System,
1008:                        com.sun.jbi.management.config.SystemConfigurationFactory.HEART_BEAT_INTERVAL);
1009:                long currHeartBeat = mHeartBeatInterval;
1010:                try {
1011:                    if (interval != null) {
1012:                        currHeartBeat = ((Integer) interval).intValue();
1013:                    }
1014:
1015:                    if (currHeartBeat != mHeartBeatInterval) {
1016:                        if (mContext.getMBeanServer().isRegistered(timerName)) {
1017:                            mLogger
1018:                                    .fine("Switching to new heart beat interval of "
1019:                                            + currHeartBeat
1020:                                            + " ms old heart beat was "
1021:                                            + mHeartBeatInterval + " ms.");
1022:
1023:                            // -- Remove the old notification
1024:                            mContext.getMBeanServer().invoke(timerName,
1025:                                    "removeNotification",
1026:                                    new Object[] { mNotificationId },
1027:                                    new String[] { "java.lang.Integer" });
1028:
1029:                            // -- Add new notfication
1030:                            mHeartBeatInterval = currHeartBeat;
1031:
1032:                            mNotificationId = (Integer) mContext
1033:                                    .getMBeanServer()
1034:                                    .invoke(
1035:                                            timerName,
1036:                                            "addNotification",
1037:                                            new Object[] {
1038:                                                    "AdminService.HeartBeat",
1039:                                                    "heartBeat",
1040:                                                    null,
1041:                                                    new Date(
1042:                                                            System
1043:                                                                    .currentTimeMillis()),
1044:                                                    new Long(mHeartBeatInterval) },
1045:                                            new String[] { "java.lang.String",
1046:                                                    "java.lang.String",
1047:                                                    "java.lang.Object",
1048:                                                    "java.util.Date", "long" });
1049:                        }
1050:                    }
1051:                } catch (Exception ex) {
1052:                    mLogger.warning(ex.toString());
1053:                }
1054:            }
1055:
1056:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.