/** * Returns the port number the RMI {@link Registry} is running on. * * @param registry the registry to find the port of. * @return the port number the registry is using. * @throws RuntimeException if there was a problem getting the port number. */ public static int getRegistryPort(Registry registry) { int port = -1; try { RemoteRef remoteRef = ((RegistryImpl)registry).getRef(); LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef(); Endpoint endpoint = liveRef.getChannel().getEndpoint(); TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint; port = tcpEndpoint.getPort(); } catch (Exception ex) { throw new RuntimeException("Error getting registry port.", ex); } return port; }
private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException { // rmi.log.0C=ActivationID.writeObject: rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.0C")); //$NON-NLS-1$ try { out.writeObject(uid); // rmi.log.0D=activator = {0} rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.0D", activator)); //$NON-NLS-1$ RemoteRef ref = ((RemoteObject) activator).getRef(); // rmi.log.09=ref = {0} rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.09", ref)); //$NON-NLS-1$ String refType = ref.getRefClass(out); // rmi.log.08=refType={0} rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.08", refType)); //$NON-NLS-1$ out.writeUTF(refType); ref.writeExternal(out); // rmi.log.04=ActivationID.writeObject COMPLETED. rlog.log(RMILog.VERBOSE, Messages.getString("rmi.log.04")); //$NON-NLS-1$ } catch (Throwable t) { // rmi.0A=Unable to serialize ActivationID: {0} throw new IOException(Messages.getString("rmi.0A", t.getMessage()));//$NON-NLS-1$ } }
/** * 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); } }
/** * To obtain the description of the Serialization of this class see the Serialized form of * java.rmi.server.RemoteObject. */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { id = (ActivationID) in.readObject(); String s = in.readUTF(); if (s.equals("")) { //$NON-NLS-1$ return; } Class extRefTypeClass = Class.forName(RemoteRef.packagePrefix +"."+ s); //$NON-NLS-1$ try { ref = (RemoteRef)extRefTypeClass.newInstance(); } catch(Throwable t) { // rmi.73=Instantiation failed. throw new ClassNotFoundException(Messages.getString("rmi.73"), t); //$NON-NLS-1$ } ref.readExternal(in); }
/** * Sends the first dirty for a received reference in order to get the * appropiate lease time from the server, and then schedules the dirty call * for lease renewal. If the first dirty message fails, a clean "strong" * message is sent for that remote object. If the first dirty call * succeeded, the reference becomes a "live" reference for the client DGC. * * @param ref * The reference received inside the stub * @return The <code>Endpoint / ObjID</code> pair contained inside the * reference * @throws UnmarshalException * If the first dirty call fails */ private final Pair<Endpoint, ObjID> activateReference(RemoteRef ref) throws UnmarshalException { // Get necessary data previously stored during RemoteRef // deserialization. Pair<Endpoint, ObjID> data = deserializedRemoteRefTable.get(ref); if (data == null) { throw new UnmarshalException( "Impossible to get a stub for this object."); } Lease lease = sendDirty(data.getFirst(), new ObjID[] { data.getSecond() }); if (lease != null) { enqueueDirtyCall(data, lease.getValue()); liveReferences.put(data, new Long(lease.getValue())); return data; } else { sendClean(data.getFirst(), new ObjID[] { data.getSecond() }, true); throw new UnmarshalException( "Impossible to get a stub for this object."); } }
public final void testInvoke004() throws RemoteException { EchoUnicast_Imp eui = new EchoUnicast_Imp() { public String echo(String msg) throws RemoteException { return msg; } }; RemoteRef ref = eui.getRef(); Echo proxy = (Echo) RemoteObject.toStub(eui); String toSend = "hola invoquer"; try { r = new RemoteObjectInvocationHandler(ref); assertEquals("The result is what we expect", toSend, r.invoke( proxy, Echo.class.getMethods()[0], new Object[] { toSend })); } catch (Throwable e) { fail("Failed with:" + e); } }
public final void testInvoke008() throws RemoteException { EchoUnicast_Imp eui = new EchoUnicast_Imp() { public String echo(String msg) throws RemoteException { return msg; } }; RemoteRef ref = eui.getRef(); Echo proxy = (Echo) RemoteObject.toStub(eui); String toSend = "hola invoquer"; try { r = new RemoteObjectInvocationHandler(ref); assertEquals("The result is what we expected", toSend, r.invoke( proxy, Echo.class.getMethods()[0], new Object[] { toSend, toSend })); } catch (Throwable e) { fail("Failed with:" + e); } }
public final void testInvoke011() throws RemoteException { BigEcho_imp bei = new BigEcho_imp() { public void echo() throws RemoteException { throw new RemoteException("Always pass throw here"); } public void echo(Object... objs) throws RemoteException { if (objs == null) { throw new RemoteException("Objs Null"); } } }; RemoteRef ref = bei.getRef(); BigEcho proxy = (BigEcho) RemoteObject.toStub(bei); try { r = new RemoteObjectInvocationHandler(ref); assertNull(r.invoke(proxy, BigEcho.class.getMethods()[1], new Object[] { new Object[] { 1, 2, 3, 4 } })); } catch (Throwable e) { fail("Failed with:" + e); } }
public final void testInvoke012() throws RemoteException { BigEcho_imp bei = new BigEcho_imp() { public void echo() throws RemoteException { throw new RemoteException("Always pass throw here"); } public void echo(Object... objs) throws RemoteException { if (objs == null) { throw new RemoteException("Objs Null"); } } }; RemoteRef ref = bei.getRef(); BigEcho proxy = (BigEcho) RemoteObject.toStub(bei); try { r = new RemoteObjectInvocationHandler(ref); assertNull(r.invoke(proxy, BigEcho.class.getMethods()[1], new Object[] { new Object[] {} })); } catch (Throwable e) { fail("Failed with:" + e); } }
public UnicastRemoteObject getObject ( final String command ) throws Exception { int jrmpPort = Integer.parseInt(command); UnicastRemoteObject uro = Reflections.createWithConstructor(ActivationGroupImpl.class, RemoteObject.class, new Class[] { RemoteRef.class }, new Object[] { new UnicastServerRef(jrmpPort) }); Reflections.getField(UnicastRemoteObject.class, "port").set(uro, jrmpPort); return uro; }
/** * private method to obtain the ref for a call. */ private synchronized RemoteRef getRef() throws RemoteException { if (ref == null) { ref = activate(false); } return ref; }
/** * Write out external representation for remote ref. */ public void writeExternal(ObjectOutput out) throws IOException { RemoteRef localRef = ref; out.writeObject(id); if (localRef == null) { out.writeUTF(""); } else { out.writeUTF(localRef.getRefClass(out)); localRef.writeExternal(out); } }
/** * Returns a proxy for the specified implClass. * * If both of the following criteria is satisfied, a dynamic proxy for * the specified implClass is returned (otherwise a RemoteStub instance * for the specified implClass is returned): * * a) either the property java.rmi.server.ignoreStubClasses is true or * a pregenerated stub class does not exist for the impl class, and * b) forceStubUse is false. * * If the above criteria are satisfied, this method constructs a * dynamic proxy instance (that implements the remote interfaces of * implClass) constructed with a RemoteObjectInvocationHandler instance * constructed with the clientRef. * * Otherwise, this method loads the pregenerated stub class (which * extends RemoteStub and implements the remote interfaces of * implClass) and constructs an instance of the pregenerated stub * class with the clientRef. * * @param implClass the class to obtain remote interfaces from * @param clientRef the remote ref to use in the invocation handler * @param forceStubUse if true, forces creation of a RemoteStub * @throws IllegalArgumentException if implClass implements illegal * remote interfaces * @throws StubNotFoundException if problem locating/creating stub or * creating the dynamic proxy instance **/ public static Remote createProxy(Class<?> implClass, RemoteRef clientRef, boolean forceStubUse) throws StubNotFoundException { Class<?> remoteClass; try { remoteClass = getRemoteClass(implClass); } catch (ClassNotFoundException ex ) { throw new StubNotFoundException( "object does not implement a remote interface: " + implClass.getName()); } if (forceStubUse || !(ignoreStubClasses || !stubClassExists(remoteClass))) { return createStub(remoteClass, clientRef); } final ClassLoader loader = implClass.getClassLoader(); final Class<?>[] interfaces = getRemoteInterfaces(implClass); final InvocationHandler handler = new RemoteObjectInvocationHandler(clientRef); /* REMIND: private remote interfaces? */ try { return AccessController.doPrivileged(new PrivilegedAction<Remote>() { public Remote run() { return (Remote) Proxy.newProxyInstance(loader, interfaces, handler); }}); } catch (IllegalArgumentException e) { throw new StubNotFoundException("unable to create proxy", e); } }
public Constructor<?> run() throws Exception { Class thisClass = RMIConnector.class; ClassLoader thisLoader = thisClass.getClassLoader(); ProtectionDomain thisProtectionDomain = thisClass.getProtectionDomain(); String[] otherClassNames = {ProxyRef.class.getName()}; ClassLoader cl = new NoCallStackClassLoader(pRefClassName, pRefByteCode, otherClassNames, thisLoader, thisProtectionDomain); Class<?> c = cl.loadClass(pRefClassName); return c.getConstructor(RemoteRef.class); }
private static RMIConnection shadowJrmpStub(RemoteObject stub) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, NoSuchMethodException { RemoteRef ref = stub.getRef(); RemoteRef proxyRef = (RemoteRef) proxyRefConstructor.newInstance(new Object[] {ref}); final Constructor<?> rmiConnectionImplStubConstructor = rmiConnectionImplStubClass.getConstructor(RemoteRef.class); Object[] args = {proxyRef}; RMIConnection proxyStub = (RMIConnection) rmiConnectionImplStubConstructor.newInstance(args); return proxyStub; }
public UnicastRemoteObject getObject ( String port ) throws Exception { int jrmpPort = Integer.parseInt(port); UnicastRemoteObject uro = Reflections.createWithConstructor(ActivationGroupImpl.class, RemoteObject.class, new Class[] { RemoteRef.class }, new Object[] { new UnicastServerRef(jrmpPort) }); Reflections.getField(UnicastRemoteObject.class, "port").set(uro, jrmpPort); return uro; }
public static void main(String[] args) throws Exception { System.err.println("\nRegression test for RFE 5096178\n"); Class<? extends P> cl = Class.forName(PImpl.class.getName() + "_Stub").asSubclass(P.class); Constructor<? extends P> cons = cl.getConstructor(RemoteRef.class); cons.newInstance(new ArgCheckingRemoteRef(Boolean.FALSE)).m(false); cons.newInstance(new ArgCheckingRemoteRef(Boolean.TRUE)).m(true); System.err.println("TEST PASSED"); }