/** * Return the current available set of instances <b>IMPORTANT: </b> users * should not hold on to the instance returned. They should always get a fresh list. * * @return all known instances * @throws Exception any errors */ @Override public Collection<ServiceInstance<T>> getAllInstances() throws Exception { return instanceProvider.getInstances(); }
@Override public ServiceInstance<T> getInstance(String id) { return instanceProvider.getInstance(id); } }
/** * Return the current available set of instances <b>IMPORTANT: </b> users * should not hold on to the instance returned. They should always get a fresh list. * * @return all known instances * @throws Exception any errors */ @Override public List<ServiceInstance<T>> getAllInstances() throws Exception { return instanceProvider.getInstances(); }
@Override public ServiceInstance<T> getInstance(String id) { return instanceProvider.getInstance(id); } }
@Override public Collection<ServiceInstance<T>> getAllInstances() throws Exception { return instanceProvider.getInstances(); }
@Override public GroupInstance instance(String groupInstanceId) { String groupName = new GroupInstanceIdBean(groupInstanceId).getGroup(); ServiceInstance<GroupProxy> instance = serviceProviders.getUnchecked(groupName).getInstance(groupInstanceId); if (instance == null) instance = nonCachedInstanceProviders.getUnchecked(groupName).getInstance(groupInstanceId); return ZkServiceInstanceAdaptor.groupInstance(instance); }
@Override public List<ServiceInstance<T>> getInstances() throws Exception { Iterable<ServiceInstance<T>> filtered = Iterables.filter(instanceProvider.getInstances(), predicates); return ImmutableList.copyOf(filtered); }
@Override public UnitInstance instance(String unitInstanceId) { String name = new UnitInstanceIdBean(unitInstanceId).getFullName(); ServiceInstance<UnitProxy> serviceInstance = serviceProviders.getUnchecked(name).getInstance(unitInstanceId); if (serviceInstance == null) serviceInstance = nonCachedInstanceProviders.getUnchecked(name).getInstance(unitInstanceId); return ZkServiceInstanceAdaptor.unitInstance(serviceInstance); }
@Override public List<ServiceInstance<T>> getInstances() throws Exception { Iterable<ServiceInstance<T>> filtered = Iterables.filter(instanceProvider.getInstances(), predicates); return ImmutableList.copyOf(filtered); } }
@Override public ApplicationInstance instance(String nodeId) { String name = NodeIdBean.parse(nodeId).getApplication(); ServiceInstance<NodeStatus> instance = serviceProviders.getUnchecked(name).getInstance(nodeId); if (instance == null) instance = nonCachedInstanceProviders.getUnchecked(name).getInstance(nodeId); return ZkServiceInstanceAdaptor.applicationInstance(instance); }
@Override public ServiceInstance<T> getInstance(InstanceProvider<T> instanceProvider) throws Exception { List<ServiceInstance<T>> instances = instanceProvider.getInstances(); if ( instances.size() == 0 ) { return null; } int thisIndex = random.nextInt(instances.size()); return instances.get(thisIndex); } }
@Override public ServiceInstance<T> getInstance(InstanceProvider<T> instanceProvider) throws Exception { List<ServiceInstance<T>> instances = instanceProvider.getInstances(); if ( instances.size() == 0 ) { return null; } int thisIndex = random.nextInt(instances.size()); return instances.get(thisIndex); } }
@Override public ServiceInstance<T> getInstance(InstanceProvider<T> instanceProvider) throws Exception { List<ServiceInstance<T>> instances = instanceProvider.getInstances(); if ( instances.size() == 0 ) { return null; } int thisIndex = Math.abs(index.getAndIncrement()); return instances.get(thisIndex % instances.size()); } }
@Override public ServiceInstance<T> getInstance(InstanceProvider<T> instanceProvider) throws Exception { List<ServiceInstance<T>> instances = instanceProvider.getInstances(); if ( instances.size() == 0 ) { return null; } int thisIndex = Math.abs(index.getAndIncrement()); return instances.get(thisIndex % instances.size()); } }
@Override public ApplicationInstance firstInstance(String name) { try { Collection<ServiceInstance<NodeStatus>> zkInstances = serviceProviders.get(name).getAllInstances(); if (zkInstances.isEmpty()) zkInstances = nonCachedInstanceProviders.get(name).getInstances(); if (zkInstances.isEmpty()) return null; return ZkServiceInstanceAdaptor.applicationInstance(zkInstances.iterator().next()); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public GroupInstance firstInstance(String name) { try { Collection<ServiceInstance<GroupProxy>> instances = serviceProviders.get(name).getAllInstances(); if (instances.isEmpty()) instances = nonCachedInstanceProviders.get(name).getInstances(); if (instances.isEmpty()) return null; return ZkServiceInstanceAdaptor.groupInstance(instances.iterator().next()); } catch (Throwable e) { throw new RuntimeException(e); } }
@Override public UnitInstance firstInstance(String unitFullName) { try { Collection<ServiceInstance<UnitProxy>> instances = serviceProviders.getUnchecked(unitFullName).getAllInstances(); if (instances.isEmpty()) instances = nonCachedInstanceProviders.get(unitFullName).getInstances(); if (instances.isEmpty()) return null; ServiceInstance<UnitProxy> zkServiceInstance = instances.iterator().next(); return ZkServiceInstanceAdaptor.unitInstance(zkServiceInstance); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public List<GroupInstance> all(String name) { try { List<ServiceInstance<GroupProxy>> instances = serviceProviders.get(name).getAllInstances(); if (instances.isEmpty()) instances = nonCachedInstanceProviders.get(name).getInstances(); List<GroupInstance> groupInstances = new ArrayList<>(); for (ServiceInstance<GroupProxy> instance : instances) { groupInstances.add(ZkServiceInstanceAdaptor.groupInstance(instance)); } return groupInstances; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public List<ApplicationInstance> all(String name) { List<ApplicationInstance> applicationInstanceList = new ArrayList<>(); try { List<ServiceInstance<NodeStatus>> allInstances = serviceProviders.get(name).getAllInstances(); if (allInstances.isEmpty()) { allInstances = nonCachedInstanceProviders.get(name).getInstances(); } for (ServiceInstance<NodeStatus> serviceInstance : allInstances) { applicationInstanceList.add(ZkServiceInstanceAdaptor.applicationInstance(serviceInstance)); } } catch (Exception e) { throw new RuntimeException(e); } return applicationInstanceList; }
@Override public List<UnitInstance> all(String unitFullName) { Collection<ServiceInstance<UnitProxy>> instances; try { instances = serviceProviders.get(unitFullName).getAllInstances(); if (instances.isEmpty()) { instances = nonCachedInstanceProviders.get(unitFullName).getInstances(); } } catch (Exception e) { throw new RuntimeException(e); } List<UnitInstance> unitInstances = new ArrayList<>(); for (ServiceInstance<UnitProxy> instance : instances) { unitInstances.add(ZkServiceInstanceAdaptor.unitInstance(instance)); } return unitInstances; }