jackowayed-rufus-tokyo 0.1.13.1 → 0.1.13.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,162 @@
1
+ #--
2
+ # Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
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
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ require 'rufus/tokyo/ttcommons'
27
+
28
+
29
+ module Rufus::Tokyo
30
+
31
+ #
32
+ # A Tokyo Cabinet table, but remote...
33
+ #
34
+ # require 'rufus/tokyo/tyrant'
35
+ # t = Rufus::Tokyo::Tyrant.new('127.0.0.1', 44001)
36
+ # t['toto'] = { 'name' => 'toto the first', 'age' => '34' }
37
+ # t['toto']
38
+ # # => { 'name' => 'toto the first', 'age' => '34' }
39
+ #
40
+ # Most of the methods of this TyrantTable class are defined in the parent
41
+ # class Rufus::Tokyo::Table.
42
+ #
43
+ class TyrantTable < Table
44
+
45
+ include TyrantCommons
46
+
47
+
48
+ attr_reader :host, :port
49
+
50
+ # Connects to the Tyrant table listening at the given host and port.
51
+ #
52
+ # You start such a Tyrant with :
53
+ #
54
+ # ttserver -port 44502 data.tct
55
+ #
56
+ # and then :
57
+ #
58
+ # require 'rufus/tokyo/tyrant'
59
+ # t = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 44502)
60
+ # t['client0'] = { 'name' => 'Heike no Kyomori', 'country' => 'jp' }
61
+ # t.close
62
+ #
63
+ #
64
+ # You can start a Tokyo Tyrant and make it listen to a unix socket (not TCP)
65
+ # with :
66
+ #
67
+ # ttserver -host /tmp/table_socket -port 0 data.tct
68
+ #
69
+ # then :
70
+ #
71
+ # require 'rufus/tokyo/tyrant'
72
+ # t = Rufus::Tokyo::TyrantTable.new('/tmp/table_socket')
73
+ # t['client0'] = { 'name' => 'Theodore Roosevelt', 'country' => 'usa' }
74
+ # t.close
75
+ #
76
+ def initialize (host, port=0)
77
+
78
+ @db = lib.tcrdbnew
79
+
80
+ @host = host
81
+ @port = port
82
+
83
+ (lib.tcrdbopen(@db, host, port) == 1) ||
84
+ raise("couldn't connect to tyrant at #{host}:#{port}")
85
+
86
+ if self.stat['type'] != 'table'
87
+
88
+ self.close
89
+
90
+ raise ArgumentError.new(
91
+ "tyrant at #{host}:#{port} is a not table, " +
92
+ "use Rufus::Tokyo::Tyrant instead to access it.")
93
+ end
94
+ end
95
+
96
+ #
97
+ # using the cabinet lib
98
+ #
99
+ def lib
100
+ TyrantLib
101
+ end
102
+
103
+ def transaction #:nodoc#
104
+ raise_transaction_nme('transaction')
105
+ end
106
+ def abort #:nodoc#
107
+ raise_transaction_nme('abort')
108
+ end
109
+ def tranbegin #:nodoc#
110
+ raise_transaction_nme('tranbegin')
111
+ end
112
+ def trancommit #:nodoc#
113
+ raise_transaction_nme('trancommit')
114
+ end
115
+ def tranabort #:nodoc#
116
+ raise_transaction_nme('tranabort')
117
+ end
118
+
119
+ #--
120
+ # Doesn't work properly, tcrdbmisc doesn't return something leveragable :(
121
+ #
122
+ #def lget (keys)
123
+ # call_misc('getlist', Rufus::Tokyo::List.new(keys))
124
+ #end
125
+ #++
126
+
127
+ protected
128
+
129
+ def raise_transaction_nme (method_name)
130
+
131
+ raise NoMethodError.new(
132
+ "Tyrant tables don't support transactions", method_name)
133
+ end
134
+
135
+ # Returns the raw stat string from the Tyrant server.
136
+ #
137
+ def do_stat
138
+
139
+ lib.tcrdbstat(@db) # note : this is using tcrdbstat
140
+ end
141
+
142
+ #--
143
+ # (see #lget's comment)
144
+ #
145
+ # wrapping tcadbmisc or tcrdbmisc
146
+ # (and taking care of freeing the list_pointer)
147
+ #
148
+ #def call_misc (function, list_pointer)
149
+ # list_pointer = list_pointer.pointer \
150
+ # if list_pointer.is_a?(Rufus::Tokyo::List)
151
+ # begin
152
+ # l = lib.tcrdbmisc(@db, function, 0, list_pointer)
153
+ # # opts always to 0 for now
154
+ # raise "function '#{function}' failed" unless l
155
+ # Rufus::Tokyo::List.new(l).release
156
+ # ensure
157
+ # Rufus::Tokyo::List.free(list_pointer)
158
+ # end
159
+ #end
160
+ #++
161
+ end
162
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jackowayed-rufus-tokyo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13.1
4
+ version: 0.1.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -33,9 +33,40 @@ extra_rdoc_files:
33
33
  - CHANGELOG.txt
34
34
  - CREDITS.txt
35
35
  files:
36
- - README.txt
37
- - CHANGELOG.txt
36
+ - lib/rufus-edo.rb
37
+ - lib/rufus/edo.rb
38
+ - lib/rufus/edo/tabcore.rb
39
+ - lib/rufus/edo/ntyrant/abstract.rb
40
+ - lib/rufus/edo/ntyrant/table.rb
41
+ - lib/rufus/edo/ntyrant.rb
42
+ - lib/rufus/edo/error.rb
43
+ - lib/rufus/edo/cabcore.rb
44
+ - lib/rufus/edo/cabinet/abstract.rb
45
+ - lib/rufus/edo/cabinet/table.rb
46
+ - lib/rufus/tokyo.rb
47
+ - lib/rufus/tokyo/config.rb
48
+ - lib/rufus/tokyo/hmethods.rb
49
+ - lib/rufus/tokyo/tyrant.rb
50
+ - lib/rufus/tokyo/dystopia/lib.rb
51
+ - lib/rufus/tokyo/dystopia/core.rb
52
+ - lib/rufus/tokyo/dystopia/words.rb
53
+ - lib/rufus/tokyo/transactions.rb
54
+ - lib/rufus/tokyo/tyrant/lib.rb
55
+ - lib/rufus/tokyo/tyrant/abstract.rb
56
+ - lib/rufus/tokyo/tyrant/table.rb
57
+ - lib/rufus/tokyo/query.rb
58
+ - lib/rufus/tokyo/dystopia.rb
59
+ - lib/rufus/tokyo/ttcommons.rb
60
+ - lib/rufus/tokyo/cabinet/lib.rb
61
+ - lib/rufus/tokyo/cabinet/util.rb
62
+ - lib/rufus/tokyo/cabinet/abstract.rb
63
+ - lib/rufus/tokyo/cabinet/table.rb
64
+ - lib/rufus-tokyo.rb
38
65
  - CREDITS.txt
66
+ - LICENSE.txt
67
+ - CHANGELOG.txt
68
+ - README.txt
69
+ - TODO.txt
39
70
  has_rdoc: true
40
71
  homepage: http://rufus.rubyforge.org/
41
72
  post_install_message: