Skip to content
torun edited this page Oct 26, 2010 · 17 revisions

Castoro::Client

It is a library built into the application accessed castoro.

  • Contact the host and path is stored content to the gateway.
  • Contact the available peer to the gateway.
  • Various requests(CREATE and DELETE command) are transmitted to peer.

Install

It is necessary to install Castoro::Common that is the class library where a common function to each component of castoro is offered beforehand.

gem install castoro-client-X.X.X.gem

Sample Script

It becomes it as follows the sample script that uses the client.

initialize

The client is initialized.
See below Usage.

require "castoro-client"

client = Castoro::Client.new("logger" => Logger.new(nil))

When the argument is omitted, the value of default is used.
See below Usage.

require "castoro-client"

client = Castoro::Client.new

The hash object can be passed to the argument.
See below Usage.

require "castoro-client"

config = {
  "logger" => Logger.new(nil),
  "my_port" => 30003,
  "expire" => 3.0,
  "request_interval" => 0.50,
  "peer_port" => 33333,
  "tcp_connect_expire" => 0.10,
  "tcp_connect_retry" => 2,
  "tcp_request_expire" => 10.00
}
client = Castoro::Client.new(config)

open and close

The client is opened and closed.
See below Usage.

require "castoro-client"

client = Castoro::Client.new

puts "client is opened? #{ client.opened? }"
client.open unless client.opened?
puts "client is opened? #{ client.opened? }"

puts "client is closed? #{ client.closed? }"
client.close unless client.closed?
puts "client is closed? #{ client.closed? }"

A series of operation can be done by using the class method “Client.open”.
See below Usage.

require "castoro-client"

Castoro::Client.open({ }) { |client|
  puts "client is closed? #{ client.closed? }"
  puts "client is opened? #{ client.opened? }"
}

The same set value as initialization can be given to the argument.
See below Usage.

require "castoro-client"

Castoro::Client.open("logger" => Logger.new(nil)) { |client|
  puts "client is closed? #{ client.closed? }"
  puts "client is opened? #{ client.opened? }"
}

To set the default value to client, empty hash is passed to the argument.
See below Usage.

require "castoro-client"

Castoro::Client.open({}) { |client|
  puts "client is closed? #{ client.closed? }"
  puts "client is opened? #{ client.opened? }"
}

The hash object can be passed to the argument.
See below Usage.

require "castoro-client"

config = {
  "logger" => Logger.new(nil),
  "my_port" => 30003,
  "expire" => 3.0,
  "request_interval" => 0.50,
  "peer_port" => 33333,
  "tcp_connect_expire" => 0.10,
  "tcp_connect_retry" => 2,
  "tcp_request_expire" => 10.00
}
Castoro::Client.open(config) { |client|
  puts "client is closed? #{ client.closed? }"
  puts "client is opened? #{ client.opened? }"
}

create

The basket that preserves contents is newly made.
See below Usage.

require "castoro-client"

Castoro::Client.open( "gateways" => [ "127.0.0.1" ] ) { |client|
  client.create("1.0.1", "length" => 99999, "class" => :original) { |host, path|
    puts host, path
  }
}

create_direct

The basket that preserves contents is newly made to the specified host.
See below Usage.

require "castoro-client"

Castoro::Client.open({ }) { |client|
  client.create_direct("peer", "1.0.1", "length" => 99999, "class" => :original) { |host, path|
    puts host, path
  }
}

get

Contact the host and path is stored content.
See below Usage.

require "castoro-client"

Castoro::Client.open( "gateways" => [ "127.0.0.1" ] ) { |client|
  puts client.get "1.0.1"
}

delete

Remove the basket.
See below Usage.

require "castoro-client"

Castoro::Client.open( "gateways" => [ "127.0.0.1" ] ) { |client|
  client.delete "1.0.1"
}

Configuration details and default

Details and the default of the configurations are the following.

Configuration Default Details
my_host IPSocket::getaddress(Socket::gethostname) The host name or ip address that can be recognized from other hosts be specify.
It is acquired in the automatic operation when not specifying.
my_ports (30003..30099) The port that the client program uses is specified.
expire 2.0 Time until the UDP connection is cut is specified.
request_interval 0.20 The interval when the request of the UDP connection is transmitted is specified.
gateways [“127.0.0.1”] The connection destination of the UDP communication is specified. (Client to Gateway)
peer_port 30111 The port number of the TCP connection destination is specified. (Client to Peer)
tcp_connect_expire 0.05 The cutting time of the TCP connection destination is specified.
tcp_connect_retry 1 The frequency is specified retrying of the TCP connection destination.
tcp_request_expire 5.00 The response standby time when the request transmits by the TCP connection destination is specified.
logger Logger.new(STDOUT) The instance of the logger can be given.

Class Descriptions