Class: Bones::RPC::Session
- Inherits:
-
Object
- Object
- Bones::RPC::Session
- Includes:
- Optionable
- Defined in:
- lib/bones/rpc/session.rb
Overview
A session in bones_rpc is root for all interactions with a Bones::RPC server or replica set.
It can talk to a single default database, or dynamically speak to multiple databases.
Instance Attribute Summary collapse
-
#cluster ⇒ Cluster
The cluster of nodes.
- #options ⇒ Object
Class Method Summary collapse
-
.connect(uri, &block) ⇒ Session
Create a new session from a URI.
Instance Method Summary collapse
-
#command(op) ⇒ Object
Run
command
on the current database. - #context ⇒ Object
-
#disconnect ⇒ true
Disconnects all nodes in the session’s cluster.
- #handle_refresh(node) ⇒ Object
-
#initialize(seeds, options = {}, &callback) ⇒ Session
constructor
Initialize a new database session.
-
#inspect ⇒ String
Provide a string inspection for the session.
- #notify(method, *params) ⇒ Object
-
#read_preference ⇒ Object
Get the read preference for the session.
- #request(method, *params) ⇒ Object
- #synchronize ⇒ Object
Constructor Details
Instance Attribute Details
#cluster ⇒ Cluster
Returns The cluster of nodes.
39 40 41 |
# File 'lib/bones/rpc/session.rb', line 39 def cluster @cluster end |
#options ⇒ Object
39 |
# File 'lib/bones/rpc/session.rb', line 39 attr_reader :cluster, :options |
Class Method Details
Instance Method Details
#command(op) ⇒ Object
Run command
on the current database.
48 49 50 |
# File 'lib/bones/rpc/session.rb', line 48 def command(op) current_database.command(op) end |
#context ⇒ Object
52 53 54 |
# File 'lib/bones/rpc/session.rb', line 52 def context @context ||= Context.new(self) end |
#disconnect ⇒ true
Disconnects all nodes in the session’s cluster. This should only be used in cases # where you know you’re not going to use the cluster on the thread anymore and need to force the connections to close.
63 64 65 |
# File 'lib/bones/rpc/session.rb', line 63 def disconnect cluster.disconnect end |
#handle_refresh(node) ⇒ Object
67 68 69 |
# File 'lib/bones/rpc/session.rb', line 67 def handle_refresh(node) @callback.call(node) if @callback end |
#inspect ⇒ String
Provide a string inspection for the session.
79 80 81 |
# File 'lib/bones/rpc/session.rb', line 79 def inspect "<#{self.class.name} seeds=#{cluster.seeds}>" end |
#notify(method, *params) ⇒ Object
143 144 145 |
# File 'lib/bones/rpc/session.rb', line 143 def notify(method, *params) context.notify(method, params) end |
#read_preference ⇒ Object
Get the read preference for the session. Will default to primary if none was provided.
156 157 158 |
# File 'lib/bones/rpc/session.rb', line 156 def read_preference @read_preference ||= ReadPreference.get([:read] || :nearest) end |
#request(method, *params) ⇒ Object
160 161 162 |
# File 'lib/bones/rpc/session.rb', line 160 def request(method, *params) context.request(method, params) end |
#synchronize ⇒ Object
164 165 166 |
# File 'lib/bones/rpc/session.rb', line 164 def synchronize context.synchronize end |