mondrian_redis_segment_cache 0.0.1-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 944df5e6367ba2e9ef1e8c4039bb27861047b29d
4
+ data.tar.gz: 88bbf5c510e78f4c134f8c3b7e89340d4d6631f5
5
+ SHA512:
6
+ metadata.gz: 18ee04d142c2eca9448abe0b02b3402c56eb3911847927eec3b370075c84cb73e9e0d61caac7f78783463777f06869da6c80f3fa777bf25508aa9e4c73439ead
7
+ data.tar.gz: 261086e8dbd5fd0b30099354a63743c291b87c84dbd7416d4e3adeade036b0b9bb87e410575d42b34512aa72bf8cede56b99e8d78f38380e9eea766dfd0e7bc4
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.ruby-*
4
+ *.swp
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mondrian_redis_segment_cache.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brandon Dewitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # MondrianRedisSegmentCache
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mondrian_redis_segment_cache'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mondrian_redis_segment_cache
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ require 'java'
2
+ require 'java_to_base64'
3
+ require 'mondrian-olap'
4
+ require 'mondrian_redis_segment_cache/created_event'
5
+ require 'mondrian_redis_segment_cache/deleted_event'
6
+ require 'mondrian_redis_segment_cache/segment_body'
7
+ require 'mondrian_redis_segment_cache/segment_header'
8
+ require "mondrian_redis_segment_cache/version"
9
+
10
+ module MondrianRedisSegmentCache
11
+ end
@@ -0,0 +1,201 @@
1
+ require 'redis'
2
+
3
+ module MondrianRedisSegmentCache
4
+ class Cache
5
+ include Java::MondrianSpi::SegmentCache
6
+
7
+ attr_reader :mondrian_redis, :listeners, :created_listener_connection, :deleted_listener_connection
8
+
9
+ SEGMENT_HEADERS_SET_KEY = "MONDRIAN_SEGMENT_HEADERS_SET"
10
+
11
+ ##
12
+ # Constructor
13
+ #
14
+ def initialize(mondrian_redis_connection)
15
+ @mondrian_redis = mondrian_redis_connection
16
+ @created_listener_connection = ::Redis.new(client_options)
17
+ @deleted_listener_connection = ::Redis.new(client_options)
18
+
19
+ reset_listeners
20
+ register_for_redis_events
21
+ end
22
+
23
+ ##
24
+ # Public Instance Methods
25
+ #
26
+ def addListener(segment_cache_listener)
27
+ listeners << segment_cache_listener
28
+ end
29
+
30
+ # returns boolean
31
+ # takes mondrian.spi.SegmentHeader
32
+ def contains(segment_header)
33
+ segment_header.description # Hazel adapter says this affects serialization
34
+ header_base64 = segment_header_to_base64(segment_header)
35
+
36
+ if header_base64
37
+ return mondrian_redis.exists(header_base64)
38
+ end
39
+
40
+ return false
41
+ end
42
+
43
+ def created_event_key
44
+ @created_event_key ||= "__keyevent@#{client_options[:db]}__:set"
45
+ end
46
+
47
+ def deleted_event_key
48
+ @created_event_key ||= "__keyevent@#{client_options[:db]}__:del"
49
+ end
50
+
51
+ # returns mondrian.spi.SegmentBody
52
+ # takes mondrian.spi.SegmentHeader
53
+ def get(segment_header)
54
+ segment_header.description # Hazel adapter says this affects serialization
55
+ header_base64 = segment_header_to_base64(segment_header)
56
+
57
+ if header_base64
58
+ body_base64 = mondrian_redis.get(header_base64)
59
+ return segment_body_from_base64(body_base64)
60
+ end
61
+
62
+ return nil
63
+ end
64
+
65
+ # returns ArrayList<SegmentHeader>
66
+ def getSegmentHeaders()
67
+ segment_headers_base64 = mondrian_redis.smembers(SEGMENT_HEADERS_SET_KEY)
68
+ segment_headers = ::Java::JavaUtil::ArrayList.new
69
+ segment_headers_base64.each do |segment_header_base64|
70
+ segment_header = segment_header_from_base64(segment_header_base64)
71
+
72
+ if segment_header
73
+ segment_headers << segment_header
74
+ end
75
+ end
76
+
77
+ return segment_headers
78
+ end
79
+
80
+ def publish_created_to_listeners(message)
81
+ segment_header = segment_header_from_base64(message)
82
+
83
+ if segment_header
84
+ listeners.each do |listener|
85
+ created_event = MondrianRedisCacheCreatedEvent.new(segment_header)
86
+ listener.handle(created_event)
87
+ end
88
+ end
89
+ end
90
+
91
+ def publish_deleted_to_listeners(message)
92
+ segment_header = segment_header_from_base64(message)
93
+
94
+ if segment_header
95
+ listeners.each do |listener|
96
+ deleted_event = MondrianRedisCacheDeletedEvent.new(segment_header)
97
+ listener.handle(deleted_evet)
98
+ end
99
+ end
100
+ end
101
+
102
+ def put(segment_header, segment_body)
103
+ segment_header.description # Hazel adapter says this affects serialization
104
+ header_base64 = segment_header_to_base64(segment_header)
105
+ body_base64 = segment_body_to_base64(segment_body)
106
+ mondrian_redis.sadd(SEGMENT_HEADERS_SET_KEY, header_base64)
107
+ set_success = mondrian_redis.set(header_base64, body_base64)
108
+
109
+ return (set_success == "OK" || set_success == true) # weird polymorphic return ?
110
+ end
111
+
112
+ def remove(segment_header)
113
+ segment_header.description # Hazel adapter says this affects serialization
114
+ header_base64 = segment_header_to_base64(segment_header)
115
+ mondrian_redis.srem(SEGMENT_HEADERS_SET_KEY, header_base64)
116
+ deleted_keys = mondrian_redis.del(header_base64)
117
+
118
+ return deleted_keys >= 1
119
+ end
120
+
121
+ def removeListener(segment_cache_listener)
122
+ listeners.delete(segment_cache_listener)
123
+ end
124
+
125
+ def reset_listeners
126
+ @listeners = Set.new
127
+ end
128
+
129
+ def supportsRichIndex()
130
+ true # this is why we are serializing the headers to base64
131
+ end
132
+
133
+ def tearDown()
134
+ # Remove all of the headers and the set that controls them
135
+ segment_headers_base64 = mondrian_redis.smembers(SEGMENT_HEADERS_SET_KEY)
136
+ segment_headers_base64.each do |segment_header_base64|
137
+ mondrian_redis.del(segment_header_base64)
138
+ end
139
+
140
+ mondrian_redis.del(SEGMENT_HEADERS_SET_KEY)
141
+ end
142
+
143
+ private
144
+
145
+ ##
146
+ # Private Instance Methods
147
+ #
148
+ def client_options
149
+ mondrian_redis.client.options
150
+ end
151
+
152
+ def register_for_redis_events
153
+ return if @listeners_registered
154
+
155
+ # Not the best multi-threaded code, but its something that "works" for now and we will
156
+ # worry about "best" later
157
+
158
+ Thread.new(created_listener_connection, self) do |created_redis_connection, mondrian_cache|
159
+ created_redis_connection.subscribe(mondrian_cache.created_event_key) do |on|
160
+ on.message do |channel, message|
161
+ mondrian_cache.publish_created_to_listeners(message)
162
+ end
163
+ end
164
+ end
165
+
166
+ Thread.new(deleted_listener_connection, self) do |deleted_redis_connection, mondrian_cache|
167
+ deleted_redis_connection.subscribe(mondrian_cache.deleted_event_key) do |on|
168
+ on.message do |channel, message|
169
+ mondrian_cache.publish_deleted_to_listeners(message)
170
+ end
171
+ end
172
+ end
173
+
174
+ @listeners_registered = true
175
+ end
176
+
177
+ def segment_body_from_base64(segment_body_base64)
178
+ return nil unless segment_body_base64
179
+ return ::Java::MondrianSpi::SegmentBody.from_base64(segment_body_base64)
180
+ rescue
181
+ return nil
182
+ end
183
+
184
+ def segment_body_to_base64(segment_body)
185
+ return nil unless segment_body
186
+ return segment_body.to_base64
187
+ end
188
+
189
+ def segment_header_from_base64(segment_header_base64)
190
+ return nil unless segment_header_base64
191
+ return ::Java::MondrianSpi::SegmentHeader.from_base64(segment_header_base64)
192
+ rescue
193
+ return nil
194
+ end
195
+
196
+ def segment_header_to_base64(segment_header)
197
+ return nil unless segment_header
198
+ return segment_header.to_base64
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,21 @@
1
+ module MondrianRedisSegmentCache
2
+ class CreatedEvent
3
+ include ::Java::MondrianSpi::SegmentCache::SegmentCacheListener::SegmentCacheEvent
4
+
5
+ def initialize(segment_header)
6
+ @segment_header = segment_header
7
+ end
8
+
9
+ def getEventType()
10
+ Java::MondrianSpi::SegmentCache::SegmentCacheListener::SegmentCacheEvent::EventType::ENTRY_CREATED
11
+ end
12
+
13
+ def getSource()
14
+ @segment_header
15
+ end
16
+
17
+ def isLocal()
18
+ false
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module MondrianRedisSegmentCache
2
+ class DeletedEvent
3
+ include ::Java::MondrianSpi::SegmentCache::SegmentCacheListener::SegmentCacheEvent
4
+
5
+ def initialize(segment_header)
6
+ @segment_header = segment_header
7
+ end
8
+
9
+ def getEventType()
10
+ Java::MondrianSpi::SegmentCache::SegmentCacheListener::SegmentCacheEvent::EventType::ENTRY_DELETED
11
+ end
12
+
13
+ def getSource()
14
+ @segment_header
15
+ end
16
+
17
+ def isLocal()
18
+ false
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ require 'java_to_base64'
2
+
3
+ # SegmentBody is an interface and thus a module in Jruby
4
+ module Java::MondrianSpi::SegmentBody
5
+ include JavaToBase64::InstanceMethods
6
+ extend JavaToBase64::ClassMethods
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'java_to_base64'
2
+
3
+ class Java::MondrianSpi::SegmentHeader
4
+ include JavaToBase64
5
+ end
@@ -0,0 +1,3 @@
1
+ module MondrianRedisSegmentCache
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mondrian_redis_segment_cache/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mondrian_redis_segment_cache"
8
+ gem.version = MondrianRedisSegmentCache::VERSION
9
+ gem.authors = ["Brandon Dewitt"]
10
+ gem.email = ["brandonsdewitt@gmail.com"]
11
+ gem.description = %q{Segment Cache for Mondrian written in JRuby with Redis as the cache store}
12
+ gem.summary = %q{Segment Cache for Mondrian written in JRuby with Redis as the cache store}
13
+ gem.homepage = ""
14
+ gem.platform = "java"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency "redis"
22
+ gem.add_dependency "java_to_base64"
23
+ gem.add_dependency "mondrian-olap"
24
+
25
+ gem.add_development_dependency "bundler"
26
+ gem.add_development_dependency "mocha"
27
+ gem.add_development_dependency "pry"
28
+ gem.add_development_dependency "rake"
29
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mondrian_redis_segment_cache
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: java
6
+ authors:
7
+ - Brandon Dewitt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '>='
23
+ - !ruby/object:Gem::Version
24
+ version: '0'
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: java_to_base64
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: mondrian-olap
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ prerelease: false
82
+ type: :development
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ prerelease: false
96
+ type: :development
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ prerelease: false
110
+ type: :development
111
+ description: Segment Cache for Mondrian written in JRuby with Redis as the cache store
112
+ email:
113
+ - brandonsdewitt@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/mondrian_redis_segment_cache.rb
124
+ - lib/mondrian_redis_segment_cache/cache.rb
125
+ - lib/mondrian_redis_segment_cache/created_event.rb
126
+ - lib/mondrian_redis_segment_cache/deleted_event.rb
127
+ - lib/mondrian_redis_segment_cache/segment_body.rb
128
+ - lib/mondrian_redis_segment_cache/segment_header.rb
129
+ - lib/mondrian_redis_segment_cache/version.rb
130
+ - mondrian_redis_segment_cache.gemspec
131
+ homepage: ''
132
+ licenses: []
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.2.2
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Segment Cache for Mondrian written in JRuby with Redis as the cache store
154
+ test_files: []