本文整理汇总了Java中org.apache.curator.x.discovery.ServiceInstance.builder方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceInstance.builder方法的具体用法?Java ServiceInstance.builder怎么用?Java ServiceInstance.builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.x.discovery.ServiceInstance
的用法示例。
在下文中一共展示了ServiceInstance.builder方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServiceInstance
import org.apache.curator.x.discovery.ServiceInstance; //导入方法依赖的package包/类
private static ServiceInstance<MetaData> getServiceInstance(
String serviceName,
int servicePort,
String serviceAddress,
Map<String, String> parameters) throws Exception {
ServiceInstanceBuilder<MetaData> builder = ServiceInstance.builder();
// Address is optional. The Curator library will automatically use the IP from the first
// ethernet device
String registerAddress = (serviceAddress == null) ? builder.build().getAddress() : serviceAddress;
MetaData metadata = new MetaData(UUID.randomUUID(), registerAddress, servicePort, serviceName);
metadata.setParameters(parameters);
builder.name(serviceName).payload(metadata).id(registerAddress + ":" +
String.valueOf(servicePort)).serviceType(ServiceType.DYNAMIC).address(registerAddress).port(servicePort);
return builder.build();
}
示例2: serviceInstance
import org.apache.curator.x.discovery.ServiceInstance; //导入方法依赖的package包/类
@Bean(name = "service-instance")
public ServiceInstance<RpcPayload> serviceInstance() throws Exception {
ServiceInstanceBuilder<RpcPayload> instance = ServiceInstance.builder();
instance.name(env.getProperty("rpc.server.service.name"))
.uriSpec(new UriSpec(env.getProperty("rpc.server.uri.spec")))
.payload(this.payload()).port(this.port())
.id(this.instanceId()).address(this.ip());
return instance.build();
}
示例3: deserialize
import org.apache.curator.x.discovery.ServiceInstance; //导入方法依赖的package包/类
@Override
public ServiceInstance<DrillbitEndpoint> deserialize(byte[] bytes) throws Exception {
DrillServiceInstance i = DrillServiceInstance.parseFrom(bytes);
ServiceInstanceBuilder<DrillbitEndpoint> b = ServiceInstance.<DrillbitEndpoint>builder();
b.id(i.getId());
b.name(ExecConstants.SERVICE_NAME);
b.registrationTimeUTC(i.getRegistrationTimeUTC());
b.payload(i.getEndpoint());
return b.build();
}
示例4: deserialize
import org.apache.curator.x.discovery.ServiceInstance; //导入方法依赖的package包/类
@Override
public ServiceInstance<NodeEndpoint> deserialize(byte[] bytes) throws Exception {
DremioServiceInstance i = DremioServiceInstance.parseFrom(bytes);
ServiceInstanceBuilder<NodeEndpoint> b = ServiceInstance.<NodeEndpoint>builder();
b.id(i.getId());
b.name(i.getName());
b.registrationTimeUTC(i.getRegistrationTimeUTC());
b.payload(i.getEndpoint());
return b.build();
}
示例5: serverRunner
import org.apache.curator.x.discovery.ServiceInstance; //导入方法依赖的package包/类
/**
* 这个bean启动后会独占线程,导致其他的bean无法执行。所以必须保证这个bean在最后才能够执行。
* @return
* @throws Exception
*/
@Bean(initMethod = "start", destroyMethod = "stop")
public ServerRunner serverRunner()
throws Exception {
String ip = this.ip;
if (ip == null)
ip = new IpPortResolver().getIpV4Address();
String instanceId = this.ip + ":" + this.port;
CuratorFramework curatorFramework =CuratorFrameworkFactory.builder()
.connectString(this.connectString)
.sessionTimeoutMs(this.sessionTimeoutMs)
.connectionTimeoutMs(this.connectionTimeoutMs)
.retryPolicy(this.retryPolicy())
.aclProvider(this.aclProvider()).authorization(this.authInfo())
.build();
InstanceSerializer<RpcPayload> serializer = new JsonSerializer();
TServerTransport transport = new TServerSocket(this.port);
TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
args.transportFactory(new TTransportFactory());
args.protocolFactory(new TBinaryProtocol.Factory());
TProcessor processor= new TProtobufProcessor();
args.processor(processor);
args.executorService(new ThreadPoolExecutor(this.minTheads,
this.maxTheads, this.keepAliveTime, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>()));
TServer server = new TThreadPoolServer(args);
ServiceInstanceBuilder<RpcPayload> instanceBuilder = ServiceInstance
.builder();
instanceBuilder.name(this.serviceName)
.uriSpec(new UriSpec(this.uriSpec)).payload(this.payload())
.port(port).id(instanceId).address(ip);
ServiceDiscoveryBuilder<RpcPayload> discoveryBuilder = ServiceDiscoveryBuilder
.builder(RpcPayload.class);
discoveryBuilder.client(curatorFramework).basePath(zkBasePath)
.serializer(serializer).thisInstance(instanceBuilder.build())
.build();
return ServerRunner
.newBuilder()
.server(server)
.curatorFramework(curatorFramework)
.serviceDiscovery(discoveryBuilder.build())
.zookeeperDeferRegisterPeriod(this.zookeeperDeferRegisterPeriod)
.zookeeperUnregisterPeriod(this.zookeeperUnregisterPeriod).build();
}