本文整理汇总了Java中javax.rmi.PortableRemoteObject类的典型用法代码示例。如果您正苦于以下问题:Java PortableRemoteObject类的具体用法?Java PortableRemoteObject怎么用?Java PortableRemoteObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PortableRemoteObject类属于javax.rmi包,在下文中一共展示了PortableRemoteObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toStub
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
@Override
public Remote toStub(final Remote obj) throws NoSuchObjectException {
if (System.getSecurityManager() == null) {
return PortableRemoteObject.toStub(obj);
} else {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<Remote>() {
@Override
public Remote run() throws Exception {
return PortableRemoteObject.toStub(obj);
}
}, STUB_ACC);
} catch (PrivilegedActionException e) {
if (e.getException() instanceof NoSuchObjectException) {
throw (NoSuchObjectException)e.getException();
}
throw new RuntimeException("Unexpected exception type", e.getException());
}
}
}
示例2: lookupBMXABean
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
private static BMXATest lookupBMXABean(InitialContext ictx, String jndiName) {
try {
Object home = ictx.lookup(jndiName);
BMXATestHome rhome = (BMXATestHome) PortableRemoteObject.narrow(
home, BMXATestHome.class);
BMXATest bean = (BMXATest) PortableRemoteObject.narrow(
rhome.create(), BMXATest.class);
return bean;
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name " + jndiName
+ " on the WebLogic server at " + url);
} catch (CreateException ce) {
log("Creation failed: " + ce);
} catch (RemoteException ex) {
log("Creation failed: " + ex);
}
return null;
}
示例3: lookupCMXABean
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
private static CMXATest lookupCMXABean(InitialContext ictx, String jndiName) {
try {
Object home = ictx.lookup(jndiName);
CMXATestHome rhome = (CMXATestHome) PortableRemoteObject.narrow(
home, CMXATestHome.class);
CMXATest bean = (CMXATest) PortableRemoteObject.narrow(
rhome.create(), CMXATest.class);
return bean;
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name " + jndiName
+ " on the WebLogic server at " + url);
} catch (CreateException ce) {
log("Creation failed: " + ce);
} catch (RemoteException ex) {
log("Creation failed: " + ex);
}
return null;
}
示例4: acquire
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
private Remote acquire(RunningInfo info) throws Exception {
Remote result;
Registry registry = LocateRegistry.getRegistry("localhost", info.port);
java.rmi.Remote lookup = registry.lookup(info.name);
if (java.rmi.Remote.class.isAssignableFrom(remoteClass)) {
Remote entry =
remoteClass.isInstance(lookup)
? (Remote) lookup
: (Remote) PortableRemoteObject.narrow(lookup, remoteClass);
if (entry == null) {
result = null;
} else {
// TODO add proxy for remote object
result = (Remote) lookup;
}
} else {
result = (Remote) lookup;
}
info.remoteRef = result;
return result;
}
示例5: createEJB3
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Obtiene un EJB a partir de su nombre JNDI
* @param jndiContextProps propiedades para obtener una referencia al contexto jndi del LDAP
* @param jndiName nombre JNDI
* @param local true si se trata de una referencia al EJB local
* @param type tipo del objeto
* @return la referencia al EJB
*/
@SuppressWarnings("unchecked")
public static <T> T createEJB3(Properties jndiContextProps,
String jndiName,boolean local,Class<T> type) {
T outEJB = null;
try {
Context initialContext = JNDIContextLocator.getInstance().getInitialContext(jndiContextProps);
String theJNDIName = jndiName + (local ? "Local" : ""); // Por "convenio" el nombre JNDI del EJB local tiene el sufijo "Local"
Object obj = initialContext.lookup(theJNDIName);
if (local) {
outEJB = (T)obj;
} else {
outEJB = (T)PortableRemoteObject.narrow(obj,type);
}
} catch(NamingException namEx) {
// TODO log
String err = Strings.of("NO se ha podido obtener un contexto jndi contra el LDAP")
.asString();
System.out.println(err);
}
return outEJB;
}
示例6: createEJB2
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Obtiene un EJB a partir de su nombre JNDI
* @param jndiContextProps propiedades para obtener una referencia al contexto jndi del LDAP
* @param jndiName nombre JNDI
* @param local true si se trata de una referencia al EJB local
* @param homeType tipo del interfaz home
* @return la referencia al EJB
*/
public static <T> T createEJB2(Properties jndiContextProps,
String jndiName,boolean local,Class<?> homeType) {
T outEJB = null;
try {
Context initialContext = JNDIContextLocator.getInstance().getInitialContext(jndiContextProps);
String theJNDIName = jndiName + (local ? "Local" : ""); // Por "convenio" el nombre JNDI del EJB local tiene el sufijo "Local"
Object home = initialContext.lookup(theJNDIName);
Object homeNarrowed = PortableRemoteObject.narrow(home,homeType);
outEJB = Reflection.of(homeNarrowed).method("create").<T>invoke(); // llamar al m�todo create en el objeto home
} catch(NamingException namEx) {
// TODO log
String err = Strings.of("NO se ha podido obtener un contexto jndi contra el LDAP")
.asString();
System.out.println(err);
}
return outEJB;
}
示例7: testNarrowedRemoteAccess
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
@Test
@RunAsClient
public void testNarrowedRemoteAccess() throws Exception
{
InitialContext iniCtx = null;
try {
iniCtx = getServerInitialContext();
Object obj = iniCtx.lookup("jaxws-jbws944//FooBean01!" + EJB3RemoteHome.class.getName());
EJB3RemoteHome ejb3Home = (EJB3RemoteHome)PortableRemoteObject.narrow(obj, EJB3RemoteHome.class);
EJB3RemoteInterface ejb3Remote = ejb3Home.create();
String helloWorld = "Hello world!";
Object retObj = ejb3Remote.echo(helloWorld);
assertEquals(helloWorld, retObj);
}
finally
{
if (iniCtx != null)
{
iniCtx.close();
}
}
}
示例8: newEJBHome
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* 得到urlName下的EJB.
*
* @param urlName
* String
* @return Object
*/
private Object newEJBHome(String urlName) {
try {
Context ctx = ServiceLocator.getInstance().getContext(urlName);
if (ctx == null) {
log.info("can't find the context by specified url " + urlName);
return null;
}
Object jndiRef = ctx.lookup(name);
Class cl = Class.forName(homeClassName);
Object homeObj = PortableRemoteObject.narrow(jndiRef, cl);
return homeObj;
} catch (Exception e) {
log.debug("create home obj fail", e);
}
return null;
}
示例9: init
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Setting up the test fixture.
*/
private void init() throws Exception
{
Context ctx = ContextHelper.getContext();
times = new long[4];
try
{
Object object = PortableRemoteObject.narrow(ctx.lookup(PBSessionHome.JNDI_NAME), EJBHome.class);
bean = ((PBSessionHome) object).create();
}
catch(Exception e)
{
e.printStackTrace(System.err);
throw e;
}
}
示例10: init
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Setting up the test fixture.
*/
private void init() throws Exception
{
Context ctx = ContextHelper.getContext();
times = new long[4];
try
{
Object object = PortableRemoteObject.narrow(ctx.lookup(ODMGSessionHome.JNDI_NAME), EJBHome.class);
bean = ((ODMGSessionHome) object).create();
}
catch(Exception e)
{
e.printStackTrace(System.err);
throw e;
}
}
示例11: prepare
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Initialize this service exporter, binding the specified service to JNDI.
* @throws NamingException if service binding failed
* @throws RemoteException if service export failed
*/
public void prepare() throws NamingException, RemoteException {
if (this.jndiName == null) {
throw new IllegalArgumentException("Property 'jndiName' is required");
}
// Initialize and cache exported object.
this.exportedObject = getObjectToExport();
PortableRemoteObject.exportObject(this.exportedObject);
rebind();
}
示例12: destroy
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Unbind the RMI service from JNDI on bean factory shutdown.
*/
@Override
public void destroy() throws NamingException, NoSuchObjectException {
if (logger.isInfoEnabled()) {
logger.info("Unbinding RMI service from JNDI location [" + this.jndiName + "]");
}
this.jndiTemplate.unbind(this.jndiName);
PortableRemoteObject.unexportObject(this.exportedObject);
}
示例13: lookup
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* This overridden lookup implementation performs a narrow operation
* after the JNDI lookup, provided that a home interface is specified.
* @see #setHomeInterface
* @see javax.rmi.PortableRemoteObject#narrow
*/
@Override
protected Object lookup() throws NamingException {
Object homeObject = super.lookup();
if (this.homeInterface != null) {
try {
homeObject = PortableRemoteObject.narrow(homeObject, this.homeInterface);
}
catch (ClassCastException ex) {
throw new RemoteLookupFailureException(
"Could not narrow EJB home stub to home interface [" + this.homeInterface.getName() + "]", ex);
}
}
return homeObject;
}
示例14: readObjectAndNarrow
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Read an object reference from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readObjectAndNarrow(InputStream in,
Class narrowTo)
throws ClassCastException
{
Object result = in.read_Object();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}
示例15: readAbstractAndNarrow
import javax.rmi.PortableRemoteObject; //导入依赖的package包/类
/**
* Read an abstract interface type from the input stream and narrow
* it to the desired type.
* @param in the stream to read from.
* @throws ClassCastException if narrowFrom cannot be cast to narrowTo.
*/
public static Object readAbstractAndNarrow(
org.omg.CORBA_2_3.portable.InputStream in, Class narrowTo)
throws ClassCastException
{
Object result = in.read_abstract_interface();
if (result != null)
return PortableRemoteObject.narrow(result, narrowTo);
else
return null;
}