Class: Baykit::BayServer::Common::RudderState

Inherits:
Object
  • Object
show all
Includes:
Util, Util::Reusable
Defined in:
lib/baykit/bayserver/common/rudder_state.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRudderState

Returns a new instance of RudderState.



40
41
42
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 40

def initialize

end

Class Attribute Details

.id_counterObject (readonly)

Returns the value of attribute id_counter.



12
13
14
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 12

def id_counter
  @id_counter
end

Instance Attribute Details

#acceptingObject

Returns the value of attribute accepting.



37
38
39
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 37

def accepting
  @accepting
end

#buf_sizeObject (readonly)

Returns the value of attribute buf_size.



25
26
27
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 25

def buf_size
  @buf_size
end

#bytes_readObject

Returns the value of attribute bytes_read.



30
31
32
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 30

def bytes_read
  @bytes_read
end

#bytes_wroteObject

Returns the value of attribute bytes_wrote.



31
32
33
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 31

def bytes_wrote
  @bytes_wrote
end

#closingObject

Returns the value of attribute closing.



23
24
25
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 23

def closing
  @closing
end

#connectingObject

Returns the value of attribute connecting.



38
39
40
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 38

def connecting
  @connecting
end

#finaleObject

Returns the value of attribute finale.



35
36
37
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 35

def finale
  @finale
end

#handshakingObject

Returns the value of attribute handshaking.



27
28
29
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 27

def handshaking
  @handshaking
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 16

def id
  @id
end

#last_access_timeObject (readonly)

Returns the value of attribute last_access_time.



22
23
24
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 22

def last_access_time
  @last_access_time
end

#multiplexerObject

Returns the value of attribute multiplexer.



20
21
22
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 20

def multiplexer
  @multiplexer
end

#read_bufObject (readonly)

Returns the value of attribute read_buf.



24
25
26
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 24

def read_buf
  @read_buf
end

#readingObject

Returns the value of attribute reading.



28
29
30
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 28

def reading
  @reading
end

#reading_lockObject (readonly)

Returns the value of attribute reading_lock.



33
34
35
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 33

def reading_lock
  @reading_lock
end

#rudderObject (readonly)

Returns the value of attribute rudder.



18
19
20
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 18

def rudder
  @rudder
end

#transporterObject (readonly)

Returns the value of attribute transporter.



19
20
21
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 19

def transporter
  @transporter
end

#write_queueObject (readonly)

Returns the value of attribute write_queue.



26
27
28
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 26

def write_queue
  @write_queue
end

#write_queue_lockObject (readonly)

Returns the value of attribute write_queue_lock.



32
33
34
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 32

def write_queue_lock
  @write_queue_lock
end

#writingObject

Returns the value of attribute writing.



29
30
31
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 29

def writing
  @writing
end

#writing_lockObject (readonly)

Returns the value of attribute writing_lock.



34
35
36
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 34

def writing_lock
  @writing_lock
end

Instance Method Details

#accessObject

Custom methods



101
102
103
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 101

def access
  @last_access_time = Time.now.tv_sec
end

#endObject



105
106
107
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 105

def end
  @finale = true
end

#init(rd, tp = nil, timeout_sec = 0) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 44

def init(rd, tp = nil, timeout_sec = 0)
  @id = RudderState.id_counter.next
  @rudder = rd
  @transporter = tp
  @timeout_sec = timeout_sec

  if tp != nil
    @buf_size = tp.get_read_buffer_size
    @handshaking = tp.secure() ? true : false
  else
    @buf_size = 8192
    @handshaking = false
  end
  @read_buf = " ".b * @buf_size

  @accepting = false
  @connecting = false
  @write_queue = []
  @write_queue_lock = Mutex::new
  @reading_lock = Mutex::new
  @writing_lock = Mutex::new
  @reading = false
  @writing = false
  @bytes_read = 0
  @bytes_wrote = 0
end

#resetObject

Implements Reusable



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 79

def reset()
  @id = 0
  @rudder = nil
  @transporter = nil
  @multiplexer = nil

  @last_access_time = 0
  @closing = false
  @read_buf.clear
  @write_queue = []
  @bytes_read = 0
  @bytes_wrote = 0
  @finale = false
  @reading = false
  @writing = false
  @timeout_sec = 0
end

#to_sObject



71
72
73
74
# File 'lib/baykit/bayserver/common/rudder_state.rb', line 71

def to_s
  str = "st(rd=#{@rudder} mpx=#{@multiplexer} tp=#{@transporter})"
  return str
end