本文整理汇总了Java中java.rmi.server.UnicastRemoteObject.exportObject方法的典型用法代码示例。如果您正苦于以下问题:Java UnicastRemoteObject.exportObject方法的具体用法?Java UnicastRemoteObject.exportObject怎么用?Java UnicastRemoteObject.exportObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.rmi.server.UnicastRemoteObject
的用法示例。
在下文中一共展示了UnicastRemoteObject.exportObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: export
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
private void export(Remote obj) throws RemoteException {
final RMIExporter exporter =
(RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
final boolean daemon = EnvHelp.isServerDaemon(env);
if (daemon && exporter != null) {
throw new IllegalArgumentException("If "+EnvHelp.JMX_SERVER_DAEMON+
" is specified as true, "+RMIExporter.EXPORTER_ATTRIBUTE+
" cannot be used to specify an exporter!");
}
if (daemon) {
if (csf == null && ssf == null) {
new UnicastServerRef(port).exportObject(obj, null, true);
} else {
new UnicastServerRef2(port, csf, ssf).exportObject(obj, null, true);
}
} else if (exporter != null) {
exporter.exportObject(obj, port, csf, ssf);
} else {
UnicastRemoteObject.exportObject(obj, port, csf, ssf);
}
}
示例2: main
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6275081\n");
Remote impl = new Remote() { };
long start = System.currentTimeMillis();
for (int i = 0; i < REPS; i++) {
System.err.println(i);
UnicastRemoteObject.exportObject(impl, 0);
UnicastRemoteObject.unexportObject(impl, true);
Thread.sleep(1); // work around BindException (bug?)
}
long delta = System.currentTimeMillis() - start;
System.err.println(REPS + " export/unexport operations took " +
delta + "ms");
if (delta > TIMEOUT) {
throw new Error("TEST FAILED: took over " + TIMEOUT + "ms");
}
System.err.println("TEST PASSED");
}
示例3: ActivationGroupImpl
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
/**
* Creates a default activation group implementation.
*
* @param id the group's identifier
* @param data ignored
*/
public ActivationGroupImpl(ActivationGroupID id, MarshalledObject<?> data)
throws RemoteException
{
super(id);
groupID = id;
/*
* Unexport activation group impl and attempt to export it on
* an unshared anonymous port. See 4692286.
*/
unexportObject(this, true);
RMIServerSocketFactory ssf = new ServerSocketFactoryImpl();
UnicastRemoteObject.exportObject(this, 0, null, ssf);
if (System.getSecurityManager() == null) {
try {
// Provide a default security manager.
System.setSecurityManager(new SecurityManager());
} catch (Exception e) {
throw new RemoteException("unable to set security manager", e);
}
}
}
示例4: run
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
/**
* Export remote objects.
* Arguments: <# objects>
*/
public long run(String[] args) throws Exception {
int size = Integer.parseInt(args[0]);
Remote[] objs = new Remote[size];
for (int i = 0; i < size; i++)
objs[i] = new RemoteObj();
long start = System.currentTimeMillis();
for (int i = 0; i < size; i++)
UnicastRemoteObject.exportObject(objs[i],0);
long time = System.currentTimeMillis() - start;
for (int i = 0; i < size; i++)
UnicastRemoteObject.unexportObject(objs[i], true);
return time;
}
示例5: main
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6275081\n");
Remote impl = new Remote() { };
long start = System.currentTimeMillis();
for (int i = 0; i < REPS; i++) {
System.err.println(i);
UnicastRemoteObject.exportObject(impl, PORT);
UnicastRemoteObject.unexportObject(impl, true);
Thread.sleep(1); // work around BindException (bug?)
}
long delta = System.currentTimeMillis() - start;
System.err.println(REPS + " export/unexport operations took " +
delta + "ms");
if (delta > TIMEOUT) {
throw new Error("TEST FAILED: took over " + TIMEOUT + "ms");
}
System.err.println("TEST PASSED");
}
示例6: main
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public static void main(String[] args) {
map_filename_blocks = new HashMap<>();
block_number = 0;
map_block_datanode = new HashMap<>();
/* Write the existing data */
restoreFilelist();
setDatanodeIps();
String myip = getMyIp();
if (myip.equals("")) {
System.err.println("Error in Getting My ip");
System.exit(-1);
}
System.setProperty("java.rmi.server.hostname", myip);
try {
Namenode obj = new Namenode();
Namenodedef stub = (Namenodedef) UnicastRemoteObject.exportObject(obj, 0);
Registry reg = LocateRegistry.getRegistry("0.0.0.0", 1099);
reg.rebind("NameNode", stub);
} catch (RemoteException e) {
e.printStackTrace();
}
}
示例7: getInstance
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public String getInstance(IStochModelFactory.OutputLevel outputLevel) {
String instanceID=null;
try {
nModels++;
instanceID= FactoryBindingID+"_IRmiIStochModel_"+nModels;
// Create a new model instance
IStochModelInstance newStochModel = stochModelFactory.getInstance(outputLevel);
// Create a new server instance and set the new model for this instance
Server obj = new Server();
obj.setModel(newStochModel);
IRmiIStochModel stub = (IRmiIStochModel) UnicastRemoteObject.exportObject(obj, 0);
// Register this insntance such that it will not be deleted.
allStochModels.add(stub);
// Bind the remote object's stub in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind(instanceID, stub);
System.err.println("Server has created model "+instanceID);
} catch (Exception e) {
System.err.println("Server exception when creating new model: " + e.toString());
e.printStackTrace();
}
return instanceID;
}
示例8: main
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6269166\n");
RMISocketFactory.setSocketFactory(new SF());
Remote impl = new ReuseDefaultPort();
Remote stub = UnicastRemoteObject.exportObject(impl, 0);
System.err.println("- exported object: " + stub);
try {
Registry registry = LocateRegistry.createRegistry(rmiPort);
System.err.println("- exported registry: " + registry);
System.err.println("TEST PASSED");
} finally {
UnicastRemoteObject.unexportObject(impl, true);
}
}
示例9: main
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6332349\n");
Ping impl = new PingImpl();
Reference<?> ref = new WeakReference<Ping>(impl);
try {
Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
Object notSerializable = new Object();
stub.ping(impl, null);
try {
stub.ping(impl, notSerializable);
} catch (MarshalException e) {
if (e.getCause() instanceof NotSerializableException) {
System.err.println("ping invocation failed as expected");
} else {
throw e;
}
}
} finally {
UnicastRemoteObject.unexportObject(impl, true);
}
impl = null;
// Might require multiple calls to System.gc() for weak-references
// processing to be complete. If the weak-reference is not cleared as
// expected we will hang here until timed out by the test harness.
while (true) {
System.gc();
Thread.sleep(20);
if (ref.get() == null) {
break;
}
}
System.err.println("TEST PASSED");
}
示例10: tryWith
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
private static void tryWith(Throwable t) throws Exception {
Remote impl = new Remote() { };
try {
CountDownLatch latch = new CountDownLatch(1);
UnicastRemoteObject.exportObject(impl, 0, null, new SSF(t, latch));
if (!latch.await(TIMEOUT, TimeUnit.MILLISECONDS)) {
throw new Error("server socket not closed");
}
} finally {
UnicastRemoteObject.unexportObject(impl, true);
}
}
示例11: export
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
@Contract("!null->!null")
public synchronized <T extends Remote> T export(@Nullable T child) throws RemoteException {
if (child == null) return null;
@SuppressWarnings("unchecked") final T result = (T)UnicastRemoteObject.exportObject(child, 0);
myChildren.put((RemoteObject)child, result);
((RemoteObject)child).myParent = this;
return result;
}
示例12: createEmbedder
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public MavenServerEmbedder createEmbedder(MavenServerSettings settings) throws RemoteException {
try {
Maven32ServerEmbedderImpl result = new Maven32ServerEmbedderImpl(settings);
UnicastRemoteObject.exportObject(result, 0);
return result;
}
catch (RemoteException e) {
throw rethrowException(e);
}
}
示例13: main
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
try {
testPkg.Server obj = new testPkg.Server();
testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
// Bind the remote object's stub in the registry
Registry registry =
LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT);
registry.bind("Hello", stub);
System.err.println("Server ready");
// now, let's test client
testPkg.Client client =
new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT);
String testStubReturn = client.testStub();
if(!testStubReturn.equals(obj.hello)) {
throw new RuntimeException("Test Fails : unexpected string from stub call");
} else {
System.out.println("Test passed");
}
registry.unbind("Hello");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
示例14: exportObject
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public Remote exportObject(Remote obj,
int port,
RMIClientSocketFactory csf,
RMIServerSocketFactory ssf)
throws RemoteException {
System.out.println("CustomRMIExporter::exportObject():: " +
"Remote = " + obj);
if (obj.toString().startsWith(
"javax.management.remote.rmi.RMIJRMPServerImpl"))
rmiServerExported = true;
if (obj.toString().startsWith(
"javax.management.remote.rmi.RMIConnectionImpl"))
rmiConnectionExported = true;
return UnicastRemoteObject.exportObject(obj, port, csf, ssf);
}
示例15: main
import java.rmi.server.UnicastRemoteObject; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 6269166\n");
RMISocketFactory.setSocketFactory(new SF());
Remote impl = new ReuseDefaultPort();
Remote stub = UnicastRemoteObject.exportObject(impl, 0);
System.err.println("- exported object: " + stub);
try {
Registry registry = LocateRegistry.createRegistry(PORT);
System.err.println("- exported registry: " + registry);
System.err.println("TEST PASSED");
} finally {
UnicastRemoteObject.unexportObject(impl, true);
}
}