提交 93ffbffb 编写于 作者: C coffeys

6893617: JDK 6 CNCtx always uses the default ORB

Reviewed-by: lancea
上级 4eca6b55
/* /*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -58,8 +58,22 @@ public class CNCtx implements javax.naming.Context { ...@@ -58,8 +58,22 @@ public class CNCtx implements javax.naming.Context {
private final static boolean debug = false; private final static boolean debug = false;
/*
* Implement one shared ORB among all CNCtx. However, there is a public constructor
* accepting an ORB, so we need the option of using a given ORB.
*/
private static ORB _defaultOrb;
ORB _orb; // used by ExceptionMapper and RMI/IIOP factory ORB _orb; // used by ExceptionMapper and RMI/IIOP factory
public NamingContext _nc; // public for accessing underlying NamingContext public NamingContext _nc; // public for accessing underlying NamingContext
private synchronized static ORB getDefaultOrb() {
if (_defaultOrb == null) {
_defaultOrb = CorbaUtils.getOrb(null, -1,
new Hashtable<String, java.lang.Object>());
}
return _defaultOrb;
}
private NameComponent[] _name = null; private NameComponent[] _name = null;
Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper
...@@ -114,8 +128,9 @@ public class CNCtx implements javax.naming.Context { ...@@ -114,8 +128,9 @@ public class CNCtx implements javax.naming.Context {
// rest is the INS name // rest is the INS name
// Return the parsed form to prevent subsequent lookup // Return the parsed form to prevent subsequent lookup
// from parsing the string as a composite name // from parsing the string as a composite name
// The caller should be aware that a toString() of the name // The caller should be aware that a toString() of the name,
// will yield its INS syntax, rather than a composite syntax // which came from the environment will yield its INS syntax,
// rather than a composite syntax
return new ResolveResult(ctx, parser.parse(rest)); return new ResolveResult(ctx, parser.parse(rest));
} }
...@@ -135,10 +150,10 @@ public class CNCtx implements javax.naming.Context { ...@@ -135,10 +150,10 @@ public class CNCtx implements javax.naming.Context {
if (orb == null || nctx == null) if (orb == null || nctx == null)
throw new ConfigurationException( throw new ConfigurationException(
"Must supply ORB or NamingContext"); "Must supply ORB or NamingContext");
_orb = orb; if (orb != null) {
orbTracker = tracker; _orb = orb;
if (orbTracker != null) { } else {
orbTracker.incRefCount(); _orb = getDefaultOrb();
} }
_nc = nctx; _nc = nctx;
_env = env; _env = env;
...@@ -212,10 +227,13 @@ public class CNCtx implements javax.naming.Context { ...@@ -212,10 +227,13 @@ public class CNCtx implements javax.naming.Context {
org.omg.CORBA.ORB inOrb = null; org.omg.CORBA.ORB inOrb = null;
String ncIor = null; String ncIor = null;
if (env != null) { if (inOrb == null && env != null) {
inOrb = (org.omg.CORBA.ORB) env.get("java.naming.corba.orb"); inOrb = (org.omg.CORBA.ORB) env.get("java.naming.corba.orb");
} }
if (inOrb == null)
inOrb = getDefaultOrb(); // will create a default ORB if none exists
// Extract PROVIDER_URL from environment // Extract PROVIDER_URL from environment
String provUrl = null; String provUrl = null;
if (env != null) { if (env != null) {
...@@ -226,13 +244,6 @@ public class CNCtx implements javax.naming.Context { ...@@ -226,13 +244,6 @@ public class CNCtx implements javax.naming.Context {
// Initialize the root naming context by using the IOR supplied // Initialize the root naming context by using the IOR supplied
// in the PROVIDER_URL // in the PROVIDER_URL
ncIor = getStringifiedIor(provUrl); ncIor = getStringifiedIor(provUrl);
if (inOrb == null) {
// no ORB instance specified; create one using env and defaults
inOrb = CorbaUtils.getOrb(null, -1, env);
orbTracker = new OrbReuseTracker(inOrb);
}
setOrbAndRootContext(inOrb, ncIor); setOrbAndRootContext(inOrb, ncIor);
} else if (provUrl != null) { } else if (provUrl != null) {
// Initialize the root naming context by using the URL supplied // Initialize the root naming context by using the URL supplied
...@@ -258,14 +269,8 @@ public class CNCtx implements javax.naming.Context { ...@@ -258,14 +269,8 @@ public class CNCtx implements javax.naming.Context {
} }
} else { } else {
// No PROVIDER_URL supplied; initialize using defaults // No PROVIDER_URL supplied; initialize using defaults
if (inOrb == null) { if (debug) {
System.err.println("Getting default ORB: " + inOrb + env);
// No ORB instance specified; create one using env and defaults
inOrb = CorbaUtils.getOrb(null, -1, env);
orbTracker = new OrbReuseTracker(inOrb);
if (debug) {
System.err.println("Getting default ORB: " + inOrb + env);
}
} }
setOrbAndRootContext(inOrb, (String)null); setOrbAndRootContext(inOrb, (String)null);
} }
...@@ -286,6 +291,10 @@ public class CNCtx implements javax.naming.Context { ...@@ -286,6 +291,10 @@ public class CNCtx implements javax.naming.Context {
*/ */
private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env) private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
if (defOrb == null)
defOrb = getDefaultOrb();
try { try {
IiopUrl parsedUrl = new IiopUrl(url); IiopUrl parsedUrl = new IiopUrl(url);
...@@ -294,19 +303,17 @@ public class CNCtx implements javax.naming.Context { ...@@ -294,19 +303,17 @@ public class CNCtx implements javax.naming.Context {
for (IiopUrl.Address addr : parsedUrl.getAddresses()) { for (IiopUrl.Address addr : parsedUrl.getAddresses()) {
try { try {
if (defOrb != null) { try {
try { String tmpUrl = "corbaloc:iiop:" + addr.host
String tmpUrl = "corbaloc:iiop:" + addr.host + ":" + addr.port + "/NameService";
+ ":" + addr.port + "/NameService"; if (debug) {
if (debug) { System.err.println("Using url: " + tmpUrl);
System.err.println("Using url: " + tmpUrl); }
} org.omg.CORBA.Object rootCtx =
org.omg.CORBA.Object rootCtx = defOrb.string_to_object(tmpUrl);
defOrb.string_to_object(tmpUrl); setOrbAndRootContext(defOrb, rootCtx);
setOrbAndRootContext(defOrb, rootCtx); return parsedUrl.getStringName();
return parsedUrl.getStringName(); } catch (Exception e) {} // keep going
} catch (Exception e) {} // keep going
}
// Get ORB // Get ORB
if (debug) { if (debug) {
...@@ -314,12 +321,8 @@ public class CNCtx implements javax.naming.Context { ...@@ -314,12 +321,8 @@ public class CNCtx implements javax.naming.Context {
+ " and port " + addr.port); + " and port " + addr.port);
} }
// Get ORB
ORB orb = CorbaUtils.getOrb(addr.host, addr.port, env);
orbTracker = new OrbReuseTracker(orb);
// Assign to fields // Assign to fields
setOrbAndRootContext(orb, (String)null); setOrbAndRootContext(defOrb, (String)null);
return parsedUrl.getStringName(); return parsedUrl.getStringName();
} catch (NamingException ne) { } catch (NamingException ne) {
...@@ -341,18 +344,16 @@ public class CNCtx implements javax.naming.Context { ...@@ -341,18 +344,16 @@ public class CNCtx implements javax.naming.Context {
*/ */
private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env) private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
if (orb == null)
orb = getDefaultOrb();
try { try {
CorbanameUrl parsedUrl = new CorbanameUrl(url); CorbanameUrl parsedUrl = new CorbanameUrl(url);
String corbaloc = parsedUrl.getLocation(); String corbaloc = parsedUrl.getLocation();
String cosName = parsedUrl.getStringName(); String cosName = parsedUrl.getStringName();
if (orb == null) {
// No ORB instance specified; create one using env and defaults
orb = CorbaUtils.getOrb(null, -1, env);
orbTracker = new OrbReuseTracker(orb);
}
setOrbAndRootContext(orb, corbaloc); setOrbAndRootContext(orb, corbaloc);
return parsedUrl.getStringName(); return parsedUrl.getStringName();
...@@ -1117,9 +1118,6 @@ public class CNCtx implements javax.naming.Context { ...@@ -1117,9 +1118,6 @@ public class CNCtx implements javax.naming.Context {
} }
synchronized public void incEnumCount() { synchronized public void incEnumCount() {
if (orbTracker == null) {
return;
}
enumCount++; enumCount++;
if (debug) { if (debug) {
System.out.println("incEnumCount, new count:" + enumCount); System.out.println("incEnumCount, new count:" + enumCount);
...@@ -1128,9 +1126,6 @@ public class CNCtx implements javax.naming.Context { ...@@ -1128,9 +1126,6 @@ public class CNCtx implements javax.naming.Context {
synchronized public void decEnumCount() synchronized public void decEnumCount()
throws NamingException { throws NamingException {
if (orbTracker == null) {
return;
}
enumCount--; enumCount--;
if (debug) { if (debug) {
System.out.println("decEnumCount, new count:" + enumCount + System.out.println("decEnumCount, new count:" + enumCount +
...@@ -1142,14 +1137,15 @@ public class CNCtx implements javax.naming.Context { ...@@ -1142,14 +1137,15 @@ public class CNCtx implements javax.naming.Context {
} }
synchronized public void close() throws NamingException { synchronized public void close() throws NamingException {
if (orbTracker == null) {
return;
}
if (enumCount > 0) { if (enumCount > 0) {
isCloseCalled = true; isCloseCalled = true;
return; return;
} }
orbTracker.decRefCount();
// Never destroy an orb in CNCtx.
// The orb we have is either the shared/default orb, or one passed in to a constructor
// from elsewhere, so that orb is somebody else's reponsibility.
} }
protected void finalize() { protected void finalize() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册