solr_like_rack_server 0.0.3-java → 0.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e538604d81eea31363c960b969f0020973ac85a9
4
- data.tar.gz: 2f3080eb6e35b434ee622b9b327a26ce9403f25c
3
+ metadata.gz: 484ac9e8567a2496df63d728ea217396db87b18a
4
+ data.tar.gz: 235c9517f537e2203252bc4e140654a11b447469
5
5
  SHA512:
6
- metadata.gz: f224920cb51cda1c1f53967e5b95408bfa2dd0c9a0ab20026d37bedb540d2db5ae8e6827c4533e2021df4f897bbcb586919da38fbacef42da55ad206a704c8e3
7
- data.tar.gz: cbb3dd72cc658875443d31a05a6c0239d84792ecd9a3a33b4214edf441a76d74effe514056b1cf4555979a59dae161d6b2ace9cc9ddcea34e3ef487f2e56b2dd
6
+ metadata.gz: 8bbd405a488a358587c59d7e98998122614672970510b77978bcb826ad8edd20ee5d51851be6e3b32f9d248bb1036b9263e0dfa653c035ad348281ac5686d922
7
+ data.tar.gz: a2b4d309ddb526e78e1d399efe7290c22bef41d682e788c3c64d2dc0d333ff8552cddb24f4d5b76b438ea7531e79b4a6f21371be4be2de38dee95a53d3078dd5
@@ -6,15 +6,20 @@ require "solr_like_rack_server/version"
6
6
  require "solr_like_rack_server/response_writer_wrapper"
7
7
 
8
8
  module SolrLikeRackServer
9
+ PORT = ENV["SOLR_LIKE_RACK_SERVER_PORT"] || 12345
10
+
9
11
  class << self
10
- def start mount_procs
11
- wakeupProc = nil
12
+ def server
13
+ @server ||= create_server
14
+ end
15
+
16
+ def create_server
12
17
  opt = {
13
- Port: 12345,
18
+ Port: SolrLikeRackServer::PORT,
14
19
  Logger: WEBrick::Log.new('/dev/null'),
15
20
  AccessLog: [],
16
21
  StartCallback: Proc.new {
17
- wakeupProc.call unless wakeupProc.nil?
22
+ Thread.main.wakeup
18
23
  }
19
24
  }
20
25
  unless ENV["SOLR_LIKE_RACK_SERVER_VERBOSE"].nil?
@@ -22,8 +27,20 @@ module SolrLikeRackServer
22
27
  opt.delete :AccessLog
23
28
  end
24
29
  server = WEBrick::HTTPServer.new opt
25
- mount_procs.each {|path, proc|
26
- server.mount_proc(path) {|req, res|
30
+ Thread.new do
31
+ server.start
32
+ end
33
+ Thread.stop
34
+ at_exit {
35
+ server.shutdown
36
+ }
37
+ server
38
+ end
39
+
40
+ def start mount_procs
41
+ mounted = []
42
+ mount_procs.each {|dir, proc|
43
+ server.mount_proc(dir) {|req, res|
27
44
  res["Content-Type"] = "application/octet-stream"
28
45
  data = if Proc === proc
29
46
  if proc.arity == 0
@@ -43,24 +60,13 @@ module SolrLikeRackServer
43
60
  end
44
61
  res.body = SolrLikeRackServer::ResponseWriterWrapper.new.write data
45
62
  }
63
+ mounted << dir
46
64
  }
47
- if block_given?
48
- wakeupProc = Proc.new { Thread.main.wakeup }
49
- server_thread = Thread.new do
50
- Thread.current[:server] = server
51
- server.start
52
- end
53
- Thread.stop
54
- begin
55
- yield
56
- ensure
57
- server_thread[:server].shutdown
58
- end
59
- else
60
- server
65
+ begin
66
+ yield
67
+ ensure
68
+ mounted.each {|dir| server.unmount dir }
61
69
  end
62
70
  end
63
-
64
- alias_method :server, :start
65
71
  end
66
72
  end
@@ -1,3 +1,3 @@
1
1
  module SolrLikeRackServer
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/test/run.rb CHANGED
@@ -33,7 +33,7 @@ reco_city = YAML.load <<EOM
33
33
  poi_num: 100
34
34
  EOM
35
35
 
36
- SolrLikeRackServer.server(
36
+ SolrLikeRackServer.start(
37
37
  "/search/map_mini/select"=>map_mini,
38
38
  "/search/reco_city/select"=>reco_city,
39
39
  ) {
@@ -51,3 +51,12 @@ SolrLikeRackServer.server(
51
51
  puts client.getBeans(Java::jp.co.mapion.solr.client.beans.Recommendation.java_class).get(0).pref_code
52
52
  puts client.getNumFound
53
53
  }
54
+
55
+ SolrLikeRackServer.start(
56
+ "/search/map_mini2/select"=>map_mini,
57
+ ) {
58
+ client = LocalSearchClient.new "map_mini2"
59
+ client.executeQuery
60
+ puts client.getBeans(Java::jp.co.mapion.solr.client.beans.Phone.java_class).get(0).poi_code
61
+ puts client.getNumFound
62
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solr_like_rack_server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - Koji NAKAMURA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler