dev@glassfish.java.net

Re: AMX sample code

From: Lloyd Chambers <Lloyd.Chambers_at_Sun.COM>
Date: Fri, 12 Sep 2008 15:57:27 -0700

First you need to get a DomainRoot.

Out of process, this means connecting to the server. Currently RMI is
not working due to a JNDI bug. So JMXMP is being used.
AppserverConnectionSource is the way to connect once it works. For now:

CONNECTING

If you are in-process, just use the
ManagementFactory.getPlatformMBeanServer()

import com.sun.appserv.management.client.AMXBooter;
import com.sun.appserv.management.client.ProxyFactory;
import com.sun.appserv.management.DomainRoot;

MBeanServerConnection getMBeanServerConnection(String host, int port)
     throws MalformedURLException, IOException {
     final String urlStr = "service:jmx:jmxmp://" + host + ":" + port;
     final JMXServiceURL url = new JMXServiceURL(urlStr);
     final JMXConnector jmxConn = JMXConnectorFactory.connect(url);
     final MBeanServerConnection conn =
jmxConn.getMBeanServerConnection();
     return conn;
}
...

AMXBooter.bootAMX( getMBeanServerConnection("localhost",8888) );
final DomainRoot domainRoot =
ProxyFactory.getInstance(conn).getDomainRoot();

You now have a 'DomainRoot' dynamic proxy to the server.

-------------------

EXAMPLES

DomainConfig dc = domainRoot.getDomainConfig();

...

HTTPListenerConfig listener =
dc.getHTTPServiceConfig().getHTTPListenerConfigMap().get("listener-1");
// caution when changing ports: could be ${...}
final String rawValue = listener.getPort(); // could be ${...}, this
is useful for display mainly
final int port = listener.resolveInteger("Port"); // will be a number
listener.setPort( "7777" );

...

dc.getResourcesConfig().createJDBCResourceConfig( jndiName, poolName,
null );

JavaConfig jc = dc.getConfigsConfig().get("server-
config").getJavaConfig();
List<String> jvmOptions = jc.getJvmOptions();
jvmOptions.add( "-Dfoo=bar" );
jc.setJvmOptions(jvmOptions);




Lloyd




On Sep 12, 2008, at 3:03 PM, Vivek Pandey wrote:

I can think of couple more:

- create a JDBC resource
- Configure HTTP/Grizzly

-vivek.
Ludovic Champenois wrote:
> Lloyd Chambers wrote:
>> Ludo,
>>
>> Give me a short list and I'll provide some code snippets in the
>> next few days.
>>
>> Lloyd
>
> Cool.
> Maybe Vivek or the community can add to this list:
>
> 1/ retrieve the current value of http port
> 2/ change it to 7777
> 3/ retrieve list of jdbcresources with their properties
> 3/ get the list of connection pools and change the password in the
> first one.
> 4/ create a connection pool
> 5/ add a jvm option
>
> I guess 1,2,3,5 would be a good start for AMX beginners.
> Ludo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: dev-help_at_glassfish.dev.java.net