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


Java JsonInstanceSerializer类代码示例

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


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

示例1: start

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
@Override
public void start() {
  try {
    // 1000ms - initial amount of time to wait between retries
    // 3 times - max number of times to retry
    client = CuratorFrameworkFactory.newClient(getIdentifier().getConnectionString(),
        new ExponentialBackoffRetry(1000, 3));
    client.start();
    client.getZookeeperClient().blockUntilConnectedOrTimedOut();
    cache = TreeCache.newBuilder(client, buildBasePath()).build();
    serializer = new JsonInstanceSerializer<HostMetadata>(HostMetadata.class);

  } catch (Exception e) {
    logger.error("Service registry start error for server identifier '{}' !",
        getIdentifier().getConnectionString(), e);
    throw new ServiceDiscoveryException(e);
  }
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:19,代码来源:ZkServiceDiscovery.java

示例2: ExampleServer

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
public ExampleServer(CuratorFramework client, String path, String serviceName, String description) throws Exception
{
    // in a real application, you'd have a convention of some kind for the URI layout
    UriSpec     uriSpec = new UriSpec("{scheme}://foo.com:{port}");

    thisInstance = ServiceInstance.<InstanceDetails>builder()
        .name(serviceName)
        .payload(new InstanceDetails(description))
        .port((int)(65535 * Math.random())) // in a real application, you'd use a common port
        .uriSpec(uriSpec)
        .build();

    // if you mark your payload class with @JsonRootName the provided JsonInstanceSerializer will work
    JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(InstanceDetails.class);

    serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class)
        .client(client)
        .basePath(path)
        .serializer(serializer)
        .thisInstance(thisInstance)
        .build();
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:23,代码来源:ExampleServer.java

示例3: Server

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
public Server(CuratorFramework client, Instance instance, String basePath) throws Exception
  {
this();
      UriSpec     uriSpec = new UriSpec("{scheme}://"+ instance.getIpAddress() + ":{port}");
      this.basePath = basePath;
      this.thisInstance = ServiceInstance.<Instance>builder()
          .name(instance.getServiceName())
          .payload(instance)
          .port(instance.getPort()) 
          .uriSpec(uriSpec)
          .build();

      JsonInstanceSerializer<Instance> serializer = new JsonInstanceSerializer<Instance>(Instance.class);

      this.serviceDiscovery = ServiceDiscoveryBuilder.builder(Instance.class)
          .client(client)
          .basePath(this.basePath)
          .serializer(serializer)
          .thisInstance(thisInstance)
          .build();
  }
 
开发者ID:cleuton,项目名称:servkeeper,代码行数:22,代码来源:Server.java

示例4: ZookeeperWrapper

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
public ZookeeperWrapper(String zkAddress) throws Exception {
	this.zkAddress = zkAddress;
	this.curatorFramework = 
			CuratorFrameworkFactory.newClient(this.zkAddress, new RetryNTimes(5, 1000));
	curatorFramework.start();

	
       this.serializer = new JsonInstanceSerializer<>(Instance.class);

	this.serviceDiscovery = ServiceDiscoveryBuilder.builder(Instance.class)
			    .basePath(this.BASE_NAME)
			    .serializer(serializer)
			    .client(curatorFramework).build();
	serviceDiscovery.start();
	this.servers = new ArrayList<Server>();
}
 
开发者ID:cleuton,项目名称:servkeeper,代码行数:17,代码来源:ZookeeperWrapper.java

示例5: testBasic

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

    ServiceInstance<String>         rhs = serializer.deserialize(bytes);
    Assert.assertEquals(instance, rhs);
    Assert.assertEquals(instance.getId(), rhs.getId());
    Assert.assertEquals(instance.getName(), rhs.getName());
    Assert.assertEquals(instance.getPayload(), rhs.getPayload());
    Assert.assertEquals(instance.getAddress(), rhs.getAddress());
    Assert.assertEquals(instance.getPort(), rhs.getPort());
    Assert.assertEquals(instance.getSslPort(), rhs.getSslPort());
    Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec());
    Assert.assertEquals(instance.isEnabled(), rhs.isEnabled());
}
 
开发者ID:apache,项目名称:curator,代码行数:19,代码来源:TestJsonInstanceSerializer.java

示例6: testWrongPayloadType

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
@Test
public void     testWrongPayloadType() throws Exception
{
    JsonInstanceSerializer<String>  stringSerializer = new JsonInstanceSerializer<String>(String.class);
    JsonInstanceSerializer<Double>  doubleSerializer = new JsonInstanceSerializer<Double>(Double.class);

    byte[]                          bytes = stringSerializer.serialize(new ServiceInstance<String>("name", "id", "address", 10, 20, "payload", 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), true));
    try
    {
        doubleSerializer.deserialize(bytes);
        Assert.fail();
    }
    catch ( ClassCastException e )
    {
        // correct
    }
}
 
开发者ID:apache,项目名称:curator,代码行数:18,代码来源:TestJsonInstanceSerializer.java

示例7: testNoPayload

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

    ServiceInstance<Void>           rhs = serializer.deserialize(bytes);
    Assert.assertEquals(instance, rhs);
    Assert.assertEquals(instance.getId(), rhs.getId());
    Assert.assertEquals(instance.getName(), rhs.getName());
    Assert.assertEquals(instance.getPayload(), rhs.getPayload());
    Assert.assertEquals(instance.getAddress(), rhs.getAddress());
    Assert.assertEquals(instance.getPort(), rhs.getPort());
    Assert.assertEquals(instance.getSslPort(), rhs.getSslPort());
    Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec());
    Assert.assertEquals(instance.isEnabled(), rhs.isEnabled());
}
 
开发者ID:apache,项目名称:curator,代码行数:19,代码来源:TestJsonInstanceSerializer.java

示例8: UriSpec

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
@Test
public void		testPayloadAsList() throws Exception
{
    JsonInstanceSerializer<Object>    serializer = new JsonInstanceSerializer<Object>(Object.class, false);
    List<String> payload = new ArrayList<String>();
    payload.add("Test value 1");
    payload.add("Test value 2");
    ServiceInstance<Object>           instance = new ServiceInstance<Object>("name", "id", "address", 10, 20, payload, 0, ServiceType.DYNAMIC, new UriSpec("{a}/b/{c}"), false);
    byte[]                            bytes = serializer.serialize(instance);

    ServiceInstance<Object>           rhs = serializer.deserialize(bytes);
    Assert.assertEquals(instance, rhs);
    Assert.assertEquals(instance.getId(), rhs.getId());
    Assert.assertEquals(instance.getName(), rhs.getName());
    Assert.assertEquals(instance.getPayload(), rhs.getPayload());
    Assert.assertEquals(instance.getAddress(), rhs.getAddress());
    Assert.assertEquals(instance.getPort(), rhs.getPort());
    Assert.assertEquals(instance.getSslPort(), rhs.getSslPort());
    Assert.assertEquals(instance.getUriSpec(), rhs.getUriSpec());
    Assert.assertEquals(instance.isEnabled(), rhs.isEnabled());
}
 
开发者ID:apache,项目名称:curator,代码行数:22,代码来源:TestJsonInstanceSerializer.java

示例9: Payload

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

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

示例10: main

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	// This method is scaffolding to get the example up and running
	TestingServer server = new TestingServer();
	CuratorFramework client = null;
	ServiceDiscovery<InstanceDetails> serviceDiscovery = null;
	Map<String, ServiceProvider<InstanceDetails>> providers = Maps.newHashMap();
	try {
		client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(1000, 3));
		client.start();
		JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(InstanceDetails.class);
		serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class).client(client).basePath(PATH).serializer(serializer).build();
		serviceDiscovery.start();
		processCommands(serviceDiscovery, providers, client);
	} finally {
		for (ServiceProvider<InstanceDetails> cache : providers.values()) {
			CloseableUtils.closeQuietly(cache);
		}
		CloseableUtils.closeQuietly(serviceDiscovery);
		CloseableUtils.closeQuietly(client);
		CloseableUtils.closeQuietly(server);
	}
}
 
开发者ID:smallnest,项目名称:ZKRecipesByExample,代码行数:23,代码来源:DiscoveryExample.java

示例11: initServiceDiscovery

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
private void initServiceDiscovery() {
    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<>(MetaData.class);
    discovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build();
    try {
        discovery.start();
        new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());
    } catch (Exception e) {
        log.error("failed to start discovery for {}", basePath, e);
        throw new RuntimeException("failed to start discovery for " + basePath, e);
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:12,代码来源:HostRegister.java

示例12: registerServiceInstance

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
public void registerServiceInstance(String region,
                                    String availabilityZone,
                                    String flavor,
                                    String serviceName,
                                    int servicePort,
                                    String serviceAddress,
                                    String serviceAddressV6,
                                    String weight) throws Exception {
    String regPath = new StringBuilder().append(registrationPath).append("/").append(region).append("/")
            .append(availabilityZone).append("/").append(flavor).toString();

    ServiceInstance<MetaData> service = getServiceInstance(serviceName, servicePort, serviceAddress, new HashMap<String, String>() {{
        put("ipv4Address", serviceAddress);
        put("ipv6Address", serviceAddressV6);
        if (weight != null) {
            put("weight", weight);
        }
    }});

    try {
        JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<>(MetaData.class);
        byte[] bytes = serializer.serialize(service);
        String path = ZKPaths.makePath(ZKPaths.makePath(regPath, service.getName()), service.getId());

        if ( ! connector.isPathExists(path)) {
            connector.createEphemeral(path);
            connector.save(new String(bytes), path);
        } else {
            log.warn("Node " + path + " already exists");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Comcast,项目名称:redirector,代码行数:35,代码来源:TestServiceUtil.java

示例13: getServiceDiscovery

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the discovery
 * @throws Exception the exception
 */
protected static ServiceDiscovery<MetaData> getServiceDiscovery(CuratorFramework curatorFramework, String basePath)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build(); // Service Discovery
    serviceDiscovery.start();

    return serviceDiscovery;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:20,代码来源:ServiceUtil.java

示例14: getServiceCacheBuilder

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the ServiceCacheBuilder
 * @throws Exception the exception
 */
protected static ServiceDiscovery<MetaData> getServiceCacheBuilder(CuratorFramework curatorFramework, String basePath)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = ServiceDiscoveryBuilder.builder(MetaData.class).client(curatorFramework).basePath(basePath).serializer(serializer).build(); // Service Discovery
    serviceDiscovery.start();

    return serviceDiscovery;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:20,代码来源:ServiceUtil.java

示例15: getServiceProvider

import org.apache.curator.x.discovery.details.JsonInstanceSerializer; //导入依赖的package包/类
/**
 * Gets the discovery.
 *
 * @param basePath         - Registration path
 * @param curatorFramework - Curator
 * @return the ServiceProvider
 * @throws Exception the exception
 */
protected static ServiceProvider<MetaData> getServiceProvider(CuratorFramework curatorFramework, String basePath, String serviceName)
        throws Exception {

    new EnsurePath(basePath).ensure(curatorFramework.getZookeeperClient());

    JsonInstanceSerializer<MetaData> serializer = new JsonInstanceSerializer<MetaData>(MetaData.class); // Payload Serializer
    ServiceDiscovery<MetaData> serviceDiscovery = getServiceDiscovery(curatorFramework, basePath);
    ServiceProvider<MetaData> serviceProvider = serviceDiscovery.serviceProviderBuilder().serviceName(serviceName).build(); // Service Provider for a particular service
    serviceProvider.start();

    return serviceProvider;
}
 
开发者ID:Microsoft,项目名称:Availability-Monitor-for-Kafka,代码行数:21,代码来源:ServiceUtil.java


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