KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ubermq > jms > server > AdminProtocol


1 /*
2  * Copyright (c) 2004 Rhombus Technologies, Inc.
3  * All rights reserved.
4  */

5 package com.ubermq.jms.server;
6
7 import java.io.IOException JavaDoc;
8 import java.net.*;
9 import java.rmi.RemoteException JavaDoc;
10 import java.rmi.registry.*;
11
12 import com.ubermq.jms.server.admin.*;
13 import com.ubermq.kernel.*;
14 import com.ubermq.kernel.IConnectionInfo.ConnectionAcceptor;
15 import com.ubermq.util.Utility;
16
17
18 /**
19  * The administration protocol implementation.
20  */

21 public class AdminProtocol
22     implements Protocol
23 {
24     private static final org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(AdminProtocol.class);
25     
26     private final int ADMIN_PORT =
27         Integer.valueOf(Configurator.getProperty(ServerConfig.ADMIN_PORT, "3998")).intValue();
28     private final String JavaDoc ADMIN_SERVICE_NAME =
29         Configurator.getProperty(ServerConfig.ADMIN_SERVICE_NAME, "UberMQAdmin");
30
31     private URI serviceURI;
32
33     public boolean isEnabled()
34     {
35         return Boolean.valueOf(Configurator.getProperty(ServerConfig.ADMIN_ENABLE, "false")).booleanValue();
36     }
37
38     public void start(IMessageProcessor mp,
39                       IConnectionInfo.ConnectionAcceptor a)
40         throws IOException JavaDoc
41     {
42         try
43         {
44             RemoteAdminProxy admin = new RemoteAdminProxy((MessageServerAdmin)mp);
45             LocateRegistry.createRegistry(ADMIN_PORT);
46
47             Registry registry = LocateRegistry.getRegistry(ADMIN_PORT);
48             registry.rebind(ADMIN_SERVICE_NAME, admin);
49
50             serviceURI = URI.create("//" + InetAddress.getLocalHost().getHostName() +
51                                         ":" + ADMIN_PORT + "/" + ADMIN_SERVICE_NAME);
52             log.info("Administrative service running at " + serviceURI.toString());
53         }
54         catch (java.rmi.RemoteException JavaDoc e)
55         {
56             // could already be created for another server.
57
throw new IOException JavaDoc(e.getMessage());
58         }
59     }
60
61     public void stop()
62     {
63     }
64
65     public String JavaDoc toString()
66     {
67         return "UberMQAdmin";
68     }
69
70     /**
71      * Returns the service URI for this protocol.
72      *
73      * @return an URI describing how to connect to
74      * this protocol, or null if a URI cannot be used.
75      */

76     public URI getServiceURI()
77     {
78         return serviceURI;
79     }
80
81
82 }
Popular Tags