Search in sources :

Example 6 with EndpointConnector

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

the class AbstractSessionLoginManager method receiveConnectMessage.

protected void receiveConnectMessage(ChannelHandlerContext ctx, Object message) throws Exception {
    // 通过用户名获取端口信息
    EndpointEntity childentity = queryEndpointEntityByMsg(message);
    // 修改协议版本,使用客户端对应协议的协议解析器
    changeProtoVersion(ctx, childentity, message);
    if (childentity == null) {
        failedLogin(ctx, message, 3);
        return;
    }
    if (!validRemoteAddress(childentity, ctx.channel())) {
        failedLogin(ctx, message, 2);
        return;
    }
    // 服务端收到Request,校验用户名密码成功
    int status = validClientMsg(childentity, message);
    // 认证成功
    if (status == 0) {
        // 打开连接,并把连接加入管理器
        EndpointManager.INS.openEndpoint(childentity);
        // 如果该连接不是此账号的第一个连接,要获取早先第一个生成的entity对象
        EndpointEntity oldEntity = EndpointManager.INS.getEndpointEntity(childentity.getId());
        // 绑定端口为对应账号的端口
        entity = oldEntity;
        // 端口已打开,获取连接器
        EndpointConnector conn = oldEntity.getSingletonConnector();
        // 检查是否超过最大连接数
        if (conn.addChannel(ctx.channel())) {
            IdleStateHandler idlehandler = (IdleStateHandler) ctx.pipeline().get(GlobalConstance.IdleCheckerHandlerName);
            ctx.pipeline().replace(idlehandler, GlobalConstance.IdleCheckerHandlerName, new IdleStateHandler(0, 0, oldEntity.getIdleTimeSec(), TimeUnit.SECONDS));
            state = SessionState.Connect;
            // channelHandler已绑定完成,给客户端发resp.
            doLoginSuccess(ctx, oldEntity, message);
            // 通知业务handler连接已建立完成
            notifyChannelConnected(ctx);
            logger.info("{} login success on channel {}", oldEntity.getId(), ctx.channel());
        } else {
            // 超过最大连接数了
            failedLogin(ctx, message, 5);
        }
    } else {
        failedLogin(ctx, message, status);
    }
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) ClientEndpoint(com.zx.sms.connect.manager.ClientEndpoint) EndpointEntity(com.zx.sms.connect.manager.EndpointEntity)

Example 7 with EndpointConnector

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

the class ChannelUtil method asyncWriteToEntity.

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

Example 8 with EndpointConnector

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

the class ChannelUtil method syncWriteBinaryMsgToEntity.

/**
 * 同步发送消息类型 <br/>
 * 注意:该方法将直接发送至编码器,不会再调用BusinessHandler里的write方法了。
 * 因此对于Deliver和Submit消息必须自己进行长短信拆分,设置PDU等相关字段
 *一般此方法用来发送二进制短信等特殊短信,需要自己生成短信的二进制内容。
 *正常短信下发要使用 syncWriteLongMsgToEntity 方法
 */
public static <T extends BaseMessage> Promise<T> syncWriteBinaryMsgToEntity(String entity, BaseMessage msg) throws Exception {
    EndpointEntity e = EndpointManager.INS.getEndpointEntity(entity);
    EndpointConnector connector = e.getSingletonConnector();
    Promise<T> promise = connector.synwrite(msg);
    if (promise == null) {
        // 为空,可能是连接断了,直接返回
        return null;
    }
    return promise;
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) EndpointEntity(com.zx.sms.connect.manager.EndpointEntity)

Example 9 with EndpointConnector

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

the class ChannelUtil method syncWriteLongMsgToEntity.

public static <T extends BaseMessage> List<Promise<T>> syncWriteLongMsgToEntity(EndpointEntity e, BaseMessage msg) throws Exception {
    EndpointConnector connector = e.getSingletonConnector();
    if (connector == null)
        return null;
    if (msg instanceof LongSMSMessage) {
        LongSMSMessage<BaseMessage> lmsg = (LongSMSMessage<BaseMessage>) msg;
        if (!lmsg.isReport()) {
            // 长短信拆分
            SmsMessage msgcontent = lmsg.getSmsMessage();
            List<LongMessageFrame> frameList = LongMessageFrameHolder.INS.splitmsgcontent(msgcontent);
            // 保证同一条长短信,通过同一个tcp连接发送
            List<BaseMessage> msgs = new ArrayList<BaseMessage>();
            for (LongMessageFrame frame : frameList) {
                BaseMessage basemsg = (BaseMessage) lmsg.generateMessage(frame);
                msgs.add(basemsg);
            }
            return connector.synwrite(msgs);
        }
    }
    Promise promise = connector.synwrite(msg);
    if (promise == null) {
        // 为空,可能是连接断了,直接返回
        return null;
    }
    List<Promise<T>> arrPromise = new ArrayList<Promise<T>>();
    arrPromise.add(promise);
    return arrPromise;
}
Also used : EndpointConnector(com.zx.sms.connect.manager.EndpointConnector) LongSMSMessage(com.zx.sms.LongSMSMessage) Promise(io.netty.util.concurrent.Promise) SmsMessage(org.marre.sms.SmsMessage) BaseMessage(com.zx.sms.BaseMessage) LongMessageFrame(com.zx.sms.codec.cmpp.wap.LongMessageFrame) ArrayList(java.util.ArrayList)

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