org.I0Itec.zkclient.exception.ZkMarshallingError Java Examples

The following examples show how to use org.I0Itec.zkclient.exception.ZkMarshallingError. 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: 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 #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: 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 #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: StringSerializer.java    From canal with Apache License 2.0 5 votes vote down vote up
public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
    try {
        return new String(bytes, "utf-8");
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #6
Source File: StringSerializer.java    From canal with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(final Object data) throws ZkMarshallingError {
    try {
        return ((String) data).getBytes("utf-8");
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #7
Source File: ByteSerializer.java    From feeyo-redisproxy with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public byte[] serialize(final Object data) throws ZkMarshallingError {
    try {
        if (data instanceof byte[]) {
            return (byte[]) data;
        } else {
            return ((String) data).getBytes("utf-8");
        }
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #8
Source File: SimpleZkSerializer.java    From sumk with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object data) throws ZkMarshallingError {
	if (data == null) {
		return null;
	}
	if (byte[].class == data.getClass()) {
		return (byte[]) data;
	}
	if (String.class == data.getClass()) {
		return ((String) data).getBytes(charset);
	}
	return S.json().toJson(data).getBytes(charset);
}
 
Example #9
Source File: ZookeeperMasterDetector.java    From jesos with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(final byte[] bytes) throws ZkMarshallingError
{
    checkNotNull(bytes, "bytes is null");
    try {
        return MasterInfo.parseFrom(bytes);
    }
    catch (final InvalidProtocolBufferException e) {
        return new ZkMarshallingError(e);
    }
}
 
Example #10
Source File: ZkUtils.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(Object obj) throws ZkMarshallingError {
	if (obj == null) {
		return null;
	}

	if (!(obj instanceof String)) {
		throw new ZkMarshallingError(
				"The input obj must be an instance of String.");
	}
	try {
		return ((String) obj).getBytes(this.encoding);
	} catch (UnsupportedEncodingException e) {
		throw new RuntimeException(e);
	}
}
 
Example #11
Source File: ZkClient.java    From brooklin with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
  String data = null;
  if (bytes != null) {
    data = new String(bytes, StandardCharsets.UTF_8);
  }
  return data;
}
 
Example #12
Source File: ZkUtils.java    From learning-hadoop with Apache License 2.0 5 votes vote down vote up
public Object deserialize(byte[] abyte0) throws ZkMarshallingError {
	try {
		return new String(abyte0, this.encoding);
	} catch (UnsupportedEncodingException e) {
		throw new RuntimeException(e);
	}

}
 
Example #13
Source File: ZkStringSerializer.java    From samza with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object data) throws ZkMarshallingError {
  if (data != null) {
    try {
      return ((String) data).getBytes(UTF_8);
    } catch (UnsupportedEncodingException e) {
      throw new ZkMarshallingError(e);
    }
  } else {
    return null;
  }
}
 
Example #14
Source File: ZkStringSerializer.java    From samza with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
  if (bytes != null) {
    try {
      return new String(bytes, 0, bytes.length, UTF_8);
    } catch (UnsupportedEncodingException e) {
      throw new ZkMarshallingError(e);
    }
  } else {
    return null;
  }
}
 
Example #15
Source File: MockKafka.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
    if (bytes == null)
        return null;
    else
        try {
            return new String(bytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new ZkMarshallingError(e);
        }
}
 
Example #16
Source File: Resources.java    From DCMonitor with MIT License 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
  if (isZKDirectBytes.get()) {
    return bytes;
  } else {
    return ZKStringSerializer.deserialize(bytes);
  }
}
 
Example #17
Source File: MockKafka.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object data) throws ZkMarshallingError {
    byte[] bytes = null;
    try {
        bytes = data.toString().getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
    return bytes;
}
 
Example #18
Source File: ByteSerializer.java    From canal with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(final Object data) throws ZkMarshallingError {
    try {
        if (data instanceof byte[]) {
            return (byte[]) data;
        } else {
            return ((String) data).getBytes("utf-8");
        }
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #19
Source File: MockKafka.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object data) throws ZkMarshallingError {
    byte[] bytes = null;
    try {
        bytes = data.toString().getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
    return bytes;
}
 
Example #20
Source File: MockKafka.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
    if (bytes == null)
        return null;
    else
        try {
            return new String(bytes, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new ZkMarshallingError(e);
        }
}
 
Example #21
Source File: StringSerializer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public Object deserialize(final byte[] bytes) throws ZkMarshallingError {
    try {
        return new String(bytes, "utf-8");
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #22
Source File: StringSerializer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(final Object data) throws ZkMarshallingError {
    try {
        return ((String) data).getBytes("utf-8");
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #23
Source File: ByteSerializer.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(final Object data) throws ZkMarshallingError {
    try {
        if (data instanceof byte[]) {
            return (byte[]) data;
        } else {
            return ((String) data).getBytes("utf-8");
        }
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #24
Source File: DataxSerializableSerializer.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object serializable) throws ZkMarshallingError {
    try {
        ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
        ObjectOutputStream stream = new ObjectOutputStream(byteArrayOS);
        stream.writeObject(serializable);
        stream.close();
        return byteArrayOS.toByteArray();
    } catch (IOException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #25
Source File: ByteSerializer.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public byte[] serialize(final Object data) throws ZkMarshallingError {
    try {
        if (data instanceof byte[]) {
            return (byte[]) data;
        } else {
            return ((String) data).getBytes("utf-8");
        }
    } catch (final UnsupportedEncodingException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #26
Source File: DLSerializableSerializer.java    From DataLink with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object serializable) throws ZkMarshallingError {
    try {
        ByteArrayOutputStream byteArrayOS = new ByteArrayOutputStream();
        ObjectOutputStream stream = new ObjectOutputStream(byteArrayOS);
        stream.writeObject(serializable);
        stream.close();
        return byteArrayOS.toByteArray();
    } catch (IOException e) {
        throw new ZkMarshallingError(e);
    }
}
 
Example #27
Source File: ZKStringSerializer.java    From hermes with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
	if (bytes == null)
		return null;
	else
		try {
			return new String(bytes, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			throw new ZkMarshallingError(e);
		}
}
 
Example #28
Source File: ZKTest.java    From krpc with MIT License 5 votes vote down vote up
@Override
public byte[] serialize(Object o) throws ZkMarshallingError {
    try {
        return o.toString().getBytes("utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return null;
}
 
Example #29
Source File: ZKTest.java    From krpc with MIT License 5 votes vote down vote up
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
    try {
        return new String(bytes, "utf-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #30
Source File: ZKStringSerializer.java    From hermes with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] serialize(Object data) throws ZkMarshallingError {
	byte[] bytes = null;
	try {
		bytes = data.toString().getBytes("UTF-8");
	} catch (UnsupportedEncodingException e) {
		throw new ZkMarshallingError(e);
	}
	return bytes;
}