本文整理汇总了Java中com.orbitz.consul.model.catalog.CatalogService.getAddress方法的典型用法代码示例。如果您正苦于以下问题:Java CatalogService.getAddress方法的具体用法?Java CatalogService.getAddress怎么用?Java CatalogService.getAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.orbitz.consul.model.catalog.CatalogService
的用法示例。
在下文中一共展示了CatalogService.getAddress方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: discoverNodes
import com.orbitz.consul.model.catalog.CatalogService; //导入方法依赖的package包/类
@Override
public Collection<DiscoveredNode> discoverNodes() {
Collection<DiscoveredNode> list = new LinkedList<>();
Properties empty = new Properties();
if (this.agentClient != null) {
try {
ConsulResponse<List<CatalogService>> service = this.agentClient.getService(serviceName);
LOG.log(Level.WARNING, "Resolving service: {0}", serviceName);
for (CatalogService s : service.getResponse()) {
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "Found service at: {0}", s.getAddress());
}
Address address = new Address(s.getAddress(), s.getServicePort());
list.add(new SimpleDiscoveredNode(address, empty));
}
if (list.isEmpty()) {
LOG.warning("No consul instances found!");
}
return list;
} catch (Exception e) {
LOG.severe(e.getMessage());
throw ExceptionUtil.rethrow(e);
}
}
return list;
}
示例2: discoverNodes
import com.orbitz.consul.model.catalog.CatalogService; //导入方法依赖的package包/类
/**
* Look in consul for nodes with a given name. Exceptions are not rethrown
* to prevent HazelCast of shutting down. This method returns an empty
* list in case of error. When for example, consul returns to a normal state
* a list of nodes is returned. HazelCast will try to connect to this
* nodes.
*
* @return A Collection of Nodes.
*/
@Override
public Collection<DiscoveryNode> discoverNodes() {
Collection<DiscoveryNode> list = new LinkedList<>();
try {
ConsulResponse<List<CatalogService>> service
= this.getClient().getService(serviceName);
for (CatalogService s : service.getResponse()) {
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "Found service at: {0}", s.getAddress());
}
Address address = new Address(s.getAddress(), s.getServicePort());
list.add(new SimpleDiscoveryNode(address));
}
LOG.log(Level.INFO, "Hazelcast found ''{0}'' instance(s) of ''{1}'' ", new Object[]{list.size(), serviceName});
return list;
} catch (Exception e) {
// The exception is no longer rethrown. When the exception
// arrives in Hazelcast-core, it will stop working totally.
// An empty list is delivered as default. This method will be
// invoked again after a certain time. When consul is available,
// it will answer, otherwise we just retry.
LOG.severe(e.getMessage());
}
return list;
}
示例3: discoverNodes
import com.orbitz.consul.model.catalog.CatalogService; //导入方法依赖的package包/类
@Override
public Iterable<DiscoveryNode> discoverNodes() {
List<DiscoveryNode> toReturn = new ArrayList<DiscoveryNode>();
try {
// discover healthy nodes only? (and its NOT the first invocation...)
if (this.consulHealthyOnly && discoverNodesInvoked) {
List<ServiceHealth> nodes = consulHealthClient.getHealthyServiceInstances(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken)).getResponse();
for (ServiceHealth node : nodes) {
toReturn.add(new SimpleDiscoveryNode(
new Address(node.getService().getAddress(),node.getService().getPort())));
getLogger().info("Discovered healthy node: " + node.getService().getAddress()+":"+node.getService().getPort());
}
// discover all services, regardless of health or this is the first invocation
} else {
ConsulResponse<List<CatalogService>> response = this.consulCatalogClient.getService(consulServiceName, ConsulUtility.getAclToken(this.consulAclToken));
for (CatalogService service : response.getResponse()) {
String discoveredAddress = null;
String rawServiceAddress = service.getServiceAddress();
String rawAddress = service.getAddress();
if (rawServiceAddress != null && !rawServiceAddress.trim().isEmpty()) {
discoveredAddress = rawServiceAddress;
} else if (rawAddress != null && !rawAddress.trim().isEmpty()) {
getLogger().warning("discoverNodes() ServiceAddress was null/blank! " +
"for service: " + service.getServiceName() +
" falling back to Address value");
discoveredAddress = rawAddress;
} else {
getLogger().warning("discoverNodes() could not discover an address, " +
"both ServiceAddress and Address were null/blank! " +
"for service: " + service.getServiceName());
}
toReturn.add(new SimpleDiscoveryNode(
new Address(discoveredAddress, service.getServicePort())));
getLogger().info("Discovered healthy node: " + discoveredAddress+":"+service.getServicePort());
}
}
} catch(Exception e) {
getLogger().severe("discoverNodes() unexpected error: " + e.getMessage(),e);
}
// flag we were invoked
discoverNodesInvoked = true;
return toReturn;
}