272 * for some reason or if it is inevitable that its {@link #start()
273 * start} method will fail.
274 *
275 * @see #start
276 */
277 public RMIConnectorServer(JMXServiceURL url, Map<String,?> environment,
278 RMIServerImpl rmiServerImpl,
279 MBeanServer mbeanServer)
280 throws IOException {
281 super(mbeanServer);
282
283 if (url == null) throw new
284 IllegalArgumentException("Null JMXServiceURL");
285 if (rmiServerImpl == null) {
286 final String prt = url.getProtocol();
287 if (prt == null || !(prt.equals("rmi"))) {
288 final String msg = "Invalid protocol type: " + prt;
289 throw new MalformedURLException(msg);
290 }
291 final String urlPath = url.getURLPath();
292 if (!urlPath.equals("")
293 && !urlPath.equals("/")
294 && !urlPath.startsWith("/jndi/")) {
295 final String msg = "URL path must be empty or start with " +
296 "/jndi/";
297 throw new MalformedURLException(msg);
298 }
299 }
300
301 if (environment == null)
302 this.attributes = Collections.emptyMap();
303 else {
304 EnvHelp.checkAttributes(environment);
305 this.attributes = Collections.unmodifiableMap(environment);
306 }
307
308 this.address = url;
309 this.rmiServerImpl = rmiServerImpl;
310 }
311
312 /**
729
730 /**
731 * Encode a stub into the JMXServiceURL.
732 * @param rmiServer The stub object to encode in the URL
733 * @param attributes A Map containing environment parameters,
734 * built from the Map specified at this object creation.
735 **/
736 private void encodeStubInAddress(
737 RMIServer rmiServer, Map<String, ?> attributes)
738 throws IOException {
739
740 final String protocol, host;
741 final int port;
742
743 if (address == null) {
744 protocol = "rmi";
745 host = null; // will default to local host name
746 port = 0;
747 } else {
748 protocol = address.getProtocol();
749 host = (address.getHost().equals("")) ? null : address.getHost();
750 port = address.getPort();
751 }
752
753 final String urlPath = encodeStub(rmiServer, attributes);
754
755 address = new JMXServiceURL(protocol, host, port, urlPath);
756 }
757
758 /**
759 * Returns the IOR of the given rmiServer.
760 **/
761 static String encodeStub(
762 RMIServer rmiServer, Map<String, ?> env) throws IOException {
763 return "/stub/" + encodeJRMPStub(rmiServer, env);
764 }
765
766 static String encodeJRMPStub(
767 RMIServer rmiServer, Map<String, ?> env)
768 throws IOException {
769 ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
272 * for some reason or if it is inevitable that its {@link #start()
273 * start} method will fail.
274 *
275 * @see #start
276 */
277 public RMIConnectorServer(JMXServiceURL url, Map<String,?> environment,
278 RMIServerImpl rmiServerImpl,
279 MBeanServer mbeanServer)
280 throws IOException {
281 super(mbeanServer);
282
283 if (url == null) throw new
284 IllegalArgumentException("Null JMXServiceURL");
285 if (rmiServerImpl == null) {
286 final String prt = url.getProtocol();
287 if (prt == null || !(prt.equals("rmi"))) {
288 final String msg = "Invalid protocol type: " + prt;
289 throw new MalformedURLException(msg);
290 }
291 final String urlPath = url.getURLPath();
292 if (!urlPath.isEmpty()
293 && !urlPath.equals("/")
294 && !urlPath.startsWith("/jndi/")) {
295 final String msg = "URL path must be empty or start with " +
296 "/jndi/";
297 throw new MalformedURLException(msg);
298 }
299 }
300
301 if (environment == null)
302 this.attributes = Collections.emptyMap();
303 else {
304 EnvHelp.checkAttributes(environment);
305 this.attributes = Collections.unmodifiableMap(environment);
306 }
307
308 this.address = url;
309 this.rmiServerImpl = rmiServerImpl;
310 }
311
312 /**
729
730 /**
731 * Encode a stub into the JMXServiceURL.
732 * @param rmiServer The stub object to encode in the URL
733 * @param attributes A Map containing environment parameters,
734 * built from the Map specified at this object creation.
735 **/
736 private void encodeStubInAddress(
737 RMIServer rmiServer, Map<String, ?> attributes)
738 throws IOException {
739
740 final String protocol, host;
741 final int port;
742
743 if (address == null) {
744 protocol = "rmi";
745 host = null; // will default to local host name
746 port = 0;
747 } else {
748 protocol = address.getProtocol();
749 host = (address.getHost().isEmpty()) ? null : address.getHost();
750 port = address.getPort();
751 }
752
753 final String urlPath = encodeStub(rmiServer, attributes);
754
755 address = new JMXServiceURL(protocol, host, port, urlPath);
756 }
757
758 /**
759 * Returns the IOR of the given rmiServer.
760 **/
761 static String encodeStub(
762 RMIServer rmiServer, Map<String, ?> env) throws IOException {
763 return "/stub/" + encodeJRMPStub(rmiServer, env);
764 }
765
766 static String encodeJRMPStub(
767 RMIServer rmiServer, Map<String, ?> env)
768 throws IOException {
769 ByteArrayOutputStream bout = new ByteArrayOutputStream();
|