KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > EJBTimerManagementMBean


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.mbeans;
25
26 import com.sun.logging.LogDomains;
27 import com.sun.enterprise.config.ConfigContext;
28 import com.sun.enterprise.config.ConfigException;
29 import com.sun.enterprise.admin.config.BaseConfigMBean;
30 import com.sun.enterprise.util.i18n.StringManager;
31
32 import com.sun.enterprise.admin.servermgmt.InstanceException;
33 import com.sun.enterprise.admin.event.AdminEventResult;
34 import com.sun.enterprise.admin.event.AdminEvent;
35 import com.sun.enterprise.admin.event.AdminEventMulticaster;
36 import com.sun.enterprise.admin.event.EjbTimerEvent;
37
38 import com.sun.enterprise.server.ApplicationServer;
39 import com.sun.enterprise.server.ServerContext;
40
41 import java.util.logging.Logger JavaDoc;
42 import java.util.logging.Level JavaDoc;
43
44 /**
45  * object name for this mbean: <domainName>:type=ejb-timer-management,category=config
46  * EJBTimerManagementMBean exposes list timers
47  *
48  * @author sridatta
49  *
50  */

51 public class EJBTimerManagementMBean
52         extends BaseConfigMBean
53         implements com.sun.enterprise.admin.mbeanapi.IEJBTimerManagementMBean
54 {
55    
56     public EJBTimerManagementMBean()
57     {
58         super();
59     }
60     
61     private Logger JavaDoc getLogger()
62     {
63         if (_logger == null) {
64             _logger = Logger.getLogger(LogDomains.ADMIN_LOGGER);
65         }
66         return _logger;
67     }
68
69     /**
70      * Lists ALL the ejb timers
71      *
72      * @param target is ignored. It is always assumed to be the
73      * PE instance. can also be null.
74      *
75      * exception InstanceException
76      *
77      * @return returns the list of timers as a string array
78      */

79     public String JavaDoc[] listTimers(String JavaDoc target)
80             throws ConfigException, InstanceException {
81        
82     fine("Entering list Timers");
83     String JavaDoc server = getServerName();
84         
85     fine("List Timers: Sending Notification to server" + server);
86      
87         String JavaDoc[] resStr = sendListTimerEvent(server, new String JavaDoc[] {server});
88     fine("RESULT: " + resStr);
89     if(resStr == null || resStr.length == 0) {
90        resStr = new String JavaDoc[] {"There are no Ejb Timers."};
91     }
92     resStr[0] = server + ": " + resStr[0];
93     return resStr;
94     }
95    
96      protected String JavaDoc[] sendListTimerEvent(String JavaDoc server, String JavaDoc[] allServers) {
97          AdminEvent event = new EjbTimerEvent(server,
98                         EjbTimerEvent.ACTION_LISTTIMERS,
99                         server,
100                         allServers);
101          
102      event.setTargetDestination(server);
103          AdminEventResult res = forwardEvent(event);
104
105     return (String JavaDoc[]) res.getAttribute(server,
106             EjbTimerEvent.EJB_TIMER_CALL_RESULT_ATTRNAME);
107      }
108        
109      protected AdminEventResult forwardEvent(AdminEvent e) {
110
111         AdminEventResult result = null;
112         result = AdminEventMulticaster.multicastEvent(e);
113         return result;
114     }
115      
116      private void fine(String JavaDoc s) {
117          getLogger().log(Level.INFO, s); //FIXME. change to fine
118
}
119
120     
121     private String JavaDoc getServerName() {
122     return ApplicationServer.getServerContext().getInstanceName();
123     }
124     ///////////////////////////////////////////////////////////////////////////
125

126     private static final StringManager _strMgr =
127                 StringManager.getManager(EJBTimerManagementMBean.class);
128     private static Logger JavaDoc _logger;
129     ///////////////////////////////////////////////////////////////////////////
130
}
131
Popular Tags