static void configureKryoLogging() { // Kryo uses only DEBUG and TRACE levels // we only forward TRACE level, because even DEBUG levels results in // a logging for each object, which is infeasible in Flink. if (LOG.isTraceEnabled()) { com.esotericsoftware.minlog.Log.setLogger(new MinlogForwarder(LOG)); com.esotericsoftware.minlog.Log.TRACE(); } }
public void run () { if (TRACE) trace("kryonet", "Server thread started."); shutdown = false; while (!shutdown) { try { update(250); } catch (IOException ex) { if (ERROR) error("kryonet", "Error updating server connections.", ex); close(); } } if (TRACE) trace("kryonet", "Server thread stopped."); }
public void stop () { if (shutdown) return; close(); if (TRACE) trace("kryonet", "Server thread stopping."); shutdown = true; }
public void close () { try { if (socketChannel != null) { socketChannel.close(); socketChannel = null; if (selectionKey != null) selectionKey.selector().wakeup(); } } catch (IOException ex) { if (DEBUG) debug("kryonet", "Unable to close TCP connection.", ex); } }
public Object read (Kryo kryo, Input input, Class type) { int objectID = input.readInt(true); Connection connection = (Connection)kryo.getContext().get("connection"); Object object = getRegisteredObject(connection, objectID); if (WARN && object == null) warn("kryonet", "Unknown object ID " + objectID + " for connection: " + connection); return object; } });
public void close () { boolean wasConnected = isConnected; isConnected = false; tcp.close(); if (udp != null && udp.connectedAddress != null) udp.close(); if (wasConnected) { notifyDisconnected(); if (INFO) info("kryonet", this + " disconnected."); } setConnected(false); }
public void removeListener (Listener listener) { super.removeListener(listener); if (TRACE) trace("kryonet", "Client listener removed."); }
public void close () { connectedAddress = null; try { if (datagramChannel != null) { datagramChannel.close(); datagramChannel = null; if (selectionKey != null) selectionKey.selector().wakeup(); } } catch (IOException ex) { if (DEBUG) debug("kryonet", "Unable to close UDP connection.", ex); } }
public void addListener (Listener listener) { super.addListener(listener); if (TRACE) trace("kryonet", "Client listener added."); }
public void stop () { if (shutdown) return; close(); if (TRACE) trace("kryonet", "Client thread stopping."); shutdown = true; selector.wakeup(); }
public void removeListener (Listener listener) { if (listener == null) throw new IllegalArgumentException("listener cannot be null."); synchronized (listenerLock) { Listener[] listeners = this.listeners; int n = listeners.length; Listener[] newListeners = new Listener[n - 1]; for (int i = 0, ii = 0; i < n; i++) { Listener copyListener = listeners[i]; if (listener == copyListener) continue; if (ii == n - 1) return; newListeners[ii++] = copyListener; } this.listeners = newListeners; } if (TRACE) trace("kryonet", "Server listener removed: " + listener.getClass().getName()); }
public void removeListener (Listener listener) { if (listener == null) throw new IllegalArgumentException("listener cannot be null."); synchronized (listenerLock) { Listener[] listeners = this.listeners; int n = listeners.length; if (n == 0) return; Listener[] newListeners = new Listener[n - 1]; for (int i = 0, ii = 0; i < n; i++) { Listener copyListener = listeners[i]; if (listener == copyListener) continue; if (ii == n - 1) return; newListeners[ii++] = copyListener; } this.listeners = newListeners; } if (TRACE) trace("kryonet", "Connection listener removed: " + listener.getClass().getName()); }
/** Allows the remote end of the specified connection to access objects registered in this ObjectSpace. */ public void addConnection (Connection connection) { if (connection == null) throw new IllegalArgumentException("connection cannot be null."); synchronized (connectionsLock) { Connection[] newConnections = new Connection[connections.length + 1]; newConnections[0] = connection; System.arraycopy(connections, 0, newConnections, 1, connections.length); connections = newConnections; } connection.addListener(invokeListener); if (TRACE) trace("kryonet", "Added connection to ObjectSpace: " + connection); }
public void addListener (Listener listener) { if (listener == null) throw new IllegalArgumentException("listener cannot be null."); synchronized (listenerLock) { Listener[] listeners = this.listeners; int n = listeners.length; for (int i = 0; i < n; i++) if (listener == listeners[i]) return; Listener[] newListeners = new Listener[n + 1]; newListeners[0] = listener; System.arraycopy(listeners, 0, newListeners, 1, n); this.listeners = newListeners; } if (TRACE) trace("kryonet", "Server listener added: " + listener.getClass().getName()); }
/** Causes this ObjectSpace to stop listening to the connections for method invocation messages. */ public void close () { Connection[] connections = this.connections; for (int i = 0; i < connections.length; i++) connections[i].removeListener(invokeListener); synchronized (instancesLock) { ArrayList<ObjectSpace> temp = new ArrayList(Arrays.asList(instances)); temp.remove(this); instances = temp.toArray(new ObjectSpace[temp.size()]); } if (TRACE) trace("kryonet", "Closed ObjectSpace."); }
/** Removes the specified connection, it will no longer be able to access objects registered in this ObjectSpace. */ public void removeConnection (Connection connection) { if (connection == null) throw new IllegalArgumentException("connection cannot be null."); connection.removeListener(invokeListener); synchronized (connectionsLock) { ArrayList<Connection> temp = new ArrayList(Arrays.asList(connections)); temp.remove(connection); connections = temp.toArray(new Connection[temp.size()]); } if (TRACE) trace("kryonet", "Removed connection from ObjectSpace: " + connection); }
/** 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); }
/** 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 (object != null) objectToID.remove(object, 0); if (TRACE) trace("kryonet", "Object " + objectID + " removed from ObjectSpace: " + object); }
void notifyReceived (Object object) { if (object instanceof Ping) { Ping ping = (Ping)object; if (ping.isReply) { if (ping.id == lastPingID - 1) { returnTripTime = (int)(System.currentTimeMillis() - lastPingSendTime); if (TRACE) trace("kryonet", this + " return trip time: " + returnTripTime); } } else { ping.isReply = true; sendTCP(ping); } } Listener[] listeners = this.listeners; for (int i = 0, n = listeners.length; i < n; i++) listeners[i].received(this, object); }
/** 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); objectToID.remove(object, 0); if (TRACE) trace("kryonet", "Object " + objectID + " removed from ObjectSpace: " + object); }