Java Code Examples for org.apache.curator.x.discovery.ServiceInstanceBuilder#name()
The following examples show how to use
org.apache.curator.x.discovery.ServiceInstanceBuilder#name() .
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: RemoteServiceLocatorConfig.java From springboot-plus with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void addServiceURI(String path, String url) { try{ ServiceInstanceBuilder<Map> service = ServiceInstance.builder(); service.address(""); service.port(0); service.name(path); Map config = new HashMap(); config.put("url", url); service.payload(config); ServiceInstance<Map> instance = service.build(); ServiceDiscovery<Map> serviceDiscovery = ServiceDiscoveryBuilder.builder(Map.class).client(client) .serializer(new JsonInstanceSerializer<Map>(Map.class)).basePath("/service").build(); // 服务注册 serviceDiscovery.registerService(instance); serviceDiscovery.start(); }catch(Exception ex){ log.warn(ex.getMessage(), ex); throw new PlatformException("服务注册中心 出错",ex); } }
Example 2
Source File: JsonServiceInstanceMarshaller.java From curator with Apache License 2.0 | 6 votes |
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(); }
Example 3
Source File: DrillServiceInstanceHelper.java From Bats with Apache License 2.0 | 5 votes |
@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(); }
Example 4
Source File: ServiceInstanceHelper.java From dremio-oss with Apache License 2.0 | 5 votes |
@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(); }
Example 5
Source File: FixedJsonInstanceSerializer.java From incubator-sentry with Apache License 2.0 | 4 votes |
@Override public ServiceInstance<T> deserialize(final byte[] pBytes) throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(pBytes); final JsonNode rootNode = mMapper.readTree(bais); final ServiceInstanceBuilder<T> builder = ServiceInstance.builder(); { final String address = getTextField(rootNode, "address"); if (address != null) { builder.address(address); } } { final String id = getTextField(rootNode, "id"); if (id != null) { builder.id(id); } } { final String name = getTextField(rootNode, "name"); if (name != null) { builder.name(name); } } { final Integer port = getIntegerField(rootNode, "port"); if (port != null) { builder.port(port); } } { final Integer sslPort = getIntegerField(rootNode, "sslPort"); if (sslPort != null) { builder.sslPort(sslPort); } } { final Long registrationTimeUTC = getLongField(rootNode, "registrationTimeUTC"); if (registrationTimeUTC != null) { builder.registrationTimeUTC(registrationTimeUTC); } } { final T payload = getObject(rootNode, "payload", mPayloadClass); if (payload != null) { builder.payload(payload); } } { final ServiceType serviceType = getObject(rootNode, "serviceType", ServiceType.class); if (serviceType != null) { builder.serviceType(serviceType); } } { final UriSpec uriSpec = getObject(rootNode, "uriSpec", UriSpec.class); if (uriSpec != null) { builder.uriSpec(uriSpec); } } return builder.build(); }