use of io.transport.core.protocol.message.internal.ConnectRespMessage in project transporter by wang4ever.
the class AbstractChannelMessageHandler method processAccpetConnect.
/**
* 新建/注册客户端连接处理
*
* @param ctx
* @param msg
*/
protected void processAccpetConnect(ChannelHandlerContext ctx, ConnectMessage msg) {
// 1.0 Check device logged in.
if (this.client == null)
throw new TransportException("No new socket channel(client is null).");
else {
String cliDeviceId = this.client.getDeviceInfo().getDeviceId();
String reqDeviceId = msg.getDeviceInfo().getDeviceId();
// 同一deviceId单点登录控制:当前channel已登录或当前deviceId已有已登录的channel(重复创建了channel)
if (!StringUtils.isEmpty(cliDeviceId) || this.repository.contains(reqDeviceId))
throw new TransportConnectLimitException("Already loggedin. deviceId(client)=" + cliDeviceId + ", deviceId(req)=" + reqDeviceId);
}
//
// 1.1 Check parameter.
msg.validation();
//
// 1.2 Check of appId connections limit.
this.accpetValidation(msg.getAppId());
//
// 2.1 Authentication appId/secret.
this.login(msg);
this.client.setDeviceInfo(msg.getDeviceInfo());
this.repository.putClient(msg.getAppId(), this.client);
if (logger.isInfoEnabled())
logger.info("新建客户端. {}, {}", ctx.channel(), this.client.getDeviceInfo().getDeviceId());
//
// 3.1 Echo result.
ConnectRespMessage resp = new ConnectRespMessage();
// 3.2 Get active cluster node info.
Map<String, NodeInfo> nodes = this.clusterService.clusterNodes(true, null);
if (nodes != null) {
for (NodeInfo node : nodes.values()) {
try {
boolean isWsCh = TransportProcessors.isWSChannel(ctx.channel());
if (isWsCh)
resp.getHostAndPorts().add(node.getHost() + ":" + node.getWsPort());
else
resp.getHostAndPorts().add(node.getHost() + ":" + node.getRpcPort());
} catch (Exception e) {
logger.error("返回节点信息错误.", e);
}
}
}
if (logger.isInfoEnabled())
logger.info("节点列表. {}", resp.getHostAndPorts());
this.echoWrite(ctx, resp);
}
Aggregations