org.apache.curator.x.discovery.details.InstanceSerializer Java Examples

The following examples show how to use org.apache.curator.x.discovery.details.InstanceSerializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServiceManager.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #2
Source File: ServiceRegister.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
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();
  }
 
Example #3
Source File: CuratorServiceDiscoveryAutoConfiguration.java    From spring-cloud-zookeeper with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(ServiceDiscoveryCustomizer.class)
public DefaultServiceDiscoveryCustomizer defaultServiceDiscoveryCustomizer(
		CuratorFramework curator, ZookeeperDiscoveryProperties properties,
		InstanceSerializer<ZookeeperInstance> serializer) {
	return new DefaultServiceDiscoveryCustomizer(curator, properties, serializer);
}
 
Example #4
Source File: DefaultServiceDiscoveryCustomizer.java    From spring-cloud-zookeeper with Apache License 2.0 5 votes vote down vote up
public DefaultServiceDiscoveryCustomizer(CuratorFramework curator,
		ZookeeperDiscoveryProperties properties,
		InstanceSerializer<ZookeeperInstance> instanceSerializer) {
	this.curator = curator;
	this.properties = properties;
	this.instanceSerializer = instanceSerializer;
}
 
Example #5
Source File: ZooKeeperAutoRegistrationCustomizer.java    From Moss with Apache License 2.0 4 votes vote down vote up
public ZooKeeperAutoRegistrationCustomizer(CuratorFramework curator, ZookeeperDiscoveryProperties properties, InstanceSerializer<ZookeeperInstance> serializer) {
    super(curator, properties, serializer);
}
 
Example #6
Source File: ZooKeeperClientAutoConfiguartion.java    From Moss with Apache License 2.0 4 votes vote down vote up
@Bean
public ZooKeeperAutoRegistrationCustomizer zooKeeperAutoRegistrationCustomizer(CuratorFramework curator,
                                                                               ZookeeperDiscoveryProperties properties,
                                                                               InstanceSerializer<ZookeeperInstance> serializer) {
    return new ZooKeeperAutoRegistrationCustomizer(curator, properties, serializer);
}
 
Example #7
Source File: ZooKeeperAutoRegistrationCustomizer.java    From Moss with Apache License 2.0 4 votes vote down vote up
public ZooKeeperAutoRegistrationCustomizer(CuratorFramework curator, ZookeeperDiscoveryProperties properties, InstanceSerializer<ZookeeperInstance> serializer) {
    super(curator, properties, serializer);
}
 
Example #8
Source File: ZooKeeperClientAutoConfiguartion.java    From Moss with Apache License 2.0 4 votes vote down vote up
@Bean
public ZooKeeperAutoRegistrationCustomizer zooKeeperAutoRegistrationCustomizer(CuratorFramework curator,
                                                                               ZookeeperDiscoveryProperties properties,
                                                                               InstanceSerializer<ZookeeperInstance> serializer) {
    return new ZooKeeperAutoRegistrationCustomizer(curator, properties, serializer);
}
 
Example #9
Source File: RpcServerConfiguration.java    From jigsaw-payment with Apache License 2.0 4 votes vote down vote up
/**
 * 这个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();
}
 
Example #10
Source File: RefreshableTransportPool.java    From jigsaw-payment with Apache License 2.0 4 votes vote down vote up
public void setSerializer(InstanceSerializer<RpcPayload> serializer) {
	this.serializer = serializer;
}
 
Example #11
Source File: HelloServerConfig.java    From jigsaw-payment with Apache License 2.0 4 votes vote down vote up
public InstanceSerializer<RpcPayload> serializer() {
	return new JsonSerializer();
}
 
Example #12
Source File: ZKAssistedDiscovery.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public <T> InstanceSerializer<T> getInstanceSerializer(
    TypeReference<ServiceInstance<T>> typeReference)
{
  return new JacksonInstanceSerializer<T>(objectReader, objectWriter, typeReference);
}
 
Example #13
Source File: ZKAssistedDiscoveryTest.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example #14
Source File: ZookeeperServiceRegistryAutoConfiguration.java    From spring-cloud-zookeeper with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public InstanceSerializer<ZookeeperInstance> instanceSerializer() {
	return new JsonInstanceSerializer<>(ZookeeperInstance.class);
}
 
Example #15
Source File: CuratorServiceDiscoveryAutoConfiguration.java    From spring-cloud-zookeeper with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public InstanceSerializer<ZookeeperInstance> deprecatedInstanceSerializer() {
	return new JsonInstanceSerializer<>(ZookeeperInstance.class);
}