Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-15441 Embedded API 2.0 #11651

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public int hashCode() {
@Override
public String toString() {
if (this == IMMORTAL) {
return "Impl{IMMORTAL}";
return "{IMMORTAL}";
} else if (this == DEFAULT) {
return "Impl{DEFAULT}";
return "{DEFAULT}";
} else {
return "Impl{" +
return "{" +
"lifespan=" + lifespan +
", maxIdle=" + maxIdle +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
* @since 14.0
**/
public interface CacheEntryMetadata {

/**
* If the entry is mortal, returns an {@link Instant} representing its creation time,
* If the entry is immortal, returns {@link Optional#empty()}
*/
Optional<Instant> creationTime();

Optional<Instant> lastAccessTime();
Expand Down
14 changes: 14 additions & 0 deletions api/src/main/java/org/infinispan/api/common/CacheOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,28 @@
* @since 14.0
**/
public interface CacheOptions {
/**
* The default options:
* <ul>
* <li>No timeout</li>
* <li>No flags</li>
* </ul>
*/
CacheOptions DEFAULT = new Impl();

static Builder options() {
return new Builder();
}

/**
* How long to wait for an operation to complete. This only applies to synchronous calls.
* Timeouts for asynchronous and reactive calls must be handled by the application.
*/
Optional<Duration> timeout();

/**
* Context-specific flags to apply to the operation.
*/
Optional<Flags<?, ?>> flags();

class Impl implements CacheOptions {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.infinispan.api.common.events.cache;

/**
* @since 14.0
**/
public interface CacheEntryRemovedEvent<K, V> extends CacheEntryEvent<K, V> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.infinispan.api.common.events.cache;

/**
* @since 15.0
**/
public interface CacheEntryUpdatedEvent<K, V> extends CacheEntryEvent<K, V> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.infinispan.api.common.events.container;

public interface Address {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.infinispan.api.common.events.cache;
package org.infinispan.api.common.events.container;

import org.infinispan.api.common.events.container.ContainerEvent;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.infinispan.api.common.events.cache;
package org.infinispan.api.common.events.container;

import org.infinispan.api.common.events.container.ContainerEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public enum ContainerListenerEventType {
CACHE_STARTED,
CACHE_STOPPED,
CONFIGURATION_CHANGED,
CLUSTER_MERGED,
VIEW_CHANGED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.infinispan.api.common.events.container;

import java.util.List;

/**
* @since 15.0
**/
public interface ViewChangeEvent extends ContainerEvent {
/**
* Gets the current list of members.
*
* @return the new view associated with this view change. List cannot be null.
*/
List<Address> newMembers();

/**
* Gets the previous list of members.
*
* @return the old view associated with this view change. List cannot be null.
*/
List<Address> oldMembers();

Address localAddress();

int viewId();

boolean isMergeView();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public InfinispanException(String message) {
super(message);
}

public InfinispanException(Throwable throwable) {
super(throwable);
}

public InfinispanException(String message, Throwable throwable) {
super(message, throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @since 14.0
**/
@FunctionalInterface
public interface SyncCacheEntryCreatedListener<K, V> extends SyncCacheEntryListener<K, V> {
void onCreate(CacheEntryEvent<K, V> event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @since 14.0
**/
@FunctionalInterface
public interface SyncCacheEntryExpiredListener<K, V> extends SyncCacheEntryListener<K, V> {
void onExpired(CacheEntryEvent<K, V> event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @since 14.0
**/
@FunctionalInterface
public interface SyncCacheEntryRemovedListener<K, V> extends SyncCacheEntryListener<K, V> {
void onRemove(CacheEntryEvent<K, V> event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/**
* @since 14.0
**/
@FunctionalInterface
public interface SyncCacheEntryUpdatedListener<K, V> extends SyncCacheEntryListener<K, V> {
void onUpdate(CacheEntryEvent<K, V> event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.infinispan.api.sync.events.container;

import org.infinispan.api.common.events.container.CacheStartEvent;

@FunctionalInterface
public interface SyncContainerCacheStartedListener {
void onCacheStart(CacheStartEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.infinispan.api.sync.events.container;

import org.infinispan.api.common.events.container.CacheStopEvent;

@FunctionalInterface
public interface SyncContainerCacheStoppedListener {
void onCacheStop(CacheStopEvent event);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.infinispan.api.sync.events.container;

import org.infinispan.api.common.events.container.ViewChangeEvent;

@FunctionalInterface
public interface SyncContainerViewChangedListener {
void onViewChanged(ViewChangeEvent event);
}
8 changes: 4 additions & 4 deletions api/src/test/java/org/infinispan/api/SyncCacheAPIDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void demo() {
mycache.entries().forEach(e -> System.out.printf("key=%s, value=%s%n", e.key(), e.value()));

// Event handling
mycache.listen((SyncCacheEntryCreatedListener<String, String>) event -> {
AutoCloseable listener = mycache.listen((SyncCacheEntryCreatedListener<String, String>) event -> {
// Handle create event
});

Expand Down Expand Up @@ -92,15 +92,15 @@ public void accept(T t) {
}
}

public static class NullListener implements SyncCacheEntryUpdatedListener, SyncCacheEntryRemovedListener {
public static class NullListener<K, V> implements SyncCacheEntryUpdatedListener<K, V>, SyncCacheEntryRemovedListener<K, V> {

@Override
public void onRemove(CacheEntryEvent event) {
public void onRemove(CacheEntryEvent<K, V> event) {

}

@Override
public void onUpdate(CacheEntryEvent event) {
public void onUpdate(CacheEntryEvent<K, V> event) {

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,52 +61,52 @@ public HotRodSyncContainer container() {

@Override
public CacheEntry<K, V> getEntry(K key, CacheOptions options) {
return await(remoteCache.getEntry(key, options));
return await(remoteCache.getEntry(key, options), options);
}

@Override
public CacheEntry<K, V> put(K key, V value, CacheWriteOptions options) {
return await(remoteCache.put(key, value, options));
return await(remoteCache.put(key, value, options), options);
}

@Override
public void set(K key, V value, CacheWriteOptions options) {
await(remoteCache.set(key, value, options));
await(remoteCache.set(key, value, options), options);
}

@Override
public CacheEntry<K, V> putIfAbsent(K key, V value, CacheWriteOptions options) {
return await(remoteCache.putIfAbsent(key, value, options));
return await(remoteCache.putIfAbsent(key, value, options), options);
}

@Override
public boolean setIfAbsent(K key, V value, CacheWriteOptions options) {
return await(remoteCache.setIfAbsent(key, value, options));
return await(remoteCache.setIfAbsent(key, value, options), options);
}

@Override
public boolean replace(K key, V value, CacheEntryVersion version, CacheWriteOptions options) {
return await(remoteCache.replace(key, value, version, options));
return await(remoteCache.replace(key, value, version, options), options);
}

@Override
public CacheEntry<K, V> getOrReplaceEntry(K key, V value, CacheEntryVersion version, CacheWriteOptions options) {
return await(remoteCache.getOrReplaceEntry(key, value, version, options));
return await(remoteCache.getOrReplaceEntry(key, value, version, options), options);
}

@Override
public boolean remove(K key, CacheOptions options) {
return await(remoteCache.remove(key, options));
return await(remoteCache.remove(key, options), options);
}

@Override
public boolean remove(K key, CacheEntryVersion version, CacheOptions options) {
return await(remoteCache.remove(key, version, options));
return await(remoteCache.remove(key, version, options), options);
}

@Override
public CacheEntry<K, V> getAndRemove(K key, CacheOptions options) {
return await(remoteCache.getAndRemove(key, options));
return await(remoteCache.getAndRemove(key, options), options);
}

@Override
Expand All @@ -121,7 +121,7 @@ public CloseableIterable<CacheEntry<K, V>> entries(CacheOptions options) {

@Override
public void putAll(Map<K, V> entries, CacheWriteOptions options) {
await(remoteCache.putAll(entries, options));
await(remoteCache.putAll(entries, options), options);
}

@Override
Expand Down Expand Up @@ -150,12 +150,12 @@ public Map<K, CacheEntry<K, V>> getAndRemoveAll(Set<K> keys, CacheWriteOptions o

@Override
public long estimateSize(CacheOptions options) {
return await(remoteCache.estimateSize(options));
return await(remoteCache.estimateSize(options), options);
}

@Override
public void clear(CacheOptions options) {
await(remoteCache.clear(options));
await(remoteCache.clear(options), options);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public HotRodSyncLocks locks() {

@Override
public void listen(SyncContainerListener listener, ContainerListenerEventType... types) {

}

@Override
Expand Down
15 changes: 10 additions & 5 deletions client/hotrod/src/main/java/org/infinispan/hotrod/impl/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import javax.transaction.xa.Xid;

import org.infinispan.api.common.CacheOptions;
import org.infinispan.commons.CacheException;
import org.infinispan.commons.marshall.WrappedByteArray;
import org.infinispan.hotrod.exceptions.HotRodClientException;
Expand Down Expand Up @@ -41,14 +42,18 @@ public byte[] getBranchQualifier() {
private Util() {
}

public static <T> T await(CompletionStage<T> cf) {
return await(cf.toCompletableFuture());
public static <T> T await(CompletionStage<T> cf, CacheOptions options) {
return await(cf.toCompletableFuture(), options);
}

public static <T> T await(CompletableFuture<T> cf) {
public static <T> T await(CompletableFuture<T> cf, CacheOptions options) {
try {
// timed wait does not do busy waiting
return cf.get(BIG_DELAY_NANOS, TimeUnit.NANOSECONDS);
if (options.timeout().isPresent()) {
return cf.get(options.timeout().get().toNanos(), TimeUnit.NANOSECONDS);
} else {
// timed wait does not do busy waiting
return cf.get(BIG_DELAY_NANOS, TimeUnit.NANOSECONDS);
}
} catch (InterruptedException e) {
// Need to restore interrupt status because InterruptedException cannot be sent back as is
Thread.currentThread().interrupt();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.infinispan.commons.api;

import java.util.EnumSet;
import java.util.concurrent.CompletionStage;

import org.infinispan.commons.configuration.BasicConfiguration;

Expand Down Expand Up @@ -105,6 +106,13 @@ public static EnumSet<AdminFlag> fromString(String s) {
*/
void removeCache(String name);

/**
* Asynchronously removes a cache from the cache container. Any persisted data will be cleared.
*
* @param name the name of the cache to remove
*/
CompletionStage<Void> removeCacheAsync(String name);

/**
* Sets any additional {@link AdminFlag}s to be used when performing administrative operations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import static java.util.Objects.requireNonNull;

import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,5 @@ public interface BasicMultimapCache<K, V> {
*/
boolean supportsDuplicates();

String getName();
}
Loading
Loading