Class: Orientdb4r::Binary::BinClient

Inherits:
Client
  • Object
show all
Includes:
Constants, OIO
Defined in:
lib/orientdb4r/bin/client.rb

Overview

This client implements the binary protocol.

Constant Summary

Constants included from Constants

Constants::MINIMAL_PROTOCOL_VERSION, Constants::REQUEST_CONNECT, Constants::REQUEST_DB_OPEN, Constants::REQUEST_SHUTDOWN, Constants::STATUS_ERROR, Constants::STATUS_OK

Constants inherited from Client

Client::SERVER_VERSION_PATTERN

Instance Attribute Summary collapse

Attributes inherited from Client

#connection_library, #database, #lb_strategy, #load_balancing, #nodes, #password, #proxy, #user

Instance Method Summary collapse

Methods included from OIO

#req_resp

Methods inherited from Client

#class_exists?, #command, #connected?, #create_class, #create_database, #create_document, #create_property, #database_exists?, #delete_database, #delete_document, #drop_class, #export, #get_class, #get_database, #get_document, #import, #list_databases, #query, #update_document

Methods included from Utils

#blank?, #compare_versions, #random_string, #verify_and_sanitize_options, #verify_options

Constructor Details

#initialize(options) ⇒ BinClient

:nodoc:



24
25
26
27
28
29
30
31
32
33
# File 'lib/orientdb4r/bin/client.rb', line 24

def initialize(options) #:nodoc:
  super()
  options_pattern = {
    :host => 'localhost', :port => 2424
  }
  verify_and_sanitize_options(options, options_pattern)

  @host = options[:host]
  @port = options[:port]
end

Instance Attribute Details

#db_connectionObject (readonly)

Returns the value of attribute db_connection.



19
20
21
# File 'lib/orientdb4r/bin/client.rb', line 19

def db_connection
  @db_connection
end

#protocolObject (readonly)

Returns the value of attribute protocol.



20
21
22
# File 'lib/orientdb4r/bin/client.rb', line 20

def protocol
  @protocol
end

#protocol_versionObject (readonly)

Returns the value of attribute protocol_version.



21
22
23
# File 'lib/orientdb4r/bin/client.rb', line 21

def protocol_version
  @protocol_version
end

#server_connectionObject (readonly)

Returns the value of attribute server_connection.



18
19
20
# File 'lib/orientdb4r/bin/client.rb', line 18

def server_connection
  @server_connection
end

Instance Method Details

#connect(options) ⇒ Object

————————————————————— CONNECTION



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/orientdb4r/bin/client.rb', line 38

def connect options #:nodoc:
  options_pattern = { :database => :mandatory, :user => :mandatory, :password => :mandatory, :session => :optional, :db_type => 'document' }
  verify_and_sanitize_options(options, options_pattern)

  @socket = TCPSocket.open(@host, @port)
  @protocol_version = BinData::Int16be.read(@socket).to_i

  Orientdb4r::logger.info "Binary protocol version: #{@protocol_version}"

  # check minimal protocol version which is supported
  @protocol = ProtocolFactory.get_protocol(protocol_version)

  command = protocol::DbOpenRequest.new(:protocol_version => protocol_version, :db_name => options[:database], :user => options[:user], :password => options[:password])

  resp = req_resp(@socket, command, protocol::DbOpenResponse.new)
  db_connection = Orientdb4r::Binary::Connection.new(resp.session, options)
  Orientdb4r::logger.info "Database connected, session=#{db_connection.session_id}"
end

#disconnectObject

:nodoc:



58
59
60
61
62
63
64
65
# File 'lib/orientdb4r/bin/client.rb', line 58

def disconnect #:nodoc:
  @socket.close
  @protocol = nil
  @protocol_version = 0
  @db_connection.close unless @db_connection.nil?
  @server_connection.close unless @server_connection.nil?
  @db_connection = nil
end

#server(options = {}) ⇒ Object

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/orientdb4r/bin/client.rb', line 68

def server(options={})
  raise NotImplementedError, 'this should be overridden by concrete client'
end