gqtp 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ source :rubygems
20
+
21
+ gemspec
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # README
2
+
3
+ ## Name
4
+
5
+ gqtp
6
+
7
+ ## Description
8
+
9
+ Gqtp gem is a
10
+ [GQTP (Groonga Query Transfer Protocol)](http://groonga.org/docs/spec/gqtp.html)
11
+ Ruby implementation.
12
+
13
+ Gqtp gem provides both GQTP client, GQTP server and GQTP proxy
14
+ implementations. They provide asynchronous API. You can use gqtp gem
15
+ for high concurrency use.
16
+
17
+ ## Install
18
+
19
+ % gem install gqtp
20
+
21
+ ## Usage
22
+
23
+ ### Client
24
+
25
+ client = GQTP::Client.new(:address => "192.168.0.1", :port => 10041)
26
+ request = client.send("status") do |header, body|
27
+ p body # => "{\"alloc_count\":163,...}"
28
+ end
29
+ request.wait
30
+
31
+ ### Server
32
+
33
+ server = GQTP::Server.new(:address => "192.168.0.1", :port => 10041)
34
+ server.on_request do |request, client|
35
+ body = "{\"alloc_count\":163,...}"
36
+ header = GQTP::Header.new
37
+ header.query_type = GQTP::Header::ContentType::JSON
38
+ header.flags = GQTP::Header::Flag::TAIL
39
+ header.size = body.bytesize
40
+ client.write(header.pack, body) do
41
+ client.close
42
+ end
43
+ end
44
+ server.run.wait
45
+
46
+ ### Proxy
47
+
48
+ proxy = GQTP::Proxy.new(:listen_address => "127.0.0.1",
49
+ :listen_port => 10041,
50
+ :upstream_address => "192.168.0.1",
51
+ :upstream_port => 10041)
52
+ proxy.run.wait
53
+
54
+ ## Dependencies
55
+
56
+ * Ruby 1.9.3
57
+
58
+ ## Mailing list
59
+
60
+ * English: [groonga-talk@lists.sourceforge.net](https://lists.sourceforge.net/lists/listinfo/groonga-talk)
61
+ * Japanese: [groonga-dev@lists.sourceforge.jp](http://lists.sourceforge.jp/mailman/listinfo/groonga-dev)
62
+
63
+ ## Thanks
64
+
65
+ * ...
66
+
67
+ ## Authors
68
+
69
+ * Kouhei Sutou \<kou@clear-code.com\>
70
+
71
+ ## License
72
+
73
+ LGPLv2.1 or later. See doc/text/lgpl-2.1.txt for details.
74
+
75
+ (Kouhei Sutou has a right to change the license including contributed
76
+ patches.)
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ task :default => :test
20
+
21
+ require "rubygems"
22
+ require "bundler/gem_helper"
23
+ require "packnga"
24
+
25
+ base_dir = File.join(File.dirname(__FILE__))
26
+
27
+ helper = Bundler::GemHelper.new(base_dir)
28
+ def helper.version_tag
29
+ version
30
+ end
31
+
32
+ helper.install
33
+ spec = helper.gemspec
34
+
35
+ Packnga::DocumentTask.new(spec) do
36
+ end
37
+
38
+ Packnga::ReleaseTask.new(spec) do
39
+ end
40
+
41
+ desc "Run tests"
42
+ task :test do
43
+ ruby("test/run-test.rb")
44
+ end
data/bin/gqtp-proxy ADDED
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License as published by the Free Software Foundation; either
8
+ # version 2.1 of the License, or (at your option) any later version.
9
+ #
10
+ # This library is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ # Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public
16
+ # License along with this library; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ require "optparse"
20
+ require "ostruct"
21
+
22
+ require "gqtp"
23
+
24
+ options = OpenStruct.new
25
+ options.listen_address = "0.0.0.0"
26
+ options.listen_port = 10041
27
+ options.upstream_address = nil
28
+ options.upstream_port = 10041
29
+ options.backend = :thread
30
+
31
+ parser = OptionParser.new
32
+ parser.on("--listen-address=ADDRESS",
33
+ "IP address or host name to listen",
34
+ "(#{options.listen_address})") do |address|
35
+ options.listen_address = address
36
+ end
37
+ parser.on("--listen-port=PORT", Integer,
38
+ "Port number to listen",
39
+ "(#{options.listen_port})") do |port|
40
+ options.listen_port = port
41
+ end
42
+ parser.on("--upstream-address=ADDRESS",
43
+ "IP address or host name of upstream",
44
+ "(#{options.upstream_address})") do |address|
45
+ options.upstream_address = address
46
+ end
47
+ parser.on("--upstream-port=PORT", Integer,
48
+ "Port number of upstream",
49
+ "(#{options.upstream_port})") do |port|
50
+ options.upstream_port = port
51
+ end
52
+ available_backends = ["thread", "synchronous", "coolio"].join(", ")
53
+ parser.on("--backend=BACKEND",
54
+ "Use BACKEND for connection",
55
+ "[#{available_backends}]",
56
+ "(#{options.backend})") do |backend|
57
+ options.backend = backend.to_sym
58
+ end
59
+
60
+ begin
61
+ parser.parse!
62
+ rescue OptionParser::ParseError
63
+ puts($!.message)
64
+ exit(false)
65
+ end
66
+
67
+ if options.upstream_address.nil?
68
+ puts("--upstream-address is required.")
69
+ exit(false)
70
+ end
71
+
72
+ proxy = GQTP::Proxy.new(:listen_address => options.listen_address,
73
+ :listen_port => options.listen_port,
74
+ :upstream_address => options.upstream_address,
75
+ :upstream_port => options.upstream_port,
76
+ :connection => options.backend)
77
+ proxy.run.wait