Class: Funl::Client

Inherits:
Object
  • Object
show all
Includes:
Stream
Defined in:
lib/funl/client.rb

Overview

Generic client base class. Manages the setup and handshake on the streams to the client sequencer and the message sequencer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Stream

#client_stream_for, #message_server_stream_for, #server_stream_for

Constructor Details

#initialize(seq: seq!, , cseq: cseq!, , arc: nil, log: Logger.new($stderr), stream_type: ObjectStream::MSGPACK_TYPE, message_class: Message) ⇒ Client

Returns a new instance of Client.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/funl/client.rb', line 24

def initialize(seq: seq!, cseq: cseq!, arc: nil,
      log: Logger.new($stderr),
      stream_type: ObjectStream::MSGPACK_TYPE,
      message_class: Message)

  @log = log
  @stream_type = stream_type ## discover this thru connections
  @message_class = message_class

  @seq = client_stream_for(seq)
  @cseq = client_stream_for(cseq)
  @arcio = arc
end

Instance Attribute Details

#arcObject (readonly)

Returns the value of attribute arc.



14
15
16
# File 'lib/funl/client.rb', line 14

def arc
  @arc
end

#blob_typeObject (readonly)

Returns the value of attribute blob_type.



21
22
23
# File 'lib/funl/client.rb', line 21

def blob_type
  @blob_type
end

#blobberObject (readonly)

Returns the value of attribute blobber.



22
23
24
# File 'lib/funl/client.rb', line 22

def blobber
  @blobber
end

#client_idObject (readonly)

Returns the value of attribute client_id.



18
19
20
# File 'lib/funl/client.rb', line 18

def client_id
  @client_id
end

#cseqObject (readonly)

Returns the value of attribute cseq.



13
14
15
# File 'lib/funl/client.rb', line 13

def cseq
  @cseq
end

#greetingObject (readonly)

Returns the value of attribute greeting.



19
20
21
# File 'lib/funl/client.rb', line 19

def greeting
  @greeting
end

#logObject (readonly)

Returns the value of attribute log.



15
16
17
# File 'lib/funl/client.rb', line 15

def log
  @log
end

#message_classObject (readonly)

Returns the value of attribute message_class.



17
18
19
# File 'lib/funl/client.rb', line 17

def message_class
  @message_class
end

#seqObject (readonly)

Returns the value of attribute seq.



12
13
14
# File 'lib/funl/client.rb', line 12

def seq
  @seq
end

#start_tickObject (readonly)

Returns the value of attribute start_tick.



20
21
22
# File 'lib/funl/client.rb', line 20

def start_tick
  @start_tick
end

#stream_typeObject (readonly)

Returns the value of attribute stream_type.



16
17
18
# File 'lib/funl/client.rb', line 16

def stream_type
  @stream_type
end

Instance Method Details

#arc_server_stream_for(io) ⇒ Object



69
70
71
72
# File 'lib/funl/client.rb', line 69

def arc_server_stream_for io
  server_stream_for(io, type: blob_type)
    # note: blob_type, not stream_type, since we are sending bare objects
end

#cseq_read_client_idObject



47
48
49
50
51
52
53
# File 'lib/funl/client.rb', line 47

def cseq_read_client_id
  log.debug "getting client_id from cseq"
  @client_id = cseq.read["client_id"]
  log.info "client_id = #{client_id}"
  cseq.close rescue nil
  @cseq = nil
end

#seq_read_greetingObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/funl/client.rb', line 55

def seq_read_greeting
  log.debug "getting greeting from seq"
  @greeting = seq.read
  @start_tick = greeting["tick"]
  log.info "start_tick = #{start_tick}"
  @blob_type = greeting["blob"]
  log.info "blob_type = #{blob_type}"
  @blobber = Blobber.for(blob_type)
  seq.expect message_class

  @arc = @arcio && client_stream_for(@arcio, type: blob_type)
    # note: @arc is nil when client is the archiver itself
end

#startObject

Handshake with both cseq and seq. Does not start any threads–that is left to subclasses. Yields after getting client id so that caller can set log.progname, for example.



41
42
43
44
45
# File 'lib/funl/client.rb', line 41

def start
  cseq_read_client_id
  yield if block_given?
  seq_read_greeting
end