Class: Beachcomber::Session
- Inherits:
-
Object
- Object
- Beachcomber::Session
- Defined in:
- lib/beachcomber/client.rb
Overview
Session holds a persistent connection to the daemon and sends multiple requests over the same socket.
Obtain a Session via Client#session:
client.session do |s|
s.set_context('/repo')
r = s.get('git.branch')
end
Not thread-safe; use one session per thread.
Instance Method Summary collapse
-
#close ⇒ Object
Closes the underlying socket connection.
-
#get(key, path: nil) ⇒ Result
Reads a cached value.
-
#get_with_flags(key, path: nil, force: false, wait: false) ⇒ Result
Reads a cached value with protocol flags.
-
#hello ⇒ HelloInfo
Sends a hello handshake and returns server info.
-
#initialize(socket, timeout) ⇒ Session
constructor
A new instance of Session.
-
#introspect(subject, duration_secs: nil) ⇒ IntrospectResponse
Introspects a daemon subsystem.
-
#put(key, data = nil, ttl: nil, path: nil) ⇒ nil
Writes a value into the daemon cache.
-
#refresh(key, path: nil) ⇒ Object
Forces the daemon to recompute a provider/key.
-
#set_context(path) ⇒ Object
Sets the default path for subsequent queries on this connection.
-
#status ⇒ Array<CacheRow>
Returns cache rows from the daemon.
Constructor Details
#initialize(socket, timeout) ⇒ Session
Returns a new instance of Session.
23 24 25 26 |
# File 'lib/beachcomber/client.rb', line 23 def initialize(socket, timeout) @socket = socket @timeout = timeout end |
Instance Method Details
#close ⇒ Object
Closes the underlying socket connection.
118 119 120 |
# File 'lib/beachcomber/client.rb', line 118 def close @socket.close unless @socket.closed? end |
#get(key, path: nil) ⇒ Result
Reads a cached value.
41 42 43 44 45 |
# File 'lib/beachcomber/client.rb', line 41 def get(key, path: nil) req = { op: 'get', key: key } req[:path] = path if path roundtrip(req) end |
#get_with_flags(key, path: nil, force: false, wait: false) ⇒ Result
Reads a cached value with protocol flags.
54 55 56 57 58 59 60 |
# File 'lib/beachcomber/client.rb', line 54 def get_with_flags(key, path: nil, force: false, wait: false) req = { op: 'get', key: key } req[:path] = path if path req[:force] = true if force req[:wait] = true if wait roundtrip(req) end |
#hello ⇒ HelloInfo
Sends a hello handshake and returns server info.
84 85 86 87 |
# File 'lib/beachcomber/client.rb', line 84 def hello resp = roundtrip_raw({ op: 'hello' }) parse_hello(resp) end |
#introspect(subject, duration_secs: nil) ⇒ IntrospectResponse
Introspects a daemon subsystem.
110 111 112 113 114 115 |
# File 'lib/beachcomber/client.rb', line 110 def introspect(subject, duration_secs: nil) req = { op: 'introspect', subject: subject.to_s } req[:duration_secs] = duration_secs if duration_secs resp = roundtrip_raw(req) parse_introspect(subject.to_s, resp) end |
#put(key, data = nil, ttl: nil, path: nil) ⇒ nil
Writes a value into the daemon cache.
96 97 98 99 100 101 102 103 |
# File 'lib/beachcomber/client.rb', line 96 def put(key, data = nil, ttl: nil, path: nil) req = { op: 'put', key: key } req[:data] = data unless data.nil? req[:ttl] = ttl if ttl req[:path] = path if path roundtrip(req) nil end |
#refresh(key, path: nil) ⇒ Object
Forces the daemon to recompute a provider/key.
66 67 68 69 70 71 |
# File 'lib/beachcomber/client.rb', line 66 def refresh(key, path: nil) req = { op: 'refresh', key: key } req[:path] = path if path roundtrip(req) nil end |
#set_context(path) ⇒ Object
Sets the default path for subsequent queries on this connection.
31 32 33 34 |
# File 'lib/beachcomber/client.rb', line 31 def set_context(path) roundtrip({ op: 'context', path: path }) nil end |
#status ⇒ Array<CacheRow>
Returns cache rows from the daemon.
76 77 78 79 |
# File 'lib/beachcomber/client.rb', line 76 def status resp_obj = roundtrip_raw({ op: 'status' }) parse_cache_rows(resp_obj) end |