本文整理汇总了Java中org.apache.curator.x.discovery.ServiceInstanceBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ServiceInstanceBuilder类的具体用法?Java ServiceInstanceBuilder怎么用?Java ServiceInstanceBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServiceInstanceBuilder类属于org.apache.curator.x.discovery包,在下文中一共展示了ServiceInstanceBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServiceInstance
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的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: deserialize
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
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();
}
示例3: register
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
public void register(ZookeeperInstance zookeeperInstance) {
try {
ServiceInstanceBuilder<ZookeeperInstance> builder = ServiceInstance.builder();
ServiceInstance<ZookeeperInstance> instance = builder.name(zookeeperInstance.name())
.payload(zookeeperInstance)
.address(zookeeperInstance.address())
.port(zookeeperInstance.port())
.uriSpec(new UriSpec("{scheme}://{address}:{port}"))
.build();
serviceDiscovery.registerService(instance);
} catch (Exception e) {
throw new ZookeeperServiceDiscoveryException("Exception on register Zookeeper service instance [" + zookeeperInstance + "]" , e);
}
}
示例4: configureServiceInstance
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
/**
* Gets the single instance of RegistrationClient.
*
* @return single instance of RegistrationClient
* @throws Exception the exception
*/
protected static ServiceInstance<MetaData> configureServiceInstance(
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();
}
示例5: buildInstance
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
private ServiceInstance<Payload> buildInstance(String serviceName, HostAndPort mainPort, Payload payload, String id, String address) throws Exception
{
ServiceInstanceBuilder<Payload> builder = ServiceInstance.<Payload>builder()
.name(serviceName)
.payload(payload)
.address(mainPort.getHostText())
.port(mainPort.getPort())
;
if ( id != null )
{
builder = builder.id(id);
}
if ( address != null )
{
builder = builder.address(address);
}
else if ( bindAddress != null )
{
builder = builder.address(bindAddress);
}
return builder.build();
}
示例6: readInstance
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
static<T> ServiceInstance<T> readInstance(JsonNode node, DiscoveryContext<T> context) throws Exception
{
ServiceInstanceBuilder<T> builder = ServiceInstance.builder();
builder.name(node.get("name").asText());
builder.id(node.get("id").asText());
builder.address(node.get("address").asText());
builder.registrationTimeUTC(node.get("registrationTimeUTC").asLong());
builder.serviceType(ServiceType.valueOf(node.get("serviceType").asText()));
builder.payload(context.unMarshallJson(node.get("payload")));
Integer port = getInteger(node, "port");
Integer sslPort = getInteger(node, "sslPort");
if ( port != null )
{
builder.port(port);
}
if ( sslPort != null )
{
builder.sslPort(sslPort);
}
return builder.build();
}
示例7: getInputAsSI
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
public ServiceInstance<NodeType> getInputAsSI(int registeredCount) throws Exception {
ServiceInstanceBuilder<NodeType> b = ServiceInstance.builder();
b.serviceType(ServiceType.PERMANENT)
.address(getHost())
.name(getType().name())
.id(getId())
.payload(getType())
.port(getPort(registeredCount));
if(getType().uriRequired)
if (!line.hasOption("uri"))
throw new IllegalArgumentException("URI is required for type: " + getType());
else
b.uriSpec(new UriSpec(line.getOptionValue("uri")));
return b.build();
}
示例8: initListenInfo
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
/**
* This must be called before other methods are used.
*
* @param port
* port this instance is listening on
*/
public synchronized void initListenInfo(final int port) {
try {
final Collection<InetAddress> ips = ServiceInstanceBuilder
.getAllLocalIPs();
if (Iterables.size(ips) > 0) {
listenAddress = String.valueOf(Iterables.get(ips, 0))
.substring(1);
LOGGER.debug("Found Local IP Addresses: {}, using {}", ips,
listenAddress);
}
} catch (final SocketException e) {
LOGGER.error("Error getting local IP addresses", e);
}
if (Strings.isNullOrEmpty(listenAddress)) {
LOGGER.debug("Using listenAddress from configuration file");
listenAddress = configuration.getListenAddress();
}
listenPort = port;
}
示例9: serviceInstance
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的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();
}
示例10: deserialize
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的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();
}
示例11: deserialize
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的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();
}
示例12: createInstance
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
private ServiceInstance<ModelEndpoint> createInstance(ModelEndpoint ep) throws Exception {
URL url = new URL(ep.getEndpoint().getUrl());
ServiceInstanceBuilder<ModelEndpoint> builder = ServiceInstance.<ModelEndpoint> builder()
.address(url.getHost())
.id(ep.getContainerId())
.name(ep.getName())
.port(url.getPort())
.registrationTimeUTC(System.currentTimeMillis())
.serviceType(ServiceType.STATIC)
.payload(ep)
;
return builder.build();
}
示例13: meWithId
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
private static ServiceInstance<NodeType> meWithId(ServiceInstance<NodeType> me, String id) throws Exception {
ServiceInstanceBuilder<NodeType> b = ServiceInstance.<NodeType>builder();
b.id(id)
.address(me.getAddress())
.name(me.getName())
.payload(me.getPayload())
.port(me.getPort())
//.sslPort(me.getSslPort())
.serviceType(me.getServiceType())
.uriSpec(me.getUriSpec());
return b.build();
}
示例14: serverRunner
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的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();
}
示例15: setup
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
UnitTestHelper.setJavaLoggingLevel(WebApplicationImpl.class, Level.WARNING);
MockDGAModel.start(8282);
testZkServer = new TestingServer(true);
zookeeperUrl = testZkServer.getConnectString();
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy);
client.start();
context = new Context.Builder()
.with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client)
.build();
MaaSConfig config = ConfigUtil.INSTANCE.read(client, "/metron/maas/config", new MaaSConfig(), MaaSConfig.class);
discoverer = new ServiceDiscoverer(client, config.getServiceRoot());
discoverer.start();
endpointUrl = new URL("http://localhost:8282");
ModelEndpoint endpoint = new ModelEndpoint();
{
endpoint.setName("dga");
endpoint.setContainerId("0");
Endpoint ep = new Endpoint();
ep.setUrl(endpointUrl.toString());
endpoint.setEndpoint(ep);
endpoint.setVersion("1.0");
}
;
ServiceInstanceBuilder<ModelEndpoint> builder = ServiceInstance.<ModelEndpoint>builder()
.address(endpointUrl.getHost())
.id("0")
.name("dga")
.port(endpointUrl.getPort())
.registrationTimeUTC(System.currentTimeMillis())
.serviceType(ServiceType.STATIC)
.payload(endpoint);
final ServiceInstance<ModelEndpoint> instance = builder.build();
discoverer.getServiceDiscovery().registerService(instance);
//wait til the endpoint is installed...
for(int i = 0;i < 10;++i) {
try {
Object o = discoverer.getEndpoint("dga");
if(o != null) {
break;
}
}
catch(Exception e) {
}
Thread.sleep(1000);
}
}