Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Support Infinispan 8.x, included in WildFly 10
  • Loading branch information
jcrossley3 committed Aug 28, 2015
1 parent d2434d6 commit 7b767c6
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 2 deletions.
74 changes: 74 additions & 0 deletions modules/caching-ispan8/pom.xml
@@ -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>
@@ -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;
}
}
@@ -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);
}
}
@@ -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 modules/caching-ispan8/src/test/clojure/wunderboss/config_test.clj
@@ -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)))
15 changes: 15 additions & 0 deletions modules/wildfly/pom.xml
Expand Up @@ -71,6 +71,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectodd.wunderboss</groupId>
<artifactId>wunderboss-caching-ispan8</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>org.projectodd.wunderboss</groupId>
<artifactId>wunderboss-caching</artifactId>
</exclusion>
<exclusion>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.projectodd.wunderboss</groupId>
<artifactId>wunderboss-transactions</artifactId>
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.projectodd.wunderboss.as.ASUtils;
import org.projectodd.wunderboss.caching.InfinispanCaching;
import org.projectodd.wunderboss.caching.Encoder6;
import org.projectodd.wunderboss.caching.Encoder8;
import org.projectodd.wunderboss.caching.Config;
import org.projectodd.wunderboss.caching.KeyEquivalenceCache;
import org.projectodd.wunderboss.codecs.Codec;
Expand All @@ -39,8 +40,9 @@ public class WildFlyCaching extends InfinispanCaching {

public WildFlyCaching(String name, Options<CreateOption> options) {
super(name, options);
if (!ASUtils.containerIsWildFly9() &&
!ASUtils.containerIsWildFly10()) {
if (ASUtils.containerIsWildFly10()) {
this.encoder = new Encoder8();
} else if (!ASUtils.containerIsWildFly9()) {
this.encoder = new Encoder6();
}
if (ASUtils.containerIsEAP()) {
Expand Down

0 comments on commit 7b767c6

Please sign in to comment.