01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: 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: /**
17: * The service implementation. <br />
18: * It exposes two interfaces: the RMI Remote interface, invocable from remote clients -
19: * represented by the {@link MyRemoteService} interface, and
20: * the management interface - represented by the {@link MyRemoteServiceObjectMBean} interface,
21: * invocable from management applications that wants to manage the features of this
22: * service.
23: *
24: * @version $Revision: 1.1 $
25: */
26: public class MyRemoteServiceObject extends RemoteServer implements
27: MyRemoteService, MyRemoteServiceObjectMBean {
28: private boolean m_running;
29:
30: public MyRemoteServiceObject() throws RemoteException {
31: }
32:
33: public void sayHello(String name) throws RemoteException {
34: System.out.println("Hello, " + name);
35: }
36:
37: public void start() throws Exception {
38: if (!m_running) {
39: UnicastRemoteObject.exportObject(this );
40: InitialContext ctx = new InitialContext();
41: ctx.rebind(JNDI_NAME, this );
42: m_running = true;
43: System.out
44: .println("My remote service started successfully");
45: }
46: }
47:
48: public void stop() throws Exception {
49: if (m_running) {
50: InitialContext ctx = new InitialContext();
51: ctx.unbind(JNDI_NAME);
52: UnicastRemoteObject.unexportObject(this , false);
53: m_running = false;
54: System.out
55: .println("My remote service stopped successfully");
56: }
57: }
58:
59: public boolean isRunning() {
60: return m_running;
61: }
62: }
|