KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > system > rmi > RMIRegistryService


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.system.rmi;
18
19 import java.rmi.registry.LocateRegistry JavaDoc;
20 import java.rmi.registry.Registry JavaDoc;
21 import java.rmi.server.UnicastRemoteObject JavaDoc;
22 import java.net.InetSocketAddress JavaDoc;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.geronimo.gbean.GBeanInfo;
27 import org.apache.geronimo.gbean.GBeanInfoBuilder;
28 import org.apache.geronimo.gbean.GBeanLifecycle;
29
30 /**
31  * Thin GBean wrapper around the RMI Registry.
32  *
33  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
34  */

35 public class RMIRegistryService implements GBeanLifecycle {
36     private static final Log log = LogFactory.getLog(RMIRegistryService.class);
37     private int port = Registry.REGISTRY_PORT;
38     private Registry JavaDoc registry;
39
40     public int getPort() {
41         return port;
42     }
43
44     public void setPort(int port) {
45         this.port = port;
46     }
47
48     public String JavaDoc getHost() {
49         return "0.0.0.0";
50     }
51
52     public String JavaDoc getProtocol() {
53         return "rmi";
54     }
55
56     public void doStart() throws Exception JavaDoc {
57         System.setProperty("java.rmi.server.RMIClassLoaderSpi",RMIClassLoaderSpiImpl.class.getName());
58         registry = LocateRegistry.createRegistry(port);
59         log.debug("Started RMI Registry on port " + port);
60     }
61
62     public void doStop() throws Exception JavaDoc {
63         UnicastRemoteObject.unexportObject(registry, true);
64         log.debug("Stopped RMI Registry");
65     }
66
67     public void doFail() {
68         try {
69             doStop();
70         } catch (Exception JavaDoc e) {
71             log.warn("RMI Registry failed");
72         }
73     }
74
75     public InetSocketAddress JavaDoc getListenAddress() {
76         return new InetSocketAddress JavaDoc(getHost(), getPort());
77     }
78
79     public static final GBeanInfo GBEAN_INFO;
80
81     static {
82         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("RMI Naming", RMIRegistryService.class);
83         infoFactory.addAttribute("host", String JavaDoc.class, false);
84         infoFactory.addAttribute("protocol", String JavaDoc.class, false);
85         infoFactory.addAttribute("port", int.class, true, true);
86         infoFactory.addAttribute("listenAddress", InetSocketAddress JavaDoc.class, false);
87         GBEAN_INFO = infoFactory.getBeanInfo();
88     }
89
90     public static GBeanInfo getGBeanInfo() {
91         return GBEAN_INFO;
92     }
93 }
94
Popular Tags