narendly commented on a change in pull request #796: WIP: Add
SharedZkClient/InnerSharedZkClient implementation
URL: https://github.com/apache/helix/pull/796#discussion_r383647138
##########
File path:
zookeeper-api/src/main/java/org/apache/helix/zookeeper/impl/factory/SharedZkClientFactory.java
##########
@@ -128,4 +139,78 @@ public int getActiveConnectionCount() {
}
return count;
}
+
+ public interface OnCloseCallback {
+ /**
+ * Triggered after the SharedZkClient is closed.
+ */
+ void onClose();
+ }
+
+ /**
+ * NOTE: do NOT use this class directly. Please use SharedZkClientFactory to
create an instance of SharedZkClient.
+ * InnerSharedZkClient is a ZkClient used by SharedZkClient to power ZK
operations against a single ZK realm.
+ *
+ * NOTE2: current InnerSharedZkClient replace the original SharedZKClient.
We intend to keep the behavior of original
+ * SharedZkClient intact. (Think of rename the original SharedZkClient as
InnerSharedZkClient. This would maintain
+ * backward compatibility.
+ */
+ public static class InnerSharedZkClient extends ZkClient implements
HelixZkClient {
+
+ private final OnCloseCallback _onCloseCallback;
+ private final ZkConnectionManager _connectionManager;
+
+ public InnerSharedZkClient(ZkConnectionManager connectionManager,
ZkClientConfig clientConfig,
+ OnCloseCallback callback) {
+ super(connectionManager.getConnection(), 0,
clientConfig.getOperationRetryTimeout(),
+ clientConfig.getZkSerializer(), clientConfig.getMonitorType(),
+ clientConfig.getMonitorKey(), clientConfig.getMonitorInstanceName(),
+ clientConfig.isMonitorRootPathOnly());
+ _connectionManager = connectionManager;
+ // Register to the base dedicated RealmAwareZkClient
+ _connectionManager.registerWatcher(this);
+ _onCloseCallback = callback;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ if (isClosed()) {
+ // Note that if register is not done while constructing, these private
fields may not be init yet.
+ if (_connectionManager != null) {
+ _connectionManager.unregisterWatcher(this);
+ }
+ if (_onCloseCallback != null) {
+ _onCloseCallback.onClose();
+ }
+ }
+ }
+
+ @Override
+ public IZkConnection getConnection() {
+ if (isClosed()) {
+ return IDLE_CONNECTION;
+ }
+ return super.getConnection();
+ }
+
+ /**
+ * Since ZkConnection session is shared in this HelixZkClient, do not
create ephemeral node using a SharedZKClient.
+ */
+ @Override
+ public String create(final String path, Object datat, final List<ACL> acl,
+ final CreateMode mode) {
+ if (mode.isEphemeral()) {
+ throw new UnsupportedOperationException(
+ "Create ephemeral nodes using " +
SharedZkClient.class.getSimpleName()
Review comment:
Nit: "Creating"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]