Class: DpStmMap::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/dp_stm_map/Manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(port, store_dir) ⇒ Manager

Returns a new instance of Manager.



29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Method Details

#portObject



42
43
44
# File 'lib/dp_stm_map/Manager.rb', line 42

def port
  @server_socket.addr[1]
end

#startObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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

#stopObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/dp_stm_map/Manager.rb', line 108

def stop
  @accept_thread.raise ManagerShutdown

  begin
    @accept_thread.join
  rescue => e
  end


end