Class: ISO8583::MKB::Gateway

Inherits:
Object
  • Object
show all
Defined in:
lib/iso8583-mkb/gateway.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Gateway

Returns a new instance of Gateway.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/iso8583-mkb/gateway.rb', line 3

def initialize(config)
  uri = URI(config[:dhi])

  raise "expected tcp scheme for DHI" if uri.scheme != "tcp"
  @dhi_host = uri.host
  @dhi_port = uri.port
  @dhi_open = false
  @reopen_timer = nil

  @deferred = []
  Logging.logger.info "Gateway started"
end

Instance Method Details

#new_transactionObject



39
40
41
# File 'lib/iso8583-mkb/gateway.rb', line 39

def new_transaction
  ISO8583Transaction.new self
end

#post_request(request) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/iso8583-mkb/gateway.rb', line 43

def post_request(request)

  if @dhi_open ||
     ((request.request.mti == 800 || request.request.mti == 810) && !@dhi.nil?)
    @dhi.request request
  else
    @deferred << request
  end
end

#runObject



16
17
18
19
20
# File 'lib/iso8583-mkb/gateway.rb', line 16

def run
  EventMachine.run do
    reopen_dhi
  end
end

#stopObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/iso8583-mkb/gateway.rb', line 22

def stop
  if !@reopen_timer.nil?
    EventMachine.cancel_timer @reopen_timer
    @reopen_timer = nil
  end

  if !@dhi.nil?
    @dhi_open = false
    @dhi.closed = ->() {}

    @dhi.close_connection
    @dhi = nil
  end

  @deferred.clear
end