Ejemplo n.º 1
0
 /**
  * Removes an object. The remote end of the ObjectSpace's connections will no longer be able to
  * access it.
  */
 public void remove(Object object) {
   if (!idToObject.containsValue(object, true)) {
     return;
   }
   int objectID = idToObject.findKey(object, true, -1);
   idToObject.remove(objectID);
   if (TRACE) {
     trace("kryonet", "Object " + objectID + " removed from ObjectSpace: " + object);
   }
 }
Ejemplo n.º 2
0
 /**
  * Registers an object to allow the remote end of the ObjectSpace's connections to access it using
  * the specified ID.
  *
  * <p>If a connection is added to multiple ObjectSpaces, the same object ID should not be
  * registered in more than one of those ObjectSpaces.
  *
  * @see #getRemoteObject(Connection, int, Class...)
  */
 public void register(int objectID, Object object) {
   if (object == null) {
     throw new IllegalArgumentException("object cannot be null.");
   }
   idToObject.put(objectID, object);
   if (TRACE) {
     trace("kryonet", "Object registered with ObjectSpace as " + objectID + ": " + object);
   }
 }
Ejemplo n.º 3
0
 @Override
 public void received(final Connection connection, Object object) {
   if (!(object instanceof InvokeMethod)) {
     return;
   }
   if (connections != null) {
     int i = 0, n = connections.length;
     for (; i < n; i++) {
       if (connection == connections[i]) {
         break;
       }
     }
     if (i == n) {
       return; // The InvokeMethod message is not for a connection in this ObjectSpace.
     }
   }
   final InvokeMethod invokeMethod = (InvokeMethod) object;
   final Object target = idToObject.get(invokeMethod.objectID);
   if (target == null) {
     if (WARN) {
       warn(
           "kryonet",
           "Ignoring remote invocation request for unknown object ID: "
               + invokeMethod.objectID);
     }
     return;
   }
   if (executor == null) {
     invoke(connection, target, invokeMethod);
   } else {
     executor.execute(
         new Runnable() {
           @Override
           public void run() {
             invoke(connection, target, invokeMethod);
           }
         });
   }
 }
Ejemplo n.º 4
0
 /**
  * Removes an object. The remote end of the ObjectSpace's connections will no longer be able to
  * access it.
  */
 public void remove(int objectID) {
   Object object = idToObject.remove(objectID);
   if (TRACE) {
     trace("kryonet", "Object " + objectID + " removed from ObjectSpace: " + object);
   }
 }