首页>代码>java实现即时消息提醒方法>/java推送/ConnectionStore.java
/**
 * 文件名: ConnectionStore.java    2012-7-16
 */
package com.gxzy.framework.comm.rtc.store;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.AsyncContext;
import javax.servlet.http.HttpServletRequest;

/**
 * 连接仓库
 * @作者 AMY
 * @版本 1.0
 */
public class ConnectionStore
{
    private static final Map<String, List<AsyncContext>> store = new ConcurrentHashMap<String, List<AsyncContext>>();
    
    //保存用户发送的最后一个rtc请求时间
    private static final Map<String, Date> lastTtcStore = new ConcurrentHashMap<String, Date>();
    
    public static Map<String, List<AsyncContext>> getStore() {
		return store;
	}

	/**
     * 孙雄伟改造支持多个链接
     * 往仓库中放入一个新的连接,改造支持多个链接
     * @param key
     * @param context
     */
    public static void put(String key, AsyncContext context)
    {
    
    	List<AsyncContext> acs = store.get(key);
    	
    	
    	
    	if(acs == null){
    		
    		acs = new ArrayList<AsyncContext>();
    		
    		store.put(key, acs);
    		
    	}
    	
    	acs.add(context);
    	
		//store.put(key, acs);
    	
        //store.put(key, context);
    	//context.getRequest().gets
    	System.out.println("request----------"+((HttpServletRequest)context.getRequest()).getSession().getId());
    	//org.apache.shiro.web.servlet.ShiroHttpServletRequest
    	
    	lastTtcStore.put(key, new Date());
    
    }
    
    /**
     * 是否包含给定主键的连接
     * @param key
     * @return
     */
    public static boolean contain(String key)
    {
        return store.containsKey(key);
    }
    
    /**
     * 返回给定主键的连接,并且将连接从仓库中移除
     * @param key
     * @return
     */
    public static List<AsyncContext> poll(String key)
    {
        if(!store.containsKey(key))
            return null;
        
        List<AsyncContext> context = store.get(key);
        
        store.remove(key);
        
        return context;
    }
    
    /**
     * 删除
     * @param key
     */
    public static void remove(String key)
    {
        if(store.containsKey(key))
            store.remove(key);
    }
}
最近下载更多
zgf099  LV1 2022年9月19日
hanweinan6  LV12 2022年9月16日
Jack261108  LV2 2022年5月6日
hnn0909  LV1 2022年4月2日
lyxtmy  LV1 2022年1月27日
msssg123  LV1 2022年1月25日
ruiqiujuice  LV1 2021年12月21日
密码烟雨城  LV1 2021年12月13日
cyx1314cmx 2021年11月13日
暂无贡献等级
duntmund  LV5 2021年11月2日
最近浏览更多
西瓜哥哥  LV4 2023年12月17日
诚壹lllyz 2023年11月17日
暂无贡献等级
溪若白  LV1 2023年7月13日
Dominick  LV14 2023年6月19日
zzhua195  LV6 2023年5月29日
wuziayng1232  LV10 2023年2月21日
long123_356  LV5 2022年12月10日
BestClever  LV32 2022年12月5日
1358849392  LV21 2022年11月11日
alonely23  LV1 2022年10月20日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友