KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > jmx > remote > server > rmi > RmiStubRegistryHandler


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * RmiRegistryHandler.java
26  * Indentation Information:
27  * 0. Please (try to) preserve these settings.
28  * 1. No tabs are used, all spaces.
29  * 2. In vi/vim -
30  * :set tabstop=4 :set shiftwidth=4 :set softtabstop=4
31  * 3. In S1 Studio -
32  * 1. Tools->Options->Editor Settings->Java Editor->Tab Size = 4
33  * 2. Tools->Options->Indentation Engines->Java Indentation Engine->Expand Tabs to Spaces = True.
34  * 3. Tools->Options->Indentation Engines->Java Indentation Engine->Number of Spaces per Tab = 4.
35  * Unit Testing Information:
36  * 0. Is Standard Unit Test Written (y/n):
37  * 1. Unit Test Location: (The instructions should be in the Unit Test Class itself).
38  */

39
40 package com.sun.enterprise.admin.jmx.remote.server.rmi;
41
42 import java.rmi.registry.Registry JavaDoc;
43 import java.rmi.registry.LocateRegistry JavaDoc;
44 import java.rmi.server.RMIClientSocketFactory JavaDoc;
45 import java.rmi.server.RMIServerSocketFactory JavaDoc;
46 import java.util.logging.Logger JavaDoc;
47
48 import com.sun.enterprise.admin.jmx.remote.IStringManager;
49 import com.sun.enterprise.admin.jmx.remote.StringManagerFactory;
50
51 /** A package-private class that deals with the RMI registry in the VM.
52  * This RMI registry is used as the naming service to find the rmi stub.
53  *
54  * @author kedar
55  * @since Sun Java System Application Server 8.1
56  */

57 class RmiStubRegistryHandler {
58     
59     private static IStringManager sm =
60         StringManagerFactory.getServerStringManager( RmiStubRegistryHandler.class );
61     
62     private final Logger JavaDoc logger;
63     
64     /** Starts the RMI registry at the given port. If the security flag is
65      * false an in-process "insecure" rmi registry will be created. If the flag
66      * is true, an attempt will be made if the registry could be made secure.
67      * Running on JDK 1.4.x has a limitation of not being able to create multiple
68      * registries in the same VM.
69      */

70     RmiStubRegistryHandler(final int port, final boolean secureRegistry, final Logger JavaDoc logger) {
71         if (logger == null)
72             throw new IllegalArgumentException JavaDoc("Internal: Null logger");
73         this.logger = logger;
74         if (secureRegistry) {
75             throw new UnsupportedOperationException JavaDoc("Yet to be implemented");
76         }
77         else {
78             startInsecureRegistry(port);
79         }
80     }
81     /* Not needed as the setup of RMIConnectorServer would do it - we only
82        need to start the registry. No need to pass on the Socket Factories. */

83     /*
84     RmiStubRegistryHandler(final int port, final boolean secureRegistry, final RMIClientSocketFactory cf, final RMIServerSocketFactory sf) {
85         if (secureRegistry) {
86             throw new UnsupportedOperationException("Yet to be implemented");
87         }
88         else {
89             startInsecureRegistry(port, cf, sf);
90         }
91     }
92     */

93     private void startInsecureRegistry(final int port) {
94         try {
95             final Registry JavaDoc r = LocateRegistry.createRegistry(port);
96             logBindings(r, port);
97         }
98         catch (final Exception JavaDoc e) {
99             final String JavaDoc msg = sm.getString("no.port.msg", new Integer JavaDoc(port));
100             throw new RuntimeException JavaDoc(e);
101         }
102     }
103     /* Not needed as the setup of RMIConnectorServer would do it - we only
104        need to start the registry. No need to pass on the Socket Factories. */

105     /*
106     private void startInsecureRegistry(final int port, final RMIClientSocketFactory cf, final RMIServerSocketFactory sf) {
107         try {
108             LocateRegistry.createRegistry(port, cf, sf);
109         }
110         catch (final Exception e) {
111         }
112     }
113     */

114     private void logBindings(final Registry JavaDoc r, final int port) {
115         try {
116             final String JavaDoc[] bs = r.list();
117             logger.fine("Initial Bindings in RmiRegistry at port: [" + port + "] :");
118             for (int i = 0 ; i < bs.length ; i++) {
119                 logger.fine("JMX Connector RMI Registry binding: " + bs[i]);
120             }
121         }
122         catch(final Exception JavaDoc e) {
123             e.printStackTrace();
124             //squelching this exception is okay, as only logging is affected.
125
}
126     }
127 }
Popular Tags