Class: Hprose::Client
Defined Under Namespace
Classes: Proxy
Constant Summary
Constants included
from ResultMode
ResultMode::Normal, ResultMode::Raw, ResultMode::RawWithEndTag, ResultMode::Serialized
Constants included
from Tags
Tags::TagArgument, Tags::TagBytes, Tags::TagCall, Tags::TagClass, Tags::TagClosebrace, Tags::TagDate, Tags::TagDouble, Tags::TagEmpty, Tags::TagEnd, Tags::TagError, Tags::TagFalse, Tags::TagFunctions, Tags::TagGuid, Tags::TagInfinity, Tags::TagInteger, Tags::TagList, Tags::TagLong, Tags::TagMap, Tags::TagNaN, Tags::TagNeg, Tags::TagNine, Tags::TagNull, Tags::TagObject, Tags::TagOpenbrace, Tags::TagPoint, Tags::TagPos, Tags::TagQuote, Tags::TagRef, Tags::TagResult, Tags::TagSemicolon, Tags::TagString, Tags::TagTime, Tags::TagTrue, Tags::TagUTC, Tags::TagUTF8Char, Tags::TagZero
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(uri = nil) ⇒ Client
Returns a new instance of Client.
48
49
50
51
52
53
|
# File 'lib/hprose/client.rb', line 48
def initialize(uri = nil)
@onerror = nil
@filters = []
@simple = false
self.uri = uri
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(methodname, *args, &block) ⇒ Object
177
178
179
|
# File 'lib/hprose/client.rb', line 177
def method_missing(methodname, *args, &block)
self.invoke(methodname, args, &block)
end
|
Instance Attribute Details
#simple ⇒ Object
Returns the value of attribute simple.
58
59
60
|
# File 'lib/hprose/client.rb', line 58
def simple
@simple
end
|
#uri ⇒ Object
Returns the value of attribute uri.
57
58
59
|
# File 'lib/hprose/client.rb', line 57
def uri
@uri
end
|
Class Method Details
.__new__ ⇒ Object
29
|
# File 'lib/hprose/client.rb', line 29
alias :__new__ :new
|
.inherited(subclass) ⇒ Object
30
31
32
33
34
|
# File 'lib/hprose/client.rb', line 30
def inherited(subclass)
class << subclass
alias :new :__new__
end
end
|
.new(uri) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/hprose/client.rb', line 37
def self.new(uri)
u = URI.parse(uri)
case u.scheme
when 'http', 'https' then
return HttpClient.new(uri)
when 'tcp', 'tcp4', 'tcp6' then
return TcpClient.new(uri)
else
raise Exception.exception("The " << u.scheme << " client isn't implemented.")
end
end
|
Instance Method Details
#[](namespace) ⇒ Object
88
89
90
|
# File 'lib/hprose/client.rb', line 88
def [](namespace)
Proxy.new(self, namespace)
end
|
#add_filter(filter) ⇒ Object
67
68
69
|
# File 'lib/hprose/client.rb', line 67
def add_filter(filter)
@filters << filter
end
|
#filter ⇒ Object
59
60
61
62
|
# File 'lib/hprose/client.rb', line 59
def filter
return nil if @filters.empty?
return @filters[0]
end
|
#filter=(filter) ⇒ Object
63
64
65
66
|
# File 'lib/hprose/client.rb', line 63
def filter=(filter)
@filters.clear
@filters << filter unless (filter.nil?)
end
|
#invoke(methodname, args = [], byref = false, resultMode = Normal, simple = nil, &block) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/hprose/client.rb', line 91
def invoke(methodname, args = [], byref = false, resultMode = Normal, simple = nil, &block)
simple = @simple if simple.nil?
if block_given? then
Thread.start do
begin
result = do_invoke(methodname, args, byref, resultMode, simple)
case block.arity
when 0 then yield
when 1 then yield result
when 2 then yield result, args
end
rescue ::Exception => e
@onerror.call(methodname, e) if (@onerror.is_a?(Proc) or
@onerror.is_a?(Method) or
@onerror.respond_to?(:call))
end
end
else
return do_invoke(methodname, args, byref, resultMode, simple)
end
end
|
#onerror(&block) ⇒ Object
73
74
75
76
|
# File 'lib/hprose/client.rb', line 73
def onerror(&block)
@onerror = block if block_given?
@onerror
end
|
#onerror=(error_handler) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/hprose/client.rb', line 77
def onerror=(error_handler)
error_handler = error_handler.to_sym if error_handler.is_a?(String)
if error_handler.is_a?(Symbol) then
error_handler = Object.method(error_handler)
end
@onerror = error_handler
end
|
#remove_filter(filter) ⇒ Object
70
71
72
|
# File 'lib/hprose/client.rb', line 70
def remove_filter(filter)
@filters.delete(filter)
end
|
#use_service(uri = nil, namespace = nil) ⇒ Object
84
85
86
87
|
# File 'lib/hprose/client.rb', line 84
def use_service(uri = nil, namespace = nil)
self.uri = uri
Proxy.new(self, namespace)
end
|