Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Support Infinispan 8.x, included in WildFly 10
- Loading branch information
1 parent
d2434d6
commit 7b767c6
Showing
7 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
|
||
<parent> | ||
<groupId>org.projectodd.wunderboss</groupId> | ||
<artifactId>wunderboss-modules</artifactId> | ||
<version>0.8.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.projectodd.wunderboss</groupId> | ||
<artifactId>wunderboss-caching-ispan8</artifactId> | ||
<name>WunderBoss Caching Module for Infinispan 8.x</name> | ||
|
||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<version.infinispan>8.0.0.CR1</version.infinispan> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectodd.wunderboss</groupId> | ||
<artifactId>wunderboss-caching</artifactId> | ||
<version>${project.version}</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-core</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-core</artifactId> | ||
<version>${version.infinispan}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>com.theoryinpractise</groupId> | ||
<artifactId>clojure-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>test</id> | ||
<phase>test</phase> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
|
||
</plugins> | ||
</build> | ||
|
||
</project> |
107 changes: 107 additions & 0 deletions
107
modules/caching-ispan8/src/main/java/org/projectodd/wunderboss/caching/CacheWithCodec8.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright 2014-2015 Red Hat, Inc, and individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.projectodd.wunderboss.caching; | ||
|
||
import org.infinispan.Cache; | ||
import org.infinispan.CacheSet; | ||
import org.infinispan.CacheCollection; | ||
import org.infinispan.CacheStream; | ||
import org.infinispan.commons.util.Closeables; | ||
import org.infinispan.commons.util.CloseableIterator; | ||
import org.infinispan.commons.util.CloseableSpliterator; | ||
import org.infinispan.container.entries.ImmortalCacheEntry; | ||
import org.infinispan.distribution.DistributionManager; | ||
import org.infinispan.distribution.ch.ConsistentHash; | ||
import org.infinispan.stream.impl.local.ValueCacheCollection; | ||
import org.infinispan.stream.impl.local.LocalEntryCacheStream; | ||
import org.projectodd.wunderboss.codecs.Codec; | ||
import java.util.AbstractCollection; | ||
import java.util.function.Function; | ||
|
||
|
||
public class CacheWithCodec8 extends CacheWithCodec { | ||
|
||
public CacheWithCodec8(Cache cache, Codec codec) { | ||
super(cache, codec); | ||
} | ||
|
||
@Override | ||
public CacheSet keySet() { | ||
return new EncodedCache(super.keySet(), x -> decode(x)); | ||
} | ||
|
||
@Override | ||
public CacheSet entrySet() { | ||
return new EncodedCache(super.entrySet(), | ||
x -> { | ||
Entry e = (Entry) x; | ||
return new ImmortalCacheEntry(decode(e.getKey()), | ||
decode(e.getValue())); | ||
}); | ||
} | ||
|
||
@Override | ||
public CacheCollection values() { | ||
return new ValueCacheCollection(this, entrySet()); | ||
} | ||
|
||
class EncodedCache extends AbstractCollection implements CacheSet { | ||
|
||
EncodedCache(CacheSet delegate, Function mapper) { | ||
this.delegate = delegate; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return CacheWithCodec8.this.size(); | ||
} | ||
|
||
@Override | ||
public CacheStream stream() { | ||
return new LocalEntryCacheStream(cache, false, getConsistentHash(cache), | ||
() -> delegate.stream().map(mapper), | ||
cache.getAdvancedCache().getComponentRegistry()); | ||
} | ||
|
||
@Override | ||
public CacheStream parallelStream() { | ||
return new LocalEntryCacheStream(cache, true, getConsistentHash(cache), | ||
() -> delegate.stream().map(mapper), | ||
cache.getAdvancedCache().getComponentRegistry()); | ||
} | ||
|
||
@Override | ||
public CloseableIterator iterator() { | ||
return Closeables.iterator(stream()); | ||
} | ||
|
||
@Override | ||
public CloseableSpliterator spliterator() { | ||
return Closeables.spliterator(stream()); | ||
} | ||
|
||
private ConsistentHash getConsistentHash(Cache cache) { | ||
DistributionManager dm = cache.getAdvancedCache().getDistributionManager(); | ||
return (dm != null) ? dm.getReadConsistentHash() : null; | ||
} | ||
|
||
private CacheSet delegate; | ||
private Function mapper; | ||
private Cache cache = CacheWithCodec8.this; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
modules/caching-ispan8/src/main/java/org/projectodd/wunderboss/caching/Encoder8.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2014-2015 Red Hat, Inc, and individual contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.projectodd.wunderboss.caching; | ||
|
||
import org.infinispan.Cache; | ||
import org.projectodd.wunderboss.codecs.Codec; | ||
|
||
public class Encoder8 implements Encoder { | ||
public Cache encode(Cache cache, Codec codec) { | ||
return new CacheWithCodec8(cache, codec); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
modules/caching-ispan8/src/test/clojure/wunderboss/caching_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
;; Copyright 2014-2015 Red Hat, Inc, and individual contributors. | ||
;; | ||
;; Licensed under the Apache License, Version 2.0 (the "License"); | ||
;; you may not use this file except in compliance with the License. | ||
;; You may obtain a copy of the License at | ||
;; | ||
;; http://www.apache.org/licenses/LICENSE-2.0 | ||
;; | ||
;; Unless required by applicable law or agreed to in writing, software | ||
;; distributed under the License is distributed on an "AS IS" BASIS, | ||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
;; See the License for the specific language governing permissions and | ||
;; limitations under the License. | ||
|
||
(ns wunderboss.caching-test | ||
(:require [clojure.test :refer :all]) | ||
(:import org.projectodd.wunderboss.WunderBoss | ||
[org.projectodd.wunderboss.caching Caching Caching$CreateOption Config] | ||
org.projectodd.wunderboss.Options | ||
org.infinispan.configuration.cache.CacheMode | ||
java.util.Arrays)) | ||
|
||
(def default (doto (WunderBoss/findOrCreateComponent Caching) (.start))) | ||
|
||
(deftest byte-array-keys | ||
(let [c (.findOrCreate default "bytes" (Options.)) | ||
k (byte-array [1 2 3]) | ||
v (byte-array [4 5 6])] | ||
(.put c k v) | ||
(is (Arrays/equals (byte-array [4 5 6]) (get c (byte-array [1 2 3])))))) | ||
|
||
(deftest mode-local-if-not-clustered | ||
(let [options (Options. {Caching$CreateOption/MODE "repl_sync"}) | ||
config (Config/uration options) | ||
c (.findOrCreate default "repl" options)] | ||
(is (= CacheMode/REPL_SYNC (.. config clustering cacheMode))) | ||
(is (= CacheMode/LOCAL (.. c getCacheConfiguration clustering cacheMode))))) | ||
|
28 changes: 28 additions & 0 deletions
28
modules/caching-ispan8/src/test/clojure/wunderboss/config_test.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
;; Copyright 2014-2015 Red Hat, Inc, and individual contributors. | ||
;; | ||
;; Licensed under the Apache License, Version 2.0 (the "License"); | ||
;; you may not use this file except in compliance with the License. | ||
;; You may obtain a copy of the License at | ||
;; | ||
;; http://www.apache.org/licenses/LICENSE-2.0 | ||
;; | ||
;; Unless required by applicable law or agreed to in writing, software | ||
;; distributed under the License is distributed on an "AS IS" BASIS, | ||
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
;; See the License for the specific language governing permissions and | ||
;; limitations under the License. | ||
|
||
(ns wunderboss.config-test | ||
(:require [clojure.test :refer :all]) | ||
(:import [org.projectodd.wunderboss.caching Caching$CreateOption Config] | ||
org.projectodd.wunderboss.Options)) | ||
|
||
(deftest persistence | ||
(is (not (.. (Config/uration (Options.)) | ||
persistence usingStores))) | ||
(is (not (.. (Config/uration (Options. {Caching$CreateOption/PERSIST false})) | ||
persistence usingStores))) | ||
(is (.. (Config/uration (Options. {Caching$CreateOption/PERSIST true})) | ||
persistence usingStores)) | ||
(is (.. (Config/uration (Options. {Caching$CreateOption/PERSIST "foo"})) | ||
persistence usingStores))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters