-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support legacy version of Infinispan
- Loading branch information
1 parent
9afe331
commit 1259954
Showing
21 changed files
with
645 additions
and
12 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ | ||
~ Copyright 2015-2017 Vladimir Bukhtoyarov | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<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/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.github.vladimir-bukhtoyarov</groupId> | ||
<artifactId>bucket4j-parent</artifactId> | ||
<version>4.2.0</version> | ||
<relativePath>../bucket4j-parent</relativePath> | ||
</parent> | ||
|
||
<artifactId>bucket4j-infinispan-8</artifactId> | ||
|
||
<properties> | ||
<infinispan-8.version>8.2.0.Final</infinispan-8.version> | ||
</properties> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.infinispan/infinispan-core --> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.vladimir-bukhtoyarov</groupId> | ||
<artifactId>bucket4j-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.vladimir-bukhtoyarov</groupId> | ||
<artifactId>bucket4j-jcache</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.vladimir-bukhtoyarov</groupId> | ||
<artifactId>bucket4j-core</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.cache</groupId> | ||
<artifactId>cache-api</artifactId> | ||
<version>${jcache.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-core</artifactId> | ||
<version>${infinispan-8.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.infinispan</groupId> | ||
<artifactId>infinispan-jcache</artifactId> | ||
<version>${infinispan-8.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
56 changes: 56 additions & 0 deletions
56
bucket4j-infinispan-8/src/main/java/io/github/bucket4j/grid/infinispan/Infinispan.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,56 @@ | ||
/* | ||
* | ||
* Copyright 2015-2017 Vladimir Bukhtoyarov | ||
* | ||
* 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 io.github.bucket4j.grid.infinispan; | ||
|
||
|
||
import io.github.bucket4j.Extension; | ||
import io.github.bucket4j.grid.GridBucketState; | ||
import io.github.bucket4j.grid.ProxyManager; | ||
import org.infinispan.commons.api.functional.FunctionalMap; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* The extension of Bucket4j library addressed to support <a href="https://ignite.apache.org/">Apache ignite</a> in-memory computing platform. | ||
* | ||
* Use this extension only if you need in asynchronous API, else stay at {@link io.github.bucket4j.grid.jcache.JCache} | ||
*/ | ||
public class Infinispan implements Extension<InfinispanBucketBuilder> { | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return new instance of {@link InfinispanBucketBuilder} | ||
*/ | ||
@Override | ||
public InfinispanBucketBuilder builder() { | ||
return new InfinispanBucketBuilder(); | ||
} | ||
|
||
/** | ||
* Creates {@link InfinispanProxyManager} for specified cache. | ||
* | ||
* @param readWriteMap cache for storing state of buckets | ||
* @param <K> type of keys in the cache | ||
* @return {@link ProxyManager} for specified cache. | ||
*/ | ||
public <K extends Serializable> ProxyManager<K> proxyManagerForMap(FunctionalMap.ReadWriteMap<K, GridBucketState> readWriteMap) { | ||
return new InfinispanProxyManager<>(readWriteMap); | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
...nfinispan-8/src/main/java/io/github/bucket4j/grid/infinispan/InfinispanBucketBuilder.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,60 @@ | ||
/* | ||
* | ||
* Copyright 2015-2017 Vladimir Bukhtoyarov | ||
* | ||
* 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 io.github.bucket4j.grid.infinispan; | ||
|
||
import io.github.bucket4j.AbstractBucketBuilder; | ||
import io.github.bucket4j.Bucket; | ||
import io.github.bucket4j.BucketConfiguration; | ||
import io.github.bucket4j.grid.GridBucket; | ||
import io.github.bucket4j.grid.GridBucketState; | ||
import io.github.bucket4j.grid.RecoveryStrategy; | ||
import org.infinispan.commons.api.functional.FunctionalMap; | ||
|
||
import javax.cache.Cache; | ||
import java.io.Serializable; | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* This builder creates the buckets backed by <a href="http://infinispan.org/"></a> in-memory data store. | ||
* | ||
* @see io.github.bucket4j.grid.jcache.JCacheBucketBuilder | ||
* | ||
*/ | ||
public class InfinispanBucketBuilder extends AbstractBucketBuilder<InfinispanBucketBuilder> { | ||
|
||
/** | ||
* Creates the new instance of {@link InfinispanBucketBuilder} | ||
*/ | ||
public InfinispanBucketBuilder() { | ||
super(); | ||
} | ||
|
||
/** | ||
* Constructs an instance of {@link GridBucket} which state actually stored inside in-memory data-grid, | ||
* semantic of this method is fully equals to {@link io.github.bucket4j.grid.jcache.JCacheBucketBuilder#build(Cache, Serializable, RecoveryStrategy)} | ||
* | ||
* @return new distributed bucket | ||
*/ | ||
public <K extends Serializable> Bucket build(FunctionalMap.ReadWriteMap<K, GridBucketState> readWriteMap, K key, RecoveryStrategy recoveryStrategy) { | ||
BucketConfiguration configuration = buildConfiguration(); | ||
InfinispanProxy<K> gridProxy = new InfinispanProxy<>(readWriteMap); | ||
return GridBucket.createInitializedBucket(key, configuration, gridProxy, recoveryStrategy); | ||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
bucket4j-infinispan-8/src/main/java/io/github/bucket4j/grid/infinispan/InfinispanProxy.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,111 @@ | ||
/* | ||
* | ||
* Copyright 2015-2017 Vladimir Bukhtoyarov | ||
* | ||
* 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 io.github.bucket4j.grid.infinispan; | ||
|
||
import io.github.bucket4j.BucketConfiguration; | ||
import io.github.bucket4j.Nothing; | ||
import io.github.bucket4j.grid.CommandResult; | ||
import io.github.bucket4j.grid.GridBucketState; | ||
import io.github.bucket4j.grid.GridCommand; | ||
import io.github.bucket4j.grid.GridProxy; | ||
import io.github.bucket4j.grid.jcache.JCacheEntryProcessor; | ||
import org.infinispan.commons.CacheException; | ||
import org.infinispan.commons.api.functional.EntryView; | ||
import org.infinispan.commons.api.functional.FunctionalMap; | ||
import org.infinispan.util.SerializableFunction; | ||
|
||
import java.io.Serializable; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
public class InfinispanProxy<K extends Serializable> implements GridProxy<K> { | ||
|
||
private final FunctionalMap.ReadWriteMap<K, GridBucketState> readWriteMap; | ||
|
||
public InfinispanProxy(FunctionalMap.ReadWriteMap<K, GridBucketState> readWriteMap) { | ||
this.readWriteMap = readWriteMap; | ||
} | ||
|
||
@Override | ||
public <T extends Serializable> CommandResult<T> execute(K key, GridCommand<T> command) { | ||
JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.executeProcessor(command); | ||
return invokeSync(key, entryProcessor); | ||
} | ||
|
||
@Override | ||
public void createInitialState(K key, BucketConfiguration configuration) { | ||
JCacheEntryProcessor<K, Nothing> entryProcessor = JCacheEntryProcessor.initStateProcessor(configuration); | ||
invokeSync(key, entryProcessor); | ||
} | ||
|
||
@Override | ||
public <T extends Serializable> T createInitialStateAndExecute(K key, BucketConfiguration configuration, GridCommand<T> command) { | ||
JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.initStateAndExecuteProcessor(command, configuration); | ||
CommandResult<T> result = invokeSync(key, entryProcessor); | ||
return result.getData(); | ||
} | ||
|
||
@Override | ||
public <T extends Serializable> CompletableFuture<CommandResult<T>> executeAsync(K key, GridCommand<T> command) { | ||
JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.executeProcessor(command); | ||
return invokeAsync(key, entryProcessor); | ||
} | ||
|
||
@Override | ||
public <T extends Serializable> CompletableFuture<T> createInitialStateAndExecuteAsync(K key, BucketConfiguration configuration, GridCommand<T> command) { | ||
JCacheEntryProcessor<K, T> entryProcessor = JCacheEntryProcessor.initStateAndExecuteProcessor(command, configuration); | ||
CompletableFuture<CommandResult<T>> result = invokeAsync(key, entryProcessor); | ||
return result.thenApply(CommandResult::getData); | ||
} | ||
|
||
@Override | ||
public Optional<BucketConfiguration> getConfiguration(K key) { | ||
try { | ||
SerializableFunction<EntryView.ReadWriteEntryView<K, GridBucketState>, GridBucketState> findFunction = | ||
(SerializableFunction<EntryView.ReadWriteEntryView<K, GridBucketState>, GridBucketState>) | ||
entry -> entry.find().orElse(null); | ||
GridBucketState state = readWriteMap.eval(key, findFunction).get(); | ||
if (state == null) { | ||
return Optional.empty(); | ||
} else { | ||
return Optional.of(state.getConfiguration()); | ||
} | ||
} catch (InterruptedException | ExecutionException e) { | ||
throw new CacheException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isAsyncModeSupported() { | ||
return true; | ||
} | ||
|
||
private <T extends Serializable> CommandResult<T> invokeSync(final K key, final JCacheEntryProcessor<K, T> entryProcessor) { | ||
try { | ||
return readWriteMap.eval(key, new SerializableFunctionAdapter<>(entryProcessor)).get(); | ||
} catch (InterruptedException | ExecutionException e) { | ||
throw new CacheException(e); | ||
} | ||
} | ||
|
||
private <T extends Serializable> CompletableFuture<CommandResult<T>> invokeAsync(final K key, final JCacheEntryProcessor<K, T> entryProcessor) { | ||
return readWriteMap.eval(key, new SerializableFunctionAdapter<>(entryProcessor)); | ||
} | ||
|
||
} |
Oops, something went wrong.