norikra-udf-lookup 0.0.1-java → 0.0.2-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: b01908e0a86f828de588a4cf2e26418fecd3b298
4
- data.tar.gz: 787fb9c26a32f6f85b2068325a1f5b17787f1b46
3
+ metadata.gz: 29af22d854e0f0a23b4b24a06c00ae1d536ccf90
4
+ data.tar.gz: 301d3a84cbf3430fcf14620823f80aa20c9eae51
5
5
  SHA512:
6
- metadata.gz: 972032745ed7468d8fd84d8fa79352c1da3377e48b8f126c130c59b159c196a57473add7b0784540fbf2b50c44f1cb3fd91753aaed31b61a122125901b0c46ef
7
- data.tar.gz: a2259e1a1dc74966a28e41550b71fad628a03325fbc00ec88cb5668a22b2d1104f207004ea7e3d0a2f0d2ed54ef714b384f26480686566748d70e46b149eeddc
6
+ metadata.gz: 6b709009220bc532c95207bd97faa6e519bed2645da1a368b1f168f6e677d3c66b276222e9242185345431a7e864de72a2e82703ddcb510381e785a2999fed5f
7
+ data.tar.gz: 72d6e73c9f20069a9174d31b0139ab29bb36db816ea1b400e6a51d602540108b0163a4b82f03082bca03496bc7710df5f4bd7e04a357945da118bbfecc6a8cd2
Binary file
@@ -1,10 +1,14 @@
1
1
  require 'java'
2
2
  java_package 'jp.gr.java_conf.ogibayashi.norikra.udf'
3
3
 
4
- class Lookup # FQDN: org.example.yourcompany.norikra.udf.MyUDF1
5
- @@lookup_table = nil
4
+ class Lookup
5
+ FILE_UPDATE_CHECK_INTERVAL = 60
6
+ @@lookup_table = Hash.new
7
+ @@next_update_check = nil
6
8
 
7
9
  def self.read_tsv(path)
10
+ info "Lookup#read_tsv Loading file : #{path}" if @logger
11
+ @@next_update_check = Time.now + FILE_UPDATE_CHECK_INTERVAL
8
12
  data = File.open(path).readlines.map do |line|
9
13
  line.chomp.split("\t")
10
14
  end
@@ -12,9 +16,17 @@ class Lookup # FQDN: org.example.yourcompany.norikra.udf.MyUDF1
12
16
  end
13
17
 
14
18
  def self.lookup_tsv(path,key,default_value)
15
- unless @@lookup_table
16
- @@lookup_table = self.read_tsv(path)
19
+ unless @@lookup_table[path]
20
+ @@lookup_table[path] = self.read_tsv(path)
17
21
  end
18
- @@lookup_table[key] || default_value
22
+ if Time.now > @@next_update_check
23
+ # Check if file was updated in last FILE_UPDATE_CHECK_INTERVAL sec.
24
+ if File::Stat.new(path).mtime > (@@next_update_check - FILE_UPDATE_CHECK_INTERVAL)
25
+ @@lookup_table[path] = self.read_tsv(path)
26
+ else
27
+ @@next_update_check = Time.now + FILE_UPDATE_CHECK_INTERVAL
28
+ end
29
+ end
30
+ @@lookup_table[path][key] || default_value
19
31
  end
20
32
  end
@@ -1,7 +1,7 @@
1
1
  module Norikra
2
2
  module Udf
3
3
  module Lookup
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: norikra-udf-lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: java
6
6
  authors:
7
7
  - Hironori Ogibayashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler