Пример #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);
   }
 }
Пример #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);
   }
 }
Пример #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);
           }
         });
   }
 }
Пример #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);
   }
 }