Esempio n. 1
0
 internal HandleHolder(ZookeeperFactory zookeeperFactory, Watcher watcher, EnsembleProvider ensembleProvider,
     int sessionTimeout, bool canBeReadOnly)
 {
     this.zookeeperFactory = zookeeperFactory;
     this.watcher = watcher;
     this.ensembleProvider = ensembleProvider;
     this.sessionTimeout = sessionTimeout;
     this.canBeReadOnly = canBeReadOnly;
 }
        /// <summary>
        /// Create Zookeeper client from config.
        /// </summary>
        /// <returns>Zookeeper client</returns>
        private IZookeeperClient GetZookeeperClient()
        {
            if (_zookeeperClient == null)
            {
                lock (SyncObject)
                {
                    if (_zookeeperClient == null)
                    {
                        _zookeeperClient = ZookeeperFactory.CreateClient(this._currentEnvironment.Location);
                    }
                }
            }

            return(_zookeeperClient);
        }
Esempio n. 3
0
        internal ConnectionState(ZookeeperFactory zookeeperFactory, EnsembleProvider ensembleProvider,
            int sessionTimeoutMs, int connectionTimeoutMs, Watcher parentWatcher, AtomicReference<TracerDriver> tracer,
            bool canBeReadOnly)
        {
            this.ensembleProvider = ensembleProvider;
            this.sessionTimeoutMs = sessionTimeoutMs;
            this.connectionTimeoutMs = connectionTimeoutMs;
            this.tracer = tracer;
            if (parentWatcher != null)
            {
                parentWatchers.AddLast(parentWatcher);
            }

            zooKeeper = new HandleHolder(zookeeperFactory, this, ensembleProvider, sessionTimeoutMs, canBeReadOnly);
        }
        /// <param name="zookeeperFactory"> factory for creating <seealso cref="ZooKeeper" /> instances </param>
        /// <param name="ensembleProvider"> the ensemble provider </param>
        /// <param name="sessionTimeoutMs"> session timeout </param>
        /// <param name="connectionTimeoutMs"> connection timeout </param>
        /// <param name="watcher"> default watcher or null </param>
        /// <param name="retryPolicy"> the retry policy to use </param>
        /// <param name="canBeReadOnly">
        ///     if true, allow ZooKeeper client to enter
        ///     read only mode in case of a network partition. See
        ///     <seealso cref="ZooKeeper#ZooKeeper(String, int, Watcher, long, byte[], boolean)" />
        ///     for details
        /// </param>
        public CuratorZookeeperClient(ZookeeperFactory zookeeperFactory, EnsembleProvider ensembleProvider,
            int sessionTimeoutMs, int connectionTimeoutMs, Watcher watcher, RetryPolicy retryPolicy, bool canBeReadOnly)
        {
            if (sessionTimeoutMs < connectionTimeoutMs)
            {
                log.warn(string.Format("session timeout [{0:D}] is less than connection timeout [{1:D}]",
                    sessionTimeoutMs, connectionTimeoutMs));
            }

            retryPolicy = Preconditions.checkNotNull(retryPolicy, "retryPolicy cannot be null");
            ensembleProvider = Preconditions.checkNotNull(ensembleProvider, "ensembleProvider cannot be null");

            this.connectionTimeoutMs = connectionTimeoutMs;
            state = new ConnectionState(zookeeperFactory, ensembleProvider, sessionTimeoutMs, connectionTimeoutMs,
                watcher, tracer, canBeReadOnly);
            setRetryPolicy(retryPolicy);
        }