Class: DpStmMap::ClientHandler

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

Instance Method Summary collapse

Constructor Details

#initialize(client_transport, transaction_handler) ⇒ ClientHandler

Returns a new instance of ClientHandler.



287
288
289
290
291
# File 'lib/dp_stm_map/Manager.rb', line 287

def initialize client_transport, transaction_handler
  @client_transport=client_transport
  @transaction_handler=transaction_handler
  @mutex=Mutex.new
end

Instance Method Details

#handle(message) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/dp_stm_map/Manager.rb', line 293

def handle message
  @mutex.synchronize do
    if TransactionMessage === message
      @client_transport.send_message message
    end
    if ClientTransactionMessage === message
      begin
        sequence=@transaction_handler.apply_transaction message.transitions, message.new_content
        @client_transport.send_message ClientTransactionSuccessfulMessage.new message.transaction_id, sequence
      rescue StaleTransactionError => e
        @client_transport.send_message ClientTransactionFailedMessage.new message.transaction_id, e.message
      end
    end
  end
end