Hi,
An application represents a J2EE Enterprise application packaged in an EAR file or EAR exploded directory. The EAR file or directory contains a set of components such as WAR, EJB, and RAR connector components, each of which can be deployed on one or more targets. A target is a server or a cluster.
ApplicationRuntimeMBean encapsulates runtime information about a deployed Enterprise application.
Here is a Sample JMX code to display the State of all the Applications deployed on All the Servers…
import javax.management.AttributeNotFoundException; import javax.management.InstanceNotFoundException; import javax.management.IntrospectionException; import javax.management.MBeanException; import javax.management.ReflectionException; import java.io.IOException; import java.net.MalformedURLException; import java.util.Hashtable; import javax.management.MBeanServerConnection; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; import weblogic.management.runtime.*; import weblogic.management.runtime.*; public class ApplicationDetails { private static MBeanServerConnection connection; private static JMXConnector connector; private static final ObjectName service; static { try { service = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean"); } catch (MalformedObjectNameException e) { throw new AssertionError(e.getMessage()); } } public static void initConnection(String hostname, String portString,String username, String password) throws IOException,MalformedURLException { String protocol = "t3"; Integer portInteger = Integer.valueOf(portString); int port = portInteger.intValue(); String jndiroot = "/jndi/"; String mserver = "weblogic.management.mbeanservers.domainruntime"; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname,port, jndiroot + mserver); Hashtable h = new Hashtable(); h.put(Context.SECURITY_PRINCIPAL, username); h.put(Context.SECURITY_CREDENTIALS, password); h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES,"weblogic.management.remote"); connector = JMXConnectorFactory.connect(serviceURL, h); connection = connector.getMBeanServerConnection(); } public static ObjectName[] getServerRuntimes() throws Exception { return (ObjectName[]) connection.getAttribute(service,"ServerRuntimes"); } public Object getObjectName(ObjectName objectName, String attributeName) throws AttributeNotFoundException,InstanceNotFoundException, MBeanException, ReflectionException, IOException { return connection.getAttribute(objectName, attributeName); } public void printClusterInfo() throws Exception { ObjectName[] serverRT = getServerRuntimes(); Hashtable server_states = new Hashtable(); for(ObjectName ser: serverRT) { System.out.println("--------------------------------------------------------------"); String serverName=(String) connection.getAttribute(ser,"Name"); System.out.print("tSERVER NAME: "+serverName); System.out.println("t SERVER STATE: "+(String) connection.getAttribute(ser,"State")); ObjectName[] appRT =(ObjectName[])connection.getAttribute(ser,"ApplicationRuntimes"); //ApplicationRuntimeMBean appRun=(ApplicationRuntimeMBean) connection.getAttribute(ser,"ApplicationRuntimes"); System.out.println("ntTotal Applications Targeted On # "+serverName+" # : "+appRT.length); for(ObjectName app: appRT) { String appName = (String) connection.getAttribute(app,"Name"); //weblogic.health.HealthState healthState = (weblogic.health.HealthState) connection.getAttribute(app,"HealthState"); //System.out.println("t Health ="+healthState.getState()); ObjectName[] componentRT =(ObjectName[])connection.getAttribute(app,"ComponentRuntimes"); for(ObjectName compRT:componentRT) { Integer stateInt=(Integer)connection.getAttribute(compRT,"DeploymentState"); String name=(String)connection.getAttribute(compRT,"Name"); String stateString=""+stateInt; if (stateInt == ComponentRuntimeMBean.ACTIVATED) stateString="ACTIVATED "; if (stateInt == ComponentRuntimeMBean.NEW) stateString="NEW"; if (stateInt == ComponentRuntimeMBean.PREPARED) stateString="PREPARED "; if (stateInt == ComponentRuntimeMBean.UNPREPARED) stateString="UNPREPARED "; System.out.println("ntSTATE: "+stateString+" AppName: "+name); } } } } public static void main(String[] args) throws Exception { String hostname = "localhost"; String portString = "7001"; String username = "weblogic"; String password = "weblogic"; ApplicationDetails s = new ApplicationDetails(); initConnection(hostname, portString, username, password); s.printClusterInfo(); connector.close(); } }
Above Program gives the Following Output:
F:DELETEBLOG_REPLIESApplicationChecker_JMX>java ApplicationDetails
————————————————————–
SERVER NAME: AdminServer SERVER STATE: RUNNING
Total Applications Targeted On # AdminServer # : 7
STATE: PREPARED AppName: helloWorldEar
STATE: ACTIVATED AppName: bea_wls_management_internal2
STATE: ACTIVATED AppName: consoleapp
STATE: ACTIVATED AppName: consoleapp
STATE: ACTIVATED AppName: bea_wls_internal
STATE: ACTIVATED AppName: bea_wls_deployment_internal
STATE: ACTIVATED AppName: mejb
STATE: ACTIVATED AppName: bea_wls9_async_response
————————————————————–
SERVER NAME: MS1 SERVER STATE: RUNNING
Total Applications Targeted On # MS1 # : 5
STATE: ACTIVATED AppName: bea_wls_internal
STATE: ACTIVATED AppName: bea_wls9_async_response
STATE: ACTIVATED AppName: bea_wls_deployment_internal
STATE: ACTIVATED AppName: bea_wls_cluster_internal
—————–
Thanks
Jay SenSharma
January 25th, 2010 on 8:17 am
Jay,
thanks again…..but still not showing PREPARED state overhere.
It also shows the Datasources and the internal applications (for example uddiexplorer or bea_wls_internal) in the list of applications. Can this be filtered out ?
cheers
Raymond
January 25th, 2010 on 8:26 am
Hi Raymond,
uddiexplorer and bea_wls_internal are the WebLogic Servers Internal Applications … Here we need to write our logic to Filter these Out:
Example: if (appName.equals(“uddiexplorer”) || appName.equals(“bea_wls_internal”) )
// Then Dont Display then… System.out.println(“”);
else
System.out.println(“Display: “+appName);
——————-
Actaually i am also surprised that the same code shows the Application States as “PREPARED” if the Application is Deployed on AdmiNServer…But if an application is deployed on Managed Server then …it is not weven listed in the Output of the program…
I don’t have answer for this…till now
Thanks
Jay Sensharma
June 30th, 2010 on 10:33 pm
Hi Jay,
Quick question. For post WL 9 I acn get for activation task (ActivationTaskMBean) I can get attribute State which has type of int. What possible values it can have? And what do they mean? Is there a javadoc describing it somewhere? BTW, I am getting 4. And if I do
eConnection.getAttribute(task ,”StatusByServer”) I see:
ServerState=4
Is ServerState has the same listof possible values?
Thanks!
July 5th, 2010 on 12:17 pm
Hi Lach_v,
The interface “weblogic.management.mbeanservers.edit.ActivationTaskMBean” has the following Constants defined in it:
int STATE_NEW = 0;
int STATE_DISTRIBUTING = 1;
int STATE_DISTRIBUTED = 2;
int STATE_PENDING = 3;
int STATE_COMMITTED = 4;
int STATE_FAILED = 5;
int STATE_CANCELING = 6;
int STATE_COMMIT_FAILING = 7;
So if you are getting ServerState=4 It means the State is “STATE_COMMITTED”.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 13th, 2010 on 12:24 am
Hi Jay,
Running this Program pointing to Weblogic 10.3 is showing following error;
Exception in thread “main” java.net.MalformedURLException: Unsupported protocol: t3 at javax.management.remote.JMXConnectorFactory
What could be the reason?
Is there any change that i need to make for 10.3?
November 13th, 2010 on 12:28 am
When i went through google I see some links pointing Weblogic Wonders for same above mentioned error.
(1)http://weblogic-wonders.com/weblogic/author/administrator/page/43/
(2)http://weblogic-wonders.com/weblogic/2009/12/05/cluster-details-jmx/
(3)http://weblogic-wonders.com/weblogic/2010/01/
Please provide alternative link.
November 13th, 2010 on 1:37 am
Hi Sathya,
Please follow the Prework Instruction given in the JMX Page (http://middlewaremagic.com/weblogic/?page_id=114) from Step1 to Step5
T3 is a Bea propitiatory protocol It means your Classpath must have the WebLogic Required Jar files where u are trying to run the JMX Programs. So make sure that u run “setWLSEnv.bat” (For WINDOWS) or “setWLSENV.sh” (for Unix Based Operating System).
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
May 28th, 2012 on 2:45 pm
Hello Jay,
i would like to setup a Sitescope monitoring using JMX.
Sitescope needs to check the appilication state whether it is “Active” or “Prepared” and based on this it needs to trigger the alert, unfortunately i was unable to see the matching Mbean details in the JMX counter, Could you please let me know which Mbean can be used to exactly pull the application State, so that i can make use of it from Sitescope. i have already setup the monitoring using JMX to pull the Datasource connection details. Appreciate your help!! Thanks in advance.
Thanks
Praveen