Friday Sep 11, 2009
For new modules like JRuby which can be added at runtime, it is possible to use v3 monitoring config using pluggability as given in the sample code below.
import org.glassfish.internal.api.Init;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.component.PostConstruct;
import org.jvnet.hk2.annotations.Inject;
import org.glassfish.api.Startup;
import com.sun.enterprise.config.serverbeans.MonitoringService;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.ConfigSupport;
import org.glassfish.api.monitoring.ContainerMonitoring;
import org.jvnet.hk2.config.TransactionFailure;
import java.beans.PropertyVetoException;
@Service
public class AddonInit implements PostConstruct {
@Inject
MonitoringService ms;
public void postConstruct() {
mprint("addon init postConstruct() ...");
if (ms.getContainerMonitoring("jruby") == null) {
try {
ConfigSupport.apply(new SingleConfigCode<MonitoringService>() {
public Object run(MonitoringService param)
throws PropertyVetoException, TransactionFailure {
ContainerMonitoring newItem = param.createChild(ContainerMonitoring.class);
newItem.setName("jruby");
newItem.setLevel("HIGH");
param.getContainerMonitoring().add(newItem);
return newItem;
}
}, ms);
} catch (TransactionFailure tf) {
// log warning
// handle exception
}
}
}
private void mprint(String str) {
if (debug) {
System.out.println("... MSR: " + str);
}
}
private final boolean debug = true;
}
Wednesday Sep 09, 2009
The monitoring funcationality including attaching btrace-agent is done based on the 'monitoring-enabled' attribute of 'monitoring-service' element. If monitoring-enabled is true then the btrace-agent is attached as part of startup. When monitoring-enabled is false, btrace-agent is not attached at startup time. However when user changes monitoring-enabled to true while the server is running, it should be possible to attach the btrace-agent and start monitoring functionality.
Purpose of this pair of commands is to provide enable /disable monitoring during run time without having to restart the server (Alternatively user should be able to use asadmin set command to enbale/disable the monitoring-enabled flag, but have to restart the server to take effect). It does attach btrace-agent based on the given pid and optionally sets the monitoring level for given modules.
enable-monitoring
enable-monitoring [--mbean=false] [--dtrace*=true] [--level web-container="LOW":ejb-container="HIGH"] [--options="debug=true"] [--pid=<pid>]
enable-monitoring
sets the attribute 'monitoring-enabled' to 'true'
enable-monitoring --mbean=true --dtrace*=false
sets the attribute 'monitoring-enabled' to 'true', mbean-enabled to true and dtrace-enabled to false
enable-monitoring --options="debug=true" --pid=<pid>
sets the attribute 'monitoring-enabled' to 'true' and attaches btrace agent using --options
enable-monitoring --level web-container="LOW":ejb="HIGH"
sets the levels for given modules in addition to 'monitoring-enabled'
disable-monitoring
disable-monitoring --modules="web-container,ejb-container"
disable-monitoring
sets the attribute 'monitoring-enabled' to 'false'
disable-monitoring --modules="web-container,ejb-container"
this command will just set the levels for given modules to 'OFF' and it does not change the value for 'monitoring-enabled'
*- Available as a value-add feature, made available only to the paid customers.
Above also caters an important use case of adhoc monitoring, i.e. turning monitoring on in production while server is running, for ex. enable dtrace on the fly.
Thursday Feb 19, 2009
comet_client
There are many examples illustrating the usage of
Grizzly Comet for Web
Client but not for Stand alone java client. I needed one and with help
from Jeanfrancois Arcand, users@grizzly.dev.java.net and my colleague Prashant
Abbagani, I came up with the following example.
Conventionally the client either polls or pulls the message from server
periodically, the draw back with this approach is that the client
wastes the resources and the messages may not be received in real time.
Instead, in comet approach, the server pushes the messages to client in
real time. For this example, I have used GlassFish v3 which comes
bundled with Grizzly and Comet. Here are the steps:
-
Download and install GlassFish v3.
-
Enable comet support in GlassFish v3.
...
<http-listener port="8080" id="http-listener-1" address="0.0.0.0" default-virtual-server="server" server-name="">
<property name="cometSupport" value="true" />
<http-listener>
...
-
Develop and deploy comet.war to push messages from server to client. You may like to refer to MyCometServlet.java source code.
 
-
Code the client CometClient.java and listen for server messages.
Start the client.
punit[105]: java CometClient
init ...
-
Simulate posting messages to server using Post2CometServlet.java.
Post message to server
punit[54]: java Post2CometServlet
punit[55]: java Post2CometServlet
punit[56]: java Post2CometServlet
punit[57]: java Post2CometServlet
punit[58]: java Post2CometServlet
The client output gets updated in real time as the messages are posted to the servlet.
punit[105]: java CometClient
init ...my message sent at 1235082867986
my message sent at 1235082891002
my message sent at 1235082892018
my message sent at 1235082893714
my message sent at 1235082894420
The above code needs to parameterize SingleConfigC...
Thanks for pointing it out. The code was already p...