/** 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. * @param objectID Must not be Integer.MAX_VALUE. * @see #getRemoteObject(Connection, int, Class...) */ public void register (int objectID, Object object) { if (objectID == Integer.MAX_VALUE) throw new IllegalArgumentException("objectID cannot be Integer.MAX_VALUE."); if (object == null) throw new IllegalArgumentException("object cannot be null."); idToObject.put(objectID, object); objectToID.put(object, objectID); if (TRACE) trace("kryonet", "Object registered with ObjectSpace as " + objectID + ": " + object); }
private void acceptOperation (SocketChannel socketChannel) { Connection connection = newConnection(); connection.initialize(serialization, writeBufferSize, objectBufferSize); connection.endPoint = this; UdpConnection udp = this.udp; if (udp != null) connection.udp = udp; try { SelectionKey selectionKey = connection.tcp.accept(selector, socketChannel); selectionKey.attach(connection); int id = nextConnectionID++; if (nextConnectionID == -1) nextConnectionID = 1; connection.id = id; connection.setConnected(true); connection.addListener(dispatchListener); if (udp == null) addConnection(connection); else pendingConnections.put(id, connection); RegisterTCP registerConnection = new RegisterTCP(); registerConnection.connectionID = id; connection.sendTCP(registerConnection); if (udp == null) connection.notifyConnected(); } catch (IOException ex) { connection.close(); if (DEBUG) debug("kryonet", "Unable to accept TCP connection.", ex); } }
public void putAll (IntMap<V> map) { for (Entry<V> entry : map.entries()) put(entry.key, entry.value); }
public void putAll (IntMap<V> map) { for (Entry<V> entry : map.entries()) put(entry.key, entry.value); }
private void putStash (int key, V value) { if (stashSize == stashCapacity) { // Too many pushes occurred and the stash is full, increase the table size. resize(capacity << 1); put(key, value); return; } // Store key in the stash. int index = capacity + stashSize; keyTable[index] = key; valueTable[index] = value; stashSize++; size++; }
private void putStash (int key, V value) { if (stashSize == stashCapacity) { // Too many pushes occurred and the stash is full, increase the table size. resize(capacity << 1); put(key, value); return; } // Store key in the stash. int index = capacity + stashSize; keyTable[index] = key; valueTable[index] = value; stashSize++; size++; }
private void putStash (int key, V value) { if (stashSize == stashCapacity) { // Too many pushes occurred and the stash is full, increase the table size. resize(capacity << 1); put(key, value); return; } // Store key in the stash. int index = capacity + stashSize; keyTable[index] = key; valueTable[index] = value; stashSize++; size++; }
public void putAll (IntMap<V> map) { for (Entry<V> entry : map.entries()) put(entry.key, entry.value); }
private void putStash (int key, V value) { if (stashSize == stashCapacity) { // Too many pushes occurred and the stash is full, increase the table size. resize(capacity << 1); put(key, value); return; } // Store key in the stash. int index = capacity + stashSize; keyTable[index] = key; valueTable[index] = value; stashSize++; size++; }
/** * 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); } }
/** 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. * @param objectID Must not be Integer.MAX_VALUE. * @see #getRemoteObject(Connection, int, Class...) */ public void register (int objectID, Object object) { if (objectID == Integer.MAX_VALUE) throw new IllegalArgumentException("objectID cannot be Integer.MAX_VALUE."); if (object == null) throw new IllegalArgumentException("object cannot be null."); idToObject.put(objectID, object); objectToID.put(object, objectID); if (TRACE) trace("kryonet", "Object registered with ObjectSpace as " + objectID + ": " + object); }
@Override public Registration register(final Registration registration) { if (null == registration) throw new IllegalArgumentException("Registration cannot be null."); if (registration.getId() != NAME) idToRegistration.put(registration.getId(), registration); classToRegistration.put(registration.getType(), registration); if (registration.getType().isPrimitive()) classToRegistration.put(getWrapperClass(registration.getType()), registration); return registration; }
public Registration register (Registration registration) { if (registration == null) throw new IllegalArgumentException("registration cannot be null."); if (registration.getId() != NAME) { if (TRACE) { trace("kryo", "Register class ID " + registration.getId() + ": " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } idToRegistration.put(registration.getId(), registration); } else if (TRACE) { trace("kryo", "Register class name: " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } classToRegistration.put(registration.getType(), registration); if (registration.getType().isPrimitive()) classToRegistration.put(getWrapperClass(registration.getType()), registration); return registration; }
public Registration register (Registration registration) { if (registration == null) throw new IllegalArgumentException("registration cannot be null."); if (registration.getId() != NAME) { if (TRACE) { trace("kryo", "Register class ID " + registration.getId() + ": " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } idToRegistration.put(registration.getId(), registration); } else if (TRACE) { trace("kryo", "Register class name: " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } classToRegistration.put(registration.getType(), registration); if (registration.getType().isPrimitive()) classToRegistration.put(getWrapperClass(registration.getType()), registration); return registration; }
public Registration register (Registration registration) { if (registration == null) throw new IllegalArgumentException("registration cannot be null."); if (registration.getId() != NAME) { if (TRACE) { trace("kryo", "Register class ID " + registration.getId() + ": " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } idToRegistration.put(registration.getId(), registration); } else if (TRACE) { trace("kryo", "Register class name: " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } classToRegistration.put(registration.getType(), registration); if (registration.getType().isPrimitive()) classToRegistration.put(getWrapperClass(registration.getType()), registration); return registration; }
public Registration register (Registration registration) { if (registration == null) throw new IllegalArgumentException("registration cannot be null."); if (TRACE) { if (registration.getId() == NAME) { trace("kryo", "Register class name: " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } else { trace("kryo", "Register class ID " + registration.getId() + ": " + className(registration.getType()) + " (" + registration.getSerializer().getClass().getName() + ")"); } } classToRegistration.put(registration.getType(), registration); idToRegistration.put(registration.getId(), registration); if (registration.getType().isPrimitive()) classToRegistration.put(getWrapperClass(registration.getType()), registration); return registration; }
protected Registration readName(final Input input) { final int nameId = input.readVarInt(true); if (nameIdToClass == null) nameIdToClass = new IntMap<>(); Class type = nameIdToClass.get(nameId); if (type == null) { // Only read the class name the first time encountered in object graph. final String className = input.readString(); type = getTypeByName(className); if (type == null) { try { type = Class.forName(className, false, kryo.getClassLoader()); } catch (ClassNotFoundException ex) { throw new KryoException("Unable to find class: " + className, ex); } if (nameToClass == null) nameToClass = new ObjectMap<>(); nameToClass.put(className, type); } nameIdToClass.put(nameId, type); } return kryo.getRegistration(type); }
protected Registration readName (Input input) { int nameId = input.readVarInt(true); if (nameIdToClass == null) nameIdToClass = new IntMap(); Class type = nameIdToClass.get(nameId); if (type == null) { // Only read the class name the first time encountered in object graph. String className = input.readString(); type = getTypeByName(className); if (type == null) { try { type = Class.forName(className, false, kryo.getClassLoader()); } catch (ClassNotFoundException ex) { if (WARN) warn("kryo", "Unable to load class " + className + " with kryo's ClassLoader. Retrying with current.."); try { type = Class.forName(className); } catch (ClassNotFoundException e) { throw new KryoException("Unable to find class: " + className, ex); } } if (nameToClass == null) nameToClass = new ObjectMap(); nameToClass.put(className, type); } nameIdToClass.put(nameId, type); if (TRACE) trace("kryo", "Read class name: " + className); } else { if (TRACE) trace("kryo", "Read class name reference " + nameId + ": " + className(type)); } return kryo.getRegistration(type); }
protected Registration readName (Input input) { int nameId = input.readVarInt(true); if (nameIdToClass == null) nameIdToClass = new IntMap(); Class type = nameIdToClass.get(nameId); if (type == null) { // Only read the class name the first time encountered in object graph. String className = input.readString(); type = getTypeByName(className); if (type == null) { try { type = Class.forName(className, false, kryo.getClassLoader()); } catch (ClassNotFoundException ex) { throw new KryoException("Unable to find class: " + className, ex); } if (nameToClass == null) nameToClass = new ObjectMap(); nameToClass.put(className, type); } nameIdToClass.put(nameId, type); if (TRACE) trace("kryo", "Read class name: " + className); } else { if (TRACE) trace("kryo", "Read class name reference " + nameId + ": " + className(type)); } return kryo.getRegistration(type); }
protected Registration readName (Input input) { int nameId = input.readVarInt(true); if (nameIdToClass == null) nameIdToClass = new IntMap(); Class type = nameIdToClass.get(nameId); if (type == null) { // Only read the class name the first time encountered in object graph. String className = input.readString(); if (nameToClass != null) type = nameToClass.get(className); if (type == null) { try { type = Class.forName(className, false, kryo.getClassLoader()); } catch (ClassNotFoundException ex) { throw new KryoException("Unable to find class: " + className, ex); } if (nameToClass == null) nameToClass = new ObjectMap(); nameToClass.put(className, type); } nameIdToClass.put(nameId, type); if (TRACE) trace("kryo", "Read class name: " + className); } else { if (TRACE) trace("kryo", "Read class name reference " + nameId + ": " + className(type)); } return kryo.getRegistration(type); }