Class: Quark::MdkDiscovery::Synapse::SynapseSource
- Inherits:
-
DatawireQuarkCore::QuarkObject
- Object
- DatawireQuarkCore::QuarkObject
- Quark::MdkDiscovery::Synapse::SynapseSource
- Extended by:
- DatawireQuarkCore::Static
- Defined in:
- lib/mdk_discovery/synapse.rb
Overview
Implementation of the Synapse discovery source.
Constant Summary
Constants included from DatawireQuarkCore::Static
DatawireQuarkCore::Static::Unassigned
Instance Attribute Summary collapse
-
#directory_path ⇒ Object
Returns the value of attribute directory_path.
-
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#files ⇒ Object
Returns the value of attribute files.
-
#subscriber ⇒ Object
Returns the value of attribute subscriber.
Instance Method Summary collapse
- #__init_fields__ ⇒ Object
- #_getClass ⇒ Object
- #_getField(name) ⇒ Object
-
#_pathToServiceName(filename) ⇒ Object
Convert ‘/path/to/service_name.json’ to ‘service_name’.
- #_setField(name, value) ⇒ Object
-
#_update(service, nodes) ⇒ Object
Send an appropriate update to the subscriber for this DiscoverySource.
-
#initialize(subscriber, directory_path, runtime, environment) ⇒ SynapseSource
constructor
A new instance of SynapseSource.
- #onMessage(origin, message) ⇒ Object
- #onStart(dispatcher) ⇒ Object
-
#onStop ⇒ Object
The Actor should begin shutting down.
Methods included from DatawireQuarkCore::Static
_lazy_statics, static, unlazy_statics
Methods inherited from DatawireQuarkCore::QuarkObject
Constructor Details
#initialize(subscriber, directory_path, runtime, environment) ⇒ SynapseSource
Returns a new instance of SynapseSource.
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/mdk_discovery/synapse.rb', line 127 def initialize(subscriber, directory_path, runtime, environment) self.__init_fields__ (self).subscriber = subscriber (self).directory_path = directory_path (self).files = runtime.getFileService() (self).environment = environment nil end |
Instance Attribute Details
#directory_path ⇒ Object
Returns the value of attribute directory_path.
120 121 122 |
# File 'lib/mdk_discovery/synapse.rb', line 120 def directory_path @directory_path end |
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
120 121 122 |
# File 'lib/mdk_discovery/synapse.rb', line 120 def dispatcher @dispatcher end |
#environment ⇒ Object
Returns the value of attribute environment.
120 121 122 |
# File 'lib/mdk_discovery/synapse.rb', line 120 def environment @environment end |
#files ⇒ Object
Returns the value of attribute files.
120 121 122 |
# File 'lib/mdk_discovery/synapse.rb', line 120 def files @files end |
#subscriber ⇒ Object
Returns the value of attribute subscriber.
120 121 122 |
# File 'lib/mdk_discovery/synapse.rb', line 120 def subscriber @subscriber end |
Instance Method Details
#__init_fields__ ⇒ Object
269 270 271 272 273 274 275 276 277 278 |
# File 'lib/mdk_discovery/synapse.rb', line 269 def __init_fields__() self.subscriber = nil self.directory_path = nil self.files = nil self.dispatcher = nil self.environment = nil nil end |
#_getClass ⇒ Object
209 210 211 212 213 214 |
# File 'lib/mdk_discovery/synapse.rb', line 209 def _getClass() return "mdk_discovery.synapse._SynapseSource" nil end |
#_getField(name) ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/mdk_discovery/synapse.rb', line 216 def _getField(name) if ((name) == ("subscriber")) return (self).subscriber end if ((name) == ("directory_path")) return (self).directory_path end if ((name) == ("files")) return (self).files end if ((name) == ("dispatcher")) return (self).dispatcher end if ((name) == ("environment")) return (self).environment end return nil nil end |
#_pathToServiceName(filename) ⇒ Object
Convert ‘/path/to/service_name.json’ to ‘service_name’.
152 153 154 155 156 157 158 159 |
# File 'lib/mdk_discovery/synapse.rb', line 152 def _pathToServiceName(filename) parts = ::DatawireQuarkCore.split(filename, "/") service = (parts)[((parts).size) - (1)] return (service)[(0)...(((service).size) - (5))] nil end |
#_setField(name, value) ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/mdk_discovery/synapse.rb', line 238 def _setField(name, value) if ((name) == ("subscriber")) (self).subscriber = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_runtime.actors.Actor } end if ((name) == ("directory_path")) (self).directory_path = ::DatawireQuarkCore.cast(value) { ::String } end if ((name) == ("files")) (self).files = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_runtime.files.FileActor } end if ((name) == ("dispatcher")) (self).dispatcher = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_runtime.actors.MessageDispatcher } end if ((name) == ("environment")) (self).environment = ::DatawireQuarkCore.cast(value) { ::Quark.mdk_protocol.OperationalEnvironment } end nil end |
#_update(service, nodes) ⇒ Object
Send an appropriate update to the subscriber for this DiscoverySource.
164 165 166 167 168 169 |
# File 'lib/mdk_discovery/synapse.rb', line 164 def _update(service, nodes) (self).dispatcher.tell(self, ::Quark.mdk_discovery.ReplaceCluster.new(service, (self).environment, nodes), (self).subscriber) nil end |
#onMessage(origin, message) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/mdk_discovery/synapse.rb', line 171 def onMessage(origin, ) typeId = (::Quark.quark.reflect.QuarkClass.get(::DatawireQuarkCore._getClass())).id service = nil if ((typeId) == ("mdk_runtime.files.FileContents")) contents = ::DatawireQuarkCore.cast() { ::Quark.mdk_runtime.files.FileContents } if (!(((contents).path).end_with?(".json"))) return end service = self._pathToServiceName((contents).path) json = ::DatawireQuarkCore::JSONObject.parse((contents).contents) nodes = ::DatawireQuarkCore::List.new([]) idx = 0 while ((idx) < (json.size())) do entry = json.getListItem(idx) node = ::Quark.mdk_discovery.Node.new() (node).id = ::Quark.quark.concurrent.Context.runtime().uuid() (node).service = service (node).version = "1.0" host = entry.getObjectItem("host").getString() port = ((entry.getObjectItem("port").getNumber()).round()).to_s (node).address = ((host) + (":")) + (port) (nodes) << (node) idx = (idx) + (1) end self._update(service, nodes) return end if ((typeId) == ("mdk_runtime.files.FileDeleted")) deleted = ::DatawireQuarkCore.cast() { ::Quark.mdk_runtime.files.FileDeleted } service = self._pathToServiceName((deleted).path) self._update(service, ::DatawireQuarkCore::List.new([])) return end nil end |
#onStart(dispatcher) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/mdk_discovery/synapse.rb', line 141 def onStart(dispatcher) (self).dispatcher = dispatcher (self).dispatcher.tell(self, ::Quark.mdk_runtime.files.SubscribeChanges.new((self).directory_path), (self).files) nil end |
#onStop ⇒ Object
The Actor should begin shutting down.
262 263 264 265 266 267 |
# File 'lib/mdk_discovery/synapse.rb', line 262 def onStop() nil nil end |