Class: Quark::Quark::Behaviors::RPC
- Inherits:
-
DatawireQuarkCore::QuarkObject
- Object
- DatawireQuarkCore::QuarkObject
- Quark::Quark::Behaviors::RPC
- Extended by:
- DatawireQuarkCore::Static
- Defined in:
- lib/quark/behaviors.rb
Constant Summary
Constants included from DatawireQuarkCore::Static
DatawireQuarkCore::Static::Unassigned
Instance Attribute Summary collapse
-
#instance ⇒ Object
Returns the value of attribute instance.
-
#methodName ⇒ Object
Returns the value of attribute methodName.
-
#returned ⇒ Object
Returns the value of attribute returned.
-
#service ⇒ Object
Returns the value of attribute service.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #__init_fields__ ⇒ Object
- #_getClass ⇒ Object
- #_getField(name) ⇒ Object
- #_setField(name, value) ⇒ Object
- #call(args) ⇒ Object
- #fail(info) ⇒ Object
-
#initialize(service, methodName) ⇒ RPC
constructor
A new instance of RPC.
- #succeed(info) ⇒ Object
- #toString ⇒ Object
Methods included from DatawireQuarkCore::Static
_lazy_statics, static, unlazy_statics
Methods inherited from DatawireQuarkCore::QuarkObject
Constructor Details
#initialize(service, methodName) ⇒ RPC
Returns a new instance of RPC.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/quark/behaviors.rb', line 78 def initialize(service, methodName) self.__init_fields__ timeout = ::DatawireQuarkCore.cast((service)._getField("timeout")) { ::Float } if (((timeout) == (nil)) || ((timeout) <= (0.0))) timeout = 10.0 end override = service.getTimeout() if (((override) != (nil)) && ((override) > (0.0))) timeout = override end (self).returned = ::Quark.quark.reflect.QuarkClass.get(::DatawireQuarkCore._getClass(service)).getMethod(methodName).getType() (self).timeout = timeout (self).methodName = methodName (self).service = service nil end |
Instance Attribute Details
#instance ⇒ Object
Returns the value of attribute instance.
71 72 73 |
# File 'lib/quark/behaviors.rb', line 71 def instance @instance end |
#methodName ⇒ Object
Returns the value of attribute methodName.
71 72 73 |
# File 'lib/quark/behaviors.rb', line 71 def methodName @methodName end |
#returned ⇒ Object
Returns the value of attribute returned.
71 72 73 |
# File 'lib/quark/behaviors.rb', line 71 def returned @returned end |
#service ⇒ Object
Returns the value of attribute service.
71 72 73 |
# File 'lib/quark/behaviors.rb', line 71 def service @service end |
#timeout ⇒ Object
Returns the value of attribute timeout.
71 72 73 |
# File 'lib/quark/behaviors.rb', line 71 def timeout @timeout end |
Instance Method Details
#__init_fields__ ⇒ Object
197 198 199 200 201 202 203 204 205 206 |
# File 'lib/quark/behaviors.rb', line 197 def __init_fields__() self.service = nil self.returned = nil self.timeout = nil self.methodName = nil self.instance = nil nil end |
#_getClass ⇒ Object
147 148 149 150 151 152 |
# File 'lib/quark/behaviors.rb', line 147 def _getClass() return "quark.behaviors.RPC" nil end |
#_getField(name) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/quark/behaviors.rb', line 154 def _getField(name) if ((name) == ("service")) return (self).service end if ((name) == ("returned")) return (self).returned end if ((name) == ("timeout")) return (self).timeout end if ((name) == ("methodName")) return (self).methodName end if ((name) == ("instance")) return (self).instance end return nil nil end |
#_setField(name, value) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/quark/behaviors.rb', line 176 def _setField(name, value) if ((name) == ("service")) (self).service = ::DatawireQuarkCore.cast(value) { ::Quark.quark.Service } end if ((name) == ("returned")) (self).returned = ::DatawireQuarkCore.cast(value) { ::Quark.quark.reflect.QuarkClass } end if ((name) == ("timeout")) (self).timeout = ::DatawireQuarkCore.cast(value) { ::Float } end if ((name) == ("methodName")) (self).methodName = ::DatawireQuarkCore.cast(value) { ::String } end if ((name) == ("instance")) (self).instance = ::DatawireQuarkCore.cast(value) { ::Quark.quark.ServiceInstance } end nil end |
#call(args) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/quark/behaviors.rb', line 100 def call(args) result = ::DatawireQuarkCore.cast(nil) { ::Quark.quark.concurrent.Future } (self).instance = (self).service.getInstance() if (((self).instance) != (nil)) request = ::DatawireQuarkCore::HTTP::Request.new((self).instance.getURL()) json = ::Quark.quark.toJSON(args, nil) envelope = ::DatawireQuarkCore::JSONObject.new (envelope).setObjectItem(("$method"), (::DatawireQuarkCore::JSONObject.new.setString((self).methodName))) (envelope).setObjectItem(("$context"), (::DatawireQuarkCore::JSONObject.new.setString("TBD"))) (envelope).setObjectItem(("rpc"), (json)) body = envelope.toString() request.setBody(body) request.setMethod("POST") rpc = ::Quark.quark.behaviors.RPCRequest.new(args, self) result = rpc.call(request) else result = ::DatawireQuarkCore.cast(@returned.construct(::DatawireQuarkCore::List.new([]))) { ::Quark.quark.concurrent.Future } result.finish(::Quark.quark.behaviors.RPCError.new("all services are down")) end ::Quark.quark.concurrent.FutureWait.waitFor(result, 10.0) return result nil end |
#fail(info) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/quark/behaviors.rb', line 133 def fail(info) (self).instance.fail(info) nil end |
#succeed(info) ⇒ Object
126 127 128 129 130 131 |
# File 'lib/quark/behaviors.rb', line 126 def succeed(info) (self).instance.succeed(info) nil end |
#toString ⇒ Object
140 141 142 143 144 145 |
# File 'lib/quark/behaviors.rb', line 140 def toString() return (((((("RPC ") + ((self).service.getName())) + (" at ")) + ((self).instance.getURL())) + (": ")) + ((self).methodName)) + ("(...)") nil end |