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/api/src/main/java/org/infinispan/api/annotations/indexing/option/TermVector.java
|
package org.infinispan.api.annotations.indexing.option;
/**
* Defines the term vector storing strategy.
* <p>
* Simplified version for Infinispan of {@link org.hibernate.search.engine.backend.types.TermVector}
*
* @since 14.0
*/
public enum TermVector {
/**
* Store term vectors.
*/
YES,
/**
* Do not store term vectors.
*/
NO,
/**
* Store the term vectors. Also store token positions into the term.
*/
WITH_POSITIONS,
/**
* Store the term vectors. Also store token character offsets into the term.
*/
WITH_OFFSETS,
/**
* Store the term vectors. Also store token positions and token character offsets into the term.
*/
WITH_POSITIONS_OFFSETS,
/**
* Store the term vectors. Also store token positions and token payloads into the term.
*/
WITH_POSITIONS_PAYLOADS,
/**
* Store the term vectors. Also store token positions, token character offsets and token payloads into the term.
*/
WITH_POSITIONS_OFFSETS_PAYLOADS
}
| 1,028
| 20.4375
| 115
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/annotations/indexing/option/Structure.java
|
package org.infinispan.api.annotations.indexing.option;
/**
* Defines how the structure of an object field is preserved upon indexing.
* <p>
* Simplified version for Infinispan of {@link org.hibernate.search.engine.backend.types.ObjectStructure}
*
* @since 14.0
*/
public enum Structure {
/**
* Flatten multi-valued object fields.
* <p>
* This structure is generally more efficient,
* but has the disadvantage of dropping the original structure
* by making the leaf fields multi-valued instead of the object fields.
*/
FLATTENED,
/**
* Store object fields as nested documents.
* <p>
* This structure is generally less efficient,
* but has the advantage of preserving the original structure.
* Note however that access to that information when querying
* requires special care.
*/
NESTED
}
| 863
| 26
| 105
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/annotations/indexing/model/Values.java
|
package org.infinispan.api.annotations.indexing.model;
public final class Values {
/**
* This special value is reserved to not index the null value, that is the default behaviour.
*/
public static final String DO_NOT_INDEX_NULL = "__Infinispan_indexNullAs_doNotIndexNull";
private Values() {
}
}
| 320
| 21.928571
| 96
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/annotations/indexing/model/Point.java
|
package org.infinispan.api.annotations.indexing.model;
/**
* A point in the geocentric coordinate system.
* <p>
* Simplified version for Infinispan of {@link org.hibernate.search.engine.spatial.GeoPoint}
*
* @since 14.0
*/
public final class Point {
static Point of(double latitude, double longitude) {
return new Point(latitude, longitude);
}
private final double latitude;
private final double longitude;
public Point(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
/**
* @return the latitude, in degrees
*/
public double latitude() {
return latitude;
}
/**
* @return the longitude, in degrees
*/
public double longitude() {
return longitude;
}
}
| 788
| 19.763158
| 92
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/exception/InfinispanException.java
|
package org.infinispan.api.exception;
/**
* InfinispanException is raised when any runtime error not related to configuration is raised. It wraps the underlying
* exception/error.
*
* @since 14.0
*/
public class InfinispanException extends RuntimeException {
public InfinispanException(String message) {
super(message);
}
public InfinispanException(String message, Throwable throwable) {
super(message, throwable);
}
}
| 450
| 24.055556
| 119
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/exception/InfinispanConfigurationException.java
|
package org.infinispan.api.exception;
/**
* Exception raised when a configuration error is found
*
* @since 14.0
*/
public class InfinispanConfigurationException extends InfinispanException {
public InfinispanConfigurationException(String message) {
super(message);
}
}
| 287
| 21.153846
| 75
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncStrongCounter.java
|
package org.infinispan.api.sync;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.infinispan.api.common.events.counter.CounterEvent;
import org.infinispan.api.configuration.CounterConfiguration;
/**
* @since 14.0
*/
public interface SyncStrongCounter {
String name();
/**
* Return the container of this counter
*
* @return
*/
SyncContainer container();
/**
* It fetches the current value.
* <p>
* It may go remotely to fetch the current value.
*
* @return The current value.
*/
long value();
/**
* Atomically increments the counter and returns the new value.
*
* @return The new value.
*/
default long incrementAndGet() {
return addAndGet(1L);
}
/**
* Atomically decrements the counter and returns the new value
*
* @return The new value.
*/
default long decrementAndGet() {
return addAndGet(-1L);
}
/**
* Atomically adds the given value and return the new value.
*
* @param delta The non-zero value to add. It can be negative.
* @return The new value.
*/
long addAndGet(long delta);
/**
* Resets the counter to its initial value.
*/
CompletableFuture<Void> reset();
/**
* Registers a {@link Consumer<CounterEvent>} to this counter.
*
* @param listener The listener to register.
* @return A {@link AutoCloseable} that allows to remove the listener via {@link AutoCloseable#close()}.
*/
AutoCloseable listen(Consumer<CounterEvent> listener);
/**
* Atomically sets the value to the given updated value if the current value {@code ==} the expected value.
* <p>
* It is the same as {@code return compareAndSwap(expect, update).thenApply(value -> value == expect);}
*
* @param expect the expected value
* @param update the new value
* @return {@code true} if successful, {@code false} otherwise.
*/
default boolean compareAndSet(long expect, long update) {
return compareAndSwap(expect, update) == expect;
}
/**
* Atomically sets the value to the given updated value if the current value {@code ==} the expected value.
* <p>
* The operation is successful if the return value is equals to the expected value.
*
* @param expect the expected value.
* @param update the new value.
* @return the previous counter's value.
*/
long compareAndSwap(long expect, long update);
/**
* Atomically sets the value to the given updated value
*
* @param value the new value.
* @return the old value of counter.
*/
long getAndSet(long value);
/**
* @return the {@link CounterConfiguration} used by this counter.
*/
CounterConfiguration configuration();
}
| 2,804
| 24.5
| 110
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncContainer.java
|
package org.infinispan.api.sync;
import java.util.function.Function;
import org.infinispan.api.Infinispan;
import org.infinispan.api.common.events.container.ContainerListenerEventType;
import org.infinispan.api.sync.events.container.SyncContainerListener;
/**
* @since 14.0
**/
public interface SyncContainer extends Infinispan {
SyncCaches caches();
SyncMultimaps multimaps();
SyncStrongCounters strongCounters();
SyncWeakCounters weakCounters();
SyncLocks locks();
void listen(SyncContainerListener listener, ContainerListenerEventType... types);
<T> T batch(Function<SyncContainer, T> function);
}
| 634
| 21.678571
| 84
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncCaches.java
|
package org.infinispan.api.sync;
import org.infinispan.api.configuration.CacheConfiguration;
/**
* @since 14.0
**/
public interface SyncCaches {
/**
* Obtains an existing cache
*
* @param name the name of the cache
* @param <K> the type of the key
* @param <V> the type of the value
* @return
*/
<K, V> SyncCache<K, V> get(String name);
/**
* @param name the name of the cache
* @param cacheConfiguration
* @param <K> the type of the key
* @param <V> the type of the value
* @return
*/
<K, V> SyncCache<K, V> create(String name, CacheConfiguration cacheConfiguration);
/**
* Creates a cache using the supplied template name
*
* @param name the name of the cache
* @param template the name of an existing template
* @param <K> the type of the key
* @param <V> the type of the value
* @return
*/
<K, V> SyncCache<K, V> create(String name, String template);
/**
* Removes a cache
*
* @param name the name of the cache to be removed
*/
void remove(String name);
/**
* Retrieves the names of all available caches
*
* @return
*/
Iterable<String> names();
/**
* Creates a cache template
*
* @param name the name of the template
* @param cacheConfiguration the configuration of the template
*/
void createTemplate(String name, CacheConfiguration cacheConfiguration);
/**
* Removes a cache template
*
* @param name the name of the template to be removed
*/
void removeTemplate(String name);
/**
* Returns the names of all available templates
*
* @return
*/
Iterable<String> templateNames();
}
| 1,785
| 22.813333
| 85
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncStreamingCache.java
|
package org.infinispan.api.sync;
import java.io.InputStream;
import java.io.OutputStream;
import org.infinispan.api.common.CacheEntryMetadata;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.CacheWriteOptions;
/**
* SyncStreamingCache implements streaming versions of most {@link SyncCache} methods
*
* @since 14.0
*/
public interface SyncStreamingCache<K> {
/**
* Retrieves the value of the specified key as an {@link InputStream}. It is up to the application to ensure that the
* stream is consumed and closed. The marshaller is ignored, i.e. all data will be read in its raw binary form. The
* returned input stream implements the {@link CacheEntryMetadata} interface. The returned input stream is not
* thread-safe.
*
* @param key key to use
*/
default <T extends InputStream & CacheEntryMetadata> T get(K key) {
return get(key, CacheOptions.DEFAULT);
}
/**
* Retrieves the value of the specified key as an {@link InputStream}. It is up to the application to ensure that the
* stream is consumed and closed. The marshaller is ignored, i.e. all data will be read in its raw binary form. The
* returned input stream implements the {@link CacheEntryMetadata} interface. The returned input stream is not
* thread-safe.
*
* @param key key to use
*/
<T extends InputStream & CacheEntryMetadata> T get(K key, CacheOptions options);
/**
* Initiates a streaming put operation. It is up to the application to write to the returned {@link OutputStream} and
* close it when there is no more data to write. The marshaller is ignored, i.e. all data will be written in its raw
* binary form. The returned output stream is not thread-safe.
*
* @param key key to use
*/
default OutputStream put(K key) {
return put(key, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param options
* @return
*/
OutputStream put(K key, CacheOptions options);
/**
* A conditional form of put which inserts an entry into the cache only if no mapping for the key is already present.
* The operation is atomic. The server only performs the operation once the stream has been closed. The returned
* output stream is not thread-safe.
*
* @param key key to use
*/
default OutputStream putIfAbsent(K key) {
return putIfAbsent(key, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param options
* @return
*/
OutputStream putIfAbsent(K key, CacheWriteOptions options);
}
| 2,577
| 33.837838
| 120
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncWeakCounter.java
|
package org.infinispan.api.sync;
/**
* @since 14.0
**/
public interface SyncWeakCounter {
/**
* Returns the name of this counter
*
* @return the name of this counter
*/
String name();
/**
* Return the container of this cache
*
* @return
*/
SyncContainer container();
long value();
/**
* Increments the counter.
*/
default void increment() {
add(1L);
}
/**
* Decrements the counter.
*/
default void decrement() {
add(-1L);
}
/**
* Adds the given value to the new value.
*
* @param delta the value to add.
*/
void add(long delta);
}
| 654
| 13.886364
| 44
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncQuery.java
|
package org.infinispan.api.sync;
import java.util.Map;
import org.infinispan.api.common.process.CacheProcessor;
import org.infinispan.api.common.process.CacheProcessorOptions;
import org.infinispan.api.sync.events.cache.SyncCacheContinuousQueryListener;
/**
* Parameterized Query builder
*
* @param <K>
* @param <V>
* @param <R> the result type for the query
*/
public interface SyncQuery<K, V, R> {
/**
* Sets the named parameter to the specified value
*
* @param name
* @param value
* @return
*/
SyncQuery<K, V, R> param(String name, Object value);
/**
* Skips the first specified number of results
*
* @param skip
* @return
*/
SyncQuery<K, V, R> skip(long skip);
/**
* Limits the number of results
*
* @param limit
* @return
*/
SyncQuery<K, V, R> limit(int limit);
/**
* Executes the query
*/
SyncQueryResult<R> find();
/**
* Continuously listen on query
*
* @param listener
* @param <R>
* @return A {@link AutoCloseable} that allows to remove the listener via {@link AutoCloseable#close()}.
*/
<R> AutoCloseable findContinuously(SyncCacheContinuousQueryListener<K, V> listener);
/**
* Executes the manipulation statement (UPDATE, REMOVE)
*
* @return the number of entries that were processed
*/
int execute();
/**
* Processes entries using an {@link SyncCacheEntryProcessor}. If the cache is embedded, the consumer will be executed
* locally on the owner of the entry. If the cache is remote, entries will be retrieved, manipulated locally and put
* back. The query <b>MUST NOT</b> use projections.
*
* @param processor the entry processor
*/
default <T> Map<K, T> process(SyncCacheEntryProcessor<K, V, T> processor) {
return process(processor, CacheProcessorOptions.DEFAULT);
}
/**
* Processes entries using a {@link SyncCacheEntryProcessor}. If the cache is embedded, the consumer will be executed
* locally on the owner of the entry. If the cache is remote, entries will be retrieved, manipulated locally and put
* back. The query <b>MUST NOT</b> use projections.
*
* @param <T>
* @param processor the entry processor
* @param options
*/
<T> Map<K, T> process(SyncCacheEntryProcessor<K, V, T> processor, CacheProcessorOptions options);
/**
* Processes entries matched by the query using a named {@link CacheProcessor}. The query <b>MUST NOT</b> use projections.
* If the cache processor returns a non-null value for an entry, it will be returned as an entry of a {@link Map}.
*
* @param processor the entry processor
* @return
*/
default <T> Map<K, T> process(CacheProcessor processor) {
return process(processor, CacheProcessorOptions.DEFAULT);
}
/**
* Processes entries matched by the query using a named {@link CacheProcessor}. The query <b>MUST NOT</b> use projections.
* If the cache processor returns a non-null value for an entry, it will be returned as an entry of a {@link Map}.
*
* @param <T>
* @param processor the named entry processor
* @param options
* @return
*/
<T> Map<K, T> process(CacheProcessor processor, CacheProcessorOptions options);
}
| 3,287
| 29.728972
| 125
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncMultimap.java
|
package org.infinispan.api.sync;
import org.infinispan.api.common.CloseableIterable;
import org.infinispan.api.configuration.MultimapConfiguration;
/**
* @param <K>
* @param <V>
* @since 14.0
*/
public interface SyncMultimap<K, V> {
String name();
MultimapConfiguration configuration();
/**
* Return the container of this multimap
*
* @return
*/
SyncContainer container();
void add(K key, V value);
CloseableIterable<V> get(K key);
boolean remove(K key);
boolean remove(K key, V value);
boolean containsKey(K key);
boolean containsEntry(K key, V value);
long estimateSize();
}
| 642
| 15.921053
| 62
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncQueryResult.java
|
package org.infinispan.api.sync;
import java.util.OptionalLong;
import org.infinispan.api.common.CloseableIterable;
/**
* @since 14.0
**/
public interface SyncQueryResult<R> extends AutoCloseable {
OptionalLong hitCount();
CloseableIterable<R> results();
void close();
}
| 287
| 15.941176
| 59
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncCache.java
|
package org.infinispan.api.sync;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.infinispan.api.common.CacheEntry;
import org.infinispan.api.common.CacheEntryVersion;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.CacheWriteOptions;
import org.infinispan.api.common.CloseableIterable;
import org.infinispan.api.common.process.CacheEntryProcessorResult;
import org.infinispan.api.common.process.CacheProcessorOptions;
import org.infinispan.api.configuration.CacheConfiguration;
import org.infinispan.api.sync.events.cache.SyncCacheEntryListener;
/**
* @since 14.0
**/
public interface SyncCache<K, V> {
/**
* Returns the name of this cache
*
* @return the name of the cache
*/
String name();
/**
* Returns the configuration of this cache
*
* @return the cache configuration
*/
CacheConfiguration configuration();
/**
* Return the container of this cache
*
* @return the cache container
*/
SyncContainer container();
/**
* Get the value of the Key if such exists
*
* @param key
* @return the value
*/
default V get(K key) {
return get(key, CacheOptions.DEFAULT);
}
/**
* Get the value of the Key if such exists
*
* @param key
* @return the value
*/
default V get(K key, CacheOptions options) {
CacheEntry<K, V> entry = getEntry(key, options);
return entry == null ? null : entry.value();
}
/**
* Get the entry of the Key if such exists
*
* @param key
* @return the entry
*/
default CacheEntry<K, V> getEntry(K key) {
return getEntry(key, CacheOptions.DEFAULT);
}
/**
* Get the entry of the Key if such exists
*
* @param key
* @param options
* @return the entry
*/
CacheEntry<K, V> getEntry(K key, CacheOptions options);
/**
* Insert the key/value pair. Returns the previous value if present.
*
* @param key
* @param value
* @return Void
*/
default CacheEntry<K, V> put(K key, V value) {
return put(key, value, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return Void
*/
CacheEntry<K, V> put(K key, V value, CacheWriteOptions options);
/**
* Similar to {@link #put(Object, Object)} but does not return the previous value.
*/
default void set(K key, V value) {
set(key, value, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return
*/
default void set(K key, V value, CacheWriteOptions options) {
put(key, value, options);
}
/**
* Save the key/value.
*
* @param key
* @param value
* @return the previous value if present
*/
default CacheEntry<K, V> putIfAbsent(K key, V value) {
return putIfAbsent(key, value, CacheWriteOptions.DEFAULT);
}
/**
* Insert the key/value if such key does not exist
*
* @param key
* @param value
* @param options
* @return the previous value if present
*/
CacheEntry<K, V> putIfAbsent(K key, V value, CacheWriteOptions options);
/**
* Save the key/value.
*
* @param key
* @param value
* @return true if the entry was set
*/
default boolean setIfAbsent(K key, V value) {
return setIfAbsent(key, value, CacheWriteOptions.DEFAULT);
}
/**
* Insert the key/value if such key does not exist
*
* @param key
* @param value
* @param options
* @return Void
*/
default boolean setIfAbsent(K key, V value, CacheWriteOptions options) {
CacheEntry<K, V> ce = putIfAbsent(key, value, options);
return ce == null;
}
/**
* @param key
* @param value
* @return
*/
default boolean replace(K key, V value, CacheEntryVersion version) {
return replace(key, value, version, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return
*/
default boolean replace(K key, V value, CacheEntryVersion version, CacheWriteOptions options) {
CacheEntry<K, V> ce = getOrReplaceEntry(key, value, version, options);
return ce != null && version.equals(ce.metadata().version());
}
/**
* @param key
* @param value
* @param version
* @return
*/
default CacheEntry<K, V> getOrReplaceEntry(K key, V value, CacheEntryVersion version) {
return getOrReplaceEntry(key, value, version, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @param version
* @return
*/
CacheEntry<K, V> getOrReplaceEntry(K key, V value, CacheEntryVersion version, CacheWriteOptions options);
/**
* Delete the key
*
* @param key
* @return true if the entry was removed
*/
default boolean remove(K key) {
return remove(key, CacheOptions.DEFAULT);
}
/**
* Delete the key
*
* @param key
* @param options
* @return true if the entry was removed
*/
default boolean remove(K key, CacheOptions options) {
CacheEntry<K, V> ce = getAndRemove(key, options);
return ce != null;
}
/**
* Delete the key only if the version matches
*
* @param key
* @param version
* @return whether the entry was removed.
*/
default boolean remove(K key, CacheEntryVersion version) {
return remove(key, version, CacheOptions.DEFAULT);
}
/**
* Delete the key only if the version matches
*
* @param key
* @param version
* @param options
* @return whether the entry was removed.
*/
boolean remove(K key, CacheEntryVersion version, CacheOptions options);
/**
* Removes the key and returns its value if present.
*
* @param key
* @return the value of the key before removal. Returns null if the key didn't exist.
*/
default CacheEntry<K, V> getAndRemove(K key) {
return getAndRemove(key, CacheOptions.DEFAULT);
}
/**
* Removes the key and returns its value if present.
*
* @param key
* @param options
* @return the value of the key before removal. Returns null if the key didn't exist.
*/
CacheEntry<K, V> getAndRemove(K key, CacheOptions options);
/**
* Retrieve all keys
*
* @return
*/
default CloseableIterable<K> keys() {
return keys(CacheOptions.DEFAULT);
}
/**
* Retrieve all keys
*
* @param options
* @return
*/
CloseableIterable<K> keys(CacheOptions options);
/**
* Retrieve all entries
*
* @return
*/
default CloseableIterable<CacheEntry<K, V>> entries() {
return entries(CacheOptions.DEFAULT);
}
/**
* Retrieve all entries
*
* @param options
* @return
*/
CloseableIterable<CacheEntry<K, V>> entries(CacheOptions options);
/**
* Puts all entries
*
* @param entries
* @return Void
*/
default void putAll(Map<K, V> entries) {
putAll(entries, CacheWriteOptions.DEFAULT);
}
/**
* @param entries
* @param options
*/
void putAll(Map<K, V> entries, CacheWriteOptions options);
/**
* Retrieves all entries for the supplied keys
*
* @param keys
* @return
*/
default Map<K, V> getAll(Set<K> keys) {
return getAll(keys, CacheOptions.DEFAULT);
}
/**
* Retrieves all entries for the supplied keys
*
* @param keys
* @param options
* @return
*/
Map<K, V> getAll(Set<K> keys, CacheOptions options);
/**
* Retrieves all entries for the supplied keys
*
* @param keys
* @return
*/
default Map<K, V> getAll(K... keys) {
return getAll(CacheOptions.DEFAULT, keys);
}
/**
* Retrieves all entries for the supplied keys
*
* @param keys
* @param options
* @return
*/
Map<K, V> getAll(CacheOptions options, K... keys);
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @return
*/
default Set<K> removeAll(Set<K> keys) {
return removeAll(keys, CacheWriteOptions.DEFAULT);
}
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @param options
* @return
*/
Set<K> removeAll(Set<K> keys, CacheWriteOptions options);
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @return
*/
default Map<K, CacheEntry<K, V>> getAndRemoveAll(Set<K> keys) {
return getAndRemoveAll(keys, CacheWriteOptions.DEFAULT);
}
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @return
*/
default Map<K, CacheEntry<K, V>> getAndRemoveAll(Set<K> keys, CacheWriteOptions options) {
Map<K, CacheEntry<K, V>> map = new HashMap<>(keys.size());
for (K key : keys) {
map.put(key, getAndRemove(key));
}
return map;
}
/**
* Estimate the size of the store
*
* @return Long, estimated size
*/
default long estimateSize() {
return estimateSize(CacheOptions.DEFAULT);
}
/**
* Estimate the size of the store
*
* @return Long, estimated size
*/
long estimateSize(CacheOptions options);
/**
* Clear the store. If a concurrent operation puts data in the store the clear might not properly work.
*/
default void clear() {
clear(CacheOptions.DEFAULT);
}
/**
* Clear the store. If a concurrent operation puts data in the store the clear might not properly work.
*/
void clear(CacheOptions options);
/**
* Find by query
*
* @param query
* @return
*/
default <R> SyncQuery<K, V, R> query(String query) {
return query(query, CacheOptions.DEFAULT);
}
/**
* Find by query
*
* @param query
* @param options
* @param <R>
* @return
*/
<R> SyncQuery<K, V, R> query(String query, CacheOptions options);
/**
* Listens to the {@link SyncCacheEntryListener}
*
* @param listener
* @return A {@link AutoCloseable} that allows to remove the listener via {@link AutoCloseable#close()}.
*/
AutoCloseable listen(SyncCacheEntryListener<K, V> listener);
/**
* Process entries using the supplied processor
*
* @param <T>
* @param keys
* @param processor
*/
default <T> Set<CacheEntryProcessorResult<K, T>> process(Set<K> keys, SyncCacheEntryProcessor<K, V, T> processor) {
return process(keys, processor, CacheProcessorOptions.DEFAULT);
}
/**
* Process entries using the supplied processor
*
* @param <T>
* @param keys
* @param processor
* @param options
*/
<T> Set<CacheEntryProcessorResult<K, T>> process(Set<K> keys, SyncCacheEntryProcessor<K, V, T> processor, CacheProcessorOptions options);
/**
* Process entries using the supplied processor
*
* @param <T>
* @param processor
*/
default <T> Set<CacheEntryProcessorResult<K, T>> processAll(SyncCacheEntryProcessor<K, V, T> processor) {
return processAll(processor, CacheProcessorOptions.DEFAULT);
}
/**
* Process entries using the supplied processor
*
* @param <T>
* @param processor
* @param options
*/
<T> Set<CacheEntryProcessorResult<K, T>> processAll(SyncCacheEntryProcessor<K, V, T> processor, CacheProcessorOptions options);
/**
* @return
*/
SyncStreamingCache<K> streaming();
}
| 11,590
| 22.321932
| 140
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncMultimaps.java
|
package org.infinispan.api.sync;
import org.infinispan.api.common.CloseableIterable;
import org.infinispan.api.configuration.MultimapConfiguration;
/**
* @since 14.0
**/
public interface SyncMultimaps {
<K, V> SyncMultimap<K, V> get(String name);
<K, V> SyncMultimap<K, V> create(String name, MultimapConfiguration cacheConfiguration);
<K, V> SyncMultimap<K, V> create(String name, String template);
void remove(String name);
CloseableIterable<String> names();
void createTemplate(String name, MultimapConfiguration cacheConfiguration);
void removeTemplate(String name);
CloseableIterable<String> templateNames();
}
| 651
| 24.076923
| 91
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncCacheEntryProcessor.java
|
package org.infinispan.api.sync;
import org.infinispan.api.common.MutableCacheEntry;
import org.infinispan.api.common.process.CacheEntryProcessorContext;
/**
* @since 14.0
**/
@FunctionalInterface
public interface SyncCacheEntryProcessor<K, V, T> {
T process(MutableCacheEntry<K, V> entry, CacheEntryProcessorContext context);
}
| 336
| 24.923077
| 80
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncStrongCounters.java
|
package org.infinispan.api.sync;
import org.infinispan.api.configuration.CounterConfiguration;
/**
* @since 14.0
**/
public interface SyncStrongCounters {
SyncStrongCounter get(String name);
SyncStrongCounter create(String name, CounterConfiguration counterConfiguration);
void remove(String name);
Iterable<String> names();
}
| 346
| 19.411765
| 84
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncLocks.java
|
package org.infinispan.api.sync;
import org.infinispan.api.common.CloseableIterable;
import org.infinispan.api.configuration.LockConfiguration;
/**
* @since 14.0
**/
public interface SyncLocks {
SyncLock create(String name, LockConfiguration configuration);
SyncLock get(String name);
void remove(String name);
CloseableIterable<String> names();
}
| 367
| 19.444444
| 65
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncLock.java
|
package org.infinispan.api.sync;
import java.util.concurrent.TimeUnit;
/**
* @since 14.0
**/
public interface SyncLock {
String name();
/**
* Return the container of this lock
*
* @return
*/
SyncContainer container();
void lock();
boolean tryLock();
boolean tryLock(long time, TimeUnit unit);
void unlock();
boolean isLocked();
boolean isLockedByMe();
}
| 409
| 12.225806
| 45
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/SyncWeakCounters.java
|
package org.infinispan.api.sync;
import org.infinispan.api.configuration.CounterConfiguration;
/**
* @since 14.0
**/
public interface SyncWeakCounters {
SyncWeakCounter get(String name);
SyncWeakCounter create(String name, CounterConfiguration counterConfiguration);
void remove(String name);
Iterable<String> names();
}
| 340
| 19.058824
| 82
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerListener.java
|
package org.infinispan.api.sync.events.container;
/**
* @since 14.0
**/
public interface SyncContainerListener {
}
| 118
| 13.875
| 49
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryRemovedListener.java
|
package org.infinispan.api.sync.events.cache;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
/**
* @since 14.0
**/
public interface SyncCacheEntryRemovedListener<K, V> extends SyncCacheEntryListener<K, V> {
void onRemove(CacheEntryEvent<K, V> event);
}
| 276
| 24.181818
| 91
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryListener.java
|
package org.infinispan.api.sync.events.cache;
/**
* @since 14.0
*/
public interface SyncCacheEntryListener<K, V> {
}
| 120
| 14.125
| 47
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryExpiredListener.java
|
package org.infinispan.api.sync.events.cache;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
/**
* @since 14.0
**/
public interface SyncCacheEntryExpiredListener<K, V> extends SyncCacheEntryListener<K, V> {
void onExpired(CacheEntryEvent<K, V> event);
}
| 277
| 24.272727
| 91
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryUpdatedListener.java
|
package org.infinispan.api.sync.events.cache;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
/**
* @since 14.0
**/
public interface SyncCacheEntryUpdatedListener<K, V> extends SyncCacheEntryListener<K, V> {
void onUpdate(CacheEntryEvent<K, V> event);
}
| 276
| 24.181818
| 91
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheContinuousQueryListener.java
|
package org.infinispan.api.sync.events.cache;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
/**
* @since 14.0
**/
public interface SyncCacheContinuousQueryListener<K, V> extends SyncCacheEntryListener<K, V> {
default void onJoin(CacheEntryEvent<K, V> event) {
}
default void onLeave(CacheEntryEvent<K, V> event) {
}
default void onUpdate(CacheEntryEvent<K, V> event) {
}
}
| 414
| 22.055556
| 94
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryCreatedListener.java
|
package org.infinispan.api.sync.events.cache;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
/**
* @since 14.0
**/
public interface SyncCacheEntryCreatedListener<K, V> extends SyncCacheEntryListener<K, V> {
void onCreate(CacheEntryEvent<K, V> event);
}
| 276
| 24.181818
| 91
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/protostream/builder/FieldBuilder.java
|
package org.infinispan.api.protostream.builder;
public class FieldBuilder {
private final MessageBuilder parent;
private String name;
private final int number;
private final boolean required;
private final String type;
private IndexedFieldBuilder indexing = null;
private boolean indexEmbedded = false;
public FieldBuilder(MessageBuilder parent, String name, int number, boolean required, String type) {
this.parent = parent;
this.name = name;
this.number = number;
this.required = required;
this.type = type;
}
public MessageBuilder message(String name) {
return parent.parent.message(name);
}
public FieldBuilder required(String name, int number, String type) {
return parent.required(name, number, type);
}
public FieldBuilder optional(String name, int number, String type) {
return parent.optional(name, number, type);
}
public IndexedFieldBuilder basic() {
indexing = new IndexedFieldBuilder(this, "@Basic");
return indexing;
}
public IndexedFieldBuilder keyword() {
indexing = new IndexedFieldBuilder(this, "@Keyword");
return indexing;
}
public IndexedFieldBuilder text() {
indexing = new IndexedFieldBuilder(this, "@Text");
return indexing;
}
public FieldBuilder embedded() {
indexEmbedded = true;
return this;
}
public String build() {
return parent.build();
}
void write(StringBuilder builder) {
if (indexing != null) {
indexing.write(builder);
} else if (indexEmbedded) {
ProtoBuf.tab(builder);
builder.append("/**\n");
ProtoBuf.tab(builder);
builder.append(" * @Embedded\n");
ProtoBuf.tab(builder);
builder.append(" */\n");
}
// optional string name = 1;\n" +
if (required) {
ProtoBuf.tab(builder);
builder.append("required ");
} else {
ProtoBuf.tab(builder);
builder.append("optional ");
}
builder.append(type);
builder.append(" ");
builder.append(name);
builder.append(" = ");
builder.append(number);
builder.append(";");
ProtoBuf.blankLine(builder);
}
}
| 2,250
| 24.579545
| 103
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/protostream/builder/MessageBuilder.java
|
package org.infinispan.api.protostream.builder;
import java.util.ArrayList;
import java.util.List;
public class MessageBuilder {
final ProtoBuf parent;
private final String name;
private final List<FieldBuilder> fields = new ArrayList<>();
private boolean indexed = false;
public MessageBuilder(ProtoBuf parent, String name) {
this.parent = parent;
this.name = name;
}
public MessageBuilder indexed() {
indexed = true;
return this;
}
public FieldBuilder required(String name, int number, String type) {
FieldBuilder field = new FieldBuilder(this, name, number, true, type);
fields.add(field);
return field;
}
public FieldBuilder optional(String name, int number, String type) {
FieldBuilder field = new FieldBuilder(this, name, number, false, type);
fields.add(field);
return field;
}
public String build() {
return parent.build();
}
void write(StringBuilder builder) {
if (indexed) {
builder.append("/**\n");
builder.append(" * @Indexed\n");
builder.append(" */\n");
}
builder.append("message ");
builder.append(name);
builder.append(" {");
ProtoBuf.blankLine(builder);
for (FieldBuilder field : fields) {
field.write(builder);
}
builder.append("}");
ProtoBuf.blankLine(builder);
}
}
| 1,408
| 22.483333
| 77
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/protostream/builder/IndexedFieldBuilder.java
|
package org.infinispan.api.protostream.builder;
public class IndexedFieldBuilder {
private final FieldBuilder parent;
// TODO ISPN-14724 Create subclasses for each indexing type
// So that we can limit the options here accordingly.
private final String indexing;
private boolean custom = false;
private Boolean searchable;
private Boolean sortable;
private Boolean projectable;
private Boolean aggregable;
private String indexNullAs;
private String analyzer;
private String searchAnalyzer;
private String normalizer;
public IndexedFieldBuilder(FieldBuilder parent, String indexing) {
this.parent = parent;
this.indexing = indexing;
}
public MessageBuilder message(String name) {
return parent.message(name);
}
public FieldBuilder required(String name, int number, String type) {
return parent.required(name, number, type);
}
public FieldBuilder optional(String name, int number, String type) {
return parent.optional(name, number, type);
}
public IndexedFieldBuilder searchable(boolean value) {
custom = true;
this.searchable = value;
return this;
}
public IndexedFieldBuilder sortable(boolean value) {
custom = true;
this.sortable = value;
return this;
}
public IndexedFieldBuilder projectable(boolean value) {
custom = true;
this.projectable = value;
return this;
}
public IndexedFieldBuilder aggregable(boolean value) {
custom = true;
this.aggregable = value;
return this;
}
public IndexedFieldBuilder indexNullAs(String value) {
custom = true;
this.indexNullAs = value;
return this;
}
public IndexedFieldBuilder analyzer(String value) {
custom = true;
this.analyzer = value;
return this;
}
public IndexedFieldBuilder searchAnalyzer(String value) {
custom = true;
this.searchAnalyzer = value;
return this;
}
public IndexedFieldBuilder normalizer(String value) {
custom = true;
this.normalizer = value;
return this;
}
void write(StringBuilder builder) {
ProtoBuf.tab(builder);
builder.append("/**\n");
ProtoBuf.tab(builder);
builder.append(" * ");
builder.append(indexing);
writeCustomization(builder);
builder.append("\n");
ProtoBuf.tab(builder);
builder.append(" */\n");
}
private void writeCustomization(StringBuilder builder) {
if (!custom) {
return;
}
builder.append("(");
boolean first = true;
if (searchable != null) {
writeAttribute(builder, "searchable", searchable, first);
first = false;
}
if (sortable != null) {
writeAttribute(builder, "sortable", sortable, first);
first = false;
}
if (projectable != null) {
writeAttribute(builder, "projectable", projectable, first);
first = false;
}
if (aggregable != null) {
writeAttribute(builder, "aggregable", aggregable, first);
first = false;
}
if (indexNullAs != null) {
writeAttribute(builder, "indexNullAs", indexNullAs, first);
first = false;
}
if (analyzer != null) {
writeAttribute(builder, "analyzer", analyzer, first);
first = false;
}
if (searchAnalyzer != null) {
writeAttribute(builder, "searchAnalyzer", searchAnalyzer, first);
first = false;
}
if (normalizer != null) {
writeAttribute(builder, "normalizer", normalizer, first);
}
builder.append(")");
}
private void writeAttribute(StringBuilder builder, String attribute, Object value, boolean first) {
if (!first) {
builder.append(", ");
}
builder.append(attribute);
builder.append("=");
if (value instanceof String) {
value = "\"" + value + "\"";
}
builder.append(value);
}
}
| 4,014
| 24.573248
| 102
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/protostream/builder/ProtoBuf.java
|
package org.infinispan.api.protostream.builder;
import java.util.ArrayList;
import java.util.List;
public final class ProtoBuf {
public static ProtoBuf builder() {
return new ProtoBuf();
}
private final List<MessageBuilder> messages = new ArrayList<>();
private String packageName;
private ProtoBuf() {
}
public ProtoBuf packageName(String packageName) {
this.packageName = packageName;
return this;
}
public MessageBuilder message(String name) {
MessageBuilder message = new MessageBuilder(this, name);
messages.add(message);
return message;
}
public String build() {
StringBuilder builder = new StringBuilder();
builder.append("syntax = \"proto2\";");
ProtoBuf.blankLine(builder);
if (packageName != null && !packageName.isBlank()) {
builder.append("package ");
builder.append(packageName);
builder.append(";");
ProtoBuf.blankLine(builder);
}
for (MessageBuilder message : messages) {
message.write(builder);
}
return builder.toString();
}
static void blankLine(StringBuilder builder) {
builder.append("\n\n");
}
static void tab(StringBuilder builder) {
builder.append(" ");
}
}
| 1,283
| 22.345455
| 67
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyQuery.java
|
package org.infinispan.api.mutiny;
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 io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* Parameterized Query builder
*
* @param <K>
* @param <V>
* @param <R> the result type for the query
*/
public interface MutinyQuery<K, V, R> {
/**
* Sets the named parameter to the specified value
*
* @param name
* @param value
* @return
*/
MutinyQuery<K, V, R> param(String name, Object value);
/**
* Skips the first specified number of results
*
* @param skip
* @return
*/
MutinyQuery<K, V, R> skip(long skip);
/**
* Limits the number of results
*
* @param limit
* @return
*/
MutinyQuery<K, V, R> limit(int limit);
/**
* Executes the query
*/
Uni<MutinyQueryResult<R>> find();
/**
* Executes the query and returns a {@link Multi} with the results
*
* @return a {@link Multi} which produces {@link CacheContinuousQueryEvent} items.
*/
<R> Multi<CacheContinuousQueryEvent<K, R>> findContinuously();
/**
* Executes the manipulation statement (UPDATE, REMOVE)
*
* @return the number of entries that were processed
*/
Uni<Long> execute();
/**
* Processes entries matched by the query using a {@link MutinyCacheEntryProcessor}. The query <b>MUST NOT</b>
* use projections. If the cache is remote, entries will be retrieved, manipulated locally and put back. The query
* <b>MUST NOT</b> use projections.
*
* @param processor the entry consumer task
*/
default <T> Multi<CacheEntryProcessorResult<K, T>> process(MutinyCacheEntryProcessor<K, V, T> processor) {
return process(processor, CacheProcessorOptions.DEFAULT);
}
/**
* Processes entries matched by the query using a {@link MutinyCacheEntryProcessor}. The query <b>MUST NOT</b>
* use projections. If the cache is remote, entries will be retrieved, manipulated locally and put back. The query
* <b>MUST NOT</b> use projections.
*
* @param processor the entry consumer task
*/
<T> Multi<CacheEntryProcessorResult<K, T>> process(MutinyCacheEntryProcessor<K, V, T> processor, CacheProcessorOptions options);
/**
* Processes entries matched by the query using a named {@link CacheProcessor}. The query <b>MUST NOT</b> use
* projections. If the cache processor returns a non-null value for an entry, it will be returned through the
* publisher.
*
* @param <T>
* @param processor the entry processor
* @return
*/
default <T> Multi<CacheEntryProcessorResult<K, T>> process(CacheProcessor processor) {
return process(processor, CacheProcessorOptions.DEFAULT);
}
/**
* Processes entries matched by the query using a named {@link CacheProcessor}. The query <b>MUST NOT</b> use
* projections. If the cache processor returns a non-null value for an entry, it will be returned through the
* publisher.
*
* @param <T>
* @param processor the named entry processor
* @param options
* @return
*/
<T> Multi<CacheEntryProcessorResult<K, T>> process(CacheProcessor processor, CacheProcessorOptions options);
}
| 3,422
| 30.40367
| 131
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyWeakCounters.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.configuration.CounterConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public interface MutinyWeakCounters {
Uni<MutinyWeakCounter> get(String name);
Uni<MutinyWeakCounter> create(String name, CounterConfiguration configuration);
Uni<Void> remove(String name);
Multi<String> names();
}
| 418
| 19.95
| 82
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyLock.java
|
package org.infinispan.api.mutiny;
import java.util.concurrent.TimeUnit;
import io.smallrye.mutiny.Uni;
public interface MutinyLock {
String name();
/**
* Return the container of this container
*
* @return
*/
MutinyContainer container();
Uni<Void> lock();
Uni<Boolean> tryLock();
Uni<Boolean> tryLock(long time, TimeUnit unit);
Uni<Void> unlock();
Uni<Boolean> isLocked();
Uni<Boolean> isLockedByMe();
}
| 458
| 14.3
| 50
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyCache.java
|
package org.infinispan.api.mutiny;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.infinispan.api.Experimental;
import org.infinispan.api.common.CacheEntry;
import org.infinispan.api.common.CacheEntryVersion;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.CacheWriteOptions;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
import org.infinispan.api.common.events.cache.CacheEntryEventType;
import org.infinispan.api.common.events.cache.CacheListenerOptions;
import org.infinispan.api.common.process.CacheEntryProcessorResult;
import org.infinispan.api.configuration.CacheConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* A Reactive Cache provides a highly concurrent and distributed data structure, non blocking and using reactive
* streams.
*
* @since 14.0
*/
@Experimental
public interface MutinyCache<K, V> {
/**
* The name of the cache.
*
* @return
*/
String name();
/**
* The configuration for this cache.
*
* @return
*/
Uni<CacheConfiguration> configuration();
/**
* Return the container of this cache
*
* @return
*/
MutinyContainer container();
/**
* Get the value of the Key if such exists
*
* @param key
* @return the value
*/
default Uni<V> get(K key) {
return get(key, CacheOptions.DEFAULT);
}
/**
* Get the value of the Key if such exists
*
* @param key
* @param options
* @return the value
*/
default Uni<V> get(K key, CacheOptions options) {
return getEntry(key, options)
.map(CacheEntry::value);
}
/**
* @param key
* @return
*/
default Uni<CacheEntry<K, V>> getEntry(K key) {
return getEntry(key, CacheOptions.DEFAULT);
}
/**
* @param key
* @param options
* @return
*/
Uni<CacheEntry<K, V>> getEntry(K key, CacheOptions options);
/**
* Insert the key/value if such key does not exist
*
* @param key
* @param value
* @return the previous value if present
*/
default Uni<CacheEntry<K, V>> putIfAbsent(K key, V value) {
return putIfAbsent(key, value, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return the previous value if present
*/
Uni<CacheEntry<K, V>> putIfAbsent(K key, V value, CacheWriteOptions options);
/**
* Insert the key/value if such key does not exist
*
* @param key
* @param value
* @return
*/
default Uni<Boolean> setIfAbsent(K key, V value) {
return setIfAbsent(key, value, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return
*/
default Uni<Boolean> setIfAbsent(K key, V value, CacheWriteOptions options) {
return putIfAbsent(key, value, options)
.map(Objects::isNull);
}
/**
* Save the key/value. If the key exists will replace the value
*
* @param key
* @param value
* @return
*/
default Uni<CacheEntry<K, V>> put(K key, V value) {
return put(key, value, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return
*/
Uni<CacheEntry<K, V>> put(K key, V value, CacheWriteOptions options);
/**
* @param key
* @param value
* @return
*/
default Uni<Void> set(K key, V value) {
return set(key, value, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return
*/
default Uni<Void> set(K key, V value, CacheWriteOptions options) {
return put(key, value, options)
.map(__ -> null);
}
/**
* Delete the key
*
* @param key
* @return true if the key existed and was removed, false if the key did not exist.
*/
default Uni<Boolean> remove(K key) {
return remove(key, CacheOptions.DEFAULT);
}
/**
* Delete the key
*
* @param key
* @param options
* @return true if the key existed and was removed, false if the key did not exist.
*/
default Uni<Boolean> remove(K key, CacheOptions options) {
return getAndRemove(key, options)
.map(Objects::nonNull);
}
/**
* Removes the key and returns its value if present.
*
* @param key
* @return the value of the key before removal. Returns null if the key didn't exist.
*/
default Uni<CacheEntry<K, V>> getAndRemove(K key) {
return getAndRemove(key, CacheOptions.DEFAULT);
}
/**
* Removes the key and returns its value if present.
*
* @param key
* @param options
* @return the value of the key before removal. Returns null if the key didn't exist.
*/
Uni<CacheEntry<K, V>> getAndRemove(K key, CacheOptions options);
/**
* Retrieve all keys
*
* @return @{@link Multi} which produces keys as items.
*/
default Multi<K> keys() {
return keys(CacheOptions.DEFAULT);
}
/**
* Retrieve all keys
*
* @return @{@link Multi} which produces keys as items.
*/
default Multi<K> keys(CacheOptions options) {
return entries(options).map(CacheEntry::key);
}
/**
* Retrieve all entries
*
* @return
*/
default Multi<CacheEntry<K, V>> entries() {
return entries(CacheOptions.DEFAULT);
}
/**
* Retrieve all entries
*
* @param options
* @return
*/
Multi<CacheEntry<K, V>> entries(CacheOptions options);
/**
* Retrieve all the entries for the specified keys.
*
* @param keys
* @return
*/
default Multi<CacheEntry<K, V>> getAll(Set<K> keys) {
return getAll(keys, CacheOptions.DEFAULT);
}
/**
* Retrieve all the entries for the specified keys.
*
* @param keys
* @param options
* @return
*/
Multi<CacheEntry<K, V>> getAll(Set<K> keys, CacheOptions options);
/**
* @param keys
* @return
*/
default Multi<CacheEntry<K, V>> getAll(K... keys) {
return getAll(CacheOptions.DEFAULT, keys);
}
/**
* @param keys
* @param options
* @return
*/
Multi<CacheEntry<K, V>> getAll(CacheOptions options, K... keys);
/**
* Put multiple entries from a {@link Multi}
*
* @param pairs
* @return Void
*/
default Uni<Void> putAll(Multi<CacheEntry<K, V>> pairs) {
return putAll(pairs, CacheWriteOptions.DEFAULT);
}
/**
* @param pairs
* @param options
* @return
*/
Uni<Void> putAll(Multi<CacheEntry<K, V>> pairs, CacheWriteOptions options);
/**
* @param map
* @param options
* @return
*/
Uni<Void> putAll(Map<K, V> map, CacheWriteOptions options);
default Uni<Void> putAll(Map<K, V> map) {
return putAll(map, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @return
*/
default Uni<Boolean> replace(K key, V value, CacheEntryVersion version) {
return replace(key, value, version, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @return
*/
default Uni<Boolean> replace(K key, V value, CacheEntryVersion version, CacheWriteOptions options) {
return getOrReplaceEntry(key, value, version, options)
.map(ce -> ce != null && version.equals(ce.metadata().version()));
}
/**
* @param key
* @param value
* @param version
* @return
*/
default Uni<CacheEntry<K, V>> getOrReplaceEntry(K key, V value, CacheEntryVersion version) {
return getOrReplaceEntry(key, value, version, CacheWriteOptions.DEFAULT);
}
/**
* @param key
* @param value
* @param options
* @param version
* @return
*/
Uni<CacheEntry<K, V>> getOrReplaceEntry(K key, V value, CacheEntryVersion version, CacheWriteOptions options);
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @return
*/
default Multi<K> removeAll(Set<K> keys) {
return removeAll(keys, CacheWriteOptions.DEFAULT);
}
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @param options
* @return
*/
Multi<K> removeAll(Set<K> keys, CacheWriteOptions options);
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @return
*/
default Multi<K> removeAll(Multi<K> keys) {
return removeAll(keys, CacheWriteOptions.DEFAULT);
}
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @param options
* @return
*/
Multi<K> removeAll(Multi<K> keys, CacheWriteOptions options);
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @return
*/
default Multi<CacheEntry<K, V>> getAndRemoveAll(Multi<K> keys) {
return getAndRemoveAll(keys, CacheWriteOptions.DEFAULT);
}
/**
* Removes a set of keys. Returns the keys that were removed.
*
* @param keys
* @param options
* @return
*/
default Multi<CacheEntry<K, V>> getAndRemoveAll(Multi<K> keys, CacheWriteOptions options) {
return keys.onItem().transformToUni(this::getAndRemove)
.concatenate();
}
/**
* Estimate the size of the store
*
* @return Long, estimated size
*/
default Uni<Long> estimateSize() {
return estimateSize(CacheOptions.DEFAULT);
}
/**
* Estimate the size of the store
*
* @param options
* @return Long, estimated size
*/
Uni<Long> estimateSize(CacheOptions options);
/**
* Clear the store. If a concurrent operation puts data in the store the clear might not properly work
*
* @return Void
*/
default Uni<Void> clear() {
return clear(CacheOptions.DEFAULT);
}
/**
* Clear the store. If a concurrent operation puts data in the store the clear might not properly work
*
* @param options
* @return Void
*/
Uni<Void> clear(CacheOptions options);
/**
* Find by QueryRequest.
*
* @param <R>
* @param query
* @return
*/
default <R> MutinyQuery<K, V, R> query(String query) {
return query(query, CacheOptions.DEFAULT);
}
/**
* Find by QueryRequest.
*
* @param <R>
* @param query
* @param options
* @return
*/
<R> MutinyQuery<K, V, R> query(String query, CacheOptions options);
/**
* Listens to the events
*
* @param types
* @return a {@link Multi} which produces {@link CacheEntryEvent} items.
*/
default Multi<CacheEntryEvent<K, V>> listen(CacheEntryEventType... types) {
return listen(new CacheListenerOptions(), types);
}
/**
* Listens to the events
*
* @param options
* @param types
* @return a {@link Multi} which produces {@link CacheEntryEvent} items.
*/
Multi<CacheEntryEvent<K, V>> listen(CacheListenerOptions options, CacheEntryEventType... types);
/**
* Process the specified entries using the supplied processor
*
* @param keys
* @param processor
*/
default <T> Multi<CacheEntryProcessorResult<K, T>> process(Set<K> keys, MutinyCacheEntryProcessor<K, V, T> processor) {
return process(keys, processor, CacheOptions.DEFAULT);
}
/**
* Process the specified entries using the supplied processor
*
* @param keys
* @param processor
* @param options
*/
<T> Multi<CacheEntryProcessorResult<K, T>> process(Set<K> keys, MutinyCacheEntryProcessor<K, V, T> processor, CacheOptions options);
/**
* @return
*/
MutinyStreamingCache<K> streaming();
}
| 11,787
| 22.482072
| 135
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyStreamingCache.java
|
package org.infinispan.api.mutiny;
import java.nio.ByteBuffer;
import java.util.List;
import org.infinispan.api.common.CacheEntryMetadata;
import org.infinispan.api.common.CacheOptions;
import org.infinispan.api.common.CacheWriteOptions;
import org.infinispan.api.sync.SyncCache;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.subscription.BackPressureStrategy;
import io.smallrye.mutiny.subscription.MultiEmitter;
/**
* SyncStreamingCache implements streaming versions of most {@link SyncCache} methods
*
* @since 14.0
*/
public interface MutinyStreamingCache<K> {
/**
* Retrieves the value of the specified key as an {@link CacheEntrySubscriber}. The marshaller is ignored, i.e. all data will be
* read in its raw binary form.
*
* @param key key to use
* @param backPressureStrategy the {@link BackPressureStrategy} to apply
*/
default CacheEntrySubscriber get(K key, BackPressureStrategy backPressureStrategy) {
return get(key, backPressureStrategy, CacheOptions.DEFAULT);
}
/**
* Retrieves the value of the specified key as an {@link CacheEntrySubscriber}. The marshaller is ignored, i.e. all data will be
* read in its raw binary form.
*
* @param key key to use
* @param backPressureStrategy the {@link BackPressureStrategy} to apply
* @param options
*/
CacheEntrySubscriber get(K key, BackPressureStrategy backPressureStrategy, CacheOptions options);
/**
* Initiates a streaming put operation. It is up to the application to write to the returned {@link MultiEmitter} and
* complete it when there is no more data to write. The marshaller is ignored, i.e. all data will be written in its
* raw binary form. The returned {@link MultiEmitter} is not thread-safe.
*
* @param key key to use
* @param backPressureStrategy the {@link BackPressureStrategy} to apply
*/
default CacheEntryPublisher put(K key, BackPressureStrategy backPressureStrategy) {
return put(key, CacheWriteOptions.DEFAULT, backPressureStrategy);
}
/**
* Initiates a streaming put operation. It is up to the application to write to the returned {@link MultiEmitter} and
* complete it when there is no more data to write. The marshaller is ignored, i.e. all data will be written in its
* raw binary form. The returned {@link MultiEmitter} is not thread-safe.
*
* @param key key to use
* @param options
* @param backPressureStrategy the {@link BackPressureStrategy} to apply
*/
CacheEntryPublisher put(K key, CacheWriteOptions options, BackPressureStrategy backPressureStrategy);
/**
* A conditional form of put which inserts an entry into the cache only if no mapping for the key is already present.
* The operation is atomic. The server only performs the operation once the {@link MultiEmitter} has been completed.
* The returned {@link MultiEmitter} is not thread-safe.
*
* @param key key to use
* @param backPressureStrategy the {@link BackPressureStrategy} to apply
*/
default CacheEntryPublisher putIfAbsent(K key, BackPressureStrategy backPressureStrategy) {
return putIfAbsent(key, CacheWriteOptions.DEFAULT, backPressureStrategy);
}
/**
* A conditional form of put which inserts an entry into the cache only if no mapping for the key is already present.
* The operation is atomic. The server only performs the operation once the {@link MultiEmitter} has been completed.
* The returned {@link MultiEmitter} is not thread-safe.
*
* @param key key to use
* @param options the entry expiration
* @param backPressureStrategy the {@link BackPressureStrategy} to apply
*/
CacheEntryPublisher putIfAbsent(K key, CacheWriteOptions options, BackPressureStrategy backPressureStrategy);
interface CacheEntrySubscriber extends Multi<List<ByteBuffer>> {
Uni<CacheEntryMetadata> metadata();
}
interface CacheEntryPublisher extends Multi<ByteBuffer>, AutoCloseable {
}
}
| 4,159
| 41.886598
| 131
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyMultimaps.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.configuration.MultimapConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public interface MutinyMultimaps {
<K, V> Uni<MutinyMultimap<K, V>> create(String name, MultimapConfiguration cacheConfiguration);
<K, V> Uni<MutinyMultimap<K, V>> create(String name, String template);
<K, V> Uni<MutinyMultimap<K, V>> get(String name);
Uni<Void> remove(String name);
Multi<String> names();
Uni<Void> createTemplate(String name, MultimapConfiguration cacheConfiguration);
Uni<Void> removeTemplate(String name);
Multi<String> templateNames();
}
| 680
| 23.321429
| 98
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyWeakCounter.java
|
package org.infinispan.api.mutiny;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public interface MutinyWeakCounter {
/**
* Returns the name of this counter
*
* @return the name of this counter
*/
String name();
/**
* Return the container of this counter
*
* @return
*/
MutinyContainer container();
/**
* Returns the current value of this counter
*
* @return
*/
Uni<Long> value();
default Uni<Void> increment() {
return add(1);
}
default Uni<Void> decrement() {
return add(-1);
}
Uni<Void> add(long delta);
}
| 618
| 14.475
| 47
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyLocks.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.configuration.LockConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public interface MutinyLocks {
Uni<MutinyLock> lock(String name);
Uni<MutinyLock> create(String name, LockConfiguration configuration);
Uni<Void> remove(String name);
Multi<String> names();
}
| 392
| 18.65
| 72
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyCacheEntryProcessor.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.common.MutableCacheEntry;
import org.infinispan.api.common.process.CacheEntryProcessorContext;
import org.infinispan.api.common.process.CacheEntryProcessorResult;
import io.smallrye.mutiny.Multi;
/**
* @since 14.0
**/
@FunctionalInterface
public interface MutinyCacheEntryProcessor<K, V, T> {
Multi<CacheEntryProcessorResult<K, T>> process(Multi<MutableCacheEntry<K,V>> entries, CacheEntryProcessorContext context);
}
| 487
| 29.5
| 125
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyStrongCounters.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.configuration.CounterConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public interface MutinyStrongCounters {
Uni<MutinyStrongCounter> get(String name);
Uni<MutinyStrongCounter> create(String name, CounterConfiguration configuration);
Uni<Void> remove(String name);
Multi<String> names();
}
| 424
| 20.25
| 84
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyContainer.java
|
package org.infinispan.api.mutiny;
import java.util.function.Function;
import org.infinispan.api.Infinispan;
import org.infinispan.api.common.events.container.ContainerEvent;
import org.infinispan.api.common.events.container.ContainerListenerEventType;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public interface MutinyContainer extends Infinispan {
MutinyCaches caches();
MutinyMultimaps multimaps();
MutinyStrongCounters strongCounters();
MutinyWeakCounters weakCounters();
MutinyLocks locks();
/**
* @param types
* @return
*/
Multi<ContainerEvent> listen(ContainerListenerEventType... types);
<R> Uni<R> execute(String name, Object... args);
<T> Uni<T> batch(Function<MutinyContainer, Uni<T>> function);
}
| 804
| 21.361111
| 77
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyCaches.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.configuration.CacheConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @since 14.0
**/
public interface MutinyCaches {
<K, V> Uni<MutinyCache<K, V>> create(String name, CacheConfiguration cacheConfiguration);
<K, V> Uni<MutinyCache<K, V>> create(String name, String template);
<K, V> Uni<MutinyCache<K, V>> get(String name);
Uni<Void> remove(String name);
Multi<String> names();
Uni<Void> createTemplate(String name, CacheConfiguration cacheConfiguration);
Uni<Void> removeTemplate(String name);
Multi<String> templateNames();
}
| 659
| 22.571429
| 92
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyQueryResult.java
|
package org.infinispan.api.mutiny;
import java.util.OptionalLong;
import io.smallrye.mutiny.Multi;
/**
* @since 14.0
**/
public interface MutinyQueryResult<R> extends AutoCloseable {
OptionalLong hitCount();
Multi<R> results();
void close();
}
| 260
| 14.352941
| 61
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyStrongCounter.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.common.events.cache.CacheEntryEvent;
import org.infinispan.api.common.events.counter.CounterEvent;
import org.infinispan.api.configuration.CounterConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* The strong consistent counter interface.
* <p>
* It provides atomic updates for the counter. All the operations are perform asynchronously and they complete the
* {@link Uni} when completed.
*
* @since 14.0
*/
public interface MutinyStrongCounter {
/**
* @return The counter name.
*/
String name();
/**
* Return the container of this counter
*
* @return
*/
MutinyContainer container();
/**
* It fetches the current value.
* <p>
* It may go remotely to fetch the current value.
*
* @return The current value.
*/
Uni<Long> value();
/**
* Atomically increments the counter and returns the new value.
*
* @return The new value.
*/
default Uni<Long> incrementAndGet() {
return addAndGet(1L);
}
/**
* Atomically decrements the counter and returns the new value
*
* @return The new value.
*/
default Uni<Long> decrementAndGet() {
return addAndGet(-1L);
}
/**
* Atomically adds the given value and return the new value.
*
* @param delta The non-zero value to add. It can be negative.
* @return The new value.
*/
Uni<Long> addAndGet(long delta);
/**
* Resets the counter to its initial value.
*/
Uni<Void> reset();
/**
* Listens to counter events.
*
* @return a {@link Multi} which produces {@link CacheEntryEvent} items.
*/
Multi<CounterEvent> listen();
/**
* Atomically sets the value to the given updated value if the current value {@code ==} the expected value.
* <p>
* It is the same as {@code return compareAndSwap(expect, update).thenApply(value -> value == expect);}
*
* @param expect the expected value
* @param update the new value
* @return {@code true} if successful, {@code false} otherwise.
*/
Uni<Boolean> compareAndSet(long expect, long update);
/**
* Atomically sets the value to the given updated value if the current value {@code ==} the expected value.
* <p>
* The operation is successful if the return value is equals to the expected value.
*
* @param expect the expected value.
* @param update the new value.
* @return the previous counter's value.
*/
Uni<Long> compareAndSwap(long expect, long update);
/**
* Atomically sets the value to the given updated value
*
* @param value the new value.
* @return the old counter's value.
*/
Uni<Long> getAndSet(long value);
Uni<CounterConfiguration> getConfiguration();
}
| 2,838
| 24.123894
| 114
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/EntryStatus.java
|
package org.infinispan.api.mutiny;
/**
* A {@link MutinyCache} entry status. Used by listeners and Continuous Query
*
* @since 14.0
*/
public enum EntryStatus {
CREATED, UPDATED, DELETED
}
| 197
| 17
| 77
|
java
|
null |
infinispan-main/api/src/main/java/org/infinispan/api/mutiny/MutinyMultimap.java
|
package org.infinispan.api.mutiny;
import org.infinispan.api.configuration.MultimapConfiguration;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
/**
* @param <K>
* @param <V>
* @since 14.0
*/
public interface MutinyMultimap<K, V> {
String name();
Uni<MultimapConfiguration> configuration();
/**
* Return the container of this Multimap.
*
* @return
*/
MutinyContainer container();
Uni<Void> add(K key, V value);
Multi<V> get(K key);
Uni<Boolean> remove(K key);
Uni<Boolean> remove(K key, V value);
Uni<Boolean> containsKey(K key);
Uni<Boolean> containsEntry(K key, V value);
Uni<Long> estimateSize();
}
| 685
| 16.15
| 62
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestLoggingClient.java
|
package org.infinispan.client.rest;
import java.util.concurrent.CompletionStage;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 11.0
**/
public interface RestLoggingClient {
CompletionStage<RestResponse> listLoggers();
CompletionStage<RestResponse> listAppenders();
CompletionStage<RestResponse> setLogger(String name, String level, String... appenders);
CompletionStage<RestResponse> removeLogger(String name);
}
| 457
| 24.444444
| 91
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestEntity.java
|
package org.infinispan.client.rest;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.infinispan.client.rest.impl.okhttp.ByteArrayRestEntityOkHttp;
import org.infinispan.client.rest.impl.okhttp.FileRestEntityOkHttp;
import org.infinispan.client.rest.impl.okhttp.InputStreamEntityOkHttp;
import org.infinispan.client.rest.impl.okhttp.StringRestEntityOkHttp;
import org.infinispan.commons.dataconversion.MediaType;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestEntity {
String getBody();
MediaType contentType();
static RestEntity create(MediaType contentType, String body) {
return new StringRestEntityOkHttp(contentType, body);
}
static RestEntity create(MediaType contentType, byte[] body) {
return new ByteArrayRestEntityOkHttp(contentType, body);
}
static RestEntity create(MediaType contentType, File file) {
return new FileRestEntityOkHttp(contentType, file);
}
static RestEntity create(MediaType contentType, InputStream inputStream) {
return new InputStreamEntityOkHttp(contentType, inputStream);
}
static RestEntity create(File file) {
if (file.getName().endsWith(".yaml") || file.getName().endsWith(".yml")) {
// We can only "guess" YAML by its extension
return RestEntity.create(MediaType.APPLICATION_YAML, file);
}
try (InputStream is = new FileInputStream(file)) {
int b;
while ((b = is.read()) > -1) {
if (b == '{') {
return RestEntity.create(MediaType.APPLICATION_JSON, file);
} else if (b == '<') {
return RestEntity.create(MediaType.APPLICATION_XML, file);
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, file);
}
}
| 1,960
| 32.237288
| 80
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestEventListener.java
|
package org.infinispan.client.rest;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 13.0
**/
public interface RestEventListener {
default void onOpen(RestResponse response) {}
default void onError(Throwable t, RestResponse response) {}
default void onMessage(String id, String type, String data) {}
default void close() {}
}
| 366
| 21.9375
| 65
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestContainerClient.java
|
package org.infinispan.client.rest;
import java.util.concurrent.CompletionStage;
/**
* @author Ryan Emerson
* @since 13.0
*/
public interface RestContainerClient {
/**
* Shuts down the container stopping all caches and resources. The servers remain running with active endpoints
* and clustering, however REST calls to container resources will result in a 503 Service Unavailable response.
*/
CompletionStage<RestResponse> shutdown();
}
| 460
| 27.8125
| 114
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestMetricsClient.java
|
package org.infinispan.client.rest;
import java.util.concurrent.CompletionStage;
/**
* An experimental rest client for Micrometer metrics in native and Prometheus compatible OpenMetrics format.
*
* @author anistor@redhat.com
* @since 10.0
*/
public interface RestMetricsClient {
CompletionStage<RestResponse> metrics();
CompletionStage<RestResponse> metrics(boolean openMetricsFormat);
CompletionStage<RestResponse> metricsMetadata();
}
| 457
| 21.9
| 109
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestSecurityClient.java
|
package org.infinispan.client.rest;
import java.util.List;
import java.util.concurrent.CompletionStage;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 12.1
**/
public interface RestSecurityClient {
CompletionStage<RestResponse> listPrincipals();
CompletionStage<RestResponse> listRoles(String principal);
CompletionStage<RestResponse> grant(String principal, List<String> roles);
CompletionStage<RestResponse> deny(String principal, List<String> roles);
CompletionStage<RestResponse> flushCache();
CompletionStage<RestResponse> createRole(String name, List<String> permissions);
CompletionStage<RestResponse> removeRole(String name);
CompletionStage<RestResponse> describeRole(String name);
}
| 752
| 26.888889
| 83
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestClient.java
|
package org.infinispan.client.rest;
import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.configuration.RestClientConfiguration;
import org.infinispan.client.rest.impl.okhttp.RestClientOkHttp;
import org.infinispan.commons.util.Experimental;
/**
* An experimental client for interacting with an Infinispan REST server.
*
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
@Experimental("This is not a supported API. Are you here for a perilous journey?")
public interface RestClient extends Closeable {
@Override
void close() throws IOException;
/**
* Interact with the single server
*/
RestServerClient server();
/**
* Interact with the whole cluster
*/
RestClusterClient cluster();
/**
* Returns a list of available cache manager names
*/
CompletionStage<RestResponse> cacheManagers();
/**
* Operations on the specified cache manager
*/
RestCacheManagerClient cacheManager(String name);
/**
* Operations on the server's Container
*/
RestContainerClient container();
/**
* Returns a list of available caches
*/
CompletionStage<RestResponse> caches();
/**
* Operations on the specified cache
*/
RestCacheClient cache(String name);
/**
* Returns a list of available counters
*/
CompletionStage<RestResponse> counters();
/**
* Operations on the specified counter
*/
RestCounterClient counter(String name);
/**
* Operations on tasks
*/
RestTaskClient tasks();
/**
* Raw HTTP operations
*/
RestRawClient raw();
/**
* Server metrics
*/
RestMetricsClient metrics();
/**
* Protobuf schemas
*/
RestSchemaClient schemas();
/**
* Returns the configuration of this {@link RestClient}
*/
RestClientConfiguration getConfiguration();
/**
* Creates a {@link RestClient} instance based on the supplied configuration
*
* @param configuration a {@link RestClientConfiguration}
* @return a {@link RestClient} instance
*/
static RestClient forConfiguration(RestClientConfiguration configuration) {
return new RestClientOkHttp(configuration);
}
/**
* Server security
*/
RestSecurityClient security();
}
| 2,361
| 20.87037
| 82
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestTaskClient.java
|
package org.infinispan.client.rest;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.CompletionStage;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.1
**/
public interface RestTaskClient {
/**
* Task type filter definition.
*/
enum ResultType {
/**
* User created tasks
*/
USER,
/**
* All tasks, including admin tasks, that contains name starting with '@@'
*/
ALL
}
/**
* Retrieves a list of tasks from the server
* @param resultType the type of task to return
*/
CompletionStage<RestResponse> list(ResultType resultType);
/**
* Executes a task with the supplied parameters. Currently only supports String values
*/
CompletionStage<RestResponse> exec(String taskName, String cacheName, Map<String, ?> parameters);
/**
* Uploads a script
*/
CompletionStage<RestResponse> uploadScript(String taskName, RestEntity script);
/**
* Downloads a script
*/
CompletionStage<RestResponse> downloadScript(String taskName);
/**
* Executes a task without parameters
*/
default CompletionStage<RestResponse> exec(String taskName) {
return exec(taskName, null, Collections.emptyMap());
}
default CompletionStage<RestResponse> exec(String taskName, Map<String, ?> parameters) {
return exec(taskName, null, parameters);
}
}
| 1,440
| 23.016667
| 100
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestServerClient.java
|
package org.infinispan.client.rest;
import java.util.List;
import java.util.concurrent.CompletionStage;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestServerClient {
CompletionStage<RestResponse> configuration();
/**
* Shuts down the server we're connected to
*/
CompletionStage<RestResponse> stop();
/**
* Returns thread information
*/
CompletionStage<RestResponse> threads();
/**
* Returns information about the server
*/
CompletionStage<RestResponse> info();
/**
* Returns memory information about the server
*/
CompletionStage<RestResponse> memory();
/**
* Performs a heap dump
*/
CompletionStage<RestResponse> heapDump(boolean live);
/**
* Returns the server environment
*/
CompletionStage<RestResponse> env();
/**
* Returns a report from the server
*/
CompletionStage<RestResponse> report();
CompletionStage<RestResponse> report(String node);
CompletionStage<RestResponse> ignoreCache(String cacheManagerName, String cacheName);
CompletionStage<RestResponse> unIgnoreCache(String cacheManagerName, String cacheName);
CompletionStage<RestResponse> listIgnoredCaches(String cacheManagerName);
RestLoggingClient logging();
CompletionStage<RestResponse> listConnections(boolean global);
CompletionStage<RestResponse> connectorNames();
CompletionStage<RestResponse> connector(String name);
CompletionStage<RestResponse> connectorStart(String name);
CompletionStage<RestResponse> connectorStop(String name);
CompletionStage<RestResponse> connectorIpFilters(String name);
CompletionStage<RestResponse> connectorIpFiltersClear(String name);
CompletionStage<RestResponse> connectorIpFilterSet(String name, List<IpFilterRule> rules);
CompletionStage<RestResponse> dataSourceNames();
CompletionStage<RestResponse> dataSourceTest(String name);
CompletionStage<RestResponse> cacheConfigDefaults();
}
| 2,023
| 24.3
| 93
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestCacheManagerClient.java
|
package org.infinispan.client.rest;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import org.infinispan.commons.dataconversion.MediaType;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestCacheManagerClient {
String name();
default CompletionStage<RestResponse> globalConfiguration() {
return globalConfiguration(MediaType.APPLICATION_JSON_TYPE);
}
CompletionStage<RestResponse> globalConfiguration(String mediaType);
CompletionStage<RestResponse> cacheConfigurations();
CompletionStage<RestResponse> cacheConfigurations(String mediaType);
CompletionStage<RestResponse> info();
CompletionStage<RestResponse> health(boolean skipBody);
default CompletionStage<RestResponse> health() {
return health(false);
}
CompletionStage<RestResponse> templates(String mediaType);
CompletionStage<RestResponse> healthStatus();
CompletionStage<RestResponse> stats();
CompletionStage<RestResponse> statsReset();
CompletionStage<RestResponse> backupStatuses();
CompletionStage<RestResponse> backupStatus(String site);
CompletionStage<RestResponse> bringBackupOnline(String backup);
CompletionStage<RestResponse> takeOffline(String backup);
CompletionStage<RestResponse> pushSiteState(String backup);
CompletionStage<RestResponse> cancelPushState(String backup);
CompletionStage<RestResponse> caches();
/**
* Creates a backup file containing all resources in this container.
*/
default CompletionStage<RestResponse> createBackup(String name) {
return createBackup(name, null);
}
/**
* Creates a backup file containing only the resources specified in the provided {@link Map}.
*
* @param resources a map of BackupManager.Resources.Type with the names of the resources to backup. If the provided
* list only contains "*" then all available resources of that type are backed up.
*/
default CompletionStage<RestResponse> createBackup(String name, Map<String, List<String>> resources) {
return createBackup(name, null, resources);
}
/**
* Creates a backup file containing only the resources specified in the provided {@link Map}.
*
* @param workingDir the path of the server directory to be used to create the backup content and store the final
* backup file. A null value indicates that the server default should be used.
* @param resources a map of BackupManager.Resources.Type with the names of the resources to backup. If the provided
* list only contains "*" then all available resources of that type are backed up. A null value
* indicates that all resources should be included in the backup.
*/
CompletionStage<RestResponse> createBackup(String name, String workingDir, Map<String, List<String>> resources);
/**
* Retrieves a backup file with the given name from the server.
*
* @param name the name of the backup.
* @param skipBody if true, then a HEAD request is issued to the server and only the HTTP headers are returned.
*/
CompletionStage<RestResponse> getBackup(String name, boolean skipBody);
/**
* @return the names of all backups.
*/
CompletionStage<RestResponse> getBackupNames();
/**
* Deletes a backup file from the server.
*
* @param name the name of the backup.
*/
CompletionStage<RestResponse> deleteBackup(String name);
/**
* Restores all content associated with this containers name contained within the provided backup file. The backup
* file is uploaded via the server endpoint for processing, returning once the restoration has completed.
*
* @param name a unique name to identify the restore request.
* @param backup the backup {@link File} containing the data to be restored.
*/
default CompletionStage<RestResponse> restore(String name, File backup) {
return restore(name, backup, null);
}
/**
* Restores the specified content from the backup file that's associated with this container's name.
*
* @param name a unique name to identify the restore request.
* @param backup the backup {@link File} containing the data to be restored.
* @param resources a map of BackupManager.Resources.Type with the names of the resources to backup. If the provided
* list only contains "*" then all available resources of that type are restored. A null value
* indicates that all resources in the backup should be restored.
*/
CompletionStage<RestResponse> restore(String name, File backup, Map<String, List<String>> resources);
/**
* Restores the specified content from the backup file that's associated with this container's name.
*
* @param name a unique name to identify the restore request.
* @param backupLocation the path of the backup file already located on the server.
* @param resources a map of BackupManager.Resources.Type with the names of the resources to backup. If the
* provided list only contains "*" then all available resources of that type are restored. A
* null value indicates that all resources in the backup should be restored.
*/
CompletionStage<RestResponse> restore(String name, String backupLocation, Map<String, List<String>> resources);
/**
* Polls a restore request progress with the given name. 201 indicates that the request has completed, 202 that it's
* in progress and 404 that it can't be found.
*
* @param name the name of the restore.
*/
CompletionStage<RestResponse> getRestore(String name);
/**
* @return the names of all restores.
*/
CompletionStage<RestResponse> getRestoreNames();
/**
* Deletes a restore request from the server. Container content is not affected.
*
* @param name the name of the restore.
*/
CompletionStage<RestResponse> deleteRestore(String name);
/**
* Globally enables automatic rebalancing.
*/
CompletionStage<RestResponse> enableRebalancing();
/**
* Globally disables automatic rebalancing.
*/
CompletionStage<RestResponse> disableRebalancing();
}
| 6,361
| 36.869048
| 120
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestCacheClient.java
|
package org.infinispan.client.rest;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import org.infinispan.commons.api.CacheContainerAdmin;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.configuration.cache.XSiteStateTransferMode;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestCacheClient {
/**
* Returns the name of the cache
*/
String name();
/**
* Returns the health of the cache
*/
CompletionStage<RestResponse> health();
/**
* Retrieve all keys
*
* @return Response with inputStream to get all the keys
*/
CompletionStage<RestResponse> keys();
/**
* Retrieve keys limited by count
*
* @param limit The maximum number of keys to retrieve
* @return Response with InputStream to get the keys
*/
CompletionStage<RestResponse> keys(int limit);
/**
* Retrieves entries without metadata
*
* @return Response with InputStream to get the entries
*/
default CompletionStage<RestResponse> entries() {
return entries(false);
}
/**
* Retrieves entries without metadata
*
* @param contentNegotiation if true, the server will convert keys and values to a readable format and return headers with the negotiated media type.
* @return Response with InputStream to get the entries
*/
CompletionStage<RestResponse> entries(boolean contentNegotiation);
/**
* Retrieves entries limited by count
*
* @param limit: The maximum number of entries to retrieve, or -1 to retrieve all
*/
CompletionStage<RestResponse> entries(int limit);
/**
* Retrieves entries with limit and metadata
*
* @param limit: The maximum number of entries to retrieve, or -1 to retrieve all
* @param metadata: if true, includes the metadata for each entry
*/
CompletionStage<RestResponse> entries(int limit, boolean metadata);
/**
* Retrieves all keys from the cache with a specific MediaType or list of MediaTypes.
*/
CompletionStage<RestResponse> keys(String mediaType);
/**
* Retrieves the cache configuration
*/
default CompletionStage<RestResponse> configuration() {
return configuration(null);
}
/**
* Retrieves the cache configuration with a specific MediaType or list of MediaTypes.
*/
CompletionStage<RestResponse> configuration(String mediaType);
/**
* Clears a cache
*/
CompletionStage<RestResponse> clear();
/**
* Obtains the total number of elements in the cache
*/
CompletionStage<RestResponse> size();
/**
* POSTs a key/value to the cache as text/plain
*
* @param key
* @param value
* @return
*/
CompletionStage<RestResponse> post(String key, String value);
/**
* POSTs a key/value to the cache as text/plain with the specified expiration
*
* @param key
* @param value
* @param ttl
* @param maxIdle
* @return
*/
CompletionStage<RestResponse> post(String key, String value, long ttl, long maxIdle);
/**
* POSTs a key/value to the cache with the specified encoding
*
* @param key
* @param value
* @return
*/
CompletionStage<RestResponse> post(String key, RestEntity value);
/**
* POSTs a key/value to the cache with the specified encoding and expiration
*
* @param key
* @param value
* @param ttl
* @param maxIdle
* @return
*/
CompletionStage<RestResponse> post(String key, RestEntity value, long ttl, long maxIdle);
/**
* PUTs a key/value to the cache as text/plain
*
* @param key
* @param value
* @return
*/
CompletionStage<RestResponse> put(String key, String value);
/**
* PUT a key/value to the cache with custom media types for keys and values
*/
CompletionStage<RestResponse> put(String key, String keyContentType, RestEntity value);
/**
* Same as {@link #put(String, String, RestEntity)} but allowing custom headers.
*/
CompletionStage<RestResponse> put(String key, String keyContentType, RestEntity value, Map<String, String> headers);
/**
* PUT an entry with metadata.
*
* @param key The key
* @param keyContentType The {@link MediaType} of the key
* @param value a {@link RestEntity} containing the value and its MediaType
* @param ttl The time to live value
* @param maxIdle The max idle value
* @return
*/
CompletionStage<RestResponse> put(String key, String keyContentType, RestEntity value, long ttl, long maxIdle);
/**
* PUTs a key/value to the cache as text/plain with the specified expiration
*
* @param key
* @param value
* @param ttl
* @param maxIdle
* @return
*/
CompletionStage<RestResponse> put(String key, String value, long ttl, long maxIdle);
/**
* PUTs a key/value to the cache with the specified encoding
*
* @param key
* @param value
* @return
*/
CompletionStage<RestResponse> put(String key, RestEntity value);
/**
* Same as {@link #put(String, RestEntity)} also allowing one or more {@link org.infinispan.context.Flag} to be passed.
*/
CompletionStage<RestResponse> put(String key, RestEntity value, String... flags);
/**
* PUTs a key/value to the cache with the specified encoding and expiration
*
* @param key
* @param value
* @param ttl
* @param maxIdle
* @return
*/
CompletionStage<RestResponse> put(String key, RestEntity value, long ttl, long maxIdle);
/**
* GETs a key from the cache
*
* @param key
* @return
*/
CompletionStage<RestResponse> get(String key);
/**
* Same as {@link #get(String)} but allowing custom headers.
*/
CompletionStage<RestResponse> get(String key, Map<String, String> headers);
/**
* GETs a key from the cache with a specific MediaType or list of MediaTypes.
*/
CompletionStage<RestResponse> get(String key, String mediaType);
/**
* Same as {@link #get(String, String)} but with an option to return extended headers.
*/
CompletionStage<RestResponse> get(String key, String mediaType, boolean extended);
/**
* Similar to {@link #get(String)} but only retrieves headers
*
* @param key
* @return
*/
CompletionStage<RestResponse> head(String key);
/**
* Similar to {@link #head(String)} but allowing custom headers
*/
CompletionStage<RestResponse> head(String key, Map<String, String> headers);
/**
* DELETEs an entry from the cache
*
* @param key
* @return
*/
CompletionStage<RestResponse> remove(String key);
/**
* Same as {@link #remove(String)} but allowing custom headers
*/
CompletionStage<RestResponse> remove(String test, Map<String, String> headers);
/**
* Creates the cache using the supplied template name
*
* @param template the name of a template
* @param flags any flags to apply to the create operation, e.g. {@link org.infinispan.commons.api.CacheContainerAdmin.AdminFlag#VOLATILE}
* @return
*/
CompletionStage<RestResponse> createWithTemplate(String template, CacheContainerAdmin.AdminFlag... flags);
/**
* Obtains statistics for the cache
*
* @return
*/
CompletionStage<RestResponse> stats();
/**
* Resets cache statistics
*
* @return
*/
CompletionStage<RestResponse> statsReset();
/**
* Obtain metrics about the distribution of data of the cache.
*
* @return
*/
CompletionStage<RestResponse> distribution();
/**
* Return the nodes which the key is present for a specific cache.
*
* @param key: the key to search.
*/
CompletionStage<RestResponse> distribution(String key);
/**
* Creates the cache using the supplied configuration
*
* @param configuration the configuration, in XML, JSON or YAML format
* @param flags any flags to apply to the create operation, e.g. {@link org.infinispan.commons.api.CacheContainerAdmin.AdminFlag#VOLATILE}
* @return
*/
CompletionStage<RestResponse> createWithConfiguration(RestEntity configuration, CacheContainerAdmin.AdminFlag... flags);
/**
* Updates the cache configuration
*
* @param configuration the configuration, in XML, JSON or YAML format
* @param flags any flags to apply to the update operation, e.g. {@link org.infinispan.commons.api.CacheContainerAdmin.AdminFlag#VOLATILE}
* @return
*/
CompletionStage<RestResponse> updateWithConfiguration(RestEntity configuration, CacheContainerAdmin.AdminFlag... flags);
/**
* Removes the cache
*
* @return
*/
CompletionStage<RestResponse> delete();
/**
* Executes an Ickle-query
*
* @param query the ickle query
*/
default CompletionStage<RestResponse> query(String query) {
return query(query, false);
}
/**
* Executes an Ickle-query
*
* @param query the ickle query
* @param local if true, query is restricted to the data present in the node that process the request.
*/
CompletionStage<RestResponse> query(String query, boolean local);
/**
* Executes an Ickle-query
*
* @param query the ickle query
* @param maxResults the maximum number of results to return
* @param offset the offset within the result from which to return results
*/
CompletionStage<RestResponse> query(String query, int maxResults, int offset);
/**
* Executes an Ickle-query
*
* @param query the ickle query
* @param maxResults the maximum number of results to return
* @param offset the offset within the result from which to return results
* @param hitCountAccuracy the limit to the hit count accuracy to return sooner
*/
CompletionStage<RestResponse> query(String query, int maxResults, int offset, int hitCountAccuracy);
/**
* @return the status of all backup sites
*/
CompletionStage<RestResponse> xsiteBackups();
/**
* @return the status of a single backup site
*/
CompletionStage<RestResponse> backupStatus(String site);
/**
* Take a backup site offline
*/
CompletionStage<RestResponse> takeSiteOffline(String site);
/**
* Bring back a backup site online
*/
CompletionStage<RestResponse> bringSiteOnline(String site);
/**
* Starts the state push to a backup site
*/
CompletionStage<RestResponse> pushSiteState(String site);
/**
* Cancels the state push
*/
CompletionStage<RestResponse> cancelPushState(String site);
/**
* Cancel the receiving state on a backup site
*/
CompletionStage<RestResponse> cancelReceiveState(String site);
/**
* Obtain the status of a state push to a backup site
*/
CompletionStage<RestResponse> pushStateStatus();
/**
* Get the configuration used to automatically take a backup site offline
*/
CompletionStage<RestResponse> getXSiteTakeOfflineConfig(String site);
/**
* Updates the configuration used to automatically take a backup site offline
*/
CompletionStage<RestResponse> updateXSiteTakeOfflineConfig(String site, int afterFailures, long minTimeToWait);
/**
* Clear the status of a state push in a site
*/
CompletionStage<RestResponse> clearPushStateStatus();
/**
* Returns the cross-site replication state transfer mode.
*
* @see XSiteStateTransferMode
*/
CompletionStage<RestResponse> xSiteStateTransferMode(String site);
/**
* Sets the cross-site replication state transfer mode.
*
* @see XSiteStateTransferMode
*/
CompletionStage<RestResponse> xSiteStateTransferMode(String site, XSiteStateTransferMode mode);
/**
* Check if the cache exists
*/
CompletionStage<RestResponse> exists();
/**
* Execute a Rolling Upgrade processing
*/
CompletionStage<RestResponse> synchronizeData(Integer readBatch, Integer threads);
/**
* Execute a Rolling Upgrade processing using defaults.
*/
CompletionStage<RestResponse> synchronizeData();
/**
* Disconnects the target cluster from the source cluster after a Rolling Upgrade
*/
CompletionStage<RestResponse> disconnectSource();
/**
* Connects the target cluster to a source cluster before a Rolling Upgrade
*
* @param remoteStoreJsonConfig The remote-store config as JSON
*/
CompletionStage<RestResponse> connectSource(RestEntity remoteStoreJsonConfig);
/**
* Checks if the cache is connected through a remote store to perform rolling upgrades
*/
CompletionStage<RestResponse> sourceConnected();
/**
* Return the remote store configuration in case the case has been connected to another cluster using
* {@link #connectSource(RestEntity)}
*/
CompletionStage<RestResponse> sourceConnection();
/**
* Rebuild the search indexes of the cache based on its data.
*/
CompletionStage<RestResponse> reindex();
/**
* Same as {@link #reindex()} but only considers data from the local cluster member.
*/
CompletionStage<RestResponse> reindexLocal();
/**
* Deletes all the indexes from the cache.
*/
CompletionStage<RestResponse> clearIndex();
/**
* Update index schema for the current cache.
*/
CompletionStage<RestResponse> updateIndexSchema();
/**
* Obtain statistics about queries.
*
* @deprecated Use {@link #searchStats()} instead.
*/
@Deprecated
CompletionStage<RestResponse> queryStats();
/**
* Obtain statistics about the indexes.
*
* @deprecated Use {@link #searchStats()} instead.
*/
@Deprecated
CompletionStage<RestResponse> indexStats();
/**
* Clear runtime query statistics.
*
* @deprecated Use {@link #searchStats()} and {@link #clearSearchStats()}.
*/
@Deprecated
CompletionStage<RestResponse> clearQueryStats();
/**
* Obtains details about the cache
*/
CompletionStage<RestResponse> details();
/**
* Obtains the index metamodel for the current cache.
* The query has to be indexed.
*
* @return the stage of the response containing the metamodel of the index
*/
CompletionStage<RestResponse> indexMetamodel();
/**
* Obtain query and indexing statistics for the cache.
*/
CompletionStage<RestResponse> searchStats();
/**
* Clear search stats.
*/
CompletionStage<RestResponse> clearSearchStats();
/**
* Enables automatic rebalancing for the cache.
*/
CompletionStage<RestResponse> enableRebalancing();
/**
* Disables automatic rebalancing for the cache.
*/
CompletionStage<RestResponse> disableRebalancing();
/**
* Updates a configuration attribute.
*/
CompletionStage<RestResponse> updateConfigurationAttribute(String attribute, String value);
/**
* Retrieves all available configuration attributes for this cache
*/
CompletionStage<RestResponse> configurationAttributes();
/**
* Retrieves all available configuration attributes for this cache optionally including values and types
*/
CompletionStage<RestResponse> configurationAttributes(boolean full);
/**
* Retrieves the Cache's Availability status.
*/
CompletionStage<RestResponse> getAvailability();
/**
* Sets the Cache's Avaialability
*/
CompletionStage<RestResponse> setAvailability(String availability);
/**
* Force the current cache topology as the stable if not running.
*/
CompletionStage<RestResponse> markTopologyStable(boolean force);
}
| 15,741
| 26.617544
| 152
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestCounterClient.java
|
package org.infinispan.client.rest;
import java.util.concurrent.CompletionStage;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestCounterClient {
CompletionStage<RestResponse> create(RestEntity configuration);
CompletionStage<RestResponse> delete();
CompletionStage<RestResponse> configuration();
CompletionStage<RestResponse> configuration(String mediaType);
CompletionStage<RestResponse> get();
CompletionStage<RestResponse> add(long delta);
CompletionStage<RestResponse> increment();
CompletionStage<RestResponse> decrement();
CompletionStage<RestResponse> reset();
CompletionStage<RestResponse> compareAndSet(long expect, long value);
CompletionStage<RestResponse> compareAndSwap(long expect, long value);
CompletionStage<RestResponse> getAndSet(long newValue);
}
| 871
| 24.647059
| 73
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestClusterClient.java
|
package org.infinispan.client.rest;
import java.io.File;
import java.util.List;
import java.util.concurrent.CompletionStage;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestClusterClient {
/**
* Shuts down the cluster
*/
CompletionStage<RestResponse> stop();
/**
* Shuts down the specified servers
*/
CompletionStage<RestResponse> stop(List<String> server);
/**
* Creates a backup file containing the content of all containers in the cluster.
*
* @param name the name of the backup.
*/
CompletionStage<RestResponse> createBackup(String name);
/**
* Retrieves a backup file with the given name from the server.
*
* @param name the name of the backup.
* @param skipBody if true, then a HEAD request is issued to the server and only the HTTP headers are returned.
*/
CompletionStage<RestResponse> getBackup(String name, boolean skipBody);
/**
* @return the names of all backups.
*/
CompletionStage<RestResponse> getBackupNames();
/**
* Deletes a backup file from the server.
*
* @param name the name of the backup.
*/
CompletionStage<RestResponse> deleteBackup(String name);
/**
* Restores all content from a backup file, by uploading the file to the server endpoint for processing, returning
* once the restoration has completed.
*
* @param name a unique name to identify the restore request.
* @param backup the backup {@link File} containing the data to be restored.
*/
CompletionStage<RestResponse> restore(String name, File backup);
/**
* Restores all content from a backup file available to the server instance.
*
* @param name a unique name to identify the restore request.
* @param backupLocation the path of the backup file already located on the server.
*/
CompletionStage<RestResponse> restore(String name, String backupLocation);
/**
* Polls a restore request progress with the given name. 201 indicates that the request has completed, 202 that it's
* in progress and 404 that it can't be found.
*
* @param name the name of the restore.
*/
CompletionStage<RestResponse> getRestore(String name);
/**
* @return the names of all restores.
*/
CompletionStage<RestResponse> getRestoreNames();
/**
* Deletes a restore request from the server. Container content is not affected.
*
* @param name the name of the restore.
*/
CompletionStage<RestResponse> deleteRestore(String name);
/**
* @return The cluster distribution information.
*/
CompletionStage<RestResponse> distribution();
}
| 2,702
| 28.703297
| 119
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/IpFilterRule.java
|
package org.infinispan.client.rest;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 12.1
**/
public class IpFilterRule {
public enum RuleType {
ACCEPT,
REJECT
}
private final RuleType type;
private final String cidr;
public IpFilterRule(RuleType type, String cidr) {
this.type = type;
this.cidr = cidr;
}
public RuleType getType() {
return type;
}
public String getCidr() {
return cidr;
}
}
| 486
| 16.392857
| 57
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestURI.java
|
package org.infinispan.client.rest;
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.client.rest.configuration.RestClientConfigurationBuilder;
import org.infinispan.client.rest.configuration.RestClientConfigurationProperties;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 12.0
**/
public class RestURI {
public static final String[] EMPTY_STRING_ARRAY = new String[0];
public static RestURI create(String uriString) {
return create(URI.create(uriString));
}
public static RestURI create(URI uri) {
if (!"http".equals(uri.getScheme()) && !"https".equals(uri.getScheme())) {
throw new IllegalArgumentException(uri.toString());
}
final List<InetSocketAddress> addresses;
final String[] userInfo;
if (uri.getHost() != null) {
addresses = Collections.singletonList(InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort() < 0 ? RestClientConfigurationProperties.DEFAULT_REST_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 ? RestClientConfigurationProperties.DEFAULT_REST_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 new IllegalArgumentException(part);
} else {
properties.setProperty(RestClientConfigurationProperties.ICR + part.substring(0, eq), part.substring(eq + 1));
}
}
}
return new RestURI(addresses, "https".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 RestURI(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 RestClientConfigurationBuilder toConfigurationBuilder() {
RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
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 "RestURI{" +
"addresses=" + addresses +
", ssl=" + ssl +
", username='" + username + '\'' +
", password='" + password + '\'' +
", properties=" + properties +
'}';
}
}
| 4,349
| 33.52381
| 218
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestRawClient.java
|
package org.infinispan.client.rest;
import java.io.Closeable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
/**
* Client to execute arbitrary requests on the server.
* The URL to be called is the scheme, host and port configured in the {@link org.infinispan.client.rest.configuration.RestClientConfigurationBuilder}
* plus the 'path' that should be supplied to the methods of this class.
*
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestRawClient {
CompletionStage<RestResponse> postForm(String path, Map<String, String> headers, Map<String, List<String>> formParameters);
default CompletionStage<RestResponse> post(String path) {
return post(path, Collections.emptyMap());
}
CompletionStage<RestResponse> postMultipartForm(String url, Map<String, String> headers, Map<String, List<String>> formParameters);
CompletionStage<RestResponse> post(String path, String body, String bodyMediaType);
CompletionStage<RestResponse> post(String path, Map<String, String> headers);
CompletionStage<RestResponse> post(String path, Map<String, String> headers, String body, String bodyMediaType);
CompletionStage<RestResponse> putValue(String path, Map<String, String> headers, String body, String bodyMediaType);
default CompletionStage<RestResponse> get(String path) {
return get(path, Collections.emptyMap());
}
CompletionStage<RestResponse> get(String path, Map<String, String> headers);
default CompletionStage<RestResponse> put(String path) {
return put(path, Collections.emptyMap());
}
CompletionStage<RestResponse> put(String path, Map<String, String> headers);
default CompletionStage<RestResponse> delete(String path) {
return delete(path, Collections.emptyMap());
}
CompletionStage<RestResponse> delete(String path, Map<String, String> headers);
CompletionStage<RestResponse> options(String path, Map<String, String> headers);
CompletionStage<RestResponse> head(String path, Map<String, String> headers);
Closeable listen(String url, Map<String, String> headers, RestEventListener listener);
}
| 2,222
| 37.327586
| 150
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestResponse.java
|
package org.infinispan.client.rest;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.infinispan.client.rest.configuration.Protocol;
import org.infinispan.commons.util.Experimental;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
@Experimental
public interface RestResponse extends RestEntity, AutoCloseable {
int OK = 200;
int CREATED = 201;
int ACCEPTED = 202;
int NO_CONTENT = 204;
int NOT_MODIFIED = 304;
int TEMPORARY_REDIRECT = 307;
int BAD_REQUEST = 400;
int UNAUTHORIZED = 401;
int FORBIDDEN = 403;
int NOT_FOUND = 404;
int METHOD_NOT_ALLOWED = 405;
int CONFLICT = 409;
int INTERNAL_SERVER_ERROR = 500;
int SERVICE_UNAVAILABLE = 503;
int getStatus();
Map<String, List<String>> headers();
/**
* Returns the value of a header as a String. For multi-valued headers, values are separated by comma.
*/
String getHeader(String header);
InputStream getBodyAsStream();
byte[] getBodyAsByteArray();
Protocol getProtocol();
void close();
boolean usedAuthentication();
}
| 1,124
| 21.5
| 105
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/RestSchemaClient.java
|
package org.infinispan.client.rest;
import java.util.concurrent.CompletionStage;
/**
* Operations for protobuf schema handling.
*
* @since 11.0
**/
public interface RestSchemaClient {
/**
* Obtains the names of the registered schemas.
*/
CompletionStage<RestResponse> names();
/**
* Obtains the names of the types.
*/
CompletionStage<RestResponse> types();
/**
* POST a schema with the supplied name and contents.
*/
CompletionStage<RestResponse> post(String schemaName, String schemaContents);
/**
* POST a schema with the supplied name and contents.
*/
CompletionStage<RestResponse> post(String schemaName, RestEntity schemaContents);
/**
* PUT a schema with the supplied name and contents.
*/
CompletionStage<RestResponse> put(String schemaName, String schemaContents);
/**
* PUT a schema with the supplied name and contents.
*/
CompletionStage<RestResponse> put(String schemaName, RestEntity schemaContents);
/**
* DELETE a schema by name.
*/
CompletionStage<RestResponse> delete(String schemaName);
/**
* GET a schema by name.
*/
CompletionStage<RestResponse> get(String schemaName);
}
| 1,217
| 22.423077
| 84
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/RestClientConfigurationChildBuilder.java
|
package org.infinispan.client.rest.configuration;
import java.util.Properties;
/**
* ConfigurationChildBuilder.
*
* @author Tristan Tarrant
* @since 10.0
*/
public interface RestClientConfigurationChildBuilder {
/**
* Adds a new remote server
*/
ServerConfigurationBuilder addServer();
/**
* Adds a list of remote servers in the form: host1[:port][;host2[:port]]...
*/
RestClientConfigurationBuilder addServers(String servers);
/**
* Selects the protocol used by the client. See @{@link Protocol}
*/
RestClientConfigurationBuilder protocol(Protocol protocol);
/**
* Configure the client to use <a href="https://http2.github.io/http2-spec/#known-http">Prior Knowledge</a>
*/
RestClientConfigurationBuilder priorKnowledge(boolean enabled);
RestClientConfigurationBuilder followRedirects(boolean followRedirects);
/**
* This property defines the maximum socket connect timeout before giving up connecting to the server.
* Defaults to 60000 (1 minute)
*/
RestClientConfigurationBuilder connectionTimeout(long connectionTimeout);
/**
* This property defines the maximum socket read timeout in milliseconds before giving up waiting for bytes from the
* server. Defaults to 60000 (1 minute)
*/
RestClientConfigurationBuilder socketTimeout(long socketTimeout);
/**
* Security Configuration
*/
SecurityConfigurationBuilder security();
/**
* Affects TCP NODELAY on the TCP stack. Defaults to enabled
*/
RestClientConfigurationBuilder tcpNoDelay(boolean tcpNoDelay);
/**
* Affects TCP KEEPALIVE on the TCP stack. Defaults to disable
*/
RestClientConfigurationBuilder tcpKeepAlive(boolean keepAlive);
/**
* Configures this builder using the specified properties. See {@link RestClientConfigurationBuilder} for a list.
*/
RestClientConfigurationBuilder withProperties(Properties properties);
/**
* Builds a configuration object
*/
RestClientConfiguration build();
}
| 2,038
| 26.931507
| 119
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/SecurityConfigurationBuilder.java
|
package org.infinispan.client.rest.configuration;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
/**
* SecurityConfigurationBuilder.
*
* @author Tristan Tarrant
* @since 10.0
*/
public class SecurityConfigurationBuilder extends AbstractConfigurationChildBuilder implements
Builder<SecurityConfiguration> {
private final AuthenticationConfigurationBuilder authentication = new AuthenticationConfigurationBuilder(this);
private final SslConfigurationBuilder ssl = new SslConfigurationBuilder(this);
SecurityConfigurationBuilder(RestClientConfigurationBuilder 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();
}
RestClientConfigurationBuilder getBuilder() {
return super.builder;
}
}
| 1,550
| 25.288136
| 114
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/SslConfiguration.java
|
package org.infinispan.client.rest.configuration;
import java.util.Arrays;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
/**
* SslConfiguration.
*
* @author Tristan Tarrant
* @since 10.0
*/
public class SslConfiguration {
private final boolean enabled;
private final String keyStoreFileName;
private final String keyStoreType;
private final char[] keyStorePassword;
private final char[] keyStoreCertificatePassword;
private final String keyAlias;
private final SSLContext sslContext;
private final String trustStoreFileName;
private final String trustStorePath;
private final String trustStoreType;
private final char[] trustStorePassword;
private final String sniHostName;
private final String protocol;
private final String provider;
private final TrustManager[] trustManagers;
private final HostnameVerifier hostnameVerifier;
SslConfiguration(boolean enabled, String keyStoreFileName, String keyStoreType, char[] keyStorePassword, char[] keyStoreCertificatePassword, String keyAlias,
SSLContext sslContext, TrustManager[] trustManagers, HostnameVerifier hostnameVerifier,
String trustStoreFileName, String trustStorePath, String trustStoreType, char[] trustStorePassword, String sniHostName, String protocol,
String provider) {
this.enabled = enabled;
this.keyStoreFileName = keyStoreFileName;
this.keyStoreType = keyStoreType;
this.keyStorePassword = keyStorePassword;
this.keyStoreCertificatePassword = keyStoreCertificatePassword;
this.keyAlias = keyAlias;
this.sslContext = sslContext;
this.hostnameVerifier = hostnameVerifier;
this.trustManagers = trustManagers;
this.trustStoreFileName = trustStoreFileName;
this.trustStorePath = trustStorePath;
this.trustStoreType = trustStoreType;
this.trustStorePassword = trustStorePassword;
this.sniHostName = sniHostName;
this.protocol = protocol;
this.provider = provider;
}
public boolean enabled() {
return enabled;
}
public String keyStoreFileName() {
return keyStoreFileName;
}
public String keyStoreType() {
return keyStoreType;
}
public char[] keyStorePassword() {
return keyStorePassword;
}
public char[] keyStoreCertificatePassword() {
return keyStoreCertificatePassword;
}
public String keyAlias() {
return keyAlias;
}
public SSLContext sslContext() {
return sslContext;
}
public TrustManager[] trustManagers() {
return trustManagers;
}
public HostnameVerifier hostnameVerifier() {
return hostnameVerifier;
}
public String trustStoreFileName() {
return trustStoreFileName;
}
public String trustStorePath() {
return trustStorePath;
}
public String trustStoreType() {
return trustStoreType;
}
public char[] trustStorePassword() {
return trustStorePassword;
}
public String sniHostName() {
return sniHostName;
}
public String protocol() {
return protocol;
}
public String provider() {
return provider;
}
@Override
public String toString() {
return "SslConfiguration{" +
"enabled=" + enabled +
", keyStoreFileName='" + keyStoreFileName + '\'' +
", keyStoreType='" + keyStoreType + '\'' +
", keyAlias='" + keyAlias + '\'' +
", sslContext=" + sslContext +
", trustManagers=" + Arrays.toString(trustManagers) +
", trustStoreFileName='" + trustStoreFileName + '\'' +
", trustStoreType='" + trustStoreType + '\'' +
", sniHostName='" + sniHostName + '\'' +
", protocol='" + protocol + '\'' +
", provider='" + provider + '\'' +
'}';
}
}
| 3,934
| 27.722628
| 160
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/RestClientConfigurationBuilder.java
|
package org.infinispan.client.rest.configuration;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.function.BiConsumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.infinispan.client.rest.RestURI;
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.commons.util.Version;
/**
* <p>ConfigurationBuilder used to generate immutable {@link RestClientConfiguration} objects.
*
* <p>If you prefer to configure the client declaratively, see {@link org.infinispan.client.rest.configuration}</p>
*
* @author Tristan Tarrant
* @since 10.0
*/
public class RestClientConfigurationBuilder implements RestClientConfigurationChildBuilder, Builder<RestClientConfiguration> {
// Match IPv4 (host:port) or IPv6 ([host]:port) addresses
private static final Pattern ADDRESS_PATTERN = Pattern
.compile("(\\[([0-9A-Fa-f:]+)\\]|([^:/?#]*))(?::(\\d*))?");
private long connectionTimeout = RestClientConfigurationProperties.DEFAULT_CONNECT_TIMEOUT;
private long socketTimeout = RestClientConfigurationProperties.DEFAULT_SO_TIMEOUT;
private final List<ServerConfigurationBuilder> servers;
private final SecurityConfigurationBuilder security;
private boolean tcpNoDelay = true;
private boolean tcpKeepAlive = false;
private Protocol protocol = Protocol.HTTP_11;
private String contextPath = "/rest";
private boolean priorKnowledge;
private boolean followRedirects = true;
private Map<String, String> headers = new HashMap<>();
public RestClientConfigurationBuilder() {
this.security = new SecurityConfigurationBuilder(this);
this.servers = new ArrayList<>();
this.headers.put("User-Agent", Version.getBrandName() + "/" + Version.getVersion());
}
@Override
public AttributeSet attributes() {
return AttributeSet.EMPTY;
}
@Override
public ServerConfigurationBuilder addServer() {
ServerConfigurationBuilder builder = new ServerConfigurationBuilder(this);
this.servers.add(builder);
return builder;
}
@Override
public RestClientConfigurationBuilder addServers(String servers) {
parseServers(servers, (host, port) -> addServer().host(host).port(port));
return this;
}
public RestClientConfigurationBuilder clearServers() {
this.servers.clear();
return this;
}
public List<ServerConfigurationBuilder> servers() {
return servers;
}
private 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
? RestClientConfigurationProperties.DEFAULT_REST_PORT
: Integer.parseInt(portString);
c.accept(host, port);
} else {
throw new IllegalArgumentException(server);
}
}
}
@Override
public RestClientConfigurationBuilder protocol(Protocol protocol) {
this.protocol = protocol;
return this;
}
@Override
public RestClientConfigurationBuilder priorKnowledge(boolean enabled) {
this.priorKnowledge = enabled;
return this;
}
@Override
public RestClientConfigurationBuilder followRedirects(boolean followRedirects) {
this.followRedirects = followRedirects;
return this;
}
@Override
public RestClientConfigurationBuilder connectionTimeout(long connectionTimeout) {
this.connectionTimeout = connectionTimeout;
return this;
}
@Override
public SecurityConfigurationBuilder security() {
return security;
}
@Override
public RestClientConfigurationBuilder socketTimeout(long socketTimeout) {
this.socketTimeout = socketTimeout;
return this;
}
@Override
public RestClientConfigurationBuilder tcpNoDelay(boolean tcpNoDelay) {
this.tcpNoDelay = tcpNoDelay;
return this;
}
@Override
public RestClientConfigurationBuilder tcpKeepAlive(boolean keepAlive) {
this.tcpKeepAlive = keepAlive;
return this;
}
public RestClientConfigurationBuilder contextPath(String contextPath) {
this.contextPath = contextPath;
return this;
}
public RestClientConfigurationBuilder uri(URI uri) {
this.read(RestURI.create(uri).toConfigurationBuilder().build(false));
return this;
}
public RestClientConfigurationBuilder uri(String uri) {
this.read(RestURI.create(uri).toConfigurationBuilder().build(false));
return this;
}
public RestClientConfigurationBuilder header(String name, String value) {
headers.put(name, value);
return this;
}
@Override
public RestClientConfigurationBuilder withProperties(Properties properties) {
TypedProperties typed = TypedProperties.toTypedProperties(properties);
this.protocol(typed.getEnumProperty(RestClientConfigurationProperties.PROTOCOL, Protocol.class, protocol, true));
this.connectionTimeout(typed.getLongProperty(RestClientConfigurationProperties.CONNECT_TIMEOUT, connectionTimeout, true));
String serverList = typed.getProperty(RestClientConfigurationProperties.SERVER_LIST, null, true);
if (serverList != null) {
this.servers.clear();
this.addServers(serverList);
}
this.contextPath(typed.getProperty(RestClientConfigurationProperties.CONTEXT_PATH, contextPath, true));
this.socketTimeout(typed.getLongProperty(RestClientConfigurationProperties.SO_TIMEOUT, socketTimeout, true));
this.tcpNoDelay(typed.getBooleanProperty(RestClientConfigurationProperties.TCP_NO_DELAY, tcpNoDelay, true));
this.tcpKeepAlive(typed.getBooleanProperty(RestClientConfigurationProperties.TCP_KEEP_ALIVE, tcpKeepAlive, true));
this.security.ssl().withProperties(properties);
this.security.authentication().withProperties(properties);
return this;
}
@Override
public void validate() {
security.validate();
}
@Override
public RestClientConfiguration 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("127.0.0.1", RestClientConfigurationProperties.DEFAULT_REST_PORT));
}
return new RestClientConfiguration(servers, protocol, connectionTimeout, socketTimeout, security.create(), tcpNoDelay, tcpKeepAlive, contextPath, priorKnowledge, followRedirects, headers);
}
@Override
public RestClientConfiguration build() {
return build(true);
}
public RestClientConfiguration build(boolean validate) {
if (validate) {
validate();
}
return create();
}
@Override
public RestClientConfigurationBuilder read(RestClientConfiguration template, Combine combine) {
this.connectionTimeout = template.connectionTimeout();
if (combine.repeatedAttributes() == Combine.RepeatedAttributes.OVERRIDE) {
this.servers.clear();
this.headers.clear();
}
for (ServerConfiguration server : template.servers()) {
this.addServer().host(server.host()).port(server.port());
}
this.socketTimeout = template.socketTimeout();
this.security.read(template.security(), combine);
this.tcpNoDelay = template.tcpNoDelay();
this.tcpKeepAlive = template.tcpKeepAlive();
this.security.read(template.security(), combine);
this.headers.putAll(template.headers());
return this;
}
}
| 8,182
| 33.527426
| 194
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/SslConfigurationBuilder.java
|
package org.infinispan.client.rest.configuration;
import java.util.List;
import java.util.Properties;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
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.
*
* @author Tristan Tarrant
* @since 10.0
*/
public class SslConfigurationBuilder extends AbstractSecurityConfigurationChildBuilder implements Builder<SslConfiguration> {
private boolean enabled = false;
private String keyStoreFileName;
private String keyStoreType;
private char[] keyStorePassword;
private char[] keyStoreCertificatePassword;
private String keyAlias;
private String trustStorePath;
private String trustStoreFileName;
private String trustStoreType;
private char[] trustStorePassword;
private SSLContext sslContext;
private String sniHostName;
private String protocol;
private String provider;
private TrustManager[] trustManagers;
private HostnameVerifier hostnameVerifier;
protected SslConfigurationBuilder(SecurityConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return AttributeSet.EMPTY;
}
/**
* Disables the SSL support
*/
public SslConfigurationBuilder disable() {
this.enabled = false;
return this;
}
/**
* Enables the SSL support
*/
public SslConfigurationBuilder enable() {
this.enabled = true;
return this;
}
/**
* Enables or disables the SSL support
*/
public SslConfigurationBuilder enabled(boolean enabled) {
this.enabled = 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) {
this.keyStoreFileName = 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) {
this.keyStoreType = 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) {
this.keyStorePassword = keyStorePassword;
return enable();
}
/**
* Specifies the password needed to access private key associated with certificate stored in specified {@link
* #keyStoreFileName(String)}. If password is not specified, password provided in {@link #keyStorePassword(char[])}
* will be used. Setting this property also implicitly enables SSL/TLS (see {@link #enable()}<br>
* <b>Note:</b> this only works with some keystore types
*
* @deprecated since 9.3
*/
@Deprecated
public SslConfigurationBuilder keyStoreCertificatePassword(char[] keyStoreCertificatePassword) {
this.keyStoreCertificatePassword = keyStoreCertificatePassword;
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) {
this.keyAlias = keyAlias;
return enable();
}
/**
* Sets an {@link SSLContext}
*/
public SslConfigurationBuilder sslContext(SSLContext sslContext) {
this.sslContext = sslContext;
return enable();
}
/**
* Sets the {@link TrustManager}s used to create the {@link SSLContext}t
*/
public SslConfigurationBuilder trustManagers(TrustManager[] trustManagers) {
this.trustManagers = trustManagers;
return enable();
}
/**
* Sets the {@link HostnameVerifier} to use when validating certificates against hostnames
*/
public SslConfigurationBuilder hostnameVerifier(HostnameVerifier hostnameVerifier) {
this.hostnameVerifier = hostnameVerifier;
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) {
this.trustStoreFileName = trustStoreFileName;
return enable();
}
/**
* Specifies a path containing certificates in PEM format. An in-memory {@link java.security.KeyStore} will be built
* with all the certificates found undert that path. This is mutually exclusive with {@link #trustStoreFileName}
* Setting this property also implicitly enables SSL/TLS (see {@link #enable()}
*/
public SslConfigurationBuilder trustStorePath(String trustStorePath) {
this.trustStorePath = trustStorePath;
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) {
this.trustStoreType = 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) {
this.trustStorePassword = 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) {
this.sniHostName = sniHostName;
return enable();
}
/**
* Configures the secure socket protocol. Setting this property also implicitly enables SSL/TLS (see {@link
* #enable()}
*
* @param protocol The standard name of the requested protocol, e.g TLSv1.2
* @see SSLContext#getInstance(String)
*/
public SslConfigurationBuilder protocol(String protocol) {
this.protocol = protocol;
return enable();
}
/**
* Configures the security provider to use when initializing TLS. Setting this property also implicitly enables SSL/TLS (see {@link
* #enable()}
*
* @param provider The name of a security provider
* @see SSLContext#getInstance(String)
*/
public SslConfigurationBuilder provider(String provider) {
this.provider = provider;
return enable();
}
@Override
public void validate() {
if (enabled) {
if (sslContext == null) {
if (keyStoreFileName != null && keyStorePassword == null) {
throw new IllegalStateException("Missing key store password");
}
if (trustStoreFileName == null && trustStorePath == null) {
throw new IllegalStateException("No SSL TrustStore configuration");
}
if (trustStoreFileName != null && trustStorePath != null) {
throw new IllegalStateException("trustStoreFileName and trustStorePath are mutually exclusive");
}
if (trustStoreFileName != null && trustStorePassword == null) {
throw new IllegalStateException("Missing trust store password ");
}
} else {
if (keyStoreFileName != null || trustStoreFileName != null) {
throw new IllegalStateException("SSLContext and stores are mutually exclusive");
}
if (trustManagers == null) {
throw new IllegalStateException("SSLContext requires configuration of the TrustManagers");
}
}
}
}
@Override
public SslConfiguration create() {
return new SslConfiguration(enabled,
keyStoreFileName, keyStoreType, keyStorePassword, keyStoreCertificatePassword, keyAlias,
sslContext, trustManagers, hostnameVerifier,
trustStoreFileName, trustStorePath, trustStoreType, trustStorePassword,
sniHostName, protocol, provider);
}
@Override
public SslConfigurationBuilder read(SslConfiguration template, Combine combine) {
this.enabled = template.enabled();
this.keyStoreFileName = template.keyStoreFileName();
this.keyStoreType = template.keyStoreType();
this.keyStorePassword = template.keyStorePassword();
this.keyStoreCertificatePassword = template.keyStoreCertificatePassword();
this.keyAlias = template.keyAlias();
this.sslContext = template.sslContext();
this.hostnameVerifier = template.hostnameVerifier();
this.trustManagers = template.trustManagers();
this.trustStoreFileName = template.trustStoreFileName();
this.trustStorePath = template.trustStorePath();
this.trustStoreType = template.trustStoreType();
this.trustStorePassword = template.trustStorePassword();
this.sniHostName = template.sniHostName();
this.protocol = template.protocol();
this.provider = template.provider();
return this;
}
@Override
public RestClientConfigurationBuilder withProperties(Properties properties) {
TypedProperties typed = TypedProperties.toTypedProperties(properties);
if (typed.containsKey(RestClientConfigurationProperties.KEY_STORE_FILE_NAME))
this.keyStoreFileName(typed.getProperty(RestClientConfigurationProperties.KEY_STORE_FILE_NAME, keyStoreFileName, true));
if (typed.containsKey(RestClientConfigurationProperties.KEY_STORE_TYPE))
this.keyStoreType(typed.getProperty(RestClientConfigurationProperties.KEY_STORE_TYPE, null, true));
if (typed.containsKey(RestClientConfigurationProperties.KEY_STORE_PASSWORD))
this.keyStorePassword(typed.getProperty(RestClientConfigurationProperties.KEY_STORE_PASSWORD, null, true).toCharArray());
if (typed.containsKey(RestClientConfigurationProperties.KEY_STORE_CERTIFICATE_PASSWORD))
this.keyStoreCertificatePassword(typed.getProperty(RestClientConfigurationProperties.KEY_STORE_CERTIFICATE_PASSWORD, null, true).toCharArray());
if (typed.containsKey(RestClientConfigurationProperties.KEY_ALIAS))
this.keyAlias(typed.getProperty(RestClientConfigurationProperties.KEY_ALIAS, null, true));
if (typed.containsKey(RestClientConfigurationProperties.TRUST_STORE_FILE_NAME))
this.trustStoreFileName(typed.getProperty(RestClientConfigurationProperties.TRUST_STORE_FILE_NAME, trustStoreFileName, true));
if (typed.containsKey(RestClientConfigurationProperties.TRUST_STORE_PATH))
this.trustStorePath(typed.getProperty(RestClientConfigurationProperties.TRUST_STORE_PATH, trustStorePath, true));
if (typed.containsKey(RestClientConfigurationProperties.TRUST_STORE_TYPE))
this.trustStoreType(typed.getProperty(RestClientConfigurationProperties.TRUST_STORE_TYPE, null, true));
if (typed.containsKey(RestClientConfigurationProperties.TRUST_STORE_PASSWORD))
this.trustStorePassword(typed.getProperty(RestClientConfigurationProperties.TRUST_STORE_PASSWORD, null, true).toCharArray());
if (typed.containsKey(RestClientConfigurationProperties.SSL_PROTOCOL))
this.protocol(typed.getProperty(RestClientConfigurationProperties.SSL_PROTOCOL, null, true));
if (typed.containsKey(RestClientConfigurationProperties.PROVIDER))
this.provider(typed.getProperty(RestClientConfigurationProperties.PROVIDER, null, true));
if (typed.containsKey(RestClientConfigurationProperties.SNI_HOST_NAME))
this.sniHostName(typed.getProperty(RestClientConfigurationProperties.SNI_HOST_NAME, null, true));
if (typed.containsKey(RestClientConfigurationProperties.SSL_CONTEXT))
this.sslContext((SSLContext) typed.get(RestClientConfigurationProperties.SSL_CONTEXT));
if (typed.containsKey(RestClientConfigurationProperties.USE_SSL))
this.enabled(typed.getBooleanProperty(RestClientConfigurationProperties.USE_SSL, enabled, true));
return builder.getBuilder();
}
}
| 13,215
| 39.292683
| 153
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/AbstractSecurityConfigurationChildBuilder.java
|
package org.infinispan.client.rest.configuration;
/**
* AbstractSecurityConfigurationChildBuilder.
*
* @author Tristan Tarrant
* @since 10.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();
}
}
| 639
| 24.6
| 98
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/AuthenticationConfigurationBuilder.java
|
package org.infinispan.client.rest.configuration;
import java.util.Properties;
import javax.security.auth.Subject;
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;
/**
* AuthenticationConfigurationBuilder.
*
* @author Tristan Tarrant
* @since 10.0
*/
public class AuthenticationConfigurationBuilder extends AbstractSecurityConfigurationChildBuilder implements Builder<AuthenticationConfiguration> {
private boolean enabled = false;
private String mechanism;
private Subject clientSubject;
private String username;
private char[] password;
private String realm;
public AuthenticationConfigurationBuilder(SecurityConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return AttributeSet.EMPTY;
}
/**
* Configures whether authentication should be enabled or not
*/
public AuthenticationConfigurationBuilder enabled(boolean enabled) {
this.enabled = enabled;
return this;
}
/**
* Enables authentication
*/
public AuthenticationConfigurationBuilder enable() {
this.enabled = true;
return this;
}
/**
* Disables authentication
*/
public AuthenticationConfigurationBuilder disable() {
this.enabled = false;
return this;
}
/**
* Selects the authentication mechanism to use for the connection to the server. Setting this property also
* implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder mechanism(String mechanism) {
this.mechanism = mechanism;
return enable();
}
/**
* Sets the client subject, necessary for those mechanisms which require it to access client credentials (i.e.
* SPNEGO). Setting this property also implicitly enables authentication (see {@link #enable()}
*/
public AuthenticationConfigurationBuilder clientSubject(Subject clientSubject) {
this.clientSubject = 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 'ApplicationRealm'. Setting this property also implicitly enables authentication (see
* {@link #enable()}
*/
public AuthenticationConfigurationBuilder realm(String realm) {
this.realm = realm;
return enable();
}
@Override
public AuthenticationConfiguration create() {
String mech = mechanism == null ? "AUTO" : mechanism;
return new AuthenticationConfiguration(clientSubject, enabled, mech, realm, username, password);
}
@Override
public Builder<?> read(AuthenticationConfiguration template, Combine combine) {
this.username = template.username();
this.password = template.password();
this.clientSubject = template.clientSubject();
this.enabled = template.enabled();
this.mechanism = template.mechanism();
return this;
}
@Override
public RestClientConfigurationBuilder withProperties(Properties properties) {
TypedProperties typed = TypedProperties.toTypedProperties(properties);
if (typed.containsKey(RestClientConfigurationProperties.AUTH_MECHANISM))
mechanism(typed.getProperty(RestClientConfigurationProperties.AUTH_MECHANISM, mechanism, true));
if (typed.containsKey(RestClientConfigurationProperties.AUTH_USERNAME))
username(typed.getProperty(RestClientConfigurationProperties.AUTH_USERNAME, username, true));
if (typed.containsKey(RestClientConfigurationProperties.AUTH_PASSWORD))
password(typed.getProperty(RestClientConfigurationProperties.AUTH_PASSWORD, null, true));
if (typed.containsKey(RestClientConfigurationProperties.AUTH_REALM))
realm(typed.getProperty(RestClientConfigurationProperties.AUTH_REALM, realm, true));
if (typed.containsKey(RestClientConfigurationProperties.AUTH_CLIENT_SUBJECT))
this.clientSubject((Subject) typed.get(RestClientConfigurationProperties.AUTH_CLIENT_SUBJECT));
if (typed.containsKey(RestClientConfigurationProperties.USE_AUTH))
this.enabled(typed.getBooleanProperty(RestClientConfigurationProperties.USE_AUTH, enabled, true));
return builder.getBuilder();
}
}
| 5,577
| 34.528662
| 147
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/SecurityConfiguration.java
|
package org.infinispan.client.rest.configuration;
/**
* SecurityConfiguration.
*
* @author Tristan Tarrant
* @since 10.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;
}
}
| 587
| 20
| 92
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/Protocol.java
|
package org.infinispan.client.rest.configuration;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public enum Protocol {
HTTP_11,
HTTP_20
}
| 181
| 15.545455
| 57
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/AbstractConfigurationChildBuilder.java
|
package org.infinispan.client.rest.configuration;
import java.util.Properties;
/**
* AbstractConfigurationChildBuilder.
*
* @author Tristan Tarrant
* @since 10.0
*/
public abstract class AbstractConfigurationChildBuilder implements RestClientConfigurationChildBuilder {
final RestClientConfigurationBuilder builder;
protected AbstractConfigurationChildBuilder(RestClientConfigurationBuilder builder) {
this.builder = builder;
}
@Override
public ServerConfigurationBuilder addServer() {
return builder.addServer();
}
@Override
public RestClientConfigurationBuilder addServers(String servers) {
return builder.addServers(servers);
}
@Override
public RestClientConfigurationBuilder protocol(Protocol protocol) {
return builder.protocol(protocol);
}
@Override
public RestClientConfigurationBuilder connectionTimeout(long connectionTimeout) {
return builder.connectionTimeout(connectionTimeout);
}
@Override
public RestClientConfigurationBuilder priorKnowledge(boolean enabled) {
return builder.priorKnowledge(enabled);
}
@Override
public RestClientConfigurationBuilder followRedirects(boolean followRedirects) {
return builder.followRedirects(followRedirects);
}
@Override
public RestClientConfigurationBuilder socketTimeout(long socketTimeout) {
return builder.socketTimeout(socketTimeout);
}
@Override
public SecurityConfigurationBuilder security() {
return builder.security();
}
@Override
public RestClientConfigurationBuilder tcpNoDelay(boolean tcpNoDelay) {
return builder.tcpNoDelay(tcpNoDelay);
}
@Override
public RestClientConfigurationBuilder tcpKeepAlive(boolean tcpKeepAlive) {
return builder.tcpKeepAlive(tcpKeepAlive);
}
@Override
public RestClientConfigurationBuilder withProperties(Properties properties) {
return builder.withProperties(properties);
}
@Override
public RestClientConfiguration build() {
return builder.build();
}
}
| 2,058
| 25.063291
| 104
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/AuthenticationConfiguration.java
|
package org.infinispan.client.rest.configuration;
import javax.security.auth.Subject;
/**
* AuthenticationConfiguration.
*
* @author Tristan Tarrant
* @since 10.0
*/
public class AuthenticationConfiguration {
private final boolean enabled;
private final Subject clientSubject;
private final String mechanism;
private final String realm;
private final String username;
private final char[] password;
public AuthenticationConfiguration(Subject clientSubject, boolean enabled, String mechanism, String realm, String username, char[] password) {
this.enabled = enabled;
this.clientSubject = clientSubject;
this.mechanism = mechanism;
this.realm = realm;
this.username = username;
this.password = password;
}
public boolean enabled() {
return enabled;
}
public String mechanism() {
return mechanism;
}
public Subject clientSubject() {
return clientSubject;
}
public String realm() {
return realm;
}
public String username() {
return username;
}
public char[] password() {
return password;
}
}
| 1,135
| 20.433962
| 145
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/ServerConfigurationBuilder.java
|
package org.infinispan.client.rest.configuration;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.Combine;
import org.infinispan.commons.configuration.attributes.AttributeSet;
/**
* ServerConfigurationBuilder.
*
* @author Tristan Tarrant
* @since 10.0
*/
public class ServerConfigurationBuilder extends AbstractConfigurationChildBuilder implements Builder<ServerConfiguration> {
private String host;
private int port = RestClientConfigurationProperties.DEFAULT_REST_PORT;
ServerConfigurationBuilder(RestClientConfigurationBuilder builder) {
super(builder);
}
@Override
public AttributeSet attributes() {
return AttributeSet.EMPTY;
}
public ServerConfigurationBuilder host(String host) {
this.host = host;
return this;
}
public ServerConfigurationBuilder port(int port) {
this.port = port;
return this;
}
@Override
public void validate() {
if (host == null || host.isEmpty()) {
throw new IllegalStateException("Missing host definition");
}
}
@Override
public ServerConfiguration create() {
return new ServerConfiguration(host, port);
}
@Override
public ServerConfigurationBuilder read(ServerConfiguration template, Combine combine) {
this.host = template.host();
this.port = template.port();
return this;
}
}
| 1,414
| 23.824561
| 123
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/RestClientConfiguration.java
|
package org.infinispan.client.rest.configuration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.infinispan.commons.configuration.BuiltBy;
import org.infinispan.commons.util.TypedProperties;
/**
* Configuration.
*
* @author Tristan Tarrant
* @since 10.0
*/
@BuiltBy(RestClientConfigurationBuilder.class)
public class RestClientConfiguration {
private final long connectionTimeout;
private final List<ServerConfiguration> servers;
private final long socketTimeout;
private final SecurityConfiguration security;
private final boolean tcpNoDelay;
private final boolean tcpKeepAlive;
private final Protocol protocol;
private final String contextPath;
private final boolean priorKnowledge;
private final boolean followRedirects;
private final Map<String, String> headers;
RestClientConfiguration(List<ServerConfiguration> servers, Protocol protocol, long connectionTimeout, long socketTimeout, SecurityConfiguration security, boolean tcpNoDelay, boolean tcpKeepAlive, String contextPath, boolean priorKnowledge, boolean followRedirects, Map<String, String> headers) {
this.servers = Collections.unmodifiableList(servers);
this.protocol = protocol;
this.connectionTimeout = connectionTimeout;
this.socketTimeout = socketTimeout;
this.security = security;
this.tcpNoDelay = tcpNoDelay;
this.tcpKeepAlive = tcpKeepAlive;
this.contextPath = contextPath;
this.priorKnowledge = priorKnowledge;
this.followRedirects = followRedirects;
this.headers = headers;
}
public Protocol protocol() {
return protocol;
}
public boolean priorKnowledge() {
return priorKnowledge;
}
public boolean followRedirects() {
return followRedirects;
}
public long connectionTimeout() {
return connectionTimeout;
}
public List<ServerConfiguration> servers() {
return servers;
}
public long socketTimeout() {
return socketTimeout;
}
public SecurityConfiguration security() {
return security;
}
public boolean tcpNoDelay() {
return tcpNoDelay;
}
public boolean tcpKeepAlive() {
return tcpKeepAlive;
}
public String contextPath() {
return contextPath;
}
public Map<String, String> headers() {
return headers;
}
public Properties properties() {
TypedProperties properties = new TypedProperties();
properties.setProperty(RestClientConfigurationProperties.PROTOCOL, protocol().name());
properties.setProperty(RestClientConfigurationProperties.CONNECT_TIMEOUT, Long.toString(connectionTimeout()));
properties.setProperty(RestClientConfigurationProperties.SO_TIMEOUT, socketTimeout());
properties.setProperty(RestClientConfigurationProperties.TCP_NO_DELAY, tcpNoDelay());
properties.setProperty(RestClientConfigurationProperties.TCP_KEEP_ALIVE, tcpKeepAlive());
properties.setProperty(RestClientConfigurationProperties.CONTEXT_PATH, contextPath());
properties.setProperty(RestClientConfigurationProperties.USER_AGENT, headers.get("User-Agent"));
StringBuilder servers = new StringBuilder();
for (ServerConfiguration server : servers()) {
if (servers.length() > 0) {
servers.append(";");
}
servers.append(server.host()).append(":").append(server.port());
}
properties.setProperty(RestClientConfigurationProperties.SERVER_LIST, servers.toString());
properties.setProperty(RestClientConfigurationProperties.USE_SSL, Boolean.toString(security.ssl().enabled()));
if (security.ssl().keyStoreFileName() != null)
properties.setProperty(RestClientConfigurationProperties.KEY_STORE_FILE_NAME, security.ssl().keyStoreFileName());
if (security.ssl().keyStorePassword() != null)
properties.setProperty(RestClientConfigurationProperties.KEY_STORE_PASSWORD, new String(security.ssl().keyStorePassword()));
if (security.ssl().keyStoreCertificatePassword() != null)
properties.setProperty(RestClientConfigurationProperties.KEY_STORE_CERTIFICATE_PASSWORD, new String(security.ssl().keyStoreCertificatePassword()));
if (security.ssl().trustStoreFileName() != null)
properties.setProperty(RestClientConfigurationProperties.TRUST_STORE_FILE_NAME, security.ssl().trustStoreFileName());
if (security.ssl().trustStorePassword() != null)
properties.setProperty(RestClientConfigurationProperties.TRUST_STORE_PASSWORD, new String(security.ssl().trustStorePassword()));
if (security.ssl().sniHostName() != null)
properties.setProperty(RestClientConfigurationProperties.SNI_HOST_NAME, security.ssl().sniHostName());
if (security.ssl().protocol() != null)
properties.setProperty(RestClientConfigurationProperties.SSL_PROTOCOL, security.ssl().protocol());
if (security.ssl().sslContext() != null)
properties.put(RestClientConfigurationProperties.SSL_CONTEXT, security.ssl().sslContext());
if (security.ssl().trustManagers() != null)
properties.put(RestClientConfigurationProperties.TRUST_MANAGERS, security.ssl().trustManagers());
properties.setProperty(RestClientConfigurationProperties.USE_AUTH, Boolean.toString(security.authentication().enabled()));
if (security.authentication().mechanism() != null)
properties.setProperty(RestClientConfigurationProperties.AUTH_MECHANISM, security.authentication().mechanism());
return properties;
}
public String toURI() {
StringBuilder sb = new StringBuilder("http");
if (security.ssl().enabled()) {
sb.append('s');
}
sb.append("://");
if (security.authentication().enabled()) {
sb.append(security.authentication().username()).append(':').append(security.authentication().password()).append('@');
}
for (int i = 0; i < servers.size(); i++) {
if (i > 0) {
sb.append(";");
}
ServerConfiguration server = servers.get(i);
sb.append(server.host()).append(":").append(server.port());
}
return sb.toString();
}
}
| 6,226
| 36.512048
| 298
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/ServerConfiguration.java
|
package org.infinispan.client.rest.configuration;
/**
* ServerConfiguration.
*
* @author Tristan Tarrant
* @since 10.0
*/
public class ServerConfiguration {
private final String host;
private final int port;
ServerConfiguration(String host, int port) {
this.host = host;
this.port = port;
}
public String host() {
return host;
}
public int port() {
return port;
}
@Override
public String toString() {
return "ServerConfiguration[" +
"host='" + host + '\'' +
", port=" + port +
']';
}
}
| 595
| 16.529412
| 49
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/configuration/RestClientConfigurationProperties.java
|
package org.infinispan.client.rest.configuration;
import java.util.Properties;
import org.infinispan.commons.util.TypedProperties;
import org.infinispan.commons.util.Version;
/**
* Encapsulate all config properties here
*
* @author Tristan Tarrant
* @version 10.0
*/
public class RestClientConfigurationProperties {
public static final String ICR = "infinispan.client.rest.";
public static final String SERVER_LIST = ICR + "server_list";
public static final String CONTEXT_PATH = ICR + "context_path";
public static final String TCP_NO_DELAY = ICR + "tcp_no_delay";
public static final String TCP_KEEP_ALIVE = ICR + "tcp_keep_alive";
// Connection properties
public static final String PROTOCOL = ICR + "protocol";
public static final String SO_TIMEOUT = ICR + "socket_timeout";
public static final String CONNECT_TIMEOUT = ICR + "connect_timeout";
public static final String USER_AGENT = Version.printVersion();
// Encryption properties
public static final String USE_SSL = ICR + "use_ssl";
public static final String KEY_STORE_FILE_NAME = ICR + "key_store_file_name";
public static final String KEY_STORE_TYPE = ICR + "key_store_type";
public static final String KEY_STORE_PASSWORD = ICR + "key_store_password";
public static final String SNI_HOST_NAME = ICR + "sni_host_name";
public static final String KEY_ALIAS = ICR + "key_alias";
public static final String KEY_STORE_CERTIFICATE_PASSWORD = ICR + "key_store_certificate_password";
public static final String TRUST_STORE_FILE_NAME = ICR + "trust_store_file_name";
public static final String TRUST_STORE_PATH = ICR + "trust_store_path";
public static final String TRUST_STORE_TYPE = ICR + "trust_store_type";
public static final String TRUST_STORE_PASSWORD = ICR + "trust_store_password";
public static final String SSL_PROTOCOL = ICR + "ssl_protocol";
public static final String SSL_CONTEXT = ICR + "ssl_context";
public static final String TRUST_MANAGERS = ICR + "trust_managers";
public static final String PROVIDER = ICR + "provider";
// Authentication properties
public static final String USE_AUTH = ICR + "use_auth";
public static final String AUTH_MECHANISM = ICR + "sasl_mechanism";
public static final String AUTH_CALLBACK_HANDLER = ICR + "auth_callback_handler";
public static final String AUTH_SERVER_NAME = ICR + "auth_server_name";
public static final String AUTH_USERNAME = ICR + "auth_username";
public static final String AUTH_PASSWORD = ICR + "auth_password";
public static final String AUTH_REALM = ICR + "auth_realm";
public static final String AUTH_CLIENT_SUBJECT = ICR + "auth_client_subject";
// defaults
public static final int DEFAULT_REST_PORT = 11222;
public static final long DEFAULT_SO_TIMEOUT = 60_000;
public static final long DEFAULT_CONNECT_TIMEOUT = 60_000;
public static final int DEFAULT_MAX_RETRIES = 10;
public static final int DEFAULT_BATCH_SIZE = 10_000;
private final TypedProperties props;
public RestClientConfigurationProperties() {
this.props = new TypedProperties();
}
public RestClientConfigurationProperties(String serverList) {
this();
setServerList(serverList);
}
public RestClientConfigurationProperties(Properties props) {
this.props = props == null ? new TypedProperties() : TypedProperties.toTypedProperties(props);
}
public void setServerList(String serverList) {
props.setProperty(SERVER_LIST, serverList);
}
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 Properties getProperties() {
return props;
}
public Protocol getProtocol() {
return Protocol.valueOf(props.getProperty(PROTOCOL, Protocol.HTTP_11.name()));
}
public void setProtocol(Protocol protocol) {
props.setProperty(PROTOCOL, protocol.name());
}
public long getSoTimeout() {
return props.getLongProperty(SO_TIMEOUT, DEFAULT_SO_TIMEOUT);
}
public void setSocketTimeout(int socketTimeout) {
props.setProperty(SO_TIMEOUT, socketTimeout);
}
public long getConnectTimeout() {
return props.getLongProperty(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 getTrustStorePath() {
return props.getProperty(TRUST_STORE_PATH);
}
public void setTrustStorePath(String trustStorePath) {
props.setProperty(TRUST_STORE_PATH, trustStorePath);
}
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(AUTH_MECHANISM);
}
public void setSaslMechanism(String saslMechanism) {
props.setProperty(AUTH_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 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 String getServerList() {
return props.getProperty(SERVER_LIST);
}
}
| 8,438
| 30.606742
| 102
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestRawClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import java.io.Closeable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestEventListener;
import org.infinispan.client.rest.RestRawClient;
import org.infinispan.client.rest.RestResponse;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.internal.Util;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSources;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class RestRawClientOkHttp implements RestRawClient {
private final RestClientOkHttp restClient;
RestRawClientOkHttp(RestClientOkHttp restClient) {
this.restClient = restClient;
}
@Override
public CompletionStage<RestResponse> postForm(String url, Map<String, String> headers, Map<String, List<String>> formParameters) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
FormBody.Builder form = new FormBody.Builder();
formParameters.forEach((k, vs) -> vs.forEach(v -> form.add(k, v)));
builder.post(form.build());
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> postMultipartForm(String url, Map<String, String> headers, Map<String, List<String>> formParameters) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
MultipartBody.Builder form = new MultipartBody.Builder();
form.setType(MultipartBody.FORM);
formParameters.forEach((k, vs) -> vs.forEach(v -> form.addFormDataPart(k, v)));
builder.post(form.build());
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String url, String body, String bodyMediaType) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
builder.post(RequestBody.create(MediaType.parse(bodyMediaType), body));
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String url, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
builder.post(Util.EMPTY_REQUEST);
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String url, Map<String, String> headers, String body, String bodyMediaType) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
builder.post(RequestBody.create(MediaType.parse(bodyMediaType), body));
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> putValue(String url, Map<String, String> headers, String body, String bodyMediaType) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
builder.put(RequestBody.create(MediaType.parse(bodyMediaType), body));
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String url, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
builder.put(Util.EMPTY_REQUEST);
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> get(String url, Map<String, String> headers) {
Request.Builder builder = new Request.Builder().get().url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> delete(String url, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
builder.delete();
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> options(String url, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
builder.method("OPTIONS", Util.EMPTY_REQUEST);
return restClient.execute(builder);
}
@Override
public CompletionStage<RestResponse> head(String url, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
builder.head();
return restClient.execute(builder);
}
@Override
public Closeable listen(String url, Map<String, String> headers, RestEventListener listener) {
Request.Builder builder = new Request.Builder();
builder.url(restClient.getBaseURL() + url);
headers.forEach(builder::header);
EventSource.Factory factory = EventSources.createFactory(restClient.client());
EventSource eventSource = factory.newEventSource(builder.build(), new RestEventListenerOkHttp(listener));
return () -> eventSource.cancel();
}
}
| 5,498
| 37.454545
| 142
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/StringRestEntityOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.commons.dataconversion.MediaType;
import okhttp3.RequestBody;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class StringRestEntityOkHttp implements RestEntity, RestEntityAdaptorOkHttp {
private final MediaType contentType;
private final String body;
public StringRestEntityOkHttp(MediaType contentType, String body) {
this.contentType = contentType;
this.body = body;
}
@Override
public String getBody() {
return body;
}
@Override
public MediaType contentType() {
return contentType;
}
@Override
public RequestBody toRequestBody() {
return RequestBody.create(okhttp3.MediaType.get(contentType.toString()), body);
}
}
| 852
| 22.694444
| 85
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/InputStreamEntityOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import java.io.InputStream;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.commons.dataconversion.MediaType;
import okhttp3.RequestBody;
/**
* @since 12.0
*/
public class InputStreamEntityOkHttp implements RestEntity, RestEntityAdaptorOkHttp {
private final MediaType contentType;
private final InputStream inputStream;
public InputStreamEntityOkHttp(MediaType contentType, InputStream inputStream) {
this.contentType = contentType;
this.inputStream = inputStream;
}
@Override
public String getBody() {
throw new UnsupportedOperationException();
}
@Override
public MediaType contentType() {
return contentType;
}
@Override
public RequestBody toRequestBody() {
return new StreamRequestBody(okhttp3.MediaType.get(contentType.toString()), inputStream);
}
}
| 902
| 23.405405
| 95
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestContainerClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestContainerClient;
import org.infinispan.client.rest.RestResponse;
import okhttp3.Request;
/**
* @author Ryan Emerson
* @since 13.0
*/
public class RestContainerClientOkHttp implements RestContainerClient {
private final RestClientOkHttp client;
private final String baseClusterURL;
public RestContainerClientOkHttp(RestClientOkHttp client) {
this.client = client;
this.baseClusterURL = String.format("%s%s/v2/container", client.getBaseURL(), client.getConfiguration().contextPath()).replaceAll("//", "/");
}
@Override
public CompletionStage<RestResponse> shutdown() {
return client.execute(
new Request.Builder()
.post(EMPTY_BODY)
.url(baseClusterURL + "?action=shutdown")
);
}
}
| 995
| 28.294118
| 147
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestEntityAdaptorOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import okhttp3.RequestBody;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public interface RestEntityAdaptorOkHttp {
RequestBody toRequestBody();
}
| 237
| 18.833333
| 57
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/StreamRequestBody.java
|
package org.infinispan.client.rest.impl.okhttp;
import java.io.IOException;
import java.io.InputStream;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.BufferedSink;
import okio.Okio;
import okio.Source;
/**
* Support for {@link java.io.InputStream} to be used in POST and PUT {@link okhttp3.RequestBody}.
* @since 12.0
*/
public class StreamRequestBody extends RequestBody {
private final MediaType contentType;
private final InputStream inputStream;
public StreamRequestBody(MediaType contentType, InputStream inputStream) {
this.contentType = contentType;
this.inputStream = inputStream;
}
@Override
public MediaType contentType() {
return contentType;
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
try (Source source = Okio.source(inputStream)) {
sink.writeAll(source);
}
}
}
| 902
| 23.405405
| 98
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestResponseOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.client.rest.configuration.Protocol;
import org.infinispan.commons.dataconversion.MediaType;
import okhttp3.Response;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class RestResponseOkHttp implements RestResponse {
private final Response response;
RestResponseOkHttp(Response response) {
this.response = response;
}
@Override
public int getStatus() {
return response.code();
}
@Override
public Map<String, List<String>> headers() {
return response.headers().toMultimap();
}
@Override
public String getHeader(String header) {
List<String> values = response.headers(header);
if (values.isEmpty()) return null;
return String.join(",", values);
}
@Override
public String getBody() {
try {
return response.body().string();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public InputStream getBodyAsStream() {
return response.body().byteStream();
}
@Override
public byte[] getBodyAsByteArray() {
try {
return response.body().bytes();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public MediaType contentType() {
okhttp3.MediaType mediaType = response.body().contentType();
return mediaType == null ? null : MediaType.fromString(mediaType.toString());
}
@Override
public Protocol getProtocol() {
switch (response.protocol()) {
case H2_PRIOR_KNOWLEDGE:
case HTTP_2:
return Protocol.HTTP_20;
case HTTP_1_1:
return Protocol.HTTP_11;
default:
throw new IllegalStateException("Unknown protocol " + response.protocol());
}
}
@Override
public void close() {
response.close();
}
@Override
public boolean usedAuthentication() {
return !response.request().headers("Authorization").isEmpty();
}
}
| 2,226
| 22.691489
| 87
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestLoggingClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.sanitize;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestLoggingClient;
import org.infinispan.client.rest.RestResponse;
import okhttp3.Request;
import okhttp3.internal.Util;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 11.0
**/
public class RestLoggingClientOkHttp implements RestLoggingClient {
private final RestClientOkHttp client;
private final String baseLoggingURL;
RestLoggingClientOkHttp(RestClientOkHttp restClient) {
this.client = restClient;
this.baseLoggingURL = String.format("%s%s/v2/logging", restClient.getBaseURL(), restClient.getConfiguration().contextPath());
}
@Override
public CompletionStage<RestResponse> listLoggers() {
return client.execute(baseLoggingURL, "loggers");
}
@Override
public CompletionStage<RestResponse> listAppenders() {
return client.execute(baseLoggingURL, "appenders");
}
@Override
public CompletionStage<RestResponse> setLogger(String name, String level, String... appenders) {
Request.Builder builder = new Request.Builder();
StringBuilder sb = new StringBuilder(baseLoggingURL);
sb.append("/loggers/");
if (name != null) {
sb.append(sanitize(name));
}
sb.append("?");
boolean amp = false;
if (level != null) {
sb.append("level=").append(level);
amp = true;
}
if (appenders != null) {
for(String appender : appenders) {
if (amp) {
sb.append("&");
}
sb.append("appender=").append(appender);
amp = true;
}
}
builder.url(sb.toString()).put(Util.EMPTY_REQUEST);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> removeLogger(String name) {
Request.Builder builder = new Request.Builder();
builder.url(baseLoggingURL + "/loggers/" + sanitize(name)).delete();
return client.execute(builder);
}
}
| 2,135
| 29.084507
| 131
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestTaskClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.sanitize;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.client.rest.RestTaskClient;
import okhttp3.Request;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.1
**/
public class RestTaskClientOkHttp implements RestTaskClient {
private final RestClientOkHttp client;
private final String baseURL;
RestTaskClientOkHttp(RestClientOkHttp client) {
this.client = client;
this.baseURL = String.format("%s%s/v2/tasks", client.getBaseURL(), client.getConfiguration().contextPath()).replaceAll("//", "/");
}
@Override
public CompletionStage<RestResponse> list(ResultType resultType) {
return client.execute(baseURL + "?type=" + resultType.toString());
}
@Override
public CompletionStage<RestResponse> exec(String taskName, String cacheName, Map<String, ?> parameters) {
Objects.requireNonNull(taskName);
Objects.requireNonNull(parameters);
Request.Builder builder = new Request.Builder();
StringBuilder sb = new StringBuilder(baseURL).append('/').append(taskName);
sb.append("?action=exec");
if (cacheName != null) {
sb.append("&cache=");
sb.append(cacheName);
}
for (Map.Entry<String, ?> parameter : parameters.entrySet()) {
sb.append("¶m.");
sb.append(parameter.getKey());
sb.append('=');
sb.append(sanitize(parameter.getValue().toString()));
}
builder.url(sb.toString()).post(EMPTY_BODY);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> uploadScript(String taskName, RestEntity script) {
Request.Builder builder = new Request.Builder();
builder.url(baseURL + "/" + sanitize(taskName)).post(((RestEntityAdaptorOkHttp) script).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> downloadScript(String taskName) {
Request.Builder builder = new Request.Builder();
builder.url(baseURL + "/" + sanitize(taskName) + "?action=script");
return client.execute(builder);
}
}
| 2,462
| 34.695652
| 136
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestClusterClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestClusterClient;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.dataconversion.internal.Json;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class RestClusterClientOkHttp implements RestClusterClient {
private final RestClientOkHttp client;
private final String baseClusterURL;
RestClusterClientOkHttp(RestClientOkHttp restClient) {
this.client = restClient;
this.baseClusterURL = String.format("%s%s/v2/cluster", restClient.getBaseURL(), restClient.getConfiguration().contextPath()).replaceAll("//", "/");
}
@Override
public CompletionStage<RestResponse> stop() {
return stop(Collections.emptyList());
}
@Override
public CompletionStage<RestResponse> stop(List<String> servers) {
Request.Builder builder = new Request.Builder();
StringBuilder sb = new StringBuilder(baseClusterURL);
sb.append("?action=stop");
for (String server : servers) {
sb.append("&server=");
sb.append(server);
}
builder.post(EMPTY_BODY).url(sb.toString());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> createBackup(String name) {
RequestBody body = new StringRestEntityOkHttp(MediaType.APPLICATION_JSON, Json.object().toString()).toRequestBody();
return client.execute(backup(name).post(body));
}
@Override
public CompletionStage<RestResponse> getBackup(String name, boolean skipBody) {
Request.Builder builder = backup(name);
if (skipBody)
builder.head();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getBackupNames() {
Request.Builder builder = new Request.Builder().url(baseClusterURL + "/backups");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> deleteBackup(String name) {
return client.execute(backup(name).delete());
}
@Override
public CompletionStage<RestResponse> restore(String name, File backup) {
RequestBody zipBody = new FileRestEntityOkHttp(MediaType.APPLICATION_ZIP, backup).toRequestBody();
RequestBody multipartBody = new MultipartBody.Builder()
.addFormDataPart("backup", backup.getName(), zipBody)
.setType(MultipartBody.FORM)
.build();
Request.Builder builder = restore(name).post(multipartBody);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> restore(String name, String backupLocation) {
Json json = Json.object();
json.set("location", backupLocation);
RequestBody body = new StringRestEntityOkHttp(MediaType.APPLICATION_JSON, json.toString()).toRequestBody();
Request.Builder builder = restore(name).post(body);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getRestore(String name) {
return client.execute(restore(name).head());
}
@Override
public CompletionStage<RestResponse> getRestoreNames() {
return client.execute(new Request.Builder().url(baseClusterURL + "/restores"));
}
@Override
public CompletionStage<RestResponse> deleteRestore(String name) {
return client.execute(restore(name).delete());
}
@Override
public CompletionStage<RestResponse> distribution() {
Request.Builder builder = new Request.Builder();
builder.url(baseClusterURL + "?action=distribution").get();
return client.execute(builder);
}
private Request.Builder backup(String name) {
return new Request.Builder().url(baseClusterURL + "/backups/" + name);
}
private Request.Builder restore(String name) {
return new Request.Builder().url(baseClusterURL + "/restores/" + name);
}
}
| 4,252
| 32.226563
| 153
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestSchemasClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.TEXT_PLAIN;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.sanitize;
import static org.infinispan.commons.dataconversion.MediaType.TEXT_PLAIN_TYPE;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.client.rest.RestSchemaClient;
import okhttp3.Request;
import okhttp3.RequestBody;
/**
* @since 11.0
*/
public class RestSchemasClientOkHttp implements RestSchemaClient {
private final RestClientOkHttp client;
private final String baseUrl;
public RestSchemasClientOkHttp(RestClientOkHttp client) {
this.client = client;
this.baseUrl = String.format("%s%s/v2/schemas", client.getBaseURL(), client.getConfiguration().contextPath())
.replaceAll("//", "/");
}
@Override
public CompletionStage<RestResponse> names() {
return client.execute(baseUrl);
}
@Override
public CompletionStage<RestResponse> types() {
return client.execute(baseUrl + "?action=types");
}
@Override
public CompletionStage<RestResponse> post(String schemaName, String schemaContents) {
Request.Builder builder = new Request.Builder();
RequestBody body = RequestBody.create(TEXT_PLAIN, schemaContents);
builder.url(schemaUrl(schemaName)).post(body);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String schemaName, RestEntity schemaContents) {
Request.Builder builder = new Request.Builder();
builder.url(schemaUrl(schemaName)).post(((RestEntityAdaptorOkHttp)schemaContents).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String schemaName, String schemaContents) {
Request.Builder builder = new Request.Builder();
RequestBody body = RequestBody.create(TEXT_PLAIN, schemaContents);
builder.url(schemaUrl(schemaName)).put(body);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String schemaName, RestEntity schemaContents) {
Request.Builder builder = new Request.Builder();
builder.url(schemaUrl(schemaName)).put(((RestEntityAdaptorOkHttp)schemaContents).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> delete(String schemaName) {
Request.Builder builder = new Request.Builder();
builder.url(schemaUrl(schemaName)).delete();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> get(String schemaName) {
Request.Builder builder = new Request.Builder();
builder.header("Accept", TEXT_PLAIN_TYPE);
return client.execute(schemaUrl(schemaName));
}
private String schemaUrl(String name) {
return baseUrl + "/" + sanitize(name);
}
}
| 3,021
| 33.340909
| 115
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestEventListenerOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import org.infinispan.client.rest.RestEventListener;
import okhttp3.Response;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 13.0
**/
public class RestEventListenerOkHttp extends EventSourceListener {
private final RestEventListener listener;
public RestEventListenerOkHttp(RestEventListener listener) {
this.listener = listener;
}
@Override
public void onOpen(EventSource eventSource, Response response) {
listener.onOpen(new RestResponseOkHttp(response));
}
@Override
public void onEvent(EventSource eventSource, String id, String type, String data) {
listener.onMessage(id, type, data);
}
@Override
public void onClosed(EventSource eventSource) {
listener.close();
}
@Override
public void onFailure(EventSource eventSource, Throwable t, Response response) {
listener.onError(t, new RestResponseOkHttp(response));
}
}
| 1,050
| 24.634146
| 86
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/FileRestEntityOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import java.io.File;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.commons.dataconversion.MediaType;
import okhttp3.RequestBody;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class FileRestEntityOkHttp implements RestEntity, RestEntityAdaptorOkHttp {
private final MediaType contentType;
private final File file;
public FileRestEntityOkHttp(MediaType contentType, File file) {
this.contentType = contentType;
this.file = file;
}
@Override
public String getBody() {
throw new UnsupportedOperationException();
}
@Override
public MediaType contentType() {
return contentType;
}
@Override
public RequestBody toRequestBody() {
return RequestBody.create(okhttp3.MediaType.get(contentType.toString()), file);
}
}
| 896
| 22.605263
| 85
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestSecurityClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import java.util.List;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.client.rest.RestSecurityClient;
import okhttp3.Request;
import okhttp3.internal.Util;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 12.1
**/
public class RestSecurityClientOkHttp implements RestSecurityClient {
private final RestClientOkHttp client;
private final String baseSecurityURL;
public RestSecurityClientOkHttp(RestClientOkHttp restClient) {
this.client = restClient;
this.baseSecurityURL = String.format("%s%s/v2/security", restClient.getBaseURL(), restClient.getConfiguration().contextPath());
}
@Override
public CompletionStage<RestResponse> listPrincipals() {
return client.execute(baseSecurityURL, "principals");
}
@Override
public CompletionStage<RestResponse> listRoles(String principal) {
return client.execute(baseSecurityURL, "roles", principal);
}
@Override
public CompletionStage<RestResponse> grant(String principal, List<String> roles) {
return modifyAcl(principal, roles, "grant");
}
@Override
public CompletionStage<RestResponse> deny(String principal, List<String> roles) {
return modifyAcl(principal, roles, "deny");
}
private CompletionStage<RestResponse> modifyAcl(String principal, List<String> roles, String action) {
Request.Builder builder = new Request.Builder();
StringBuilder sb = new StringBuilder(baseSecurityURL);
sb.append("/roles/").append(principal).append("?action=").append(action);
for (String role : roles) {
sb.append("&role=").append(role);
}
builder.url(sb.toString()).put(Util.EMPTY_REQUEST);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> flushCache() {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(baseSecurityURL + "/cache?action=flush");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> createRole(String name, List<String> permissions) {
Request.Builder builder = new Request.Builder();
StringBuilder sb = new StringBuilder(baseSecurityURL);
sb.append("/permissions/").append(name).append('?');
for (int i = 0; i < permissions.size(); i++) {
if (i > 0) {
sb.append('&');
}
sb.append("permission=").append(permissions.get(i));
}
builder.url(sb.toString()).put(Util.EMPTY_REQUEST);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> removeRole(String name) {
Request.Builder builder = new Request.Builder();
builder.url(baseSecurityURL + "/permissions/" + name);
return client.execute(builder.delete());
}
@Override
public CompletionStage<RestResponse> describeRole(String name) {
Request.Builder builder = new Request.Builder();
builder.url(baseSecurityURL + "/permissions/" + name);
return client.execute(builder.get());
}
}
| 3,232
| 33.031579
| 133
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestCacheClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.TEXT_PLAIN;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.addEnumHeader;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.sanitize;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestCacheClient;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.commons.api.CacheContainerAdmin;
import org.infinispan.configuration.cache.XSiteStateTransferMode;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.internal.Util;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class RestCacheClientOkHttp implements RestCacheClient {
private final RestClientOkHttp client;
private final String name;
private final String cacheUrl;
private final String rollingUpgradeUrl;
RestCacheClientOkHttp(RestClientOkHttp restClient, String name) {
this.client = restClient;
this.name = name;
this.cacheUrl = String.format("%s%s/v2/caches/%s", restClient.getBaseURL(), restClient.getConfiguration().contextPath(), sanitize(name));
this.rollingUpgradeUrl = cacheUrl + "/rolling-upgrade";
}
@Override
public String name() {
return name;
}
@Override
public CompletionStage<RestResponse> health() {
Request.Builder builder = new Request.Builder().url(cacheUrl + "?action=health");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> clear() {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(cacheUrl + "?action=clear");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> exists() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl).head();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> synchronizeData(Integer readBatch, Integer threads) {
Request.Builder builder = new Request.Builder();
StringBuilder sb = new StringBuilder(cacheUrl + "?action=sync-data");
if (readBatch != null) {
sb.append("&read-batch=").append(readBatch);
}
if (threads != null) {
sb.append("&threads=").append(threads);
}
builder.post(EMPTY_BODY).url(sb.toString());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> synchronizeData() {
return synchronizeData(null, null);
}
@Override
public CompletionStage<RestResponse> disconnectSource() {
Request.Builder builder = new Request.Builder();
builder.url(rollingUpgradeUrl + "/source-connection").delete();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> connectSource(RestEntity value) {
Request.Builder builder = new Request.Builder();
builder.post(((RestEntityAdaptorOkHttp) value).toRequestBody()).url(rollingUpgradeUrl + "/source-connection");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> sourceConnected() {
Request.Builder builder = new Request.Builder();
builder.url(rollingUpgradeUrl + "/source-connection").head();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> sourceConnection() {
Request.Builder builder = new Request.Builder();
builder.url(rollingUpgradeUrl + "/source-connection").get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> size() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=size").get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String key, String value) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).post(RequestBody.create(TEXT_PLAIN, value));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String key, RestEntity value) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).post(((RestEntityAdaptorOkHttp) value).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String key, String value, long ttl, long maxIdle) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).post(RequestBody.create(TEXT_PLAIN, value));
addExpirationHeaders(builder, ttl, maxIdle);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> post(String key, RestEntity value, long ttl, long maxIdle) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).post(((RestEntityAdaptorOkHttp) value).toRequestBody());
addExpirationHeaders(builder, ttl, maxIdle);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, String value) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).put(RequestBody.create(TEXT_PLAIN, value));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, String keyContentType, RestEntity value) {
Request.Builder builder = new Request.Builder();
if (keyContentType != null) {
builder.addHeader("Key-Content-Type", keyContentType);
}
builder.url(cacheUrl + "/" + sanitize(key)).put(((RestEntityAdaptorOkHttp) value).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, String keyContentType, RestEntity value, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
if (keyContentType != null) {
builder.addHeader("Key-Content-Type", keyContentType);
}
builder.url(cacheUrl + "/" + sanitize(key)).put(((RestEntityAdaptorOkHttp) value).toRequestBody());
headers.forEach(builder::header);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, String keyContentType, RestEntity value, long ttl, long maxIdle) {
Request.Builder builder = new Request.Builder();
if (keyContentType != null) {
builder.addHeader("Key-Content-Type", keyContentType);
}
builder.url(cacheUrl + "/" + sanitize(key)).put(((RestEntityAdaptorOkHttp) value).toRequestBody());
addExpirationHeaders(builder, ttl, maxIdle);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, RestEntity value, String... flags) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).put(((RestEntityAdaptorOkHttp) value).toRequestBody());
if (flags.length > 0) {
builder.header("flags", String.join(",", flags));
}
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, RestEntity value) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).put(((RestEntityAdaptorOkHttp) value).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, String value, long ttl, long maxIdle) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).put(RequestBody.create(TEXT_PLAIN, value));
addExpirationHeaders(builder, ttl, maxIdle);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> put(String key, RestEntity value, long ttl, long maxIdle) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key)).put(((RestEntityAdaptorOkHttp) value).toRequestBody());
addExpirationHeaders(builder, ttl, maxIdle);
return client.execute(builder);
}
private void addExpirationHeaders(Request.Builder builder, long ttl, long maxIdle) {
if (ttl != 0) {
builder.addHeader("timeToLiveSeconds", Long.toString(ttl));
}
if (maxIdle != 0) {
builder.addHeader("maxIdleTimeSeconds", Long.toString(maxIdle));
}
}
@Override
public CompletionStage<RestResponse> get(String key) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> get(String key, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key));
headers.forEach(builder::header);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> get(String key, String mediaType) {
return get(key, mediaType, false);
}
@Override
public CompletionStage<RestResponse> get(String key, String mediaType, boolean extended) {
Request.Builder builder = new Request.Builder();
String url = cacheUrl + "/" + sanitize(key);
if (extended) {
url = url + "?extended=true";
}
builder.url(url);
if (mediaType != null) {
builder.header("Accept", mediaType);
}
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> head(String key) {
return head(key, Collections.emptyMap());
}
@Override
public CompletionStage<RestResponse> head(String key, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key) + "?extended").head();
headers.forEach(builder::header);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> remove(String key) {
return remove(key, Collections.emptyMap());
}
@Override
public CompletionStage<RestResponse> remove(String key, Map<String, String> headers) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key) + "?extended").delete();
headers.forEach(builder::header);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> createWithTemplate(String template, CacheContainerAdmin.AdminFlag... flags) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?template=" + template).post(EMPTY_BODY);
addEnumHeader("flags", builder, flags);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> createWithConfiguration(RestEntity configuration, CacheContainerAdmin.AdminFlag... flags) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl).post(((RestEntityAdaptorOkHttp) configuration).toRequestBody());
addEnumHeader("flags", builder, flags);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> delete() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl).delete();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> keys() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=keys").get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> keys(int limit) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=keys&limit=" + limit).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> entries() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=entries").get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> entries(boolean contentNegotiation) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=entries&content-negotiation=" + contentNegotiation).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> entries(int limit) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=entries&limit=" + limit).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> entries(int limit, boolean metadata) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=entries&metadata=" + metadata + "&limit=" + limit).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> keys(String mediaType) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=keys").get();
builder.header("Accept", mediaType);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> configuration(String mediaType) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=config");
if (mediaType != null) {
builder.header("Accept", mediaType);
}
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> stats() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=stats").get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> statsReset() {
Request.Builder builder = new Request.Builder();
builder.method("POST", new FormBody.Builder().build()).url(cacheUrl + "?action=stats-reset");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> distribution() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=distribution").get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> distribution(String key) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/" + sanitize(key) + "?action=distribution").get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> query(String query, boolean local) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "?action=search&query=" + sanitize(query) + "&local=" + local).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> query(String query, int maxResults, int offset) {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s?action=search&query=%s&max_results=%d&offset=%d", cacheUrl, sanitize(query), maxResults, offset)).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> query(String query, int maxResults, int offset, int hitCountAccuracy) {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s?action=search&query=%s&max_results=%d&offset=%d&hit_count_accuracy=%d", cacheUrl, sanitize(query), maxResults, offset, hitCountAccuracy)).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> xsiteBackups() {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s/x-site/backups/", cacheUrl));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> backupStatus(String site) {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s/x-site/backups/%s", cacheUrl, site));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> takeSiteOffline(String site) {
return executeXSiteOperation(site, "take-offline");
}
@Override
public CompletionStage<RestResponse> bringSiteOnline(String site) {
return executeXSiteOperation(site, "bring-online");
}
@Override
public CompletionStage<RestResponse> pushSiteState(String site) {
return executeXSiteOperation(site, "start-push-state");
}
@Override
public CompletionStage<RestResponse> cancelPushState(String site) {
return executeXSiteOperation(site, "cancel-push-state");
}
@Override
public CompletionStage<RestResponse> cancelReceiveState(String site) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(String.format("%s/x-site/backups/%s?action=%s", cacheUrl, site, "cancel-receive-state"));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> pushStateStatus() {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s/x-site/backups?action=push-state-status", cacheUrl));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> clearPushStateStatus() {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(String.format("%s/x-site/local?action=clear-push-state-status", cacheUrl));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getXSiteTakeOfflineConfig(String site) {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s/x-site/backups/%s/take-offline-config", cacheUrl, site));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> updateXSiteTakeOfflineConfig(String site, int afterFailures, long minTimeToWait) {
Request.Builder builder = new Request.Builder();
String url = String.format("%s/x-site/backups/%s/take-offline-config", cacheUrl, site);
String body = String.format("{\"after_failures\":%d,\"min_wait\":%d}", afterFailures, minTimeToWait);
builder.url(url);
builder.method("PUT", RequestBody.create(MediaType.parse("application/json"), body));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> xSiteStateTransferMode(String site) {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s/x-site/backups/%s/state-transfer-mode", cacheUrl, site));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> xSiteStateTransferMode(String site, XSiteStateTransferMode mode) {
Request.Builder builder = new Request.Builder();
builder.url(String.format("%s/x-site/backups/%s/state-transfer-mode?action=set&mode=%s", cacheUrl, site, mode.toString()));
return client.execute(builder.post(EMPTY_BODY));
}
private CompletionStage<RestResponse> executeXSiteOperation(String site, String action) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(String.format("%s/x-site/backups/%s?action=%s", cacheUrl, site, action));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> reindex() {
return executeIndexOperation("reindex", false);
}
@Override
public CompletionStage<RestResponse> reindexLocal() {
return executeIndexOperation("reindex", true);
}
@Override
public CompletionStage<RestResponse> clearIndex() {
return executeIndexOperation("clear", false);
}
@Override
public CompletionStage<RestResponse> updateIndexSchema() {
return executeIndexOperation("updateSchema", false);
}
@Override
public CompletionStage<RestResponse> queryStats() {
return executeSearchStatOperation("query", null);
}
@Override
public CompletionStage<RestResponse> indexStats() {
return executeSearchStatOperation("indexes", null);
}
@Override
public CompletionStage<RestResponse> clearQueryStats() {
return executeSearchStatOperation("query", "clear");
}
private CompletionStage<RestResponse> executeIndexOperation(String action, boolean local) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(String.format("%s/search/indexes?action=%s&local=%s", cacheUrl, action, local));
return client.execute(builder);
}
private CompletionStage<RestResponse> executeSearchStatOperation(String type, String action) {
Request.Builder builder = new Request.Builder();
String url = String.format("%s/search/%s/stats", cacheUrl, type);
if (action != null) {
url = url + "?action=" + action;
builder.post(EMPTY_BODY);
}
builder.url(url);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> details() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl).get();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> indexMetamodel() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/search/indexes/metamodel");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> searchStats() {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl + "/search/stats");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> clearSearchStats() {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(cacheUrl + "/search/stats?action=clear");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> enableRebalancing() {
return setRebalancing(true);
}
@Override
public CompletionStage<RestResponse> disableRebalancing() {
return setRebalancing(false);
}
private CompletionStage<RestResponse> setRebalancing(boolean enable) {
String action = enable ? "enable-rebalancing" : "disable-rebalancing";
return client.execute(
new Request.Builder()
.post(Util.EMPTY_REQUEST)
.url(cacheUrl + "?action=" + action)
);
}
@Override
public CompletionStage<RestResponse> updateWithConfiguration(RestEntity configuration, CacheContainerAdmin.AdminFlag... flags) {
Request.Builder builder = new Request.Builder();
builder.url(cacheUrl).put(((RestEntityAdaptorOkHttp) configuration).toRequestBody());
addEnumHeader("flags", builder, flags);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> updateConfigurationAttribute(String attribute, String value) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(cacheUrl + "?action=set-mutable-attribute&attribute-name=" + attribute + "&attribute-value=" + value);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> configurationAttributes() {
return configurationAttributes(false);
}
@Override
public CompletionStage<RestResponse> configurationAttributes(boolean full) {
Request.Builder builder = new Request.Builder();
builder.get().url(cacheUrl + "?action=get-mutable-attributes" + (full ? "&full=true" : ""));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getAvailability() {
return client.execute(new Request.Builder().url(cacheUrl + "?action=get-availability"));
}
@Override
public CompletionStage<RestResponse> setAvailability(String availability) {
return client.execute(
new Request.Builder()
.post(EMPTY_BODY)
.url(cacheUrl + "?action=set-availability&availability=" + availability)
);
}
@Override
public CompletionStage<RestResponse> markTopologyStable(boolean force) {
return client.execute(
new Request.Builder()
.post(EMPTY_BODY)
.url(cacheUrl + "?action=initialize&force=" + force)
);
}
}
| 24,512
| 35.861654
| 180
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/ByteArrayRestEntityOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import java.nio.charset.StandardCharsets;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.commons.dataconversion.MediaType;
import okhttp3.RequestBody;
/**
* @since 10.1
**/
public class ByteArrayRestEntityOkHttp implements RestEntity, RestEntityAdaptorOkHttp {
private final MediaType contentType;
private final byte[] body;
public ByteArrayRestEntityOkHttp(MediaType contentType, byte[] body) {
this.contentType = contentType;
this.body = body;
}
@Override
public String getBody() {
return new String(body, StandardCharsets.UTF_8);
}
@Override
public MediaType contentType() {
return contentType;
}
@Override
public RequestBody toRequestBody() {
return RequestBody.create(okhttp3.MediaType.get(contentType.toString()), body);
}
}
| 879
| 22.783784
| 87
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestCounterClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.sanitize;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestCounterClient;
import org.infinispan.client.rest.RestEntity;
import org.infinispan.client.rest.RestResponse;
import okhttp3.Request;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class RestCounterClientOkHttp implements RestCounterClient {
private final RestClientOkHttp client;
private final String name;
private final String counterUrl;
RestCounterClientOkHttp(RestClientOkHttp client, String name) {
this.client = client;
this.name = name;
this.counterUrl = String.format("%s%s/v2/counters/%s", client.getBaseURL(), client.getConfiguration().contextPath(), sanitize(name)).replaceAll("//", "/");
}
@Override
public CompletionStage<RestResponse> create(RestEntity configuration) {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl).post(((RestEntityAdaptorOkHttp) configuration).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> delete() {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl).delete();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> configuration() {
return configuration(null);
}
@Override
public CompletionStage<RestResponse> configuration(String mediaType) {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl + "/config");
if (mediaType != null) {
builder.header("Accept", mediaType);
}
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> get() {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> add(long delta) {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl + "?action=add&delta=" + delta).post(EMPTY_BODY);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> increment() {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl + "?action=increment").post(EMPTY_BODY);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> decrement() {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl + "?action=decrement").post(EMPTY_BODY);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> reset() {
Request.Builder builder = new Request.Builder();
builder.url(counterUrl + "?action=reset").post(EMPTY_BODY);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> compareAndSet(long expect, long value) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(counterUrl + "?action=compareAndSet&expect=" + expect + "&update=" + value);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> compareAndSwap(long expect, long value) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(counterUrl + "?action=compareAndSwap&expect=" + expect + "&update=" + value);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getAndSet(long newValue) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(counterUrl + "?action=getAndSet&value=" + newValue);
return client.execute(builder);
}
}
| 3,907
| 33.280702
| 161
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestServerClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import java.util.List;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.IpFilterRule;
import org.infinispan.client.rest.RestLoggingClient;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.client.rest.RestServerClient;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.dataconversion.internal.Json;
import okhttp3.FormBody;
import okhttp3.Request;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class RestServerClientOkHttp implements RestServerClient {
private final RestClientOkHttp client;
private final String baseServerURL;
RestServerClientOkHttp(RestClientOkHttp restClient) {
this.client = restClient;
this.baseServerURL = String.format("%s%s/v2/server", restClient.getBaseURL(), restClient.getConfiguration().contextPath()).replaceAll("//", "/");
}
@Override
public CompletionStage<RestResponse> configuration() {
return client.execute(baseServerURL, "config");
}
@Override
public CompletionStage<RestResponse> stop() {
Request.Builder builder = new Request.Builder().post(EMPTY_BODY).url(baseServerURL + "?action=stop");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> threads() {
return client.execute(baseServerURL, "threads");
}
@Override
public CompletionStage<RestResponse> info() {
return client.execute(baseServerURL);
}
@Override
public CompletionStage<RestResponse> memory() {
return client.execute(baseServerURL, "memory");
}
@Override
public CompletionStage<RestResponse> heapDump(boolean live) {
String url = String.format("%s/memory?action=heap-dump&live=%b", baseServerURL, live);
return client.execute(new Request.Builder().url(url).method("POST",new FormBody.Builder().build()));
}
@Override
public CompletionStage<RestResponse> env() {
return client.execute(baseServerURL, "env");
}
@Override
public CompletionStage<RestResponse> report() {
return client.execute(baseServerURL, "report");
}
@Override
public CompletionStage<RestResponse> report(String node) {
return client.execute(baseServerURL, "report", node);
}
@Override
public CompletionStage<RestResponse> ignoreCache(String cacheManagerName, String cacheName) {
return ignoreCacheOp(cacheManagerName, cacheName, "POST");
}
@Override
public CompletionStage<RestResponse> unIgnoreCache(String cacheManagerName, String cacheName) {
return ignoreCacheOp(cacheManagerName, cacheName, "DELETE");
}
private CompletionStage<RestResponse> ignoreCacheOp(String cacheManagerName, String cacheName, String method) {
String url = String.format("%s/ignored-caches/%s/%s", baseServerURL, cacheManagerName, cacheName);
Request.Builder builder = new Request.Builder().url(url).method(method, new FormBody.Builder().build());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> listIgnoredCaches(String cacheManagerName) {
String url = String.format("%s/ignored-caches/%s", baseServerURL, cacheManagerName);
return client.execute(new Request.Builder().url(url));
}
@Override
public RestLoggingClient logging() {
return new RestLoggingClientOkHttp(client);
}
@Override
public CompletionStage<RestResponse> listConnections(boolean global) {
return client.execute(baseServerURL, "connections?global=" + global);
}
@Override
public CompletionStage<RestResponse> connectorNames() {
return client.execute(baseServerURL, "connectors");
}
@Override
public CompletionStage<RestResponse> connectorStart(String name) {
String url = String.format("%s/connectors/%s?action=start", baseServerURL, name);
Request.Builder builder = new Request.Builder().url(url).post(new FormBody.Builder().build());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> connectorStop(String name) {
String url = String.format("%s/connectors/%s?action=stop", baseServerURL, name);
Request.Builder builder = new Request.Builder().url(url).post(new FormBody.Builder().build());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> connector(String name) {
return client.execute(baseServerURL, "connectors", name);
}
@Override
public CompletionStage<RestResponse> connectorIpFilters(String name) {
return client.execute(baseServerURL, "connectors", name, "ip-filter");
}
@Override
public CompletionStage<RestResponse> connectorIpFiltersClear(String name) {
String url = String.format("%s/connectors/%s/ip-filter", baseServerURL, name);
Request.Builder builder = new Request.Builder().url(url).delete();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> connectorIpFilterSet(String name, List<IpFilterRule> rules) {
String url = String.format("%s/connectors/%s/ip-filter", baseServerURL, name);
Json json = Json.array();
for (IpFilterRule rule : rules) {
json.add(Json.object().set("type", rule.getType().name()).set("cidr", rule.getCidr()));
}
Request.Builder builder = new Request.Builder().url(url).post(new StringRestEntityOkHttp(MediaType.APPLICATION_JSON, json.toString()).toRequestBody());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> dataSourceNames() {
return client.execute(baseServerURL, "datasources");
}
@Override
public CompletionStage<RestResponse> dataSourceTest(String name) {
String url = String.format("%s/datasources/%s?action=test", baseServerURL, name);
Request.Builder builder = new Request.Builder().url(url).post(new FormBody.Builder().build());
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> cacheConfigDefaults() {
return client.execute(baseServerURL+ "/caches/defaults");
}
}
| 6,254
| 34.948276
| 157
|
java
|
null |
infinispan-main/client/rest-client/src/main/java/org/infinispan/client/rest/impl/okhttp/RestCacheManagerClientOkHttp.java
|
package org.infinispan.client.rest.impl.okhttp;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.EMPTY_BODY;
import static org.infinispan.client.rest.impl.okhttp.RestClientOkHttp.sanitize;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletionStage;
import org.infinispan.client.rest.RestCacheManagerClient;
import org.infinispan.client.rest.RestResponse;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.dataconversion.internal.Json;
import okhttp3.FormBody;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.internal.Util;
/**
* @author Tristan Tarrant <tristan@infinispan.org>
* @since 10.0
**/
public class RestCacheManagerClientOkHttp implements RestCacheManagerClient {
private final RestClientOkHttp client;
private final String name;
private final String baseCacheManagerUrl;
RestCacheManagerClientOkHttp(RestClientOkHttp client, String name) {
this.client = client;
this.name = name;
this.baseCacheManagerUrl = String.format("%s%s/v2/cache-managers/%s", client.getBaseURL(), client.getConfiguration().contextPath(), sanitize(name)).replaceAll("//", "/");
}
@Override
public String name() {
return name;
}
@Override
public CompletionStage<RestResponse> globalConfiguration(String mediaType) {
Request.Builder builder = new Request.Builder();
builder.url(baseCacheManagerUrl + "/config").header("Accept", mediaType);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> cacheConfigurations() {
return client.execute(baseCacheManagerUrl, "cache-configs");
}
@Override
public CompletionStage<RestResponse> cacheConfigurations(String mediaType) {
Request.Builder builder = new Request.Builder();
builder.url(baseCacheManagerUrl + "/cache-configs").header("Accept", mediaType);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> templates(String mediaType) {
Request.Builder builder = new Request.Builder();
builder.url(baseCacheManagerUrl + "/cache-configs/templates").header("Accept", mediaType);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> info() {
return client.execute(baseCacheManagerUrl);
}
@Override
public CompletionStage<RestResponse> stats() {
return client.execute(baseCacheManagerUrl, "stats");
}
@Override
public CompletionStage<RestResponse> statsReset() {
Request.Builder builder = new Request.Builder();
builder.method("POST",new FormBody.Builder().build()).url(baseCacheManagerUrl + "/stats?action=reset");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> backupStatuses() {
return client.execute(baseCacheManagerUrl, "x-site", "backups");
}
@Override
public CompletionStage<RestResponse> backupStatus(String site) {
return client.execute(baseCacheManagerUrl, "x-site", "backups", site);
}
@Override
public CompletionStage<RestResponse> bringBackupOnline(String backup) {
return executeXSiteOperation(backup, "bring-online");
}
@Override
public CompletionStage<RestResponse> takeOffline(String backup) {
return executeXSiteOperation(backup, "take-offline");
}
@Override
public CompletionStage<RestResponse> pushSiteState(String backup) {
return executeXSiteOperation(backup, "start-push-state");
}
@Override
public CompletionStage<RestResponse> cancelPushState(String backup) {
return executeXSiteOperation(backup, "cancel-push-state");
}
private CompletionStage<RestResponse> executeXSiteOperation(String backup, String operation) {
Request.Builder builder = new Request.Builder();
builder.post(EMPTY_BODY).url(String.format("%s/x-site/backups/%s?action=%s", baseCacheManagerUrl, backup, operation));
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> health() {
return health(false);
}
@Override
public CompletionStage<RestResponse> health(boolean skipBody) {
Request.Builder builder = new Request.Builder().url(baseCacheManagerUrl);
if (skipBody) {
builder.head();
}
builder.url(baseCacheManagerUrl + "/health");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> healthStatus() {
return client.execute(baseCacheManagerUrl, "health", "status");
}
@Override
public CompletionStage<RestResponse> caches() {
return client.execute(baseCacheManagerUrl, "caches");
}
@Override
public CompletionStage<RestResponse> createBackup(String name, String workingDir, Map<String, List<String>> resources) {
Json json = Json.object();
if (workingDir != null)
json.set("directory", workingDir);
if (resources != null)
json.set("resources", Json.factory().make(resources));
RequestBody body = new StringRestEntityOkHttp(MediaType.APPLICATION_JSON, json.toString()).toRequestBody();
Request.Builder builder = backup(name).post(body);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getBackup(String name, boolean skipBody) {
Request.Builder builder = backup(name);
if (skipBody)
builder.head();
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getBackupNames() {
Request.Builder builder = new Request.Builder().url(baseCacheManagerUrl + "/backups");
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> deleteBackup(String name) {
return client.execute(backup(name).delete());
}
@Override
public CompletionStage<RestResponse> restore(String name, File backup, Map<String, List<String>> resources) {
Json json = resources != null ? Json.factory().make(resources) : Json.object();
RequestBody zipBody = new FileRestEntityOkHttp(MediaType.APPLICATION_ZIP, backup).toRequestBody();
RequestBody multipartBody = new MultipartBody.Builder()
.addFormDataPart("resources", json.toString())
.addFormDataPart("backup", backup.getName(), zipBody)
.setType(MultipartBody.FORM)
.build();
Request.Builder builder = restore(name).post(multipartBody);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> restore(String name, String backupLocation, Map<String, List<String>> resources) {
Json json = Json.object();
json.set("location", backupLocation);
if (resources != null)
json.set("resources", Json.factory().make(resources));
RequestBody body = new StringRestEntityOkHttp(MediaType.APPLICATION_JSON, json.toString()).toRequestBody();
Request.Builder builder = restore(name).post(body);
return client.execute(builder);
}
@Override
public CompletionStage<RestResponse> getRestore(String name) {
return client.execute(restore(name).head());
}
@Override
public CompletionStage<RestResponse> getRestoreNames() {
return client.execute(new Request.Builder().url(baseCacheManagerUrl + "/restores"));
}
@Override
public CompletionStage<RestResponse> deleteRestore(String name) {
return client.execute(restore(name).delete());
}
@Override
public CompletionStage<RestResponse> enableRebalancing() {
return setRebalancing(true);
}
@Override
public CompletionStage<RestResponse> disableRebalancing() {
return setRebalancing(false);
}
private CompletionStage<RestResponse> setRebalancing(boolean enable) {
String action = enable ? "enable-rebalancing" : "disable-rebalancing";
return client.execute(
new Request.Builder()
.post(Util.EMPTY_REQUEST)
.url(baseCacheManagerUrl + "?action=" + action)
);
}
private Request.Builder backup(String name) {
return new Request.Builder().url(baseCacheManagerUrl + "/backups/" + name);
}
private Request.Builder restore(String name) {
return new Request.Builder().url(baseCacheManagerUrl + "/restores/" + name);
}
}
| 8,405
| 32.624
| 176
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.