Skip to content

Instantly share code, notes, and snippets.

@patelm5
Last active December 11, 2015 02:38
Show Gist options
  • Save patelm5/4531571 to your computer and use it in GitHub Desktop.
Save patelm5/4531571 to your computer and use it in GitHub Desktop.
Simple Broadcast Service for Atmosphere.
@Service
public class BroadcastService {
private final static Logger logger = Logger.getLogger(BroadcastService.class.getName());
private Map<String, Broadcaster> broadcastTokens = new ConcurrentHashMap<String, Broadcaster>();
public void broadcast(String message) {
for (Broadcaster token : broadcastTokens.values()) {
token.broadcast(message);
logger.info("Broadcasting message:"+message);
}
}
public void addBroadcastToken(String channel, Broadcaster token) {
broadcastTokens.put(channel, token);
}
public void destroyBroadcastToken(String channel) {
Broadcaster token = broadcastTokens.get(channel);
if (token != null) {
token.destroy();
broadcastTokens.remove(channel);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment