下面列出了javax.naming.InitialContext#unbind ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void unregisterJNDI(DataSourceMetaInfo dsmInfo) {
try {
// PrivilegedCarbonContext.startTenantFlow();
// PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(this.getTenantId());
JNDIConfig jndiConfig = dsmInfo.getJndiConfig();
if (jndiConfig == null) {
return;
}
try {
InitialContext context = new InitialContext(jndiConfig.extractHashtableEnv());
context.unbind(jndiConfig.getName());
} catch (NamingException e) {
log.error("Error in unregistering JNDI name: " +
jndiConfig.getName() + " - " + e.getMessage(), e);
}
} finally {
// PrivilegedCarbonContext.endTenantFlow();
}
}
@Override
public void unbind(String jndiName) {
final InitialContext initialContext = buildInitialContext();
final Name name = parseName( jndiName, initialContext );
try {
initialContext.unbind( name );
}
catch (Exception e) {
throw new JndiException( "Error performing unbind [" + name + "]", e );
}
finally {
cleanUp( initialContext );
}
}
@Test(expected = IllegalStateException.class)
public void testMissingBeanException() throws Exception {
// Simulate missing EJB
InitialContext context = new InitialContext();
context.unbind(APPlatformService.JNDI_NAME);
// And invoke internal EJB constructor
new ConfigurationBean();
}
@Test(expected = RuntimeException.class)
public void initializeNoJndi() throws Exception {
InitialContext context = new InitialContext();
context.unbind(APPlatformService.JNDI_NAME);
// when no platform service is available via JNDI, the controller cannot
// work
new RORController().initialize();
}
@Test(expected = RuntimeException.class)
public void initializeNoJndi_Communication() throws Exception {
InitialContext context = new InitialContext();
context.unbind(APPlatformService.JNDI_NAME);
// when no platform service is available via JNDI, the controller cannot
// work
new ProcessManagerBean().initialize();
}
public void stop() throws Exception
{
if (m_running)
{
InitialContext ctx = new InitialContext();
ctx.unbind(JNDI_NAME);
UnicastRemoteObject.unexportObject(this, false);
m_running = false;
System.out.println("My remote service stopped successfully");
}
}
/**
* Stop the server.
* @throws Exception
*/
public void stop() throws Exception {
if (node != null) {
deleteAndFlush();
node.stop();
System.out.println("================ STOPPED ES ================ ");
}
server.stop();
if (ds != null) {
ds.close();
InitialContext ctx = TestUtil.initialContext();
ctx.unbind("java:comp/env/jdbc/ApiManagerDS");
}
}
@After
public void tearDown() throws NamingException {
InitialContext ctx = new InitialContext();
ctx.unbind( fullJndiName );
}
/**
* Unbounds object under specified name.
*
* @param jndiName
* the JNDI name of the object to be unbound.
*/
private void unbind(String jndiName) throws NamingException {
InitialContext initialContext = new InitialContext();
initialContext.unbind(jndiName);
}