本文整理匯總了Java中com.mpush.api.srd.ServiceNode類的典型用法代碼示例。如果您正苦於以下問題:Java ServiceNode類的具體用法?Java ServiceNode怎麽用?Java ServiceNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ServiceNode類屬於com.mpush.api.srd包,在下文中一共展示了ServiceNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: refresh
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
/**
* 從zk中獲取可提供服務的機器,並以在線用戶量排序
*/
private void refresh() {
//1.從緩存中拿取可用的長鏈接服務器節點
List<ServiceNode> nodes = discovery.lookup(ServiceNames.CONN_SERVER);
if (nodes.size() > 0) {
//2.對serverNodes可以按某種規則排序,以便實現負載均衡,比如:隨機,輪詢,鏈接數量等
this.serverNodes = nodes
.stream()
.map(this::convert)
.sorted(ServerNode::compareTo)
.collect(Collectors.toList());
}
}
示例2: convert
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
private ServerNode convert(ServiceNode node) {
String public_ip = node.getAttr(ServiceNames.ATTR_PUBLIC_IP);
if (public_ip == null) {
public_ip = node.getHost();
}
long onlineUserNum = getOnlineUserNum(public_ip);
return new ServerNode(public_ip, node.getPort(), onlineUserNum);
}
示例3: removeClient
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
private void removeClient(ServiceNode node) {
if (node != null) {
List<Connection> clients = connections.remove(getHostAndPort(node.getHost(), node.getPort()));
if (clients != null) {
clients.forEach(Connection::close);
}
}
}
示例4: cs
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
public static ServiceNode cs() {
CommonServiceNode node = new CommonServiceNode();
node.setHost(ConfigTools.getConnectServerRegisterIp());
node.setPort(CC.mp.net.connect_server_port);
node.setPersistent(false);
node.setServiceName(ServiceNames.CONN_SERVER);
node.setAttrs(CC.mp.net.connect_server_register_attr);
return node;
}
示例5: ws
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
public static ServiceNode ws() {
CommonServiceNode node = new CommonServiceNode();
node.setHost(ConfigTools.getConnectServerRegisterIp());
node.setPort(CC.mp.net.ws_server_port);
node.setPersistent(false);
node.setServiceName(ServiceNames.WS_SERVER);
//node.addAttr(ATTR_PUBLIC_IP, ConfigTools.getPublicIp());
return node;
}
示例6: gs
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
public static ServiceNode gs() {
CommonServiceNode node = new CommonServiceNode();
node.setHost(ConfigTools.getGatewayServerRegisterIp());
node.setPort(CC.mp.net.gateway_server_port);
node.setPersistent(false);
node.setServiceName(ServiceNames.GATEWAY_SERVER);
return node;
}
示例7: onServiceAdded
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceAdded(String s, ServiceNode serviceNode) {
refresh();
}
示例8: onServiceUpdated
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceUpdated(String s, ServiceNode serviceNode) {
refresh();
}
示例9: onServiceRemoved
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceRemoved(String s, ServiceNode serviceNode) {
refresh();
}
示例10: onServiceAdded
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceAdded(String path, ServiceNode node) {
addConnection(node);
}
示例11: onServiceUpdated
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceUpdated(String path, ServiceNode node) {
addConnection(node);
}
示例12: onServiceRemoved
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceRemoved(String path, ServiceNode node) {
ip_address.remove(node.hostAndPort());
logger.warn("Gateway Server zkNode={} was removed.", node);
}
示例13: addConnection
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
private void addConnection(ServiceNode node) {
ip_address.put(node.hostAndPort(), new InetSocketAddress(node.getHost(), node.getPort()));
}
示例14: onServiceAdded
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceAdded(String path, ServiceNode node) {
asyncAddConnection(node);
}
示例15: onServiceUpdated
import com.mpush.api.srd.ServiceNode; //導入依賴的package包/類
@Override
public void onServiceUpdated(String path, ServiceNode node) {
removeClient(node);
asyncAddConnection(node);
}