/** * Receives a dispatch request from the Transport Layer and forwards it to * the appropriate dispatcher object. * * @param objID * The <code>ObjID</code> received in the request * @param hash * The method identificator received in the request * @param args * The arguments received in the request * @return The result of the invocation in the remote object * @throws Exception * If the invocation of the method throws an exception */ public final Object executeCall(ObjID objID, long hash, Object[] args) throws Exception { if (objID == null) { throw new NoSuchObjectException( "Remote server not available (ObjID == null)."); } ServerRef sref = serverRefsMap.get(objID); if (sref == null) { throw new NoSuchObjectException( "Remote server not available (ObjID not found in lookup)."); } /* * REVIEW: For call execution the instance of ServerRef needed is of * type UnicastServerRefImpl, instead of ServerRef... (ServerRef doesn't * specify the dispach method) Review the casting or the type stored in * the container when the implementation of the Activation framework * takes place. */ if (sref instanceof UnicastServerRefImpl) { return ((UnicastServerRefImpl) sref).executeCall(args, hash); } throw new NoSuchObjectException( "Remote server not available (No UnicastServerImpl reference)."); }
/** * Returns the number of arguments received by the method represented by * <code>methodHash</code> in the remote object referenced by * <code>objID</code> * * @param objID * The <code>ObjID</code> received in the request * @param methodHash * The method identificator received in the request * @return the number of arguments of the method * @throws NoSuchObjectException * if there isn't any exported object with the received * <code>ObjID</code> */ public final int getArgsCount(ObjID objID, long methodHash) throws NoSuchObjectException { if (objID == null) { throw new NoSuchObjectException( "Remote server not available (ObjID == null)."); } ServerRef sref = serverRefsMap.get(objID); if (sref == null) { throw new NoSuchObjectException( "Remote server not available (ObjID not found in lookup)."); } /* * REVIEW: For call execution the instance of ServerRef needed is of * type UnicastServerRefImpl, instead of ServerRef... (ServerRef doesn't * specify the getArgsCount method) Review the casting or the type * stored in the container when the implementation of the Activation * framework takes place. */ if (sref instanceof UnicastServerRefImpl) { return ((UnicastServerRefImpl) sref).getArgsCount(methodHash); } throw new NoSuchObjectException( "Remote server not available (No UnicastServerImpl reference)."); }
/** * Returns true if the method represented by <code>methodHash</code> in * the remote object referenced by <code>objID</code> returns any value. * (the return type of the method is different than <code>void</code>) * * @param objID * The <code>ObjID</code> received in the request * @param methodHash * The method identificator received in the request * @return true if the return type of the method is different than * <code>void</code>, otherwise returns false * @throws NoSuchObjectException * if there isn't any exported object with the received * <code>ObjID</code> */ public final boolean sendReturnValue(ObjID objID, long methodHash) throws NoSuchObjectException { if (objID == null) { throw new NoSuchObjectException( "Remote server not available (ObjID == null)."); } ServerRef sref = serverRefsMap.get(objID); if (sref == null) { throw new NoSuchObjectException( "Remote server not available (ObjID not found in lookup)."); } /* * REVIEW: For call execution the instance of ServerRef needed is of * type UnicastServerRefImpl, instead of ServerRef... (ServerRef doesn't * specify the sendReturnValue method) Review the casting or the type * stored in the container when the implementation of the Activation * framework takes place. */ if (sref instanceof UnicastServerRefImpl) { return ((UnicastServerRefImpl) sref).sendReturnValue(methodHash); } throw new NoSuchObjectException( "Remote server not available (No UnicastServerImpl reference)."); }
/** * Creates a new instance of <code>RemoteReferenceManager</code>. This * created instance should be the one and only. (<code>RemoteReferenceManager</code> * is a Singleton object) */ private RemoteReferenceManager() { // Initialize internal tables serverRefsMap = new Hashtable<ObjID, ServerRef>(); exportedRemotes = Collections .synchronizedMap(new WeakHashMap<Remote, Pair<Remote, ObjID>>()); // Export the Distributed Garbage Collector dgc = new DGCImpl(); ObjID objID = new ObjID(ObjID.DGC_ID); UnicastServerRefImpl sref = new UnicastServerRefImpl(dgc, objID, null); storeExportData(null, objID, sref, null); }
/** * Exports the registry implementation in the received port, with the * received socket factories. The exportation procedure is similar to the * procedure implemented for <code>UnicastRemoteObject</code>, but using * the special well-known <code>ObjID</code> for the registry. * * @param port * The port where the registry will listen requests * @param csf * The <code>ClientSocketFactory</code> that will be used to * contact this registry * @param ssf * The <code>ServerSocketFactory</code> used for exportation * @param useType2Ref * Indicates whether the references created during object * exportation should be "UnicastRef" or "UnicastRef2" * @return A stub for this registry implementation * @throws RemoteException */ public final Remote exportObject(int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf, boolean useType2Ref) throws RemoteException { if (port == 0) { port = Registry.REGISTRY_PORT; } RemoteReferenceManager rrm = RemoteReferenceManager .getRemoteReferenceManager(); if (rrm.isExported(this)) { throw new RemoteException("Object already exported."); } TransportManager tm = TransportManager.getTransportManager(); ObjID objID = new ObjID(ObjID.REGISTRY_ID); Endpoint ep = tm.export(objID, port, ssf, csf); ServerRef sref; Remote stub; if (useType2Ref) { sref = new UnicastServerRef2Impl(this, objID, ep); stub = rrm.createStub(new UnicastRemoteRef2Impl(objID, ep), this); } else { sref = new UnicastServerRefImpl(this, objID, ep); stub = rrm.createStub(new UnicastRemoteRefImpl(objID, ep), this); } rrm.storeExportData(this, objID, sref, stub); return stub; }
/** * Creates a new instance of <code>RemoteReferenceManager</code>. This * created instance should be the one and only. (<code>RemoteReferenceManager</code> * is a Singleton object) */ private RemoteReferenceManager() { // Initialize internal tables serverRefsMap = new ConcurrentHashMap<ObjID, ServerRef>(); exportedRemotes = Collections .synchronizedMap(new WeakHashMap<Remote, Pair<Remote, ObjID>>()); // Export the Distributed Garbage Collector dgc = new DGCImpl(); ObjID objID = new ObjID(ObjID.DGC_ID); UnicastServerRefImpl sref = new UnicastServerRefImpl(dgc, objID, null); storeExportData(null, objID, sref, null); }
/** * Stores the data generated during object exportation into the * <code>RemoteReferenceManager</code> internal tables * * @param obj * The remote object being exported * @param objID * The <code>ObjID</code> generated for <code>obj</code> * @param sref * The <code>ServerRef</code> generated for <code>obj</code> * @param stub * The stub generated for <code>obj</code> */ public final void storeExportData(Remote obj, ObjID objID, ServerRef sref, Remote stub) { serverRefsMap.put(objID, sref); exportedRemotes.put(obj, new Pair<Remote, ObjID>(stub, objID)); dgc.register(objID, obj); }