1 8 9 package mx4j.examples.mbeans.rmi; 10 11 import java.rmi.RemoteException ; 12 import java.rmi.server.RemoteServer ; 13 import java.rmi.server.UnicastRemoteObject ; 14 import javax.naming.InitialContext ; 15 16 26 public class MyRemoteServiceObject extends RemoteServer implements MyRemoteService, MyRemoteServiceObjectMBean 27 { 28 private boolean m_running; 29 30 public MyRemoteServiceObject() throws RemoteException 31 { 32 } 33 34 public void sayHello(String name) throws RemoteException 35 { 36 System.out.println("Hello, " + name); 37 } 38 39 public void start() throws Exception 40 { 41 if (!m_running) 42 { 43 UnicastRemoteObject.exportObject(this); 44 InitialContext ctx = new InitialContext (); 45 ctx.rebind(JNDI_NAME, this); 46 m_running = true; 47 System.out.println("My remote service started successfully"); 48 } 49 } 50 51 public void stop() throws Exception 52 { 53 if (m_running) 54 { 55 InitialContext ctx = new InitialContext (); 56 ctx.unbind(JNDI_NAME); 57 UnicastRemoteObject.unexportObject(this, false); 58 m_running = false; 59 System.out.println("My remote service stopped successfully"); 60 } 61 } 62 63 public boolean isRunning() 64 { 65 return m_running; 66 } 67 } 68 | Popular Tags |