class DpStmMap::Manager

Public Class Methods

new(port, store_dir) click to toggle source
# File lib/dp_stm_map/Manager.rb, line 29
def initialize port, store_dir
  @port=port
  @state=:not_running


  FileUtils.mkdir_p(store_dir) unless File.exist? store_dir

  @transaction_log=TransactionLog.new("%s/log" % store_dir)
  reference_counts=ReferenceCounts.new("%s/refcounts" % store_dir)
  current_values=CurrentValues.new("%s/current_values" % store_dir)
  @tx_manager=ClientTransactionManager.new(current_values, reference_counts, @transaction_log)
end

Public Instance Methods

port() click to toggle source
# File lib/dp_stm_map/Manager.rb, line 42
def port
  @server_socket.addr[1]
end
start() click to toggle source
# File lib/dp_stm_map/Manager.rb, line 47
def start
  @server_socket=TCPServer.new @port
  @accept_thread=Thread.new do
    begin
      active_threads=[]
      loop do
        client_socket=@server_socket.accept
        client_socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)

        active_threads << Thread.new do

          begin
            transport=SocketTransport.new(client_socket)
            client_handler=ClientHandler.new transport, @tx_manager
            msg=transport.next_message

            raise "client did not send ClientHelloMessage" unless ClientHelloMessage === msg

            transport.send_message ServerHelloMessage.new


            @transaction_log.add_listener(msg.last_transaction_sequence) do |seq, tx|
              client_handler.handle TransactionMessage.new(seq, *tx)
            end

            loop do
              msg=transport.next_message
              client_handler.handle msg
            end

          rescue ManagerShutdown => e


          rescue => e
            # puts "Error during processing: #{$!}"
            # puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"

          ensure
            # puts "closed socket to client"
            client_socket.close
          end
        end
      end

    rescue ManagerShutdown => e
    ensure
      @server_socket.close unless @server_socket.closed?
      active_threads.each do |thread|
        thread.raise ManagerShutdown
        thread.join
      end



    end


  end
end
stop() click to toggle source
# File lib/dp_stm_map/Manager.rb, line 108
def stop
  @accept_thread.raise ManagerShutdown

  begin
    @accept_thread.join
  rescue => e
  end


end