use of io.transport.common.bean.NodeInfo 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);
}
use of io.transport.common.bean.NodeInfo in project transporter by wang4ever.
the class DefaultClusterService method joining.
@Override
public void joining(HostAndPort actorHap) {
// Get the cluster all list matching actorPort, and update it to active
// state.
NodeInfo node = this.clusterNode(false, actorHap);
if (node != null) {
// Update to active state.
node.setIsActive(true);
Map<String, String> nodes = Maps.newHashMap();
nodes.put(node.getId(), node.toString());
// Update node.
this.jedisService.mapPut(config.getCtlClusterNodesPKey(), nodes);
if (logger.isInfoEnabled())
logger.info("Node `{}` is joining the cluster.", actorHap);
} else
logger.warn("Node `{}` is failing to join the cluster, and the matching of the actor node is null.", actorHap);
}
use of io.transport.common.bean.NodeInfo in project transporter by wang4ever.
the class ActorManager method run.
@Override
public void run(ApplicationArguments args) throws Exception {
if (this.started) {
logger.warn("Actor system initialized.");
return;
}
// 1.1 Creating a local actor system.
try {
this._system = ActorSystem.create(conf.getActorSystemName(), conf.getConfig());
// 1.2 Create a local default actor.
this.actorCreate(ActorPath.DEFAULT_ACTOR_NAME);
this.started = true;
if (logger.isInfoEnabled())
logger.info("Actor system initialization successfully.");
} catch (Throwable t) {
throw new AkkaException("Initialization of the actor system has failed.", t);
}
// 2.1 Save cluster node info.
try {
NodeInfo hap = new NodeInfo(conf.getHostname(), conf.getConfiguration().getRpcConfig().getPort(), conf.getConfiguration().getWsConfig().getPort(), conf.getRemote().getPort());
// 初始化加入集群
this.clusterService.initial(hap);
} catch (Exception e) {
throw new AkkaException("Failure to initial the cluster node information.", e);
}
}
use of io.transport.common.bean.NodeInfo in project transporter by wang4ever.
the class DefaultClusterService method clusterNodes.
@Override
public Map<String, NodeInfo> clusterNodes(boolean isActive, HostAndPort actorHap) {
Map<String, NodeInfo> nodes = null;
Map<String, String> nodesAll = this.jedisService.getMap(this.config.getCtlClusterNodesPKey());
if (nodesAll != null) {
nodes = new HashMap<>(64);
for (String hap0 : nodesAll.values()) {
boolean flag = false;
NodeInfo node = JSON.parseObject(hap0, NodeInfo.class);
if (isActive) {
if (node != null && node.getIsActive())
flag = true;
} else
flag = true;
if (flag && (actorHap == null || actorHap != null && this.matchActorNode(node, actorHap)))
nodes.put(node.getId(), node);
}
}
return nodes;
}
use of io.transport.common.bean.NodeInfo in project transporter by wang4ever.
the class DefaultClusterService method leaving.
@Override
public void leaving(HostAndPort actorHap) {
// Get the cluster all list matching actorPort, and then update it to
// inactive state.
NodeInfo node = this.clusterNode(false, actorHap);
if (node != null) {
// Update to inactive state.
node.setIsActive(false);
Map<String, String> nodes = Maps.newHashMap();
nodes.put(node.getId(), node.toString());
// Update node.
this.jedisService.mapPut(config.getCtlClusterNodesPKey(), nodes);
if (logger.isInfoEnabled())
logger.info("Node `{}` has gone away from the removal cluster.", actorHap);
} else
logger.warn("Node `{}` failure to leave the cluster, and the matching of the actor node is null.", actorHap);
}
Aggregations