Module: LanGrove::Handler
- Included in:
- Base, Deferred, SocketBase
- Defined in:
- lib/langrove/handler/socket_multiplexer.rb,
lib/langrove/handler/base.rb,
lib/langrove/handler/socket.rb,
lib/langrove/handler/deferred.rb,
lib/langrove/handler/web_socket.rb,
lib/langrove/handler/socket_base.rb,
lib/langrove/handler/handler_base.rb,
lib/langrove/handler/http_servlet.rb
Overview
Occasionally a daemon is required to maintain multiple handlers in state, each receiving data asymetrically from an already aggregated source.
eg. A post accumulated syslog stream being forwarded
to the local daemon containing log events from
the entire network.
This stream would arrive on a single socket to which there would therefore be only one attached Handler in the Daemon (per the pattern)
The purpose of this de-multiplexer is to re-align this situation back to pattern.
ie. To arrive at the situation where there is a representative
entity present in the local Server for each connected Client,
even if only connected 'virtually' via the remote proxy.
Allowing therefore the unmodified application of Behaviours
to these representative Handlers.
Defined Under Namespace
Modules: SocketBase Classes: Base, Deferred, HttpServlet, Socket, SocketMultiplexer, WebSocket
Constant Summary collapse
Instance Attribute Summary collapse
-
#capsule ⇒ Object
Handler contains a ‘capsule’ of data to be maniplulated by the implementor toward achieving their architected goal.
-
#config ⇒ Object
Returns the value of attribute config.
-
#key ⇒ Object
key contains the persistance storage address for the capsule.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#pending_capsule ⇒ Object
pending_capsule is populated with the first received message and is used as source to construct the (storage) key.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#scheduler ⇒ Object
Returns the value of attribute scheduler.
-
#server ⇒ Object
Returns the value of attribute server.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #assign(parameters) ⇒ Object
- #connect ⇒ Object
- #disconnect ⇒ Object
- #error(err) ⇒ Object
- #event_filter(type, object) {|object| ... } ⇒ Object
- #receive(decoded_data) ⇒ Object
- #reload ⇒ Object
- #reload_handler ⇒ Object
-
#start ⇒ Object
Event Callbacks.
- #start_handler ⇒ Object
- #stop ⇒ Object
- #stop_handler ⇒ Object
- #transform(type, object) {|object| ... } ⇒ Object
- #unique ⇒ Object
Instance Attribute Details
#capsule ⇒ Object
Handler contains a ‘capsule’ of data to be maniplulated by the implementor toward achieving their architected goal.
-
It is stored in the @capsule instance variable.
-
It is acted upon by certain of the built in Behaviours
-
Is is accessable through the following attribute
23 24 25 |
# File 'lib/langrove/handler/handler_base.rb', line 23 def capsule @capsule end |
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/langrove/handler/handler_base.rb', line 11 def config @config end |
#key ⇒ Object
key contains the persistance storage address for the capsule
35 36 37 |
# File 'lib/langrove/handler/handler_base.rb', line 35 def key @key end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/langrove/handler/handler_base.rb', line 10 def logger @logger end |
#pending_capsule ⇒ Object
pending_capsule is populated with the first received message and is used as source to construct the (storage) key
29 30 31 |
# File 'lib/langrove/handler/handler_base.rb', line 29 def pending_capsule @pending_capsule end |
#protocol ⇒ Object
Returns the value of attribute protocol.
8 9 10 |
# File 'lib/langrove/handler/handler_base.rb', line 8 def protocol @protocol end |
#scheduler ⇒ Object
Returns the value of attribute scheduler.
9 10 11 |
# File 'lib/langrove/handler/handler_base.rb', line 9 def scheduler @scheduler end |
#server ⇒ Object
Returns the value of attribute server.
7 8 9 |
# File 'lib/langrove/handler/handler_base.rb', line 7 def server @server end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/langrove/handler/handler_base.rb', line 5 def type @type end |
Instance Method Details
#assign(parameters) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/langrove/handler/handler_base.rb', line 200 def assign( parameters ) @root = parameters[ :root ] @logger = @root.logger @type = :handler @capsule = {} if @capsule.nil? @key = nil @pending_capsule = nil # # Assigns daemon infrastructure # to sub process Handler (this) # self.config = parameters[ :handler ][ :config ] # # Bind to (own instance) of Protocol + Protocol Config # self.protocol = parameters[ :protocol ][ :class ].new( @root, parameters[ :protocol ][ :config ], nil ) # # Bind to Server # self.server = parameters[ :server ] parameters[ :server ].connect( self ) end |
#connect ⇒ Object
48 |
# File 'lib/langrove/handler/handler_base.rb', line 48 def connect; end |
#disconnect ⇒ Object
50 |
# File 'lib/langrove/handler/handler_base.rb', line 50 def disconnect; end |
#error(err) ⇒ Object
52 |
# File 'lib/langrove/handler/handler_base.rb', line 52 def error( err ); end |
#event_filter(type, object) {|object| ... } ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/langrove/handler/handler_base.rb', line 67 def event_filter( type, object, &block ) # # OVERRIDE # # Certain behaviours call back through this filter # on the handler. # # The implementor can override this to affect control # over certain of the internal event pipelines. # # By not yielding into the block, the implementor can # prevent the <object> from traversing further. # # # <type> # # Refers to which behaviour is calling back for # filtration. # # These include: # # :notification - A notification is about to be # triggered. # # <object> # # The notification. # # <&block> # # This block to yield into after choosing to allow # the event to traverse further. # yield object if block end |
#receive(decoded_data) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/langrove/handler/handler_base.rb', line 54 def receive( decoded_data ) # # OVERRIDE # @capsule = decoded_data end |
#reload ⇒ Object
46 |
# File 'lib/langrove/handler/handler_base.rb', line 46 def reload; end |
#reload_handler ⇒ Object
172 173 174 175 176 177 178 |
# File 'lib/langrove/handler/handler_base.rb', line 172 def reload_handler @root.trigger( self, :handler, :reload ) reload end |
#start ⇒ Object
Event Callbacks
42 |
# File 'lib/langrove/handler/handler_base.rb', line 42 def start; end |
#start_handler ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/langrove/handler/handler_base.rb', line 146 def start_handler @logger.debug "#{self}.start_handler()" # # trigger event # @root.trigger( self, :handler, :start ) # # call overridable # start end |
#stop ⇒ Object
44 |
# File 'lib/langrove/handler/handler_base.rb', line 44 def stop; end |
#stop_handler ⇒ Object
164 165 166 167 168 169 170 |
# File 'lib/langrove/handler/handler_base.rb', line 164 def stop_handler @root.trigger( self, :handler, :stop ) stop end |
#transform(type, object) {|object| ... } ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 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 |
# File 'lib/langrove/handler/handler_base.rb', line 106 def transform( type, object, &block ) # # OVERRIDE # # Certain of the behaviours call through this transform # to adjust the data format of the capsule. # # eg. The notifier requires a notification to be assembled # into the format for the destination system. # # <type> # # Refers to which behaviour is calling back for # transformation. # # These include: # # :notification - A notification is about to be # triggered. # # # # <object> # # The notification. Usually the 'capsule' and enqueued # # # Default is no transform # yield object # # Return false if the notification should not go ahead # return true end |
#unique ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/langrove/handler/handler_base.rb', line 180 def unique raise LanGrove::DaemonConfigException.new( "Called unique without :unique: key specified" ) if @config[:unique].nil? unique = @capsule[@config[:unique]] raise LanGrove::RuntimeException.new( "Missing value for :unique: #{@config[:unique]}" ) if unique.nil? return unique end |