Skip to content

Instantly share code, notes, and snippets.

@SpaceManiac
Created May 9, 2011 04:03
Show Gist options
  • Save SpaceManiac/962034 to your computer and use it in GitHub Desktop.
Save SpaceManiac/962034 to your computer and use it in GitHub Desktop.
package net.glowstone.net;
import java.util.ArrayList;
import java.util.List;
/**
* A list of all the sessions which provides a convenient {@link #pulse()}
* method to pulse every session in one operation.
* @author Graham Edgecombe
*/
public final class SessionRegistry {
/**
* A list of the sessions.
*/
private final List<Session> sessions = new ArrayList<Session>();
/**
* Pulses all the sessions.
*/
public void pulse() {
synchronized (sessions) {
for (Session session : sessions) {
session.pulse();
}
}
}
/**
* Adds a new session.
* @param session The session to add.
*/
public void add(Session session) {
synchronized (sessions) {
sessions.add(session);
}
}
/**
* Removes a session.
* @param session The session to remove.
*/
public void remove(Session session) {
synchronized (sessions) {
sessions.remove(session);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment