/** * Looks up a remote object on the server by type and returns a local proxy to the * remote object that was shared on the other end of the network connection. */ public <T> T getRemoteObject( Class<T> type ) { return rmi.getRemoteObject(type); }
/** * Exposes the specified object to the other end of the connection as * the specified interface type. The object can be looked up by type * on the other end. */ public <T> void share( T object, Class<? super T> type ) { share(defaultChannel, object, type); }
/** * Sets up RMI hosting services for the hosted connection allowing * getRmiRegistry() to return a valid RmiRegistry object. * This method is called automatically for all new connections if * autohost is set to true. */ public void startHostingOnConnection( HostedConnection hc ) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "startHostingOnConnection:{0}", hc); } RmiRegistry rmi = new RmiRegistry(hc, rpcService.getRpcConnection(hc), rmiId, defaultChannel); hc.setAttribute(ATTRIBUTE_NAME, rmi); // Register any global shares for( Map.Entry<String, GlobalShare> e : globalShares.entrySet() ) { GlobalShare share = e.getValue(); rmi.share(share.channel, e.getKey(), share.object, share.type); } }
@Override public Object call( RpcConnection conn, short objectId, short procId, Object... args ) { if( objectId == rmiId ) { rmiUpdate(procId, args); return null; } else { return invokeLocal(objectId, procId, args); } } }
/** * Handle remote object registry updates from the other end. */ protected void rmiUpdate( short procId, Object[] args ) { if( log.isLoggable(Level.FINEST) ) { log.finest("rmiUpdate(" + procId + ", " + Arrays.asList(args) + ")"); } switch( procId ) { case NEW_CLASS: addRemoteClass((ClassInfo)args[0]); break; case REMOVE_OBJECT: removeRemoteObject((Short)args[0]); break; case ADD_OBJECT: ClassInfo info = remote.classes.get((Short)args[3]); addRemoteObject((Byte)args[0], (Short)args[1], (String)args[2], info); break; } }
@Override public Object invoke(Object o, Method method, Object[] os) throws Throwable { MethodInfo mi = getMethodInfo(method); if( mi == null ) { // Try to invoke locally return method.invoke(this, os); } return rmi.invokeRemote(channel, objectId, mi.getId(), mi.getCallType(), os); }
/** * Returns a local object that was previously registered with share() using * just type registration. */ public <T> T getLocalObject( Class<T> type ) { return getLocalObject(type.getName(), type); }
@Override protected void onInitialize( ClientServiceManager s ) { rpc = getService(RpcClientService.class); if( rpc == null ) { throw new RuntimeException("RmiClientService requires RpcClientService"); } // Register it now so that it is available when the // server starts to send us stuff. Waiting until start() // is too late in this case. rmi = new RmiRegistry(rpc.getRpcConnection(), rmiObjectId, defaultChannel); }
/** * Handle remote object registry updates from the other end. */ protected void rmiUpdate( short procId, Object[] args ) { if( log.isLoggable(Level.FINEST) ) { log.finest("rmiUpdate(" + procId + ", " + Arrays.asList(args) + ")"); } switch( procId ) { case NEW_CLASS: addRemoteClass((ClassInfo)args[0]); break; case REMOVE_OBJECT: removeRemoteObject((Short)args[0]); break; case ADD_OBJECT: ClassInfo info = remote.classes.get((Short)args[3]); addRemoteObject((Byte)args[0], (Short)args[1], (String)args[2], info); break; } }
@Override public Object call( RpcConnection conn, short objectId, short procId, Object... args ) { if( objectId == rmiId ) { rmiUpdate(procId, args); return null; } else { return invokeLocal(objectId, procId, args); } } }
@Override public Object invoke(Object o, Method method, Object[] os) throws Throwable { MethodInfo mi = getMethodInfo(method); if( mi == null ) { // Try to invoke locally return method.invoke(this, os); } return rmi.invokeRemote(channel, objectId, mi.getId(), mi.getCallType(), os); }
/** * Returns a local object that was previously registered with share() using * just type registration. */ public <T> T getLocalObject( Class<T> type ) { return getLocalObject(type.getName(), type); }
@Override protected void onInitialize( ClientServiceManager s ) { rpc = getService(RpcClientService.class); if( rpc == null ) { throw new RuntimeException("RmiClientService requires RpcClientService"); } // Register it now so that it is available when the // server starts to send us stuff. Waiting until start() // is too late in this case. rmi = new RmiRegistry(rpc.getRpcConnection(), rmiObjectId, defaultChannel); }
/** * Exposes the specified object to the other end of the connection as * the specified interface type and associates it with the specified name. * The object can be looked up by the associated name on the other end of * the connection. */ public <T> void share( String name, T object, Class<? super T> type ) { share(defaultChannel, name, object, type); }
/** * Looks up a remote object on the server by name and returns a local proxy to the * remote object that was shared on the other end of the network connection. */ public <T> T getRemoteObject( String name, Class<T> type ) { return rmi.getRemoteObject(name, type); }
/** * Sets up RMI hosting services for the hosted connection allowing * getRmiRegistry() to return a valid RmiRegistry object. * This method is called automatically for all new connections if * autohost is set to true. */ public void startHostingOnConnection( HostedConnection hc ) { if( log.isLoggable(Level.FINEST) ) { log.log(Level.FINEST, "startHostingOnConnection:{0}", hc); } RmiRegistry rmi = new RmiRegistry(hc, rpcService.getRpcConnection(hc), rmiId, defaultChannel); hc.setAttribute(ATTRIBUTE_NAME, rmi); // Register any global shares for( Map.Entry<String, GlobalShare> e : globalShares.entrySet() ) { GlobalShare share = e.getValue(); rmi.share(share.channel, e.getKey(), share.object, share.type); } }
/** * Exposes, through a specific connection channel, the specified object * to the other end of the connection as the specified interface type. * The object can be looked up by type on the other end. * The specified channel will be used for all network communication * specific to this object. */ public <T> void share( byte channel, T object, Class<? super T> type ) { share(channel, type.getName(), object, type); }
/** * Looks up a remote object by type and returns a local proxy to the remote object * that was shared on the other end of the network connection. If this is called * from a client then it is accessing a shared object registered on the server. * If this is called from the server then it is accessing a shared object registered * on the client. */ public <T> T getRemoteObject( Class<T> type ) { return getRemoteObject(type.getName(), type); }
@Override public void start() { super.start(); // Register all of the classes that have been waiting. synchronized(pending) { for( ObjectInfo info : pending ) { rmi.share(info.channel, info.name, info.object, info.type); } pending.clear(); isStarted = true; } }
/** * Looks up a remote object on the server by name and returns a local proxy to the * remote object that was shared on the other end of the network connection. */ public <T> T getRemoteObject( String name, Class<T> type ) { return rmi.getRemoteObject(name, type); }