org.I0Itec.zkclient.serialize.ZkSerializer Java Examples

The following examples show how to use org.I0Itec.zkclient.serialize.ZkSerializer. 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: ZkClientCRUD.java    From yuzhouwan with Apache License 2.0 6 votes vote down vote up
private void init() {
        zkClient = new ZkClient(HOST.concat(":" + CLIENT_PORT), TIME_OUT_MILLISECOND);

        zkSerializer = new ZkSerializer() {
            /**
             * TODO{Benedict Jin}: kryo
             */
            @Override
            public byte[] serialize(Object data) throws ZkMarshallingError {
                return new byte[0];
            }

            @Override
            public Object deserialize(byte[] bytes) throws ZkMarshallingError {
                return null;
            }
        };
//        zkClient.setZkSerializer(zkSerializer);
    }
 
Example #2
Source File: DiscoveryTool.java    From kafka-metrics with Apache License 2.0 6 votes vote down vote up
public DiscoveryTool(String serverstring) {
    super(serverstring, 30000, 30000, new ZkSerializer() {
        private final ObjectMapper mapper = new ObjectMapper();

        @Override
        public byte[] serialize(Object o) throws ZkMarshallingError {
            throw new ZkMarshallingError("This is a read-only zkClient");
        }

        @Override
        public Object deserialize(byte[] bytes) throws ZkMarshallingError {
            try {
                return mapper.readTree(bytes);
            } catch (IOException e) {
                throw new ZkMarshallingError(e);
            }
        }
    });
}
 
Example #3
Source File: KafkaProduceOffsetFetcher.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public KafkaProduceOffsetFetcher(String zkHost) {
    this.zkClient = new ZkClient(zkHost, SESSION_TIMEOUT, CONNECTION_TIMEOUT, new ZkSerializer() {
        @Override
        public byte[] serialize(Object o) throws ZkMarshallingError {
            return ((String) o).getBytes();
        }

        @Override
        public Object deserialize(byte[] bytes) throws ZkMarshallingError {
            if (bytes == null) {
                return null;
            } else {
                return StringUtils.newStringUtf8(bytes);
            }
        }
    });
}
 
Example #4
Source File: KafkaProduceOffsetFetcher.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public KafkaProduceOffsetFetcher(String zkHost) {
    this.zkClient = new ZkClient(zkHost, SESSION_TIMEOUT, CONNECTION_TIMEOUT, new ZkSerializer() {
        @Override
        public byte[] serialize(Object o) throws ZkMarshallingError {
            return ((String) o).getBytes();
        }

        @Override
        public Object deserialize(byte[] bytes) throws ZkMarshallingError {
            if (bytes == null) {
                return null;
            } else {
                return StringUtils.newStringUtf8(bytes);
            }
        }
    });
}
 
Example #5
Source File: ZkSerializerFactory.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * product  ZkSerializer with className.
 *
 * @param className className
 * @return ZkSerializer zk serializer
 */
public static ZkSerializer of(final String className) {
    return StreamSupport.stream(SERVICE_LOADER.spliterator(), false)
            .filter(service -> Objects.equals(service.getClass().getName().substring(service.getClass().getName().lastIndexOf(".") + 1), className))
            .findFirst()
            .orElse(new KryoSerializer());
}
 
Example #6
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public ZkClient(IZkConnection zkConnection, int connectionTimeout, ZkSerializer zkSerializer) {
    this(zkConnection, connectionTimeout, zkSerializer, -1, null);
}
 
Example #7
Source File: ZkClientx.java    From canal with Apache License 2.0 4 votes vote down vote up
private ZkClientx(IZkConnection zkConnection, int connectionTimeout, ZkSerializer zkSerializer){
    super(zkConnection, connectionTimeout, zkSerializer);
}
 
Example #8
Source File: ZkClientx.java    From canal with Apache License 2.0 4 votes vote down vote up
public ZkClientx(String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer){
    this(new ZooKeeperx(zkServers, sessionTimeout), connectionTimeout, zkSerializer);
}
 
Example #9
Source File: ZkClientx.java    From feeyo-redisproxy with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private ZkClientx(IZkConnection zkConnection, int connectionTimeout, ZkSerializer zkSerializer){
    super(zkConnection, connectionTimeout, zkSerializer);
}
 
Example #10
Source File: ZkClientx.java    From feeyo-redisproxy with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ZkClientx(String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer){
    this(new ZkConnection(zkServers, sessionTimeout), connectionTimeout, zkSerializer);
}
 
Example #11
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public void setZkSerializer(ZkSerializer zkSerializer) {
    _zkSerializer = zkSerializer;
}
 
Example #12
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public ZkClient(String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer) {
    this(new ZkConnection(zkServers, sessionTimeout), connectionTimeout, zkSerializer);
}
 
Example #13
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public ZkClient(String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer, IZkStateListener zkStateListener) {
    this(new ZkConnection(zkServers, sessionTimeout), connectionTimeout, zkSerializer, -1, zkStateListener);
}
 
Example #14
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public ZkClient(String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer) {
    this(new ZkConnection(zkServers, sessionTimeout), connectionTimeout, zkSerializer);
}
 
Example #15
Source File: ZkClientx.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
private ZkClientx(IZkConnection zkConnection, int connectionTimeout, ZkSerializer zkSerializer){
    super(zkConnection, connectionTimeout, zkSerializer);
}
 
Example #16
Source File: ZkClientx.java    From canal-1.1.3 with Apache License 2.0 4 votes vote down vote up
public ZkClientx(String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer){
    this(new ZooKeeperx(zkServers, sessionTimeout), connectionTimeout, zkSerializer);
}
 
Example #17
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public void setZkSerializer(ZkSerializer zkSerializer) {
    _zkSerializer = zkSerializer;
}
 
Example #18
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public ZkClient(IZkConnection zkConnection, int connectionTimeout, ZkSerializer zkSerializer) {
    this(zkConnection, connectionTimeout, zkSerializer, -1, null);
}
 
Example #19
Source File: ZkClient.java    From DDMQ with Apache License 2.0 4 votes vote down vote up
public ZkClient(String zkServers, int sessionTimeout, int connectionTimeout, ZkSerializer zkSerializer, IZkStateListener zkStateListener) {
    this(new ZkConnection(zkServers, sessionTimeout), connectionTimeout, zkSerializer, -1, zkStateListener);
}
 
Example #20
Source File: ZkClient.java    From DDMQ with Apache License 2.0 3 votes vote down vote up
/**
 *
 * @param zkConnection
 *            The Zookeeper servers
 * @param connectionTimeout
 *            The connection timeout in milli seconds
 * @param zkSerializer
 *            The Zookeeper data serializer
 * @param operationRetryTimeout
 *            Most operations done through this {@link org.I0Itec.zkclient.ZkClient} are retried in cases like
 *            connection loss with the Zookeeper servers. During such failures, this
 *            <code>operationRetryTimeout</code> decides the maximum amount of time, in milli seconds, each
 *            operation is retried. A value lesser than 0 is considered as
 *            "retry forever until a connection has been reestablished".
 */
public ZkClient(final IZkConnection zkConnection, final int connectionTimeout, final ZkSerializer zkSerializer, final long operationRetryTimeout, final IZkStateListener zkStateListener) {
    if (zkConnection == null) {
        throw new NullPointerException("Zookeeper connection is null!");
    }
    _connection = zkConnection;
    _zkSerializer = zkSerializer;
    _operationRetryTimeoutInMillis = operationRetryTimeout;
    _isZkSaslEnabled = isZkSaslEnabled();
    if(zkStateListener != null) {
        subscribeStateChanges(zkStateListener);
    }

    connect(connectionTimeout, this);
}
 
Example #21
Source File: ZkClient.java    From DDMQ with Apache License 2.0 3 votes vote down vote up
/**
 *
 * @param zkConnection
 *            The Zookeeper servers
 * @param connectionTimeout
 *            The connection timeout in milli seconds
 * @param zkSerializer
 *            The Zookeeper data serializer
 * @param operationRetryTimeout
 *            Most operations done through this {@link org.I0Itec.zkclient.ZkClient} are retried in cases like
 *            connection loss with the Zookeeper servers. During such failures, this
 *            <code>operationRetryTimeout</code> decides the maximum amount of time, in milli seconds, each
 *            operation is retried. A value lesser than 0 is considered as
 *            "retry forever until a connection has been reestablished".
 */
public ZkClient(final IZkConnection zkConnection, final int connectionTimeout, final ZkSerializer zkSerializer, final long operationRetryTimeout, final IZkStateListener zkStateListener) {
    if (zkConnection == null) {
        throw new NullPointerException("Zookeeper connection is null!");
    }
    _connection = zkConnection;
    _zkSerializer = zkSerializer;
    _operationRetryTimeoutInMillis = operationRetryTimeout;
    _isZkSaslEnabled = isZkSaslEnabled();
    if(zkStateListener != null) {
        subscribeStateChanges(zkStateListener);
    }

    connect(connectionTimeout, this);
}
 
Example #22
Source File: ZkStateStore.java    From incubator-gobblin with Apache License 2.0 3 votes vote down vote up
/**
 * State store that stores instances of {@link State}s in a ZooKeeper-backed {@link HelixPropertyStore}
 * storeRootDir will be created when the first entry is written if it does not exist
 * @param connectString ZooKeeper connect string
 * @param storeRootDir The root directory for the state store
 * @param compressedValues should values be compressed for storage?
 * @param stateClass The type of state being stored
 * @throws IOException
 */
public ZkStateStore(String connectString, String storeRootDir, boolean compressedValues, Class<T> stateClass)
    throws IOException {
  this.compressedValues = compressedValues;
  this.stateClass = stateClass;

  ZkSerializer serializer = new ByteArraySerializer();
  propStore = new ZkHelixPropertyStore<byte[]>(connectString, serializer, storeRootDir);
}
 
Example #23
Source File: ZkClient.java    From DDMQ with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param zkServers
 *            The Zookeeper servers
 * @param sessionTimeout
 *            The session timeout in milli seconds
 * @param connectionTimeout
 *            The connection timeout in milli seconds
 * @param zkSerializer
 *            The Zookeeper data serializer
 * @param operationRetryTimeout
 *            Most operations done through this {@link org.I0Itec.zkclient.ZkClient} are retried in cases like
 *            connection loss with the Zookeeper servers. During such failures, this
 *            <code>operationRetryTimeout</code> decides the maximum amount of time, in milli seconds, each
 *            operation is retried. A value lesser than 0 is considered as
 *            "retry forever until a connection has been reestablished".
 */
public ZkClient(final String zkServers, final int sessionTimeout, final int connectionTimeout, final ZkSerializer zkSerializer, final long operationRetryTimeout) {
    this(new ZkConnection(zkServers, sessionTimeout), connectionTimeout, zkSerializer, operationRetryTimeout, null);
}
 
Example #24
Source File: ZkClient.java    From DDMQ with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param zkServers
 *            The Zookeeper servers
 * @param sessionTimeout
 *            The session timeout in milli seconds
 * @param connectionTimeout
 *            The connection timeout in milli seconds
 * @param zkSerializer
 *            The Zookeeper data serializer
 * @param operationRetryTimeout
 *            Most operations done through this {@link org.I0Itec.zkclient.ZkClient} are retried in cases like
 *            connection loss with the Zookeeper servers. During such failures, this
 *            <code>operationRetryTimeout</code> decides the maximum amount of time, in milli seconds, each
 *            operation is retried. A value lesser than 0 is considered as
 *            "retry forever until a connection has been reestablished".
 */
public ZkClient(final String zkServers, final int sessionTimeout, final int connectionTimeout, final ZkSerializer zkSerializer, final long operationRetryTimeout) {
    this(new ZkConnection(zkServers, sessionTimeout), connectionTimeout, zkSerializer, operationRetryTimeout, null);
}