repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodAsyncLocks.java
|
package org.infinispan.hotrod;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow;
import org.infinispan.api.async.AsyncLock;
import org.infinispan.api.async.AsyncLocks;
import org.infinispan.api.configuration.LockConfiguration;
/**
* @since 14.0
**/
public class HotRodAsyncLocks implements AsyncLocks {
private final HotRod hotrod;
HotRodAsyncLocks(HotRod hotrod) {
this.hotrod = hotrod;
}
@Override
public CompletionStage<AsyncLock> create(String name, LockConfiguration configuration) {
return CompletableFuture.completedFuture(new HotRodAsyncLock(hotrod, name)); // PLACEHOLDER
}
@Override
public CompletionStage<AsyncLock> lock(String name) {
return CompletableFuture.completedFuture(new HotRodAsyncLock(hotrod, name)); // PLACEHOLDER
}
@Override
public CompletionStage<Void> remove(String name) {
return null;
}
@Override
public Flow.Publisher<String> names() {
return null;
}
}
| 1,045
| 24.512195
| 97
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodMutinyStrongCounters.java
|
package org.infinispan.hotrod;
import org.infinispan.api.configuration.CounterConfiguration;
import org.infinispan.api.mutiny.MutinyStrongCounter;
import org.infinispan.api.mutiny.MutinyStrongCounters;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public class HotRodMutinyStrongCounters implements MutinyStrongCounters {
private final HotRod hotrod;
HotRodMutinyStrongCounters(HotRod hotrod) {
this.hotrod = hotrod;
}
@Override
public Uni<MutinyStrongCounter> get(String name) {
return Uni.createFrom().item(new HotRodMutinyStrongCounter(hotrod, name)); // PLACEHOLDER
}
@Override
public Uni<MutinyStrongCounter> create(String name, CounterConfiguration configuration) {
return Uni.createFrom().item(new HotRodMutinyStrongCounter(hotrod, name)); // PLACEHOLDER
}
@Override
public Uni<Void> remove(String name) {
return null;
}
@Override
public Multi<String> names() {
return null;
}
}
| 1,011
| 24.3
| 95
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodAsyncQuery.java
|
package org.infinispan.hotrod;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Flow;
import org.infinispan.api.async.AsyncCacheEntryProcessor;
import org.infinispan.api.async.AsyncQuery;
import org.infinispan.api.async.AsyncQueryResult;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.events.cache.CacheContinuousQueryEvent;
import org.infinispan.api.common.process.CacheEntryProcessorResult;
import org.infinispan.api.common.process.CacheProcessor;
import org.infinispan.api.common.process.CacheProcessorOptions;
import org.infinispan.hotrod.impl.cache.RemoteQuery;
/**
* @since 14.0
**/
public class HotRodAsyncQuery<K, V, R> implements AsyncQuery<K, V, R> {
private final RemoteQuery query;
HotRodAsyncQuery(String query, CacheOptions options) {
this.query = new RemoteQuery(query, options);
}
@Override
public AsyncQuery<K, V, R> param(String name, Object value) {
query.param(name, value);
return this;
}
@Override
public AsyncQuery<K, V, R> skip(long skip) {
query.skip(skip);
return this;
}
@Override
public AsyncQuery<K, V, R> limit(int limit) {
query.limit(limit);
return this;
}
@Override
public CompletionStage<AsyncQueryResult<R>> find() {
return null;
}
@Override
public Flow.Publisher<CacheContinuousQueryEvent<K, R>> findContinuously(String query) {
return null;
}
@Override
public CompletionStage<Long> execute() {
return null;
}
@Override
public <T> Flow.Publisher<CacheEntryProcessorResult<K, T>> process(AsyncCacheEntryProcessor<K, V, T> processor, CacheProcessorOptions options) {
return null;
}
@Override
public <T> Flow.Publisher<CacheEntryProcessorResult<K, T>> process(CacheProcessor processor, CacheProcessorOptions options) {
return null;
}
}
| 1,893
| 26.449275
| 147
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodFlag.java
|
package org.infinispan.hotrod;
import org.infinispan.api.common.Flag;
import org.infinispan.api.common.Flags;
/**
* Defines all the flags available in the Hot Rod client that can influence the behavior of operations.
* <p />
* Available flags:
* <ul>
* <li>{@link #DEFAULT_LIFESPAN} This flag can either be used as a request flag during a put operation to mean
* that the default server lifespan should be applied or as a response flag meaning that
* the return entry has a default lifespan value</li>
* <li>{@link #DEFAULT_MAXIDLE} This flag can either be used as a request flag during a put operation to mean
* that the default server maxIdle should be applied or as a response flag meaning that
* the return entry has a default maxIdle value</li>
* <li>{@link #SKIP_CACHE_LOAD} Skips loading an entry from any configured
* cache loaders</li>
* <li>{@link #SKIP_INDEXING} Used by the Query module only, it will prevent the indexes to be updated as a result
* of the current operations.
* <li>{@link #SKIP_LISTENER_NOTIFICATION} Used when an operation wants to skip notifications to the registered listeners
* </ul>
*
* @since 14.0
*/
public enum HotRodFlag implements Flag {
/**
* This flag can either be used as a request flag during a put operation to mean that the default
* server lifespan should be applied or as a response flag meaning that the return entry has a
* default lifespan value
*/
DEFAULT_LIFESPAN(0x0002),
/**
* This flag can either be used as a request flag during a put operation to mean that the default
* server maxIdle should be applied or as a response flag meaning that the return entry has a
* default maxIdle value
*/
DEFAULT_MAXIDLE(0x0004),
/**
* Skips loading an entry from any configured cache loaders
*/
SKIP_CACHE_LOAD(0x0008),
/**
* Used by the Query module only, it will prevent the indexes to be updated as a result of the current operations.
*/
SKIP_INDEXING(0x0010),
/**
* It will skip client listeners to be notified.
*/
SKIP_LISTENER_NOTIFICATION(0x0020)
;
private final int flagInt;
HotRodFlag(int flagInt) {
this.flagInt = flagInt;
}
public int getFlagInt() {
return flagInt;
}
@Override
public Flags<?, ?> add(Flags<?, ?> flags) {
HotRodFlags userFlags = (HotRodFlags) flags;
if (userFlags == null) {
userFlags = HotRodFlags.of(this);
} else {
userFlags.add(this);
}
return userFlags;
}
}
| 2,793
| 36.253333
| 126
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodAsyncCaches.java
|
package org.infinispan.hotrod;
import java.util.Set;
import java.util.concurrent.CompletionStage;
import org.infinispan.api.async.AsyncCache;
import org.infinispan.api.async.AsyncCaches;
import org.infinispan.api.configuration.CacheConfiguration;
import org.infinispan.hotrod.configuration.RemoteCacheConfiguration;
/**
* @since 14.0
**/
public class HotRodAsyncCaches implements AsyncCaches {
private final HotRod hotrod;
HotRodAsyncCaches(HotRod hotrod) {
this.hotrod = hotrod;
}
@Override
public <K, V> CompletionStage<AsyncCache<K, V>> create(String name, CacheConfiguration cacheConfiguration) {
RemoteCacheConfiguration configuration = RemoteCacheConfiguration.fromCacheConfiguration(name, cacheConfiguration);
return hotrod.transport.<K, V>getRemoteCache(name, configuration).thenApply(r -> new HotRodAsyncCache<>(hotrod, r));
}
@Override
public <K, V> CompletionStage<AsyncCache<K, V>> create(String name, String template) {
RemoteCacheConfiguration configuration = RemoteCacheConfiguration.fromTemplate(name, template);
return hotrod.transport.<K, V>getRemoteCache(name, configuration).thenApply(r -> new HotRodAsyncCache<>(hotrod, r));
}
@Override
public <K, V> CompletionStage<AsyncCache<K, V>> get(String name) {
return hotrod.transport.<K, V>getRemoteCache(name).thenApply(r -> new HotRodAsyncCache<>(hotrod, r));
}
@Override
public CompletionStage<Void> remove(String name) {
return hotrod.transport.removeCache(name);
}
@Override
public CompletionStage<Set<String>> names() {
return hotrod.transport.getCacheNames();
}
@Override
public CompletionStage<Void> createTemplate(String name, CacheConfiguration cacheConfiguration) {
return null;
}
@Override
public CompletionStage<Void> removeTemplate(String name) {
return null;
}
@Override
public CompletionStage<Set<String>> templateNames() {
return hotrod.transport.getTemplateNames();
}
}
| 2,014
| 30.984127
| 122
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodAsyncLock.java
|
package org.infinispan.hotrod;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
import org.infinispan.api.async.AsyncLock;
/**
* @since 14.0
**/
public class HotRodAsyncLock implements AsyncLock {
private final HotRod hotrod;
private final String name;
HotRodAsyncLock(HotRod hotrod, String name) {
this.hotrod = hotrod;
this.name = name;
}
@Override
public String name() {
return name;
}
@Override
public HotRodAsyncContainer container() {
return hotrod.async();
}
@Override
public CompletionStage<Void> lock() {
return null;
}
@Override
public CompletionStage<Boolean> tryLock() {
return null;
}
@Override
public CompletionStage<Boolean> tryLock(long time, TimeUnit unit) {
return null;
}
@Override
public CompletionStage<Void> unlock() {
return null;
}
@Override
public CompletionStage<Boolean> isLocked() {
return null;
}
@Override
public CompletionStage<Boolean> isLockedByMe() {
return null;
}
}
| 1,094
| 17.25
| 70
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncMultimaps.java
|
package org.infinispan.hotrod;
import org.infinispan.api.common.CloseableIterable;
import org.infinispan.api.configuration.MultimapConfiguration;
import org.infinispan.api.sync.SyncMultimaps;
/**
* @since 14.0
**/
public class HotRodSyncMultimaps implements SyncMultimaps {
private final HotRod hotrod;
public HotRodSyncMultimaps(HotRod hotrod) {
this.hotrod = hotrod;
}
@Override
public <K, V> HotRodSyncMultimap<K, V> get(String name) {
return new HotRodSyncMultimap(hotrod, name);
}
@Override
public <K, V> HotRodSyncMultimap<K, V> create(String name, MultimapConfiguration cacheConfiguration) {
return new HotRodSyncMultimap<>(hotrod, name);
}
@Override
public <K, V> HotRodSyncMultimap<K, V> create(String name, String template) {
return new HotRodSyncMultimap<>(hotrod, name);
}
@Override
public void remove(String name) {
}
@Override
public CloseableIterable<String> names() {
return null;
}
@Override
public void createTemplate(String name, MultimapConfiguration cacheConfiguration) {
}
@Override
public void removeTemplate(String name) {
}
@Override
public CloseableIterable<String> templateNames() {
return null;
}
}
| 1,260
| 21.122807
| 105
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRod.java
|
package org.infinispan.hotrod;
import org.infinispan.api.Infinispan;
import org.infinispan.hotrod.configuration.HotRodConfiguration;
import org.infinispan.hotrod.impl.HotRodTransport;
/**
* @since 14.0
**/
public class HotRod implements Infinispan {
final HotRodConfiguration configuration;
final HotRodTransport transport;
HotRod(HotRodConfiguration configuration) {
this(configuration, new HotRodTransport(configuration));
}
HotRod(HotRodConfiguration configuration, HotRodTransport transport) {
this.configuration = configuration;
this.transport = transport;
this.transport.start();
}
@Override
public HotRodSyncContainer sync() {
return new HotRodSyncContainer(this);
}
@Override
public HotRodAsyncContainer async() {
return new HotRodAsyncContainer(this);
}
@Override
public HotRodMutinyContainer mutiny() {
return new HotRodMutinyContainer(this);
}
@Override
public void close() {
transport.close();
}
}
| 1,022
| 22.25
| 73
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncCaches.java
|
package org.infinispan.hotrod;
import static org.infinispan.hotrod.impl.Util.await;
import org.infinispan.api.configuration.CacheConfiguration;
import org.infinispan.api.sync.SyncCaches;
import org.infinispan.hotrod.impl.cache.RemoteCache;
/**
* @since 14.0
**/
public class HotRodSyncCaches implements SyncCaches {
private final HotRod hotrod;
public HotRodSyncCaches(HotRod hotrod) {
this.hotrod = hotrod;
}
@Override
public <K, V> HotRodSyncCache<K, V> get(String name) {
//FIXME
return await(hotrod.transport.getRemoteCache(name).thenApply(r -> new HotRodSyncCache<>(hotrod, (RemoteCache<K, V>) r)));
}
@Override
public <K, V> HotRodSyncCache<K, V> create(String name, CacheConfiguration cacheConfiguration) {
//FIXME
return await(hotrod.transport.getRemoteCache(name).thenApply(r -> new HotRodSyncCache<>(hotrod, (RemoteCache<K, V>) r)));
}
@Override
public <K, V> HotRodSyncCache<K, V> create(String name, String template) {
return await(hotrod.transport.getRemoteCache(name).thenApply(r -> new HotRodSyncCache<>(hotrod, (RemoteCache<K, V>) r)));
}
@Override
public void remove(String name) {
}
@Override
public Iterable<String> names() {
return null;
}
@Override
public void createTemplate(String name, CacheConfiguration cacheConfiguration) {
}
@Override
public void removeTemplate(String name) {
}
@Override
public Iterable<String> templateNames() {
return null;
}
}
| 1,522
| 23.967213
| 127
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodMutinyContainer.java
|
package org.infinispan.hotrod;
import java.util.function.Function;
import org.infinispan.api.common.events.container.ContainerEvent;
import org.infinispan.api.common.events.container.ContainerListenerEventType;
import org.infinispan.api.mutiny.MutinyContainer;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public class HotRodMutinyContainer implements MutinyContainer {
private final HotRod hotrod;
public HotRodMutinyContainer(HotRod hotrod) {
this.hotrod = hotrod;
}
@Override
public HotRodSyncContainer sync() {
return hotrod.sync();
}
@Override
public HotRodAsyncContainer async() {
return hotrod.async();
}
@Override
public HotRodMutinyContainer mutiny() {
return this;
}
@Override
public void close() {
hotrod.close();
}
@Override
public HotRodMutinyCaches caches() {
return new HotRodMutinyCaches(hotrod);
}
@Override
public HotRodMutinyMultimaps multimaps() {
return new HotRodMutinyMultimaps(hotrod);
}
@Override
public HotRodMutinyStrongCounters strongCounters() {
return new HotRodMutinyStrongCounters(hotrod);
}
@Override
public HotRodMutinyWeakCounters weakCounters() {
return new HotRodMutinyWeakCounters(hotrod);
}
@Override
public HotRodMutinyLocks locks() {
return new HotRodMutinyLocks(hotrod);
}
@Override
public Multi<ContainerEvent> listen(ContainerListenerEventType... types) {
return null;
}
@Override
public <R> Uni<R> execute(String name, Object... args) {
return null;
}
@Override
public <T> Uni<T> batch(Function<MutinyContainer, Uni<T>> function) {
return null;
}
}
| 1,749
| 20.341463
| 77
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodMutinyStrongCounter.java
|
package org.infinispan.hotrod;
import org.infinispan.api.common.events.counter.CounterEvent;
import org.infinispan.api.configuration.CounterConfiguration;
import org.infinispan.api.mutiny.MutinyStrongCounter;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public class HotRodMutinyStrongCounter implements MutinyStrongCounter {
private final HotRod hotrod;
private final String name;
HotRodMutinyStrongCounter(HotRod hotrod, String name) {
this.hotrod = hotrod;
this.name = name;
}
@Override
public String name() {
return name;
}
@Override
public HotRodMutinyContainer container() {
return hotrod.mutiny();
}
@Override
public Uni<Long> value() {
return null;
}
@Override
public Uni<Long> addAndGet(long delta) {
return null;
}
@Override
public Uni<Void> reset() {
return null;
}
@Override
public Multi<CounterEvent> listen() {
return null;
}
@Override
public Uni<Boolean> compareAndSet(long expect, long update) {
return null;
}
@Override
public Uni<Long> compareAndSwap(long expect, long update) {
return null;
}
@Override
public Uni<Long> getAndSet(long value) {
return null;
}
@Override
public Uni<CounterConfiguration> getConfiguration() {
return null;
}
}
| 1,390
| 18.319444
| 71
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodFlags.java
|
package org.infinispan.hotrod;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.Flags;
/**
* @since 14.0
**/
public class HotRodFlags implements Flags<HotRodFlag, HotRodFlags> {
int flags;
HotRodFlags() {}
public static HotRodFlags of(HotRodFlag... flag) {
HotRodFlags flags = new HotRodFlags();
for(HotRodFlag f : flag) {
flags.add(f);
}
return flags;
}
public static int toInt(CacheOptions.Impl options) {
HotRodFlags flags = (HotRodFlags) options.rawFlags();
return flags == null ? 0 : flags.toInt();
}
@Override
public HotRodFlags add(HotRodFlag flag) {
flags |= flag.getFlagInt();
return this;
}
@Override
public boolean contains(HotRodFlag flag) {
return (flags & flag.getFlagInt()) != 0;
}
@Override
public HotRodFlags addAll(Flags<HotRodFlag, HotRodFlags> flags) {
HotRodFlags theFlags = (HotRodFlags) flags;
this.flags |= theFlags.flags;
return this;
}
public int toInt() {
return flags;
}
}
| 1,081
| 21.081633
| 68
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncStrongCounter.java
|
package org.infinispan.hotrod;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.infinispan.api.common.events.counter.CounterEvent;
import org.infinispan.api.configuration.CounterConfiguration;
import org.infinispan.api.sync.SyncStrongCounter;
/**
* @since 14.0
**/
public class HotRodSyncStrongCounter implements SyncStrongCounter {
private final HotRod hotrod;
private final String name;
HotRodSyncStrongCounter(HotRod hotrod, String name) {
this.hotrod = hotrod;
this.name = name;
}
@Override
public String name() {
return name;
}
@Override
public HotRodSyncContainer container() {
return hotrod.sync();
}
@Override
public long value() {
return 0;
}
@Override
public long addAndGet(long delta) {
return 0;
}
@Override
public CompletableFuture<Void> reset() {
return null;
}
@Override
public AutoCloseable listen(Consumer<CounterEvent> listener) {
return null;
}
@Override
public long compareAndSwap(long expect, long update) {
return 0;
}
@Override
public long getAndSet(long value) {
return 0;
}
@Override
public CounterConfiguration configuration() {
return null;
}
}
| 1,291
| 18.283582
| 67
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncQuery.java
|
package org.infinispan.hotrod;
import java.util.Map;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.process.CacheProcessor;
import org.infinispan.api.common.process.CacheProcessorOptions;
import org.infinispan.api.sync.SyncCacheEntryProcessor;
import org.infinispan.api.sync.SyncQuery;
import org.infinispan.api.sync.SyncQueryResult;
import org.infinispan.api.sync.events.cache.SyncCacheContinuousQueryListener;
import org.infinispan.hotrod.impl.cache.RemoteQuery;
/**
* @since 14.0
**/
public class HotRodSyncQuery<K, V, R> implements SyncQuery<K, V, R> {
private final RemoteQuery query;
HotRodSyncQuery(String query, CacheOptions options) {
this.query = new RemoteQuery(query, options);
}
@Override
public SyncQuery<K, V, R> param(String name, Object value) {
query.param(name, value);
return this;
}
@Override
public SyncQuery<K, V, R> skip(long skip) {
query.skip(skip);
return this;
}
@Override
public SyncQuery<K, V, R> limit(int limit) {
query.limit(limit);
return this;
}
@Override
public SyncQueryResult<R> find() {
throw new UnsupportedOperationException();
}
@Override
public <R1> AutoCloseable findContinuously(SyncCacheContinuousQueryListener<K, V> listener) {
throw new UnsupportedOperationException();
}
@Override
public int execute() {
throw new UnsupportedOperationException();
}
@Override
public <T> Map<K, T> process(SyncCacheEntryProcessor<K, V, T> processor, CacheProcessorOptions options) {
throw new UnsupportedOperationException();
}
@Override
public <T> Map<K, T> process(CacheProcessor processor, CacheProcessorOptions options) {
throw new UnsupportedOperationException();
}
}
| 1,804
| 25.940299
| 108
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodMutinyLock.java
|
package org.infinispan.hotrod;
import java.util.concurrent.TimeUnit;
import org.infinispan.api.mutiny.MutinyLock;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public class HotRodMutinyLock implements MutinyLock {
private final HotRod hotrod;
private final String name;
HotRodMutinyLock(HotRod hotrod, String name) {
this.hotrod = hotrod;
this.name = name;
}
@Override
public String name() {
return name;
}
@Override
public HotRodMutinyContainer container() {
return hotrod.mutiny();
}
@Override
public Uni<Void> lock() {
return null;
}
@Override
public Uni<Boolean> tryLock() {
return null;
}
@Override
public Uni<Boolean> tryLock(long time, TimeUnit unit) {
return null;
}
@Override
public Uni<Void> unlock() {
return null;
}
@Override
public Uni<Boolean> isLocked() {
return null;
}
@Override
public Uni<Boolean> isLockedByMe() {
return null;
}
}
| 1,016
| 15.672131
| 58
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodAsyncWeakCounter.java
|
package org.infinispan.hotrod;
import java.util.concurrent.CompletionStage;
import org.infinispan.api.async.AsyncContainer;
import org.infinispan.api.async.AsyncWeakCounter;
import org.infinispan.api.configuration.CounterConfiguration;
/**
* @since 14.0
**/
public class HotRodAsyncWeakCounter implements AsyncWeakCounter {
private final HotRod hotrod;
private final String name;
HotRodAsyncWeakCounter(HotRod hotrod, String name) {
this.hotrod = hotrod;
this.name = name;
}
@Override
public String name() {
return name;
}
@Override
public CompletionStage<CounterConfiguration> configuration() {
return null;
}
@Override
public AsyncContainer container() {
return null;
}
@Override
public CompletionStage<Long> value() {
return null;
}
@Override
public CompletionStage<Void> add(long delta) {
return null;
}
}
| 920
| 19.021739
| 65
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncLocks.java
|
package org.infinispan.hotrod;
import org.infinispan.api.common.CloseableIterable;
import org.infinispan.api.configuration.LockConfiguration;
import org.infinispan.api.sync.SyncLocks;
/**
* @since 14.0
**/
public class HotRodSyncLocks implements SyncLocks {
private final HotRod hotrod;
HotRodSyncLocks(HotRod hotrod) {
this.hotrod = hotrod;
}
@Override
public HotRodSyncLock create(String name, LockConfiguration configuration) {
return new HotRodSyncLock(hotrod, name); // PLACEHOLDER
}
@Override
public HotRodSyncLock get(String name) {
return new HotRodSyncLock(hotrod, name); // PLACEHOLDER
}
@Override
public void remove(String name) {
}
@Override
public CloseableIterable<String> names() {
return null;
}
}
| 793
| 20.459459
| 79
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncMultimap.java
|
package org.infinispan.hotrod;
import org.infinispan.api.common.CloseableIterable;
import org.infinispan.api.configuration.MultimapConfiguration;
import org.infinispan.api.sync.SyncMultimap;
/**
* @since 14.0
**/
public class HotRodSyncMultimap<K, V> implements SyncMultimap<K, V> {
private final HotRod hotrod;
private final String name;
HotRodSyncMultimap(HotRod hotrod, String name) {
this.hotrod = hotrod;
this.name = name;
}
@Override
public String name() {
return name;
}
@Override
public MultimapConfiguration configuration() {
return null;
}
@Override
public HotRodSyncContainer container() {
return hotrod.sync();
}
@Override
public void add(K key, V value) {
}
@Override
public CloseableIterable<V> get(K key) {
return null;
}
@Override
public boolean remove(K key) {
return false;
}
@Override
public boolean remove(K key, V value) {
return false;
}
@Override
public boolean containsKey(K key) {
return false;
}
@Override
public boolean containsEntry(K key, V value) {
return false;
}
@Override
public long estimateSize() {
return 0;
}
}
| 1,232
| 16.869565
| 69
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/NearCacheMode.java
|
package org.infinispan.hotrod.configuration;
/**
* Decides how client-side near caching should work.
*
* @since 14.0
*/
public enum NearCacheMode {
// TODO: Add SELECTIVE (or similar) when ISPN-5545 implemented
/**
* Near caching is disabled.
*/
DISABLED,
/**
* Near cache is invalidated, so when entries are updated or removed
* server-side, invalidation messages will be sent to clients to remove
* them from the near cache.
*/
INVALIDATED;
public boolean enabled() {
return this != DISABLED;
}
public boolean invalidated() {
return this == INVALIDATED;
}
}
| 634
| 18.242424
| 74
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ClusterConfiguration.java
|
package org.infinispan.hotrod.configuration;
import java.util.List;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
/**
* @since 14.0
*/
public class ClusterConfiguration extends ConfigurationElement<ClusterConfiguration> {
static final AttributeDefinition<String> NAME = AttributeDefinition.builder("name", null, String.class).build();
// default intelligence is "null" to use the client intelligence defined globally
static final AttributeDefinition<ClientIntelligence> CLIENT_INTELLIGENCE = AttributeDefinition.builder("client_intelligence", null, ClientIntelligence.class).build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(ClusterConfiguration.class, NAME, CLIENT_INTELLIGENCE);
}
private final List<ServerConfiguration> servers;
ClusterConfiguration(AttributeSet attributes, List<ServerConfiguration> servers) {
super("cluster", attributes);
this.servers = servers;
}
public List<ServerConfiguration> getServers() {
return servers;
}
public String getClusterName() {
return attributes.attribute(NAME).get();
}
public ClientIntelligence getClientIntelligence() {
return attributes.attribute(CLIENT_INTELLIGENCE).get();
}
}
| 1,420
| 34.525
| 169
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/SaslStrength.java
|
package org.infinispan.hotrod.configuration;
/**
* SaslStrength. Possible values for the SASL strength property.
*
* @since 14.0
*/
public enum SaslStrength {
LOW("low"), MEDIUM("medium"), HIGH("high");
private String v;
SaslStrength(String v) {
this.v = v;
}
@Override
public String toString() {
return v;
}
}
| 352
| 15.045455
| 64
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/StatisticsConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.StatisticsConfiguration.ENABLED;
import static org.infinispan.hotrod.configuration.StatisticsConfiguration.JMX_DOMAIN;
import static org.infinispan.hotrod.configuration.StatisticsConfiguration.JMX_ENABLED;
import static org.infinispan.hotrod.configuration.StatisticsConfiguration.JMX_NAME;
import static org.infinispan.hotrod.configuration.StatisticsConfiguration.MBEAN_SERVER_LOOKUP;
import static org.infinispan.hotrod.impl.ConfigurationProperties.JMX;
import static org.infinispan.hotrod.impl.ConfigurationProperties.STATISTICS;
import java.util.Properties;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.jmx.MBeanServerLookup;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.hotrod.impl.ConfigurationProperties;
/**
* Configures client-side statistics
*
* @since 14.0
*/
public class StatisticsConfigurationBuilder extends AbstractConfigurationChildBuilder implements
Builder<StatisticsConfiguration> {
private final AttributeSet attributes = StatisticsConfiguration.attributeDefinitionSet();
StatisticsConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return attributes;
}
/**
* Enables or disables client-side statistics collection
*
* @param enabled whether to enable client-side statistics
*/
public StatisticsConfigurationBuilder enabled(boolean enabled) {
attributes.attribute(ENABLED).set(enabled);
return this;
}
/**
* Enables client-side statistics collection
*/
public StatisticsConfigurationBuilder enable() {
return enabled(true);
}
/**
* Disables client-side statistics collection
*/
public StatisticsConfigurationBuilder disable() {
return enabled(false);
}
/**
* Enables or disables exposure of client-side statistics over JMX
*/
public StatisticsConfigurationBuilder jmxEnabled(boolean enabled) {
attributes.attribute(JMX_ENABLED).set(enabled);
return this;
}
/**
* Enables exposure of client-side statistics over JMX
*/
public StatisticsConfigurationBuilder jmxEnable() {
return jmxEnabled(true);
}
/**
* Disables exposure of client-side statistics over JMX
*/
public StatisticsConfigurationBuilder jmxDisable() {
return jmxEnabled(false);
}
/**
* Sets the JMX domain name with which MBeans are exposed. Defaults to "org.infinispan" ({@link StatisticsConfiguration#JMX_DOMAIN})
* @param jmxDomain the JMX domain name
*/
public StatisticsConfigurationBuilder jmxDomain(String jmxDomain) {
attributes.attribute(JMX_DOMAIN).set(jmxDomain);
return this;
}
/**
* Sets the name of the MBean. Defaults to "Default" ({@link StatisticsConfiguration#JMX_NAME})
* @param jmxName
*/
public StatisticsConfigurationBuilder jmxName(String jmxName) {
attributes.attribute(JMX_NAME).set(jmxName);
return this;
}
/**
* Sets the instance of the {@link org.infinispan.commons.jmx.MBeanServerLookup} class to be used to bound JMX MBeans
* to.
*
* @param mBeanServerLookupInstance An instance of {@link org.infinispan.commons.jmx.MBeanServerLookup}
*/
public StatisticsConfigurationBuilder mBeanServerLookup(MBeanServerLookup mBeanServerLookupInstance) {
attributes.attribute(MBEAN_SERVER_LOOKUP).set(mBeanServerLookupInstance);
return this;
}
@Override
public StatisticsConfiguration create() {
return new StatisticsConfiguration(attributes.protect());
}
@Override
public Builder<?> read(StatisticsConfiguration template, Combine combine) {
this.attributes.read(template.attributes(), combine);
return this;
}
@Override
public HotRodConfigurationBuilder withProperties(Properties properties) {
TypedProperties typed = TypedProperties.toTypedProperties(properties);
enabled(typed.getBooleanProperty(STATISTICS, ENABLED.getDefaultValue()));
jmxEnabled(typed.getBooleanProperty(JMX, JMX_ENABLED.getDefaultValue()));
jmxDomain(typed.getProperty(ConfigurationProperties.JMX_DOMAIN, JMX_DOMAIN.getDefaultValue()));
jmxName(typed.getProperty(ConfigurationProperties.JMX_NAME, JMX_NAME.getDefaultValue()));
return builder;
}
}
| 4,575
| 32.896296
| 135
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/TransportFactory.java
|
package org.infinispan.hotrod.configuration;
import java.util.concurrent.ExecutorService;
import org.infinispan.hotrod.impl.transport.netty.DefaultTransportFactory;
import org.infinispan.hotrod.impl.transport.netty.NativeTransport;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.DatagramChannel;
import io.netty.channel.socket.SocketChannel;
/**
* TransportFactory is responsible for creating Netty's {@link SocketChannel}s and {@link EventLoopGroup}s.
*
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 12.1
**/
public interface TransportFactory {
TransportFactory DEFAULT = new DefaultTransportFactory();
/**
* Returns the Netty {@link SocketChannel} class to use in the transport.
*/
Class<? extends SocketChannel> socketChannelClass();
/**
* Returns the Netty {@link DatagramChannel} class to use for DNS resolution.
*/
default Class<? extends DatagramChannel> datagramChannelClass() {
return NativeTransport.datagramChannelClass();
}
/**
* Creates an event loop group
*
* @param maxExecutors the maximum number of executors
* @param executorService the executor service to use
* @return an instance of Netty's {@link EventLoopGroup}
*/
EventLoopGroup createEventLoopGroup(int maxExecutors, ExecutorService executorService);
}
| 1,354
| 31.261905
| 107
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ClientIntelligence.java
|
package org.infinispan.hotrod.configuration;
/**
* ClientIntelligence specifies the level of intelligence used by the client.
* <ul> <li><b>BASIC</b> means that the
* client doesn't handle server topology changes and therefore will only used the list of servers supplied at
* configuration time</li>
* <li><b>TOPOLOGY_AWARE</b> means that the client wants to receive topology updates from the
* servers so that it can deal with added / removed servers dynamically. Requests will go to the servers using a
* round-robin approach</li>
* <li><b>HASH_DISTRIBUTION_AWARE</b> like <i>TOPOLOGY_AWARE</i> but with the additional
* advantage that each request involving keys will be routed to the server who is the primary owner which improves
* performance greatly. This is the default</li>
* </ul>
*
* @since 14.0
*/
public enum ClientIntelligence {
BASIC(1),
TOPOLOGY_AWARE(2),
HASH_DISTRIBUTION_AWARE(3);
final byte value;
ClientIntelligence(int value) {
this.value = (byte) value;
}
public byte getValue() {
return value;
}
public static ClientIntelligence getDefault() {
return HASH_DISTRIBUTION_AWARE;
}
}
| 1,171
| 30.675676
| 114
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/package-info.java
|
/**
* Hot Rod client configuration API.
*
* <p>It is possible to configure the {@link org.infinispan.hotrod.RemoteCacheManager} either programmatically,
* using a URI or by constructing a {@link org.infinispan.hotrod.configuration.HotRodConfiguration} using a {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder}
* or declaratively, by placing a properties file named <tt>hotrod-client.properties</tt> in the classpath.</p>
*
* <p>A Hot Rod URI follows the following format:
* <code>hotrod[s]://[user[:password]@]host[:port][,host2[:port]][?property=value[&property2=value2]]</code>
* </p>
* <ul>
* <li><b>hotrod</b> or <b>hotrods</b> specifies whether to use a plain connection or TLS/SSL encryption.</li>
* <li><b>user</b> and <b>password</b> optionally specify authentication credentials.</li>
* <li><b>host</b> and <b>port</b> comma-separated list of one or more servers.</li>
* <li><b>property</b> and <b>value</b> one or more ampersand-separated (&) property name/value pairs. The property name must omit the infinispan.client.hotrod prefix.</li>
* </ul>
*
* <p>The following table describes the individual properties
* and the related programmatic configuration API.</p>
*
* <table cellspacing="0" cellpadding="3" border="1">
* <thead>
* <tr>
* <th>Name</th>
* <th>Type</th>
* <th>Default</th>
* <th>Description</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <th colspan="4">Connection properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.uri</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>Configures the client via a URI</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.server_list</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>Adds a list of remote servers in the form: host1[:port][;host2[:port]]...</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.tcp_no_delay</b></td>
* <td>Boolean</td>
* <td>true</td>
* <td>Enables/disables the {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#tcpNoDelay(boolean) TCP_NO_DELAY} flag</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.tcp_keep_alive</b></td>
* <td>Boolean</td>
* <td>false</td>
* <td>Enables/disables the {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#tcpKeepAlive(boolean) TCP_KEEPALIVE} flag</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.client_intelligence</b></td>
* <td>String</td>
* <td>{@link org.infinispan.hotrod.configuration.ClientIntelligence#HASH_DISTRIBUTION_AWARE HASH_DISTRIBUTION_AWARE}</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#clientIntelligence(ClientIntelligence) ClientIntelligence}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.request_balancing_strategy</b></td>
* <td>String (class name)</td>
* <td>{@link org.infinispan.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy RoundRobinBalancingStrategy}</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#balancingStrategy(String) FailoverRequestBalancingStrategy}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.socket_timeout</b></td>
* <td>Integer</td>
* <td>60000</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#socketTimeout(int) timeout} for socket read/writes</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.connect_timeout</b></td>
* <td>Integer</td>
* <td>60000</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#connectionTimeout(int) timeout} for connections</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.max_retries</b></td>
* <td>Integer</td>
* <td>10</td>
* <td>The maximum number of operation {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#maxRetries(int) retries}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.batch_size</b></td>
* <td>Integer</td>
* <td>10000</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#batchSize(int) size} of a batches when iterating</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.protocol_version</b></td>
* <td>String</td>
* <td>Latest version supported by the client in use</td>
* <td>The Hot Rod {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#version(org.infinispan.hotrod.configuration.ProtocolVersion) version}.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.dns_resolver_min_ttl</b></td>
* <td>Integer</td>
* <td>0</td>
* <td>The minimum TTL of the cached DNS resource records (in seconds). If the TTL of the DNS resource record returned by the DNS server is less than the minimum TTL, the resolver will ignore the TTL from the DNS server and use the minimum TTL instead. The defaults respect the DNS server TTL.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.dns_resolver_max_ttl</b></td>
* <td>Integer</td>
* <td>Integer.MAX_VALUE</td>
* <td>The maximum TTL of the cached DNS resource records (in seconds). If the TTL of the DNS resource record returned by the DNS server is greater than the maximum TTL, the resolver will ignore the TTL from the DNS server and use the maximum TTL instead. The defaults respect the DNS server TTL.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.dns_resolver_negative_ttl</b></td>
* <td>Integer</td>
* <td>0</td>
* <td>Sets the TTL of the cache for the failed DNS queries (in seconds).</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.transport_factory</b></td>
* <td>String</td>
* <td>{@link org.infinispan.hotrod.impl.transport.netty.DefaultTransportFactory}</td>
* <td>Specifies the transport factory to use.</td>
* </tr>
* <tr>
* <th colspan="4">Connection pool properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.connection_pool.max_active</b></td>
* <td>Integer</td>
* <td>-1 (no limit)</td>
* <td>Maximum number of {@link org.infinispan.hotrod.configuration.ConnectionPoolConfigurationBuilder#maxActive(int) connections} per server</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.connection_pool.exhausted_action</b></td>
* <td>String</td>
* <td>{@link org.infinispan.hotrod.configuration.ExhaustedAction#WAIT WAIT}</td>
* <td>Specifies what happens when asking for a connection from a server's pool, and that pool is {@link org.infinispan.hotrod.configuration.ConnectionPoolConfigurationBuilder#exhaustedAction(org.infinispan.hotrod.configuration.ExhaustedAction) exhausted}.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.connection_pool.max_wait</b></td>
* <td>Long</td>
* <td>-1 (no limit)</td>
* <td>{@link org.infinispan.hotrod.configuration.ConnectionPoolConfigurationBuilder#maxWait(long) Time} to wait in milliseconds for a connection to become available when exhausted_action is WAIT</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.connection_pool.min_idle</b></td>
* <td>Integer</td>
* <td>1</td>
* <td>Minimum number of idle {@link org.infinispan.hotrod.configuration.ConnectionPoolConfigurationBuilder#minIdle(int) connections} that each server should have available.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.connection_pool.min_evictable_idle_time</b></td>
* <td>Integer</td>
* <td>1800000</td>
* <td>Minimum amount of {@link org.infinispan.hotrod.configuration.ConnectionPoolConfigurationBuilder#minEvictableIdleTime(long) time} that an connection may sit idle in the pool</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.connection_pool.max_pending_requests</b></td>
* <td>Integer</td>
* <td>5</td>
* <td>Specifies maximum number of {@link org.infinispan.hotrod.configuration.ConnectionPoolConfigurationBuilder#maxPendingRequests(int) requests} sent over single connection at one instant.</td>
* </tr>
* <tr>
* <th colspan="4">Thread pool properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.async_executor_factory</b></td>
* <td>String (class name)</td>
* <td>{@link org.infinispan.hotrod.impl.async.DefaultAsyncExecutorFactory DefaultAsyncExecutorFactory}</td>
* <td>The {@link org.infinispan.hotrod.configuration.ExecutorFactoryConfigurationBuilder#factoryClass(String) factory} for creating threads</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.default_executor_factory.pool_size</b></td>
* <td>Integer</td>
* <td>99</td>
* <td>Size of the thread pool</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.default_executor_factory.threadname_prefix</b></td>
* <td>String</td>
* <td>HotRod-client-async-pool</td>
* <td>Prefix for the default executor thread names</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.default_executor_factory.threadname_suffix</b></td>
* <td>String</td>
* <td>"" (empty value)</td>
* <td>Suffix for the default executor thread names</td>
* </tr>
* <tr>
* <th colspan="4">Marshalling properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.marshaller</b></td>
* <td>String (class name)</td>
* <td>{@link org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller} if the infinispan-jboss-marshalling module is present on the classpath, otherwise {@link org.infinispan.commons.marshall.ProtoStreamMarshaller} is used</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#marshaller(String) marshaller} that serializes keys and values</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.force_return_values</b></td>
* <td>Boolean</td>
* <td>false</td>
* <td>Whether to {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#forceReturnValues(boolean) return values} for puts/removes</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.java_serial_allowlist</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>A {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#addJavaSerialAllowList(String...) class allowList} which are trusted for unmarshalling.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.hash_function_impl.2</b></td>
* <td>String</td>
* <td>{@link org.infinispan.hotrod.impl.consistenthash.ConsistentHashV2 ConsistentHashV2}</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#consistentHashImpl(int, String) hash function} to use.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.context-initializers</b></td>
* <td>String (class names)</td>
* <td>"" (empty value)</td>
* <td>A list of {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#addContextInitializers(org.infinispan.protostream.SerializationContextInitializer... contextInitializers) SerializationContextInitializer implementation}</td>
* </tr>
* <tr>
* <th colspan="4">Encryption (TLS/SSL) properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.use_ssl</b></td>
* <td>Boolean</td>
* <td>false</td>
* <td>{@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#enable() Enable TLS} (implicitly enabled if a trust store is set)</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.key_store_file_name</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#keyStoreFileName(String) filename} of a keystore to use when using client certificate authentication.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.key_store_type</b></td>
* <td>String</td>
* <td>JKS</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#keyStoreType(String) keystore type}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.key_store_password</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#keyStorePassword(char[]) keystore password}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.key_alias</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#keyAlias(String) alias} of the </td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.trust_store_file_name</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#trustStoreFileName(String) path} of the trust store.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.trust_store_type</b></td>
* <td>String</td>
* <td>JKS</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#trustStoreType(String) type} of the trust store. Valid values are <tt>JKS</tt>, <tt>JCEKS</tt>, <tt>PCKS12</tt> and <tt>PEM</tt></td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.trust_store_password</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#trustStorePassword(char[]) password} of the trust store.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.sni_host_name</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#sniHostName(String) SNI hostname} to connect to.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.ssl_ciphers</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>A list of ciphers, separated with spaces and in order of preference, that are used during the SSL handshake to negotiate
* a cryptographic algorithm for key encrytion. By default, the SSL protocol (e.g. TLSv1.2) determines which ciphers to use.
* You should customize the cipher list with caution to avoid vulnerabilities from weak algorithms.
* For details about cipher lists and possible values, refer to OpenSSL documentation at <a href="https://www.openssl.org/docs/man1.1.1/man1/ciphers">https://www.openssl.org/docs/man1.1.1/man1/ciphers</a></td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.ssl_protocol</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.SslConfigurationBuilder#protocol(String) SSL protocol} to use (e.g. TLSv1.2).</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.ssl_provider</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The security provider to use when creating the SSL engine. If left unspecified, it will attempt to use the <tt>openssl</tt> for the high-performance native implementation, otherwise the internal JDK will be used.</td>
* </tr>
* <tr>
* <th colspan="4">Authentication properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.use_auth</b></td>
* <td>Boolean</td>
* <td>Enabled implicitly with other authentication properties.</td>
* <td>{@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#enabled(boolean) Enable} authentication.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.sasl_mechanism</b></td>
* <td>String</td>
* <td><pre>SCRAM-SHA-512</pre> if username and password are set<br>EXTERNAL if a trust store is set.</td>
* <td>The {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#saslMechanism(String) SASL mechanism} to use for authentication.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.auth_callback_handler</b></td>
* <td>String</td>
* <td>Automatically selected based on the configured SASL mechanism.</td>
* <td>The {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#callbackHandler(javax.security.auth.callback.CallbackHandler) CallbackHandler} to use for providing credentials for authentication.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.auth_server_name</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#serverName(String) server name} to use (for Kerberos).</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.auth_username</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#username(String) username}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.auth_password</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>The {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#password(char[]) password}</td>
* </tr>
* <tr>
* * <td><b>infinispan.client.hotrod.auth_token</b></td>
* * <td>String</td>
* * <td>N/A</td>
* * <td>The {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#token(String) OAuth token}</td>
* * </tr>
* <tr>
* <td><b>infinispan.client.hotrod.auth_realm</b></td>
* <td>String</td>
* <td>default</td>
* <td>The {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#realm(String) realm} (for DIGEST-MD5 authentication).</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.sasl_properties.*</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>A {@link org.infinispan.hotrod.configuration.AuthenticationConfigurationBuilder#saslProperties(java.util.Map) SASL property} (mech-specific)</td>
* </tr>
* <tr>
* <th colspan="4">Transaction properties</th>
* </tr>
* <tr>
* <th colspan="4">Near cache properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.near_cache.mode</b></td>
* <td>String ({@link org.infinispan.hotrod.configuration.NearCacheMode} enum name)</td>
* <td>{@link org.infinispan.hotrod.configuration.NearCacheMode#DISABLED DISABLED}</td>
* <td>The default near-cache {@link org.infinispan.hotrod.configuration.NearCacheConfigurationBuilder#mode(NearCacheMode) mode}. It is preferable to use the per-cache configuration.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.near_cache.max_entries</b></td>
* <td>Integer</td>
* <td>-1 (no limit)</td>
* <td>The {@link org.infinispan.hotrod.configuration.NearCacheConfigurationBuilder#maxEntries(int) maximum} number of entries to keep in the local cache. It is preferable to use the per-cache configuration.</td>
* </tr>
* <tr>
* <th colspan="4">Cross-site replication properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cluster.SITE</b></td>
* <td>String HOST and int PORT configuration</td>
* <td>Example for siteA and siteB:<br/>
* infinispan.client.hotrod.cluster.siteA=hostA1:11222; hostA2:11223`<br/>
* infinispan.client.hotrod.cluster.siteB=hostB1:11222; hostB2:11223`
* </td>
* <td>Relates to {@link org.infinispan.hotrod.configuration.ClusterConfigurationBuilder#addCluster(java.lang.String)} and
* {@link org.infinispan.hotrod.configuration.ClusterConfigurationBuilder#addClusterNode(java.lang.String, int)}</td>
* </tr>
* <tr>
* <th colspan="4">Statistics properties</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.statistics</b></td>
* <td>Boolean</td>
* <td>Default value {@link org.infinispan.hotrod.configuration.StatisticsConfiguration#ENABLED}</td>
* <td>Relates to {@link org.infinispan.hotrod.configuration.StatisticsConfigurationBuilder#enabled(boolean)}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.jmx</b></td>
* <td>Boolean</td>
* <td>Default value {@link org.infinispan.hotrod.configuration.StatisticsConfiguration#JMX_ENABLED}</td>
* <td>Relates to {@link org.infinispan.hotrod.configuration.StatisticsConfigurationBuilder#jmxEnabled(boolean)}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.jmx_name</b></td>
* <td>String</td>
* <td>Default value {@link org.infinispan.hotrod.configuration.StatisticsConfiguration#JMX_NAME}</td>
* <td>Relates to {@link org.infinispan.hotrod.configuration.StatisticsConfigurationBuilder#jmxName(java.lang.String)}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.jmx_domain</b></td>
* <td>String</td>
* <td>Default value {@link org.infinispan.hotrod.configuration.StatisticsConfiguration#JMX_DOMAIN}</td>
* <td>Relates to {@link org.infinispan.hotrod.configuration.StatisticsConfigurationBuilder#jmxDomain(java.lang.String)}</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.tracing.propagation_enabled</b></td>
* <td>Boolean</td>
* <td>Enabled implicitly by the presence of the OpenTelemetry API cn the client classpath.</td>
* <td>Relates to {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#disableTracingPropagation()}} ()}</td>
* </tr>
* <tr>
* <th colspan="4">Per-cache properties</th>
* </tr>
* <tr>
* <th colspan="4">In per-cache configuration properties, you can use wildcards with <i>cachename</i>, for example: <code>cache-*</code>.</th>
* </tr>
* <tr>
* <th colspan="4">If cache names include the <code>'.'</code> character you must enclose the cache name in square brackets, for example: <code>[example.MyConfig]</code>.</th>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.configuration</b></td>
* <td>XML</td>
* <td>N/A</td>
* <td>Provides a cache configuration, in XML format, to use when clients request caches that do not exist.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.configuration_uri</b></td>
* <td>XML</td>
* <td>N/A</td>
* <td>Provides a URI to a cache configuration, in XML format, to use when clients request caches that do not exist.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.template_name</b></td>
* <td>String</td>
* <td>N/A</td>
* <td>Names a cache template to use when clients request caches that do not exist. The cache template must be available on the server.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.near_cache.mode</b></td>
* <td>String ({@link org.infinispan.hotrod.configuration.NearCacheMode} enum name)</td>
* <td>{@link org.infinispan.hotrod.configuration.NearCacheMode#DISABLED DISABLED}</td>
* <td>The near-cache {@link org.infinispan.hotrod.configuration.RemoteCacheConfigurationBuilder#nearCacheMode(org.infinispan.hotrod.configuration.NearCacheMode)} (NearCacheMode) mode} for this cache</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.near_cache.max_entries</b></td>
* <td>Integer</td>
* <td>-1 (no limit)</td>
* <td>The {@link org.infinispan.hotrod.configuration.RemoteCacheConfigurationBuilder#nearCacheMaxEntries(int) maximum} number of entries to keep locally for the specified cache.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.force_return_values</b></td>
* <td>Boolean</td>
* <td>false</td>
* <td>Whether to {@link org.infinispan.hotrod.configuration.RemoteCacheConfigurationBuilder#forceReturnValues(boolean) return values} for puts/removes for the specified cache.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.transaction.transaction_mode</b></td>
* <td>String ({@link org.infinispan.hotrod.configuration.TransactionMode} enum name)</td>
* <td>{@link org.infinispan.hotrod.configuration.TransactionMode#NONE NONE}</td>
* <td>The default {@link org.infinispan.hotrod.configuration.RemoteCacheConfigurationBuilder#transactionMode(TransactionMode) transaction mode} for the specified cache.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.transaction.transaction_manager_lookup</b></td>
* <td>String (class name)</td>
* <td>{@link org.infinispan.hotrod.transaction.lookup.GenericTransactionManagerLookup GenericTransactionManagerLookup}</td>
* <td>The {@link org.infinispan.commons.tx.lookup.TransactionManagerLookup} for the specified cache.</td>
* </tr>
* <tr>
* <td><b>infinispan.client.hotrod.cache.<i>cachename</i>.marshaller</b></td>
* <td>String (class name)</td>
* <td>{@link org.infinispan.commons.marshall.ProtoStreamMarshaller} unless another marshaller is used.</td>
* <td>The {@link org.infinispan.hotrod.configuration.HotRodConfigurationBuilder#marshaller(String) marshaller} that serializes keys and values for the specified cache.</td>
* </tr>
* </tbody>
* </table>
*
* @api.public
*/
package org.infinispan.hotrod.configuration;
| 27,575
| 55.162933
| 310
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/SecurityConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
/**
* SecurityConfigurationBuilder.
*
* @since 14.0
*/
public class SecurityConfigurationBuilder extends AbstractConfigurationChildBuilder implements
Builder<SecurityConfiguration> {
private final AuthenticationConfigurationBuilder authentication = new AuthenticationConfigurationBuilder(this.builder);
private final SslConfigurationBuilder ssl = new SslConfigurationBuilder(this.builder);
SecurityConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return AttributeSet.EMPTY;
}
public AuthenticationConfigurationBuilder authentication() {
return authentication;
}
public SslConfigurationBuilder ssl() {
return ssl;
}
@Override
public SecurityConfiguration create() {
return new SecurityConfiguration(authentication.create(), ssl.create());
}
@Override
public Builder<?> read(SecurityConfiguration template, Combine combine) {
authentication.read(template.authentication(), combine);
ssl.read(template.ssl(), combine);
return this;
}
@Override
public void validate() {
authentication.validate();
ssl.validate();
}
HotRodConfigurationBuilder getBuilder() {
return super.builder;
}
}
| 1,526
| 25.327586
| 122
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/SslConfiguration.java
|
package org.infinispan.hotrod.configuration;
import java.security.KeyStore;
import javax.net.ssl.SSLContext;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
/**
* SslConfiguration.
*
* @since 14.0
*/
public class SslConfiguration extends ConfigurationElement<SslConfiguration> {
static final AttributeDefinition<String[]> CIPHERS = AttributeDefinition.builder("ciphers", null, String[].class).immutable().build();
static final AttributeDefinition<Boolean> ENABLED = AttributeDefinition.builder("use-ssl", false, Boolean.class).immutable().build();
static final AttributeDefinition<String> KEY_ALIAS = AttributeDefinition.builder("key-alias", null, String.class).immutable().build();
static final AttributeDefinition<String> KEYSTORE_FILENAME = AttributeDefinition.builder("keystore-filename", null, String.class).immutable().build();
static final AttributeDefinition<char[]> KEYSTORE_PASSWORD = AttributeDefinition.builder("keystore-password", null, char[].class).immutable().build();
static final AttributeDefinition<String> KEYSTORE_TYPE = AttributeDefinition.builder("keystore-type", KeyStore.getDefaultType(), String.class).immutable().build();
static final AttributeDefinition<String> PROTOCOL = AttributeDefinition.builder("protocol", null, String.class).immutable().build();
static final AttributeDefinition<String> PROVIDER = AttributeDefinition.builder("provider", null, String.class).immutable().build();
static final AttributeDefinition<String> SNI_HOSTNAME = AttributeDefinition.builder("sni-hostname", null, String.class).immutable().build();
static final AttributeDefinition<SSLContext> SSL_CONTEXT = AttributeDefinition.builder("ssl-context", null, SSLContext.class).immutable().build();
static final AttributeDefinition<String> TRUSTSTORE_FILENAME = AttributeDefinition.builder("truststore-filename", null, String.class).immutable().build();
static final AttributeDefinition<char[]> TRUSTSTORE_PASSWORD = AttributeDefinition.builder("truststore-password", null, char[].class).immutable().build();
static final AttributeDefinition<String> TRUSTSTORE_TYPE = AttributeDefinition.builder("truststore-type", KeyStore.getDefaultType(), String.class).immutable().build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(SslConfiguration.class,
ENABLED, KEY_ALIAS, KEYSTORE_FILENAME, KEYSTORE_PASSWORD, KEYSTORE_TYPE, PROTOCOL,
PROVIDER, SNI_HOSTNAME, SSL_CONTEXT, TRUSTSTORE_FILENAME, TRUSTSTORE_PASSWORD, TRUSTSTORE_TYPE);
}
SslConfiguration(AttributeSet attributes) {
super("ssl", attributes);
}
public boolean enabled() {
return attributes.attribute(ENABLED).get();
}
public String keyStoreFileName() {
return attributes.attribute(KEYSTORE_FILENAME).get();
}
public String keyStoreType() {
return attributes.attribute(KEYSTORE_TYPE).get();
}
public char[] keyStorePassword() {
return attributes.attribute(KEYSTORE_PASSWORD).get();
}
public String keyAlias() {
return attributes.attribute(KEY_ALIAS).get();
}
public SSLContext sslContext() {
return attributes.attribute(SSL_CONTEXT).get();
}
public String trustStoreFileName() {
return attributes.attribute(TRUSTSTORE_FILENAME).get();
}
public String trustStoreType() {
return attributes.attribute(TRUSTSTORE_TYPE).get();
}
public char[] trustStorePassword() {
return attributes.attribute(TRUSTSTORE_PASSWORD).get();
}
public String sniHostName() {
return attributes.attribute(SNI_HOSTNAME).get();
}
public String protocol() {
return attributes.attribute(PROTOCOL).get();
}
public String[] ciphers() {
return attributes.attribute(CIPHERS).get();
}
public String provider() {
return attributes.attribute(PROVIDER).get();
}
}
| 4,048
| 42.537634
| 170
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/RemoteCacheConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.commons.util.Util.getInstance;
import static org.infinispan.commons.util.Util.loadClass;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.CONFIGURATION;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.FORCE_RETURN_VALUES;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.MARSHALLER;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.MARSHALLER_CLASS;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.NAME;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.TEMPLATE_NAME;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.TRANSACTION_MANAGER;
import static org.infinispan.hotrod.configuration.RemoteCacheConfiguration.TRANSACTION_MODE;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.net.URI;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
import java.util.Scanner;
import java.util.function.Consumer;
import org.infinispan.commons.CacheConfigurationException;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.tx.lookup.TransactionManagerLookup;
import org.infinispan.commons.util.FileLookupFactory;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.hotrod.HotRod;
import org.infinispan.hotrod.impl.ConfigurationProperties;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.hotrod.transaction.lookup.GenericTransactionManagerLookup;
/**
* Per-cache configuration.
*
* @since 14.0
**/
public class RemoteCacheConfigurationBuilder implements Builder<RemoteCacheConfiguration> {
private final HotRodConfigurationBuilder builder;
private final AttributeSet attributes;
private final NearCacheConfigurationBuilder nearCache;
RemoteCacheConfigurationBuilder(HotRodConfigurationBuilder builder, String name) {
this.builder = builder;
this.attributes = RemoteCacheConfiguration.attributeDefinitionSet();
this.attributes.attribute(NAME).set(name);
this.nearCache = new NearCacheConfigurationBuilder(builder);
}
@Override
public AttributeSet attributes() {
return attributes;
}
RemoteCacheConfigurationBuilder(String name) {
this(null, name);
}
public NearCacheConfigurationBuilder nearCache() {
return nearCache;
}
/**
* Whether or not to implicitly FORCE_RETURN_VALUE for all calls to this cache.
*/
public RemoteCacheConfigurationBuilder forceReturnValues(boolean forceReturnValues) {
attributes.attribute(FORCE_RETURN_VALUES).set(forceReturnValues);
return this;
}
/**
* Specifies the declarative configuration to be used to create the cache if it doesn't already exist on the server.
*
* @param configuration the XML representation of a cache configuration.
* @return an instance of the builder
*/
public RemoteCacheConfigurationBuilder configuration(String configuration) {
attributes.attribute(CONFIGURATION).set(configuration);
return this;
}
/**
* Specifies a URI pointing to the declarative configuration to be used to create the cache if it doesn't already
* exist on the server.
*
* @param uri the URI of the configuration.
* @return an instance of the builder
*/
public RemoteCacheConfigurationBuilder configurationURI(URI uri) {
try {
URL url;
if (!uri.isAbsolute()) {
url = FileLookupFactory.newInstance().lookupFileLocation(uri.toString(), this.getClass().getClassLoader());
} else {
url = uri.toURL();
}
try (Scanner scanner = new Scanner(url.openStream(), StandardCharsets.UTF_8.toString()).useDelimiter("\\A")) {
return this.configuration(scanner.next());
}
} catch (Exception e) {
throw new CacheConfigurationException(e);
}
}
/**
* Specifies the name of a template to be used to create the cache if it doesn't already exist on the server.
*
* @param templateName the name of the template.
* @return an instance of the builder
*/
public RemoteCacheConfigurationBuilder templateName(String templateName) {
attributes.attribute(TEMPLATE_NAME).set(templateName);
return this;
}
/**
* The {@link TransactionMode} in which a resource will be enlisted.
*
* @param mode the transaction mode
* @return an instance of the builder
*/
public RemoteCacheConfigurationBuilder transactionMode(TransactionMode mode) {
attributes.attribute(TRANSACTION_MODE).set(mode);
return this;
}
/**
* Specifies a custom {@link Marshaller} implementation. See {@link #marshaller(Marshaller)}.
*
* @param className Fully qualifies class name of the marshaller implementation.
*/
public RemoteCacheConfigurationBuilder marshaller(String className) {
marshaller(loadClass(className, Thread.currentThread().getContextClassLoader()));
return this;
}
/**
* Specifies a custom {@link Marshaller} implementation. See {@link #marshaller(Marshaller)}.
*
* @param marshallerClass the marshaller class.
*/
public RemoteCacheConfigurationBuilder marshaller(Class<? extends Marshaller> marshallerClass) {
attributes.attribute(MARSHALLER_CLASS).set(marshallerClass);
return this;
}
/**
* Specifies a custom {@link Marshaller} implementation to serialize and deserialize user objects. Has precedence over
* {@link #marshaller(Class)} and {@link #marshaller(String)}. If not configured, the global marshaller will be used
* for the cache operations.
*
* @param marshaller the marshaller instance
*/
public RemoteCacheConfigurationBuilder marshaller(Marshaller marshaller) {
attributes.attribute(MARSHALLER).set(marshaller);
return this;
}
/**
* The {@link TransactionManagerLookup} to lookup for the transaction manager to interact with.
*
* @param lookup A {@link TransactionManagerLookup} instance.
* @return An instance of the builder.
*/
public RemoteCacheConfigurationBuilder transactionManagerLookup(TransactionManagerLookup lookup) {
attributes.attribute(TRANSACTION_MANAGER).set(lookup);
return this;
}
@Override
public void validate() {
if (attributes.attribute(CONFIGURATION).isModified() && attributes.attribute(TEMPLATE_NAME).isModified()) {
throw Log.HOTROD.remoteCacheTemplateNameXorConfiguration(attributes.attribute(NAME).get());
}
if (attributes.attribute(TRANSACTION_MODE).get() == null) {
throw HOTROD.invalidTransactionMode();
}
if (attributes.attribute(TRANSACTION_MANAGER).get() == null) {
throw HOTROD.invalidTransactionManagerLookup();
}
}
@Override
public RemoteCacheConfiguration create() {
return new RemoteCacheConfiguration(attributes.protect(), nearCache.create());
}
@Override
public Builder<?> read(RemoteCacheConfiguration template, Combine combine) {
this.nearCache.read(template.nearCache(), combine);
this.attributes.read(template.attributes(), combine);
return this;
}
public HotRodConfigurationBuilder withProperties(Properties properties) {
TypedProperties typed = TypedProperties.toTypedProperties(properties);
findCacheProperty(attributes, typed, ConfigurationProperties.CACHE_CONFIGURATION_SUFFIX, this::configuration);
findCacheProperty(attributes, typed, ConfigurationProperties.CACHE_CONFIGURATION_URI_SUFFIX, v -> this.configurationURI(URI.create(v)));
findCacheProperty(attributes, typed, ConfigurationProperties.CACHE_TEMPLATE_NAME_SUFFIX, this::templateName);
findCacheProperty(attributes, typed, ConfigurationProperties.CACHE_FORCE_RETURN_VALUES_SUFFIX, v -> this.forceReturnValues(Boolean.parseBoolean(v)));
findCacheProperty(attributes, typed, ConfigurationProperties.CACHE_TRANSACTION_MODE_SUFFIX, v -> this.transactionMode(TransactionMode.valueOf(v)));
findCacheProperty(attributes, typed, ConfigurationProperties.CACHE_TRANSACTION_MANAGER_LOOKUP_SUFFIX, this::transactionManagerLookupClass);
findCacheProperty(attributes, typed, ConfigurationProperties.CACHE_MARSHALLER, this::marshaller);
nearCache.withProperties(properties);
return builder;
}
private void transactionManagerLookupClass(String lookupClass) {
TransactionManagerLookup lookup = lookupClass == null || GenericTransactionManagerLookup.class.getName().equals(lookupClass) ?
GenericTransactionManagerLookup.getInstance() :
getInstance(loadClass(lookupClass, HotRod.class.getClassLoader()));
transactionManagerLookup(lookup);
}
private static void findCacheProperty(AttributeSet attributes, TypedProperties properties, String name, Consumer<String> consumer) {
String cacheName = attributes.attribute(NAME).get();
String value = null;
if (properties.containsKey(ConfigurationProperties.CACHE_PREFIX + cacheName + name)) {
value = properties.getProperty(ConfigurationProperties.CACHE_PREFIX + cacheName + name, true);
} else if (properties.containsKey(ConfigurationProperties.CACHE_PREFIX + '[' + cacheName + ']' + name)) {
value = properties.getProperty(ConfigurationProperties.CACHE_PREFIX + '[' + cacheName + ']' + name, true);
}
if (value != null) {
consumer.accept(value);
}
}
}
| 9,802
| 41.621739
| 155
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/NearCache.java
|
package org.infinispan.hotrod.configuration;
import org.infinispan.api.common.CacheEntry;
/**
* Near cache contract.
*
* @since 14.0
*/
public interface NearCache<K, V> extends Iterable<CacheEntry<K, V>> {
void put(CacheEntry<K, V> entry);
void putIfAbsent(CacheEntry<K, V> entry);
boolean remove(K key);
CacheEntry<K, V> get(K key);
void clear();
int size();
}
| 387
| 20.555556
| 69
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/SslConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.SslConfiguration.CIPHERS;
import static org.infinispan.hotrod.configuration.SslConfiguration.ENABLED;
import static org.infinispan.hotrod.configuration.SslConfiguration.KEYSTORE_FILENAME;
import static org.infinispan.hotrod.configuration.SslConfiguration.KEYSTORE_PASSWORD;
import static org.infinispan.hotrod.configuration.SslConfiguration.KEYSTORE_TYPE;
import static org.infinispan.hotrod.configuration.SslConfiguration.KEY_ALIAS;
import static org.infinispan.hotrod.configuration.SslConfiguration.PROTOCOL;
import static org.infinispan.hotrod.configuration.SslConfiguration.PROVIDER;
import static org.infinispan.hotrod.configuration.SslConfiguration.SNI_HOSTNAME;
import static org.infinispan.hotrod.configuration.SslConfiguration.SSL_CONTEXT;
import static org.infinispan.hotrod.configuration.SslConfiguration.TRUSTSTORE_FILENAME;
import static org.infinispan.hotrod.configuration.SslConfiguration.TRUSTSTORE_PASSWORD;
import static org.infinispan.hotrod.configuration.SslConfiguration.TRUSTSTORE_TYPE;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.util.List;
import java.util.Properties;
import javax.net.ssl.SSLContext;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.util.TypedProperties;
/**
*
* SSLConfigurationBuilder.
*
* @since 14.0
*/
public class SslConfigurationBuilder extends AbstractConfigurationChildBuilder implements Builder<SslConfiguration> {
private final AttributeSet attributes = SslConfiguration.attributeDefinitionSet();
SslConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return attributes;
}
/**
* Disables the SSL support
*/
public SslConfigurationBuilder disable() {
return enabled(false);
}
/**
* Enables the SSL support
*/
public SslConfigurationBuilder enable() {
return enabled(true);
}
/**
* Enables or disables the SSL support
*/
public SslConfigurationBuilder enabled(boolean enabled) {
attributes.attribute(ENABLED).set(enabled);
return this;
}
/**
* Specifies the filename of a keystore to use to create the {@link SSLContext} You also need to
* specify a {@link #keyStorePassword(char[])}. Alternatively specify an initialized {@link #sslContext(SSLContext)}.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder keyStoreFileName(String keyStoreFileName) {
attributes.attribute(KEYSTORE_FILENAME).set(keyStoreFileName);
return enable();
}
/**
* Specifies the type of the keystore, such as JKS or JCEKS. Defaults to JKS.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder keyStoreType(String keyStoreType) {
attributes.attribute(KEYSTORE_TYPE).set(keyStoreType);
return enable();
}
/**
* Specifies the password needed to open the keystore You also need to specify a
* {@link #keyStoreFileName(String)}. Alternatively specify an initialized {@link #sslContext(SSLContext)}.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder keyStorePassword(char[] keyStorePassword) {
attributes.attribute(KEYSTORE_PASSWORD).set(keyStorePassword);
return enable();
}
/**
* Sets the alias of the key to use, in case the keyStore contains multiple certificates.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder keyAlias(String keyAlias) {
attributes.attribute(KEY_ALIAS).set(keyAlias);
return enable();
}
/**
* Specifies a pre-built {@link SSLContext}
*/
public SslConfigurationBuilder sslContext(SSLContext sslContext) {
attributes.attribute(SSL_CONTEXT).set(sslContext);
return enable();
}
/**
* Specifies the filename of a truststore to use to create the {@link SSLContext} You also need
* to specify a {@link #trustStorePassword(char[])}. Alternatively specify an initialized {@link #sslContext(SSLContext)}.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder trustStoreFileName(String trustStoreFileName) {
attributes.attribute(TRUSTSTORE_FILENAME).set(trustStoreFileName);
return enable();
}
/**
* Specifies the type of the truststore, such as JKS or JCEKS. Defaults to JKS.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder trustStoreType(String trustStoreType) {
attributes.attribute(TRUSTSTORE_TYPE).set(trustStoreType);
return enable();
}
/**
* Specifies the password needed to open the truststore You also need to specify a
* {@link #trustStoreFileName(String)}. Alternatively specify an initialized {@link #sslContext(SSLContext)}.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder trustStorePassword(char[] trustStorePassword) {
attributes.attribute(TRUSTSTORE_PASSWORD).set(trustStorePassword);
return enable();
}
/**
* Specifies the TLS SNI hostname for the connection
* @see javax.net.ssl.SSLParameters#setServerNames(List).
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder sniHostName(String sniHostName) {
attributes.attribute(SNI_HOSTNAME).set(sniHostName);
return enable();
}
/**
* Configures the SSL provider.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*
* @see SSLContext#getInstance(String)
* @param provider The name of the provider to use when obtaining an SSLContext.
*/
public SslConfigurationBuilder provider(String provider) {
attributes.attribute(PROVIDER).set(provider);
return enable();
}
/**
* Configures the secure socket protocol.
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*
* @see SSLContext#getInstance(String)
* @param protocol The standard name of the requested protocol, e.g TLSv1.2
*/
public SslConfigurationBuilder protocol(String protocol) {
attributes.attribute(PROTOCOL).set(protocol);
return enable();
}
/**
* Configures the ciphers
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*
* @see SSLContext#getInstance(String)
* @param ciphers one or more cipher names
*/
public SslConfigurationBuilder ciphers(String... ciphers) {
attributes.attribute(CIPHERS).set(ciphers);
return enable();
}
@Override
public void validate() {
if (attributes.attribute(ENABLED).get()) {
if (attributes.attribute(SSL_CONTEXT).isNull()) {
if (!attributes.attribute(KEYSTORE_FILENAME).isNull() && attributes.attribute(KEYSTORE_PASSWORD).isNull()) {
throw HOTROD.missingKeyStorePassword(attributes.attribute(KEYSTORE_FILENAME).get());
}
if (attributes.attribute(TRUSTSTORE_FILENAME).isNull()) {
throw HOTROD.noSSLTrustManagerConfiguration();
}
if (!attributes.attribute(TRUSTSTORE_FILENAME).isNull() && attributes.attribute(TRUSTSTORE_PASSWORD).isNull() && !"pem".equalsIgnoreCase(attributes.attribute(KEYSTORE_TYPE).get())) {
throw HOTROD.missingTrustStorePassword(attributes.attribute(TRUSTSTORE_FILENAME).get());
}
} else {
if (!attributes.attribute(KEYSTORE_FILENAME).isNull() || !attributes.attribute(TRUSTSTORE_FILENAME).isNull()) {
throw HOTROD.xorSSLContext();
}
}
}
}
@Override
public SslConfiguration create() {
return new SslConfiguration(attributes.protect());
}
@Override
public Builder read(SslConfiguration template, Combine combine) {
this.attributes.read(template.attributes(), combine);
return this;
}
@Override
public HotRodConfigurationBuilder withProperties(Properties properties) {
attributes.fromProperties(TypedProperties.toTypedProperties(properties), "org.infinispan.client.");
return builder;
}
}
| 8,671
| 37.202643
| 194
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/NearCacheFactory.java
|
package org.infinispan.hotrod.configuration;
import java.util.function.Consumer;
import org.infinispan.api.common.CacheEntry;
/**
* @since 14.0
**/
public interface NearCacheFactory {
<K,V> NearCache<K, V> createNearCache(NearCacheConfiguration config, Consumer<CacheEntry<K, V>> removedConsumer);
}
| 308
| 22.769231
| 116
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ConfigurationChildBuilder.java
|
package org.infinispan.hotrod.configuration;
import java.net.URI;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.hotrod.impl.consistenthash.ConsistentHashV2;
import org.infinispan.protostream.SerializationContextInitializer;
/**
* ConfigurationChildBuilder.
*
* @since 14.0
*/
public interface ConfigurationChildBuilder {
/**
* Adds a new remote server
*/
ServerConfigurationBuilder addServer();
/**
* Adds a new remote server cluster
*/
ClusterConfigurationBuilder addCluster(String clusterName);
/**
* Adds a list of remote servers in the form: host1[:port][;host2[:port]]...
*/
HotRodConfigurationBuilder addServers(String servers);
/**
* Configuration for the executor service used for asynchronous work on the Transport, including
* asynchronous marshalling and Cache 'async operations' such as Cache.putAsync().
*/
ExecutorFactoryConfigurationBuilder asyncExecutorFactory();
/**
* For replicated (vs distributed) Hot Rod server clusters, the client balances requests to the
* servers according to this strategy.
*/
HotRodConfigurationBuilder balancingStrategy(String balancingStrategy);
/**
* For replicated (vs distributed) Hot Rod server clusters, the client balances requests to the
* servers according to this strategy.
*/
HotRodConfigurationBuilder balancingStrategy(Supplier<FailoverRequestBalancingStrategy> balancingStrategyFactory);
/**
* For replicated (vs distributed) Hot Rod server clusters, the client balances requests to the
* servers according to this strategy.
*/
HotRodConfigurationBuilder balancingStrategy(Class<? extends FailoverRequestBalancingStrategy> balancingStrategy);
/**
* Specifies the level of "intelligence" the client should have
*/
HotRodConfigurationBuilder clientIntelligence(ClientIntelligence clientIntelligence);
/**
* Configures the connection pool
*/
ConnectionPoolConfigurationBuilder connectionPool();
/**
* This property defines the maximum socket connect timeout in milliseconds before giving up connecting to the
* server. Defaults to 2000 (2 seconds).
*/
HotRodConfigurationBuilder connectionTimeout(int connectionTimeout);
/**
* Defines the {@link ConsistentHash} implementation to use for the specified version. By default,
* {@link ConsistentHashV2} is used for version 1 and {@link ConsistentHashV2} is used for version 2.
*/
HotRodConfigurationBuilder consistentHashImpl(int version, Class<? extends ConsistentHash> consistentHashClass);
/**
* Defines the {@link ConsistentHash} implementation to use for the specified version. By default,
* {@link ConsistentHashV2} is used for version 1 and {@link ConsistentHashV2} is used for version 2.
*/
HotRodConfigurationBuilder consistentHashImpl(int version, String consistentHashClass);
HotRodConfigurationBuilder dnsResolverMinTTL(int ttl);
HotRodConfigurationBuilder dnsResolverMaxTTL(int ttl);
HotRodConfigurationBuilder dnsResolverNegativeTTL(int ttl);
/**
* Whether or not to implicitly FORCE_RETURN_VALUE for all calls.
*/
HotRodConfigurationBuilder forceReturnValues(boolean forceReturnValues);
/**
* Allows you to specify a custom {@link Marshaller} implementation to
* serialize and deserialize user objects. This method is mutually exclusive with {@link #marshaller(Marshaller)}.
*/
HotRodConfigurationBuilder marshaller(String marshaller);
/**
* Allows you to specify a custom {@link Marshaller} implementation to
* serialize and deserialize user objects. This method is mutually exclusive with {@link #marshaller(Marshaller)}.
*/
HotRodConfigurationBuilder marshaller(Class<? extends Marshaller> marshaller);
/**
* Allows you to specify an instance of {@link Marshaller} to serialize
* and deserialize user objects. This method is mutually exclusive with {@link #marshaller(Class)}.
*/
HotRodConfigurationBuilder marshaller(Marshaller marshaller);
/**
* Supply a {@link SerializationContextInitializer} implementation to register classes with the {@link
* org.infinispan.commons.marshall.ProtoStreamMarshaller}'s {@link org.infinispan.protostream.SerializationContext}.
*/
HotRodConfigurationBuilder addContextInitializer(String contextInitializer);
/**
* Supply a {@link SerializationContextInitializer} implementation to register classes with the {@link
* org.infinispan.commons.marshall.ProtoStreamMarshaller}'s {@link org.infinispan.protostream.SerializationContext}.
*/
HotRodConfigurationBuilder addContextInitializer(SerializationContextInitializer contextInitializer);
/**
* Convenience method to supply multiple {@link SerializationContextInitializer} implementations.
*
* @see #addContextInitializer(SerializationContextInitializer).
*/
HotRodConfigurationBuilder addContextInitializers(SerializationContextInitializer... contextInitializers);
/**
* This property defines the protocol version that this client should use. Defaults to the latest protocol version
* supported by this client.
*/
HotRodConfigurationBuilder version(ProtocolVersion protocolVersion);
/**
* This property defines the maximum socket read timeout in milliseconds before giving up waiting
* for bytes from the server. Defaults to 2000 (2 seconds)
*/
HotRodConfigurationBuilder socketTimeout(int socketTimeout);
/**
* Security Configuration
*/
SecurityConfigurationBuilder security();
/**
* Affects TCP NODELAY on the TCP stack. Defaults to enabled
*/
HotRodConfigurationBuilder tcpNoDelay(boolean tcpNoDelay);
/**
* Affects TCP KEEPALIVE on the TCP stack. Defaults to disable
*/
HotRodConfigurationBuilder tcpKeepAlive(boolean keepAlive);
/**
* Configures this builder using the specified URI.
*/
HotRodConfigurationBuilder uri(URI uri);
/**
* Configures this builder using the specified URI.
*/
HotRodConfigurationBuilder uri(String uri);
/**
* It sets the maximum number of retries for each request. A valid value should be greater or equals than 0 (zero).
* Zero means no retry will made in case of a network failure. It defaults to 3.
*/
HotRodConfigurationBuilder maxRetries(int maxRetries);
/**
* List of regular expressions for classes that can be deserialized using standard Java deserialization
* when reading data that might have been stored with a different endpoint, e.g. REST.
*/
HotRodConfigurationBuilder addJavaSerialAllowList(String... regEx);
/**
* Sets the batch size of internal iterators (ie. <code>keySet().iterator()</code>. Defaults to 10_000
* @param batchSize the batch size to set
* @return this configuration builder with the batch size set
*/
HotRodConfigurationBuilder batchSize(int batchSize);
/**
* Configures client-side statistics.
*/
StatisticsConfigurationBuilder statistics();
/**
* Per-cache configuration
* @param name the name of the cache to which specific configuration should be applied. You may use wildcard globbing (e.g. <code>cache-*</code>) which will apply to any cache that matches.
* @return the {@link RemoteCacheConfigurationBuilder} for the cache
*/
RemoteCacheConfigurationBuilder remoteCache(String name);
/**
* Sets the transaction's timeout.
* <p>
* This timeout is used by the server to rollback unrecoverable transaction when they are idle for this amount of
* time.
* <p>
* An unrecoverable transaction are transaction enlisted as Synchronization ({@link TransactionMode#NON_XA})
* or XAResource without recovery enabled ({@link TransactionMode#NON_DURABLE_XA}).
* <p>
* For XAResource, this value is overwritten by XAResource#setTransactionTimeout(int).
* <p>
* It defaults to 1 minute.
*/
HotRodConfigurationBuilder transactionTimeout(long timeout, TimeUnit timeUnit);
/**
* Set the TransportFactory. It defaults to {@link org.infinispan.hotrod.impl.transport.netty.DefaultTransportFactory}
* @param transportFactory an instance of {@link TransportFactory}
*/
HotRodConfigurationBuilder transportFactory(TransportFactory transportFactory);
/**
* Configures this builder using the specified properties. See {@link HotRodConfigurationBuilder} for a list.
*/
HotRodConfigurationBuilder withProperties(Properties properties);
/**
* Builds a configuration object
*/
HotRodConfiguration build();
}
| 8,826
| 36.561702
| 192
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/AbstractSecurityConfigurationChildBuilder.java
|
package org.infinispan.hotrod.configuration;
/**
* AbstractSecurityConfigurationChildBuilder.
*
* @since 14.0
*/
public class AbstractSecurityConfigurationChildBuilder extends AbstractConfigurationChildBuilder {
final SecurityConfigurationBuilder builder;
AbstractSecurityConfigurationChildBuilder(SecurityConfigurationBuilder builder) {
super(builder.getBuilder());
this.builder = builder;
}
public AuthenticationConfigurationBuilder authentication() {
return builder.authentication();
}
public SslConfigurationBuilder ssl() {
return builder.ssl();
}
}
| 607
| 24.333333
| 98
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/AuthenticationConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.AuthenticationConfiguration.CALLBACK_HANDLER;
import static org.infinispan.hotrod.configuration.AuthenticationConfiguration.CLIENT_SUBJECT;
import static org.infinispan.hotrod.configuration.AuthenticationConfiguration.ENABLED;
import static org.infinispan.hotrod.configuration.AuthenticationConfiguration.SASL_MECHANISM;
import static org.infinispan.hotrod.configuration.AuthenticationConfiguration.SASL_PROPERTIES;
import static org.infinispan.hotrod.configuration.AuthenticationConfiguration.SERVER_NAME;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.util.Map;
import java.util.Properties;
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.sasl.Sasl;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.Attribute;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.hotrod.impl.security.BasicCallbackHandler;
import org.infinispan.hotrod.impl.security.TokenCallbackHandler;
import org.infinispan.hotrod.impl.security.VoidCallbackHandler;
/**
* AuthenticationConfigurationBuilder.
*
* @since 14.0
*/
public class AuthenticationConfigurationBuilder extends AbstractConfigurationChildBuilder implements Builder<AuthenticationConfiguration> {
private final AttributeSet attributes = AuthenticationConfiguration.attributeDefinitionSet();
public static final String DEFAULT_REALM = "default";
private static final String EXTERNAL_MECH = "EXTERNAL";
private static final String OAUTHBEARER_MECH = "OAUTHBEARER";
private static final String GSSAPI_MECH = "GSSAPI";
private static final String GS2_KRB5_MECH = "GS2-KRB5";
private String username;
private char[] password;
private String realm;
private String token;
public AuthenticationConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return attributes;
}
/**
* Specifies a {@link CallbackHandler} to be used during the authentication handshake. The {@link Callback}s that
* need to be handled are specific to the chosen SASL mechanism.
*/
public AuthenticationConfigurationBuilder callbackHandler(CallbackHandler callbackHandler) {
attributes.attribute(CALLBACK_HANDLER).set(callbackHandler);
return this;
}
/**
* Configures whether authentication should be enabled or not
*/
public AuthenticationConfigurationBuilder enabled(boolean enabled) {
attributes.attribute(ENABLED).set(enabled);
return this;
}
/**
* Enables authentication
*/
public AuthenticationConfigurationBuilder enable() {
return enabled(true);
}
/**
* Disables authentication
*/
public AuthenticationConfigurationBuilder disable() {
return enabled(false);
}
/**
* Selects the SASL mechanism to use for the connection to the server. Setting this property also implicitly enables
* authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder saslMechanism(String saslMechanism) {
attributes.attribute(SASL_MECHANISM).set(saslMechanism);
return enable();
}
/**
* Sets the SASL properties. Setting this property also implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder saslProperties(Map<String, String> saslProperties) {
attributes.attribute(SASL_PROPERTIES).set(saslProperties);
return enable();
}
/**
* Sets the SASL QOP property. If multiple values are specified they will determine preference order. Setting this
* property also implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder saslQop(SaslQop... qop) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < qop.length; i++) {
if (i > 0) {
s.append(",");
}
s.append(qop[i].toString());
}
attributes.attribute(SASL_PROPERTIES).get().put(Sasl.QOP, s.toString());
return enable();
}
/**
* Sets the SASL strength property. If multiple values are specified they will determine preference order. Setting
* this property also implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder saslStrength(SaslStrength... strength) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < strength.length; i++) {
if (i > 0) {
s.append(",");
}
s.append(strength[i].toString());
}
attributes.attribute(SASL_PROPERTIES).get().put(Sasl.STRENGTH, s.toString());
return enable();
}
/**
* Sets the name of the server as expected by the SASL protocol Setting this property also implicitly enables
* authentication (see {@link #enable()} This defaults to "infinispan"
*/
public AuthenticationConfigurationBuilder serverName(String serverName) {
attributes.attribute(SERVER_NAME).set(serverName);
return enable();
}
/**
* Sets the client subject, necessary for those SASL mechanisms which require it to access client credentials (i.e.
* GSSAPI). Setting this property also implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder clientSubject(Subject clientSubject) {
attributes.attribute(CLIENT_SUBJECT).set(clientSubject);
return enable();
}
/**
* Specifies the username to be used for authentication. This will use a simple CallbackHandler. This is mutually
* exclusive with explicitly providing the CallbackHandler. Setting this property also implicitly enables
* authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder username(String username) {
this.username = username;
return enable();
}
/**
* Specifies the password to be used for authentication. A username is also required. Setting this property also
* implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder password(String password) {
this.password = password != null ? password.toCharArray() : null;
return enable();
}
/**
* Specifies the password to be used for authentication. A username is also required. Setting this property also
* implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder password(char[] password) {
this.password = password;
return enable();
}
/**
* Specifies the realm to be used for authentication. Username and password also need to be supplied. If none is
* specified, this defaults to {@link #DEFAULT_REALM}. Setting this property also implicitly enables authentication
* (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder realm(String realm) {
this.realm = realm;
return enable();
}
public AuthenticationConfigurationBuilder token(String token) {
this.token = token;
return enable();
}
@Override
public AuthenticationConfiguration create() {
String mech = attributes.attribute(SASL_MECHANISM).get();
CallbackHandler cbh = attributes.attribute(CALLBACK_HANDLER).get();
if (cbh == null) {
if (OAUTHBEARER_MECH.equals(mech)) {
attributes.attribute(CALLBACK_HANDLER).set(new TokenCallbackHandler(token));
} else if (username != null) {
attributes.attribute(CALLBACK_HANDLER).set(new BasicCallbackHandler(username, realm != null ? realm : DEFAULT_REALM, password));
} else if (EXTERNAL_MECH.equals(mech) || GSSAPI_MECH.equals(mech) || GS2_KRB5_MECH.equals(mech)) {
attributes.attribute(CALLBACK_HANDLER).set(new VoidCallbackHandler());
}
}
return new AuthenticationConfiguration(attributes.protect());
}
@Override
public AuthenticationConfigurationBuilder read(AuthenticationConfiguration template, Combine combine) {
this.attributes.read(template.attributes(), combine);
return this;
}
@Override
public void validate() {
if (attributes.attribute(ENABLED).get()) {
Attribute<CallbackHandler> cbh = attributes.attribute(CALLBACK_HANDLER);
Attribute<String> mech = attributes.attribute(SASL_MECHANISM);
if (cbh.isNull() && attributes.attribute(CLIENT_SUBJECT).isNull() && username == null && token == null && !EXTERNAL_MECH.equals(mech)) {
throw HOTROD.invalidAuthenticationConfiguration();
}
if (OAUTHBEARER_MECH.equals(mech) && cbh.isNull() && token == null) {
throw HOTROD.oauthBearerWithoutToken();
}
if (!cbh.isNull() && (username != null || token != null)) {
throw HOTROD.callbackHandlerAndUsernameMutuallyExclusive();
}
}
}
@Override
public HotRodConfigurationBuilder withProperties(Properties properties) {
attributes.fromProperties(TypedProperties.toTypedProperties(properties), "org.infinispan.client.");
return builder;
}
}
| 9,466
| 38.119835
| 145
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/RemoteCacheConfiguration.java
|
package org.infinispan.hotrod.configuration;
import org.infinispan.api.configuration.CacheConfiguration;
import org.infinispan.commons.configuration.attributes.Attribute;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.tx.lookup.TransactionManagerLookup;
import org.infinispan.hotrod.transaction.lookup.GenericTransactionManagerLookup;
/**
* @since 14.0
**/
public class RemoteCacheConfiguration extends ConfigurationElement<RemoteCacheConfiguration> {
public static final AttributeDefinition<String> CONFIGURATION = AttributeDefinition.builder("configuration", null, String.class).build();
public static final AttributeDefinition<Boolean> FORCE_RETURN_VALUES = AttributeDefinition.builder("force-return-values", false, Boolean.class).build();
public static final AttributeDefinition<String> NAME = AttributeDefinition.builder("name", null, String.class).build();
public static final AttributeDefinition<String> TEMPLATE_NAME = AttributeDefinition.builder("template-name", null, String.class).build();
public static final AttributeDefinition<TransactionMode> TRANSACTION_MODE = AttributeDefinition.builder("transaction-mode", TransactionMode.NONE).build();
public static final AttributeDefinition<TransactionManagerLookup> TRANSACTION_MANAGER = AttributeDefinition.builder("transaction-manager", GenericTransactionManagerLookup.getInstance(), TransactionManagerLookup.class).build();
public static final AttributeDefinition<Marshaller> MARSHALLER = AttributeDefinition.builder("marshaller", null, Marshaller.class).build();
public static final AttributeDefinition<Class> MARSHALLER_CLASS = AttributeDefinition.builder("marshallerClass", null, Class.class).build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(RemoteCacheConfiguration.class, CONFIGURATION, FORCE_RETURN_VALUES, NAME, MARSHALLER, MARSHALLER_CLASS, TEMPLATE_NAME, TRANSACTION_MODE, TRANSACTION_MANAGER);
}
private final NearCacheConfiguration nearCache;
private final Attribute<String> configuration;
private final Attribute<Boolean> forceReturnValues;
private final Attribute<Marshaller> marshaller;
private final Attribute<Class> marshallerClass;
private final Attribute<String> name;
private final Attribute<String> templateName;
private final Attribute<TransactionMode> transactionMode;
private final Attribute<TransactionManagerLookup> transactionManager;
RemoteCacheConfiguration(AttributeSet attributes, NearCacheConfiguration nearCache) {
super("remote-cache", attributes, nearCache);
this.nearCache = nearCache;
configuration = attributes.attribute(CONFIGURATION);
forceReturnValues = attributes.attribute(FORCE_RETURN_VALUES);
name = attributes.attribute(NAME);
marshaller = attributes.attribute(MARSHALLER);
marshallerClass = attributes.attribute(MARSHALLER_CLASS);
templateName = attributes.attribute(TEMPLATE_NAME);
transactionMode = attributes.attribute(TRANSACTION_MODE);
transactionManager = attributes.attribute(TRANSACTION_MANAGER);
}
public static RemoteCacheConfiguration fromCacheConfiguration(String name, CacheConfiguration cacheConfiguration) {
RemoteCacheConfigurationBuilder builder = new RemoteCacheConfigurationBuilder(name);
builder.configuration(cacheConfiguration.toString());
return builder.create();
}
public static RemoteCacheConfiguration fromTemplate(String name, String template) {
RemoteCacheConfigurationBuilder builder = new RemoteCacheConfigurationBuilder(name);
builder.templateName(template);
return builder.create();
}
public NearCacheConfiguration nearCache() {
return nearCache;
}
public String configuration() {
return configuration.get();
}
public boolean forceReturnValues() {
return forceReturnValues.get();
}
public String name() {
return name.get();
}
public Marshaller marshaller() {
return marshaller.get();
}
public Class<? extends Marshaller> marshallerClass() {
return marshallerClass.get();
}
public String templateName() {
return templateName.get();
}
public TransactionMode transactionMode() {
return transactionMode.get();
}
public TransactionManagerLookup transactionManagerLookup() {
return transactionManager.get();
}
}
| 4,633
| 45.34
| 229
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/SecurityConfiguration.java
|
package org.infinispan.hotrod.configuration;
/**
* SecurityConfiguration.
*
* @since 14.0
*/
public class SecurityConfiguration {
private final AuthenticationConfiguration authentication;
private final SslConfiguration ssl;
SecurityConfiguration(AuthenticationConfiguration authentication, SslConfiguration ssl) {
this.authentication = authentication;
this.ssl = ssl;
}
public AuthenticationConfiguration authentication() {
return authentication;
}
public SslConfiguration ssl() {
return ssl;
}
}
| 555
| 19.592593
| 92
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/FailoverRequestBalancingStrategy.java
|
package org.infinispan.hotrod.configuration;
import java.net.SocketAddress;
import java.util.Collection;
import java.util.Set;
import net.jcip.annotations.NotThreadSafe;
/**
* Defines what servers will be selected when a smart-routed request fails.
*/
@NotThreadSafe
public interface FailoverRequestBalancingStrategy {
/**
* Inform the strategy about the currently alive servers.
* @param servers
*/
void setServers(Collection<SocketAddress> servers);
/**
* @param failedServers
* @return Address of the next server the request should be routed to.
*/
SocketAddress nextServer(Set<SocketAddress> failedServers);
}
| 656
| 24.269231
| 75
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/HotRodConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.ALLOW_LIST;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.BATCH_SIZE;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.CLIENT_INTELLIGENCE;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.CONNECT_TIMEOUT;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.CONSISTENT_HASH_IMPL;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.DNS_RESOLVER_MAX_TTL;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.DNS_RESOLVER_MIN_TTL;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.DNS_RESOLVER_NEGATIVE_TTL;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.FORCE_RETURN_VALUES;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.MARSHALLER;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.MARSHALLER_CLASS;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.MAX_RETRIES;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.SOCKET_TIMEOUT;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.TCP_KEEPALIVE;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.TCP_NODELAY;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.TRANSACTION_TIMEOUT;
import static org.infinispan.hotrod.configuration.HotRodConfiguration.VERSION;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.infinispan.api.configuration.Configuration;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.marshall.ProtoStreamMarshaller;
import org.infinispan.commons.util.Features;
import org.infinispan.commons.util.Util;
import org.infinispan.hotrod.HotRod;
import org.infinispan.hotrod.impl.ConfigurationProperties;
import org.infinispan.hotrod.impl.HotRodURI;
import org.infinispan.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.hotrod.impl.logging.LogFactory;
import org.infinispan.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy;
import org.infinispan.protostream.SerializationContextInitializer;
/**
* <p>ConfigurationBuilder used to generate immutable {@link HotRodConfiguration} objects to pass to the
* {@link org.infinispan.api.Infinispan#create(Configuration)} method.</p>
*
* <p>If you prefer to configure the client declaratively, see {@link org.infinispan.hotrod.configuration}</p>
*
* @since 14.0
*/
public class HotRodConfigurationBuilder implements ConfigurationChildBuilder, Builder<HotRodConfiguration> {
private static final Log log = LogFactory.getLog(HotRodConfigurationBuilder.class, Log.class);
private final AttributeSet attributes = HotRodConfiguration.attributeDefinitionSet();
// Match IPv4 (host:port) or IPv6 ([host]:port) addresses
private static final Pattern ADDRESS_PATTERN = Pattern
.compile("(\\[([0-9A-Fa-f:]+)\\]|([^:/?#]*))(?::(\\d*))?");
private static final int CACHE_PREFIX_LENGTH = ConfigurationProperties.CACHE_PREFIX.length();
private final ExecutorFactoryConfigurationBuilder asyncExecutorFactory;
private Supplier<FailoverRequestBalancingStrategy> balancingStrategyFactory = RoundRobinBalancingStrategy::new;
private final ConnectionPoolConfigurationBuilder connectionPool;
private final List<ServerConfigurationBuilder> servers = new ArrayList<>();
private final SecurityConfigurationBuilder security;
private final List<String> allowListRegExs = new ArrayList<>();
private final StatisticsConfigurationBuilder statistics;
private final List<ClusterConfigurationBuilder> clusters = new ArrayList<>();
private Features features;
private final List<SerializationContextInitializer> contextInitializers = new ArrayList<>();
private final Map<String, RemoteCacheConfigurationBuilder> remoteCacheBuilders;
private TransportFactory transportFactory = TransportFactory.DEFAULT;
private boolean tracingPropagationEnabled = ConfigurationProperties.DEFAULT_TRACING_PROPAGATION_ENABLED;
public HotRodConfigurationBuilder() {
this.connectionPool = new ConnectionPoolConfigurationBuilder(this);
this.asyncExecutorFactory = new ExecutorFactoryConfigurationBuilder(this);
this.security = new SecurityConfigurationBuilder(this);
this.statistics = new StatisticsConfigurationBuilder(this);
this.remoteCacheBuilders = new HashMap<>();
}
@Override
public AttributeSet attributes() {
return attributes;
}
@Override
public ServerConfigurationBuilder addServer() {
ServerConfigurationBuilder builder = new ServerConfigurationBuilder(this);
this.servers.add(builder);
return builder;
}
@Override
public ClusterConfigurationBuilder addCluster(String clusterName) {
ClusterConfigurationBuilder builder = new ClusterConfigurationBuilder(this, clusterName);
this.clusters.add(builder);
return builder;
}
@Override
public HotRodConfigurationBuilder addServers(String servers) {
parseServers(servers, (host, port) -> addServer().host(host).port(port));
return this;
}
public List<ServerConfigurationBuilder> servers() {
return servers;
}
public static void parseServers(String servers, BiConsumer<String, Integer> c) {
for (String server : servers.split(";")) {
Matcher matcher = ADDRESS_PATTERN.matcher(server.trim());
if (matcher.matches()) {
String v6host = matcher.group(2);
String v4host = matcher.group(3);
String host = v6host != null ? v6host : v4host;
String portString = matcher.group(4);
int port = portString == null
? ConfigurationProperties.DEFAULT_HOTROD_PORT
: Integer.parseInt(portString);
c.accept(host, port);
} else {
throw HOTROD.parseErrorServerAddress(server);
}
}
}
@Override
public ExecutorFactoryConfigurationBuilder asyncExecutorFactory() {
return this.asyncExecutorFactory;
}
@Override
public HotRodConfigurationBuilder balancingStrategy(String balancingStrategy) {
this.balancingStrategyFactory = () -> Util.getInstance(balancingStrategy, HotRod.class.getClassLoader());
return this;
}
@Override
public HotRodConfigurationBuilder balancingStrategy(Supplier<FailoverRequestBalancingStrategy> balancingStrategyFactory) {
this.balancingStrategyFactory = balancingStrategyFactory;
return this;
}
@Override
public HotRodConfigurationBuilder balancingStrategy(Class<? extends FailoverRequestBalancingStrategy> balancingStrategy) {
this.balancingStrategyFactory = () -> Util.getInstance(balancingStrategy);
return this;
}
@Override
public HotRodConfigurationBuilder clientIntelligence(ClientIntelligence clientIntelligence) {
attributes.attribute(CLIENT_INTELLIGENCE).set(clientIntelligence);
return this;
}
@Override
public ConnectionPoolConfigurationBuilder connectionPool() {
return connectionPool;
}
@Override
public HotRodConfigurationBuilder connectionTimeout(int connectionTimeout) {
attributes.attribute(CONNECT_TIMEOUT).set(connectionTimeout);
return this;
}
@Override
public HotRodConfigurationBuilder consistentHashImpl(int version, Class<? extends ConsistentHash> consistentHashClass) {
if (version == 1) {
log.warn("Hash function version 1 is no longer supported.");
} else {
attributes.attribute(CONSISTENT_HASH_IMPL).get()[version - 1] = consistentHashClass;
}
return this;
}
@Override
public HotRodConfigurationBuilder consistentHashImpl(int version, String consistentHashClass) {
return consistentHashImpl(version, Util.loadClass(consistentHashClass, HotRod.class.getClassLoader()));
}
@Override
public HotRodConfigurationBuilder dnsResolverMinTTL(int ttl) {
attributes.attribute(DNS_RESOLVER_MIN_TTL).set(ttl);
return this;
}
@Override
public HotRodConfigurationBuilder dnsResolverMaxTTL(int ttl) {
attributes.attribute(DNS_RESOLVER_MAX_TTL).set(ttl);
return this;
}
@Override
public HotRodConfigurationBuilder dnsResolverNegativeTTL(int ttl) {
attributes.attribute(DNS_RESOLVER_NEGATIVE_TTL).set(ttl);
return this;
}
@Override
public HotRodConfigurationBuilder forceReturnValues(boolean forceReturnValues) {
attributes.attribute(FORCE_RETURN_VALUES).set(forceReturnValues);
return this;
}
@Override
public HotRodConfigurationBuilder marshaller(String marshallerClassName) {
return marshaller(marshallerClassName == null ? null : Util.loadClass(marshallerClassName, HotRod.class.getClassLoader()));
}
@Override
public HotRodConfigurationBuilder marshaller(Class<? extends Marshaller> marshallerClass) {
attributes.attribute(MARSHALLER).set(marshallerClass == null ? null : Util.getInstance(marshallerClass));
attributes.attribute(MARSHALLER_CLASS).set(marshallerClass);
return this;
}
@Override
public HotRodConfigurationBuilder marshaller(Marshaller marshaller) {
attributes.attribute(MARSHALLER).set(marshaller);
attributes.attribute(MARSHALLER_CLASS).set(marshaller == null ? null : marshaller.getClass());
return this;
}
@Override
public HotRodConfigurationBuilder addContextInitializer(String contextInitializer) {
SerializationContextInitializer sci = Util.getInstance(contextInitializer, HotRod.class.getClassLoader());
return addContextInitializers(sci);
}
@Override
public HotRodConfigurationBuilder addContextInitializer(SerializationContextInitializer contextInitializer) {
if (contextInitializer != null)
this.contextInitializers.add(contextInitializer);
return this;
}
@Override
public HotRodConfigurationBuilder addContextInitializers(SerializationContextInitializer... contextInitializers) {
this.contextInitializers.addAll(Arrays.asList(contextInitializers));
return this;
}
@Override
public HotRodConfigurationBuilder version(ProtocolVersion protocolVersion) {
attributes.attribute(VERSION).set(protocolVersion);
return this;
}
@Override
public SecurityConfigurationBuilder security() {
return security;
}
@Override
public HotRodConfigurationBuilder socketTimeout(int socketTimeout) {
attributes.attribute(SOCKET_TIMEOUT).set(socketTimeout);
return this;
}
@Override
public HotRodConfigurationBuilder tcpNoDelay(boolean tcpNoDelay) {
attributes.attribute(TCP_NODELAY).set(tcpNoDelay);
return this;
}
@Override
public HotRodConfigurationBuilder tcpKeepAlive(boolean keepAlive) {
attributes.attribute(TCP_KEEPALIVE).set(keepAlive);
return this;
}
@Override
public HotRodConfigurationBuilder uri(URI uri) {
// it returns this
return HotRodURI.create(uri).toConfigurationBuilder(this);
}
@Override
public HotRodConfigurationBuilder uri(String uri) {
return uri(java.net.URI.create(uri));
}
@Override
public HotRodConfigurationBuilder maxRetries(int maxRetries) {
attributes.attribute(MAX_RETRIES).set(maxRetries);
return this;
}
@Override
public HotRodConfigurationBuilder addJavaSerialAllowList(String... regEx) {
this.allowListRegExs.addAll(Arrays.asList(regEx));
attributes.attribute(ALLOW_LIST).set(allowListRegExs.toArray(new String[0]));
return this;
}
@Override
public HotRodConfigurationBuilder batchSize(int batchSize) {
if (batchSize <= 0) {
throw new IllegalArgumentException("batchSize must be greater than 0");
}
attributes.attribute(BATCH_SIZE).set(batchSize);
return this;
}
@Override
public StatisticsConfigurationBuilder statistics() {
return statistics;
}
@Override
public RemoteCacheConfigurationBuilder remoteCache(String name) {
return remoteCacheBuilders.computeIfAbsent(name, (n) -> new RemoteCacheConfigurationBuilder(this, n));
}
@Override
public HotRodConfigurationBuilder transactionTimeout(long timeout, TimeUnit timeUnit) {
attributes.attribute(TRANSACTION_TIMEOUT).set(timeUnit.toMillis(timeout));
return this;
}
@Override
public HotRodConfigurationBuilder transportFactory(TransportFactory transportFactory) {
this.transportFactory = transportFactory;
return this;
}
public HotRodConfigurationBuilder disableTracingPropagation() {
this.tracingPropagationEnabled = false;
return this;
}
@Override
public HotRodConfigurationBuilder withProperties(Properties properties) {
//FIXME
return this;
}
@Override
public void validate() {
attributes.validate();
connectionPool.validate();
asyncExecutorFactory.validate();
security.validate();
statistics.validate();
if (attributes.attribute(MAX_RETRIES).get() < 0) {
throw HOTROD.invalidMaxRetries(attributes.attribute(MAX_RETRIES).get());
}
Set<String> clusterNameSet = new HashSet<>(clusters.size());
for (ClusterConfigurationBuilder clusterConfigBuilder : clusters) {
if (!clusterNameSet.add(clusterConfigBuilder.getClusterName())) {
throw HOTROD.duplicateClusterDefinition(clusterConfigBuilder.getClusterName());
}
clusterConfigBuilder.validate();
}
}
@Override
public HotRodConfiguration create() {
List<ServerConfiguration> servers = new ArrayList<>();
if (this.servers.size() > 0)
for (ServerConfigurationBuilder server : this.servers) {
servers.add(server.create());
}
else {
servers.add(new ServerConfiguration(ServerConfiguration.attributeDefinitionSet().protect()));
}
List<ClusterConfiguration> serverClusterConfigs = clusters.stream()
.map(ClusterConfigurationBuilder::create).collect(Collectors.toList());
Map<String, RemoteCacheConfiguration> remoteCaches = remoteCacheBuilders.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey, e -> e.getValue().create()));
return new HotRodConfiguration(attributes.protect(),
asyncExecutorFactory.create(),
balancingStrategyFactory,
connectionPool.create(),
servers,
security.create(),
serverClusterConfigs,
statistics.create(),
features,
contextInitializers,
remoteCaches,
transportFactory,
tracingPropagationEnabled);
}
// Method that handles default marshaller - needed as a placeholder
private Marshaller handleNullMarshaller() {
return new ProtoStreamMarshaller();
}
@Override
public HotRodConfiguration build() {
features = new Features(HotRod.class.getClassLoader());
return build(true);
}
public HotRodConfiguration build(boolean validate) {
if (validate) {
validate();
}
return create();
}
@Override
public HotRodConfigurationBuilder read(HotRodConfiguration template, Combine combine) {
this.attributes.read(template.attributes(), combine);
this.asyncExecutorFactory.read(template.asyncExecutorFactory(), combine);
this.balancingStrategyFactory = template.balancingStrategyFactory();
this.connectionPool.read(template.connectionPool(), combine);
this.servers.clear();
for (ServerConfiguration server : template.servers()) {
this.addServer().host(server.host()).port(server.port());
}
this.clusters.clear();
template.clusters().forEach(cluster -> this.addCluster(cluster.getClusterName()).read(cluster, combine));
this.security.read(template.security(), combine);
this.transportFactory = template.transportFactory();
this.statistics.read(template.statistics(), combine);
this.contextInitializers.clear();
this.contextInitializers.addAll(template.getContextInitializers());
return this;
}
}
| 16,961
| 37.288939
| 129
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/TransactionMode.java
|
package org.infinispan.hotrod.configuration;
/**
* Specifies how a resource is enlisted in a transaction
*
* If {@link #NONE} is used, the resource won't be transactional.
*
* @since 14.0
*/
public enum TransactionMode {
/**
* The cache is not transactional
*/
NONE,
/**
* The cache is enlisted as a synchronization
*/
NON_XA,
/**
* The cache is enlisted as XAResource but it doesn't keep any recovery information.
*/
NON_DURABLE_XA,
/**
* The cache is enlisted as XAResource with recovery support.
*
* This mode isn't available yet.
*/
FULL_XA
}
| 618
| 19.633333
| 87
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/AbstractConfigurationChildBuilder.java
|
package org.infinispan.hotrod.configuration;
import java.net.URI;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.protostream.SerializationContextInitializer;
/**
* AbstractConfigurationChildBuilder.
*
* @since 14.0
*/
public abstract class AbstractConfigurationChildBuilder implements ConfigurationChildBuilder {
final HotRodConfigurationBuilder builder;
protected AbstractConfigurationChildBuilder(HotRodConfigurationBuilder builder) {
this.builder = builder;
}
@Override
public ServerConfigurationBuilder addServer() {
return builder.addServer();
}
@Override
public ClusterConfigurationBuilder addCluster(String clusterName) {
return builder.addCluster(clusterName);
}
@Override
public HotRodConfigurationBuilder addServers(String servers) {
return builder.addServers(servers);
}
@Override
public ExecutorFactoryConfigurationBuilder asyncExecutorFactory() {
return builder.asyncExecutorFactory();
}
@Override
public HotRodConfigurationBuilder balancingStrategy(String balancingStrategy) {
return builder.balancingStrategy(balancingStrategy);
}
@Override
public HotRodConfigurationBuilder balancingStrategy(Class<? extends FailoverRequestBalancingStrategy> balancingStrategy) {
return builder.balancingStrategy(balancingStrategy);
}
@Override
public HotRodConfigurationBuilder balancingStrategy(Supplier<FailoverRequestBalancingStrategy> balancingStrategyFactory) {
return builder.balancingStrategy(balancingStrategyFactory);
}
@Override
public HotRodConfigurationBuilder clientIntelligence(ClientIntelligence clientIntelligence) {
return builder.clientIntelligence(clientIntelligence);
}
@Override
public ConnectionPoolConfigurationBuilder connectionPool() {
return builder.connectionPool();
}
@Override
public HotRodConfigurationBuilder connectionTimeout(int connectionTimeout) {
return builder.connectionTimeout(connectionTimeout);
}
@Override
public HotRodConfigurationBuilder consistentHashImpl(int version, Class<? extends ConsistentHash> consistentHashClass) {
return builder.consistentHashImpl(version, consistentHashClass);
}
@Override
public HotRodConfigurationBuilder consistentHashImpl(int version, String consistentHashClass) {
return builder.consistentHashImpl(version, consistentHashClass);
}
@Override
public HotRodConfigurationBuilder dnsResolverMinTTL(int ttl) {
return builder.dnsResolverMinTTL(ttl);
}
@Override
public HotRodConfigurationBuilder dnsResolverMaxTTL(int ttl) {
return builder.dnsResolverMaxTTL(ttl);
}
@Override
public HotRodConfigurationBuilder dnsResolverNegativeTTL(int ttl) {
return builder.dnsResolverNegativeTTL(ttl);
}
@Override
public HotRodConfigurationBuilder forceReturnValues(boolean forceReturnValues) {
return builder.forceReturnValues(forceReturnValues);
}
@Override
public HotRodConfigurationBuilder marshaller(String marshaller) {
return builder.marshaller(marshaller);
}
@Override
public HotRodConfigurationBuilder marshaller(Class<? extends Marshaller> marshaller) {
return builder.marshaller(marshaller);
}
@Override
public HotRodConfigurationBuilder marshaller(Marshaller marshaller) {
return builder.marshaller(marshaller);
}
@Override
public HotRodConfigurationBuilder addContextInitializer(String contextInitializer) {
return builder.addContextInitializer(contextInitializer);
}
@Override
public HotRodConfigurationBuilder addContextInitializer(SerializationContextInitializer contextInitializer) {
return builder.addContextInitializer(contextInitializer);
}
@Override
public HotRodConfigurationBuilder addContextInitializers(SerializationContextInitializer... contextInitializers) {
return builder.addContextInitializers(contextInitializers);
}
@Override
public HotRodConfigurationBuilder version(ProtocolVersion protocolVersion) {
return builder.version(protocolVersion);
}
@Override
public HotRodConfigurationBuilder socketTimeout(int socketTimeout) {
return builder.socketTimeout(socketTimeout);
}
@Override
public SecurityConfigurationBuilder security() {
return builder.security();
}
@Override
public HotRodConfigurationBuilder tcpNoDelay(boolean tcpNoDelay) {
return builder.tcpNoDelay(tcpNoDelay);
}
@Override
public HotRodConfigurationBuilder tcpKeepAlive(boolean tcpKeepAlive) {
return builder.tcpKeepAlive(tcpKeepAlive);
}
@Override
public HotRodConfigurationBuilder maxRetries(int retriesPerServer) {
return builder.maxRetries(retriesPerServer);
}
@Override
public HotRodConfigurationBuilder addJavaSerialAllowList(String... regExs) {
return builder.addJavaSerialAllowList(regExs);
}
@Override
public HotRodConfigurationBuilder batchSize(int batchSize) {
return builder.batchSize(batchSize);
}
@Override
public StatisticsConfigurationBuilder statistics() {
return builder.statistics();
}
@Override
public RemoteCacheConfigurationBuilder remoteCache(String name) {
return builder.remoteCache(name);
}
@Override
public HotRodConfigurationBuilder transactionTimeout(long timeout, TimeUnit timeUnit) {
return builder.transactionTimeout(timeout, timeUnit);
}
@Override
public HotRodConfigurationBuilder transportFactory(TransportFactory transportFactory) {
return builder.transportFactory(transportFactory);
}
@Override
public HotRodConfigurationBuilder uri(URI uri) {
return builder.uri(uri);
}
@Override
public HotRodConfigurationBuilder uri(String uri) {
return builder.uri(uri);
}
@Override
public HotRodConfigurationBuilder withProperties(Properties properties) {
return builder.withProperties(properties);
}
@Override
public HotRodConfiguration build() {
return builder.build();
}
}
| 6,281
| 28.218605
| 125
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/AuthenticationConfiguration.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.commons.configuration.attributes.CollectionAttributeCopier.collectionCopier;
import java.util.HashMap;
import java.util.Map;
import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
/**
* AuthenticationConfiguration.
*
* @since 14.0
*/
public class AuthenticationConfiguration extends ConfigurationElement<AuthenticationConfiguration> {
static final AttributeDefinition<Boolean> ENABLED = AttributeDefinition.builder("use-auth", false, Boolean.class).build();
static final AttributeDefinition<CallbackHandler> CALLBACK_HANDLER = AttributeDefinition.builder("callback-handler", null, CallbackHandler.class).build();
static final AttributeDefinition<Subject> CLIENT_SUBJECT = AttributeDefinition.builder("client-subject", null, Subject.class).build();
static final AttributeDefinition<String> SASL_MECHANISM = AttributeDefinition.builder("sasl-mechanism", "SCRAM-SHA-512", String.class).build();
static final AttributeDefinition<Map<String, String>> SASL_PROPERTIES = AttributeDefinition.builder("sasl-properties", null, (Class<Map<String, String>>) (Class<?>) Map.class)
.copier(collectionCopier())
.initializer(HashMap::new).immutable().build();
static final AttributeDefinition<String> SERVER_NAME = AttributeDefinition.builder("server-name", "infinispan", String.class).build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(AuthenticationConfiguration.class, ENABLED, CALLBACK_HANDLER, CLIENT_SUBJECT, SASL_MECHANISM, SASL_PROPERTIES, SERVER_NAME);
}
AuthenticationConfiguration(AttributeSet attributes) {
super("authentication", attributes);
}
public CallbackHandler callbackHandler() {
return attributes.attribute(CALLBACK_HANDLER).get();
}
public boolean enabled() {
return attributes.attribute(ENABLED).get();
}
public String saslMechanism() {
return attributes.attribute(SASL_MECHANISM).get();
}
public Map<String, String> saslProperties() {
return attributes.attribute(SASL_PROPERTIES).get();
}
public String serverName() {
return attributes.attribute(SERVER_NAME).get();
}
public Subject clientSubject() {
return attributes.attribute(CLIENT_SUBJECT).get();
}
}
| 2,573
| 40.516129
| 178
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ConnectionPoolConfiguration.java
|
package org.infinispan.hotrod.configuration;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
/**
* ConnectionPoolConfiguration.
*
* @since 14.0
*/
public class ConnectionPoolConfiguration extends ConfigurationElement<ConnectionPoolConfiguration> {
static final AttributeDefinition<ExhaustedAction> EXHAUSTED_ACTION = AttributeDefinition.builder("exhausted_action", ExhaustedAction.WAIT, ExhaustedAction.class).build();
static final AttributeDefinition<Integer> MAX_ACTIVE = AttributeDefinition.builder("max_active", -1, Integer.class).build();
static final AttributeDefinition<Long> MAX_WAIT = AttributeDefinition.builder("max_wait", -1l, Long.class).build();
static final AttributeDefinition<Integer> MIN_IDLE = AttributeDefinition.builder("min_idle", -1, Integer.class).build();
static final AttributeDefinition<Long> MIN_EVICTABLE_IDLE_TIME = AttributeDefinition.builder("min_evictable_idle_time", 180000L, Long.class).build();
static final AttributeDefinition<Integer> MAX_PENDING_REQUESTS = AttributeDefinition.builder("max_pending_requests", 5, Integer.class).build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(ServerConfiguration.class, EXHAUSTED_ACTION, MAX_ACTIVE, MAX_WAIT, MIN_IDLE, MIN_EVICTABLE_IDLE_TIME, MAX_PENDING_REQUESTS);
}
ConnectionPoolConfiguration(AttributeSet attributes) {
super("connection-pool", attributes);
}
public ExhaustedAction exhaustedAction() {
return attributes.attribute(EXHAUSTED_ACTION).get();
}
public int maxActive() {
return attributes.attribute(MAX_ACTIVE).get();
}
public long maxWait() {
return attributes.attribute(MAX_WAIT).get();
}
public int minIdle() {
return attributes.attribute(MIN_IDLE).get();
}
public long minEvictableIdleTime() {
return attributes.attribute(MIN_EVICTABLE_IDLE_TIME).get();
}
public int maxPendingRequests() {
return attributes.attribute(MAX_PENDING_REQUESTS).get();
}
}
| 2,180
| 40.942308
| 173
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/HotRodConfiguration.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.infinispan.api.configuration.Configuration;
import org.infinispan.commons.configuration.ClassAllowList;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.marshall.ProtoStreamMarshaller;
import org.infinispan.commons.util.Features;
import org.infinispan.hotrod.impl.consistenthash.ConsistentHash;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.protostream.SerializationContextInitializer;
/**
* Configuration.
*
* @since 14.0
*/
public class HotRodConfiguration extends ConfigurationElement<HotRodConfiguration> implements Configuration {
static final AttributeDefinition<String[]> ALLOW_LIST = AttributeDefinition.builder("allow_list", new String[0], String[].class).immutable().build();
static final AttributeDefinition<Integer> BATCH_SIZE = AttributeDefinition.builder("batch_size", 10_000, Integer.class).build();
static final AttributeDefinition<ClientIntelligence> CLIENT_INTELLIGENCE = AttributeDefinition.builder("client_intelligence", ClientIntelligence.getDefault(), ClientIntelligence.class).immutable().build();
static final AttributeDefinition<Integer> CONNECT_TIMEOUT = AttributeDefinition.builder("connect_timeout", 2_000, Integer.class).build();
static final AttributeDefinition<Class[]> CONSISTENT_HASH_IMPL = AttributeDefinition.builder("hash_function_impl", ConsistentHash.DEFAULT, Class[].class).immutable().build();
static final AttributeDefinition<Integer> DNS_RESOLVER_MIN_TTL = AttributeDefinition.builder("dns_resolver_min_ttl", 0).build();
static final AttributeDefinition<Integer> DNS_RESOLVER_MAX_TTL = AttributeDefinition.builder("dns_resolver_max_ttl", Integer.MAX_VALUE).build();
static final AttributeDefinition<Integer> DNS_RESOLVER_NEGATIVE_TTL = AttributeDefinition.builder("dns_resolver_negative_ttl", 0).build();
static final AttributeDefinition<Boolean> FORCE_RETURN_VALUES = AttributeDefinition.builder("force_return_values", false, Boolean.class).build();
static final AttributeDefinition<Marshaller> MARSHALLER = AttributeDefinition.builder("marshaller", null, Marshaller.class).immutable().initializer(ProtoStreamMarshaller::new).build();
static final AttributeDefinition<Class> MARSHALLER_CLASS = AttributeDefinition.builder("marshaller_class", ProtoStreamMarshaller.class, Class.class).immutable().build();
static final AttributeDefinition<Integer> MAX_RETRIES = AttributeDefinition.builder("max_retries", 3, Integer.class).validator(v -> {
if (v < 0) throw HOTROD.invalidMaxRetries(v);
}).build();
static final AttributeDefinition<Integer> SOCKET_TIMEOUT = AttributeDefinition.builder("socket_timeout", 2_000, Integer.class).build();
static final AttributeDefinition<Boolean> TCP_KEEPALIVE = AttributeDefinition.builder("tcp_keepalive", true, Boolean.class).build();
static final AttributeDefinition<Boolean> TCP_NODELAY = AttributeDefinition.builder("tcp_no_delay", true, Boolean.class).build();
static final AttributeDefinition<Long> TRANSACTION_TIMEOUT = AttributeDefinition.builder("transaction_timeout", 60_000l, Long.class).build();
static final AttributeDefinition<String> URI = AttributeDefinition.builder("uri", null, String.class).immutable().build();
static final AttributeDefinition<ProtocolVersion> VERSION = AttributeDefinition.builder("version", ProtocolVersion.PROTOCOL_VERSION_AUTO, ProtocolVersion.class).build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(HotRodConfiguration.class, ALLOW_LIST, BATCH_SIZE, CLIENT_INTELLIGENCE, CONNECT_TIMEOUT,
CONSISTENT_HASH_IMPL, DNS_RESOLVER_MIN_TTL, DNS_RESOLVER_MAX_TTL, DNS_RESOLVER_NEGATIVE_TTL,
FORCE_RETURN_VALUES, MARSHALLER, MARSHALLER_CLASS, MAX_RETRIES, SOCKET_TIMEOUT,
TCP_KEEPALIVE, TCP_NODELAY, TRANSACTION_TIMEOUT, URI, VERSION);
}
private final ExecutorFactoryConfiguration asyncExecutorFactory;
private final Supplier<FailoverRequestBalancingStrategy> balancingStrategyFactory;
private final ConnectionPoolConfiguration connectionPool;
private final List<ServerConfiguration> servers;
private final SecurityConfiguration security;
private final List<ClusterConfiguration> clusters;
private final ClassAllowList classAllowList;
private final StatisticsConfiguration statistics;
private final Features features;
private final List<SerializationContextInitializer> contextInitializers;
private final Map<String, RemoteCacheConfiguration> remoteCaches;
private final TransportFactory transportFactory;
private final boolean tracingPropagationEnabled;
HotRodConfiguration(AttributeSet attributes,
ExecutorFactoryConfiguration asyncExecutorFactory,
Supplier<FailoverRequestBalancingStrategy> balancingStrategyFactory,
ConnectionPoolConfiguration connectionPool,
List<ServerConfiguration> servers,
SecurityConfiguration security,
List<ClusterConfiguration> clusters,
StatisticsConfiguration statistics,
Features features,
List<SerializationContextInitializer> contextInitializers,
Map<String, RemoteCacheConfiguration> remoteCaches,
TransportFactory transportFactory,
boolean tracingPropagationEnabled) {
super("", attributes);
this.asyncExecutorFactory = asyncExecutorFactory;
this.balancingStrategyFactory = balancingStrategyFactory;
this.connectionPool = connectionPool;
this.servers = Collections.unmodifiableList(servers);
this.security = security;
this.clusters = clusters;
this.classAllowList = new ClassAllowList(Arrays.asList(attributes.attribute(ALLOW_LIST).get()));
this.statistics = statistics;
this.features = features;
this.contextInitializers = contextInitializers;
this.remoteCaches = remoteCaches;
this.transportFactory = transportFactory;
this.tracingPropagationEnabled = tracingPropagationEnabled;
}
public ExecutorFactoryConfiguration asyncExecutorFactory() {
return asyncExecutorFactory;
}
public Supplier<FailoverRequestBalancingStrategy> balancingStrategyFactory() {
return balancingStrategyFactory;
}
public ClientIntelligence clientIntelligence() {
return attributes.attribute(CLIENT_INTELLIGENCE).get();
}
public ConnectionPoolConfiguration connectionPool() {
return connectionPool;
}
public int connectionTimeout() {
return attributes.attribute(CONNECT_TIMEOUT).get();
}
public Class<? extends ConsistentHash>[] consistentHashImpl() {
Class[] classes = attributes.attribute(CONSISTENT_HASH_IMPL).get();
return Arrays.copyOf(classes, classes.length);
}
public Class<? extends ConsistentHash> consistentHashImpl(int version) {
return attributes.attribute(CONSISTENT_HASH_IMPL).get()[version - 1];
}
public int dnsResolverMinTTL() {
return attributes.attribute(DNS_RESOLVER_MIN_TTL).get();
}
public int dnsResolverMaxTTL() {
return attributes.attribute(DNS_RESOLVER_MAX_TTL).get();
}
public int dnsResolverNegativeTTL() {
return attributes.attribute(DNS_RESOLVER_NEGATIVE_TTL).get();
}
public boolean forceReturnValues() {
return attributes.attribute(FORCE_RETURN_VALUES).get();
}
public Marshaller marshaller() {
return attributes.attribute(MARSHALLER).get();
}
public Class<? extends Marshaller> marshallerClass() {
return attributes.attribute(MARSHALLER_CLASS).get();
}
public ProtocolVersion version() {
return attributes.attribute(VERSION).get();
}
public List<ServerConfiguration> servers() {
return servers;
}
public List<ClusterConfiguration> clusters() {
return clusters;
}
public int socketTimeout() {
return attributes.attribute(SOCKET_TIMEOUT).get();
}
public SecurityConfiguration security() {
return security;
}
public boolean tcpNoDelay() {
return attributes.attribute(TCP_NODELAY).get();
}
public boolean tcpKeepAlive() {
return attributes.attribute(TCP_KEEPALIVE).get();
}
public int maxRetries() {
return attributes.attribute(MAX_RETRIES).get();
}
public String[] serialAllowList() {
return attributes.attribute(ALLOW_LIST).get();
}
public ClassAllowList getClassAllowList() {
return classAllowList;
}
public int batchSize() {
return attributes.attribute(BATCH_SIZE).get();
}
public Map<String, RemoteCacheConfiguration> remoteCaches() {
return Collections.unmodifiableMap(remoteCaches);
}
/**
* Create a new {@link RemoteCacheConfiguration}. This can be used to create additional configurations after the
* client has been initialized.
*
* @param name the name of the cache configuration to create
* @param builderConsumer a {@link Consumer} which receives a {@link RemoteCacheConfigurationBuilder} and can apply
* the necessary configurations on it.
* @return the {@link RemoteCacheConfiguration}
* @throws IllegalArgumentException if a cache configuration with the same name already exists
*/
public RemoteCacheConfiguration addRemoteCache(String name, Consumer<RemoteCacheConfigurationBuilder> builderConsumer) {
synchronized (remoteCaches) {
if (remoteCaches.containsKey(name)) {
throw Log.HOTROD.duplicateCacheConfiguration(name);
} else {
RemoteCacheConfigurationBuilder builder = new RemoteCacheConfigurationBuilder(null, name);
builderConsumer.accept(builder);
builder.validate();
RemoteCacheConfiguration configuration = builder.create();
remoteCaches.put(name, configuration);
return configuration;
}
}
}
/**
* Remove a {@link RemoteCacheConfiguration} from this {@link HotRodConfiguration}. If the cache configuration
* doesn't exist, this method has no effect.
*
* @param name the name of the {@link RemoteCacheConfiguration} to remove.
*/
public void removeRemoteCache(String name) {
remoteCaches.remove(name);
}
public StatisticsConfiguration statistics() {
return statistics;
}
/**
* see {@link HotRodConfigurationBuilder#transactionTimeout(long, TimeUnit)},
*/
public long transactionTimeout() {
return attributes.attribute(TRANSACTION_TIMEOUT).get();
}
public Features features() {
return features;
}
public List<SerializationContextInitializer> getContextInitializers() {
return contextInitializers;
}
public TransportFactory transportFactory() {
return transportFactory;
}
/**
* OpenTelemetry tracing propagation will be activated if this property is true
* and if the OpenTelemetry API jar is detected on the classpath.
* By default, the property is true.
*
* @return if the tracing propagation is enabled
*/
public boolean tracingPropagationEnabled() {
return tracingPropagationEnabled;
}
}
| 11,808
| 42.415441
| 208
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/NearCacheConfiguration.java
|
package org.infinispan.hotrod.configuration;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
import org.infinispan.hotrod.near.DefaultNearCacheFactory;
public class NearCacheConfiguration extends ConfigurationElement<NearCacheConfiguration> {
// TODO: Consider an option to configure key equivalence function for near cache (e.g. for byte arrays)
static final AttributeDefinition<NearCacheMode> MODE = AttributeDefinition.builder("mode", NearCacheMode.DISABLED, NearCacheMode.class).build();
static final AttributeDefinition<Integer> MAX_ENTRIES = AttributeDefinition.builder("max-entries", null, Integer.class).build();
static final AttributeDefinition<Boolean> BLOOM_FILTER = AttributeDefinition.builder("bloom-filter", false, Boolean.class).build();
static final AttributeDefinition<NearCacheFactory> FACTORY = AttributeDefinition.builder("factory", DefaultNearCacheFactory.INSTANCE, NearCacheFactory.class).build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(ServerConfiguration.class, MODE, MAX_ENTRIES, BLOOM_FILTER, FACTORY);
}
NearCacheConfiguration(AttributeSet attributes) {
super("near-cache", attributes);
}
public int maxEntries() {
return attributes.attribute(MAX_ENTRIES).get();
}
public NearCacheMode mode() {
return attributes.attribute(MODE).get();
}
public boolean bloomFilter() {
return attributes.attribute(BLOOM_FILTER).get();
}
public NearCacheFactory nearCacheFactory() {
return attributes.attribute(FACTORY).get();
}
}
| 1,741
| 43.666667
| 169
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ProtocolVersion.java
|
package org.infinispan.hotrod.configuration;
import java.util.Locale;
/**
* Enumeration of supported Hot Rod client protocol VERSIONS.
*
* @since 14.0
*/
public enum ProtocolVersion {
// These need to go in order: lowest version is first - this way compareTo works for VERSIONS
PROTOCOL_VERSION_40(4, 0),
// New VERSIONS go above this line to satisfy compareTo of enum working for VERSIONS
// The version here doesn't matter as long as it is >= 3.0. It must be the LAST version
PROTOCOL_VERSION_AUTO(4, 0, "AUTO"),
;
private static final ProtocolVersion[] VERSIONS = values();
public static final ProtocolVersion DEFAULT_PROTOCOL_VERSION = PROTOCOL_VERSION_AUTO;
public static final ProtocolVersion HIGHEST_PROTOCOL_VERSION = VERSIONS[VERSIONS.length - 2];
private final String textVersion;
private final int version;
ProtocolVersion(int major, int minor) {
this(major, minor, String.format(Locale.ROOT, "%d.%d", major, minor));
}
ProtocolVersion(int major, int minor, String name) {
assert minor < 10;
this.textVersion = name;
this.version = major * 10 + minor;
}
@Override
public String toString() {
return textVersion;
}
public int getVersion() {
return version;
}
public static ProtocolVersion parseVersion(String version) {
if ("AUTO".equalsIgnoreCase(version)) {
return PROTOCOL_VERSION_AUTO;
}
for (ProtocolVersion v : VERSIONS) {
if (v.textVersion.equals(version))
return v;
}
throw new IllegalArgumentException("Illegal version " + version);
}
public static ProtocolVersion getBestVersion(int version) {
// We skip the last version (auto)
for (int i = VERSIONS.length - 2; i >= 0; i--) {
if (version >= VERSIONS[i].version)
return VERSIONS[i];
}
throw new IllegalArgumentException("Illegal version " + version);
}
}
| 1,955
| 28.19403
| 96
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/StatisticsConfiguration.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.commons.configuration.attributes.IdentityAttributeCopier.identityCopier;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
import org.infinispan.commons.jmx.MBeanServerLookup;
import org.infinispan.commons.jmx.PlatformMBeanServerLookup;
import org.infinispan.commons.util.Util;
/**
* @since 14.0
*/
public class StatisticsConfiguration extends ConfigurationElement<StatisticsConfiguration> {
public static final AttributeDefinition<Boolean> ENABLED = AttributeDefinition.builder("enabled", false).immutable().build();
public static final AttributeDefinition<Boolean> JMX_ENABLED = AttributeDefinition.builder("jmx_enabled", false).immutable().build();
public static final AttributeDefinition<String> JMX_DOMAIN = AttributeDefinition.builder("jmx_domain", "org.infinispan").immutable().build();
public static final AttributeDefinition<MBeanServerLookup> MBEAN_SERVER_LOOKUP = AttributeDefinition.builder("mbeanserverlookup", (MBeanServerLookup) Util.getInstance(PlatformMBeanServerLookup.class))
.copier(identityCopier()).immutable().build();
public static final AttributeDefinition<String> JMX_NAME = AttributeDefinition.builder("jmx_name", "Default").immutable().build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(StatisticsConfiguration.class, ENABLED, JMX_ENABLED, JMX_DOMAIN, MBEAN_SERVER_LOOKUP, JMX_NAME);
}
StatisticsConfiguration(AttributeSet attributes) {
super("statistics", attributes);
}
public boolean enabled() {
return attributes.attribute(ENABLED).get();
}
public boolean jmxEnabled() {
return attributes.attribute(JMX_ENABLED).get();
}
public String jmxDomain() {
return attributes.attribute(JMX_DOMAIN).get();
}
public MBeanServerLookup mbeanServerLookup() {
return attributes.attribute(MBEAN_SERVER_LOOKUP).get();
}
public String jmxName() {
return attributes.attribute(JMX_NAME).get();
}
}
| 2,204
| 43.1
| 203
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/NearCacheConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.NearCacheConfiguration.BLOOM_FILTER;
import static org.infinispan.hotrod.configuration.NearCacheConfiguration.FACTORY;
import static org.infinispan.hotrod.configuration.NearCacheConfiguration.MAX_ENTRIES;
import static org.infinispan.hotrod.configuration.NearCacheConfiguration.MODE;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.util.Properties;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.hotrod.impl.ConfigurationProperties;
public class NearCacheConfigurationBuilder extends AbstractConfigurationChildBuilder
implements Builder<NearCacheConfiguration> {
private final AttributeSet attributes = NearCacheConfiguration.attributeDefinitionSet();
NearCacheConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return attributes;
}
/**
* Specifies the maximum number of entries that will be held in the near cache.
*
* @param maxEntries maximum entries in the near cache.
* @return an instance of the builder
*/
public NearCacheConfigurationBuilder maxEntries(int maxEntries) {
attributes.attribute(MAX_ENTRIES).set(maxEntries);
return this;
}
/**
* Specifies whether bloom filter should be used for near cache to limit the number of write
* notifications for unrelated keys.
* @param enable whether to enable bloom filter
* @return an instance of this builder
*/
public NearCacheConfigurationBuilder bloomFilter(boolean enable) {
attributes.attribute(BLOOM_FILTER).set(enable);
return this;
}
/**
* Specifies the near caching mode. See {@link NearCacheMode} for details on the available modes.
*
* @param mode one of {@link NearCacheMode}
* @return an instance of the builder
*/
public NearCacheConfigurationBuilder mode(NearCacheMode mode) {
attributes.attribute(MODE).set(mode);
return this;
}
/**
* Specifies a {@link NearCacheFactory} which is responsible for creating near cache instances.
*
* @param factory a {@link NearCacheFactory}
* @return an instance of the builder
*/
public NearCacheConfigurationBuilder nearCacheFactory(NearCacheFactory factory) {
attributes.attribute(FACTORY).set(factory);
return this;
}
@Override
public void validate() {
if (attributes.attribute(MODE).get().enabled()) {
if (attributes.attribute(MAX_ENTRIES).isNull()) {
throw HOTROD.nearCacheMaxEntriesUndefined();
}
int maxEntries = attributes.attribute(MAX_ENTRIES).get();
boolean bloomFilter = attributes.attribute(BLOOM_FILTER).get();
if (maxEntries < 0 && bloomFilter) {
throw HOTROD.nearCacheMaxEntriesPositiveWithBloom(maxEntries);
}
if (bloomFilter) {
int maxActive = connectionPool().maxActive();
ExhaustedAction exhaustedAction = connectionPool().exhaustedAction();
if (maxActive != 1 || exhaustedAction != ExhaustedAction.WAIT) {
throw HOTROD.bloomFilterRequiresMaxActiveOneAndWait(maxEntries, exhaustedAction);
}
}
}
}
@Override
public NearCacheConfiguration create() {
return new NearCacheConfiguration(attributes.protect());
}
@Override
public NearCacheConfigurationBuilder read(NearCacheConfiguration template, Combine combine) {
this.attributes.read(template.attributes(), combine);
return this;
}
@Override
public HotRodConfigurationBuilder withProperties(Properties properties) {
TypedProperties typed = TypedProperties.toTypedProperties(properties);
if (typed.containsKey(ConfigurationProperties.NEAR_CACHE_MAX_ENTRIES)) {
this.maxEntries(typed.getIntProperty(ConfigurationProperties.NEAR_CACHE_MAX_ENTRIES, -1));
}
if (typed.containsKey(ConfigurationProperties.NEAR_CACHE_MODE)) {
this.mode(NearCacheMode.valueOf(typed.getProperty(ConfigurationProperties.NEAR_CACHE_MODE)));
}
if (typed.containsKey(ConfigurationProperties.NEAR_CACHE_BLOOM_FILTER)) {
this.bloomFilter(typed.getBooleanProperty(ConfigurationProperties.NEAR_CACHE_BLOOM_FILTER, false));
}
return builder;
}
}
| 4,589
| 36.933884
| 108
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ExhaustedAction.java
|
package org.infinispan.hotrod.configuration;
/**
* Enumeration for whenExhaustedAction. Order is important, as the underlying commons-pool uses a byte to represent values
* ExhaustedAction.
*
* @since 14.0
*/
public enum ExhaustedAction {
EXCEPTION, // GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL
WAIT, // GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK
CREATE_NEW // GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW
}
| 423
| 29.285714
| 122
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/SaslQop.java
|
package org.infinispan.hotrod.configuration;
/**
* SaslQop. Possible values for the SASL QOP property
*
* @since 14.0
*/
public enum SaslQop {
AUTH("auth"), AUTH_INT("auth-int"), AUTH_CONF("auth-conf");
private String v;
SaslQop(String v) {
this.v = v;
}
@Override
public String toString() {
return v;
}
}
| 348
| 14.173913
| 62
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ConnectionPoolConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.ConnectionPoolConfiguration.EXHAUSTED_ACTION;
import static org.infinispan.hotrod.configuration.ConnectionPoolConfiguration.MAX_ACTIVE;
import static org.infinispan.hotrod.configuration.ConnectionPoolConfiguration.MAX_PENDING_REQUESTS;
import static org.infinispan.hotrod.configuration.ConnectionPoolConfiguration.MAX_WAIT;
import static org.infinispan.hotrod.configuration.ConnectionPoolConfiguration.MIN_EVICTABLE_IDLE_TIME;
import static org.infinispan.hotrod.configuration.ConnectionPoolConfiguration.MIN_IDLE;
import java.util.Properties;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.util.TypedProperties;
/**
* ConnectionPoolConfigurationBuilder. Specifies connection pooling properties for the HotRod client.
*
* @since 14.0
*/
public class ConnectionPoolConfigurationBuilder extends AbstractConfigurationChildBuilder implements Builder<ConnectionPoolConfiguration> {
private final AttributeSet attributes = ConnectionPoolConfiguration.attributeDefinitionSet();
ConnectionPoolConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return attributes;
}
/**
* Specifies what happens when asking for a connection from a server's pool, and that pool is
* exhausted.
*/
public ConnectionPoolConfigurationBuilder exhaustedAction(ExhaustedAction exhaustedAction) {
attributes.attribute(EXHAUSTED_ACTION).set(exhaustedAction);
return this;
}
/**
* Returns the configured action when the pool has become exhausted.
* @return the action to perform
*/
public ExhaustedAction exhaustedAction() {
return attributes.attribute(EXHAUSTED_ACTION).get();
}
/**
* Controls the maximum number of connections per server that are allocated (checked out to
* client threads, or idle in the pool) at one time. When non-positive, there is no limit to the
* number of connections per server. When maxActive is reached, the connection pool for that
* server is said to be exhausted. The default setting for this parameter is -1, i.e. there is no
* limit.
*/
public ConnectionPoolConfigurationBuilder maxActive(int maxActive) {
attributes.attribute(MAX_ACTIVE).set(maxActive);
return this;
}
/**
* Returns the number of configured maximum connections per server that can be allocated. When this is non-positive
* there is no limit to the number of connections.
* @return maximum number of open connections to a server
*/
public int maxActive() {
return attributes.attribute(MAX_ACTIVE).get();
}
/**
* The amount of time in milliseconds to wait for a connection to become available when the
* exhausted action is {@link ExhaustedAction#WAIT}, after which a {@link java.util.NoSuchElementException}
* will be thrown. If a negative value is supplied, the pool will block indefinitely.
*/
public ConnectionPoolConfigurationBuilder maxWait(long maxWait) {
attributes.attribute(MAX_WAIT).set(maxWait);
return this;
}
/**
* Sets a target value for the minimum number of idle connections (per server) that should always
* be available. If this parameter is set to a positive number and timeBetweenEvictionRunsMillis
* > 0, each time the idle connection eviction thread runs, it will try to create enough idle
* instances so that there will be minIdle idle instances available for each server. The default
* setting for this parameter is 1.
*/
public ConnectionPoolConfigurationBuilder minIdle(int minIdle) {
attributes.attribute(MIN_IDLE).set(minIdle);
return this;
}
/**
* Specifies the minimum amount of time that an connection may sit idle in the pool before it is
* eligible for eviction due to idle time. When non-positive, no connection will be dropped from
* the pool due to idle time alone. This setting has no effect unless
* timeBetweenEvictionRunsMillis > 0. The default setting for this parameter is 180000 (3
* minutes).
*/
public ConnectionPoolConfigurationBuilder minEvictableIdleTime(long minEvictableIdleTime) {
attributes.attribute(MIN_EVICTABLE_IDLE_TIME).set(minEvictableIdleTime);
return this;
}
/**
* Specifies maximum number of requests sent over single connection at one instant.
* Connections with more concurrent requests will be ignored in the pool when choosing available connection
* and the pool will try to create a new connection if all connections are utilized. Only if the new connection
* cannot be created and the {@link #exhaustedAction(ExhaustedAction) exhausted action}
* is set to {@link ExhaustedAction#WAIT} the pool will allow sending the request over one of the over-utilized
* connections.
* The rule of thumb is that this should be set to higher values if the values are small (< 1kB) and to lower values
* if the entries are big (> 10kB).
* Default setting for this parameter is 5.
*/
public ConnectionPoolConfigurationBuilder maxPendingRequests(int maxPendingRequests) {
attributes.attribute(MAX_PENDING_REQUESTS).set(maxPendingRequests);
return this;
}
/**
* Configures the connection pool parameter according to properties
*/
public ConnectionPoolConfigurationBuilder withPoolProperties(Properties properties) {
attributes.fromProperties(TypedProperties.toTypedProperties(properties), "org.infinispan.client.connection_pool.");
return this;
}
@Override
public ConnectionPoolConfiguration create() {
return new ConnectionPoolConfiguration(attributes.protect());
}
@Override
public ConnectionPoolConfigurationBuilder read(ConnectionPoolConfiguration template, Combine combine) {
this.attributes.read(template.attributes(), combine);
return this;
}
}
| 6,143
| 42.574468
| 139
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ServerConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.ServerConfiguration.HOST;
import static org.infinispan.hotrod.configuration.ServerConfiguration.PORT;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
/**
* ServerConfigurationBuilder.
*
* @since 14.0
*/
public class ServerConfigurationBuilder extends AbstractConfigurationChildBuilder implements Builder<ServerConfiguration> {
private static final Pattern ADDRESS_PATTERN = Pattern.compile("(\\[([0-9A-Fa-f:]+)\\]|([^:/?#]*))(?::(\\d*))?");
private final AttributeSet attributes = ServerConfiguration.attributeDefinitionSet();
ServerConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return attributes;
}
public ServerConfigurationBuilder host(String host) {
attributes.attribute(HOST).set(host);
return this;
}
public ServerConfigurationBuilder port(int port) {
attributes.attribute(PORT).set(port);
return this;
}
@Override
public void validate() {
}
@Override
public ServerConfiguration create() {
return new ServerConfiguration(attributes.protect());
}
@Override
public Builder read(ServerConfiguration template, Combine combine) {
this.attributes.read(template.attributes(), combine);
return this;
}
public static void parseServers(String servers, BiConsumer<String, Integer> c) {
for (String server : servers.split(";")) {
Matcher matcher = ADDRESS_PATTERN.matcher(server.trim());
if (matcher.matches()) {
String v6host = matcher.group(2);
String v4host = matcher.group(3);
String host = v6host != null ? v6host : v4host;
String portString = matcher.group(4);
int port = portString == null
? PORT.getDefaultValue()
: Integer.parseInt(portString);
c.accept(host, port);
} else {
throw HOTROD.parseErrorServerAddress(server);
}
}
}
}
| 2,401
| 29.405063
| 123
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ClusterConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import static org.infinispan.hotrod.configuration.ClusterConfiguration.CLIENT_INTELLIGENCE;
import static org.infinispan.hotrod.configuration.ClusterConfiguration.NAME;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
/**
* @since 14.0
*/
public class ClusterConfigurationBuilder extends AbstractConfigurationChildBuilder implements Builder<ClusterConfiguration> {
private final List<ServerConfigurationBuilder> servers = new ArrayList<>();
private final AttributeSet attributes = ClusterConfiguration.attributeDefinitionSet();
protected ClusterConfigurationBuilder(HotRodConfigurationBuilder builder, String clusterName) {
super(builder);
attributes.attribute(NAME).set(clusterName);
}
@Override
public AttributeSet attributes() {
return attributes;
}
public String getClusterName() {
return attributes.attribute(NAME).get();
}
public ClusterConfigurationBuilder addClusterNode(String host, int port) {
ServerConfigurationBuilder serverBuilder = new ServerConfigurationBuilder(builder);
servers.add(serverBuilder.host(host).port(port));
return this;
}
public ClusterConfigurationBuilder addClusterNodes(String serverList) {
HotRodConfigurationBuilder.parseServers(serverList, (host, port) -> {
ServerConfigurationBuilder serverBuilder = new ServerConfigurationBuilder(builder);
servers.add(serverBuilder.host(host).port(port));
});
return this;
}
public ClusterConfigurationBuilder clusterClientIntelligence(ClientIntelligence intelligence) {
// null is valid, means using the global intelligence (for backwards compatibility)
attributes.attribute(CLIENT_INTELLIGENCE).set(intelligence);
return this;
}
@Override
public void validate() {
if (attributes.attribute(NAME).isNull()) {
throw HOTROD.missingClusterNameDefinition();
}
if (servers.isEmpty()) {
throw HOTROD.missingClusterServersDefinition(getClusterName());
}
for (ServerConfigurationBuilder serverConfigBuilder : servers) {
serverConfigBuilder.validate();
}
}
@Override
public ClusterConfiguration create() {
List<ServerConfiguration> serverCluster = servers.stream()
.map(ServerConfigurationBuilder::create).collect(Collectors.toList());
return new ClusterConfiguration(attributes, serverCluster);
}
@Override
public Builder<?> read(ClusterConfiguration template, Combine combine) {
template.getServers().forEach(server -> this.addClusterNode(server.host(), server.port()));
return this;
}
}
| 2,952
| 35.012195
| 125
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ExecutorFactoryConfigurationBuilder.java
|
package org.infinispan.hotrod.configuration;
import java.util.Properties;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.executors.ExecutorFactory;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.commons.util.Util;
import org.infinispan.hotrod.HotRod;
import org.infinispan.hotrod.impl.async.DefaultAsyncExecutorFactory;
/**
* Configures executor factory.
*
* @since 14.0
*/
public class ExecutorFactoryConfigurationBuilder extends AbstractConfigurationChildBuilder implements Builder<ExecutorFactoryConfiguration> {
private Class<? extends ExecutorFactory> factoryClass = DefaultAsyncExecutorFactory.class;
private ExecutorFactory factory;
private Properties properties;
private final HotRodConfigurationBuilder builder;
ExecutorFactoryConfigurationBuilder(HotRodConfigurationBuilder builder) {
super(builder);
this.builder = builder;
this.properties = new Properties();
}
@Override
public AttributeSet attributes() {
return AttributeSet.EMPTY;
}
/**
* Specify factory class for executor
*
* @param factoryClass
* clazz
* @return this ExecutorFactoryConfig
*/
public ExecutorFactoryConfigurationBuilder factoryClass(Class<? extends ExecutorFactory> factoryClass) {
this.factoryClass = factoryClass;
return this;
}
public ExecutorFactoryConfigurationBuilder factoryClass(String factoryClass) {
this.factoryClass = Util.loadClass(factoryClass, HotRod.class.getClassLoader());
return this;
}
/**
* Specify factory class for executor
*
* @param factory
* clazz
* @return this ExecutorFactoryConfig
*/
public ExecutorFactoryConfigurationBuilder factory(ExecutorFactory factory) {
this.factory = factory;
return this;
}
/**
* Add key/value property pair to this executor factory configuration
*
* @param key
* property key
* @param value
* property value
* @return previous value if exists, null otherwise
*/
public ExecutorFactoryConfigurationBuilder addExecutorProperty(String key, String value) {
this.properties.put(key, value);
return this;
}
/**
* Set key/value properties to this executor factory configuration
*
* @param props
* Properties
* @return this ExecutorFactoryConfig
*/
public ExecutorFactoryConfigurationBuilder withExecutorProperties(Properties props) {
this.properties = props;
return this;
}
@Override
public ExecutorFactoryConfiguration create() {
if (factory != null)
return new ExecutorFactoryConfiguration(factory, TypedProperties.toTypedProperties(properties));
else
return new ExecutorFactoryConfiguration(factoryClass, TypedProperties.toTypedProperties(properties));
}
@Override
public ExecutorFactoryConfigurationBuilder read(ExecutorFactoryConfiguration template, Combine combine) {
this.factory = template.factory();
this.factoryClass = template.factoryClass();
this.properties = template.properties();
return this;
}
@Override
public String toString() {
return "ExecutorFactoryConfigurationBuilder [factoryClass=" + factoryClass + ", factory=" + factory + ", properties=" + properties + "]";
}
}
| 3,521
| 29.894737
| 143
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ExecutorFactoryConfiguration.java
|
package org.infinispan.hotrod.configuration;
import org.infinispan.commons.configuration.AbstractTypedPropertiesConfiguration;
import org.infinispan.commons.executors.ExecutorFactory;
import org.infinispan.commons.util.TypedProperties;
/**
* ExecutorFactoryConfiguration.
*
* @since 14.0
*/
public class ExecutorFactoryConfiguration extends AbstractTypedPropertiesConfiguration {
private final Class<? extends ExecutorFactory> factoryClass;
private final ExecutorFactory factory;
@Deprecated
ExecutorFactoryConfiguration(Class<? extends ExecutorFactory> factoryClass, TypedProperties properties) {
super(properties);
this.factoryClass = factoryClass;
this.factory = null;
}
@Deprecated
ExecutorFactoryConfiguration(ExecutorFactory factory, TypedProperties properties) {
super(properties);
this.factory = factory;
this.factoryClass = null;
}
public Class<? extends ExecutorFactory> factoryClass() {
return factoryClass;
}
public ExecutorFactory factory() {
return factory;
}
@Override
public String toString() {
return "ExecutorFactoryConfiguration [factoryClass=" + factoryClass + ", factory=" + factory + ", properties()=" + properties() + "]";
}
}
| 1,262
| 27.066667
| 140
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/configuration/ServerConfiguration.java
|
package org.infinispan.hotrod.configuration;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.ConfigurationElement;
/**
* ServerConfiguration.
*
* @since 14.0
*/
public class ServerConfiguration extends ConfigurationElement<ServerConfiguration> {
static final AttributeDefinition<String> HOST = AttributeDefinition.builder("host", "127.0.0.1", String.class).build();
public static final AttributeDefinition<Integer> PORT = AttributeDefinition.builder("port", 11222, Integer.class).build();
static AttributeSet attributeDefinitionSet() {
return new AttributeSet(ServerConfiguration.class, HOST, PORT);
}
ServerConfiguration(AttributeSet attributes) {
super("server", attributes);
}
public String host() {
return attributes.attribute(HOST).get();
}
public int port() {
return attributes.attribute(PORT).get();
}
}
| 1,027
| 31.125
| 125
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/telemetry/impl/TelemetryServiceImpl.java
|
package org.infinispan.hotrod.telemetry.impl;
import java.nio.charset.StandardCharsets;
import org.infinispan.hotrod.impl.protocol.HeaderParams;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.Context;
public class TelemetryServiceImpl implements TelemetryService {
private final W3CTraceContextPropagator propagator;
public TelemetryServiceImpl() {
propagator = W3CTraceContextPropagator.getInstance();
}
public void injectSpanContext(HeaderParams header) {
// Inject the request with the *current* Context, which contains client current Span if exists.
propagator.inject(Context.current(), header,
(carrier, paramKey, paramValue) ->
carrier.otherParam(paramKey, paramValue.getBytes(StandardCharsets.UTF_8))
);
}
}
| 849
| 31.692308
| 101
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/telemetry/impl/TelemetryService.java
|
package org.infinispan.hotrod.telemetry.impl;
import org.infinispan.hotrod.impl.protocol.HeaderParams;
public interface TelemetryService {
/**
* Try to create a {@link TelemetryService} instance.
*
* @throws ClassCastException if the OpenTelemetry API module is not in the classpath
* @return a {@link TelemetryService} instance
*/
static TelemetryService create() {
return new TelemetryServiceImpl();
}
void injectSpanContext(HeaderParams header);
}
| 494
| 23.75
| 88
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/near/NearCacheService.java
|
package org.infinispan.hotrod.near;
import java.net.SocketAddress;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import org.infinispan.api.common.CacheEntry;
import org.infinispan.commons.util.BloomFilter;
import org.infinispan.commons.util.IntSet;
import org.infinispan.commons.util.MurmurHash3BloomFilter;
import org.infinispan.commons.util.Util;
import org.infinispan.hotrod.configuration.NearCache;
import org.infinispan.hotrod.configuration.NearCacheConfiguration;
import org.infinispan.hotrod.event.ClientCacheEntryExpiredEvent;
import org.infinispan.hotrod.event.ClientCacheEntryModifiedEvent;
import org.infinispan.hotrod.event.ClientCacheEntryRemovedEvent;
import org.infinispan.hotrod.event.ClientCacheFailoverEvent;
import org.infinispan.hotrod.event.impl.ClientListenerNotifier;
import org.infinispan.hotrod.impl.cache.RemoteCache;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.hotrod.impl.logging.LogFactory;
/**
* Near cache service, manages the lifecycle of the near cache.
*
* @since 14.0
*/
public class NearCacheService<K, V> implements NearCache<K, V> {
private static final Log log = LogFactory.getLog(NearCacheService.class);
private final NearCacheConfiguration config;
private final ClientListenerNotifier listenerNotifier;
private final AtomicInteger nearCacheRemovals = new AtomicInteger();
private Object listener;
private byte[] listenerId;
private NearCache<K, V> cache;
private Runnable invalidationCallback;
private int bloomFilterBits = -1;
private int bloomFilterUpdateThreshold;
private RemoteCache<K, V> remote;
private SocketAddress listenerAddress;
protected NearCacheService(NearCacheConfiguration config, ClientListenerNotifier listenerNotifier) {
this.config = config;
this.listenerNotifier = listenerNotifier;
}
public SocketAddress start(RemoteCache<K, V> remote) {
if (cache == null) {
// Create near cache
cache = createNearCache(config, this::entryRemovedFromNearCache);
// Add a listener that updates the near cache
listener = new InvalidatedNearCacheListener<>(this);
int maxEntries = config.maxEntries();
if (maxEntries > 0 && config.bloomFilter()) {
bloomFilterBits = determineBloomFilterBits(maxEntries);
// We want to scale the update frequency of the bloom filter to be based on the number of max entries
// This number along with default values of 3 hash algorithms and 4x bit size we end up with
// between 14.689 and 16.573 percent hits per entry.
bloomFilterUpdateThreshold = maxEntries / 16 + 3;
listenerAddress = remote.addNearCacheListener(listener, bloomFilterBits);
} else {
//FIXME: remote.addClientListener(listener);
}
// Get the listener ID for faster listener connected lookups
listenerId = listenerNotifier.findListenerId(listener);
}
this.remote = remote;
return listenerAddress;
}
private static int determineBloomFilterBits(int maxEntries) {
int bloomFilterBitScaler = Integer.parseInt(System.getProperty("infinispan.bloom-filter.bit-multiplier", "4"));
return maxEntries * bloomFilterBitScaler;
}
void entryRemovedFromNearCache(CacheEntry<K, V> entry) {
while (true) {
int removals = nearCacheRemovals.get();
if (removals >= bloomFilterUpdateThreshold) {
if (nearCacheRemovals.compareAndSet(removals, 0)) {
remote.updateBloomFilter();
break;
}
} else if (nearCacheRemovals.compareAndSet(removals, removals + 1)) {
break;
}
}
}
public void stop(RemoteCache<K, V> remote) {
if (log.isTraceEnabled())
log.tracef("Stop near cache, remove underlying listener id %s", Util.printArray(listenerId));
// Remove listener
//FIXME: remote.removeClientListener(listener);
// Empty cache
cache.clear();
}
protected NearCache<K, V> createNearCache(NearCacheConfiguration config, Consumer<CacheEntry<K, V>> removedConsumer) {
return config.nearCacheFactory().createNearCache(config, removedConsumer);
}
public static <K, V> NearCacheService<K, V> create(
NearCacheConfiguration config, ClientListenerNotifier listenerNotifier) {
return new NearCacheService<>(config, listenerNotifier);
}
@Override
public void put(CacheEntry<K, V> entry) {
cache.put(entry);
if (log.isTraceEnabled())
log.tracef("Put %s in near cache (listenerId=%s)", entry, Util.printArray(listenerId));
}
@Override
public void putIfAbsent(CacheEntry<K, V> entry) {
cache.putIfAbsent(entry);
if (log.isTraceEnabled())
log.tracef("Conditionally put %s if absent in near cache (listenerId=%s)", entry, Util.printArray(listenerId));
}
@Override
public boolean remove(K key) {
boolean removed = cache.remove(key);
if (removed) {
if (invalidationCallback != null) {
invalidationCallback.run();
}
if (log.isTraceEnabled())
log.tracef("Removed key=%s from near cache (listenedId=%s)", key, Util.printArray(listenerId));
} else {
log.tracef("Received false positive remove for key=%s from near cache (listenedId=%s)", key, Util.printArray(listenerId));
// There was a false positive, add that to the removal
entryRemovedFromNearCache(null);
}
return removed;
}
@Override
public CacheEntry<K, V> get(K key) {
boolean listenerConnected = isConnected();
if (listenerConnected) {
CacheEntry<K, V> entry = cache.get(key);
if (log.isTraceEnabled())
log.tracef("Get key=%s returns entry=%s (listenerId=%s)", key, entry, Util.printArray(listenerId));
return entry;
}
if (log.isTraceEnabled())
log.tracef("Near cache disconnected from server, returning null for key=%s (listenedId=%s)",
key, Util.printArray(listenerId));
return null;
}
@Override
public void clear() {
cache.clear();
if (log.isTraceEnabled()) log.tracef("Cleared near cache (listenerId=%s)", Util.printArray(listenerId));
}
@Override
public int size() {
return cache.size();
}
@Override
public Iterator<CacheEntry<K, V>> iterator() {
return cache.iterator();
}
boolean isConnected() {
return listenerNotifier.isListenerConnected(listenerId);
}
public void setInvalidationCallback(Runnable r) {
this.invalidationCallback = r;
}
public int getBloomFilterBits() {
return bloomFilterBits;
}
public byte[] getListenerId() {
return listenerId;
}
public byte[] calculateBloomBits() {
if (bloomFilterBits <= 0) {
return null;
}
BloomFilter<byte[]> bloomFilter = MurmurHash3BloomFilter.createFilter(bloomFilterBits);
for (CacheEntry<K, V> entry : cache) {
bloomFilter.addToFilter(remote.keyToBytes(entry.key()));
}
IntSet intSet = bloomFilter.getIntSet();
return intSet.toBitSet();
}
private static class InvalidatedNearCacheListener<K, V> {
private static final Log log = LogFactory.getLog(InvalidatedNearCacheListener.class);
private final NearCache<K, V> cache;
private InvalidatedNearCacheListener(NearCache<K, V> cache) {
this.cache = cache;
}
@SuppressWarnings("unused")
public void handleModifiedEvent(ClientCacheEntryModifiedEvent<K> event) {
invalidate(event.getKey());
}
@SuppressWarnings("unused")
public void handleRemovedEvent(ClientCacheEntryRemovedEvent<K> event) {
invalidate(event.getKey());
}
@SuppressWarnings("unused")
public void handleExpiredEvent(ClientCacheEntryExpiredEvent<K> event) {
invalidate(event.getKey());
}
@SuppressWarnings("unused")
public void handleFailover(ClientCacheFailoverEvent e) {
if (log.isTraceEnabled()) log.trace("Clear near cache after fail-over of server");
cache.clear();
}
private void invalidate(K key) {
cache.remove(key);
}
}
}
| 8,377
| 33.336066
| 131
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/near/DefaultNearCacheFactory.java
|
package org.infinispan.hotrod.near;
import java.util.function.Consumer;
import org.infinispan.api.common.CacheEntry;
import org.infinispan.hotrod.configuration.NearCache;
import org.infinispan.hotrod.configuration.NearCacheConfiguration;
import org.infinispan.hotrod.configuration.NearCacheFactory;
/**
* @since 14.0
**/
public class DefaultNearCacheFactory implements NearCacheFactory {
public static final DefaultNearCacheFactory INSTANCE = new DefaultNearCacheFactory();
@Override
public <K, V> NearCache<K, V> createNearCache(NearCacheConfiguration config, Consumer<CacheEntry<K, V>> removedConsumer) {
return config.maxEntries() > 0
? BoundedConcurrentMapNearCache.create(config, removedConsumer)
: ConcurrentMapNearCache.create();
}
@Override
public String toString() {
return "DefaultNearCacheFactory{}";
}
}
| 880
| 30.464286
| 125
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/near/BoundedConcurrentMapNearCache.java
|
package org.infinispan.hotrod.near;
import java.util.Iterator;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
import org.infinispan.api.common.CacheEntry;
import org.infinispan.hotrod.configuration.NearCache;
import org.infinispan.hotrod.configuration.NearCacheConfiguration;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
/**
* Near cache based on {@link BoundedConcurrentMapNearCache}
*
* @since 14.0
*/
final class BoundedConcurrentMapNearCache<K, V> implements NearCache<K, V> {
private final ConcurrentMap<K, CacheEntry<K, V>> map;
private final Cache<K, CacheEntry<K, V>> cache;
private BoundedConcurrentMapNearCache(Cache<K, CacheEntry<K, V>> cache) {
this.cache = cache;
this.map = cache.asMap();
}
public static <K, V> NearCache<K, V> create(final NearCacheConfiguration config,
Consumer<? super CacheEntry<K, V>> removedConsumer) {
Cache<K, CacheEntry<K, V>> cache = Caffeine.newBuilder()
.maximumSize(config.maxEntries())
.removalListener((key, value, cause) -> removedConsumer.accept(null))
.build();
return new BoundedConcurrentMapNearCache<>(cache);
}
@Override
public void put(CacheEntry<K, V> entry) {
cache.put(entry.key(), entry);
}
@Override
public void putIfAbsent(CacheEntry<K, V> entry) {
map.putIfAbsent(entry.key(), entry);
}
@Override
public boolean remove(K key) {
return map.remove(key) != null;
}
@Override
public CacheEntry<K, V> get(K key) {
return map.get(key);
}
@Override
public void clear() {
map.clear();
}
@Override
public int size() {
// Make sure to clean up any evicted entries so the returned size is correct
cache.cleanUp();
return map.size();
}
@Override
public Iterator<CacheEntry<K, V>> iterator() {
return map.values().stream().iterator();
}
}
| 2,035
| 26.146667
| 100
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/near/ConcurrentMapNearCache.java
|
package org.infinispan.hotrod.near;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.infinispan.api.common.CacheEntry;
import org.infinispan.hotrod.configuration.NearCache;
/**
* A concurrent-map-based near cache implementation.
* It does not provide eviction capabilities.
*
* @since 14.0
*/
final class ConcurrentMapNearCache<K, V> implements NearCache<K, V> {
private final ConcurrentMap<K, CacheEntry<K, V>> cache = new ConcurrentHashMap<>();
@Override
public void put(CacheEntry<K, V> entry) {
cache.put(entry.key(), entry);
}
@Override
public void putIfAbsent(CacheEntry<K, V> entry) {
cache.putIfAbsent(entry.key(), entry);
}
@Override
public boolean remove(K key) {
return cache.remove(key) != null;
}
@Override
public CacheEntry<K, V> get(K key) {
return cache.get(key);
}
@Override
public void clear() {
cache.clear();
}
@Override
public int size() {
return cache.size();
}
public static <K, V> NearCache<K, V> create() {
return new ConcurrentMapNearCache<K, V>();
}
@Override
public Iterator<CacheEntry<K, V>> iterator() {
return cache.values().stream().iterator();
}
}
| 1,298
| 20.65
| 86
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/filter/Filters.java
|
package org.infinispan.hotrod.filter;
/**
* @since 14.0
*/
public final class Filters {
/**
* The name of the factory used for query DSL based filters and converters. This factory is provided internally by
* the server.
*/
public static final String QUERY_DSL_FILTER_FACTORY_NAME = "query-dsl-filter-converter-factory";
public static final String ITERATION_QUERY_FILTER_CONVERTER_FACTORY_NAME = "iteration-filter-converter-factory";
public static final String CONTINUOUS_QUERY_FILTER_FACTORY_NAME = "continuous-query-filter-converter-factory";
private Filters() {
}
}
| 605
| 27.857143
| 117
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/jmx/RemoteCacheClientStatisticsMXBean.java
|
package org.infinispan.hotrod.jmx;
/**
* RemoteCache client-side statistics (such as number of connections)
*/
public interface RemoteCacheClientStatisticsMXBean {
/**
* Returns the number of hits for a remote cache.
*/
long getRemoteHits();
/**
* Returns the number of misses for a remote cache.
*/
long getRemoteMisses();
/**
* Returns the average read time, in milliseconds, for a remote cache.
*/
long getAverageRemoteReadTime();
/**
* Returns the number of remote cache stores (put, replace) that the client applied.
* Failed conditional operations do not increase the count of entries in the remote cache. Put operations always increase the count even if an operation replaces an equal value.
*/
long getRemoteStores();
/**
* Returns the average store time, in milliseconds, for a remote cache.
*/
long getAverageRemoteStoreTime();
/**
* Returns the number of removes for a remote cache.
*/
long getRemoteRemoves();
/**
* Returns the average time, in milliseconds, for remove operations in a remote cache.
*/
long getAverageRemoteRemovesTime();
/**
* Returns the number of near-cache hits. Returns a value of 0 if near-caching is disabled.
*/
long getNearCacheHits();
/**
* Returns the number of near-cache misses. Returns a value of 0 if near-caching is disabled.
*/
long getNearCacheMisses();
/**
* Returns the number of near-cache invalidations. Returns a value of 0 if near-caching is disabled.
*/
long getNearCacheInvalidations();
/**
* Returns the number of entries currently stored in the near-cache. Returns a value of 0 if near-caching is disabled.
*/
long getNearCacheSize();
/**
* Resets statistics.
*/
void resetStatistics();
/**
* Returns the time, in seconds, since the last reset. See {@link #resetStatistics()}
*/
long getTimeSinceReset();
}
| 1,966
| 25.581081
| 180
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/jmx/RemoteCacheManagerMXBean.java
|
package org.infinispan.hotrod.jmx;
/**
* RemoteCacheManager client-side statistics and operations
*/
public interface RemoteCacheManagerMXBean {
/**
* Returns a list of servers to which the client is currently connected in the format of ip_address:port_number.
*/
String[] getServers();
/**
* Returns the number of active connections
*/
int getActiveConnectionCount();
/**
* Returns the total number of connections
*/
int getConnectionCount();
/**
* Returns the number of idle connections
*/
int getIdleConnectionCount();
/**
* Returns the total number of retries that have been executed
*/
long getRetries();
/**
* Switch remote cache manager to a different cluster, previously
* declared via configuration. If the switch was completed successfully,
* this method returns {@code true}, otherwise it returns {@code false}.
*
* @param clusterName name of the cluster to which to switch to
* @return {@code true} if the cluster was switched, {@code false} otherwise
*/
boolean switchToCluster(String clusterName);
/**
* Switch remote cache manager to a the default cluster, previously
* declared via configuration. If the switch was completed successfully,
* this method returns {@code true}, otherwise it returns {@code false}.
*
* @return {@code true} if the cluster was switched, {@code false} otherwise
*/
boolean switchToDefaultCluster();
}
| 1,487
| 28.176471
| 115
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/multimap/MultimapCacheManager.java
|
package org.infinispan.hotrod.multimap;
import org.infinispan.commons.util.Experimental;
@Experimental
public interface MultimapCacheManager<K, V> {
/**
* Retrieves a named multimap cache from the system.
*
* @param name, name of multimap cache to retrieve
* @return null if no configuration exists as per rules set above, otherwise returns a multimap cache instance
* identified by cacheName and doesn't support duplicates
*/
default RemoteMultimapCache<K, V> get(String name) {
return get(name, false);
}
/**
* Retrieves a named multimap cache from the system.
*
* @param name, name of multimap cache to retrieve
* @param supportsDuplicates, boolean check for identifying whether it supports duplicates or not.
* @return null if no configuration exists as per rules set above, otherwise returns a multimap cache instance
* identified by cacheName
*/
RemoteMultimapCache<K, V> get(String name, boolean supportsDuplicates);
}
| 1,003
| 33.62069
| 113
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/multimap/RemoteMultimapCache.java
|
package org.infinispan.hotrod.multimap;
import java.util.Collection;
import java.util.concurrent.CompletionStage;
import org.infinispan.api.common.CacheEntryCollection;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.CacheWriteOptions;
/**
* @param <K>
* @param <V>
* @since 14.0
*/
public interface RemoteMultimapCache<K, V> {
CompletionStage<CacheEntryCollection<K, V>> getWithMetadata(K key, CacheOptions options);
CompletionStage<Void> put(K key, V value, CacheWriteOptions options);
CompletionStage<Collection<V>> get(K key, CacheOptions options);
CompletionStage<Boolean> remove(K key, CacheOptions options);
CompletionStage<Boolean> remove(K key, V value, CacheOptions options);
CompletionStage<Boolean> containsKey(K key, CacheOptions options);
CompletionStage<Boolean> containsValue(V value, CacheOptions options);
CompletionStage<Boolean> containsEntry(K key, V value, CacheOptions options);
CompletionStage<Long> size(CacheOptions options);
boolean supportsDuplicates();
}
| 1,063
| 27.756757
| 92
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/package-info.java
|
/**
* Hot Rod client exceptions.
*
* @api.public
*/
package org.infinispan.hotrod.exceptions;
| 98
| 13.142857
| 41
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/RemoteNodeSuspectException.java
|
package org.infinispan.hotrod.exceptions;
/**
* When a remote node is suspected and evicted from the cluster while an
* operation is ongoing, the Hot Rod client emits this exception.
*
* @since 14.0
*/
public class RemoteNodeSuspectException extends HotRodClientException {
public RemoteNodeSuspectException(String msgFromServer, long messageId, short status) {
super(msgFromServer, messageId, status);
}
}
| 427
| 25.75
| 90
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/RemoteIllegalLifecycleStateException.java
|
package org.infinispan.hotrod.exceptions;
import java.net.SocketAddress;
/**
* This exception is thrown when the remote cache or cache manager does not
* have the right lifecycle state for operations to be called on it. Situations
* like this include when the cache is stopping or is stopped, when the cache
* manager is stopped...etc.
*
* @since 14.0
*/
public class RemoteIllegalLifecycleStateException extends HotRodClientException {
private final SocketAddress serverAddress;
public RemoteIllegalLifecycleStateException(String msgFromServer, long messageId, short status, SocketAddress serverAddress) {
super(msgFromServer, messageId, status);
this.serverAddress = serverAddress;
}
public SocketAddress getServerAddress() {
return serverAddress;
}
}
| 800
| 28.666667
| 129
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/HotRodTimeoutException.java
|
package org.infinispan.hotrod.exceptions;
/**
* Signals an remote timeout(due to locking) in the infinispan server.
*
* @since 14.0
*/
public class HotRodTimeoutException extends HotRodClientException {
public HotRodTimeoutException() {
}
public HotRodTimeoutException(String message) {
super(message);
}
public HotRodTimeoutException(Throwable cause) {
super(cause);
}
public HotRodTimeoutException(String message, Throwable cause) {
super(message, cause);
}
public HotRodTimeoutException(String remoteMessage, long messageId, int errorStatusCode) {
super(remoteMessage, messageId, errorStatusCode);
}
}
| 668
| 22.892857
| 93
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/ParallelOperationException.java
|
package org.infinispan.hotrod.exceptions;
/**
*/
public class ParallelOperationException extends HotRodClientException {
public ParallelOperationException(String message) {
super(message);
}
public ParallelOperationException(Throwable cause) {
super(cause);
}
public ParallelOperationException(String message, Throwable cause) {
super(message, cause);
}
}
| 397
| 19.947368
| 71
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/RemoteCacheManagerNotStartedException.java
|
package org.infinispan.hotrod.exceptions;
import org.infinispan.hotrod.impl.cache.RemoteCache;
/**
* Thrown when trying to use an {@link RemoteCache} that is associated to an
* {@link org.infinispan.hotrod.RemoteCacheManager} that was not started.
*
* @since 14.0
*/
public class RemoteCacheManagerNotStartedException extends HotRodClientException {
public RemoteCacheManagerNotStartedException(String message) {
super(message);
}
}
| 453
| 25.705882
| 82
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/InvalidResponseException.java
|
package org.infinispan.hotrod.exceptions;
/**
* Signals an internal protocol error.
*
* @since 14.0
*/
public class InvalidResponseException extends HotRodClientException {
public InvalidResponseException() {
}
public InvalidResponseException(String message) {
super(message);
}
public InvalidResponseException(String message, Throwable cause) {
super(message, cause);
}
public InvalidResponseException(Throwable cause) {
super(cause);
}
}
| 490
| 19.458333
| 69
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/CacheNotTransactionalException.java
|
package org.infinispan.hotrod.exceptions;
/**
* When try to create a transactional {@code org.infinispan.hotrod.RemoteCache} but the cache in the Hot Rod
* server isn't transactional, this exception is thrown.
*
* Check if the cache is properly configured in the server configuration.
*
* @since 14.0
*/
public class CacheNotTransactionalException extends HotRodClientException {
public CacheNotTransactionalException() {
}
public CacheNotTransactionalException(String message) {
super(message);
}
public CacheNotTransactionalException(Throwable cause) {
super(cause);
}
public CacheNotTransactionalException(String message, Throwable cause) {
super(message, cause);
}
public CacheNotTransactionalException(String remoteMessage, long messageId, int errorStatusCode) {
super(remoteMessage, messageId, errorStatusCode);
}
}
| 888
| 27.677419
| 108
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/HotRodClientException.java
|
package org.infinispan.hotrod.exceptions;
/**
* Base class for exceptions reported by the hot rod client.
*
* @since 14.0
*/
public class HotRodClientException extends RuntimeException {
private long messageId = -1;
private int errorStatusCode = -1;
public HotRodClientException() {
}
public HotRodClientException(String message) {
super(message);
}
public HotRodClientException(Throwable cause) {
super(cause);
}
public HotRodClientException(String message, Throwable cause) {
super(message, cause);
}
public HotRodClientException(String remoteMessage, long messageId, int errorStatusCode) {
super(remoteMessage);
this.messageId = messageId;
this.errorStatusCode = errorStatusCode;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(getClass().getName());
sb.append(":");
if (messageId != -1) sb.append("Request for messageId=").append(messageId);
if (errorStatusCode != -1) sb.append(" returned ").append(toErrorMsg(errorStatusCode));
String message = getLocalizedMessage();
if (message != null) sb.append(": ").append(message);
return sb.toString();
}
private String toErrorMsg(int errorStatusCode) {
return String.format("server error (status=0x%x)", errorStatusCode);
}
public boolean isServerError() {
return errorStatusCode != -1;
}
}
| 1,427
| 26.461538
| 93
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/exceptions/TransportException.java
|
package org.infinispan.hotrod.exceptions;
import java.net.SocketAddress;
/**
* Indicates a communication exception with the Hot Rod server: e.g. TCP connection is broken while reading a response
* from the server.
*
* @since 14.0
*/
public class TransportException extends HotRodClientException {
private final SocketAddress serverAddress;
public TransportException(String message, SocketAddress serverAddress) {
super(message);
this.serverAddress = serverAddress;
}
public TransportException(String message, Throwable cause, SocketAddress serverAddress) {
super(message, cause);
this.serverAddress = serverAddress;
}
public TransportException(Throwable cause, SocketAddress serverAddress) {
super(cause);
this.serverAddress = serverAddress;
}
public SocketAddress getServerAddress() {
return serverAddress;
}
}
| 894
| 24.571429
| 118
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/package-info.java
|
/**
* Hot Rod client remote event API.
*
* @api.public
*/
package org.infinispan.hotrod.event;
| 99
| 13.285714
| 36
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientListener.java
|
package org.infinispan.hotrod.event;
/**
* Annotation that marks a class to receive remote events from Hot Rod caches.
* Classes with this annotation are expected to have at least one callback
* annotated with one of the events it can receive:
* {@link org.infinispan.client.hotrod.annotation.ClientCacheEntryCreated},
* {@link org.infinispan.client.hotrod.annotation.ClientCacheEntryModified},
* {@link org.infinispan.client.hotrod.annotation.ClientCacheEntryRemoved},
* {@link org.infinispan.client.hotrod.annotation.ClientCacheFailover}
*
* @author Galder Zamarreño
*/
public interface ClientListener {
/**
* Defines the key/value filter factory for this client listener. Filter
* factories create filters that help decide which events should be sent
* to this client listener. This helps with reducing traffic from server
* to client. By default, no filtering is applied.
*/
String filterFactoryName();
/**
* Defines the converter factory for this client listener. Converter
* factories create event converters that customize the contents of the
* events sent to this listener. When event customization is enabled,
* {@link org.infinispan.client.hotrod.annotation.ClientCacheEntryCreated},
* {@link org.infinispan.client.hotrod.annotation.ClientCacheEntryModified},
* and {@link org.infinispan.client.hotrod.annotation.ClientCacheEntryRemoved}
* callbacks receive {@link org.infinispan.client.hotrod.event.ClientCacheEntryCustomEvent}
* instances as parameters instead of their corresponding create/modified/removed
* event. Event customization helps reduce the payload of events, or
* increase to send even more information back to the client listener.
* By default, no event customization is applied.
*/
String converterFactoryName();
/**
* This option affects the type of the parameters received by a configured
* filter and/or converter. If using raw data, filter and/or converter
* classes receive raw binary arrays as parameters instead of unmarshalled
* instances, which is the default. On top of that, when raw data is
* enabled, custom events produced by the converters are expected to be
* byte arrays. This option is useful when trying to avoid marshalling
* costs involved in unmarshalling data to pass to filter/converter
* callbacks or costs involved in marshalling custom event POJOs.
* Using raw data also helps with potential classloading issues related to
* loading callback parameter classes or custom event POJOs. By using raw
* data, there's no need for class sharing between the server and client.
* By default, using raw binary data for filter/converter callbacks is
* disabled.
*/
boolean useRawData();
/**
* This flag enables cached state to be sent back to remote clients when
* either adding a cache listener for the first time, or when the node where
* a remote listener is registered changes. When enabled, state is sent
* back as cache entry created events to the clients. In the special case
* that the node where the remote listener is registered changes, before
* sending any cache entry created events, the client receives a failover
* event so that it's aware of the change of node. This is useful in order
* to do local clean up before receiving the state again. For example, a
* client building a local near cache and keeping it up to date with remote
* events might decide to clear in when the failover event is received and
* before the state is received.
*
* If disabled, no state is sent back to the client when adding a listener,
* nor it gets state when the node where the listener is registered changes.
*
* By default, including state is disabled in order to provide best
* performance. If clients must receive all events, enable including state.
*/
boolean includeCurrentState();
}
| 3,968
| 49.884615
| 94
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientCacheEntryCreatedEvent.java
|
package org.infinispan.hotrod.event;
import org.infinispan.hotrod.impl.cache.RemoteCache;
/**
* Client side cache entry created events provide information on the created
* key, and the version of the entry. This version can be used to invoke conditional
* operations on the server, such as
* {@link RemoteCache#replaceWithVersion(Object, Object, long)}
* or {@link RemoteCache#removeWithVersion(Object, long)}
*
* @param <K> type of key created.
*/
public interface ClientCacheEntryCreatedEvent<K> extends ClientEvent {
/**
* Created cache entry's key.
* @return an instance of the key with which a cache entry has been
* created in the remote server(s).
*/
K getKey();
/**
* Provides access to the version of the created cache entry. This version
* can be used to invoke conditional operations on the server, such as
* {@link RemoteCache#replaceWithVersion(Object, Object, long)}
* or {@link RemoteCache#removeWithVersion(Object, long)}
*
* @return a long containing the version of the created cache entry.
*/
long getVersion();
/**
* This will be true if the write command that caused this had to be retried
* again due to a topology change. This could be a sign that this event
* has been duplicated or another event was dropped and replaced
* (eg: ModifiedEvent replaced CreateEvent)
*
* @return Whether the command that caused this event was retried
*/
boolean isCommandRetried();
}
| 1,493
| 32.954545
| 84
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientCacheFailoverEvent.java
|
package org.infinispan.hotrod.event;
/**
* Event received when the registered listener fails over to a different node.
* Receiving this event indicates that a failure happened in the node where
* the listener was registered in and another server has been selected for
* installing the listener in. As a result of this failover, some events might
* have been missed, hence, this event can be used to clear locally cached
* data. After this failover event is received, the entire cache contents will
* be iterated over and the client receives events on these contents, which
* can be used to rebuild any locally built cache.
*
* @since 14.0
*/
public interface ClientCacheFailoverEvent extends ClientEvent {
}
| 721
| 39.111111
| 78
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientCacheEntryModifiedEvent.java
|
package org.infinispan.hotrod.event;
import org.infinispan.hotrod.impl.cache.RemoteCache;
/**
* Client side cache entry modified events provide information on the modified
* key, and the version of the entry after the modification. This version can
* be used to invoke conditional operations on the server, such as
* {@link RemoteCache#replaceWithVersion(Object, Object, long)}
* or {@link RemoteCache#removeWithVersion(Object, long)}
*
* @param <K> type of key created.
*/
public interface ClientCacheEntryModifiedEvent<K> extends ClientEvent {
/**
* Modifiedcache entry's key.
* @return an instance of the key with which a cache entry has been
* modified in the remote server(s).
*/
K getKey();
/**
* Provides access to the version of the modified cache entry. This version
* can be used to invoke conditional operations on the server, such as
* {@link RemoteCache#replaceWithVersion(Object, Object, long)}
* or {@link RemoteCache#removeWithVersion(Object, long)}
*
* @return a long containing the version of the modified cache entry.
*/
long getVersion();
/**
* This will be true if the write command that caused this had to be retried
* again due to a topology change. This could be a sign that this event
* has been duplicated or another event was dropped and replaced
* (eg: ModifiedEvent replaced CreateEvent)
*
* @return Whether the command that caused this event was retried
*/
boolean isCommandRetried();
}
| 1,522
| 33.613636
| 79
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientEvent.java
|
package org.infinispan.hotrod.event;
/**
*/
public interface ClientEvent {
enum Type {
CLIENT_CACHE_ENTRY_CREATED,
CLIENT_CACHE_ENTRY_MODIFIED,
CLIENT_CACHE_ENTRY_REMOVED,
CLIENT_CACHE_ENTRY_EXPIRED,
CLIENT_CACHE_FAILOVER
}
Type getType();
}
| 285
| 15.823529
| 36
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientCacheEntryRemovedEvent.java
|
package org.infinispan.hotrod.event;
/**
* Client side cache entry removed events provide information on the removed key.
*
* @param <K> type of key created.
*/
public interface ClientCacheEntryRemovedEvent<K> extends ClientEvent {
/**
* Created cache entry's key.
* @return an instance of the key with which a cache entry has been
* created in remote server.
*/
K getKey();
/**
* This will be true if the write command that caused this had to be retried
* again due to a topology change. This could be a sign that this event
* has been duplicated or another event was dropped and replaced
* (eg: ModifiedEvent replaced CreateEvent)
*
* @return Whether the command that caused this event was retried
*/
boolean isCommandRetried();
}
| 798
| 27.535714
| 81
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/IncorrectClientListenerException.java
|
package org.infinispan.hotrod.event;
import org.infinispan.hotrod.exceptions.HotRodClientException;
/**
*/
public class IncorrectClientListenerException extends HotRodClientException {
public IncorrectClientListenerException(String message) {
super(message);
}
}
| 278
| 22.25
| 77
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientCacheEntryExpiredEvent.java
|
package org.infinispan.hotrod.event;
/**
* Client side cache entry expired events provide information on the expired key.
*
* @param <K> type of key expired.
*/
public interface ClientCacheEntryExpiredEvent<K> extends ClientEvent {
/**
* Created cache entry's key.
* @return an instance of the key with which a cache entry has been
* created in remote server.
*/
K getKey();
}
| 405
| 22.882353
| 81
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/ClientCacheEntryCustomEvent.java
|
package org.infinispan.hotrod.event;
/**
* The events generated by default contain just enough information to make the
* event relevant but they avoid cramming too much information in order to reduce
* the cost of sending them. Optionally, the information shipped in the events
* can be customised in order to contain more information, such as values, or to
* contain even less information. This customization is done with {@link org.infinispan.filter.Converter}
* instances generated by a {@link org.infinispan.filter.ConverterFactory}.
*
* As a result of this conversion, custom events are reprenseted by this class,
* and are expected in methods annotation with either
* {@link org.infinispan.hotrod.annotation.ClientCacheEntryCreated},
* {@link org.infinispan.hotrod.annotation.ClientCacheEntryModified} or,
* {@link org.infinispan.hotrod.annotation.ClientCacheEntryRemoved}.
* The event parameter for any of these callbacks is always a {@link ClientCacheEntryCustomEvent},
* and if needed, the event's {@link org.infinispan.hotrod.event.ClientCacheEntryCustomEvent#getType()}
* can be queried to find out whether the originating event was the result of create,
* modified or removed.
*
* @param <T> Type of customized event data. It needs to be marshallable.
*/
public interface ClientCacheEntryCustomEvent<T> extends ClientEvent {
/**
* Customized event data. It can be any type as long as it can be converted
* to binary format for shipping between the server and client.
*
* @return an instance of the customised event data.
*/
T getEventData();
/**
* This will be true if the write command that caused this had to be retried
* again due to a topology change. This could be a sign that this event
* has been duplicated or another event was dropped and replaced
* (eg: ModifiedEvent replaced CreateEvent)
*
* @return Whether the command that caused this event was retried
*/
boolean isCommandRetried();
}
| 1,996
| 44.386364
| 105
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/ExpiredEventImpl.java
|
package org.infinispan.hotrod.event.impl;
import org.infinispan.hotrod.event.ClientCacheEntryExpiredEvent;
public class ExpiredEventImpl<K> extends AbstractClientEvent implements ClientCacheEntryExpiredEvent<K> {
private final K key;
public ExpiredEventImpl(byte[] listenerId, K key) {
super(listenerId);
this.key = key;
}
@Override
public K getKey() {
return key;
}
@Override
public Type getType() {
return Type.CLIENT_CACHE_ENTRY_EXPIRED;
}
@Override
public String toString() {
return "ExpiredEventImpl(" + "key=" + key + ")";
}
}
| 605
| 20.642857
| 105
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/RemovedEventImpl.java
|
package org.infinispan.hotrod.event.impl;
import org.infinispan.hotrod.event.ClientCacheEntryRemovedEvent;
public class RemovedEventImpl<K> extends AbstractClientEvent implements ClientCacheEntryRemovedEvent<K> {
private final K key;
private final boolean retried;
public RemovedEventImpl(byte[] listenerId, K key, boolean retried) {
super(listenerId);
this.key = key;
this.retried = retried;
}
@Override
public K getKey() {
return key;
}
@Override
public boolean isCommandRetried() {
return retried;
}
@Override
public Type getType() {
return Type.CLIENT_CACHE_ENTRY_REMOVED;
}
@Override
public String toString() {
return "RemovedEventImpl(" + "key=" + key + ")";
}
}
| 766
| 20.914286
| 105
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/ClientEventDispatcher.java
|
package org.infinispan.hotrod.event.impl;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.SocketAddress;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.infinispan.commons.util.Util;
import org.infinispan.hotrod.event.ClientCacheFailoverEvent;
import org.infinispan.hotrod.event.ClientEvent;
import org.infinispan.hotrod.impl.DataFormat;
import org.infinispan.hotrod.impl.cache.InvalidatedNearRemoteCache;
import org.infinispan.hotrod.impl.cache.RemoteCache;
import org.infinispan.hotrod.impl.operations.ClientListenerOperation;
public final class ClientEventDispatcher extends EventDispatcher<ClientEvent> {
public static final ClientCacheFailoverEvent FAILOVER_EVENT_SINGLETON = () -> ClientEvent.Type.CLIENT_CACHE_FAILOVER;
private static final Map<Class<? extends Annotation>, Class<?>[]> allowedListeners = new HashMap<>(5);
private final Map<Class<? extends Annotation>, List<ClientListenerInvocation>> invocables;
private final ClientListenerOperation op;
private final RemoteCache<?, ?> remoteCache;
ClientEventDispatcher(ClientListenerOperation op, SocketAddress address, Map<Class<? extends Annotation>,
List<ClientListenerInvocation>> invocables, String cacheName, Runnable cleanup, RemoteCache<?, ?> remoteCache) {
super(cacheName, op.listener, op.listenerId, address, cleanup);
this.op = op;
this.invocables = invocables;
this.remoteCache = remoteCache;
}
public static ClientEventDispatcher create(ClientListenerOperation op, SocketAddress address, Runnable cleanup,
RemoteCache<?, ?> remoteCache) {
Map<Class<? extends Annotation>, List<ClientEventDispatcher.ClientListenerInvocation>> invocables = null;
return new ClientEventDispatcher(op, address, invocables, op.getCacheName(), cleanup, remoteCache);
}
static void testListenerMethodValidity(Method m, Class<?>[] allowedParameters, String annotationName) {
boolean isAllowed = false;
for (Class<?> allowedParameter : allowedParameters) {
if (m.getParameterCount() == 1 && m.getParameterTypes()[0].isAssignableFrom(allowedParameter)) {
isAllowed = true;
break;
}
}
if (!isAllowed)
throw HOTROD.incorrectClientListener(annotationName, Arrays.asList(allowedParameters));
if (!m.getReturnType().equals(void.class))
throw HOTROD.incorrectClientListener(annotationName);
}
@Override
public void invokeEvent(ClientEvent clientEvent) {
if (log.isTraceEnabled())
log.tracef("Event %s received for listener with id=%s", clientEvent, Util.printArray(listenerId));
switch (clientEvent.getType()) {
case CLIENT_CACHE_ENTRY_CREATED:
//FIXME: invokeCallbacks(clientEvent, ClientCacheEntryCreated.class);
break;
case CLIENT_CACHE_ENTRY_MODIFIED:
//FIXME: invokeCallbacks(clientEvent, ClientCacheEntryModified.class);
break;
case CLIENT_CACHE_ENTRY_REMOVED:
//FIXME:invokeCallbacks(clientEvent, ClientCacheEntryRemoved.class);
break;
case CLIENT_CACHE_ENTRY_EXPIRED:
//FIXME:invokeCallbacks(clientEvent, ClientCacheEntryExpired.class);
break;
}
}
private void invokeCallbacks(ClientEvent event, Class<? extends Annotation> type) {
List<ClientListenerInvocation> callbacks = invocables.get(type);
if (callbacks != null) {
for (ClientListenerInvocation callback : callbacks)
callback.invoke(event);
}
}
@Override
public CompletableFuture<Void> executeFailover() {
CompletableFuture<SocketAddress> future = op.copy().execute().toCompletableFuture();
if (remoteCache instanceof InvalidatedNearRemoteCache) {
future = future.thenApply(socketAddress -> {
((InvalidatedNearRemoteCache<?, ?>) remoteCache).setBloomListenerAddress(socketAddress);
return socketAddress;
});
}
return future.thenApply(ignore -> null);
}
@Override
protected void invokeFailoverEvent() {
List<ClientListenerInvocation> callbacks = null;//invocables.get(ClientCacheFailover.class);
if (callbacks != null) {
for (ClientListenerInvocation callback : callbacks) {
callback.invoke(FAILOVER_EVENT_SINGLETON);
}
}
}
protected DataFormat getDataFormat() {
return op.dataFormat();
}
static final class ClientListenerInvocation {
final Object listener;
final Method method;
private ClientListenerInvocation(Object listener, Method method) {
this.listener = listener;
this.method = method;
}
public void invoke(ClientEvent event) {
try {
method.invoke(listener, event);
} catch (Exception e) {
throw HOTROD.exceptionInvokingListener(
e.getClass().getName(), method, listener, e);
}
}
}
}
| 5,227
| 37.441176
| 121
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/EventDispatcher.java
|
package org.infinispan.hotrod.event.impl;
import java.net.SocketAddress;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.hotrod.impl.logging.LogFactory;
public abstract class EventDispatcher<T> {
static final Log log = LogFactory.getLog(EventDispatcher.class);
private static final AtomicReferenceFieldUpdater<EventDispatcher, DispatcherStatus> statusUpdater
= AtomicReferenceFieldUpdater.newUpdater(EventDispatcher.class, DispatcherStatus.class, "status");
final Object listener;
final byte[] listenerId;
final SocketAddress address;
final String cacheName;
final Runnable cleanup;
private volatile DispatcherStatus status = DispatcherStatus.STOPPED;
EventDispatcher(String cacheName, Object listener, byte[] listenerId, SocketAddress address, Runnable cleanup) {
this.listener = listener;
this.listenerId = listenerId;
this.address = address;
this.cacheName = cacheName;
this.cleanup = cleanup;
}
public boolean start() {
return statusUpdater.compareAndSet(this, EventDispatcher.DispatcherStatus.STOPPED, EventDispatcher.DispatcherStatus.RUNNING);
}
public boolean stop() {
boolean stopped = statusUpdater.compareAndSet(this, DispatcherStatus.RUNNING, DispatcherStatus.STOPPED);
if (stopped && cleanup != null) {
cleanup.run();
}
return stopped;
}
public boolean isRunning() {
return status == DispatcherStatus.RUNNING;
}
public abstract CompletableFuture<Void> executeFailover();
protected abstract void invokeEvent(T event);
protected void invokeFailoverEvent() {}
public SocketAddress address() {
return address;
}
enum DispatcherStatus {
STOPPED,
RUNNING
}
}
| 1,881
| 29.852459
| 131
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/CounterEventDispatcher.java
|
package org.infinispan.hotrod.event.impl;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.infinispan.hotrod.impl.counter.HotRodCounterEvent;
public class CounterEventDispatcher extends EventDispatcher<HotRodCounterEvent> {
private final ConcurrentMap<String, List<Consumer<HotRodCounterEvent>>> clientListeners;
private final Supplier<CompletableFuture<Void>> failover;
public CounterEventDispatcher(byte[] listenerId,
ConcurrentMap<String, List<Consumer<HotRodCounterEvent>>> clientListeners,
SocketAddress address, Supplier<CompletableFuture<Void>> failover, Runnable cleanup) {
super("", null, listenerId, address, cleanup);
this.clientListeners = clientListeners;
this.failover = failover;
}
@Override
public CompletableFuture<Void> executeFailover() {
return failover.get();
}
@Override
protected void invokeEvent(HotRodCounterEvent event) {
if (log.isTraceEnabled()) {
log.tracef("Received counter event %s", event);
}
clientListeners.getOrDefault(event.getCounterName(), Collections.emptyList())
.parallelStream()
.forEach(handle -> handle.accept(event));
}
}
| 1,453
| 35.35
| 119
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/ReconnectTask.java
|
package org.infinispan.hotrod.event.impl;
import java.util.concurrent.ScheduledFuture;
import java.util.function.Consumer;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.hotrod.impl.logging.LogFactory;
import org.infinispan.commons.util.Util;
public class ReconnectTask implements Runnable, Consumer<Void> {
private static final Log log = LogFactory.getLog(ReconnectTask.class);
private final EventDispatcher<?> dispatcher;
private ScheduledFuture<?> cancellationFuture;
private boolean completed = false;
public ReconnectTask(EventDispatcher<?> dispatcher) {
this.dispatcher = dispatcher;
}
@Override
public void run() {
if (log.isTraceEnabled()) {
log.tracef("Reconnecting client listener with id %s", Util.printArray(dispatcher.listenerId));
}
dispatcher.executeFailover().thenAccept(this);
}
public synchronized void setCancellationFuture(ScheduledFuture<?> cancellationFuture) {
this.cancellationFuture = cancellationFuture;
if (completed) {
cancellationFuture.cancel(false);
}
}
@Override
public synchronized void accept(Void address) {
ScheduledFuture<?> cancellationFuture = this.cancellationFuture;
completed = true;
if (cancellationFuture != null) {
cancellationFuture.cancel(false);
}
}
}
| 1,365
| 29.355556
| 103
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/CreatedEventImpl.java
|
package org.infinispan.hotrod.event.impl;
import org.infinispan.hotrod.event.ClientCacheEntryCreatedEvent;
public class CreatedEventImpl<K> extends AbstractClientEvent implements ClientCacheEntryCreatedEvent<K> {
final K key;
final long version;
final boolean retried;
public CreatedEventImpl(byte[] listenerId, K key, long version, boolean retried) {
super(listenerId);
this.key = key;
this.version = version;
this.retried = retried;
}
@Override
public K getKey() {
return key;
}
@Override
public long getVersion() {
return version;
}
@Override
public boolean isCommandRetried() {
return retried;
}
@Override
public Type getType() {
return Type.CLIENT_CACHE_ENTRY_CREATED;
}
@Override
public String toString() {
return "CreatedEventImpl(" + "key=" + key
+ ", dataVersion=" + version + ")";
}
}
| 929
| 20.627907
| 105
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/CustomEventImpl.java
|
package org.infinispan.hotrod.event.impl;
import org.infinispan.hotrod.event.ClientCacheEntryCustomEvent;
import org.infinispan.commons.util.Util;
public class CustomEventImpl<T> extends AbstractClientEvent implements ClientCacheEntryCustomEvent<T> {
private final T data;
private final boolean retried;
private final Type type;
public CustomEventImpl(byte[] listenerId, T data, boolean retried, Type type) {
super(listenerId);
this.data = data;
this.retried = retried;
this.type = type;
}
@Override
public T getEventData() {
return data;
}
@Override
public boolean isCommandRetried() {
return retried;
}
@Override
public Type getType() {
return type;
}
@Override
public String toString() {
return "CustomEventImpl(" + "eventData=" + Util.toStr(data) + ", eventType=" + type + ")";
}
}
| 892
| 22.5
| 103
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/ModifiedEventImpl.java
|
package org.infinispan.hotrod.event.impl;
import org.infinispan.hotrod.event.ClientCacheEntryModifiedEvent;
public class ModifiedEventImpl<K> extends AbstractClientEvent implements ClientCacheEntryModifiedEvent<K> {
private final K key;
private final long version;
private final boolean retried;
public ModifiedEventImpl(byte[] listenerId, K key, long version, boolean retried) {
super(listenerId);
this.key = key;
this.version = version;
this.retried = retried;
}
@Override
public K getKey() {
return key;
}
@Override
public long getVersion() {
return version;
}
@Override
public boolean isCommandRetried() {
return retried;
}
@Override
public Type getType() {
return Type.CLIENT_CACHE_ENTRY_MODIFIED;
}
@Override
public String toString() {
return "ModifiedEventImpl(" + "key=" + key
+ ", dataVersion=" + version + ")";
}
}
| 959
| 21.325581
| 107
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/ClientListenerNotifier.java
|
package org.infinispan.hotrod.event.impl;
import static org.infinispan.hotrod.impl.logging.Log.HOTROD;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.infinispan.commons.configuration.ClassAllowList;
import org.infinispan.commons.marshall.WrappedByteArray;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.commons.util.Util;
import org.infinispan.hotrod.impl.DataFormat;
import org.infinispan.hotrod.configuration.HotRodConfiguration;
import org.infinispan.hotrod.impl.ConfigurationProperties;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.hotrod.impl.logging.LogFactory;
import org.infinispan.hotrod.impl.protocol.Codec;
import org.infinispan.hotrod.impl.transport.netty.ChannelFactory;
/**
*/
// Note: this class was moved to impl package as it was not meant to be public
public class ClientListenerNotifier {
private static final Log log = LogFactory.getLog(ClientListenerNotifier.class, Log.class);
public static final AtomicInteger counter = new AtomicInteger(0);
// Time for trying to reconnect listeners when all connections are down.
public static final int RECONNECT_PERIOD = 5000;
private final ConcurrentMap<WrappedByteArray, EventDispatcher<?>> dispatchers = new ConcurrentHashMap<>();
private final ScheduledThreadPoolExecutor reconnectExecutor;
private final Codec codec;
private final ChannelFactory channelFactory;
private final ClassAllowList allowList;
public ClientListenerNotifier(Codec codec, ChannelFactory channelFactory, HotRodConfiguration configuration) {
this.codec = codec;
this.channelFactory = channelFactory;
this.allowList = configuration.getClassAllowList();
TypedProperties defaultAsyncExecutorProperties = configuration.asyncExecutorFactory().properties();
ConfigurationProperties cp = new ConfigurationProperties(defaultAsyncExecutorProperties);
final String threadNamePrefix = cp.getDefaultExecutorFactoryThreadNamePrefix();
final String threadNameSuffix = cp.getDefaultExecutorFactoryThreadNameSuffix();
reconnectExecutor = new ScheduledThreadPoolExecutor(1, r -> {
// Reuse the DefaultAsyncExecutorFactory thread name settings
Thread th = new Thread(r, threadNamePrefix + "-" + counter.getAndIncrement() + threadNameSuffix);
th.setDaemon(true);
return th;
});
reconnectExecutor.setKeepAliveTime(2 * RECONNECT_PERIOD, TimeUnit.MILLISECONDS);
reconnectExecutor.allowCoreThreadTimeOut(true);
}
public void addDispatcher(EventDispatcher<?> dispatcher) {
dispatchers.put(new WrappedByteArray(dispatcher.listenerId), dispatcher);
if (log.isTraceEnabled())
log.tracef("Add dispatcher %s for client listener with id %s, for listener %s",
dispatcher, Util.printArray(dispatcher.listenerId), dispatcher.listener);
}
public void failoverListeners(Set<SocketAddress> failedServers) {
// Compile all listener ids that need failing over
List<WrappedByteArray> failoverListenerIds = new ArrayList<>();
for (Map.Entry<WrappedByteArray, EventDispatcher<?>> entry : dispatchers.entrySet()) {
EventDispatcher<?> dispatcher = entry.getValue();
if (failedServers.contains(dispatcher.address()))
failoverListenerIds.add(entry.getKey());
}
if (log.isTraceEnabled() && failoverListenerIds.isEmpty())
log.tracef("No event listeners registered in failed servers: %s", failedServers);
// Remove tracking listeners and read to the fallback transport
failoverListenerIds.forEach(wrapped -> failoverClientListener(wrapped.getBytes()));
}
public void failoverClientListener(byte[] listenerId) {
EventDispatcher<?> dispatcher = removeClientListener(listenerId);
if (dispatcher == null) {
return;
}
// Invoke failover event callback, if presents
dispatcher.invokeFailoverEvent();
// Re-execute adding client listener in one of the remaining nodes
dispatcher.executeFailover().whenComplete((ignore, throwable) -> {
if (throwable != null) {
if (throwable instanceof RejectedExecutionException) {
log.debug("Client listener failover rejected, not retrying", throwable);
} else {
log.debug("Unable to failover client listener, so ignore connection reset", throwable);
ReconnectTask reconnectTask = new ReconnectTask(dispatcher);
ScheduledFuture<?> scheduledFuture = reconnectExecutor.scheduleAtFixedRate(reconnectTask, RECONNECT_PERIOD, RECONNECT_PERIOD, TimeUnit.MILLISECONDS);
reconnectTask.setCancellationFuture(scheduledFuture);
}
} else {
if (log.isTraceEnabled()) {
log.tracef("Fallback listener id %s from a failed server %s",
Util.printArray(listenerId), dispatcher.address());
}
}
});
}
public void startClientListener(byte[] listenerId) {
EventDispatcher eventDispatcher = dispatchers.get(new WrappedByteArray(listenerId));
eventDispatcher.start();
}
public EventDispatcher<?> removeClientListener(byte[] listenerId) {
return removeClientListener(new WrappedByteArray(listenerId));
}
private EventDispatcher<?> removeClientListener(WrappedByteArray listenerId) {
EventDispatcher dispatcher = dispatchers.remove(listenerId);
if (dispatcher == null) {
if (log.isTraceEnabled()) {
log.tracef("Client listener %s not present (removed concurrently?)", Util.printArray(listenerId.getBytes()));
}
} else {
dispatcher.stop();
}
if (log.isTraceEnabled())
log.tracef("Remove client listener with id %s", Util.printArray(listenerId.getBytes()));
return dispatcher;
}
public byte[] findListenerId(Object listener) {
for (EventDispatcher<?> dispatcher : dispatchers.values()) {
if (dispatcher.listener.equals(listener))
return dispatcher.listenerId;
}
return null;
}
public boolean isListenerConnected(byte[] listenerId) {
EventDispatcher<?> dispatcher = dispatchers.get(new WrappedByteArray(listenerId));
// If listener not present, is not active
return dispatcher != null && dispatcher.isRunning();
}
public SocketAddress findAddress(byte[] listenerId) {
EventDispatcher<?> dispatcher = dispatchers.get(new WrappedByteArray(listenerId));
if (dispatcher != null)
return dispatcher.address();
return null;
}
public Set<Object> getListeners(String cacheName) {
Set<Object> ret = new HashSet<>(dispatchers.size());
for (EventDispatcher<?> dispatcher : dispatchers.values()) {
if (dispatcher.cacheName.equals(cacheName))
ret.add(dispatcher.listener);
}
return ret;
}
public void stop() {
for (WrappedByteArray listenerId : dispatchers.keySet()) {
if (log.isTraceEnabled())
log.tracef("Remote cache manager stopping, remove client listener id %s", Util.printArray(listenerId.getBytes()));
removeClientListener(listenerId);
}
reconnectExecutor.shutdownNow();
}
public <T> void invokeEvent(byte[] listenerId, T event) {
EventDispatcher<T> eventDispatcher = (EventDispatcher<T>) dispatchers.get(new WrappedByteArray(listenerId));
if (eventDispatcher == null) {
throw HOTROD.unexpectedListenerId(Util.printArray(listenerId));
}
eventDispatcher.invokeEvent(event);
}
public DataFormat getCacheDataFormat(byte[] listenerId) {
ClientEventDispatcher clientEventDispatcher = (ClientEventDispatcher) dispatchers.get(new WrappedByteArray(listenerId));
if (clientEventDispatcher == null) {
throw HOTROD.unexpectedListenerId(Util.printArray(listenerId));
}
return clientEventDispatcher.getDataFormat();
}
public Codec codec() {
return codec;
}
public ClassAllowList allowList() {
return allowList;
}
public ChannelFactory channelFactory() {
return channelFactory;
}
}
| 8,646
| 40.17619
| 164
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/event/impl/AbstractClientEvent.java
|
package org.infinispan.hotrod.event.impl;
import org.infinispan.hotrod.event.ClientEvent;
public abstract class AbstractClientEvent implements ClientEvent {
private final byte[] listenerId;
protected AbstractClientEvent(byte[] listenerId) {
this.listenerId = listenerId;
}
public byte[] getListenerId() {
return listenerId;
}
}
| 359
| 21.5
| 66
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/impl/ConfigurationProperties.java
|
package org.infinispan.hotrod.impl;
import java.util.Objects;
import java.util.Properties;
import java.util.regex.Pattern;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.hotrod.configuration.ClientIntelligence;
import org.infinispan.hotrod.configuration.ExhaustedAction;
import org.infinispan.hotrod.configuration.HotRodConfiguration;
import org.infinispan.hotrod.configuration.NearCacheMode;
import org.infinispan.hotrod.configuration.ProtocolVersion;
import org.infinispan.hotrod.configuration.StatisticsConfiguration;
import org.infinispan.hotrod.configuration.TransportFactory;
import org.infinispan.hotrod.impl.async.DefaultAsyncExecutorFactory;
import org.infinispan.hotrod.impl.transport.tcp.RoundRobinBalancingStrategy;
import org.infinispan.hotrod.transaction.lookup.GenericTransactionManagerLookup;
/**
* Encapsulate all config properties here
*
* @version 4.1
*/
public class ConfigurationProperties {
static final String ICH = "infinispan.client.hotrod.";
public static final String URI = ICH + "uri";
public static final String SERVER_LIST = ICH + "server_list";
public static final String MARSHALLER = ICH + "marshaller";
public static final String CONTEXT_INITIALIZERS = ICH + "context-initializers";
public static final String ASYNC_EXECUTOR_FACTORY = ICH + "async_executor_factory";
public static final String CLIENT_INTELLIGENCE = ICH + "client_intelligence";
public static final String DEFAULT_EXECUTOR_FACTORY_POOL_SIZE = ICH + "default_executor_factory.pool_size";
public static final String DEFAULT_EXECUTOR_FACTORY_THREADNAME_PREFIX = ICH + "default_executor_factory.threadname_prefix";
public static final String DEFAULT_EXECUTOR_FACTORY_THREADNAME_SUFFIX = ICH + "default_executor_factory.threadname_suffix";
public static final String TCP_NO_DELAY = ICH + "tcp_no_delay";
public static final String TCP_KEEP_ALIVE = ICH + "tcp_keep_alive";
public static final String REQUEST_BALANCING_STRATEGY = ICH + "request_balancing_strategy";
public static final String FORCE_RETURN_VALUES = ICH + "force_return_values";
public static final String HASH_FUNCTION_PREFIX = ICH + "hash_function_impl";
// Connection properties
public static final String SO_TIMEOUT = ICH + "socket_timeout";
public static final String CONNECT_TIMEOUT = ICH + "connect_timeout";
public static final String PROTOCOL_VERSION = ICH + "protocol_version";
public static final String TRANSPORT_FACTORY = ICH + "transport_factory";
// Encryption properties
public static final String USE_SSL = ICH + "use_ssl";
public static final String KEY_STORE_FILE_NAME = ICH + "key_store_file_name";
public static final String KEY_STORE_TYPE = ICH + "key_store_type";
public static final String KEY_STORE_PASSWORD = ICH + "key_store_password";
public static final String SNI_HOST_NAME = ICH + "sni_host_name";
public static final String KEY_ALIAS = ICH + "key_alias";
public static final String KEY_STORE_CERTIFICATE_PASSWORD = ICH + "key_store_certificate_password";
public static final String TRUST_STORE_FILE_NAME = ICH + "trust_store_file_name";
public static final String TRUST_STORE_PATH = ICH + "trust_store_path";
public static final String TRUST_STORE_TYPE = ICH + "trust_store_type";
public static final String TRUST_STORE_PASSWORD = ICH + "trust_store_password";
public static final String SSL_PROVIDER = ICH + "ssl_provider";
public static final String SSL_PROTOCOL = ICH + "ssl_protocol";
public static final String SSL_CIPHERS = ICH + "ssl_ciphers";
public static final String SSL_CONTEXT = ICH + "ssl_context";
public static final String MAX_RETRIES = ICH + "max_retries";
// Authentication properties
public static final String USE_AUTH = ICH + "use_auth";
public static final String SASL_MECHANISM = ICH + "sasl_mechanism";
public static final String AUTH_CALLBACK_HANDLER = ICH + "auth_callback_handler";
public static final String AUTH_SERVER_NAME = ICH + "auth_server_name";
public static final String AUTH_USERNAME = ICH + "auth_username";
public static final String AUTH_PASSWORD = ICH + "auth_password";
public static final String AUTH_TOKEN = ICH + "auth_token";
public static final String AUTH_REALM = ICH + "auth_realm";
public static final String AUTH_CLIENT_SUBJECT = ICH + "auth_client_subject";
public static final String SASL_PROPERTIES_PREFIX = ICH + "sasl_properties";
public static final Pattern SASL_PROPERTIES_PREFIX_REGEX =
Pattern.compile('^' + ConfigurationProperties.SASL_PROPERTIES_PREFIX + '.');
public static final String JAVA_SERIAL_ALLOWLIST = ICH + "java_serial_allowlist";
public static final String BATCH_SIZE = ICH + "batch_size";
// Statistics properties
public static final String STATISTICS = ICH + "statistics";
public static final String JMX = ICH + "jmx";
public static final String JMX_NAME = ICH + "jmx_name";
public static final String JMX_DOMAIN = ICH + "jmx_domain";
// Transaction properties
public static final String TRANSACTION_MANAGER_LOOKUP = ICH + "transaction.transaction_manager_lookup";
public static final String TRANSACTION_MODE = ICH + "transaction.transaction_mode";
public static final String TRANSACTION_TIMEOUT = ICH + "transaction.timeout";
// Near cache properties
public static final String NEAR_CACHE_MAX_ENTRIES = ICH + "near_cache.max_entries";
public static final String NEAR_CACHE_MODE = ICH + "near_cache.mode";
public static final String NEAR_CACHE_BLOOM_FILTER = ICH + "near_cache.bloom_filter";
public static final String NEAR_CACHE_NAME_PATTERN = ICH + "near_cache.name_pattern";
// Pool properties
public static final String CONNECTION_POOL_MAX_ACTIVE = ICH + "connection_pool.max_active";
public static final String CONNECTION_POOL_MAX_WAIT = ICH + "connection_pool.max_wait";
public static final String CONNECTION_POOL_MIN_IDLE = ICH + "connection_pool.min_idle";
public static final String CONNECTION_POOL_MAX_PENDING_REQUESTS = ICH + "connection_pool.max_pending_requests";
public static final String CONNECTION_POOL_MIN_EVICTABLE_IDLE_TIME = ICH + "connection_pool.min_evictable_idle_time";
public static final String CONNECTION_POOL_EXHAUSTED_ACTION = ICH + "connection_pool.exhausted_action";
// XSite properties
public static final String CLUSTER_PROPERTIES_PREFIX = ICH + "cluster";
public static final Pattern CLUSTER_PROPERTIES_PREFIX_REGEX =
Pattern.compile('^' + ConfigurationProperties.CLUSTER_PROPERTIES_PREFIX + '.');
// Tracing properties
public static final String TRACING_PROPAGATION_ENABLED = ICH + "tracing.propagation_enabled";
// Cache properties
public static final String CACHE_PREFIX= ICH + "cache.";
public static final String CACHE_CONFIGURATION_SUFFIX = ".configuration";
public static final String CACHE_CONFIGURATION_URI_SUFFIX = ".configuration_uri";
public static final String CACHE_FORCE_RETURN_VALUES_SUFFIX = ".force_return_values";
public static final String CACHE_MARSHALLER = ".marshaller";
public static final String CACHE_NEAR_CACHE_MODE_SUFFIX = ".near_cache.mode";
public static final String CACHE_NEAR_CACHE_MAX_ENTRIES_SUFFIX = ".near_cache.max_entries";
public static final String CACHE_NEAR_CACHE_FACTORY_SUFFIX = ".near_cache.factory";
public static final String CACHE_NEAR_CACHE_BLOOM_FILTER_SUFFIX = ".near_cache.bloom_filter";
public static final String CACHE_TEMPLATE_NAME_SUFFIX = ".template_name";
public static final String CACHE_TRANSACTION_MODE_SUFFIX = ".transaction.transaction_mode";
public static final String CACHE_TRANSACTION_MANAGER_LOOKUP_SUFFIX = ".transaction.transaction_manager_lookup";
// defaults
public static final int DEFAULT_HOTROD_PORT = 11222;
public static final int DEFAULT_SO_TIMEOUT = 60_000;
public static final int DEFAULT_CONNECT_TIMEOUT = 60_000;
public static final int DEFAULT_MAX_RETRIES = 10;
public static final int DEFAULT_BATCH_SIZE = 10_000;
public static final int DEFAULT_MAX_PENDING_REQUESTS = 5;
public static final long DEFAULT_MIN_EVICTABLE_IDLE_TIME = 1800000L;
public static final int DEFAULT_MAX_ACTIVE = -1;
public static final int DEFAULT_MAX_WAIT = -1;
public static final int DEFAULT_MIN_IDLE = -1;
public static final boolean DEFAULT_TRACING_PROPAGATION_ENABLED = true;
private final TypedProperties props;
public ConfigurationProperties() {
this.props = new TypedProperties();
}
public ConfigurationProperties(String serverList) {
this();
setServerList(serverList);
}
public ConfigurationProperties(Properties props) {
this.props = props == null ? new TypedProperties() : TypedProperties.toTypedProperties(props);
}
public void setURI(String uri) {
props.setProperty(URI, uri);
}
public String getURI() {
return props.getProperty(URI);
}
public void setServerList(String serverList) {
props.setProperty(SERVER_LIST, serverList);
}
public String getMarshaller() {
return props.getProperty(MARSHALLER);
}
public void setMarshaller(String marshaller) {
props.setProperty(MARSHALLER, marshaller);
}
public String getContextInitializers() {
return props.getProperty(CONTEXT_INITIALIZERS);
}
public void setContextInitializers(String contextInitializers) {
props.setProperty(CONTEXT_INITIALIZERS, contextInitializers);
}
public String getAsyncExecutorFactory() {
return props.getProperty(ASYNC_EXECUTOR_FACTORY, DefaultAsyncExecutorFactory.class.getName());
}
public int getDefaultExecutorFactoryPoolSize() {
return props.getIntProperty(DEFAULT_EXECUTOR_FACTORY_POOL_SIZE, 99);
}
public void setDefaultExecutorFactoryPoolSize(int poolSize) {
props.setProperty(DEFAULT_EXECUTOR_FACTORY_POOL_SIZE, poolSize);
}
public String getDefaultExecutorFactoryThreadNamePrefix() {
return props.getProperty(DEFAULT_EXECUTOR_FACTORY_THREADNAME_PREFIX, DefaultAsyncExecutorFactory.THREAD_NAME);
}
public void setDefaultExecutorFactoryThreadNamePrefix(String threadNamePrefix) {
props.setProperty(DEFAULT_EXECUTOR_FACTORY_THREADNAME_PREFIX, threadNamePrefix);
}
public String getDefaultExecutorFactoryThreadNameSuffix() {
return props.getProperty(DEFAULT_EXECUTOR_FACTORY_THREADNAME_SUFFIX, "");
}
public void setDefaultExecutorFactoryThreadNameSuffix(String threadNameSuffix) {
props.setProperty(DEFAULT_EXECUTOR_FACTORY_THREADNAME_SUFFIX, threadNameSuffix);
}
public void setTransportFactory(String transportFactoryClass) {
props.setProperty(TRANSPORT_FACTORY, transportFactoryClass);
}
public void setTransportFactory(Class<TransportFactory> transportFactory) {
setTransportFactory(transportFactory.getName());
}
public String getTransportFactory() {
return props.getProperty(TRANSPORT_FACTORY, TransportFactory.DEFAULT.getClass().getName());
}
public boolean getTcpNoDelay() {
return props.getBooleanProperty(TCP_NO_DELAY, true);
}
public void setTcpNoDelay(boolean tcpNoDelay) {
props.setProperty(TCP_NO_DELAY, tcpNoDelay);
}
public boolean getTcpKeepAlive() {
return props.getBooleanProperty(TCP_KEEP_ALIVE, false);
}
public void setTcpKeepAlive(boolean tcpKeepAlive) {
props.setProperty(TCP_KEEP_ALIVE, tcpKeepAlive);
}
public String getRequestBalancingStrategy() {
return props.getProperty(REQUEST_BALANCING_STRATEGY, RoundRobinBalancingStrategy.class.getName());
}
public boolean getForceReturnValues() {
return props.getBooleanProperty(FORCE_RETURN_VALUES, false);
}
public void setForceReturnValues(boolean forceReturnValues) {
props.setProperty(FORCE_RETURN_VALUES, forceReturnValues);
}
public Properties getProperties() {
return props;
}
public int getSoTimeout() {
return props.getIntProperty(SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
}
public void setSocketTimeout(int socketTimeout) {
props.setProperty(SO_TIMEOUT, socketTimeout);
}
public String getProtocolVersion() {
return props.getProperty(PROTOCOL_VERSION, ProtocolVersion.DEFAULT_PROTOCOL_VERSION.toString());
}
public void setProtocolVersion(String protocolVersion) {
props.setProperty(PROTOCOL_VERSION, protocolVersion);
}
public String getClientIntelligence() {
return props.getProperty(CLIENT_INTELLIGENCE, ClientIntelligence.getDefault().name());
}
public void setClientIntelligence(String clientIntelligence) {
props.setProperty(CLIENT_INTELLIGENCE, clientIntelligence);
}
public int getConnectTimeout() {
return props.getIntProperty(CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT);
}
public void setConnectTimeout(int connectTimeout) {
props.setProperty(CONNECT_TIMEOUT, connectTimeout);
}
public boolean getUseSSL() {
return props.getBooleanProperty(USE_SSL, false);
}
public void setUseSSL(boolean useSSL) {
props.setProperty(USE_SSL, useSSL);
}
public String getKeyStoreFileName() {
return props.getProperty(KEY_STORE_FILE_NAME);
}
public void setKeyStoreFileName(String keyStoreFileName) {
props.setProperty(KEY_STORE_FILE_NAME, keyStoreFileName);
}
public String getKeyStoreType() {
return props.getProperty(KEY_STORE_TYPE);
}
public void setKeyStoreType(String keyStoreType) {
props.setProperty(KEY_STORE_TYPE, keyStoreType);
}
public String getKeyStorePassword() {
return props.getProperty(KEY_STORE_PASSWORD);
}
public void setKeyStorePassword(String keyStorePassword) {
props.setProperty(KEY_STORE_PASSWORD, keyStorePassword);
}
public void setKeyStoreCertificatePassword(String keyStoreCertificatePassword) {
props.setProperty(KEY_STORE_CERTIFICATE_PASSWORD, keyStoreCertificatePassword);
}
public String getKeyAlias() {
return props.getProperty(KEY_ALIAS);
}
public void setKeyAlias(String keyAlias) {
props.setProperty(KEY_ALIAS, keyAlias);
}
public String getTrustStoreFileName() {
return props.getProperty(TRUST_STORE_FILE_NAME);
}
public void setTrustStoreFileName(String trustStoreFileName) {
props.setProperty(TRUST_STORE_FILE_NAME, trustStoreFileName);
}
public String getTrustStoreType() {
return props.getProperty(TRUST_STORE_TYPE);
}
public void setTrustStoreType(String trustStoreType) {
props.setProperty(TRUST_STORE_TYPE, trustStoreType);
}
public String getTrustStorePassword() {
return props.getProperty(TRUST_STORE_PASSWORD);
}
public void setTrustStorePassword(String trustStorePassword) {
props.setProperty(TRUST_STORE_PASSWORD, trustStorePassword);
}
public String getSSLProtocol() {
return props.getProperty(SSL_PROTOCOL);
}
public void setSSLProtocol(String sslProtocol) {
props.setProperty(SSL_PROTOCOL, sslProtocol);
}
public String getSniHostName() {
return props.getProperty(SNI_HOST_NAME);
}
public void setSniHostName(String sniHostName) {
props.setProperty(SNI_HOST_NAME, sniHostName);
}
public boolean getUseAuth() {
return props.getBooleanProperty(USE_AUTH, false);
}
public void setUseAuth(boolean useAuth) {
props.setProperty(USE_AUTH, useAuth);
}
public String getSaslMechanism() {
return props.getProperty(SASL_MECHANISM);
}
public void setSaslMechanism(String saslMechanism) {
props.setProperty(SASL_MECHANISM, saslMechanism);
}
public String getAuthUsername() {
return props.getProperty(AUTH_USERNAME);
}
public void setAuthUsername(String authUsername) {
props.setProperty(AUTH_USERNAME, authUsername);
}
public String getAuthPassword() {
return props.getProperty(AUTH_PASSWORD);
}
public void setAuthPassword(String authPassword) {
props.setProperty(AUTH_PASSWORD, authPassword);
}
public String getAuthToken() {
return props.getProperty(AUTH_TOKEN);
}
public void setAuthToken(String authToken) {
props.setProperty(AUTH_TOKEN, authToken);
}
public String getAuthRealm() {
return props.getProperty(AUTH_REALM);
}
public void setAuthRealm(String authRealm) {
props.setProperty(AUTH_REALM, authRealm);
}
public void setAuthServerName(String authServerName) {
props.setProperty(AUTH_SERVER_NAME, authServerName);
}
public int getMaxRetries() {
return props.getIntProperty(MAX_RETRIES, DEFAULT_MAX_RETRIES);
}
public void setMaxRetries(int maxRetries) {
props.setProperty(MAX_RETRIES, maxRetries);
}
public int getBatchSize() {
return props.getIntProperty(BATCH_SIZE, DEFAULT_BATCH_SIZE);
}
public void setBatchSize(int batchSize) {
props.setProperty(BATCH_SIZE, batchSize);
}
public void setStatistics(boolean statistics) {
props.setProperty(STATISTICS, statistics);
}
public boolean isStatistics() {
return props.getBooleanProperty(STATISTICS, StatisticsConfiguration.ENABLED.getDefaultValue());
}
public void setJmx(boolean jmx) {
props.setProperty(JMX, jmx);
}
public boolean isJmx() {
return props.getBooleanProperty(JMX, StatisticsConfiguration.JMX_ENABLED.getDefaultValue());
}
public void setJmxName(String jmxName) {
props.setProperty(JMX_NAME, jmxName);
}
public void getJmxName() {
props.getProperty(JMX_NAME);
}
public void setJmxDomain(String jmxDomain) {
props.setProperty(JMX_DOMAIN, jmxDomain);
}
public void getJmxDomain() {
props.getProperty(JMX_DOMAIN);
}
public String getTransactionManagerLookup() {
return props.getProperty(TRANSACTION_MANAGER_LOOKUP, GenericTransactionManagerLookup.class.getName(), true);
}
public NearCacheMode getNearCacheMode() {
return props.getEnumProperty(NEAR_CACHE_MODE, NearCacheMode.class, NearCacheMode.DISABLED, true);
}
public void setNearCacheMode(String nearCacheMode) {
props.setProperty(NEAR_CACHE_MODE, nearCacheMode);
}
public int getNearCacheMaxEntries() {
return props.getIntProperty(NEAR_CACHE_MAX_ENTRIES, -1);
}
public void setNearCacheMaxEntries(int nearCacheMaxEntries) {
props.setProperty(NEAR_CACHE_MAX_ENTRIES, nearCacheMaxEntries);
}
public int getConnectionPoolMaxActive() {
return props.getIntProperty(CONNECTION_POOL_MAX_ACTIVE, DEFAULT_MAX_ACTIVE);
}
public void setConnectionPoolMaxActive(int connectionPoolMaxActive) {
props.setProperty(CONNECTION_POOL_MAX_ACTIVE, connectionPoolMaxActive);
}
public long getConnectionPoolMaxWait() {
return props.getLongProperty(CONNECTION_POOL_MAX_WAIT, DEFAULT_MAX_WAIT);
}
public void setConnectionPoolMaxWait(long connectionPoolMaxWait) {
props.setProperty(CONNECTION_POOL_MAX_WAIT, connectionPoolMaxWait);
}
public int gtConnectionPoolMinIdle() {
return props.getIntProperty(CONNECTION_POOL_MIN_IDLE, DEFAULT_MIN_IDLE);
}
public void setConnectionPoolMinIdle(int connectionPoolMinIdle) {
props.setProperty(CONNECTION_POOL_MIN_IDLE, connectionPoolMinIdle);
}
public int getConnectionPoolMaxPendingRequests() {
return props.getIntProperty(CONNECTION_POOL_MAX_PENDING_REQUESTS, DEFAULT_MAX_PENDING_REQUESTS);
}
public void setConnectionPoolMaxPendingRequests(int connectionPoolMaxPendingRequests) {
props.setProperty(CONNECTION_POOL_MAX_PENDING_REQUESTS, connectionPoolMaxPendingRequests);
}
public long setConnectionPoolMinEvictableIdleTime() {
return props.getLongProperty(CONNECTION_POOL_MIN_EVICTABLE_IDLE_TIME, DEFAULT_MIN_EVICTABLE_IDLE_TIME);
}
public void setConnectionPoolMinEvictableIdleTime(long connectionPoolMinEvictableIdleTime) {
props.setProperty(CONNECTION_POOL_MIN_EVICTABLE_IDLE_TIME, connectionPoolMinEvictableIdleTime);
}
public ExhaustedAction getConnectionPoolExhaustedAction() {
return props.getEnumProperty(CONNECTION_POOL_EXHAUSTED_ACTION, ExhaustedAction.class, ExhaustedAction.WAIT);
}
public void setConnectionPoolExhaustedAction(String connectionPoolExhaustedAction) {
props.setProperty(CONNECTION_POOL_EXHAUSTED_ACTION, connectionPoolExhaustedAction);
}
public boolean isTracingPropagationEnabled() {
return props.getBooleanProperty(TRACING_PROPAGATION_ENABLED, DEFAULT_TRACING_PROPAGATION_ENABLED);
}
public void setTracingPropagationEnabled(boolean tracingPropagationEnabled) {
props.setProperty(TRACING_PROPAGATION_ENABLED, tracingPropagationEnabled);
}
/**
* Is version previous to, and not including, 1.2?
*/
public static boolean isVersionPre12(HotRodConfiguration cfg) {
String version = cfg.version().toString();
return Objects.equals(version, "1.0") || Objects.equals(version, "1.1");
}
public String getServerList(){
return props.getProperty(SERVER_LIST);
}
/**
* @deprecated Use {@link #setJavaSerialAllowList(String)} instead. To be removed in 14.0.
* @param javaSerialWhitelist
*/
@Deprecated
public void setJavaSerialWhitelist(String javaSerialWhitelist) {
setJavaSerialAllowList(javaSerialWhitelist);
}
public void setJavaSerialAllowList(String javaSerialAllowlist) {
props.setProperty(JAVA_SERIAL_ALLOWLIST, javaSerialAllowlist);
}
public void setTransactionMode(String transactionMode) {
props.setProperty(TRANSACTION_MODE, transactionMode);
}
public String getTransactionMode() {
return props.getProperty(TRANSACTION_MODE);
}
public void setTransactionTimeout(int transactionTimeout) {
props.setProperty(TRANSACTION_TIMEOUT, transactionTimeout);
}
public int getTransactionTimeout() {
return props.getIntProperty(TRANSACTION_TIMEOUT, DEFAULT_SO_TIMEOUT);
}
}
| 22,007
| 36.944828
| 126
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/impl/HotRodURI.java
|
package org.infinispan.hotrod.impl;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.infinispan.hotrod.configuration.HotRodConfigurationBuilder;
import org.infinispan.hotrod.impl.logging.Log;
/**
* @since 14.0
**/
public class HotRodURI {
public static final String[] EMPTY_STRING_ARRAY = new String[0];
public static HotRodURI create(String uriString) {
return create(URI.create(uriString));
}
public static HotRodURI create(URI uri) {
if (!"hotrod".equals(uri.getScheme()) && !"hotrods".equals(uri.getScheme())) {
throw Log.HOTROD.notaHotRodURI(uri.toString());
}
final List<InetSocketAddress> addresses;
final String[] userInfo;
if (uri.getHost() != null) {
addresses = Collections.singletonList(InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort() < 0 ? ConfigurationProperties.DEFAULT_HOTROD_PORT : uri.getPort()));
userInfo = uri.getUserInfo() != null ? uri.getUserInfo().split(":") : EMPTY_STRING_ARRAY;
} else {
// We need to handle this by hand
String authority = uri.getAuthority();
final int at = authority.indexOf('@');
userInfo = at < 0 ? EMPTY_STRING_ARRAY : authority.substring(0, at).split(":");
String[] hosts = at < 0 ? authority.split(",") : authority.substring(at + 1).split(",");
addresses = new ArrayList<>(hosts.length);
for (String host : hosts) {
int colon = host.lastIndexOf(':');
addresses.add(InetSocketAddress.createUnresolved(colon < 0 ? host : host.substring(0, colon), colon < 0 ? ConfigurationProperties.DEFAULT_HOTROD_PORT : Integer.parseInt(host.substring(colon + 1))));
}
}
Properties properties = new Properties();
if (uri.getQuery() != null) {
String[] parts = uri.getQuery().split("&");
for (String part : parts) {
int eq = part.indexOf('=');
if (eq < 0) {
throw Log.HOTROD.invalidPropertyFormat(part);
} else {
properties.setProperty(ConfigurationProperties.ICH + part.substring(0, eq), part.substring(eq + 1));
}
}
}
return new HotRodURI(addresses, "hotrods".equals(uri.getScheme()), userInfo.length > 0 ? userInfo[0] : null, userInfo.length > 1 ? userInfo[1] : null, properties);
}
private final List<InetSocketAddress> addresses;
private final boolean ssl;
private final String username;
private final String password;
private final Properties properties;
private HotRodURI(List<InetSocketAddress> addresses, boolean ssl, String username, String password, Properties properties) {
this.addresses = addresses;
this.ssl = ssl;
this.username = username;
this.password = password;
this.properties = properties;
}
public List<InetSocketAddress> getAddresses() {
return addresses;
}
public boolean isSsl() {
return ssl;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public Properties getProperties() {
return properties;
}
public HotRodConfigurationBuilder toConfigurationBuilder() {
return toConfigurationBuilder(new HotRodConfigurationBuilder());
}
public HotRodConfigurationBuilder toConfigurationBuilder(HotRodConfigurationBuilder builder) {
for(InetSocketAddress address : addresses) {
builder.addServer().host(address.getHostString()).port(address.getPort());
}
if (ssl) {
builder.security().ssl().enable();
}
if (username != null) {
builder.security().authentication().username(username);
}
if (password != null) {
builder.security().authentication().password(password);
}
builder.withProperties(properties);
return builder;
}
@Override
public String toString() {
return "HotRodURI{" +
"addresses=" + addresses +
", ssl=" + ssl +
", username='" + username + '\'' +
", password='" + password + '\'' +
", properties=" + properties +
'}';
}
}
| 4,324
| 32.789063
| 210
|
java
|
null |
infinispan-main/client/hotrod/src/main/java/org/infinispan/hotrod/impl/DataFormat.java
|
package org.infinispan.hotrod.impl;
import static org.infinispan.hotrod.marshall.MarshallerUtil.bytes2obj;
import static org.infinispan.hotrod.marshall.MarshallerUtil.obj2bytes;
import org.infinispan.commons.configuration.ClassAllowList;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.marshall.AdaptiveBufferSizePredictor;
import org.infinispan.commons.marshall.BufferSizePredictor;
import org.infinispan.commons.marshall.IdentityMarshaller;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.util.Util;
import org.infinispan.hotrod.configuration.RemoteCacheConfiguration;
import org.infinispan.hotrod.impl.logging.Log;
import org.infinispan.hotrod.impl.logging.LogFactory;
/**
* Defines data format for keys and values during Hot Rod client requests.
*
* @since 9.3
*/
public final class DataFormat {
private static final Log log = LogFactory.getLog(DataFormat.class, Log.class);
private final MediaType keyType;
private final MediaType valueType;
private final Marshaller keyMarshaller;
private final Marshaller valueMarshaller;
private MarshallerRegistry marshallerRegistry;
private Marshaller defaultMarshaller;
private boolean isObjectStorage;
private final BufferSizePredictor keySizePredictor = new AdaptiveBufferSizePredictor();
private final BufferSizePredictor valueSizePredictor = new AdaptiveBufferSizePredictor();
private DataFormat(MediaType keyType, MediaType valueType, Marshaller keyMarshaller, Marshaller valueMarshaller) {
this.keyType = keyType;
this.valueType = valueType;
this.keyMarshaller = keyMarshaller;
this.valueMarshaller = valueMarshaller;
}
public DataFormat withoutValueType() {
DataFormat dataFormat = new DataFormat(keyType, null, keyMarshaller, null);
dataFormat.marshallerRegistry = this.marshallerRegistry;
dataFormat.defaultMarshaller = this.defaultMarshaller;
dataFormat.isObjectStorage = this.isObjectStorage;
return dataFormat;
}
public MediaType getKeyType() {
if (keyType != null) return keyType;
Marshaller marshaller = resolveKeyMarshaller();
return marshaller == null ? null : marshaller.mediaType();
}
public MediaType getValueType() {
if (valueType != null) return valueType;
Marshaller marshaller = resolveValueMarshaller();
return marshaller == null ? null : marshaller.mediaType();
}
public void initialize(HotRodTransport hotRodTransport, String cacheName, boolean serverObjectStorage) {
this.marshallerRegistry = hotRodTransport.getMarshallerRegistry();
this.isObjectStorage = serverObjectStorage;
this.defaultMarshaller = hotRodTransport.getMarshaller();
RemoteCacheConfiguration remoteCacheConfiguration = hotRodTransport.getConfiguration().remoteCaches().get(cacheName);
if (remoteCacheConfiguration != null) {
Marshaller cacheMarshaller = remoteCacheConfiguration.marshaller();
if (cacheMarshaller != null) {
defaultMarshaller = cacheMarshaller;
} else {
Class<? extends Marshaller> marshallerClass = remoteCacheConfiguration.marshallerClass();
if (marshallerClass != null) {
Marshaller registryMarshaller = marshallerRegistry.getMarshaller(marshallerClass);
defaultMarshaller = registryMarshaller != null ? registryMarshaller : Util.getInstance(marshallerClass);
}
}
}
}
private Marshaller resolveValueMarshaller() {
if (valueMarshaller != null) return valueMarshaller;
if (valueType == null) return defaultMarshaller;
Marshaller forValueType = marshallerRegistry.getMarshaller(valueType);
if (forValueType != null) return forValueType;
log.debugf("No marshaller registered for %s, using no-op marshaller", valueType);
return IdentityMarshaller.INSTANCE;
}
public boolean isObjectStorage() {
return isObjectStorage;
}
private Marshaller resolveKeyMarshaller() {
if (keyMarshaller != null) return keyMarshaller;
if (keyType == null) return defaultMarshaller;
Marshaller forKeyType = marshallerRegistry.getMarshaller(keyType);
if (forKeyType != null) return forKeyType;
log.debugf("No marshaller registered for %s, using no-op marshaller", keyType);
return IdentityMarshaller.INSTANCE;
}
public byte[] keyToBytes(Object key) {
Marshaller keyMarshaller = resolveKeyMarshaller();
return obj2bytes(keyMarshaller, key, keySizePredictor);
}
public byte[] valueToBytes(Object value) {
Marshaller valueMarshaller = resolveValueMarshaller();
return obj2bytes(valueMarshaller, value, valueSizePredictor);
}
public <T> T keyToObj(byte[] bytes, ClassAllowList allowList) {
Marshaller keyMarshaller = resolveKeyMarshaller();
return bytes2obj(keyMarshaller, bytes, isObjectStorage, allowList);
}
public <T> T valueToObj(byte[] bytes, ClassAllowList allowList) {
Marshaller valueMarshaller = resolveValueMarshaller();
return bytes2obj(valueMarshaller, bytes, isObjectStorage, allowList);
}
@Override
public String toString() {
return "DataFormat{" +
"keyType=" + keyType +
", valueType=" + valueType +
", keyMarshaller=" + keyMarshaller +
", valueMarshaller=" + valueMarshaller +
", marshallerRegistry=" + marshallerRegistry +
", defaultMarshaller=" + defaultMarshaller +
'}';
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private MediaType keyType;
private MediaType valueType;
private Marshaller valueMarshaller;
private Marshaller keyMarshaller;
public Builder from(DataFormat dataFormat) {
this.keyType = dataFormat.keyType;
this.valueType = dataFormat.valueType;
this.keyMarshaller = dataFormat.keyMarshaller;
this.valueMarshaller = dataFormat.valueMarshaller;
return this;
}
public Builder valueMarshaller(Marshaller valueMarshaller) {
this.valueMarshaller = valueMarshaller;
return this;
}
public Builder keyMarshaller(Marshaller keyMarshaller) {
this.keyMarshaller = keyMarshaller;
return this;
}
public Builder keyType(MediaType keyType) {
this.keyType = keyType;
return this;
}
public Builder valueType(MediaType valueType) {
this.valueType = valueType;
return this;
}
public DataFormat build() {
return new DataFormat(keyType, valueType, keyMarshaller, valueMarshaller);
}
}
}
| 6,788
| 35.304813
| 123
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.