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


Java ServiceType类代码示例

本文整理汇总了Java中org.apache.curator.x.discovery.ServiceType的典型用法代码示例。如果您正苦于以下问题:Java ServiceType类的具体用法?Java ServiceType怎么用?Java ServiceType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServiceType类属于org.apache.curator.x.discovery包,在下文中一共展示了ServiceType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: registerResource

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
private ServiceInstance<String> registerResource(final RegisteredService registeredService,
                                                 final ServiceDiscovery<String> serviceDiscovery) {
    try {
        UriSpec uriSpec = new UriSpec("{scheme}://{address}:{port}" +
                ResourcePaths.ROOT_PATH +
                registeredService.getVersionedPath());

        ServiceInstance<String> serviceInstance = ServiceInstance.<String>builder()
                .serviceType(ServiceType.DYNAMIC) //==ephemeral zk nodes so instance will disappear if we lose zk conn
                .uriSpec(uriSpec)
                .name(registeredService.getVersionedServiceName(stroomPropertyService))
                .address(advertisedHostNameOrIpAddress)
                .port(advertisedPort)
                .build();

        LOGGER.info("Attempting to register '{}' with service discovery at {}",
                registeredService.getVersionedServiceName(stroomPropertyService), serviceInstance.buildUriSpec());

        Preconditions.checkNotNull(serviceDiscovery).registerService(serviceInstance);

        LOGGER.info("Successfully registered '{}' service.", registeredService.getVersionedServiceName(stroomPropertyService));
        return serviceInstance;
    } catch (Exception e) {
        throw new RuntimeException("Failed to register service " + registeredService.getVersionedServiceName(stroomPropertyService), e);
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:27,代码来源:ServiceDiscoveryRegistrar.java

示例2: getServiceInstance

import org.apache.curator.x.discovery.ServiceType; //导入依赖的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

示例3: configureServiceInstance

import org.apache.curator.x.discovery.ServiceType; //导入依赖的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();
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:27,代码来源:ServiceUtil.java

示例4: registerServerUrls

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
public void registerServerUrls(String serviceName, String[] serverUrls) {
  fixedInstances = new ArrayList<>();
  for (String serverUrl : serverUrls) {
    URL url;
    try {
      url = new URL(serverUrl);
    } catch (MalformedURLException me) {
      throw new ApiConfigException("Server url '" + serverUrl + "' is incorrect.", me);
    }
    boolean ssl = url.getProtocol().equals("https");

    ServiceInstance<Map> serviceInstance = new ServiceInstance<>(
      serviceName,
      UUID.randomUUID().toString(),
      url.getHost(),
      ssl ? null : url.getPort(),
      ssl ? url.getPort() : null,
      new HashMap(),
      System.currentTimeMillis(),
      ServiceType.DYNAMIC,
      new UriSpec());

    fixedInstances.add(serviceInstance);
  }
}
 
开发者ID:tommyxu,项目名称:curator-service-api-client,代码行数:26,代码来源:FixedListServiceInstanceFinder.java

示例5: readInstance

import org.apache.curator.x.discovery.ServiceType; //导入依赖的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();
}
 
开发者ID:apache,项目名称:curator,代码行数:25,代码来源:JsonServiceInstanceMarshaller.java

示例6: checkService

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
private void checkService(String name)
{
    try
    {
        Collection<ServiceInstance<Object>>     instances = discovery.queryForInstances(name);
        for ( ServiceInstance<Object> instance : instances )
        {
            if ( instance.getServiceType() == ServiceType.STATIC )
            {
                if ( (System.currentTimeMillis() - instance.getRegistrationTimeUTC()) > instanceRefreshMs )
                {
                    discovery.unregisterService(instance);
                }
            }
        }
    }
    catch ( Exception e )
    {
        ThreadUtils.checkInterrupted(e);
        log.error(String.format("GC for service: %s", name), e);
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:23,代码来源:InstanceCleanup.java

示例7: OldServiceInstance

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
/**
 * @param name name of the service
 * @param id id of this instance (must be unique)
 * @param address address of this instance
 * @param port the port for this instance or null
 * @param sslPort the SSL port for this instance or null
 * @param payload the payload for this instance or null
 * @param registrationTimeUTC the time (in UTC) of the registration
 * @param serviceType type of the service
 * @param uriSpec the uri spec or null
 */
OldServiceInstance(String name, String id, String address, Integer port, Integer sslPort, T payload, long registrationTimeUTC, ServiceType serviceType, UriSpec uriSpec)
{
    name = Preconditions.checkNotNull(name, "name cannot be null");
    id = Preconditions.checkNotNull(id, "id cannot be null");

    this.serviceType = serviceType;
    this.uriSpec = uriSpec;
    this.name = name;
    this.id = id;
    this.address = address;
    this.port = port;
    this.sslPort = sslPort;
    this.payload = payload;
    this.registrationTimeUTC = registrationTimeUTC;
}
 
开发者ID:apache,项目名称:curator,代码行数:27,代码来源:OldServiceInstance.java

示例8: TestNewServiceInstance

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
public TestNewServiceInstance(String name, String id, String address, Integer port, Integer sslPort, T payload, long registrationTimeUTC, ServiceType serviceType, UriSpec uriSpec, boolean enabled, String new1, Long new2, Date new3, URI new4)
{
    name = Preconditions.checkNotNull(name, "name cannot be null");
    id = Preconditions.checkNotNull(id, "id cannot be null");

    this.new1 = new1;
    this.new2 = new2;
    this.new3 = new3;
    this.new4 = new4;
    this.serviceType = serviceType;
    this.uriSpec = uriSpec;
    this.name = name;
    this.id = id;
    this.address = address;
    this.port = port;
    this.sslPort = sslPort;
    this.payload = payload;
    this.registrationTimeUTC = registrationTimeUTC;
    this.enabled = enabled;
}
 
开发者ID:apache,项目名称:curator,代码行数:21,代码来源:TestNewServiceInstance.java

示例9: testBackwardCompatibility

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
@Test
public void testBackwardCompatibility() throws Exception
{
    JsonInstanceSerializer<TestJsonInstanceSerializer.Payload> serializer = new JsonInstanceSerializer<TestJsonInstanceSerializer.Payload>(TestJsonInstanceSerializer.Payload.class, true, true);
    ServiceInstance<TestJsonInstanceSerializer.Payload> instance = new ServiceInstance<TestJsonInstanceSerializer.Payload>("name", "id", "address", 10, 20, new TestJsonInstanceSerializer.Payload("test"), 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), false);
    byte[] bytes = serializer.serialize(instance);

    instance = serializer.deserialize(bytes);
    Assert.assertTrue(instance.isEnabled());    // passed false for enabled in the ctor but that is lost with compatibleSerializationMode

    ObjectMapper mapper = new ObjectMapper();
    JavaType type = mapper.getTypeFactory().constructType(OldServiceInstance.class);
    OldServiceInstance rawServiceInstance = mapper.readValue(bytes, type);
    TestJsonInstanceSerializer.Payload.class.cast(rawServiceInstance.getPayload()); // just to verify that it's the correct type
    //noinspection unchecked
    OldServiceInstance<TestJsonInstanceSerializer.Payload> check = (OldServiceInstance<TestJsonInstanceSerializer.Payload>)rawServiceInstance;
    Assert.assertEquals(check.getName(), instance.getName());
    Assert.assertEquals(check.getId(), instance.getId());
    Assert.assertEquals(check.getAddress(), instance.getAddress());
    Assert.assertEquals(check.getPort(), instance.getPort());
    Assert.assertEquals(check.getSslPort(), instance.getSslPort());
    Assert.assertEquals(check.getPayload(), instance.getPayload());
    Assert.assertEquals(check.getRegistrationTimeUTC(), instance.getRegistrationTimeUTC());
    Assert.assertEquals(check.getServiceType(), instance.getServiceType());
    Assert.assertEquals(check.getUriSpec(), instance.getUriSpec());
}
 
开发者ID:apache,项目名称:curator,代码行数:27,代码来源:TestJsonInstanceSerializerCompatibility.java

示例10: testForwardCompatibility

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
@Test
public void testForwardCompatibility() throws Exception
{
    OldServiceInstance<TestJsonInstanceSerializer.Payload> oldInstance = new OldServiceInstance<TestJsonInstanceSerializer.Payload>("name", "id", "address", 10, 20, new TestJsonInstanceSerializer.Payload("test"), 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"));
    ObjectMapper mapper = new ObjectMapper();
    byte[] oldJson = mapper.writeValueAsBytes(oldInstance);

    JsonInstanceSerializer<TestJsonInstanceSerializer.Payload> serializer = new JsonInstanceSerializer<TestJsonInstanceSerializer.Payload>(TestJsonInstanceSerializer.Payload.class);
    ServiceInstance<TestJsonInstanceSerializer.Payload> instance = serializer.deserialize(oldJson);
    Assert.assertEquals(oldInstance.getName(), instance.getName());
    Assert.assertEquals(oldInstance.getId(), instance.getId());
    Assert.assertEquals(oldInstance.getAddress(), instance.getAddress());
    Assert.assertEquals(oldInstance.getPort(), instance.getPort());
    Assert.assertEquals(oldInstance.getSslPort(), instance.getSslPort());
    Assert.assertEquals(oldInstance.getPayload(), instance.getPayload());
    Assert.assertEquals(oldInstance.getRegistrationTimeUTC(), instance.getRegistrationTimeUTC());
    Assert.assertEquals(oldInstance.getServiceType(), instance.getServiceType());
    Assert.assertEquals(oldInstance.getUriSpec(), instance.getUriSpec());
    Assert.assertTrue(instance.isEnabled());
}
 
开发者ID:apache,项目名称:curator,代码行数:21,代码来源:TestJsonInstanceSerializerCompatibility.java

示例11: getInputAsSI

import org.apache.curator.x.discovery.ServiceType; //导入依赖的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();

}
 
开发者ID:abbaspour,项目名称:urmia,代码行数:20,代码来源:AdminCommand.java

示例12: testWhoAmI_2instance_sort_Port

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
@Test
public void testWhoAmI_2instance_sort_Port() throws Exception {
    deleteAll(ODS);

    ServiceInstance<NodeType> b1 = ns.builder(ODS, ServiceType.STATIC).id("testWhoAmI_2instance_sort_Port-id1").build();
    ns.add(b1);

    ServiceInstance<NodeType> b2 = ns.builder(ODS, ServiceType.STATIC).id("testWhoAmI_2instance_sort_Port-id2").build();
    ns.add(b2);

    Optional<ServiceInstance<NodeType>> opt = ns.whoAmI(ODS, false);

    assertTrue(opt.isPresent());
    ServiceInstance<NodeType> si = opt.get();

    assertEquals(ODS, si.getPayload());
    assertEquals(b1.getName(), si.getName());
    assertEquals(b1.getId(), si.getId());
    assertEquals(ODS.defaultPort, si.getPort().intValue());

}
 
开发者ID:abbaspour,项目名称:urmia,代码行数:22,代码来源:ZkNamingServiceTest.java

示例13: createServiceDiscovery

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
private void createServiceDiscovery() {
    LOGGER.info("Starting Curator client using Zookeeper at '{}'...", zookeeper);
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
    CuratorFramework client = CuratorFrameworkFactory.newClient(zookeeper, retryPolicy);
    client.start();

    try {
        LOGGER.info("Setting up instance for '{}' service, running on '{}:{}'...", name, ipAddress, port);
        ServiceInstance<String> instance = ServiceInstance.<String>builder()
                .serviceType(ServiceType.PERMANENT)
                .name(name)
                .address(ipAddress)
                .port(port)
                .build();

        ServiceDiscovery serviceDiscovery = ServiceDiscoveryBuilder
                .builder(String.class)
                .client(client)
                .basePath("stroom-services")
                .thisInstance(instance)
                .build();

        serviceDiscovery.start();
        LOGGER.info("Service instance created successfully!");
    } catch (Exception e){
        LOGGER.error("Service instance creation failed! ", e);
    }
}
 
开发者ID:gchq,项目名称:stroom-stats,代码行数:29,代码来源:StroomServiceRegisterer.java

示例14: deserialize

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
@Override
public ServiceInstance<ZookeeperInstance> deserialize(byte[] bytes) throws Exception {
	JsonNode tree = mapper.readTree(bytes);

	String id = tree.get("id").asText();
	String name = tree.get("name").asText();
	String address = tree.get("address").asText();

	Integer port = Optional.ofNullable(tree.get("port"))
			.map(p -> p.asInt())
				.orElse(null);

	Integer sslPort = Optional.ofNullable(tree.get("sslPort"))
			.map(p -> p.asInt())
				.orElse(null);

	long registrationTimeUTC = Optional.ofNullable(tree.get("registrationTimeUTC"))
			.map(r -> r.asLong())
				.orElse(0l);

	ServiceType serviceType = Optional.ofNullable(tree.get("serviceType"))
			.map(s -> ServiceType.valueOf(s.asText()))
				.orElse(null);

	UriSpec uriSpec = Optional.ofNullable(tree.get("uriSpec"))
			.map(u -> new UriSpec(u.asText()))
				.orElse(null);

	JsonNode payload = tree.get("payload");

	ZookeeperInstance zookeeperInstance = Optional.ofNullable(payload)
			.map(p -> Tryable.of(() -> mapper.readValue(p, ZookeeperInstance.class)))
				.orElse(null);

	return new ServiceInstance<>(name, id, address, port, sslPort, zookeeperInstance, registrationTimeUTC,
			serviceType, uriSpec);
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:38,代码来源:ZookeeperInstanceSerializer.java

示例15: registerInstance

import org.apache.curator.x.discovery.ServiceType; //导入依赖的package包/类
@Override
public void registerInstance(String name, String id, String address, Integer port, Integer sslPort, String serviceType, List<String> addressList, Map<String, ?> meta) {

  Map<String, Object> metaData = new HashMap<>(meta == null ? Collections.emptyMap() : meta);
  metaData.put("addressList", addressList);
  metaData.put("serviceType", serviceType);

  ServiceInstance<Map> serviceInstance = new ServiceInstance<>(
    name,
    id,
    address,
    port, sslPort,
    metaData,
    System.currentTimeMillis(),
    ServiceType.DYNAMIC,
    null);

  serviceDiscovery = ServiceDiscoveryBuilder.builder(Map.class)
    .client(curatorFramework)
    .basePath(Constants.SERVICES_PATH)
    .serializer(new ServiceInstanceSerializer<>(Map.class))
    .thisInstance(serviceInstance)
    .build();

  try {
    serviceDiscovery.start();
  } catch (Exception e) {
    throw new RuntimeException("Cannot register service", e);
  }

  log.debug("Service {} registered", name);
}
 
开发者ID:tommyxu,项目名称:curator-service-api-client,代码行数:33,代码来源:ServiceRegisterImpl.java


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