Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 153 lines (128 sloc) 4.172 kB
a610327 @jmettraux fitting back the license in 80 cols
authored
1 #--
9424c3d @jmettraux 2010
authored
2 # Copyright (c) 2009-2010, John Mettraux, jmettraux@gmail.com
a610327 @jmettraux fitting back the license in 80 cols
authored
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
10 #
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 # THE SOFTWARE.
21 #
4eb2df7 @jmettraux shortened the license header
authored
22 # Made in Japan.
23 #++
a610327 @jmettraux fitting back the license in 80 cols
authored
24
7c70dc3 @jmettraux todo : added ext method for calling embedded Lua function (tokyo/edo …
authored
25 require 'rufus/tokyo/ttcommons'
dfe69bb @jmettraux implemented Rufus::Edo::NetTyrant
authored
26
27
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
28 module Rufus::Tokyo
d9bcc86 @jmettraux tyrant tables in, but specs are broken for now (and 1.9.1 is not happ…
authored
29
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
30 #
31 # A Tokyo Cabinet table, but remote...
32 #
33 # require 'rufus/tokyo/tyrant'
34 # t = Rufus::Tokyo::Tyrant.new('127.0.0.1', 44001)
35 # t['toto'] = { 'name' => 'toto the first', 'age' => '34' }
36 # t['toto']
37 # # => { 'name' => 'toto the first', 'age' => '34' }
38 #
062b601 @jmettraux documented Tyrant and unix sockets, and initial doc about Rufus::Edo
authored
39 # Most of the methods of this TyrantTable class are defined in the parent
40 # class Rufus::Tokyo::Table.
41 #
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
42 class TyrantTable < Table
dfe69bb @jmettraux implemented Rufus::Edo::NetTyrant
authored
43
7c70dc3 @jmettraux todo : added ext method for calling embedded Lua function (tokyo/edo …
authored
44 include TyrantCommons
f2a3cc0 @therealadam Kill duplication by movingext and outlen_op methods to their own modu…
therealadam authored
45 include Outlen
46 include Ext
6db1e84 @jmettraux cleaned up 'no transactions' code
authored
47 include NoTransactions
dfe69bb @jmettraux implemented Rufus::Edo::NetTyrant
authored
48
d9bcc86 @jmettraux tyrant tables in, but specs are broken for now (and 1.9.1 is not happ…
authored
49
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
50 attr_reader :host, :port
96f61ee @jmettraux keeping track of host and port
authored
51
062b601 @jmettraux documented Tyrant and unix sockets, and initial doc about Rufus::Edo
authored
52 # Connects to the Tyrant table listening at the given host and port.
53 #
54 # You start such a Tyrant with :
55 #
56 # ttserver -port 44502 data.tct
57 #
58 # and then :
59 #
60 # require 'rufus/tokyo/tyrant'
da29dc0 @jmettraux rufus/edo and rufus/edo/ntyrant done
authored
61 # t = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 44502)
062b601 @jmettraux documented Tyrant and unix sockets, and initial doc about Rufus::Edo
authored
62 # t['client0'] = { 'name' => 'Heike no Kyomori', 'country' => 'jp' }
63 # t.close
64 #
65 #
66 # You can start a Tokyo Tyrant and make it listen to a unix socket (not TCP)
67 # with :
68 #
da29dc0 @jmettraux rufus/edo and rufus/edo/ntyrant done
authored
69 # ttserver -host /tmp/table_socket -port 0 data.tct
062b601 @jmettraux documented Tyrant and unix sockets, and initial doc about Rufus::Edo
authored
70 #
71 # then :
72 #
73 # require 'rufus/tokyo/tyrant'
da29dc0 @jmettraux rufus/edo and rufus/edo/ntyrant done
authored
74 # t = Rufus::Tokyo::TyrantTable.new('/tmp/table_socket')
062b601 @jmettraux documented Tyrant and unix sockets, and initial doc about Rufus::Edo
authored
75 # t['client0'] = { 'name' => 'Theodore Roosevelt', 'country' => 'usa' }
76 # t.close
77 #
c57749f @jmettraux Tokyo Tyrant reconnect stuff is in, but well, it's useless...
authored
78 def initialize (host, port=0, params={})
d9bcc86 @jmettraux tyrant tables in, but specs are broken for now (and 1.9.1 is not happ…
authored
79
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
80 @db = lib.tcrdbnew
d9bcc86 @jmettraux tyrant tables in, but specs are broken for now (and 1.9.1 is not happ…
authored
81
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
82 @host = host
83 @port = port
96f61ee @jmettraux keeping track of host and port
authored
84
b70a7dd @jmettraux newer version of FFI have bool type. Adapted. Closes gh-23
authored
85 lib.tcrdbopen(@db, host, port) ||
92f66d2 @jmettraux error on open reorg. Closes gh-11
authored
86 raise(TokyoError.new("couldn't connect to tyrant at #{host}:#{port}"))
b23a743 @jmettraux todo : Tyrant and TyrantTable now complain when used in lieu of each …
authored
87
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
88 if self.stat['type'] != 'table'
b23a743 @jmettraux todo : Tyrant and TyrantTable now complain when used in lieu of each …
authored
89
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
90 self.close
b23a743 @jmettraux todo : Tyrant and TyrantTable now complain when used in lieu of each …
authored
91
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
92 raise ArgumentError.new(
93 "tyrant at #{host}:#{port} is a not table, " +
94 "use Rufus::Tokyo::Tyrant instead to access it.")
49c2dee Added the Rufus::Tokyo module names back into all the files, to wrap …
Justin W. Reagor authored
95 end
a2006f8 @jmettraux minimal warnings when running with -w
authored
96
97 @default_proc = nil
c57749f @jmettraux Tokyo Tyrant reconnect stuff is in, but well, it's useless...
authored
98
99 #
100 # timeout and reconnect
101
102 # defaults to two minutes
103
104 timeout = params[:timeout] || 120.0
105 lib.tcrdbtune(@db, timeout, 1)
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
106 end
d9bcc86 @jmettraux tyrant tables in, but specs are broken for now (and 1.9.1 is not happ…
authored
107
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
108 #
109 # using the cabinet lib
110 #
111 def lib
112 TyrantLib
113 end
89dcf9a @jmettraux todo : implemented Rufus::Tokyo::Table#transaction
authored
114
57d1dfc @jmettraux more rdoc and a failed experiment (tcrdbmisc and tables) report
authored
115 #--
116 # Doesn't work properly, tcrdbmisc doesn't return something leveragable :(
117 #
118 #def lget (keys)
119 # call_misc('getlist', Rufus::Tokyo::List.new(keys))
120 #end
121 #++
122
82ee6c9 @jmettraux back to the original namespace scheme (http://bit.ly/6QaLo)
authored
123 protected
89dcf9a @jmettraux todo : implemented Rufus::Tokyo::Table#transaction
authored
124
dfe69bb @jmettraux implemented Rufus::Edo::NetTyrant
authored
125 # Returns the raw stat string from the Tyrant server.
126 #
127 def do_stat
57d1dfc @jmettraux more rdoc and a failed experiment (tcrdbmisc and tables) report
authored
128
129 lib.tcrdbstat(@db) # note : this is using tcrdbstat
dfe69bb @jmettraux implemented Rufus::Edo::NetTyrant
authored
130 end
57d1dfc @jmettraux more rdoc and a failed experiment (tcrdbmisc and tables) report
authored
131
132 #--
133 # (see #lget's comment)
134 #
135 # wrapping tcadbmisc or tcrdbmisc
136 # (and taking care of freeing the list_pointer)
137 #
138 #def call_misc (function, list_pointer)
139 # list_pointer = list_pointer.pointer \
140 # if list_pointer.is_a?(Rufus::Tokyo::List)
141 # begin
142 # l = lib.tcrdbmisc(@db, function, 0, list_pointer)
143 # # opts always to 0 for now
144 # raise "function '#{function}' failed" unless l
145 # Rufus::Tokyo::List.new(l).release
146 # ensure
147 # Rufus::Tokyo::List.free(list_pointer)
148 # end
149 #end
150 #++
d9bcc86 @jmettraux tyrant tables in, but specs are broken for now (and 1.9.1 is not happ…
authored
151 end
152 end
Something went wrong with that request. Please try again.