当前位置: 首页>>代码示例>>Java>>正文


Java ServiceInstance.builder方法代码示例

本文整理汇总了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();
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:21,代码来源:TestServiceUtil.java

示例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();
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:10,代码来源:HelloServerConfig.java

示例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();
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:11,代码来源:DrillServiceInstanceHelper.java

示例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();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:11,代码来源:ServiceInstanceHelper.java

示例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();
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:58,代码来源:RpcServerConfiguration.java


注:本文中的org.apache.curator.x.discovery.ServiceInstance.builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。