Search in sources :

Example 1 with EndpointConnector

use of com.zx.sms.connect.manager.EndpointConnector in project SMSGate by Lihuanghe.

the class ChannelUtil method asyncWriteToEntity.

public static ChannelFuture asyncWriteToEntity(String entity, Object msg) {
    EndpointEntity e = EndpointManager.INS.getEndpointEntity(entity);
    EndpointConnector connector = e.getSingletonConnector();
    return asyncWriteToEntity(connector, msg, null);
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) EndpointEntity(com.zx.sms.connect.manager.EndpointEntity)

Example 2 with EndpointConnector

use of com.zx.sms.connect.manager.EndpointConnector in project SMSGate by Lihuanghe.

the class MessageReceiveHandler method userEventTriggered.

public synchronized void userEventTriggered(final ChannelHandlerContext ctx, Object evt) throws Exception {
    synchronized (lock) {
        if (evt == SessionState.Connect && !inited) {
            EventLoopGroupFactory.INS.submitUnlimitCircleTask(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    long nowcnt = cnt.get();
                    EndpointConnector conn = getEndpointEntity().getSingletonConnector();
                    logger.info("channels : {},Totle Receive Msg Num:{},   speed : {}/s", conn == null ? 0 : conn.getConnectionNum(), nowcnt, (nowcnt - lastNum) / rate);
                    lastNum = nowcnt;
                    return true;
                }
            }, new ExitUnlimitCirclePolicy() {

                @Override
                public boolean notOver(Future future) {
                    inited = getEndpointEntity().getSingletonConnector().getConnectionNum() > 0;
                    return inited;
                }
            }, rate * 1000);
            inited = true;
        }
    }
    ctx.fireUserEventTriggered(evt);
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) ExitUnlimitCirclePolicy(com.zx.sms.connect.manager.ExitUnlimitCirclePolicy) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future)

Example 3 with EndpointConnector

use of com.zx.sms.connect.manager.EndpointConnector in project SMSGate by Lihuanghe.

the class ConnState method printOne.

private String printOne(EndpointEntity e) {
    StringBuilder sb = new StringBuilder();
    EndpointConnector econn = e.getSingletonConnector();
    if (econn == null)
        return "";
    Channel[] carr = econn.getallChannel();
    if (carr != null && carr.length > 0) {
        for (int i = 0; i < carr.length; i++) {
            Channel ch = carr[i];
            SessionStateManager ssm = (SessionStateManager) ch.pipeline().get("sessionStateManager");
            sb.append("\tch[");
            sb.append(ch.localAddress().toString());
            if (e instanceof ServerEndpoint) {
                sb.append("<-");
            } else {
                sb.append("->");
            }
            sb.append(ch.remoteAddress().toString() + "]");
            sb.append("\tWaitting-resp=").append(ssm.getWaittingResp());
            sb.append("\tWriteCount=").append(ssm.getWriteCount());
            sb.append("\tReadCount=").append(ssm.getReadCount());
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) Channel(io.netty.channel.Channel) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint) SessionStateManager(com.zx.sms.session.cmpp.SessionStateManager) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint)

Example 4 with EndpointConnector

use of com.zx.sms.connect.manager.EndpointConnector in project SMSGate by Lihuanghe.

the class AbstractSessionLoginManager method receiveConnectResponseMessage.

/**
 * 状态 0:正确 1:消息结构错 2:非法源地址 3:认证错 4:版本太高 5~ :其他错误
 */
private void receiveConnectResponseMessage(ChannelHandlerContext ctx, Object message) throws Exception {
    int status = validServermsg(message);
    if (status == 0) {
        EndpointConnector conn = entity.getSingletonConnector();
        if (conn.addChannel(ctx.channel())) {
            state = SessionState.Connect;
            // 如果没有超过最大连接数配置,建立连接
            notifyChannelConnected(ctx);
            logger.info("{} login success on channel {}", entity.getId(), ctx.channel());
        } else {
            ctx.close();
            return;
        }
    } else {
        logger.info("{} login failed (status = {}) on channel {}", entity.getId(), status, ctx.channel());
        ctx.close();
        return;
    }
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) ClientEndpoint(com.zx.sms.connect.manager.ClientEndpoint)

Example 5 with EndpointConnector

use of com.zx.sms.connect.manager.EndpointConnector in project SMSGate by Lihuanghe.

the class AbstractSessionLoginManager method channelInactive.

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    Channel ch = ctx.channel();
    if (state == SessionState.Connect) {
        EndpointConnector conn = entity.getSingletonConnector();
        if (conn != null)
            conn.removeChannel(ch);
        logger.warn("Connection closed . {} , connect count : {}", entity, conn == null ? 0 : conn.getConnectionNum());
    } else {
        logger.warn("session is not created. the entity is {}.channel remote is {}", entity, ctx.channel().remoteAddress());
    }
    ctx.fireChannelInactive();
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) Channel(io.netty.channel.Channel)

Aggregations

EndpointConnector (com.zx.sms.connect.manager.EndpointConnector)9 EndpointEntity (com.zx.sms.connect.manager.EndpointEntity)4 ClientEndpoint (com.zx.sms.connect.manager.ClientEndpoint)2 Channel (io.netty.channel.Channel)2 BaseMessage (com.zx.sms.BaseMessage)1 LongSMSMessage (com.zx.sms.LongSMSMessage)1 LongMessageFrame (com.zx.sms.codec.cmpp.wap.LongMessageFrame)1 ExitUnlimitCirclePolicy (com.zx.sms.connect.manager.ExitUnlimitCirclePolicy)1 ServerEndpoint (com.zx.sms.connect.manager.ServerEndpoint)1 SessionStateManager (com.zx.sms.session.cmpp.SessionStateManager)1 ChannelFuture (io.netty.channel.ChannelFuture)1 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)1 Future (io.netty.util.concurrent.Future)1 Promise (io.netty.util.concurrent.Promise)1 ArrayList (java.util.ArrayList)1 SmsMessage (org.marre.sms.SmsMessage)1