Class: Universa::RemoteAdapter
- Inherits:
-
Delegator
- Object
- Delegator
- Universa::RemoteAdapter
- Defined in:
- lib/universa/service.rb
Overview
The basic class to write remote class adapters (extensions). Delegates contained Ref instance therefore behaves like remote interface with some extensions.
Key feature of RemoteAdapter class is the cross-call persistence. It means once created instances of the RemoteAdapter descendants are cached just like (in fact, instead of) Ref instances, so when the remote party returns the reference to the object once wrapped by this instance, the instance will be returned unless it is already garbage collected. instance will be returned, what means sort of cross-platform calls persistence.
Extending this class normally should not implement the constructor, By defaul the constructor is passed to the remote to create remote instance.
Direct Known Subclasses
Binder, ChangeOwnerPermission, Contract, HashId, KeyAddress, PrivateKey, PublicKey, RevokePermission, Role, SplitJoinPermission
Class Method Summary collapse
- .invoke_static(method_name, *args) ⇒ Object
-
.remote_class(name) ⇒ Object
Registers remote class name to be used with this adapted.
-
.remote_class_name ⇒ String
Returns remote class name.
Instance Method Summary collapse
-
#__getobj__ ⇒ Ref
Delegated object.
-
#__setobj__ ⇒ Object
Updating proxied object is not allowed.
-
#initialize(*args) ⇒ RemoteAdapter
constructor
Instantiate new proxy object passing arguments to the remote constructor.
-
#inspect ⇒ Object
debugging label.
-
#to_s ⇒ String
call the remote toString().
Constructor Details
#initialize(*args) ⇒ RemoteAdapter
Instantiate new proxy object passing arguments to the remote constructor. The UMO host will try ot find overloaded constructor that matches the arguments.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/universa/service.rb', line 89 def initialize(*args) if args.length == 1 && args[0].is_a?(ReferenceCreationData) @remote = args[0].ref else # User called constructor remote_class_name = self.class.remote_class_name remote_class_name&.length or raise Error, "provide remote_class_name" @remote = Service.umi.instantiate remote_class_name, *args, adapter: self end end |
Class Method Details
.invoke_static(method_name, *args) ⇒ Object
143 144 145 |
# File 'lib/universa/service.rb', line 143 def self.invoke_static(method_name, *args) Service.umi.invoke_static @remote_class_name, method_name, *args end |
.remote_class(name) ⇒ Object
Registers remote class name to be used with this adapted. Call it early in descendant class declaration.
128 129 130 |
# File 'lib/universa/service.rb', line 128 def self.remote_class name @remote_class_name = name end |
.remote_class_name ⇒ String
Returns remote class name. There is no need to override it, when inheriting it use remote_class
helper:
class MyKeyAddress < ObjectProxy
remote_class 'com.icodici.crypto.KeyAddress'
#...
end
Notice: remote_class will do allnecessary work for you.
122 123 124 |
# File 'lib/universa/service.rb', line 122 def self.remote_class_name @remote_class_name or raise Error, "provde remote class name" end |
Instance Method Details
#__getobj__ ⇒ Ref
Delegated object
102 103 104 |
# File 'lib/universa/service.rb', line 102 def __getobj__ @remote end |
#__setobj__ ⇒ Object
Updating proxied object is not allowed. Raises error.
107 108 109 |
# File 'lib/universa/service.rb', line 107 def __setobj__ raise "ObectProxy does not support changing referenced object" end |
#inspect ⇒ Object
debugging label
133 134 135 |
# File 'lib/universa/service.rb', line 133 def inspect "<#{self.class.name}:#{__id__}:#{@remote._remote_class_name}:#{@remote._remote_id}}>" end |
#to_s ⇒ String
call the remote toString(). Does not cache it.
139 140 141 |
# File 'lib/universa/service.rb', line 139 def to_s toString() end |