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

The following examples show how to use org.apache.curator.x.discovery.ServiceInstance#getPort() . 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: JsonObjectSerializer.java    From vertx-service-discovery with Apache License 2.0 6 votes vote down vote up
public ServiceInstance<JsonObject> deserialize(byte[] bytes) throws Exception {
  ServiceInstance rawServiceInstance = this.mapper.readValue(bytes, this.type);
  ServiceInstanceBuilder<JsonObject> builder = ServiceInstance.<JsonObject>builder()
      .address(rawServiceInstance.getAddress())
      .id(rawServiceInstance.getId())
      .name(rawServiceInstance.getName())
      .payload(new JsonObject(rawServiceInstance.getPayload().toString()))
      .registrationTimeUTC(rawServiceInstance.getRegistrationTimeUTC())
      .serviceType(rawServiceInstance.getServiceType());

  if (rawServiceInstance.getSslPort() != null) {
    builder.sslPort(rawServiceInstance.getSslPort());
  }
  if (rawServiceInstance.getPort() != null) {
    builder.sslPort(rawServiceInstance.getPort());
  }
  if (rawServiceInstance.getUriSpec() != null) {
    builder.uriSpec(rawServiceInstance.getUriSpec());
  }
  return builder.build();
}
 
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: 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);
}