下面列出了javax.naming.Context#rebind ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void bindGlobals(final Map<String, Object> bindings) throws NamingException {
final Context containerSystemContext = containerSystem.getJNDIContext();
for (final Entry<String, Object> value : bindings.entrySet()) {
final String path = value.getKey();
// keep only global bindings
if (path.startsWith("module/") || path.startsWith("app/") || path.startsWith("comp/") || path.equalsIgnoreCase("global/dummy")) {
continue;
}
// a bit weird but just to be consistent if user doesn't lookup directly the resource
final Context lastContext = Contexts.createSubcontexts(containerSystemContext, path);
try {
lastContext.rebind(path.substring(path.lastIndexOf('/') + 1, path.length()), value.getValue());
} catch (final NameAlreadyBoundException nabe) {
nabe.printStackTrace();
}
containerSystemContext.rebind(path, value.getValue());
}
}
private static DataSource initDataSource() {
JdbcDataSource dataSource = new JdbcDataSource();
String dbUrl = DatabaseCreator.nextUrl();
dataSource.setURL(dbUrl);
String jndiName = "jdbc/RxDS";
try {
Context context = new InitialContext();
context.rebind(jndiName, dataSource);
} catch (NamingException e) {
throw new RuntimeException(e);
}
return dataSource;
}
public void run() {
while (shouldKeepBinding()) {
try {
Context objectContext = configuration.getObjectContext();
objectContext.rebind(name, server.getServant());
objectContext.close();
} catch (Exception ex) {
System.err.println("Exception binding at " + new Date() + "; will keep trying...");
ex.printStackTrace();
} finally {
try {
Thread.sleep(REBIND_PERIOD);
} catch (InterruptedException ignore) {
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
/**
* Binds the given stub and skeleton.
*
* <p>
* Both have to be exported. The skeleton has to be accessed from the
* stub via RMI and the stub has to be exported to be accessible via
* JNDI.
* </p>
*
* @param context The context to bind skeleton and stub.
* @param skeleton The skeleton to bind.
* @param stub The stub to bind.
*/
static void bind(final Context context, final Skeleton skeleton,
final Stub stub) {
final String skeletonName;
try {
skeletonName = skeleton.getSkeletonName();
} catch (RemoteException re) {
LOGGER.error("error retrieving the skeleton name", re);
return;
}
final String stubName = stub.getStubName();
try {
context.rebind(skeletonName, skeleton);
context.rebind(stubName, stub);
} catch (javax.naming.NamingException ne) {
LOGGER.error("naming exception while exporting '" + skeletonName
+ "'", ne);
return;
}
LOGGER.info("bound '" + stubName + "' to '"
+ stub.getClass().getName() + "'");
}
private boolean bindToJndi(final String jndiName, final Object objectToBind) throws NamingException {
if (context != null) {
String parentContext;
String jndiNameInContext;
int sepIndex = jndiName.lastIndexOf('/');
if (sepIndex == -1) {
parentContext = "";
} else {
parentContext = jndiName.substring(0, sepIndex);
}
jndiNameInContext = jndiName.substring(sepIndex + 1);
try {
context.lookup(jndiName);
//JMSServerManagerImpl.log.warn("Binding for " + jndiName + " already exists");
return false;
} catch (Throwable e) {
// OK
}
Context c = JNDIUtil.createContext(context, parentContext);
c.rebind(jndiNameInContext, objectToBind);
}
return true;
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void rebindSessionManager(final SessionManager sessionManager, final String jndiName) {
LOG.info("Binding Hibersap SessionManager '" + sessionManager.getConfig().getName()
+ "' to JNDI name '" + jndiName + "'");
try {
Context ctx = new InitialContext();
ctx.rebind(jndiName, sessionManager);
} catch (NamingException e) {
throw new HibersapException("Failed binding Hibersap SessionManager to JNDI name [" + jndiName + "]", e);
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public static void main(String[] args) {
int retryCount = 0;
while (retryCount < MAX_RETRY) {
try {
//HelloServer.set("SETTING TEST ITL");
// Step 1: Instantiate the Hello servant
HelloImpl helloRef = new HelloImpl();
// Step 2: Publish the reference in the Naming Service
// using JNDI API
Context initialNamingContext = new InitialContext();
initialNamingContext.rebind("HelloService", helloRef);
System.out.println("Hello Server: Ready...");
break;
} catch (Exception e) {
System.out.println("Server initialization problem: " + e);
e.printStackTrace();
retryCount++;
try {
Thread.sleep(ONE_SECOND);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
public void start() throws Exception
{
if (!m_isRunning)
{
// export the remote object
PortableRemoteObject.exportObject(this);
// set up the initialContext
Context ctx = new InitialContext();
ctx.rebind(IIOP_JNDI_NAME, this);
System.out.println("My Service servant started successfully");
m_isRunning = true;
}
}
public void run() {
while (shouldKeepBinding()) try {
Context objectContext = configuration.getObjectContext();
objectContext.rebind(name, server.getServant());
objectContext.close();
} catch (Throwable ex) {
System.err.println("Exception binding at " + new Date() + "; will keep trying...");
ex.printStackTrace();
} finally {
try {
Thread.sleep(REBIND_PERIOD);
} catch (InterruptedException ignore) {}
}
}
private CamelContext createCamelContext(StorageCredentials creds) throws Exception {
WildFlyCamelContext camelctx = new WildFlyCamelContext();
Context jndictx = camelctx.getNamingContext();
jndictx.rebind("creds", creds);
return camelctx;
}