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

io.baltoro.remote.api.ClientPool Maven / Gradle / Ivy

There is a newer version: 4.0.12
Show newest version
package io.baltoro.remote.api;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

public class ClientPool
{
	
	static Log log = LogFactory.getLog(ClientPool.class);
	
	private static ClientPool threadMap;
	private Map> map;
	
	
	private ClientPool()
    {
		map = new HashMap>(1000);
    }
	
	public static ClientPool getInstance()
	{
		if(threadMap == null)
		{
			synchronized ("1".intern())
            {
				if(threadMap == null)
				{
					threadMap = new  ClientPool();
				}
            }
		}
		
		return threadMap;
	}
	
	
	public Map> getAllRequestQueues() 
	{
		return map;
	}

	public ConcurrentLinkedQueue getRequestQueue(String mbSessionId)
	{
		ConcurrentLinkedQueue pollingQueue = map.get(mbSessionId);
		if(pollingQueue != null)
		{
			return pollingQueue;
		}
		
			
		if(pollingQueue == null)
		{
			synchronized (mbSessionId.intern())
            {
            	pollingQueue = map.get(mbSessionId);
            	if(pollingQueue == null)
            	{
            		pollingQueue = new ConcurrentLinkedQueue();
            		map.put(mbSessionId, pollingQueue);
            	}
                
            }
		}
		
		return pollingQueue;
	}
	
	public void clearRequestQueue(String mbSessionId)
	{
		map.remove(mbSessionId);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy