KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mx4j > examples > mbeans > iiop > HelloImpl


1 /*
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8 package mx4j.examples.mbeans.iiop;
9
10 import java.rmi.RemoteException JavaDoc;
11 import javax.naming.Context JavaDoc;
12 import javax.naming.InitialContext JavaDoc;
13 import javax.rmi.PortableRemoteObject JavaDoc;
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.4 $
24  */

25 public class HelloImpl implements Hello, HelloImplMBean
26 {
27    private boolean m_isRunning;
28
29    public HelloImpl() throws RemoteException JavaDoc
30    {
31    }
32
33    public void sayHello(String JavaDoc name) throws RemoteException JavaDoc
34    {
35       String JavaDoc hello = "Hello";
36       System.out.println(hello + " " + name);
37    }
38
39    public void start() throws Exception JavaDoc
40    {
41       if (!m_isRunning)
42       {
43          // export the remote object
44
PortableRemoteObject.exportObject(this);
45          // set up the initialContext
46
Context JavaDoc ctx = new InitialContext JavaDoc();
47          ctx.rebind(IIOP_JNDI_NAME, this);
48          System.out.println("My Service servant started successfully");
49          m_isRunning = true;
50       }
51    }
52
53    public void stop() throws Exception JavaDoc
54    {
55       if (m_isRunning)
56       {
57          PortableRemoteObject.unexportObject(this);
58          Context JavaDoc ctx = new InitialContext JavaDoc();
59          ctx.unbind(IIOP_JNDI_NAME);
60          m_isRunning = false;
61          System.out.println("My Service Servant stopped successfully");
62       }
63    }
64
65    public boolean isRunning()
66    {
67       return m_isRunning;
68    }
69 }
70
Popular Tags