Class: Thingfish::Handler
- Inherits:
-
Strelka::App
- Object
- Strelka::App
- Thingfish::Handler
- Extended by:
- Configurability, Loggability, Strelka::MethodUtilities
- Defined in:
- lib/thingfish/handler.rb
Overview
Network-accessable datastore service
Constant Summary collapse
- ID =
Strelka App ID
'thingfish'
- CONFIG_DEFAULTS =
Configurability API – set config defaults
{ datastore: 'memory', metastore: 'memory', processors: [], event_socket_uri: 'tcp://127.0.0.1:3475', }
- OPERATIONAL_METADATA_KEYS =
Metadata keys which aren’t directly modifiable via the REST API :TODO: Consider making either all of these or a subset of them
be immutable.
%w[ format extent created uploadaddress ]
- REQUIRED_RELATED_METADATA_KEYS =
Metadata keys that must be provided by plugins for related resources
%w[ relationship format ]
Instance Attribute Summary collapse
-
#datastore ⇒ Object
readonly
The datastore.
-
#event_socket ⇒ Object
readonly
The PUB socket on which resource events are published.
-
#metastore ⇒ Object
readonly
The metastore.
Class Method Summary collapse
-
.configure(config = nil) ⇒ Object
Configurability API – install the configuration.
-
.load_processors(processor_list) ⇒ Object
Load the Thingfish::Processors in the given
processor_list
and return an instance of each one.
Instance Method Summary collapse
-
#initialize ⇒ Handler
constructor
Set up the metastore, datastore, and event socket when the handler is created.
-
#restart ⇒ Object
Restart handler hook.
-
#run ⇒ Object
Run the handler – overridden to set up the event socket on startup.
-
#setup_event_socket ⇒ Object
Set up the event socket.
-
#shutdown ⇒ Object
Shutdown handler hook.
-
#thingfish ⇒ Object
Configurability API.
Constructor Details
#initialize ⇒ Handler
Set up the metastore, datastore, and event socket when the handler is created.
117 118 119 120 121 122 123 |
# File 'lib/thingfish/handler.rb', line 117 def initialize( * ) # :notnew: super @datastore = Thingfish::Datastore.create( self.class.datastore ) @metastore = Thingfish::Metastore.create( self.class. ) @event_socket = nil end |
Instance Attribute Details
#datastore ⇒ Object (readonly)
The datastore
131 132 133 |
# File 'lib/thingfish/handler.rb', line 131 def datastore @datastore end |
#event_socket ⇒ Object (readonly)
The PUB socket on which resource events are published
137 138 139 |
# File 'lib/thingfish/handler.rb', line 137 def event_socket @event_socket end |
#metastore ⇒ Object (readonly)
The metastore
134 135 136 |
# File 'lib/thingfish/handler.rb', line 134 def @metastore end |
Class Method Details
.configure(config = nil) ⇒ Object
Configurability API – install the configuration
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/thingfish/handler.rb', line 98 def self::configure( config=nil ) config = self.defaults.merge( config || {} ) self.datastore = config[:datastore] self. = config[:metastore] self.event_socket_uri = config[:event_socket_uri] self.plugin( :filters ) # pre-load the filters plugin for deferred config self.processors = self.load_processors( config[:processors] ) self.processors.each do |processor| self.filter( :request, &processor.method(:process_request) ) self.filter( :response, &processor.method(:process_response) ) end end |
.load_processors(processor_list) ⇒ Object
Load the Thingfish::Processors in the given processor_list
and return an instance of each one.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/thingfish/handler.rb', line 79 def self::load_processors( processor_list ) self.log.info "Loading processors" processors = [] processor_list.each do |processor_type| begin processors << Thingfish::Processor.create( processor_type ) self.log.debug " loaded %s: %p" % [ processor_type, processors.last ] rescue LoadError => err self.log.error "%p: %s while loading the %s processor" % [ err.class, err., processor_type ] end end return processors end |
Instance Method Details
#restart ⇒ Object
Restart handler hook.
165 166 167 168 169 170 171 172 173 |
# File 'lib/thingfish/handler.rb', line 165 def restart if self.event_socket oldsock = @event_socket @event_socket = @event_socket.dup oldsock.close end super end |
#run ⇒ Object
Run the handler – overridden to set up the event socket on startup.
141 142 143 144 |
# File 'lib/thingfish/handler.rb', line 141 def run self.setup_event_socket super end |
#setup_event_socket ⇒ Object
Set up the event socket.
148 149 150 151 152 153 154 |
# File 'lib/thingfish/handler.rb', line 148 def setup_event_socket if self.class.event_socket_uri && ! @event_socket @event_socket = CZTop::Socket::PUB.new @event_socket..linger = 0 @event_socket.bind( self.class.event_socket_uri ) end end |
#shutdown ⇒ Object
Shutdown handler hook.
158 159 160 161 |
# File 'lib/thingfish/handler.rb', line 158 def shutdown self.event_socket.close if self.event_socket super end |
#thingfish ⇒ Object
Configurability API
62 |
# File 'lib/thingfish/handler.rb', line 62 config_key :thingfish |