Search in sources :

Example 1 with VersionObject

use of com.zx.sms.common.storedMap.VersionObject in project SMSGate by Lihuanghe.

the class AbstractEndpointConnector method addChannel.

public synchronized boolean addChannel(Channel ch) {
    int nowConnCnt = getConnectionNum();
    EndpointEntity endpoint = getEndpointEntity();
    if (endpoint.getMaxChannels() == 0 || endpoint.getMaxChannels() > nowConnCnt) {
        ConcurrentMap<Serializable, VersionObject> storedMap = null;
        if (endpoint.isReSendFailMsg()) {
            // 如果上次发送失败的消息要重发一次,则要创建持久化Map用于存储发送的message
            storedMap = BDBStoredMapFactoryImpl.INS.buildMap(endpoint.getId(), "Session_" + endpoint.getId());
        } else {
            storedMap = new ConcurrentHashMap();
        }
        logger.info("Channel added To Endpoint {} .totalCnt:{} ,remoteAddress: {}", endpoint, nowConnCnt + 1, ch.remoteAddress());
        if (nowConnCnt == 0 && endpoint.isReSendFailMsg()) {
            // 如果是第一个连接。要把上次发送失败的消息取出,再次发送一次
            ch.pipeline().addAfter(GlobalConstance.codecName, sessionHandler, createSessionManager(endpoint, storedMap, true));
        } else {
            ch.pipeline().addAfter(GlobalConstance.codecName, sessionHandler, createSessionManager(endpoint, storedMap, false));
        }
        // 增加流量整形 ,每个连接每秒发送,接收消息数不超过配置的值
        ch.pipeline().addAfter(GlobalConstance.codecName, "ChannelTrafficAfter", new MessageChannelTrafficShapingHandler(endpoint.getWriteLimit(), endpoint.getReadLimit(), 250));
        bindHandler(ch.pipeline(), getEndpointEntity());
        /* 所有的handler都已加入pipeliner后再标识连接已建立,
			 * 如过早加入connector,遇到有消息发送时,可能业务handler还未加入,
			 * 引起消息未经handler处理就发了出去。
			 */
        ch.attr(GlobalConstance.attributeKey).set(SessionState.Connect);
        getChannels().add(ch);
        return true;
    } else {
        logger.warn("allowed max channel count: {} ,deny to login.{}", endpoint.getMaxChannels(), endpoint);
        return false;
    }
}
Also used : VersionObject(com.zx.sms.common.storedMap.VersionObject) Serializable(java.io.Serializable) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CMPPServerEndpointEntity(com.zx.sms.connect.manager.cmpp.CMPPServerEndpointEntity)

Example 2 with VersionObject

use of com.zx.sms.common.storedMap.VersionObject in project SMSGate by Lihuanghe.

the class TestLevelDBQuque method teststoreMap.

public void teststoreMap() {
    Map<Serializable, VersionObject> map = BDBStoredMapFactoryImpl.INS.buildMap("abc", "abc");
    // Use the db in here....
    long start = System.currentTimeMillis();
    int i = 10000;
    long l = 0;
    while (i-- > 0) {
        map.put(l++, new VersionObject(new CmppActiveTestRequestMessage()));
    }
    System.out.println("teststoreMap");
    System.out.println(System.currentTimeMillis() - start);
}
Also used : VersionObject(com.zx.sms.common.storedMap.VersionObject) Serializable(java.io.Serializable) CmppActiveTestRequestMessage(com.zx.sms.codec.cmpp.msg.CmppActiveTestRequestMessage)

Aggregations

VersionObject (com.zx.sms.common.storedMap.VersionObject)2 Serializable (java.io.Serializable)2 CmppActiveTestRequestMessage (com.zx.sms.codec.cmpp.msg.CmppActiveTestRequestMessage)1 CMPPServerEndpointEntity (com.zx.sms.connect.manager.cmpp.CMPPServerEndpointEntity)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1