Class: EventMachine::Protocols::Couchbase::Node
- Inherits:
-
Connection
- Object
- Connection
- EventMachine::Protocols::Couchbase::Node
- Includes:
- EM::Deferrable
- Defined in:
- lib/em-couchbase/node.rb
Instance Attribute Summary collapse
-
#admin ⇒ Object
readonly
Returns the value of attribute admin.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#couch ⇒ Object
readonly
Returns the value of attribute couch.
-
#direct ⇒ Object
readonly
Returns the value of attribute direct.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #arithm(opcode, opaque, vbucket, key, options = {}) ⇒ Object
- #authenticate ⇒ Object protected
- #connection_completed ⇒ Object protected
- #get(tuples, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Node
constructor
A new instance of Node.
- #receive_data(data) ⇒ Object
- #set(opaque, vbucket, key, value, options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Node
Returns a new instance of Node.
35 36 37 38 39 40 41 42 |
# File 'lib/em-couchbase/node.rb', line 35 def initialize( = {}) @data = "" # naive buffer implementation .each do |k, v| if respond_to?(k) instance_variable_set("@#{k}", v) end end end |
Instance Attribute Details
#admin ⇒ Object (readonly)
Returns the value of attribute admin.
31 32 33 |
# File 'lib/em-couchbase/node.rb', line 31 def admin @admin end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
26 27 28 |
# File 'lib/em-couchbase/node.rb', line 26 def client @client end |
#couch ⇒ Object (readonly)
Returns the value of attribute couch.
30 31 32 |
# File 'lib/em-couchbase/node.rb', line 30 def couch @couch end |
#direct ⇒ Object (readonly)
Returns the value of attribute direct.
29 30 31 |
# File 'lib/em-couchbase/node.rb', line 29 def direct @direct end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
28 29 30 |
# File 'lib/em-couchbase/node.rb', line 28 def proxy @proxy end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
32 33 34 |
# File 'lib/em-couchbase/node.rb', line 32 def status @status end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
33 34 35 |
# File 'lib/em-couchbase/node.rb', line 33 def version @version end |
Class Method Details
.connect(options) ⇒ Object
44 45 46 47 |
# File 'lib/em-couchbase/node.rb', line 44 def self.connect() host, port = [:direct].split(':') EventMachine.connect(host, port, self, ) end |
Instance Method Details
#==(other) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/em-couchbase/node.rb', line 101 def ==(other) other = Node.new(other) if other.is_a?(Hash) self.class == other.class && self.direct == other.direct && self.couch == other.couch && self.status == other.status end |
#arithm(opcode, opaque, vbucket, key, options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/em-couchbase/node.rb', line 74 def arithm(opcode, opaque, vbucket, key, = {}) if .is_a?(Fixnum) = {:delta => } end packet = Packet.build(opaque, vbucket, opcode, key, [:delta], [:initial], [:expiration], [:cas]) client.register_packet(opaque, packet) send_data(packet) end |
#authenticate ⇒ Object (protected)
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/em-couchbase/node.rb', line 111 def authenticate if client.config.sasl_password # currently Couchbase supports PLAIN only authentication # this is why it doesn't ask list of mechanisms packet = Packet.build(0, 0, :sasl_auth, "PLAIN", client.config.bucket_name, client.config.sasl_password) send_data(packet) end end |
#connection_completed ⇒ Object (protected)
122 123 124 125 |
# File 'lib/em-couchbase/node.rb', line 122 def connection_completed authenticate succeed end |
#get(tuples, options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/em-couchbase/node.rb', line 91 def get(tuples, = {}) packets = "" tuples.each do |opaque, vbucket, key| packet = Packet.build(opaque, vbucket, :get, key) client.register_packet(opaque, packet) packets << packet end send_data(packets) end |
#receive_data(data) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/em-couchbase/node.rb', line 49 def receive_data(data) @data << data Packet.parse(@data) do |op, opaque, result| if result.error.class == Error::NotMyVbucket client.retry(:not_my_vbucket, opaque) else if op == :sasl_auth raise result.error unless result.success? else client.run_callback(opaque, result) end end end end |
#set(opaque, vbucket, key, value, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/em-couchbase/node.rb', line 64 def set(opaque, vbucket, key, value, = {}) packet = Packet.build(opaque, vbucket, :set, key, value, [:flags], [:expiration], [:cas]) client.register_packet(opaque, packet) send_data(packet) end |