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: package mx4j.examples.mbeans.iiop;
09:
10: import java.rmi.RemoteException;
11: import javax.naming.Context;
12: import javax.naming.InitialContext;
13: import javax.rmi.PortableRemoteObject;
14:
15: /**
16: * The Hello service implementation. <br />
17: * It exposes two interfaces: the RMI Remote interface, invocable from remote clients -
18: * represented by the {@link Hello} interface, and
19: * the management interface - represented by the {@link HelloImplMBean} interface,
20: * invocable from management applications that wants to manage the features of this
21: * service.
22: *
23: * @version $Revision: 1.1 $
24: */
25: public class HelloImpl implements Hello, HelloImplMBean {
26: private boolean m_isRunning;
27:
28: public HelloImpl() throws RemoteException {
29: }
30:
31: public void sayHello(String name) throws RemoteException {
32: String hello = "Hello";
33: System.out.println(hello + " " + name);
34: }
35:
36: public void start() throws Exception {
37: if (!m_isRunning) {
38: // export the remote object
39: PortableRemoteObject.exportObject(this );
40: // set up the initialContext
41: Context ctx = new InitialContext();
42: ctx.rebind(IIOP_JNDI_NAME, this );
43: System.out
44: .println("My Service servant started successfully");
45: m_isRunning = true;
46: }
47: }
48:
49: public void stop() throws Exception {
50: if (m_isRunning) {
51: PortableRemoteObject.unexportObject(this );
52: Context ctx = new InitialContext();
53: ctx.unbind(IIOP_JNDI_NAME);
54: m_isRunning = false;
55: System.out
56: .println("My Service Servant stopped successfully");
57: }
58: }
59:
60: public boolean isRunning() {
61: return m_isRunning;
62: }
63: }
|