Class: Tupelo::PersistentArchiver

Inherits:
Client show all
Includes:
Funl::HistoryClient
Defined in:
lib/tupelo/tuplets/persistent-archiver.rb,
lib/tupelo/tuplets/persistent-archiver.rb,
lib/tupelo/tuplets/persistent-archiver/worker.rb

Defined Under Namespace

Classes: ForkRequest, Worker

Constant Summary collapse

ZERO_TOLERANCE =

How many tuples with count=0 do we permit before cleaning up?

1000

Constants inherited from Client

Client::TUPELO_META_KEY, Client::TUPELO_SUBSPACE_TAG

Instance Attribute Summary collapse

Attributes inherited from Client

#tuplespace, #worker

Instance Method Summary collapse

Methods inherited from Client

#inspect, #log, #make_queue, #make_scheduler, #or, #trace_loop, #tracing?

Methods included from Client::Api

#abort, #define_subspace, #notifier, #pulse_nowait, #pulse_wait, #read_all, #read_nowait, #read_wait, #subspace, #take, #take_nowait, #trans_class, #transaction, #use_subspaces!, #write_nowait, #write_wait

Constructor Details

#initialize(server, **opts) ⇒ PersistentArchiver

Returns a new instance of PersistentArchiver.



19
20
21
22
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 19

def initialize server, **opts
  super arc: nil, tuplespace: Tupelo::PersistentArchiver::Tuplespace, **opts
  @server = server
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



13
14
15
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 13

def server
  @server
end

#server_threadObject (readonly)

Returns the value of attribute server_thread.



14
15
16
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 14

def server_thread
  @server_thread
end

Instance Method Details

#handle_conn(conn) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 76

def handle_conn conn
  log.debug {"accepted #{conn.inspect}"}
  begin
    worker << ForkRequest.new(conn)
  rescue => ex
    log.error ex
    raise
  end
end

#make_workerObject



45
46
47
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 45

def make_worker
  Tupelo::PersistentArchiver::Worker.new self
end

#runObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 62

def run
  loop do
    ## nonblock_accept?
    Thread.new(server.accept) do |conn|
      handle_conn conn
    end

    ## periodically send worker request to dump space to file?
  end
rescue => ex
  log.error ex
  raise
end

#startObject



49
50
51
52
53
54
55
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 49

def start
  ## load from file?
  super # start worker thread
  @server_thread = Thread.new do
    run
  end
end

#stopObject



57
58
59
60
# File 'lib/tupelo/tuplets/persistent-archiver.rb', line 57

def stop
  server_thread.kill if server_thread
  super # stop worker thread
end