Class ConnectionGroup
java.lang.Object
me.tamkungz.signals.connection.ConnectionGroup
- All Implemented Interfaces:
Connection
Tracks many connections and disconnects them all at once, for example when a plugin disables.
Connections added after the group was disconnected are disconnected immediately.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T extends Connection>
Tadd(T connection) Tracks a connection.static ConnectionGroupcreate()Creates an empty group.voidDisconnects every tracked connection and stops accepting new ones.booleanTells whether this connection is still active.static ConnectionGroupof(Connection... connections) Creates a group that tracks the given connections.intsize()Returns how many connections the group currently tracks.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Connection
close
-
Constructor Details
-
ConnectionGroup
public ConnectionGroup()
-
-
Method Details
-
create
-
of
Creates a group that tracks the given connections.- Parameters:
connections- connections to track, none of them may benull- Returns:
- a new, connected group
-
add
Tracks a connection. If the group is already disconnected, the connection is disconnected right away.- Type Parameters:
T- connection type- Parameters:
connection- connection to track- Returns:
- the same connection
-
size
public int size()Returns how many connections the group currently tracks.Connections that were disconnected on their own are dropped as the group grows, so this can include a few that are no longer connected.
- Returns:
- number of tracked connections
-
disconnect
public void disconnect()Disconnects every tracked connection and stops accepting new ones.A connection that fails to disconnect does not stop the rest; the first failure is rethrown afterwards with the others attached as suppressed exceptions.
- Specified by:
disconnectin interfaceConnection
-
isConnected
public boolean isConnected()Description copied from interface:ConnectionTells whether this connection is still active.- Specified by:
isConnectedin interfaceConnection- Returns:
trueuntilConnection.disconnect()has been called
-