io.github.bucket4j.grid.hazelcast.Bucket4jHazelcast Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bucket4j_jdk11-hazelcast-4 Show documentation
Show all versions of bucket4j_jdk11-hazelcast-4 Show documentation
Bucket4j integration with Hazelcast 3.x branch
The newest version!
/*-
* ========================LICENSE_START=================================
* Bucket4j
* %%
* Copyright (C) 2015 - 2024 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==================================
*/
package io.github.bucket4j.grid.hazelcast;
import java.util.Objects;
import com.hazelcast.map.IMap;
import io.github.bucket4j.distributed.proxy.AbstractProxyManagerBuilder;
/**
* Entry point for Hazelcast integration
*/
public class Bucket4jHazelcast {
/**
* Returns the builder for {@link HazelcastProxyManager}
*
* @param map
*
* @return new instance of {@link HazelcastCompareAndSwapBasedProxyManagerBuilder}
*
* @param type ok key
*/
public static HazelcastProxyManagerBuilder entryProcessorBasedBuilder(IMap map) {
return new HazelcastProxyManagerBuilder<>(map);
}
/**
* Returns the builder for {@link HazelcastLockBasedProxyManager}
*
* @param map
*
* @return new instance of {@link HazelcastLockBasedProxyManagerBuilder}
*
* @param type ok key
*/
public static HazelcastLockBasedProxyManagerBuilder lockBasedBuilder(IMap map) {
return new HazelcastLockBasedProxyManagerBuilder<>(map);
}
/**
* Returns the builder for {@link HazelcastCompareAndSwapBasedProxyManager}
*
* @param map
*
* @return new instance of {@link HazelcastCompareAndSwapBasedProxyManagerBuilder}
*
* @param type ok key
*/
public static HazelcastCompareAndSwapBasedProxyManagerBuilder casBasedBuilder(IMap map) {
return new HazelcastCompareAndSwapBasedProxyManagerBuilder<>(map);
}
public static class HazelcastProxyManagerBuilder extends AbstractProxyManagerBuilder, HazelcastProxyManagerBuilder> {
final IMap map;
String offloadableExecutorName;
public HazelcastProxyManagerBuilder(IMap map) {
this.map = Objects.requireNonNull(map);
}
public HazelcastProxyManagerBuilder offloadableExecutorName(String offloadableExecutorName) {
this.offloadableExecutorName = Objects.requireNonNull(offloadableExecutorName);
return this;
}
@Override
public HazelcastProxyManager build() {
return new HazelcastProxyManager<>(this);
}
@Override
public boolean isExpireAfterWriteSupported() {
return true;
}
}
public static class HazelcastCompareAndSwapBasedProxyManagerBuilder extends AbstractProxyManagerBuilder, HazelcastCompareAndSwapBasedProxyManagerBuilder> {
final IMap map;
public HazelcastCompareAndSwapBasedProxyManagerBuilder(IMap map) {
this.map = Objects.requireNonNull(map);
}
@Override
public HazelcastCompareAndSwapBasedProxyManager build() {
return new HazelcastCompareAndSwapBasedProxyManager<>(this);
}
}
public static class HazelcastLockBasedProxyManagerBuilder extends AbstractProxyManagerBuilder, HazelcastLockBasedProxyManagerBuilder> {
final IMap map;
public HazelcastLockBasedProxyManagerBuilder(IMap map) {
this.map = Objects.requireNonNull(map);
}
@Override
public HazelcastLockBasedProxyManager build() {
return new HazelcastLockBasedProxyManager<>(this);
}
@Override
public boolean isExpireAfterWriteSupported() {
return true;
}
}
}