Code example for CopyOnWriteArraySet

0
 
    private static final long serialVersionUID = 1L;
 
    private static final String GUEST_PREFIX = "Guest";
 
    private final AtomicInteger connectionIds = new AtomicInteger(0);
    private final Set<ChatMessageInbound> connections =
            new CopyOnWriteArraySet<ChatMessageInbound>();
 
    @Override 
    protected StreamInbound createWebSocketInbound(String subProtocol,
            HttpServletRequest request) {
        return new ChatMessageInbound(connectionIds.incrementAndGet());
    } 
 
    private final class ChatMessageInbound extends MessageInbound { 
 
        private final String nickname;
 
        private ChatMessageInbound(int id) {
            this.nickname = GUEST_PREFIX + id;