Class: Baykit::BayServer::Agent::Multiplexer::TaxiMultiplexer

Inherits:
MultiplexerBase
  • Object
show all
Includes:
Baykit::BayServer, Baykit::BayServer::Agent::Multiplexer, Common, Rudders, Taxi, Util
Defined in:
lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb

Defined Under Namespace

Classes: TaxiForMpx

Instance Attribute Summary

Attributes inherited from MultiplexerBase

#agent, #channel_count, #lock, #rudders, #rudders_lock

Instance Method Summary collapse

Methods inherited from MultiplexerBase

#add_rudder_state, #close_all, #close_rudder, #close_timeout_sockets, #consume_oldest_unit, #find_rudder_state_by_key, #get_rudder_state, #get_transporter, #is_busy, #remove_rudder_state

Methods included from Common::Multiplexer

#add_rudder_state, #close_rudder, #consume_oldest_unit, #get_rudder_state, #get_transporter, #is_busy, #on_busy, #on_free, #remove_rudder_state, #req_end, #shutdown

Constructor Details

#initialize(agt) ⇒ TaxiMultiplexer

Returns a new instance of TaxiMultiplexer.



45
46
47
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 45

def initialize(agt)
  super
end

Instance Method Details

#cancel_read(st) ⇒ Object



125
126
127
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 125

def cancel_read(st)

end

#cancel_write(st) ⇒ Object



129
130
131
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 129

def cancel_write(st)

end

#do_next_read(rd) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 159

def do_next_read(rd)
  st = get_rudder_state(rd)

  begin
    len = st.rudder.read(st.read_buf, st.buf_size)
    if len <= 0
      len = 0
    end
    @agent.send_read_letter(st.id, rd, self, len, nil, true)

  rescue Exception => e
    @agent.send_error_letter(st.id, rd, self, e, true)
  end
end

#do_next_write(rd) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 174

def do_next_write(rd)
  st = get_rudder_state(rd)
  st.access

  begin
    if st.write_queue.empty?
      raise Sink("%s write queue is empty", self)
    end

    u = st.write_queue[0]
    if u.buf.length == 0
      len = 0
    else
      len = st.rudder.write(u.buf)
      u.buf.slice!(0, len)
    end
    @agent.send_wrote_letter(st.id, rd, self, len, true)

  rescue Exception => e
    @agent.send_error_letter(st.id, rd, self, e, true)
  end
end

#is_non_blockingObject



145
146
147
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 145

def is_non_blocking()
  return false
end

#next_accept(st) ⇒ Object

Raises:



133
134
135
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 133

def next_accept(st)
  raise Sink.new
end

#next_read(st) ⇒ Object



137
138
139
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 137

def next_read(st)
  next_run(st, true)
end

#next_run(st, for_read) ⇒ Object



153
154
155
156
157
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 153

def next_run(st, for_read)
  BayLog.debug("%s Post next run: %s", self, st)

  TaxiRunner.post(@agent.agent_id, TaxiForMpx.new(st, for_read))
end

#next_write(st) ⇒ Object



141
142
143
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 141

def next_write(st)
  next_run(st, false)
end

#req_accept(rd) ⇒ Object

Implements Multiplexer

Raises:



57
58
59
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 57

def req_accept(rd)
  raise Sink.new
end

#req_close(rd) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 117

def req_close(rd)
  BayLog.debug("%s reqClose rd=%s", @agent, rd);
  close_rudder(rd)
  st = get_rudder_state(rd)
  @agent.send_closed_letter(st.id, rd, self, true)
  st.access
end

#req_connect(rd, adr) ⇒ Object

Raises:



61
62
63
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 61

def req_connect(rd, adr)
  raise Sink.new
end

#req_read(rd) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 65

def req_read(rd)
  st = get_rudder_state(rd)
  if st == nil
    return
  end

  BayLog.debug("%s reqRead rd=%s state=%s", @agent, st.rudder, st);
  need_read = false
  st.reading_lock.synchronize do
    if !st.reading
      need_read = true
      st.reading = true
    end
  end

  if need_read
    next_run(st, true)
  end

  st.access
end

#req_write(rd, buf, adr, tag, &lis) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 87

def req_write(rd, buf, adr, tag, &lis)
  st = get_rudder_state(rd)
  BayLog.debug("%s reqWrite st=%s", @agent, st)

  if st == nil
    BayLog.warn("%s Channel is closed: %s", @agent, rd)
    lis.call
    return
  end

  unt = WriteUnit.new(buf, adr, tag, &lis)
  st.write_queue_lock.synchronize do
    st.write_queue << unt
  end

  need_write = false
  st.writing_lock.synchronize do
    if !st.writing
      need_write = true
      st.writing = true
    end
  end

  if need_write
    next_run(st, false)
  end

  st.access
end

#to_sObject



48
49
50
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 48

def to_s
  return "TaxiMpx[#{@agent}]"
end

#use_async_apiObject



149
150
151
# File 'lib/baykit/bayserver/agent/multiplexer/taxi_multiplexer.rb', line 149

def use_async_api()
  return false
end