本文整理汇总了Java中javax.naming.InitialContext.rebind方法的典型用法代码示例。如果您正苦于以下问题:Java InitialContext.rebind方法的具体用法?Java InitialContext.rebind怎么用?Java InitialContext.rebind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.naming.InitialContext
的用法示例。
在下文中一共展示了InitialContext.rebind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bind
import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
* Registers a new service in JNDI. The service is bound to the name define by the service interface's
* {@link io.bdj.service.ServiceAddress} annotation.
*
* @param service
* the service instance to be registered. The service must implement an interface that is annotated with
* {@link io.bdj.service.ServiceAddress} that defines the service address.
*/
public static <S, I extends S> void bind(Class<S> serviceClass, I service) {
ServiceAddress addr = getServiceAddress(serviceClass);
try {
InitialContext ic = new InitialContext();
ic.rebind(addr.value(), service);
} catch (NamingException e) {
throw new ServiceRuntimeException("Could not bind service " + serviceClass);
}
}
示例2: bind
import javax.naming.InitialContext; //导入方法依赖的package包/类
/**
* Bind a stub to a registry.
* @param jndiUrl URL of the stub in the registry, extracted
* from the <code>JMXServiceURL</code>.
* @param attributes A Hashtable containing environment parameters,
* built from the Map specified at this object creation.
* @param rmiServer The object to bind in the registry
* @param rebind true if the object must be rebound.
**/
void bind(String jndiUrl, Hashtable<?, ?> attributes,
RMIServer rmiServer, boolean rebind)
throws NamingException, MalformedURLException {
// if jndiURL is not null, we nust bind the stub to a
// directory.
InitialContext ctx =
new InitialContext(attributes);
if (rebind)
ctx.rebind(jndiUrl, rmiServer);
else
ctx.bind(jndiUrl, rmiServer);
ctx.close();
}