Java Code Examples for org.apache.curator.x.discovery.ServiceInstance#getId()

The following examples show how to use org.apache.curator.x.discovery.ServiceInstance#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegistrationHolder.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
static <T> Set<ServiceInstance<T>> filter(
    Set<ServiceInstance<T>> instances,
    Set<RegistrationHolder<ServiceInstance<T>>> registrations) {
  List<ServiceInstance<T>> toRemove = new ArrayList<>();

  for (ServiceInstance<T> instance : instances) {
    String id = instance.getId();
    for (RegistrationHolder<ServiceInstance<T>> holder : registrations) {
      if (holder.svc().getId().equals(id)) {
        toRemove.add(instance);
      }
    }
  }

  instances.removeAll(toRemove);
  return instances;
}
 
Example 2
Source File: ZKClusterCoordinator.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public RegistrationHandle register(DrillbitEndpoint data) {
  try {
    data = data.toBuilder().setState(State.ONLINE).build();
    ServiceInstance<DrillbitEndpoint> serviceInstance = newServiceInstance(data);
    discovery.registerService(serviceInstance);
    return new ZKRegistrationHandle(serviceInstance.getId(),data);
  } catch (Exception e) {
    Throwables.throwIfUnchecked(e);
    throw new RuntimeException(e);
  }
}
 
Example 3
Source File: LeaderInitEventHandler.java    From hermes with Apache License 2.0 5 votes vote down vote up
private Map<String, ClientContext> loadAndAddBrokerListListener(ServiceCacheListener listener) {
	if (listener != null) {
		m_serviceCache.addListener(listener, m_eventBus.getExecutor());
	}
	List<ServiceInstance<Void>> instances = m_serviceCache.getInstances();
	Map<String, ClientContext> brokers = new HashMap<>();
	for (ServiceInstance<Void> instance : instances) {
		String name = instance.getId();
		String ip = instance.getAddress();
		int port = instance.getPort();
		brokers.put(name, new ClientContext(name, ip, port, null, null, m_systemClockService.now()));
	}
	return brokers;
}
 
Example 4
Source File: RegistrationHolder.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
static <T> Set<RegistrationHolder<ServiceInstance<T>>> filter(
    Set<RegistrationHolder<ServiceInstance<T>>> registrations,
    Collection<ServiceInstance<T>> instances) {
  List<RegistrationHolder<ServiceInstance<T>>> toRemove = new ArrayList<>();
  for (RegistrationHolder<ServiceInstance<T>> holder : registrations) {
    for (ServiceInstance<T> instance : instances) {
      String id = instance.getId();
      if (holder.svc().getId().equals(id)) {
        toRemove.add(holder);
      }
    }
  }
  registrations.removeAll(toRemove);
  return registrations;
}
 
Example 5
Source File: ZooKeeperDiscovery.java    From soabase with Apache License 2.0 5 votes vote down vote up
private DiscoveryInstance toSoaInstance(ServiceInstance<Payload> instance)
{
    if ( instance == null )
    {
        return null;
    }

    Payload payload = instance.getPayload();
    int port = Objects.firstNonNull(instance.getPort(), Objects.firstNonNull(instance.getSslPort(), 0));
    return new DiscoveryInstanceImpl(instance.getId(), instance.getAddress(), port, instance.getSslPort() != null, payload);
}
 
Example 6
Source File: JsonInstanceSerializer.java    From curator with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(ServiceInstance<T> instance) throws Exception
{
    if ( compatibleSerializationMode )
    {
        OldServiceInstance<T> compatible = new OldServiceInstance<T>(instance.getName(), instance.getId(), instance.getAddress(), instance.getPort(), instance.getSslPort(), instance.getPayload(), instance.getRegistrationTimeUTC(), instance.getServiceType(), instance.getUriSpec());
        return mapper.writeValueAsBytes(compatible);
    }
    return mapper.writeValueAsBytes(instance);
}
 
Example 7
Source File: CuratorRegistrationSpec.java    From armeria with Apache License 2.0 4 votes vote down vote up
CuratorRegistrationSpec(ServiceInstance<?> serviceInstance) {
    this.serviceInstance = serviceInstance;
    path = '/' + serviceInstance.getName() + '/' + serviceInstance.getId();
}