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


Java ServiceType.DYNAMIC属性代码示例

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


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

示例1: registerServerUrls

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,代码行数:25,代码来源:FixedListServiceInstanceFinder.java

示例2: testBackwardCompatibility

@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,代码行数:26,代码来源:TestJsonInstanceSerializerCompatibility.java

示例3: testForwardCompatibility

@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,代码行数:20,代码来源:TestJsonInstanceSerializerCompatibility.java

示例4: registerInstance

@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,代码行数:32,代码来源:ServiceRegisterImpl.java

示例5: testCompatibilityMode

@Test
public void testCompatibilityMode() 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}"), true);
    byte[] bytes = serializer.serialize(instance);

    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[] oldBytes = mapper.writeValueAsBytes(oldInstance);
    Assert.assertEquals(bytes, oldBytes, String.format("%s vs %s", new String(bytes), new String(oldBytes)));
}
 
开发者ID:apache,项目名称:curator,代码行数:12,代码来源:TestJsonInstanceSerializerCompatibility.java

示例6: testFutureChanges

@Test
public void testFutureChanges() throws Exception
{
    TestNewServiceInstance<String> newInstance = new TestNewServiceInstance<String>("name", "id", "address", 10, 20, "hey", 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), false, "what", 10101L, new Date(), new URI("http://hey"));
    byte[] newInstanceBytes = new ObjectMapper().writeValueAsBytes(newInstance);
    JsonInstanceSerializer<String> serializer = new JsonInstanceSerializer<String>(String.class);
    ServiceInstance<String> instance = serializer.deserialize(newInstanceBytes);
    Assert.assertEquals(instance.getName(), "name");
    Assert.assertEquals(instance.getPayload(), "hey");
    Assert.assertEquals(instance.isEnabled(), false);
}
 
开发者ID:apache,项目名称:curator,代码行数:11,代码来源:TestJsonInstanceSerializerCompatibility.java

示例7: OldServiceInstance

OldServiceInstance()
{
    this("", "", null, null, null, null, 0, ServiceType.DYNAMIC, null);
}
 
开发者ID:apache,项目名称:curator,代码行数:4,代码来源:OldServiceInstance.java

示例8: TestNewServiceInstance

/**
 * Inits to default values. Only exists for deserialization
 */
TestNewServiceInstance()
{
    this("", "", null, null, null, null, 0, ServiceType.DYNAMIC, null, true, null, null, null, null);
}
 
开发者ID:apache,项目名称:curator,代码行数:7,代码来源:TestNewServiceInstance.java


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