Class: Hoss::Transport::Base Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/hoss/transport/base.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

WATCHER_EXECUTION_INTERVAL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

5
WATCHER_TIMEOUT_INTERVAL =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

4
WORKER_JOIN_TIMEOUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

5

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Base.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hoss/transport/base.rb', line 41

def initialize(config)
  @config = config
  @queue = SizedQueue.new(config.max_queue_size)

  @serializers = Serializers.new(config)
  @filters = Filters.new(config)

  @stopped = Concurrent::AtomicBoolean.new
  @workers = Array.new(config.pool_size)

  @worker_mutex = Mutex.new
end

Instance Attribute Details

#configObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/hoss/transport/base.rb', line 54

def config
  @config
end

#filtersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/hoss/transport/base.rb', line 54

def filters
  @filters
end

#queueObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/hoss/transport/base.rb', line 54

def queue
  @queue
end

#stoppedObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/hoss/transport/base.rb', line 54

def stopped
  @stopped
end

#watcherObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/hoss/transport/base.rb', line 54

def watcher
  @watcher
end

#workersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
# File 'lib/hoss/transport/base.rb', line 54

def workers
  @workers
end

Instance Method Details

#add_filter(key, callback) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



94
95
96
# File 'lib/hoss/transport/base.rb', line 94

def add_filter(key, callback)
  @filters.add(key, callback)
end

#handle_forking!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



98
99
100
101
102
103
104
105
# File 'lib/hoss/transport/base.rb', line 98

def handle_forking!
  # We can't just stop and start again because the StopMessage
  # will then be the first message processed when the transport is
  # restarted.
  stop_watcher
  ensure_worker_count
  create_watcher
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
64
65
# File 'lib/hoss/transport/base.rb', line 56

def start
  debug '%s: Starting Transport', pid_str
  # Set @stopped to false first, in case transport is restarted;
  # ensure_worker_count requires @stopped to be false
  # ~estolfo
  @stopped.make_false unless @stopped.false?

  ensure_worker_count
  create_watcher
end

#stopObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
70
71
72
73
74
# File 'lib/hoss/transport/base.rb', line 67

def stop
  debug '%s: Stopping Transport', pid_str

  @stopped.make_true

  stop_watcher
  stop_workers
end

#submit(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/hoss/transport/base.rb', line 76

def submit(resource)
  if @stopped.true?
    warn '%s: Transport stopping, no new events accepted', pid_str
    debug 'Dropping: %s', resource.inspect
    return false
  end

  queue.push(resource, true)

  true
rescue ThreadError
  throttled_queue_full_warning
  nil
rescue Exception => e
  error '%s: Failed adding to the transport queue: %p', pid_str, e.inspect
  nil
end