JMX(Java Management Extensions)는 프로그래머들에게 자바 어플리케이션의 모니터링과 관리 기능을 제공한다. Java 어플리케이션을 로컬 혹은 원격에서 관리할 수 있도록한다.
JMX 의 구현체인 MX4J의 Sample코드를 따라 해보자..
RMI MBean Example
Server (리모트 서비스를 구동하는 클래스)
JMX 의 구현체인 MX4J의 Sample코드를 따라 해보자..
RMI MBean Example
RMI 리모트 객체를 MBeans 로서 노출시키는 방법을 설명하고 있다.
JMX를 통하여 이 리모트 객체의 구현체인 서비스를 기동/종료/재기동이 가능하고 기동여부를 확인하고 설정을 변경이 가능하게 될 것이다.
Sample Classes
sample Class는 아래의 5개 클래스로 구성되어 있다.
Client (클라이언트 클래스)
MyRemoteService (리모트 인터페이스)
MyRemoteServiceObjectMBean ( management interface)
MyRemoteServiceObject (리모트 인터페이스를 구현한 the MBean )
설명
MyRemoteServiceObject는 MBean이자 Remote 객체이다.
Client는 이 두 인터페이스를 통해서 접근하게 된다.
리모트 인터페이스인 MyRemoteService는 단 하나의 메소드만 가진다.
public void sayHello( String name );
이것은 Client의 요청을 실행하게 될 것이다.
Management Interface인 MyRemoteSeviceObjectMBean은 3개의 메소드를 가진다.
public void start()
public void stop()
public boolean isRunning()
구현체들
Server Class
public class Server
{
public static void main(String[] args) throws Exception
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
ObjectName name = new ObjectName("examples:type=remote");
MyRemoteServiceObject remote = new MyRemoteServiceObject();
server.registerMBean(remote, name);
MyRemoteServiceObjectMBean managed = (MyRemoteServiceObjectMBean)MBeanServerInvocationHandler.newProxyInstance(server, name, MyRemoteServiceObjectMBean.class, false);
managed.start();
}
}
MyRemoteServiceObject Class
public class MyRemoteServiceObject extends RemoteServer implements MyRemoteService, MyRemoteServiceObjectMBean
{
private boolean m_running;
public MyRemoteServiceObject() throws RemoteException {}
public void sayHello(String name) throws RemoteException
{
System.out.println("Hello, " + name);
}
public void start() throws Exception
{
if (!m_running)
{
UnicastRemoteObject.exportObject(this);
InitialContext ctx = new InitialContext();
ctx.rebind(JNDI_NAME, this);
m_running = true;
System.out.println("My remote service started successfully");
}
}
public void stop() throws Exception
{
if (m_running)
{
InitialContext ctx = new InitialContext();
ctx.unbind(JNDI_NAME);
UnicastRemoteObject.unexportObject(this, false);
m_running = false;
System.out.println("My remote service stopped successfully");
}
}
public boolean isRunning()
{
return m_running;
}
}
실행


댓글