/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace Kafka.Client.ZooKeeperIntegration { using System; using System.Collections.Generic; using Kafka.Client.ZooKeeperIntegration.Listeners; using Org.Apache.Zookeeper.Data; using ZooKeeperNet; /// /// Abstracts the interaction with zookeeper /// internal interface IZooKeeperClient : IWatcher, IDisposable { /// /// Gets time (in miliseconds) of event thread idleness /// /// /// Used for testing purpose /// int? IdleTime { get; } /// /// Connects to ZooKeeper server within given time period and installs watcher in ZooKeeper /// void Connect(); /// /// Closes current connection to ZooKeeper /// void Disconnect(); /// /// Re-connect to ZooKeeper server when session expired /// /// /// The servers. /// /// /// The connection timeout. /// void Reconnect(string servers, int connectionTimeout); /// /// Waits untill ZooKeeper connection is established /// /// /// The connection timeout. /// /// /// Status /// bool WaitUntilConnected(int connectionTimeout); /// /// Retries given delegate until connections is established /// /// /// The delegate to invoke. /// /// /// Type of data returned by delegate /// /// /// data returned by delegate /// T RetryUntilConnected(Func callback); /// /// Subscribes listeners on ZooKeeper state changes events /// /// /// The listener. /// void Subscribe(IZooKeeperStateListener listener); /// /// Un-subscribes listeners on ZooKeeper state changes events /// /// /// The listener. /// void Unsubscribe(IZooKeeperStateListener listener); /// /// Subscribes listeners on ZooKeeper child changes under given path /// /// /// The parent path. /// /// /// The listener. /// void Subscribe(string path, IZooKeeperChildListener listener); /// /// Un-subscribes listeners on ZooKeeper child changes under given path /// /// /// The parent path. /// /// /// The listener. /// void Unsubscribe(string path, IZooKeeperChildListener listener); /// /// Subscribes listeners on ZooKeeper data changes under given path /// /// /// The parent path. /// /// /// The listener. /// void Subscribe(string path, IZooKeeperDataListener listener); /// /// Un-subscribes listeners on ZooKeeper data changes under given path /// /// /// The parent path. /// /// /// The listener. /// void Unsubscribe(string path, IZooKeeperDataListener listener); /// /// Un-subscribes all listeners /// void UnsubscribeAll(); /// /// Installs a child watch for the given path. /// /// /// The parent path. /// /// /// the current children of the path or null if the znode with the given path doesn't exist /// IList WatchForChilds(string path); /// /// Installs a data watch for the given path. /// /// /// The parent path. /// void WatchForData(string path); /// /// Checks whether znode for a given path exists /// /// /// The given path. /// /// /// Result of check /// bool Exists(string path); /// /// Checks whether znode for a given path exists. /// /// /// The given path. /// /// /// Indicates whether should reinstall watcher in ZooKeeper. /// /// /// Result of check /// bool Exists(string path, bool watch); /// /// Gets all children for a given path /// /// /// The given path. /// /// /// Children /// IList GetChildren(string path); /// /// Gets all children for a given path /// /// /// The given path. /// /// /// Indicates whether should reinstall watcher in ZooKeeper. /// /// /// Children /// IList GetChildren(string path, bool watch); /// /// Counts number of children for a given path. /// /// /// The given path. /// /// /// Number of children /// int CountChildren(string path); /// /// Fetches data from a given path in ZooKeeper /// /// /// The given path. /// /// /// The statistics. /// /// /// Indicates whether should reinstall watcher in ZooKeeper. /// /// /// Expected type of data /// /// /// Data /// T ReadData(string path, Stat stats, bool watch) where T : class; /// /// Fetches data from a given path in ZooKeeper /// /// /// The given path. /// /// /// The statistics. /// /// /// Expected type of data /// /// /// Data /// T ReadData(string path, Stat stats) where T : class; /// /// Fetches data from a given path in ZooKeeper /// /// /// Expected type of data /// /// /// The given path. /// /// /// Data or null, if znode does not exist /// T ReadData(string path) where T : class; /// /// Fetches data for given path /// /// /// The given path. /// /// /// Indicates, whether should return null or throw exception when /// znode doesn't exist /// /// /// Expected type of data /// /// /// Data /// T ReadData(string path, bool returnNullIfPathNotExists) where T : class; /// /// Writes data for a given path /// /// /// The given path. /// /// /// The data to write. /// void WriteData(string path, object data); /// /// Writes data for a given path /// /// /// The given path. /// /// /// The data to write. /// /// /// Expected version of data /// void WriteData(string path, object data, int expectedVersion); /// /// Deletes znode for a given path /// /// /// The given path. /// /// /// Status /// bool Delete(string path); /// /// Deletes znode and his children for a given path /// /// /// The given path. /// /// /// Status /// bool DeleteRecursive(string path); /// /// Creates persistent znode and all intermediate znodes (if do not exist) for a given path /// /// /// The given path. /// void MakeSurePersistentPathExists(string path); /// /// Fetches children for a given path /// /// /// The path. /// /// /// Children or null, if znode does not exist /// IList GetChildrenParentMayNotExist(string path); /// /// Creates a persistent znode for a given path /// /// /// The given path. /// /// /// Indicates whether should create all intermediate znodes /// /// /// Persistent znodes won't disappear after session close /// Doesn't re-create missing intermediate znodes /// void CreatePersistent(string path, bool createParents); /// /// Creates a persistent znode for a given path /// /// /// The given path. /// /// /// Persistent znodes won't disappear after session close /// Doesn't re-create missing intermediate znodes /// void CreatePersistent(string path); /// /// Creates a persistent znode for a given path and writes data into it /// /// /// The given path. /// /// /// The data to write. /// /// /// Persistent znodes won't disappear after session close /// void CreatePersistent(string path, object data); /// /// Creates a sequential, persistent znode for a given path and writes data into it /// /// /// The given path. /// /// /// The data to write. /// /// /// Persistent znodes won't dissapear after session close /// /// /// The created znode's path /// string CreatePersistentSequential(string path, object data); /// /// Creates a ephemeral znode for a given path /// /// /// The given path. /// /// /// Ephemeral znodes will disappear after session close /// void CreateEphemeral(string path); /// /// Creates a ephemeral znode for a given path and writes data into it /// /// /// The given path. /// /// /// The data to write. /// /// /// Ephemeral znodes will disappear after session close /// void CreateEphemeral(string path, object data); /// /// Creates a ephemeral, sequential znode for a given path and writes data into it /// /// /// The given path. /// /// /// The data to write. /// /// /// Ephemeral znodes will disappear after session close /// /// /// Created znode's path /// string CreateEphemeralSequential(string path, object data); } }