io.github.bucket4j.grid.infinispan.hotrod.HotrodInfinispanProxyManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bucket4j_jdk11-infinispan Show documentation
Show all versions of bucket4j_jdk11-infinispan Show documentation
Bucket4j integration with Infinispan
The newest version!
/*-
* ========================LICENSE_START=================================
* Bucket4j
* %%
* Copyright (C) 2015 - 2020 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.
* =========================LICENSE_END==================================
*/
/*
*
* Copyright 2015-2018 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.hotrod;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.commons.CacheException;
import org.infinispan.functional.FunctionalMap.ReadWriteMap;
import io.github.bucket4j.distributed.proxy.AbstractProxyManager;
import io.github.bucket4j.distributed.proxy.ClientSideConfig;
import io.github.bucket4j.distributed.remote.CommandResult;
import io.github.bucket4j.distributed.remote.Request;
import io.github.bucket4j.distributed.serialization.InternalSerializationHelper;
import io.github.bucket4j.grid.infinispan.Bucket4jInfinispan;
import io.github.bucket4j.grid.infinispan.InfinispanProcessor;
import static io.github.bucket4j.distributed.serialization.InternalSerializationHelper.deserializeResult;
/**
* The extension of Bucket4j library addressed to support Infinispan in-memory computing platform via Hotrod client.
*/
public class HotrodInfinispanProxyManager extends AbstractProxyManager {
private final RemoteCache remoteCache;
public HotrodInfinispanProxyManager(Bucket4jInfinispan.HotrodInfinispanProxyManagerBuilder builder) {
super(builder.getClientSideConfig());
this.remoteCache = builder.remoteCache;
}
@Override
public CommandResult execute(K key, Request request) {
byte[] requestBytes = InternalSerializationHelper.serializeRequest(request);
Map params = new HashMap<>();
params.put(Bucket4jTask.KEY_PARAM, key);
params.put(Bucket4jTask.REQUEST_PARAM, requestBytes);
byte[] responseBytes = remoteCache.execute(Bucket4jTask.TASK_NAME, params, key);
return deserializeResult(responseBytes, request.getBackwardCompatibilityVersion());
}
@Override
public boolean isAsyncModeSupported() {
return false;
}
@Override
public void removeProxy(K key) {
remoteCache.remove(key);
}
@Override
protected CompletableFuture removeAsync(K key) {
throw new UnsupportedOperationException();
}
@Override
public CompletableFuture> executeAsync(K key, Request request) {
throw new UnsupportedOperationException();
}
@Override
public boolean isExpireAfterWriteSupported() {
return true;
}
}