Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ZooKeeperClient"/> class.
 /// </summary>
 /// <param name="connection">
 /// The connection to ZooKeeper.
 /// </param>
 /// <param name="serializer">
 /// The given serializer.
 /// </param>
 /// <param name="connectionTimeout">
 /// The connection timeout (in miliseconds). Default is infinitive.
 /// </param>
 /// <remarks>
 /// Default serializer is string UTF-8 serializer
 /// </remarks>
 public ZooKeeperClient(
     IZooKeeperConnection connection,
     IZooKeeperSerializer serializer,
     int connectionTimeout = DefaultConnectionTimeout)
 {
     this.serializer        = serializer;
     this.connection        = connection;
     this.connectionTimeout = connectionTimeout;
 }
Exemple #2
0
 /// <summary>
 /// Closes current connection to ZooKeeper
 /// </summary>
 /// <remarks>
 /// Also, stops background thread
 /// </remarks>
 public void Disconnect()
 {
     Logger.Debug("Closing ZooKeeperClient...");
     this.shutdownTriggered = true;
     this.eventWorker.Interrupt();
     this.eventWorker.Join(5000);
     this.connection.Dispose();
     this.connection = null;
 }
Exemple #3
0
 /// <summary>
 /// Re-connect to ZooKeeper server when session expired
 /// </summary>
 /// <param name="servers">
 /// The servers.
 /// </param>
 /// <param name="connectionTimeout">
 /// The connection timeout.
 /// </param>
 public void Reconnect(string servers, int connectionTimeout)
 {
     this.EnsuresNotDisposed();
     Logger.Debug("Reconnecting");
     this.connection.Dispose();
     this.connection = new ZooKeeperConnection(servers, connectionTimeout);
     this.connection.Connect(this);
     Logger.Debug("Reconnected");
 }
Exemple #4
0
        /// <summary>
        ///     Closes current connection to ZooKeeper
        /// </summary>
        /// <remarks>
        ///     Also, stops background thread
        /// </remarks>
        public void Disconnect()
        {
            Logger.Debug("Closing ZooKeeperClient");
            shutdownTriggered = true;
            eventWorker.Interrupt();
            try
            {
                if (eventWorker.ThreadState != ThreadState.Unstarted)
                {
                    eventWorker.Join(5000);
                }
            }
            catch (ThreadStateException)
            {
                // exception means worker thread was interrupted even before we started waiting.
            }

            if (connection != null)
            {
                connection.Dispose();
            }

            connection = null;
        }