Class: Vigilem::Core::Hub

Inherits:
Object
  • Object
show all
Extended by:
Support::ObjSpace
Defined in:
lib/vigilem/core/hub.rb

Overview

copies events or messages from the system to all the attached buffers except the link, much like a network hub

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group) ⇒ Hub

Returns a new instance of Hub.

Parameters:

  • group


12
13
14
15
# File 'lib/vigilem/core/hub.rb', line 12

def initialize(group)
  @group_id = group
  @buffers = []
end

Instance Attribute Details

#buffersObject (readonly)

Returns the value of attribute buffers.



9
10
11
# File 'lib/vigilem/core/hub.rb', line 9

def buffers
  @buffers
end

#group_idObject (readonly)

Returns the value of attribute group_id.



9
10
11
# File 'lib/vigilem/core/hub.rb', line 9

def group_id
  @group_id
end

Class Method Details

.aquire(grp_id) ⇒ Hub

finds a hub based on a group identifier, if no Hub is found a new one is returned

Parameters:

  • link

    the link registered for a hub

Returns:

  • (Hub)

    the hub for passed in link



45
46
47
# File 'lib/vigilem/core/hub.rb', line 45

def aquire(grp_id)
  all.find {|hub| hub.group_id == grp_id } || obj_register(new(grp_id))
end

Instance Method Details

#add_buffer(buffer) ⇒ Object Also known as: <<

Returns self is expected like array.

Parameters:

  • buffer (EventBuffer)

    that will receive events from the hub

Returns:

  • self is expected like array



20
21
22
23
# File 'lib/vigilem/core/hub.rb', line 20

def add_buffer(buffer)
  @buffers << buffer
  self
end

#demux(buff, *msgs) ⇒ Array

Returns the buffers that got updated.

Parameters:

  • msgs (Array)

    the messages to push out

Returns:

  • (Array)

    the buffers that got updated



30
31
32
33
34
# File 'lib/vigilem/core/hub.rb', line 30

def demux(buff, *msgs)
  buffers.select do |buffer| 
    buffer.concat(msgs) if (not msgs.empty?) and (not buffer.equal?(buff))
  end
end