Tuesday Nov 06, 2007

Management Rules - observedmbean property

My previous blog on selfmanagement and https://glassfish.dev.java.net/javaee5/selfmanagement/selfmanagement_example.html explain how to create management rules with an example.

Assumptions : 

Same example as in the above link (memory rule) taken. 

Custom Mbeans  Memory (impl-class-name:com.sun.example.mbeans.Memory) and MemoryActionBean (impl-class-name:com.sun.example.action.MemoryAction) are deployed.

Problem : 

In GUI, when a new management rule is created following the steps and with the values :

Observed Mbean : com.sun.examples.mbeans.Memory

Observed Attribute : FreeMemory 

and other values as specified in the example,

the server.log shows an error message that the rule is not configured because of some errors. The log looks like

Error creating and configuring the rule : MemRule due to
IlegalArguments specified for its event type : monitor. Create the
rule with correct arugments for the configured event.|#]

Solution :

Modify the domain.xml under install_directory/domains/domain1/config/ directory - edit the management rule MemRule :

Change the line

property name="observedobject" value="com.sun.example.mbeans.Memory"


property name="observedmbean" value="Memory"

Restart the server after this change. And you will see that the error message goes away. Note here that "observedobject" is changed to "observedmbean" and the new value is the name of the custom mbean deployed with the impl-class-name : com.sun.example.mbeans.Memory.

Explanation :

In GUI, the Observed Mbean takes values like

This value is translated into "observedobject" property in domain.xml. Hence if you specify "com.sun.example.mbeans.Memory", in domain.xml you will see this value against the property "observedobject". 

Very few know that there is another property called "observedmbean" that accepts the mbean name directly. But in GUI, there is no explicit way of specifying this observedmbean property. One has to enter the whole object name for the input "Observed Mbean" in GUI, which will get translated into "observedobject" in domain.xml. Alternatively, domain.xml can be modified with observedmbean property.

Whereas in CLI, you could just specify the parameter "observedmbean"
with value "Memory" in the command line, without even specifying the "observedobject" property.

Ex: asadmin create-management-rule --port 4848 --user admin_user
--action  MemoryActionBean --eventtype monitor --eventloglevel WARNING --eventproperties
<blah-blah>:observedmbean=Memory:<blah-blah> rule_name

This is an advantage CLI has over GUI.  


Tuesday Oct 30, 2007

Troubleshooting - Cluster startup Failure

Recently i had this problem.. I setup a cluster with an instance. But was not able to start it up. 

I got a series of  java.net.ConnectException: Connection refused exceptions and the instance did not startup.

What did the wonder?

 The /etc/hosts file had the following entries: mymachine mymachine localhost

 When i commented out this line in the hosts file and add a physical IP entry like

129.xxx.xxx.xx mymachine

 and startup the instance, it goes through fine :)


MQ needs the hostname to map to the absolute IP and not

Friday Oct 26, 2007

Lookup from Standalone Client

My previous blog was about accessing a JDBC resource from an ejb. 

This blog talks about accessing the JDBC resource i created in the last blog, from a standalone client.

I use the same configuration from my previous blog : jdbc/cactus for my resource that needs to be accessed.

My sample will have the following code:

InitialContext ctx = new InitialContext();

javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/cactus";)

Connection c = ds.getConnection();



Compile the sample

 Run the sample

 Note the included jars in the classpath

  • appserv-rt.jar
  • javaee.jar
  • appserv-admin.jar
  • imqjmsra.jar
  • derbyclient.jar

Also, observe the system properties for the server host and naming service port.

JDBC resource lookup from EJB

Accessing a JDBC resource from an EJB is a fairly simple thing to do. As simple as the following:

1. Start domain and database

After installing GlassFishV2, start the domain domain1 and start the database. I would be using Derby in this example. Derby can be started in 2 ways    

  • <INSTALL_ROOT>/bin/asadmin start-database
  • From netbeans : Tools -> Java DB Database -> Start JavaDB Server. The port settings for the server started up can be modified in ~/.netbeans-derby/derby.properties

 Now, the database is started at port :1527 and domain is running at 4848.

2. Create a JDBC Connection pool and JDBC Resource

 Login to the Admin Console (http://localhost:4848) and navigate to Resources->JDBC->ConnectionPools. Click on New and enter the details like Name:Cacti  ResourceType:javax.sql.DataSource DatabaseVendor:Derby. In the next screen, accept the default values but don't forget to enter the following additional properties

  • DatabaseName : sampleDB
  • ConnectionAttributes : create=true (if the sampleDB does not exist)
  • Password : dbpassword
  • PortNumber : 1527 (or the customized DB port)
  • ServerName : localhost
  • User : dbuser

Click on Finish. To verify, click on the 'Cacti' connection pool you just created and do a 'Ping connection Pool".

 Navigate to Resources->JDBC->JDBCResource on the left panel of the admin console and click on New. Specify a JNDI name as "jdbc/cactus". I chose to append the name cactus with jdbc since i am accessing a database. Choose the pool name you just created "Cacti" and click on 'OK'.

3. Access the resource in your app

Suppose i have an EJB that has to use this JDBC resource. This can be done as follows in the SampleEjb.java : test() method

InitialContext ic = new InitialContext();
DataSource ds = (javax.sql.DataSource) ic.lookup("jdbc/cactus";)

Connection con = ds.getConnection();

insert("something", ...., con);


Create the appropriate Remote and Home interfaces.  

4. Specifying the appropriate deployment descriptors:

Consider this is a web application.


    <display-name>Sample EJB Test</display-name>


    <description>Sample test</description>
    <display-name>Sample test </display-name>
          <description> Sample bean </description>
          <display-name> Sample bean </display-name>




        <display-name>Sample Test Servlet</display-name>

5. After all this coding, the structure would look like


Build this application, create an ear and deploy this application on the application server via the admin console.

6. The Application can be accessed via http://localhost:8080/sample-test

Wednesday Sep 05, 2007

2 Machine Cluster Setup - CLI mode

Build : GlassFish V2 b58c on Solaris

Namesake names of machines : Tiger.cat.com, Cactus.plant.com

Using the Command Line Interface of GlassFish, a cluster can be setup with ease across 2 machines. Heres how it can be done:

1. Download GF v2 b58c from https://glassfish.dev.java.net/downloads/v2-b58c.html

2. Unbundle GlassFish following the instructions and do a ant -f setup-cluster.xml to enable clustering support on the installation.

Do Step2 on both Tiger.cat.com and Cactus.plant.com

3. On Tiger.cat.com, do the following:

  • Under {GF_install}/bin, do "asadmin start-domain" which will start up the default domain "domain1".
  • Create a node-agent as using the command "asadmin create-node-agent --host localhost --port 4848 man-agent"
  • Create a cluster with the command "asadmin create-cluster --host localhost --port 4848 cat-cluster"
  • Create an instance with the command "asadmin create-instance --host localhost --port 4848 --nodeagent man-agent --cluster cat-cluster instance1"

Note that in all the above steps, 4848 is the admin port of the domain domain1.

  • Start the node-agent : "asadmin start-node-agent --syncinstances=true man-agent"

The "syncinstances" flag starts up the cluster and instance as well. Its default value is false.

4. On Cactus.plant.com, do the following:

  • Under {GF_install}/bin, execute "asadmin create-node-agent --host Tiger.cat.com --port 4848 animal-agent" to create a node-agent on this machine pointing to the DAS (Tiger.cat.com).

After this step, observe in the /nodeagents directory that animal-agent is created.

  • Create an instance on this machine as "asadmin create-instance --host Tiger.cat.com --port 4848 --nodeagent animal-agent --cluster cat-cluster instance2"

  • Start node-agent, while the other node-agent is running: "asadmin start-node-agent --syncinstances=true animal-agent"

 2 machine cluster is successfully setup !!!




« July 2016