本文整理汇总了Java中com.mpush.api.srd.ServiceNames类的典型用法代码示例。如果您正苦于以下问题:Java ServiceNames类的具体用法?Java ServiceNames怎么用?Java ServiceNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceNames类属于com.mpush.api.srd包,在下文中一共展示了ServiceNames类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import com.mpush.api.srd.ServiceNames; //导入依赖的package包/类
public void start() {
CacheManagerFactory.create().init(); //启动缓冲服务
ServiceDiscovery discovery = ServiceDiscoveryFactory.create();// 启动发现服务
discovery.syncStart();
discovery.subscribe(ServiceNames.CONN_SERVER, new ConnServerNodeListener());
scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
scheduledExecutor.scheduleAtFixedRate(this::refresh, 0, 5, TimeUnit.MINUTES);
}
示例2: refresh
import com.mpush.api.srd.ServiceNames; //导入依赖的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());
}
}
示例3: convert
import com.mpush.api.srd.ServiceNames; //导入依赖的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);
}
示例4: cs
import com.mpush.api.srd.ServiceNames; //导入依赖的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.ServiceNames; //导入依赖的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.ServiceNames; //导入依赖的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: getServers
import com.mpush.api.srd.ServiceNames; //导入依赖的package包/类
public List<ServiceNode> getServers() {
return ServiceDiscoveryFactory.create().lookup(ServiceNames.CONN_SERVER);
}
示例8: getConnectServerList
import com.mpush.api.srd.ServiceNames; //导入依赖的package包/类
public Collection<ServiceNode> getConnectServerList() {
return serviceDiscovery.lookup(ServiceNames.CONN_SERVER);
}