本文整理汇总了Java中org.apache.curator.x.discovery.ServiceInstanceBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceInstanceBuilder.build方法的具体用法?Java ServiceInstanceBuilder.build怎么用?Java ServiceInstanceBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.curator.x.discovery.ServiceInstanceBuilder
的用法示例。
在下文中一共展示了ServiceInstanceBuilder.build方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例4: 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();
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8: 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();
}
示例9: 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();
}
示例10: 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();
}
示例11: 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();
}
示例12: 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);
}
}
示例13: deserialize
import org.apache.curator.x.discovery.ServiceInstanceBuilder; //导入方法依赖的package包/类
@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();
}