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

The following examples show how to use org.apache.curator.x.discovery.ServiceInstance#getAddress() . 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: AbstractTransportPool.java    From jigsaw-payment with Apache License 2.0 6 votes vote down vote up
/**
 * 根据rc的设置来确定创建什么类型的transport;
 *
 * @param instance
 * @return
 */
protected TTransport createNativeTransport(
        ServiceInstance<RpcPayload> instance) {
    TSocket socket = new TSocket(instance.getAddress(), instance.getPort());
    socket.setTimeout(socketTimeout);

    RpcPayload server = instance.getPayload();
    if ((server == null) || (server.getTransport() == null)
            || (server.getTransport().equals("socket"))) {
        return socket;
    } else if ("framed-transport".equals(server.getTransport())) {
        return new TFramedTransport(socket);
    }

    // for default, use TSocket;
    return socket;
}
 
Example 2
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 3
Source File: ZookeeperFetcher.java    From Ratel with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
@Override
public String fetchServiceAddress(String serviceName) throws Exception {
    final ServiceInstance serviceInstance = serviceProviderHandler.getProvider(serviceName).getInstance();

    return serviceInstance == null ? "" : serviceInstance.getAddress();
}
 
Example 4
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 5
Source File: ZooKeeperUpdatingListener.java    From armeria with Apache License 2.0 5 votes vote down vote up
private static ZooKeeperRegistrationSpec curatorSpec(
        ServiceInstance<?> serviceInstance, Server server) {
    final CuratorRegistrationSpecBuilder builder =
            ZooKeeperRegistrationSpec.builderForCurator(serviceInstance.getName());
    builder.serviceId(serviceInstance.getId());
    final String address;
    if (serviceInstance.getAddress() != null) {
        address = serviceInstance.getAddress();
    } else {
        address = defaultAddress(server);
    }
    builder.serviceAddress(address);
    final int port = port(server, SessionProtocol.HTTP, serviceInstance.getPort());
    if (port > 0) {
        builder.port(port);
    }
    final int sslPort = port(server, SessionProtocol.HTTPS, serviceInstance.getSslPort());
    if (sslPort > 0) {
        builder.sslPort(sslPort);
    }
    builder.serviceType(serviceInstance.getServiceType());
    final Object payload = serviceInstance.getPayload();
    if (payload != null) {
        builder.payload(payload);
    }
    return builder.build();
}
 
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: ZookeeperFetcher.java    From Ratel with Apache License 2.0 4 votes vote down vote up
@Override
public String apply(ServiceInstance serviceInstance) {
    return serviceInstance.getAddress();
}