Class: HazelcastCacheClient
- Inherits:
-
Object
- Object
- HazelcastCacheClient
- Includes:
- Singleton
- Defined in:
- lib/jruby-hazelcast.rb
Defined Under Namespace
Classes: CacheException
Instance Attribute Summary collapse
-
#app_root ⇒ Object
Returns the value of attribute app_root.
-
#client ⇒ Object
Returns the value of attribute client.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#map ⇒ Object
Returns the value of attribute map.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #get(k) ⇒ Object
-
#initialize ⇒ HazelcastCacheClient
constructor
A new instance of HazelcastCacheClient.
- #parse_options(app_root = Dir.pwd) ⇒ Object
- #put(k, v) ⇒ Object
- #remove(k, v) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ HazelcastCacheClient
Returns a new instance of HazelcastCacheClient.
44 45 46 47 48 49 50 51 52 |
# File 'lib/jruby-hazelcast.rb', line 44 def initialize @hostname = 'localhost' @username = 'dev' @password = 'dev-pass' @mapname = 'default' @client = HazelcastClient.newHazelcastClient(@username, @password, @hostname); @map = @client.getMap(@mapname); end |
Instance Attribute Details
#app_root ⇒ Object
Returns the value of attribute app_root.
40 41 42 |
# File 'lib/jruby-hazelcast.rb', line 40 def app_root @app_root end |
#client ⇒ Object
Returns the value of attribute client.
40 41 42 |
# File 'lib/jruby-hazelcast.rb', line 40 def client @client end |
#hostname ⇒ Object
Returns the value of attribute hostname.
40 41 42 |
# File 'lib/jruby-hazelcast.rb', line 40 def hostname @hostname end |
#map ⇒ Object
Returns the value of attribute map.
40 41 42 |
# File 'lib/jruby-hazelcast.rb', line 40 def map @map end |
#password ⇒ Object
Returns the value of attribute password.
40 41 42 |
# File 'lib/jruby-hazelcast.rb', line 40 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
40 41 42 |
# File 'lib/jruby-hazelcast.rb', line 40 def username @username end |
Instance Method Details
#get(k) ⇒ Object
101 102 103 104 |
# File 'lib/jruby-hazelcast.rb', line 101 def get(k) return unless k @map.get(k) end |
#parse_options(app_root = Dir.pwd) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/jruby-hazelcast.rb', line 54 def (app_root = Dir.pwd) if defined?(RAILS_ROOT) self.app_root = RAILS_ROOT + '/config/' environment = RAILS_ENV || 'production' else self.app_root = app_root environment = ENV['JRUBY_HAZELCAST_ENV'] || 'production' end config_file = self.app_root + '/hazelcast.yml' if !File.exists?(config_file) return puts "hazelcast.yml missing in directory " + self.app_root + ' , using defaults !!!' return false end conf = YAML::load(ERB.new(IO.read(config_file)).result)[environment] return if conf.nil? conf.each do |key,value| case key when 'hostname' @hostname = value when 'username' @username = value when 'password' @password = value when 'mapname' @mapname = value end unless conf.nil? end end |
#put(k, v) ⇒ Object
96 97 98 99 |
# File 'lib/jruby-hazelcast.rb', line 96 def put(k,v) return unless k && v @map.put(k,v) end |
#remove(k, v) ⇒ Object
92 93 94 |
# File 'lib/jruby-hazelcast.rb', line 92 def remove(k,v) @map.remove(k,v) end |
#values ⇒ Object
88 89 90 |
# File 'lib/jruby-hazelcast.rb', line 88 def values @map.values.to_a end |