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);
}
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);
}
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();
}
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;
}
}
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();
}
Aggregations