本文整理汇总了Java中org.apache.curator.x.discovery.details.InstanceSerializer类的典型用法代码示例。如果您正苦于以下问题:Java InstanceSerializer类的具体用法?Java InstanceSerializer怎么用?Java InstanceSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InstanceSerializer类属于org.apache.curator.x.discovery.details包,在下文中一共展示了InstanceSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildServiceDiscoveryWith
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
private ServiceDiscovery<ZookeeperInstance> buildServiceDiscoveryWith(ZookeeperConfiguration configuration, CuratorFramework curator,
InstanceSerializer<ZookeeperInstance> serializer) {
try {
if (!CuratorFrameworkState.STARTED.equals(curator.getState())) {
curator.start();
}
ServiceDiscovery<ZookeeperInstance> serviceDiscovery = ServiceDiscoveryBuilder.builder(ZookeeperInstance.class)
.client(curator)
.basePath(configuration.root())
.serializer(serializer)
.build();
serviceDiscovery.start();
return serviceDiscovery;
} catch (Exception e) {
throw new ZookeeperServiceDiscoveryException("Error on create Zookeeper ServiceDiscovery", e);
}
}
示例2: init
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
private void init() throws IOException {
try {
haContext.startCuratorFramework();
InstanceSerializer<Void> instanceSerializer = new FixedJsonInstanceSerializer<Void>(Void.class);
serviceDiscovery = ServiceDiscoveryBuilder.<Void>builder(Void.class)
.basePath(HAContext.SENTRY_SERVICE_REGISTER_NAMESPACE)
.serializer(instanceSerializer)
.client(haContext.getCuratorFramework())
.build();
serviceDiscovery.start();
serviceProvider = serviceDiscovery
.serviceProviderBuilder()
.serviceName(HAContext.SENTRY_SERVICE_REGISTER_NAMESPACE)
.build();
serviceProvider.start();
} catch (Exception e) {
throw new IOException(e);
}
}
示例3: regService
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
public void regService(String host, int port) throws Exception {
haContext.startCuratorFramework();
ServiceInstance<Void> serviceInstance = ServiceInstance.<Void>builder()
.address(host)
.port(port)
.name(HAContext.SENTRY_SERVICE_REGISTER_NAMESPACE)
.build();
InstanceSerializer<Void> instanceSerializer = new FixedJsonInstanceSerializer<Void>(Void.class);
ServiceDiscoveryBuilder.builder(Void.class)
.basePath(HAContext.SENTRY_SERVICE_REGISTER_NAMESPACE)
.client(haContext.getCuratorFramework())
.serializer(instanceSerializer)
.thisInstance(serviceInstance)
.build()
.start();
}
示例4: defaultServiceDiscoveryCustomizer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(ServiceDiscoveryCustomizer.class)
public DefaultServiceDiscoveryCustomizer defaultServiceDiscoveryCustomizer(
CuratorFramework curator, ZookeeperDiscoveryProperties properties,
InstanceSerializer<ZookeeperInstance> serializer) {
return new DefaultServiceDiscoveryCustomizer(curator, properties, serializer);
}
开发者ID:spring-cloud,项目名称:spring-cloud-zookeeper,代码行数:8,代码来源:CuratorServiceDiscoveryAutoConfiguration.java
示例5: serverRunner
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
/**
* 这个bean启动后会独占线程,导致其他的bean无法执行。所以必须保证这个bean在最后才能够执行。
* @return
* @throws Exception
*/
@Bean(initMethod = "start", destroyMethod = "stop")
public ServerRunner serverRunner()
throws Exception {
String ip = this.ip;
if (ip == null)
ip = new IpPortResolver().getIpV4Address();
String instanceId = this.ip + ":" + this.port;
CuratorFramework curatorFramework =CuratorFrameworkFactory.builder()
.connectString(this.connectString)
.sessionTimeoutMs(this.sessionTimeoutMs)
.connectionTimeoutMs(this.connectionTimeoutMs)
.retryPolicy(this.retryPolicy())
.aclProvider(this.aclProvider()).authorization(this.authInfo())
.build();
InstanceSerializer<RpcPayload> serializer = new JsonSerializer();
TServerTransport transport = new TServerSocket(this.port);
TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport);
args.transportFactory(new TTransportFactory());
args.protocolFactory(new TBinaryProtocol.Factory());
TProcessor processor= new TProtobufProcessor();
args.processor(processor);
args.executorService(new ThreadPoolExecutor(this.minTheads,
this.maxTheads, this.keepAliveTime, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>()));
TServer server = new TThreadPoolServer(args);
ServiceInstanceBuilder<RpcPayload> instanceBuilder = ServiceInstance
.builder();
instanceBuilder.name(this.serviceName)
.uriSpec(new UriSpec(this.uriSpec)).payload(this.payload())
.port(port).id(instanceId).address(ip);
ServiceDiscoveryBuilder<RpcPayload> discoveryBuilder = ServiceDiscoveryBuilder
.builder(RpcPayload.class);
discoveryBuilder.client(curatorFramework).basePath(zkBasePath)
.serializer(serializer).thisInstance(instanceBuilder.build())
.build();
return ServerRunner
.newBuilder()
.server(server)
.curatorFramework(curatorFramework)
.serviceDiscovery(discoveryBuilder.build())
.zookeeperDeferRegisterPeriod(this.zookeeperDeferRegisterPeriod)
.zookeeperUnregisterPeriod(this.zookeeperUnregisterPeriod).build();
}
示例6: setSerializer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
public void setSerializer(InstanceSerializer<RpcPayload> serializer) {
this.serializer = serializer;
}
示例7: serializer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
public InstanceSerializer<RpcPayload> serializer() {
return new JsonSerializer();
}
示例8: ZookeeperServiceDiscovery
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
public ZookeeperServiceDiscovery(ZookeeperConfiguration configuration, CuratorFramework curator, InstanceSerializer<ZookeeperInstance> serializer) {
this.serviceDiscovery = buildServiceDiscoveryWith(configuration, curator, serializer);
this.curator = curator;
}
示例9: getInstanceSerializer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
public <T> InstanceSerializer<T> getInstanceSerializer(
TypeReference<ServiceInstance<T>> typeReference)
{
return new JacksonInstanceSerializer<T>(objectReader, objectWriter, typeReference);
}
示例10: testSerialization
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
@Test
public void testSerialization() throws Exception
{
ZKAssistedDiscovery discovery = new ZKAssistedDiscovery();
discovery.setServiceName("ApexFlumeTest");
discovery.setConnectionString("localhost:2181");
discovery.setBasePath("/HelloApex");
discovery.setup(null);
ServiceInstance<byte[]> instance = discovery.getInstance(new Service<byte[]>()
{
@Override
public String getHost()
{
return "localhost";
}
@Override
public int getPort()
{
return 8080;
}
@Override
public byte[] getPayload()
{
return null;
}
@Override
public String getId()
{
return "localhost8080";
}
});
InstanceSerializer<byte[]> instanceSerializer =
discovery.getInstanceSerializerFactory().getInstanceSerializer(new TypeReference<ServiceInstance<byte[]>>()
{
});
byte[] serialize = instanceSerializer.serialize(instance);
logger.debug("serialized json = {}", new String(serialize));
ServiceInstance<byte[]> deserialize = instanceSerializer.deserialize(serialize);
assertArrayEquals("Metadata", instance.getPayload(), deserialize.getPayload());
}
示例11: testSerialization
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
@Test
public void testSerialization() throws Exception
{
ZKAssistedDiscovery discovery = new ZKAssistedDiscovery();
discovery.setServiceName("DTFlumeTest");
discovery.setConnectionString("localhost:2181");
discovery.setBasePath("/HelloDT");
discovery.setup(null);
ServiceInstance<byte[]> instance = discovery.getInstance(new Service<byte[]>()
{
@Override
public String getHost()
{
return "localhost";
}
@Override
public int getPort()
{
return 8080;
}
@Override
public byte[] getPayload()
{
return null;
}
@Override
public String getId()
{
return "localhost8080";
}
});
InstanceSerializer<byte[]> instanceSerializer =
discovery.getInstanceSerializerFactory().getInstanceSerializer(new TypeReference<ServiceInstance<byte[]>>()
{
});
byte[] serialize = instanceSerializer.serialize(instance);
logger.debug("serialized json = {}", new String(serialize));
ServiceInstance<byte[]> deserialize = instanceSerializer.deserialize(serialize);
assertArrayEquals("Metadata", instance.getPayload(), deserialize.getPayload());
}
示例12: instanceSerializer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public InstanceSerializer<ZookeeperInstance> instanceSerializer() {
return new JsonInstanceSerializer<>(ZookeeperInstance.class);
}
开发者ID:spring-cloud,项目名称:spring-cloud-zookeeper,代码行数:6,代码来源:ZookeeperServiceRegistryAutoConfiguration.java
示例13: deprecatedInstanceSerializer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public InstanceSerializer<ZookeeperInstance> deprecatedInstanceSerializer() {
return new JsonInstanceSerializer<>(ZookeeperInstance.class);
}
开发者ID:spring-cloud,项目名称:spring-cloud-zookeeper,代码行数:6,代码来源:CuratorServiceDiscoveryAutoConfiguration.java
示例14: DefaultServiceDiscoveryCustomizer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
public DefaultServiceDiscoveryCustomizer(CuratorFramework curator, ZookeeperDiscoveryProperties properties, InstanceSerializer<ZookeeperInstance> instanceSerializer) {
this.curator = curator;
this.properties = properties;
this.instanceSerializer = instanceSerializer;
}
示例15: instanceSerializer
import org.apache.curator.x.discovery.details.InstanceSerializer; //导入依赖的package包/类
@Bean
public InstanceSerializer<ZookeeperInstance> instanceSerializer() {
return new JsonInstanceSerializer<>(ZookeeperInstance.class);
}