Class: LanGrove::Handler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/langrove/handler_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_hash, daemon_name, logger) ⇒ Base

Returns a new instance of Base.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/langrove/handler_base.rb', line 118

def initialize( config_hash, daemon_name, logger )
  
  @config        = config_hash
  @daemon_name   = daemon_name
  @logger        = logger
  
  @clients = {}
  
  begin
  
    @logger.info "TODO: fall back to default Handler::Base"
    
    @my_config     = @config[ :daemons ][ @daemon_name ][ :handler ]

  rescue
    
    error = "Missing config item for daemon: #{@daemon_name}" 
    
    @logger.error "EXIT: #{error}"
    
    raise LanGrove::DaemonConfigException.new( 
    
      "Missing config item for daemon: #{@daemon_name}" 
      
    )
    
  end
  
end

Instance Attribute Details

#clients=(value) ⇒ Object (writeonly)

One handler exists in the daemon with the primary purpose of housing through an addressable Hash the set of connected clients,

In this:

but, NOT YET



15
16
17
# File 'lib/langrove/handler_base.rb', line 15

def clients=(value)
  @clients = value
end

#protocolObject (readonly)

The protocol defininition per the config is loaded by this Handler, but not instanciated.

This definition is then exposed,

By this:



25
26
27
# File 'lib/langrove/handler_base.rb', line 25

def protocol
  @protocol
end

Instance Method Details

#connect(client) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/langrove/handler_base.rb', line 77

def connect( client )
  
  #
  # A client has connected at the Adaptor
  # 
  # It should be inserted into the collection
  # of clients maintained here. 
  #
  @logger.debug "Client::#{client} registers with Handler#{self}"
  
  if client.respond_to?( :unique_key ) then
    
    @clients[ client.unique_key ] = client
    return
    
  end
  
  @clients[ client ] = 1
  
end

#disconnect(client) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/langrove/handler_base.rb', line 98

def disconnect( client )
  
  #
  # A client has disconnected
  # 
  # It should be removed from the collection.
  #
  
  #
  # TODO: There will likely be a callback
  #       in the EM::Connection superclass
  #       that can be used here.
  # 
  #       Client::Base extends EM::Connection
  # 
  
  @logger.info( "TODO: implement #{self.classname}disconnect()" )
  
end

#periodicObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/langrove/handler_base.rb', line 54

def periodic
  
  #
  # Call periodic on all clients
  # in the collection
  #
  
  @clients.each do |key, value|
    
    if value == 1 then
      
      key.periodic
      
      next
      
    end
    
    value.periodic
    
  end
  
end

#start_daemonObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/langrove/handler_base.rb', line 27

def start_daemon

  #
  # OVERRIDE 
  #
  # To prepare the Handler in any necessary 
  # ways before the thread is handed over to 
  # the socket listener, (or thing),
  #
  # The daemon has just started.
  #

end

#stop_daemonObject



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

def stop_daemon
  
  #
  # OVERRIDE 
  # 
  # To perfom any necessties before process
  # termination,
  #
  # The daemon has received a signal to stop.
  #
  
end