/** * Deregisters a server object from the runtime, allowing the object to become * available for garbage collection. * @param obj the object to unexport. * @exception NoSuchObjectException if the remote object is not * currently exported. */ public void unexportObject(Remote obj) throws NoSuchObjectException { if (obj == null) { throw new NullPointerException("invalid argument"); } if (StubAdapter.isStub(obj) || obj instanceof java.rmi.server.RemoteStub) { throw new NoSuchObjectException( "Can only unexport a server object."); } Tie theTie = Util.getTie(obj); if (theTie != null) { Util.unexportObject(obj); } else { if (Utility.loadTie(obj) == null) { UnicastRemoteObject.unexportObject(obj,true); } else { throw new NoSuchObjectException("Object not exported."); } } }
/** * Export this object, create the skeleton and stubs for this * dispatcher. Create a stub based on the type of the impl, * initialize it with the appropriate remote reference. Create the * target defined by the impl, dispatcher (this) and stub. * Export that target via the Ref. */ public Remote exportObject(Remote impl, Object data, boolean permanent) throws RemoteException { Class<?> implClass = impl.getClass(); Remote stub; try { stub = Util.createProxy(implClass, getClientRef(), forceStubUse); } catch (IllegalArgumentException e) { throw new ExportException( "remote object implements illegal remote interface", e); } if (stub instanceof RemoteStub) { setSkeleton(impl); } Target target = new Target(impl, this, stub, ref.getObjID(), permanent); ref.exportObject(target); hashToMethod_Map = hashToMethod_Maps.get(implClass); return stub; }
/** * Export this object, create the skeleton and stubs for this * dispatcher. Create a stub based on the type of the impl, * initialize it with the appropriate remote reference. Create the * target defined by the impl, dispatcher (this) and stub. * Export that target via the Ref. */ public Remote exportObject(Remote impl, Object data, boolean permanent) throws RemoteException { Class implClass = impl.getClass(); Remote stub; try { stub = Util.createProxy(implClass, getClientRef(), forceStubUse); } catch (IllegalArgumentException e) { throw new ExportException( "remote object implements illegal remote interface", e); } if (stub instanceof RemoteStub) { setSkeleton(impl); } Target target = new Target(impl, this, stub, ref.getObjID(), permanent); ref.exportObject(target); hashToMethod_Map = hashToMethod_Maps.get(implClass); return stub; }
/** * Returns the Remote Stub for the given activatable class. */ public static RemoteStub getStub(ActivationDesc desc, ActivationID aid) throws StubNotFoundException { String cn = desc.getClassName(); String stubName = ""; //$NON-NLS-1$ try { Class cl = RMIClassLoader.loadClass(desc.getLocation(), cn); Class rcl = RMIUtil.getRemoteClass(cl); stubName = rcl.getName() + "_Stub"; //$NON-NLS-1$ Class stubClass = RMIClassLoader.loadClass((String) null, stubName); Constructor constructor = stubClass.getConstructor(new Class[] { RemoteRef.class }); RemoteStub stub = (RemoteStub) constructor.newInstance(new Object[] { new ActivatableRef(aid, null) }); return stub; } catch (Exception ex) { // rmi.68=Stub {0} not found. throw new StubNotFoundException(Messages.getString("rmi.68", stubName), //$NON-NLS-1$ //$NON-NLS-2$ ex); } }
/** * Returns a stub if the object to be serialized is a * {@link java.rmi.Remote} instance. * * @param obj * the object to be replaced if needed be. * @return if the argument was a {@link java.rmi.Remote} object locally * exported a stub for that object is returned, in case it is not a * {@link java.rmi.Remote} the object is returned * @throws IOException * if the I/O operation fails */ @Override protected final Object replaceObject(Object obj) throws IOException { if (obj instanceof Remote) { RemoteReferenceManager rrm = RemoteReferenceManager .getRemoteReferenceManager(); if (rrm.isExported((Remote) obj)) { writesRemote = true; return RemoteObject.toStub((Remote) obj); } if (obj instanceof RemoteStub) { writesRemote = true; return obj; } if (Proxy.isProxyClass(obj.getClass())) { InvocationHandler ih = Proxy.getInvocationHandler(obj); if (ih instanceof RemoteObjectInvocationHandler) { writesRemote = true; } } } return obj; }
/** * replaceObject is extended to check for instances of Remote * that need to be serialized as proxy objects. RemoteProxy.getProxy * is called to check for and find the stub. */ @Override protected Object replaceObject(Object obj) throws IOException { System.out.println(" */*/*/*/*/*/*/* /*/*/**//**/ Inside replaceObject /*/**/*//*/**//*/*/**//*/*"); if ((obj instanceof Remote) && !(obj instanceof RemoteStub)) { System.out.println(" */*/*/*/*/*/*/* /*/*/**//**/ found a Remote object " + obj + " /*/**/*//*/**//*/*/**//*/*"); Remote target = RemoteObject.toStub((Remote) obj); if (target != null) { return target; } } System.out .println(" */*/*/*/*/*/*/* /*/*/**//**/ Normal obj : " + obj + "/*/**/*//*/**//*/*/**//*/*"); return obj; }
/** * Returns a stub for the given server object. * @param obj the server object for which a stub is required. Must either be a subclass * of PortableRemoteObject or have been previously the target of a call to * {@link #exportObject}. * @return the most derived stub for the object. * @exception NoSuchObjectException if a stub cannot be located for the given server object. */ public Remote toStub (Remote obj) throws NoSuchObjectException { Remote result = null; if (obj == null) { throw new NullPointerException("invalid argument"); } // If the class is already an IIOP stub then return it. if (StubAdapter.isStub( obj )) { return obj; } // If the class is already a JRMP stub then return it. if (obj instanceof java.rmi.server.RemoteStub) { return obj; } // Has it been exported to IIOP? Tie theTie = Util.getTie(obj); if (theTie != null) { result = Utility.loadStub(theTie,null,null,true); } else { if (Utility.loadTie(obj) == null) { result = java.rmi.server.RemoteObject.toStub(obj); } } if (result == null) { throw new NoSuchObjectException("object not exported"); } return result; }
/** * Checks for objects that are instances of java.rmi.Remote * that need to be serialized as proxy objects. */ protected final Object replaceObject(Object obj) throws IOException { if ((obj instanceof Remote) && !(obj instanceof RemoteStub)) { Target target = ObjectTable.getTarget((Remote) obj); if (target != null) { return target.getStub(); } } return obj; }
/** * Checks for objects that are instances of java.rmi.Remote * that need to be serialized as proxy objects. */ @SuppressWarnings("deprecation") protected final Object replaceObject(Object obj) throws IOException { if ((obj instanceof Remote) && !(obj instanceof RemoteStub)) { Target target = ObjectTable.getTarget((Remote) obj); if (target != null) { return target.getStub(); } } return obj; }