All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.genexus.internet.websocket.GXWebSocketSessionCollection Maven / Gradle / Ivy

Go to download

Core classes for the runtime used by Java and Android apps generated with GeneXus

There is a newer version: 4.7.3
Show newest version
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