com.genexus.internet.websocket.GXWebSocketSessionCollection Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gxclassR Show documentation
Show all versions of gxclassR Show documentation
Core classes for the runtime used by Java and Android apps generated with GeneXus
package com.genexus.internet.websocket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
public class GXWebSocketSessionCollection {
private ConcurrentHashMap> clients = new ConcurrentHashMap>();
public void put(GXWebSocketSession ws){
String key = ws.getId();
if (!clients.containsKey(key)){
clients.put(key, Collections.synchronizedList(new ArrayList()) );
}
clients.get(key).remove(ws);
clients.get(key).add(ws);
//System.out.println("New WebSocket " + key + " - " + clients.get(key).size() );
}
public boolean remove(GXWebSocketSession ws){
String key = ws.getId();
Boolean removed = false;
if (clients.containsKey(key)){
removed = clients.get(key).remove(ws);
if (removed && clients.get(key).size() == 0)
clients.remove(key);
}
//System.out.println("Removed websocket" + key + " - " + clients.get(key).size() );
return removed;
}
public List getById(String key){
//System.out.println("getById websocket" + key + " - " + clients.get(key).size() );
return clients.get(key);
}
public List getAll(){
List allWS = new ArrayList();
for (List list : clients.values()){
for (GXWebSocketSession s : list){
allWS.add(s);
}
}
return allWS;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy