From 844a915ef2cd5f8ef5d4ac48571acc9b2d05de43 Mon Sep 17 00:00:00 2001 From: Tristan Tarrant Date: Fri, 22 Dec 2023 16:14:49 +0100 Subject: [PATCH] ISPN-15441 Embedded API 2.0 --- .../api/common/CacheEntryExpiration.java | 6 +- .../api/common/CacheEntryMetadata.java | 5 +- .../infinispan/api/common/CacheOptions.java | 14 ++ .../events/cache/CacheEntryRemovedEvent.java | 7 + .../events/cache/CacheEntryUpdatedEvent.java | 7 + .../api/common/events/container/Address.java | 4 + .../{cache => container}/CacheStartEvent.java | 2 +- .../{cache => container}/CacheStopEvent.java | 2 +- .../container/ContainerListenerEventType.java | 1 - .../events/container/ViewChangeEvent.java | 28 +++ .../api/exception/InfinispanException.java | 4 + .../cache/SyncCacheEntryCreatedListener.java | 1 + .../cache/SyncCacheEntryExpiredListener.java | 1 + .../cache/SyncCacheEntryRemovedListener.java | 1 + .../cache/SyncCacheEntryUpdatedListener.java | 1 + .../SyncContainerCacheStartedListener.java | 8 + .../SyncContainerCacheStoppedListener.java | 8 + .../SyncContainerViewChangedListener.java | 8 + .../org/infinispan/api/SyncCacheAPIDemo.java | 8 +- .../infinispan/hotrod/HotRodSyncCache.java | 26 +-- .../hotrod/HotRodSyncContainer.java | 1 - .../java/org/infinispan/hotrod/impl/Util.java | 15 +- .../commons/api/CacheContainerAdmin.java | 8 + .../util/concurrent/CompletableFutures.java | 2 + .../multimap/api/BasicMultimapCache.java | 1 + core/pom.xml | 4 + .../configuration/cache/Configuration.java | 3 +- .../global/GlobalConfiguration.java | 2 +- .../manager/DefaultCacheManager.java | 6 + .../manager/DefaultCacheManagerAdmin.java | 44 ++++- .../manager/EmbeddedCacheManager.java | 3 + .../manager/EmbeddedCacheManagerAdmin.java | 67 ++++++- embedded/pom.xml | 59 ++++++ .../org/infinispan/embedded/Embedded.java | 47 +++++ .../embedded/EmbeddedAsyncCache.java | 171 ++++++++++++++++++ .../embedded/EmbeddedAsyncCaches.java | 66 +++++++ .../embedded/EmbeddedAsyncContainer.java | 82 +++++++++ .../embedded/EmbeddedAsyncLocks.java | 43 +++++ .../embedded/EmbeddedAsyncMultiMap.java | 72 ++++++++ .../embedded/EmbeddedAsyncMultimaps.java | 66 +++++++ .../embedded/EmbeddedAsyncQuery.java | 70 +++++++ .../embedded/EmbeddedAsyncStreamingCache.java | 29 +++ .../embedded/EmbeddedAsyncStrongCounters.java | 43 +++++ .../embedded/EmbeddedAsyncWeakCounters.java | 43 +++++ .../infinispan/embedded/EmbeddedFactory.java | 30 +++ .../org/infinispan/embedded/EmbeddedFlag.java | 41 +++++ .../infinispan/embedded/EmbeddedFlags.java | 49 +++++ .../embedded/EmbeddedMutinyCache.java | 141 +++++++++++++++ .../embedded/EmbeddedMutinyCaches.java | 61 +++++++ .../embedded/EmbeddedMutinyContainer.java | 88 +++++++++ .../embedded/EmbeddedMutinyLocks.java | 39 ++++ .../embedded/EmbeddedMutinyMultimaps.java | 59 ++++++ .../embedded/EmbeddedMutinyQuery.java | 74 ++++++++ .../EmbeddedMutinyStreamingCache.java | 34 ++++ .../EmbeddedMutinyStrongCounters.java | 43 +++++ .../embedded/EmbeddedMutinyWeakCounters.java | 43 +++++ .../embedded/EmbeddedSyncCache.java | 144 +++++++++++++++ .../embedded/EmbeddedSyncCaches.java | 61 +++++++ .../embedded/EmbeddedSyncContainer.java | 80 ++++++++ .../infinispan/embedded/EmbeddedSyncLock.java | 65 +++++++ .../embedded/EmbeddedSyncLocks.java | 43 +++++ .../embedded/EmbeddedSyncMultimap.java | 73 ++++++++ .../embedded/EmbeddedSyncMultimaps.java | 63 +++++++ .../embedded/EmbeddedSyncQuery.java | 68 +++++++ .../embedded/EmbeddedSyncQueryResult.java | 34 ++++ .../embedded/EmbeddedSyncStreamingCache.java | 37 ++++ .../embedded/EmbeddedSyncStrongCounter.java | 70 +++++++ .../embedded/EmbeddedSyncStrongCounters.java | 43 +++++ .../embedded/EmbeddedSyncWeakCounter.java | 38 ++++ .../embedded/EmbeddedSyncWeakCounters.java | 42 +++++ .../org/infinispan/embedded/EmbeddedURI.java | 119 ++++++++++++ .../embedded/impl/EmbeddedCacheEntry.java | 52 ++++++ .../embedded/impl/EmbeddedUtil.java | 29 +++ .../infinispan/embedded/impl/logging/Log.java | 20 ++ .../embedded/impl/logging/LogFactory.java | 20 ++ .../org/infinispan/embedded/EmbeddedTest.java | 19 ++ .../infinispan/embedded/EmbeddedURITest.java | 55 ++++++ .../src/test/resources/infinispan-uri.xml | 3 + .../api/embedded/MultimapCacheManager.java | 6 +- .../multimap/impl/EmbeddedMultimapCache.java | 5 + .../impl/EmbeddedMultimapCacheManager.java | 17 +- .../impl/MultimapStoreBucketTest.java | 2 +- pom.xml | 1 + 83 files changed, 2938 insertions(+), 62 deletions(-) create mode 100644 api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryRemovedEvent.java create mode 100644 api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryUpdatedEvent.java create mode 100644 api/src/main/java/org/infinispan/api/common/events/container/Address.java rename api/src/main/java/org/infinispan/api/common/events/{cache => container}/CacheStartEvent.java (77%) rename api/src/main/java/org/infinispan/api/common/events/{cache => container}/CacheStopEvent.java (74%) create mode 100644 api/src/main/java/org/infinispan/api/common/events/container/ViewChangeEvent.java create mode 100644 api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStartedListener.java create mode 100644 api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStoppedListener.java create mode 100644 api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerViewChangedListener.java create mode 100644 embedded/pom.xml create mode 100644 embedded/src/main/java/org/infinispan/embedded/Embedded.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCache.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCaches.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncContainer.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncLocks.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultiMap.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultimaps.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncQuery.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStreamingCache.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStrongCounters.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncWeakCounters.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedFactory.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedFlag.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedFlags.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCache.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCaches.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyContainer.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyLocks.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyMultimaps.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyQuery.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStreamingCache.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStrongCounters.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyWeakCounters.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCache.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCaches.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncContainer.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLock.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLocks.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimap.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimaps.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQuery.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQueryResult.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStreamingCache.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounter.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounters.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounter.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounters.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/EmbeddedURI.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedCacheEntry.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedUtil.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/impl/logging/Log.java create mode 100644 embedded/src/main/java/org/infinispan/embedded/impl/logging/LogFactory.java create mode 100644 embedded/src/test/java/org/infinispan/embedded/EmbeddedTest.java create mode 100644 embedded/src/test/java/org/infinispan/embedded/EmbeddedURITest.java create mode 100644 embedded/src/test/resources/infinispan-uri.xml diff --git a/api/src/main/java/org/infinispan/api/common/CacheEntryExpiration.java b/api/src/main/java/org/infinispan/api/common/CacheEntryExpiration.java index 8de6ca3e39b7..75023640f409 100644 --- a/api/src/main/java/org/infinispan/api/common/CacheEntryExpiration.java +++ b/api/src/main/java/org/infinispan/api/common/CacheEntryExpiration.java @@ -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 + '}'; diff --git a/api/src/main/java/org/infinispan/api/common/CacheEntryMetadata.java b/api/src/main/java/org/infinispan/api/common/CacheEntryMetadata.java index 55ffb4e551d5..f0203b457b18 100644 --- a/api/src/main/java/org/infinispan/api/common/CacheEntryMetadata.java +++ b/api/src/main/java/org/infinispan/api/common/CacheEntryMetadata.java @@ -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 creationTime(); Optional lastAccessTime(); diff --git a/api/src/main/java/org/infinispan/api/common/CacheOptions.java b/api/src/main/java/org/infinispan/api/common/CacheOptions.java index 92c4a52c9a0f..ff68394a9b5b 100644 --- a/api/src/main/java/org/infinispan/api/common/CacheOptions.java +++ b/api/src/main/java/org/infinispan/api/common/CacheOptions.java @@ -7,14 +7,28 @@ * @since 14.0 **/ public interface CacheOptions { + /** + * The default options: + *
    + *
  • No timeout
  • + *
  • No flags
  • + *
+ */ 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 timeout(); + /** + * Context-specific flags to apply to the operation. + */ Optional> flags(); class Impl implements CacheOptions { diff --git a/api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryRemovedEvent.java b/api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryRemovedEvent.java new file mode 100644 index 000000000000..85c793eb3df3 --- /dev/null +++ b/api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryRemovedEvent.java @@ -0,0 +1,7 @@ +package org.infinispan.api.common.events.cache; + +/** + * @since 14.0 + **/ +public interface CacheEntryRemovedEvent extends CacheEntryEvent { +} diff --git a/api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryUpdatedEvent.java b/api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryUpdatedEvent.java new file mode 100644 index 000000000000..d3d26755d44e --- /dev/null +++ b/api/src/main/java/org/infinispan/api/common/events/cache/CacheEntryUpdatedEvent.java @@ -0,0 +1,7 @@ +package org.infinispan.api.common.events.cache; + +/** + * @since 15.0 + **/ +public interface CacheEntryUpdatedEvent extends CacheEntryEvent { +} diff --git a/api/src/main/java/org/infinispan/api/common/events/container/Address.java b/api/src/main/java/org/infinispan/api/common/events/container/Address.java new file mode 100644 index 000000000000..60cb27a3636c --- /dev/null +++ b/api/src/main/java/org/infinispan/api/common/events/container/Address.java @@ -0,0 +1,4 @@ +package org.infinispan.api.common.events.container; + +public interface Address { +} diff --git a/api/src/main/java/org/infinispan/api/common/events/cache/CacheStartEvent.java b/api/src/main/java/org/infinispan/api/common/events/container/CacheStartEvent.java similarity index 77% rename from api/src/main/java/org/infinispan/api/common/events/cache/CacheStartEvent.java rename to api/src/main/java/org/infinispan/api/common/events/container/CacheStartEvent.java index 46a2d764ac67..c33a458a8db5 100644 --- a/api/src/main/java/org/infinispan/api/common/events/cache/CacheStartEvent.java +++ b/api/src/main/java/org/infinispan/api/common/events/container/CacheStartEvent.java @@ -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; diff --git a/api/src/main/java/org/infinispan/api/common/events/cache/CacheStopEvent.java b/api/src/main/java/org/infinispan/api/common/events/container/CacheStopEvent.java similarity index 74% rename from api/src/main/java/org/infinispan/api/common/events/cache/CacheStopEvent.java rename to api/src/main/java/org/infinispan/api/common/events/container/CacheStopEvent.java index 2bcfac94e315..4f120e4d2c77 100644 --- a/api/src/main/java/org/infinispan/api/common/events/cache/CacheStopEvent.java +++ b/api/src/main/java/org/infinispan/api/common/events/container/CacheStopEvent.java @@ -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; diff --git a/api/src/main/java/org/infinispan/api/common/events/container/ContainerListenerEventType.java b/api/src/main/java/org/infinispan/api/common/events/container/ContainerListenerEventType.java index 9e7789a0946a..9c72f7574329 100644 --- a/api/src/main/java/org/infinispan/api/common/events/container/ContainerListenerEventType.java +++ b/api/src/main/java/org/infinispan/api/common/events/container/ContainerListenerEventType.java @@ -7,6 +7,5 @@ public enum ContainerListenerEventType { CACHE_STARTED, CACHE_STOPPED, CONFIGURATION_CHANGED, - CLUSTER_MERGED, VIEW_CHANGED } diff --git a/api/src/main/java/org/infinispan/api/common/events/container/ViewChangeEvent.java b/api/src/main/java/org/infinispan/api/common/events/container/ViewChangeEvent.java new file mode 100644 index 000000000000..728db6ff5f41 --- /dev/null +++ b/api/src/main/java/org/infinispan/api/common/events/container/ViewChangeEvent.java @@ -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
newMembers(); + + /** + * Gets the previous list of members. + * + * @return the old view associated with this view change. List cannot be null. + */ + List
oldMembers(); + + Address localAddress(); + + int viewId(); + + boolean isMergeView(); +} diff --git a/api/src/main/java/org/infinispan/api/exception/InfinispanException.java b/api/src/main/java/org/infinispan/api/exception/InfinispanException.java index 6fb17b38e2f9..50ef15c31a02 100644 --- a/api/src/main/java/org/infinispan/api/exception/InfinispanException.java +++ b/api/src/main/java/org/infinispan/api/exception/InfinispanException.java @@ -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); } diff --git a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryCreatedListener.java b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryCreatedListener.java index 73a61d85485a..2abfd2b61c62 100644 --- a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryCreatedListener.java +++ b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryCreatedListener.java @@ -5,6 +5,7 @@ /** * @since 14.0 **/ +@FunctionalInterface public interface SyncCacheEntryCreatedListener extends SyncCacheEntryListener { void onCreate(CacheEntryEvent event); } diff --git a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryExpiredListener.java b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryExpiredListener.java index 4b04494b43a4..e2ae86371e50 100644 --- a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryExpiredListener.java +++ b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryExpiredListener.java @@ -5,6 +5,7 @@ /** * @since 14.0 **/ +@FunctionalInterface public interface SyncCacheEntryExpiredListener extends SyncCacheEntryListener { void onExpired(CacheEntryEvent event); } diff --git a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryRemovedListener.java b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryRemovedListener.java index b6b1879384fe..b3c58fb77067 100644 --- a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryRemovedListener.java +++ b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryRemovedListener.java @@ -5,6 +5,7 @@ /** * @since 14.0 **/ +@FunctionalInterface public interface SyncCacheEntryRemovedListener extends SyncCacheEntryListener { void onRemove(CacheEntryEvent event); } diff --git a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryUpdatedListener.java b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryUpdatedListener.java index 04fcaed2ac51..b1ca320c285f 100644 --- a/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryUpdatedListener.java +++ b/api/src/main/java/org/infinispan/api/sync/events/cache/SyncCacheEntryUpdatedListener.java @@ -5,6 +5,7 @@ /** * @since 14.0 **/ +@FunctionalInterface public interface SyncCacheEntryUpdatedListener extends SyncCacheEntryListener { void onUpdate(CacheEntryEvent event); } diff --git a/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStartedListener.java b/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStartedListener.java new file mode 100644 index 000000000000..21a49659f3db --- /dev/null +++ b/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStartedListener.java @@ -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); +} diff --git a/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStoppedListener.java b/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStoppedListener.java new file mode 100644 index 000000000000..ecd6789785d7 --- /dev/null +++ b/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerCacheStoppedListener.java @@ -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); +} diff --git a/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerViewChangedListener.java b/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerViewChangedListener.java new file mode 100644 index 000000000000..4068346e4496 --- /dev/null +++ b/api/src/main/java/org/infinispan/api/sync/events/container/SyncContainerViewChangedListener.java @@ -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); +} diff --git a/api/src/test/java/org/infinispan/api/SyncCacheAPIDemo.java b/api/src/test/java/org/infinispan/api/SyncCacheAPIDemo.java index a09216f4eace..e0aab9b7bd02 100644 --- a/api/src/test/java/org/infinispan/api/SyncCacheAPIDemo.java +++ b/api/src/test/java/org/infinispan/api/SyncCacheAPIDemo.java @@ -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) event -> { + AutoCloseable listener = mycache.listen((SyncCacheEntryCreatedListener) event -> { // Handle create event }); @@ -92,15 +92,15 @@ public void accept(T t) { } } - public static class NullListener implements SyncCacheEntryUpdatedListener, SyncCacheEntryRemovedListener { + public static class NullListener implements SyncCacheEntryUpdatedListener, SyncCacheEntryRemovedListener { @Override - public void onRemove(CacheEntryEvent event) { + public void onRemove(CacheEntryEvent event) { } @Override - public void onUpdate(CacheEntryEvent event) { + public void onUpdate(CacheEntryEvent event) { } } diff --git a/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncCache.java b/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncCache.java index f5d74d4ff005..57d0b1fa1066 100644 --- a/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncCache.java +++ b/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncCache.java @@ -61,52 +61,52 @@ public HotRodSyncContainer container() { @Override public CacheEntry getEntry(K key, CacheOptions options) { - return await(remoteCache.getEntry(key, options)); + return await(remoteCache.getEntry(key, options), options); } @Override public CacheEntry 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 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 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 getAndRemove(K key, CacheOptions options) { - return await(remoteCache.getAndRemove(key, options)); + return await(remoteCache.getAndRemove(key, options), options); } @Override @@ -121,7 +121,7 @@ public CloseableIterable> entries(CacheOptions options) { @Override public void putAll(Map entries, CacheWriteOptions options) { - await(remoteCache.putAll(entries, options)); + await(remoteCache.putAll(entries, options), options); } @Override @@ -150,12 +150,12 @@ public Map> getAndRemoveAll(Set 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 diff --git a/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncContainer.java b/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncContainer.java index ea643d566f1c..880cc2cf15d8 100644 --- a/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncContainer.java +++ b/client/hotrod/src/main/java/org/infinispan/hotrod/HotRodSyncContainer.java @@ -63,7 +63,6 @@ public HotRodSyncLocks locks() { @Override public void listen(SyncContainerListener listener, ContainerListenerEventType... types) { - } @Override diff --git a/client/hotrod/src/main/java/org/infinispan/hotrod/impl/Util.java b/client/hotrod/src/main/java/org/infinispan/hotrod/impl/Util.java index 26edffb70736..80c6fac39744 100644 --- a/client/hotrod/src/main/java/org/infinispan/hotrod/impl/Util.java +++ b/client/hotrod/src/main/java/org/infinispan/hotrod/impl/Util.java @@ -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; @@ -41,14 +42,18 @@ public byte[] getBranchQualifier() { private Util() { } - public static T await(CompletionStage cf) { - return await(cf.toCompletableFuture()); + public static T await(CompletionStage cf, CacheOptions options) { + return await(cf.toCompletableFuture(), options); } - public static T await(CompletableFuture cf) { + public static T await(CompletableFuture 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(); diff --git a/commons/all/src/main/java/org/infinispan/commons/api/CacheContainerAdmin.java b/commons/all/src/main/java/org/infinispan/commons/api/CacheContainerAdmin.java index 0c0216d0f1b5..8b573e01418a 100644 --- a/commons/all/src/main/java/org/infinispan/commons/api/CacheContainerAdmin.java +++ b/commons/all/src/main/java/org/infinispan/commons/api/CacheContainerAdmin.java @@ -1,6 +1,7 @@ package org.infinispan.commons.api; import java.util.EnumSet; +import java.util.concurrent.CompletionStage; import org.infinispan.commons.configuration.BasicConfiguration; @@ -105,6 +106,13 @@ public static EnumSet 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 removeCacheAsync(String name); + /** * Sets any additional {@link AdminFlag}s to be used when performing administrative operations. * diff --git a/commons/all/src/main/java/org/infinispan/commons/util/concurrent/CompletableFutures.java b/commons/all/src/main/java/org/infinispan/commons/util/concurrent/CompletableFutures.java index 30537234c708..78f288e90eed 100644 --- a/commons/all/src/main/java/org/infinispan/commons/util/concurrent/CompletableFutures.java +++ b/commons/all/src/main/java/org/infinispan/commons/util/concurrent/CompletableFutures.java @@ -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; diff --git a/commons/all/src/main/java/org/infinispan/multimap/api/BasicMultimapCache.java b/commons/all/src/main/java/org/infinispan/multimap/api/BasicMultimapCache.java index c30f01a75a2b..58bd7d8e1bd4 100644 --- a/commons/all/src/main/java/org/infinispan/multimap/api/BasicMultimapCache.java +++ b/commons/all/src/main/java/org/infinispan/multimap/api/BasicMultimapCache.java @@ -157,4 +157,5 @@ public interface BasicMultimapCache { */ boolean supportsDuplicates(); + String getName(); } diff --git a/core/pom.xml b/core/pom.xml index 8bf6d4f25fbf..c58388ac8b57 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -14,6 +14,10 @@ Infinispan core module + + org.infinispan + infinispan-api + org.infinispan infinispan-commons diff --git a/core/src/main/java/org/infinispan/configuration/cache/Configuration.java b/core/src/main/java/org/infinispan/configuration/cache/Configuration.java index 1a209a83efcf..22a7643a6a0b 100644 --- a/core/src/main/java/org/infinispan/configuration/cache/Configuration.java +++ b/core/src/main/java/org/infinispan/configuration/cache/Configuration.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Objects; +import org.infinispan.api.configuration.CacheConfiguration; import org.infinispan.commons.configuration.BasicConfiguration; import org.infinispan.commons.configuration.attributes.Attribute; import org.infinispan.commons.configuration.attributes.AttributeDefinition; @@ -16,7 +17,7 @@ import org.infinispan.commons.io.StringBuilderWriter; import org.infinispan.configuration.parsing.ParserRegistry; -public class Configuration extends ConfigurationElement implements BasicConfiguration { +public class Configuration extends ConfigurationElement implements BasicConfiguration, CacheConfiguration { public static final AttributeDefinition CONFIGURATION = AttributeDefinition.builder(org.infinispan.configuration.parsing.Attribute.CONFIGURATION, null, String.class).immutable().build(); public static final AttributeDefinition SIMPLE_CACHE = AttributeDefinition.builder(org.infinispan.configuration.parsing.Attribute.SIMPLE_CACHE, false).immutable().build(); diff --git a/core/src/main/java/org/infinispan/configuration/global/GlobalConfiguration.java b/core/src/main/java/org/infinispan/configuration/global/GlobalConfiguration.java index 86dfd2ace05a..16cfed871502 100644 --- a/core/src/main/java/org/infinispan/configuration/global/GlobalConfiguration.java +++ b/core/src/main/java/org/infinispan/configuration/global/GlobalConfiguration.java @@ -28,7 +28,7 @@ */ @Scope(Scopes.GLOBAL) @SurvivesRestarts -public class GlobalConfiguration { +public class GlobalConfiguration implements org.infinispan.api.configuration.Configuration { private final Map, ?> modules; private final SiteConfiguration site; diff --git a/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java b/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java index 3e1403634766..62cf6259cf4b 100644 --- a/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java +++ b/core/src/main/java/org/infinispan/manager/DefaultCacheManager.java @@ -530,6 +530,12 @@ public Cache getCache(String cacheName) { return internalGetCache(cacheName); } + @Override + public CompletionStage> getCacheAsync(String cacheName) { + Executor blockingExecutor = globalComponentRegistry.getComponent(ExecutorService.class, KnownComponentNames.BLOCKING_EXECUTOR); + return CompletableFuture.supplyAsync(() -> getCache(cacheName), blockingExecutor); + } + private Cache internalGetCache(String cacheName) { if (cacheName == null) throw new NullPointerException("Null arguments not allowed"); diff --git a/core/src/main/java/org/infinispan/manager/DefaultCacheManagerAdmin.java b/core/src/main/java/org/infinispan/manager/DefaultCacheManagerAdmin.java index 35fb3cf77937..108dcbd765b0 100644 --- a/core/src/main/java/org/infinispan/manager/DefaultCacheManagerAdmin.java +++ b/core/src/main/java/org/infinispan/manager/DefaultCacheManagerAdmin.java @@ -4,6 +4,7 @@ import java.util.Collections; import java.util.EnumSet; +import java.util.concurrent.CompletionStage; import javax.security.auth.Subject; @@ -43,6 +44,12 @@ public Cache createCache(String cacheName, Configuration configurat return cacheManager.getCache(cacheName); } + @Override + public CompletionStage> createCacheAsync(String name, Configuration configuration) { + authorizer.checkPermission(subject, AuthorizationPermission.CREATE); + return clusterConfigurationManager.createCache(name, configuration, flags).thenCompose(__ -> cacheManager.getCacheAsync(name)); + } + @Override public Cache getOrCreateCache(String cacheName, Configuration configuration) { authorizer.checkPermission(subject, AuthorizationPermission.CREATE); @@ -57,6 +64,12 @@ public Cache createCache(String cacheName, String template) { return cacheManager.getCache(cacheName); } + @Override + public CompletionStage> createCacheAsync(String name, String template) { + authorizer.checkPermission(subject, AuthorizationPermission.CREATE); + return clusterConfigurationManager.createCache(name, template, flags).thenCompose(__ -> cacheManager.getCacheAsync(name)); + } + @Override public Cache getOrCreateCache(String cacheName, String template) { authorizer.checkPermission(subject, AuthorizationPermission.CREATE); @@ -66,27 +79,46 @@ public Cache getOrCreateCache(String cacheName, String template) { @Override public void createTemplate(String name, Configuration configuration) { + join(createTemplateAsync(name, configuration)); + } + + @Override + public CompletionStage createTemplateAsync(String name, Configuration configuration) { authorizer.checkPermission(subject, AuthorizationPermission.CREATE); - join(clusterConfigurationManager.createTemplate(name, configuration, flags)); + return clusterConfigurationManager.createTemplate(name, configuration, flags); } @Override public Configuration getOrCreateTemplate(String name, Configuration configuration) { + return join(getOrCreateTemplateAsync(name, configuration)); + } + + @Override + public CompletionStage getOrCreateTemplateAsync(String name, Configuration configuration) { authorizer.checkPermission(subject, AuthorizationPermission.CREATE); - join(clusterConfigurationManager.getOrCreateTemplate(name, configuration, flags)); - return cacheManager.getCacheConfiguration(name); + return clusterConfigurationManager.getOrCreateTemplate(name, configuration, flags).thenApply(__ -> cacheManager.getCacheConfiguration(name)); } @Override public void removeTemplate(String name) { + join(removeTemplateAsync(name)); + } + + @Override + public CompletionStage removeTemplateAsync(String name) { authorizer.checkPermission(subject, AuthorizationPermission.CREATE); - join(clusterConfigurationManager.removeTemplate(name, flags)); + return clusterConfigurationManager.removeTemplate(name, flags); + } + + @Override + public void removeCache(String name) { + join(removeCacheAsync(name)); } @Override - public void removeCache(String cacheName) { + public CompletionStage removeCacheAsync(String name) { authorizer.checkPermission(subject, AuthorizationPermission.CREATE); - join(clusterConfigurationManager.removeCache(cacheName, flags)); + return clusterConfigurationManager.removeCache(name, flags); } @Override diff --git a/core/src/main/java/org/infinispan/manager/EmbeddedCacheManager.java b/core/src/main/java/org/infinispan/manager/EmbeddedCacheManager.java index 529428541e02..71ea9e269522 100644 --- a/core/src/main/java/org/infinispan/manager/EmbeddedCacheManager.java +++ b/core/src/main/java/org/infinispan/manager/EmbeddedCacheManager.java @@ -3,6 +3,7 @@ import java.io.Closeable; import java.util.List; import java.util.Set; +import java.util.concurrent.CompletionStage; import javax.security.auth.Subject; @@ -226,6 +227,8 @@ default Set getCacheConfigurationNames() { */ Cache getCache(String cacheName); + CompletionStage> getCacheAsync(String cacheName); + /** * Creates a cache on the local node using the supplied configuration. *

diff --git a/core/src/main/java/org/infinispan/manager/EmbeddedCacheManagerAdmin.java b/core/src/main/java/org/infinispan/manager/EmbeddedCacheManagerAdmin.java index 99248ab4e3ed..e0d639b17b57 100644 --- a/core/src/main/java/org/infinispan/manager/EmbeddedCacheManagerAdmin.java +++ b/core/src/main/java/org/infinispan/manager/EmbeddedCacheManagerAdmin.java @@ -1,5 +1,7 @@ package org.infinispan.manager; +import java.util.concurrent.CompletionStage; + import javax.security.auth.Subject; import org.infinispan.Cache; @@ -24,11 +26,20 @@ public interface EmbeddedCacheManagerAdmin extends CacheContainerAdmin Cache createCache(String name, String template); + /** + * Asynchronous version of {@link #createCache(String, String)} + * + * @param name the name of the cache to create + * @param template the template to use for the cache. If null, the configuration marked as default on the container + * will be used + * @return a {@link CompletionStage} holding the cache + */ + CompletionStage> createCacheAsync(String name, String template); + /** * Retrieves an existing cache or creates one using the specified template if it doesn't exist * @@ -44,26 +55,36 @@ public interface EmbeddedCacheManagerAdmin extends CacheContainerAdmin the generic type of the key - * @param the generic type of the value + * @param the generic type of the key + * @param the generic type of the value * @return the cache - * * @throws org.infinispan.commons.CacheException if a cache with the same name already exists */ Cache createCache(String name, Configuration configuration); + /** + * Asynchronous version of {@link #createCache(String, Configuration)} + * @param name the name of the cache + * @param configuration the configuration to use. It must be a clustered configuration (e.g. distributed) + * @param the generic type of the key + * @param the generic type of the value + * @return a {@link CompletionStage} holding the cache + * @throws org.infinispan.commons.CacheException if a cache with the same name already exists + */ + CompletionStage> createCacheAsync(String name, Configuration configuration); + /** * Retrieves an existing cache or creates one across the cluster using the specified configuration. * The cache will survive topology changes, e.g. when a new node joins the cluster, * it will automatically be created there. This method will wait for the cache to be created on all nodes before * returning. * - * @param name the name of the cache + * @param name the name of the cache * @param configuration the configuration to use. It must be a clustered configuration (e.g. distributed) - * @param the generic type of the key - * @param the generic type of the value + * @param the generic type of the key + * @param the generic type of the value * @return the cache */ Cache getOrCreateCache(String name, Configuration configuration); @@ -74,24 +95,42 @@ public interface EmbeddedCacheManagerAdmin extends CacheContainerAdmin} + */ + CompletionStage createTemplateAsync(String name, Configuration configuration); + /** * Retrieves an existing template or creates one across the cluster using the specified configuration. * The template will survive topology changes, e.g. when a new node joins the cluster, * it will automatically be created there. This method will wait for the template to be created on all nodes before * returning. * - * @param name the name of the template + * @param name the name of the template * @param configuration the configuration to use. It must be a clustered configuration (e.g. distributed) * @return the template configuration */ Configuration getOrCreateTemplate(String name, Configuration configuration); + /** + * Asynchronous version of {@link #getOrCreateTemplate(String, Configuration)} + * + * @param name the name of the template + * @param configuration the configuration to use. It must be a clustered configuration (e.g. distributed) + * @return a {@link CompletionStage} holding the template configuration + */ + CompletionStage getOrCreateTemplateAsync(String name, Configuration configuration); + /** * Removes a template from the cache container. Any persisted data will be cleared. * @@ -99,6 +138,14 @@ public interface EmbeddedCacheManagerAdmin extends CacheContainerAdmin removeTemplateAsync(String name); + + /** * Performs any cache manager operations using the specified {@link Subject}. Only applies to cache managers with authorization * enabled (see {@link GlobalConfigurationBuilder#security()}. diff --git a/embedded/pom.xml b/embedded/pom.xml new file mode 100644 index 000000000000..fe3b02048730 --- /dev/null +++ b/embedded/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + org.infinispan + infinispan-parent + 15.0.0-SNAPSHOT + ../pom.xml + + + infinispan-embedded + Infinispan org.infinispan.embedded.Embedded + Infinispan org.infinispan.embedded.Embedded module + + + + org.infinispan + infinispan-api + + + io.smallrye.reactive + mutiny + + + org.infinispan + infinispan-core + + + org.infinispan + infinispan-clustered-counter + + + org.infinispan + infinispan-clustered-lock + + + org.infinispan + infinispan-multimap + + + org.infinispan + infinispan-query + + + org.kohsuke.metainf-services + metainf-services + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + diff --git a/embedded/src/main/java/org/infinispan/embedded/Embedded.java b/embedded/src/main/java/org/infinispan/embedded/Embedded.java new file mode 100644 index 000000000000..e625c54fb821 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/Embedded.java @@ -0,0 +1,47 @@ +package org.infinispan.embedded; + +import org.infinispan.api.Infinispan; +import org.infinispan.api.async.AsyncContainer; +import org.infinispan.api.mutiny.MutinyContainer; +import org.infinispan.api.sync.SyncContainer; +import org.infinispan.commons.util.Util; +import org.infinispan.configuration.global.GlobalConfiguration; +import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; +import org.infinispan.manager.DefaultCacheManager; + +/** + * @since 15.0 + */ +public class Embedded implements Infinispan { + final DefaultCacheManager cacheManager; + + Embedded(ConfigurationBuilderHolder configuration) { + this.cacheManager = new DefaultCacheManager(configuration, true); + } + + Embedded(GlobalConfiguration configuration) { + ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder(); + holder.getGlobalConfigurationBuilder().read(configuration); + this.cacheManager = new DefaultCacheManager(configuration, true); + } + + @Override + public SyncContainer sync() { + return new EmbeddedSyncContainer(this); + } + + @Override + public AsyncContainer async() { + return new EmbeddedAsyncContainer(this); + } + + @Override + public MutinyContainer mutiny() { + return new EmbeddedMutinyContainer(this); + } + + @Override + public void close() { + Util.close(cacheManager); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCache.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCache.java new file mode 100644 index 000000000000..f30ca8bd961d --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCache.java @@ -0,0 +1,171 @@ +package org.infinispan.embedded; + +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; + +import org.infinispan.AdvancedCache; +import org.infinispan.api.async.AsyncCache; +import org.infinispan.api.async.AsyncCacheEntryProcessor; +import org.infinispan.api.async.AsyncContainer; +import org.infinispan.api.async.AsyncQuery; +import org.infinispan.api.async.AsyncStreamingCache; +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.common.process.CacheProcessorOptions; +import org.infinispan.api.configuration.CacheConfiguration; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncCache implements AsyncCache { + private final Embedded embedded; + private final AdvancedCache cache; + + EmbeddedAsyncCache(Embedded embedded, AdvancedCache cache) { + this.embedded = embedded; + this.cache = cache; + } + + @Override + public String name() { + return cache.getName(); + } + + @Override + public CompletionStage configuration() { + return null; + } + + @Override + public AsyncContainer container() { + return embedded.async(); + } + + @Override + public CompletionStage> getEntry(K key, CacheOptions options) { + return null; + } + + @Override + public CompletionStage> putIfAbsent(K key, V value, CacheWriteOptions options) { + return null; + } + + @Override + public CompletionStage> put(K key, V value, CacheWriteOptions options) { + return null; + } + + @Override + public CompletionStage> getOrReplaceEntry(K key, V value, CacheEntryVersion version, CacheWriteOptions options) { + return null; + } + + @Override + public CompletionStage remove(K key, CacheOptions options) { + return null; + } + + @Override + public CompletionStage remove(K key, CacheEntryVersion version, CacheOptions options) { + return null; + } + + @Override + public CompletionStage> getAndRemove(K key, CacheOptions options) { + return null; + } + + @Override + public Flow.Publisher keys(CacheOptions options) { + return null; + } + + @Override + public Flow.Publisher> entries(CacheOptions options) { + return null; + } + + @Override + public CompletionStage putAll(Map entries, CacheWriteOptions options) { + return null; + } + + @Override + public CompletionStage putAll(Flow.Publisher> entries, CacheWriteOptions options) { + return null; + } + + @Override + public Flow.Publisher> getAll(Set keys, CacheOptions options) { + return null; + } + + @Override + public Flow.Publisher> getAll(CacheOptions options, K... keys) { + return null; + } + + @Override + public Flow.Publisher removeAll(Set keys, CacheWriteOptions options) { + return null; + } + + @Override + public Flow.Publisher removeAll(Flow.Publisher keys, CacheWriteOptions options) { + return null; + } + + @Override + public Flow.Publisher> getAndRemoveAll(Set keys, CacheWriteOptions options) { + return null; + } + + @Override + public Flow.Publisher> getAndRemoveAll(Flow.Publisher keys, CacheWriteOptions options) { + return null; + } + + @Override + public CompletionStage estimateSize(CacheOptions options) { + return null; + } + + @Override + public CompletionStage clear(CacheOptions options) { + return cache.clearAsync(); + } + + @Override + public AsyncQuery query(String query, CacheOptions options) { + return new EmbeddedAsyncQuery<>(cache.query(query), options); + } + + @Override + public Flow.Publisher> listen(CacheListenerOptions options, CacheEntryEventType... types) { + return null; + } + + @Override + public Flow.Publisher> process(Set keys, AsyncCacheEntryProcessor task, CacheOptions options) { + return null; + } + + @Override + public Flow.Publisher> processAll(AsyncCacheEntryProcessor processor, CacheProcessorOptions options) { + return null; + } + + @Override + public AsyncStreamingCache streaming() { + return new EmbeddedAsyncStreamingCache<>(cache); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCaches.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCaches.java new file mode 100644 index 000000000000..4cb2231af31b --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncCaches.java @@ -0,0 +1,66 @@ +package org.infinispan.embedded; + +import java.util.Collections; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; + +import org.infinispan.Cache; +import org.infinispan.api.async.AsyncCache; +import org.infinispan.api.async.AsyncCaches; +import org.infinispan.api.configuration.CacheConfiguration; +import org.infinispan.configuration.cache.Configuration; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncCaches implements AsyncCaches { + private final Embedded embedded; + + EmbeddedAsyncCaches(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public CompletionStage> create(String name, CacheConfiguration cacheConfiguration) { + CompletionStage> cache = embedded.cacheManager.administration().createCacheAsync(name, (Configuration) cacheConfiguration); + return cache.thenApply(c -> new EmbeddedAsyncCache<>(embedded, c.getAdvancedCache())); + } + + @Override + public CompletionStage> create(String name, String template) { + CompletionStage> cache = embedded.cacheManager.administration().createCacheAsync(name, template); + return cache.thenApply(c -> new EmbeddedAsyncCache<>(embedded, c.getAdvancedCache())); + } + + @Override + public CompletionStage> get(String name) { + CompletionStage> cache = embedded.cacheManager.getCacheAsync(name); + return cache.thenApply(c -> new EmbeddedAsyncCache<>(embedded, c.getAdvancedCache())); + } + + @Override + public CompletionStage remove(String name) { + return embedded.cacheManager.administration().removeCacheAsync(name); + } + + @Override + public CompletionStage> names() { + return CompletableFuture.completedFuture(embedded.cacheManager.getCacheNames()); + } + + @Override + public CompletionStage createTemplate(String name, CacheConfiguration cacheConfiguration) { + return embedded.cacheManager.administration().createTemplateAsync(name, (Configuration) cacheConfiguration); + } + + @Override + public CompletionStage removeTemplate(String name) { + return embedded.cacheManager.administration().removeTemplateAsync(name); + } + + @Override + public CompletionStage> templateNames() { + return CompletableFuture.completedFuture(Collections.emptySet()); // TODO + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncContainer.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncContainer.java new file mode 100644 index 000000000000..b36e9fbaea0d --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncContainer.java @@ -0,0 +1,82 @@ +package org.infinispan.embedded; + +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; +import java.util.function.Function; + +import org.infinispan.api.async.AsyncCaches; +import org.infinispan.api.async.AsyncContainer; +import org.infinispan.api.async.AsyncLocks; +import org.infinispan.api.async.AsyncMultimaps; +import org.infinispan.api.async.AsyncStrongCounters; +import org.infinispan.api.async.AsyncWeakCounters; +import org.infinispan.api.common.events.container.ContainerEvent; +import org.infinispan.api.common.events.container.ContainerListenerEventType; +import org.infinispan.api.mutiny.MutinyContainer; +import org.infinispan.api.sync.SyncContainer; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncContainer implements AsyncContainer { + private final Embedded embedded; + + EmbeddedAsyncContainer(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public SyncContainer sync() { + return embedded.sync(); + } + + @Override + public AsyncContainer async() { + return this; + } + + @Override + public MutinyContainer mutiny() { + return embedded.mutiny(); + } + + @Override + public void close() { + embedded.close(); + } + + @Override + public AsyncCaches caches() { + return new EmbeddedAsyncCaches(embedded); + } + + @Override + public AsyncMultimaps multimaps() { + return new EmbeddedAsyncMultimaps(embedded); + } + + @Override + public AsyncStrongCounters strongCounters() { + return new EmbeddedAsyncStrongCounters(embedded); + } + + @Override + public AsyncWeakCounters weakCounters() { + return new EmbeddedAsyncWeakCounters(embedded); + } + + @Override + public AsyncLocks locks() { + return new EmbeddedAsyncLocks(embedded); + } + + @Override + public Flow.Publisher listen(ContainerListenerEventType... types) { + return null; + } + + @Override + public CompletionStage batch(Function> function) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncLocks.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncLocks.java new file mode 100644 index 000000000000..ef56f3a8ca21 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncLocks.java @@ -0,0 +1,43 @@ +package org.infinispan.embedded; + +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; + +import org.infinispan.api.async.AsyncLock; +import org.infinispan.api.async.AsyncLocks; +import org.infinispan.api.configuration.LockConfiguration; +import org.infinispan.lock.EmbeddedClusteredLockManagerFactory; +import org.infinispan.lock.api.ClusteredLockManager; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncLocks implements AsyncLocks { + private final Embedded embedded; + private final ClusteredLockManager lockManager; + + EmbeddedAsyncLocks(Embedded embedded) { + this.embedded = embedded; + this.lockManager = EmbeddedClusteredLockManagerFactory.from(embedded.cacheManager); + } + + @Override + public CompletionStage create(String name, LockConfiguration configuration) { + return null; + } + + @Override + public CompletionStage lock(String name) { + return null; + } + + @Override + public CompletionStage remove(String name) { + return null; + } + + @Override + public Flow.Publisher names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultiMap.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultiMap.java new file mode 100644 index 000000000000..5787668c8549 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultiMap.java @@ -0,0 +1,72 @@ +package org.infinispan.embedded; + +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; + +import org.infinispan.api.async.AsyncContainer; +import org.infinispan.api.async.AsyncMultimap; +import org.infinispan.api.configuration.MultimapConfiguration; +import org.infinispan.multimap.api.embedded.MultimapCache; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncMultiMap implements AsyncMultimap { + private final MultimapCache multimap; + private final Embedded embedded; + + EmbeddedAsyncMultiMap(Embedded embedded, MultimapCache multimap) { + this.embedded = embedded; + this.multimap = multimap; + } + + @Override + public String name() { + return multimap.getName(); + } + + @Override + public CompletionStage configuration() { + return null; + } + + @Override + public AsyncContainer container() { + return embedded.async(); + } + + @Override + public CompletionStage add(K key, V value) { + return multimap.put(key, value); + } + + @Override + public Flow.Publisher get(K key) { + return null; + } + + @Override + public CompletionStage remove(K key) { + return multimap.remove(key); + } + + @Override + public CompletionStage remove(K key, V value) { + return multimap.remove(key, value); + } + + @Override + public CompletionStage containsKey(K key) { + return multimap.containsKey(key); + } + + @Override + public CompletionStage containsEntry(K key, V value) { + return multimap.containsEntry(key, value); + } + + @Override + public CompletionStage estimateSize() { + return multimap.size(); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultimaps.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultimaps.java new file mode 100644 index 000000000000..0890f44a9f02 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncMultimaps.java @@ -0,0 +1,66 @@ +package org.infinispan.embedded; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; + +import org.infinispan.api.async.AsyncMultimap; +import org.infinispan.api.async.AsyncMultimaps; +import org.infinispan.api.configuration.MultimapConfiguration; +import org.infinispan.multimap.api.embedded.EmbeddedMultimapCacheManagerFactory; +import org.infinispan.multimap.api.embedded.MultimapCache; +import org.infinispan.multimap.api.embedded.MultimapCacheManager; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncMultimaps implements AsyncMultimaps { + private final Embedded embedded; + private final MultimapCacheManager multimapCacheManager; + + EmbeddedAsyncMultimaps(Embedded embedded) { + this.embedded = embedded; + this.multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(embedded.cacheManager); + } + + @Override + public CompletionStage> create(String name, MultimapConfiguration cacheConfiguration) { + return null; + } + + @Override + public CompletionStage> create(String name, String template) { + return null; + } + + @Override + public CompletionStage> get(String name) { + MultimapCache multimap = multimapCacheManager.get(name); + return CompletableFuture.completedFuture(new EmbeddedAsyncMultiMap<>(embedded, multimap)); + } + + @Override + public CompletionStage remove(String name) { + return null; + } + + @Override + public Flow.Publisher names() { + return null; + } + + @Override + public CompletionStage createTemplate(String name, MultimapConfiguration cacheConfiguration) { + return null; + } + + @Override + public CompletionStage removeTemplate(String name) { + return null; + } + + @Override + public Flow.Publisher templateNames() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncQuery.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncQuery.java new file mode 100644 index 000000000000..51d1c1847aec --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncQuery.java @@ -0,0 +1,70 @@ +package org.infinispan.embedded; + +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; +import java.util.concurrent.TimeUnit; + +import org.infinispan.api.async.AsyncCacheEntryProcessor; +import org.infinispan.api.async.AsyncQuery; +import org.infinispan.api.async.AsyncQueryResult; +import org.infinispan.api.common.CacheOptions; +import org.infinispan.api.common.events.cache.CacheContinuousQueryEvent; +import org.infinispan.api.common.process.CacheEntryProcessorResult; +import org.infinispan.api.common.process.CacheProcessor; +import org.infinispan.api.common.process.CacheProcessorOptions; +import org.infinispan.commons.api.query.Query; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncQuery implements AsyncQuery { + private final Query query; + + EmbeddedAsyncQuery(Query query, CacheOptions options) { + this.query = query; + options.timeout().ifPresent(d -> query.timeout(d.toNanos(), TimeUnit.NANOSECONDS)); + } + + @Override + public AsyncQuery param(String name, Object value) { + query.setParameter(name, value); + return this; + } + + @Override + public AsyncQuery skip(long skip) { + query.startOffset(skip); + return this; + } + + @Override + public AsyncQuery limit(int limit) { + query.maxResults(limit); + return this; + } + + @Override + public CompletionStage> find() { + return null; + } + + @Override + public Flow.Publisher> findContinuously(String query) { + return null; + } + + @Override + public CompletionStage execute() { + return null; + } + + @Override + public Flow.Publisher> process(AsyncCacheEntryProcessor processor, CacheProcessorOptions options) { + return null; + } + + @Override + public Flow.Publisher> process(CacheProcessor processor, CacheProcessorOptions options) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStreamingCache.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStreamingCache.java new file mode 100644 index 000000000000..20ea65027de9 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStreamingCache.java @@ -0,0 +1,29 @@ +package org.infinispan.embedded; + +import org.infinispan.AdvancedCache; +import org.infinispan.api.async.AsyncStreamingCache; +import org.infinispan.api.common.CacheOptions; +import org.infinispan.api.common.CacheWriteOptions; + +public class EmbeddedAsyncStreamingCache implements AsyncStreamingCache { + private final AdvancedCache cache; + + EmbeddedAsyncStreamingCache(AdvancedCache cache) { + this.cache = cache; + } + + @Override + public CacheEntrySubscriber get(K key, CacheOptions metadata) { + return null; + } + + @Override + public CacheEntryPublisher put(K key, CacheWriteOptions metadata) { + return null; + } + + @Override + public CacheEntryPublisher putIfAbsent(K key, CacheWriteOptions metadata) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStrongCounters.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStrongCounters.java new file mode 100644 index 000000000000..bc5d0b2aebec --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncStrongCounters.java @@ -0,0 +1,43 @@ +package org.infinispan.embedded; + +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; + +import org.infinispan.api.async.AsyncStrongCounter; +import org.infinispan.api.async.AsyncStrongCounters; +import org.infinispan.api.configuration.CounterConfiguration; +import org.infinispan.counter.EmbeddedCounterManagerFactory; +import org.infinispan.counter.api.CounterManager; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncStrongCounters implements AsyncStrongCounters { + private final Embedded embedded; + private final CounterManager counterManager; + + EmbeddedAsyncStrongCounters(Embedded embedded) { + this.embedded = embedded; + this.counterManager = EmbeddedCounterManagerFactory.asCounterManager(embedded.cacheManager); + } + + @Override + public CompletionStage get(String name) { + return null; + } + + @Override + public CompletionStage create(String name, CounterConfiguration configuration) { + return null; + } + + @Override + public CompletionStage remove(String name) { + return null; + } + + @Override + public Flow.Publisher names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncWeakCounters.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncWeakCounters.java new file mode 100644 index 000000000000..5895027e2405 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedAsyncWeakCounters.java @@ -0,0 +1,43 @@ +package org.infinispan.embedded; + +import java.util.concurrent.CompletionStage; +import java.util.concurrent.Flow; + +import org.infinispan.api.async.AsyncWeakCounter; +import org.infinispan.api.async.AsyncWeakCounters; +import org.infinispan.api.configuration.CounterConfiguration; +import org.infinispan.counter.EmbeddedCounterManagerFactory; +import org.infinispan.counter.api.CounterManager; + +/** + * @since 15.0 + */ +public class EmbeddedAsyncWeakCounters implements AsyncWeakCounters { + private final Embedded embedded; + private final CounterManager counterManager; + + EmbeddedAsyncWeakCounters(Embedded embedded) { + this.embedded = embedded; + this.counterManager = EmbeddedCounterManagerFactory.asCounterManager(embedded.cacheManager); + } + + @Override + public CompletionStage get(String name) { + return null; + } + + @Override + public CompletionStage create(String name, CounterConfiguration configuration) { + return null; + } + + @Override + public CompletionStage remove(String name) { + return null; + } + + @Override + public Flow.Publisher names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedFactory.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedFactory.java new file mode 100644 index 000000000000..00fd6b718fb1 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedFactory.java @@ -0,0 +1,30 @@ +package org.infinispan.embedded; + +import java.net.URI; + +import org.infinispan.api.Infinispan; +import org.infinispan.api.configuration.Configuration; +import org.infinispan.configuration.global.GlobalConfiguration; +import org.kohsuke.MetaInfServices; + +/** + * @since 15.0 + */ +@MetaInfServices(Infinispan.Factory.class) +public class EmbeddedFactory implements Infinispan.Factory { + @Override + public Infinispan create(URI uri) { + try { + return new Embedded(EmbeddedURI.create(uri).toConfiguration()); + } catch (Throwable t) { + // Not a Hot Rod URI + return null; + } + } + + @Override + public Infinispan create(Configuration configuration) { + assert configuration instanceof GlobalConfiguration; + return new Embedded((GlobalConfiguration) configuration); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedFlag.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedFlag.java new file mode 100644 index 000000000000..39ef79698ca5 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedFlag.java @@ -0,0 +1,41 @@ +package org.infinispan.embedded; + +import org.infinispan.api.common.Flag; +import org.infinispan.api.common.Flags; + +/** + * Defines all the flags available in Embedded mode that can influence the behavior of operations. + *

+ * Available flags: + *

    + *
  • {@link #DEFAULT_LIFESPAN} This flag can either be used as a request flag during a put operation to mean + * that the default server lifespan should be applied or as a response flag meaning that + * the return entry has a default lifespan value
  • + *
+ * + * @since 15.0 + */ +public enum EmbeddedFlag implements Flag { + TODO(0); + + private final int flagInt; + + EmbeddedFlag(int flagInt) { + this.flagInt = flagInt; + } + + public int getFlagInt() { + return flagInt; + } + + @Override + public Flags add(Flags flags) { + EmbeddedFlags userFlags = (EmbeddedFlags) flags; + if (userFlags == null) { + userFlags = EmbeddedFlags.of(this); + } else { + userFlags.add(this); + } + return userFlags; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedFlags.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedFlags.java new file mode 100644 index 000000000000..06b441865d10 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedFlags.java @@ -0,0 +1,49 @@ +package org.infinispan.embedded; + +import org.infinispan.api.common.CacheOptions; +import org.infinispan.api.common.Flags; + +/** + * @since 15.0 + **/ +public class EmbeddedFlags implements Flags { + int flags; + + EmbeddedFlags() { + } + + public static EmbeddedFlags of(EmbeddedFlag... flag) { + EmbeddedFlags flags = new EmbeddedFlags(); + for (EmbeddedFlag f : flag) { + flags.add(f); + } + return flags; + } + + public static int toInt(CacheOptions.Impl options) { + EmbeddedFlags flags = (EmbeddedFlags) options.rawFlags(); + return flags == null ? 0 : flags.toInt(); + } + + @Override + public EmbeddedFlags add(EmbeddedFlag flag) { + flags |= flag.getFlagInt(); + return this; + } + + @Override + public boolean contains(EmbeddedFlag flag) { + return (flags & flag.getFlagInt()) != 0; + } + + @Override + public EmbeddedFlags addAll(Flags flags) { + EmbeddedFlags theFlags = (EmbeddedFlags) flags; + this.flags |= theFlags.flags; + return this; + } + + public int toInt() { + return flags; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCache.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCache.java new file mode 100644 index 000000000000..7e21953b2337 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCache.java @@ -0,0 +1,141 @@ +package org.infinispan.embedded; + +import java.util.Map; +import java.util.Set; + +import org.infinispan.AdvancedCache; +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 org.infinispan.api.mutiny.MutinyCache; +import org.infinispan.api.mutiny.MutinyCacheEntryProcessor; +import org.infinispan.api.mutiny.MutinyContainer; +import org.infinispan.api.mutiny.MutinyQuery; +import org.infinispan.api.mutiny.MutinyStreamingCache; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyCache implements MutinyCache { + private final Embedded embedded; + private final AdvancedCache cache; + + EmbeddedMutinyCache(Embedded embedded, AdvancedCache cache) { + this.embedded = embedded; + this.cache = cache; + } + + @Override + public String name() { + return cache.getName(); + } + + @Override + public Uni configuration() { + return null; + } + + @Override + public MutinyContainer container() { + return embedded.mutiny(); + } + + @Override + public Uni> getEntry(K key, CacheOptions options) { + return null; + } + + @Override + public Uni> putIfAbsent(K key, V value, CacheWriteOptions options) { + return null; + } + + @Override + public Uni> put(K key, V value, CacheWriteOptions options) { + return null; + } + + @Override + public Uni> getAndRemove(K key, CacheOptions options) { + return null; + } + + @Override + public Multi> entries(CacheOptions options) { + return null; + } + + @Override + public Multi> getAll(Set keys, CacheOptions options) { + return null; + } + + @Override + public Multi> getAll(CacheOptions options, K... keys) { + return null; + } + + @Override + public Uni putAll(Multi> pairs, CacheWriteOptions options) { + return null; + } + + @Override + public Uni putAll(Map map, CacheWriteOptions options) { + return null; + } + + @Override + public Uni> getOrReplaceEntry(K key, V value, CacheEntryVersion version, CacheWriteOptions options) { + return null; + } + + @Override + public Multi removeAll(Set keys, CacheWriteOptions options) { + return null; + } + + @Override + public Multi removeAll(Multi keys, CacheWriteOptions options) { + return null; + } + + @Override + public Uni estimateSize(CacheOptions options) { + return Uni.createFrom().completionStage(cache.sizeAsync()); + } + + @Override + public Uni clear(CacheOptions options) { + return Uni.createFrom().completionStage(cache.clearAsync()); + } + + @Override + public MutinyQuery query(String query, CacheOptions options) { + return new EmbeddedMutinyQuery<>(cache.query(query), options); + } + + @Override + public Multi> listen(CacheListenerOptions options, CacheEntryEventType... types) { + return null; + } + + @Override + public Multi> process(Set keys, MutinyCacheEntryProcessor processor, CacheOptions options) { + return null; + } + + @Override + public MutinyStreamingCache streaming() { + return new EmbeddedMutinyStreamingCache<>(cache); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCaches.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCaches.java new file mode 100644 index 000000000000..79e59c75ab98 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyCaches.java @@ -0,0 +1,61 @@ +package org.infinispan.embedded; + +import org.infinispan.Cache; +import org.infinispan.api.configuration.CacheConfiguration; +import org.infinispan.api.mutiny.MutinyCache; +import org.infinispan.api.mutiny.MutinyCaches; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyCaches implements MutinyCaches { + private final Embedded embedded; + + EmbeddedMutinyCaches(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public Uni> create(String name, CacheConfiguration cacheConfiguration) { + return null; + } + + @Override + public Uni> create(String name, String template) { + return null; + } + + @Override + public Uni> get(String name) { + Uni> uni = Uni.createFrom().completionStage(embedded.cacheManager.getCacheAsync(name)); + return uni.onItem().transform(Cache::getAdvancedCache).onItem().transform(a -> new EmbeddedMutinyCache<>(embedded, a)); + } + + @Override + public Uni remove(String name) { + return null; + } + + @Override + public Multi names() { + return null; + } + + @Override + public Uni createTemplate(String name, CacheConfiguration cacheConfiguration) { + return null; + } + + @Override + public Uni removeTemplate(String name) { + return null; + } + + @Override + public Multi templateNames() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyContainer.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyContainer.java new file mode 100644 index 000000000000..cf952aa8ebb3 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyContainer.java @@ -0,0 +1,88 @@ +package org.infinispan.embedded; + +import java.util.function.Function; + +import org.infinispan.api.async.AsyncContainer; +import org.infinispan.api.common.events.container.ContainerEvent; +import org.infinispan.api.common.events.container.ContainerListenerEventType; +import org.infinispan.api.mutiny.MutinyCaches; +import org.infinispan.api.mutiny.MutinyContainer; +import org.infinispan.api.mutiny.MutinyLocks; +import org.infinispan.api.mutiny.MutinyMultimaps; +import org.infinispan.api.mutiny.MutinyStrongCounters; +import org.infinispan.api.mutiny.MutinyWeakCounters; +import org.infinispan.api.sync.SyncContainer; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyContainer implements MutinyContainer { + private final Embedded embedded; + + EmbeddedMutinyContainer(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public SyncContainer sync() { + return embedded.sync(); + } + + @Override + public AsyncContainer async() { + return embedded.async(); + } + + @Override + public MutinyContainer mutiny() { + return this; + } + + @Override + public void close() { + embedded.close(); + } + + @Override + public MutinyCaches caches() { + return new EmbeddedMutinyCaches(embedded); + } + + @Override + public MutinyMultimaps multimaps() { + return new EmbeddedMutinyMultimaps(embedded); + } + + @Override + public MutinyStrongCounters strongCounters() { + return new EmbeddedMutinyStrongCounters(embedded); + } + + @Override + public MutinyWeakCounters weakCounters() { + return new EmbeddedMutinyWeakCounters(embedded); + } + + @Override + public MutinyLocks locks() { + return new EmbeddedMutinyLocks(embedded); + } + + @Override + public Multi listen(ContainerListenerEventType... types) { + return null; + } + + @Override + public Uni execute(String name, Object... args) { + return null; + } + + @Override + public Uni batch(Function> function) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyLocks.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyLocks.java new file mode 100644 index 000000000000..da715ae4e7ef --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyLocks.java @@ -0,0 +1,39 @@ +package org.infinispan.embedded; + +import org.infinispan.api.configuration.LockConfiguration; +import org.infinispan.api.mutiny.MutinyLock; +import org.infinispan.api.mutiny.MutinyLocks; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyLocks implements MutinyLocks { + private final Embedded embedded; + + EmbeddedMutinyLocks(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public Uni lock(String name) { + return null; + } + + @Override + public Uni create(String name, LockConfiguration configuration) { + return null; + } + + @Override + public Uni remove(String name) { + return null; + } + + @Override + public Multi names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyMultimaps.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyMultimaps.java new file mode 100644 index 000000000000..66f4df5bf1b9 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyMultimaps.java @@ -0,0 +1,59 @@ +package org.infinispan.embedded; + +import org.infinispan.api.configuration.MultimapConfiguration; +import org.infinispan.api.mutiny.MutinyMultimap; +import org.infinispan.api.mutiny.MutinyMultimaps; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyMultimaps implements MutinyMultimaps { + private final Embedded embedded; + + EmbeddedMutinyMultimaps(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public Uni> create(String name, MultimapConfiguration cacheConfiguration) { + return null; + } + + @Override + public Uni> create(String name, String template) { + return null; + } + + @Override + public Uni> get(String name) { + return null; + } + + @Override + public Uni remove(String name) { + return null; + } + + @Override + public Multi names() { + return null; + } + + @Override + public Uni createTemplate(String name, MultimapConfiguration cacheConfiguration) { + return null; + } + + @Override + public Uni removeTemplate(String name) { + return null; + } + + @Override + public Multi templateNames() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyQuery.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyQuery.java new file mode 100644 index 000000000000..858810e672d0 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyQuery.java @@ -0,0 +1,74 @@ +package org.infinispan.embedded; + +import java.util.concurrent.TimeUnit; + +import org.infinispan.api.common.CacheOptions; +import org.infinispan.api.common.events.cache.CacheContinuousQueryEvent; +import org.infinispan.api.common.process.CacheEntryProcessorResult; +import org.infinispan.api.common.process.CacheProcessor; +import org.infinispan.api.common.process.CacheProcessorOptions; +import org.infinispan.api.mutiny.MutinyCacheEntryProcessor; +import org.infinispan.api.mutiny.MutinyQuery; +import org.infinispan.api.mutiny.MutinyQueryResult; +import org.infinispan.commons.api.query.Query; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @param + * @param + * @param + * @since 15.0 + */ +public class EmbeddedMutinyQuery implements MutinyQuery { + private final Query query; + + EmbeddedMutinyQuery(Query query, CacheOptions options) { + this.query = query; + options.timeout().ifPresent(d -> query.timeout(d.toNanos(), TimeUnit.NANOSECONDS)); + } + + @Override + public MutinyQuery param(String name, Object value) { + query.setParameter(name, value); + return this; + } + + @Override + public MutinyQuery skip(long skip) { + query.startOffset(skip); + return this; + } + + @Override + public MutinyQuery limit(int limit) { + query.maxResults(limit); + return this; + } + + @Override + public Uni> find() { + return null; + } + + @Override + public Multi> findContinuously() { + return null; + } + + @Override + public Uni execute() { + return null; + } + + @Override + public Multi> process(MutinyCacheEntryProcessor processor, CacheProcessorOptions options) { + return null; + } + + @Override + public Multi> process(CacheProcessor processor, CacheProcessorOptions options) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStreamingCache.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStreamingCache.java new file mode 100644 index 000000000000..c594d334aed9 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStreamingCache.java @@ -0,0 +1,34 @@ +package org.infinispan.embedded; + +import org.infinispan.AdvancedCache; +import org.infinispan.api.common.CacheOptions; +import org.infinispan.api.common.CacheWriteOptions; +import org.infinispan.api.mutiny.MutinyStreamingCache; + +import io.smallrye.mutiny.subscription.BackPressureStrategy; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyStreamingCache implements MutinyStreamingCache { + private final AdvancedCache cache; + + EmbeddedMutinyStreamingCache(AdvancedCache cache) { + this.cache = cache; + } + + @Override + public CacheEntrySubscriber get(K key, BackPressureStrategy backPressureStrategy, CacheOptions options) { + return null; + } + + @Override + public CacheEntryPublisher put(K key, CacheWriteOptions options, BackPressureStrategy backPressureStrategy) { + return null; + } + + @Override + public CacheEntryPublisher putIfAbsent(K key, CacheWriteOptions options, BackPressureStrategy backPressureStrategy) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStrongCounters.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStrongCounters.java new file mode 100644 index 000000000000..614bc2a8896e --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyStrongCounters.java @@ -0,0 +1,43 @@ +package org.infinispan.embedded; + +import org.infinispan.api.configuration.CounterConfiguration; +import org.infinispan.api.mutiny.MutinyStrongCounter; +import org.infinispan.api.mutiny.MutinyStrongCounters; +import org.infinispan.counter.EmbeddedCounterManagerFactory; +import org.infinispan.counter.api.CounterManager; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyStrongCounters implements MutinyStrongCounters { + private final Embedded embedded; + private final CounterManager counterManager; + + EmbeddedMutinyStrongCounters(Embedded embedded) { + this.embedded = embedded; + this.counterManager = EmbeddedCounterManagerFactory.asCounterManager(embedded.cacheManager); + } + + @Override + public Uni get(String name) { + return null; + } + + @Override + public Uni create(String name, CounterConfiguration configuration) { + return null; + } + + @Override + public Uni remove(String name) { + return null; + } + + @Override + public Multi names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyWeakCounters.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyWeakCounters.java new file mode 100644 index 000000000000..c67972094ce2 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedMutinyWeakCounters.java @@ -0,0 +1,43 @@ +package org.infinispan.embedded; + +import org.infinispan.api.configuration.CounterConfiguration; +import org.infinispan.api.mutiny.MutinyWeakCounter; +import org.infinispan.api.mutiny.MutinyWeakCounters; +import org.infinispan.counter.EmbeddedCounterManagerFactory; +import org.infinispan.counter.api.CounterManager; + +import io.smallrye.mutiny.Multi; +import io.smallrye.mutiny.Uni; + +/** + * @since 15.0 + */ +public class EmbeddedMutinyWeakCounters implements MutinyWeakCounters { + private final Embedded embedded; + private final CounterManager counterManager; + + EmbeddedMutinyWeakCounters(Embedded embedded) { + this.embedded = embedded; + this.counterManager = EmbeddedCounterManagerFactory.asCounterManager(embedded.cacheManager); + } + + @Override + public Uni get(String name) { + return null; + } + + @Override + public Uni create(String name, CounterConfiguration configuration) { + return null; + } + + @Override + public Uni remove(String name) { + return null; + } + + @Override + public Multi names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCache.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCache.java new file mode 100644 index 000000000000..95a80f0eaf47 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCache.java @@ -0,0 +1,144 @@ +package org.infinispan.embedded; + +import java.util.Map; +import java.util.Set; + +import org.infinispan.AdvancedCache; +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.SyncCache; +import org.infinispan.api.sync.SyncCacheEntryProcessor; +import org.infinispan.api.sync.SyncContainer; +import org.infinispan.api.sync.SyncQuery; +import org.infinispan.api.sync.SyncStreamingCache; +import org.infinispan.api.sync.events.cache.SyncCacheEntryListener; +import org.infinispan.embedded.impl.EmbeddedCacheEntry; + +/** + * @since 15.0 + */ +public class EmbeddedSyncCache implements SyncCache { + private final Embedded embedded; + private final AdvancedCache cache; + + EmbeddedSyncCache(Embedded embedded, AdvancedCache cache) { + this.embedded = embedded; + this.cache = cache; + } + + @Override + public String name() { + return cache.getName(); + } + + @Override + public CacheConfiguration configuration() { + return null; + } + + @Override + public SyncContainer container() { + return embedded.sync(); + } + + @Override + public CacheEntry getEntry(K key, CacheOptions options) { + return new EmbeddedCacheEntry<>(cache.getCacheEntry(key)); + } + + @Override + public CacheEntry put(K key, V value, CacheWriteOptions options) { + return null; + } + + @Override + public CacheEntry putIfAbsent(K key, V value, CacheWriteOptions options) { + return null; + } + + @Override + public CacheEntry getOrReplaceEntry(K key, V value, CacheEntryVersion version, CacheWriteOptions options) { + return null; + } + + @Override + public boolean remove(K key, CacheEntryVersion version, CacheOptions options) { + return false; + } + + @Override + public CacheEntry getAndRemove(K key, CacheOptions options) { + return null; + } + + @Override + public CloseableIterable keys(CacheOptions options) { + return null; + } + + @Override + public CloseableIterable> entries(CacheOptions options) { + return null; + } + + @Override + public void putAll(Map entries, CacheWriteOptions options) { + + } + + @Override + public Map getAll(Set keys, CacheOptions options) { + return null; + } + + @Override + public Map getAll(CacheOptions options, K... keys) { + return null; + } + + @Override + public Set removeAll(Set keys, CacheWriteOptions options) { + return null; + } + + @Override + public long estimateSize(CacheOptions options) { + return 0; + } + + @Override + public void clear(CacheOptions options) { + cache.clear(); + } + + @Override + public SyncQuery query(String query, CacheOptions options) { + return new EmbeddedSyncQuery<>(cache.query(query), options); + } + + @Override + public AutoCloseable listen(SyncCacheEntryListener listener) { + return null; + } + + @Override + public Set> process(Set keys, SyncCacheEntryProcessor processor, CacheProcessorOptions options) { + return null; + } + + @Override + public Set> processAll(SyncCacheEntryProcessor processor, CacheProcessorOptions options) { + return null; + } + + @Override + public SyncStreamingCache streaming() { + return new EmbeddedSyncStreamingCache<>(cache); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCaches.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCaches.java new file mode 100644 index 000000000000..d6b12d6ffa98 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncCaches.java @@ -0,0 +1,61 @@ +package org.infinispan.embedded; + +import org.infinispan.Cache; +import org.infinispan.api.configuration.CacheConfiguration; +import org.infinispan.api.sync.SyncCache; +import org.infinispan.api.sync.SyncCaches; +import org.infinispan.configuration.cache.Configuration; + +/** + * @since 15.0 + */ +public class EmbeddedSyncCaches implements SyncCaches { + private final Embedded embedded; + + EmbeddedSyncCaches(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public SyncCache get(String name) { + Cache cache = embedded.cacheManager.getCache(name); + return new EmbeddedSyncCache<>(embedded, cache.getAdvancedCache()); + } + + @Override + public SyncCache create(String name, CacheConfiguration cacheConfiguration) { + Cache cache = embedded.cacheManager.administration().getOrCreateCache(name, (Configuration) cacheConfiguration); + return new EmbeddedSyncCache<>(embedded, cache.getAdvancedCache()); + } + + @Override + public SyncCache create(String name, String template) { + Cache cache = embedded.cacheManager.administration().getOrCreateCache(name, template); + return new EmbeddedSyncCache<>(embedded, cache.getAdvancedCache()); + } + + @Override + public void remove(String name) { + embedded.cacheManager.administration().removeCache(name); + } + + @Override + public Iterable names() { + return embedded.cacheManager.getCacheNames(); + } + + @Override + public void createTemplate(String name, CacheConfiguration cacheConfiguration) { + embedded.cacheManager.administration().createTemplate(name, (Configuration) cacheConfiguration); + } + + @Override + public void removeTemplate(String name) { + embedded.cacheManager.administration().removeTemplate(name); + } + + @Override + public Iterable templateNames() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncContainer.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncContainer.java new file mode 100644 index 000000000000..9aaf74687b35 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncContainer.java @@ -0,0 +1,80 @@ +package org.infinispan.embedded; + +import java.util.function.Function; + +import org.infinispan.api.async.AsyncContainer; +import org.infinispan.api.common.events.container.ContainerListenerEventType; +import org.infinispan.api.mutiny.MutinyContainer; +import org.infinispan.api.sync.SyncCaches; +import org.infinispan.api.sync.SyncContainer; +import org.infinispan.api.sync.SyncLocks; +import org.infinispan.api.sync.SyncMultimaps; +import org.infinispan.api.sync.SyncStrongCounters; +import org.infinispan.api.sync.SyncWeakCounters; +import org.infinispan.api.sync.events.container.SyncContainerListener; + +/** + * @since 15.0 + */ +public class EmbeddedSyncContainer implements SyncContainer { + private final Embedded embedded; + + EmbeddedSyncContainer(Embedded embedded) { + this.embedded = embedded; + } + + @Override + public SyncContainer sync() { + return this; + } + + @Override + public AsyncContainer async() { + return embedded.async(); + } + + @Override + public MutinyContainer mutiny() { + return embedded.mutiny(); + } + + @Override + public void close() { + embedded.close(); + } + + @Override + public SyncCaches caches() { + return new EmbeddedSyncCaches(embedded); + } + + @Override + public SyncMultimaps multimaps() { + return new EmbeddedSyncMultimaps(embedded); + } + + @Override + public SyncStrongCounters strongCounters() { + return new EmbeddedSyncStrongCounters(embedded); + } + + @Override + public SyncWeakCounters weakCounters() { + return new EmbeddedSyncWeakCounters(embedded); + } + + @Override + public SyncLocks locks() { + return new EmbeddedSyncLocks(embedded); + } + + @Override + public void listen(SyncContainerListener listener, ContainerListenerEventType... types) { + + } + + @Override + public T batch(Function function) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLock.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLock.java new file mode 100644 index 000000000000..e4f312b4689c --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLock.java @@ -0,0 +1,65 @@ +package org.infinispan.embedded; + +import static org.infinispan.commons.util.concurrent.CompletableFutures.uncheckedAwait; + +import java.util.concurrent.TimeUnit; + +import org.infinispan.api.sync.SyncContainer; +import org.infinispan.api.sync.SyncLock; +import org.infinispan.lock.api.ClusteredLock; + +/** + * @since 15.0 + */ +public class EmbeddedSyncLock implements SyncLock { + private final Embedded embedded; + private final String name; + private final ClusteredLock lock; + + EmbeddedSyncLock(Embedded embedded, String name, ClusteredLock lock) { + this.embedded = embedded; + this.name = name; + this.lock = lock; + } + + @Override + public String name() { + ; + return name; + } + + @Override + public SyncContainer container() { + return embedded.sync(); + } + + @Override + public void lock() { + uncheckedAwait(lock.lock()); + } + + @Override + public boolean tryLock() { + return uncheckedAwait(lock.tryLock()); + } + + @Override + public boolean tryLock(long time, TimeUnit unit) { + return uncheckedAwait(lock.tryLock(time, unit)); + } + + @Override + public void unlock() { + uncheckedAwait(lock.unlock()); + } + + @Override + public boolean isLocked() { + return uncheckedAwait(lock.isLocked()); + } + + @Override + public boolean isLockedByMe() { + return uncheckedAwait(lock.isLockedByMe()); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLocks.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLocks.java new file mode 100644 index 000000000000..1db5157b11ff --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncLocks.java @@ -0,0 +1,43 @@ +package org.infinispan.embedded; + +import static org.infinispan.commons.util.concurrent.CompletableFutures.uncheckedAwait; + +import org.infinispan.api.common.CloseableIterable; +import org.infinispan.api.configuration.LockConfiguration; +import org.infinispan.api.sync.SyncLock; +import org.infinispan.api.sync.SyncLocks; +import org.infinispan.lock.EmbeddedClusteredLockManagerFactory; +import org.infinispan.lock.api.ClusteredLockManager; + +/** + * @since 15.0 + */ +public class EmbeddedSyncLocks implements SyncLocks { + private final Embedded embedded; + private final ClusteredLockManager lockManager; + + EmbeddedSyncLocks(Embedded embedded) { + this.embedded = embedded; + this.lockManager = EmbeddedClusteredLockManagerFactory.from(embedded.cacheManager); + } + + @Override + public SyncLock create(String name, LockConfiguration configuration) { + return null; + } + + @Override + public SyncLock get(String name) { + return new EmbeddedSyncLock(embedded, name, lockManager.get(name)); + } + + @Override + public void remove(String name) { + uncheckedAwait(lockManager.remove(name)); + } + + @Override + public CloseableIterable names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimap.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimap.java new file mode 100644 index 000000000000..669d9b3e5f42 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimap.java @@ -0,0 +1,73 @@ +package org.infinispan.embedded; + +import static org.infinispan.commons.util.concurrent.CompletableFutures.uncheckedAwait; +import static org.infinispan.embedded.impl.EmbeddedUtil.closeableIterable; + +import org.infinispan.api.common.CloseableIterable; +import org.infinispan.api.configuration.MultimapConfiguration; +import org.infinispan.api.sync.SyncContainer; +import org.infinispan.api.sync.SyncMultimap; +import org.infinispan.multimap.api.embedded.MultimapCache; + +/** + * @since 15.0 + */ +public class EmbeddedSyncMultimap implements SyncMultimap { + private final Embedded embedded; + private final MultimapCache multimapCache; + + EmbeddedSyncMultimap(Embedded embedded, MultimapCache multimapCache) { + this.embedded = embedded; + this.multimapCache = multimapCache; + } + + @Override + public String name() { + return multimapCache.getName(); + } + + @Override + public MultimapConfiguration configuration() { + return null; + } + + @Override + public SyncContainer container() { + return embedded.sync(); + } + + @Override + public void add(K key, V value) { + uncheckedAwait(multimapCache.put(key, value)); + } + + @Override + public CloseableIterable get(K key) { + return closeableIterable(uncheckedAwait(multimapCache.get(key))); + } + + @Override + public boolean remove(K key) { + return uncheckedAwait(multimapCache.remove(key)); + } + + @Override + public boolean remove(K key, V value) { + return uncheckedAwait(multimapCache.remove(key, value)); + } + + @Override + public boolean containsKey(K key) { + return uncheckedAwait(multimapCache.containsKey(key)); + } + + @Override + public boolean containsEntry(K key, V value) { + return uncheckedAwait(multimapCache.containsEntry(key, value)); + } + + @Override + public long estimateSize() { + return uncheckedAwait(multimapCache.size()); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimaps.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimaps.java new file mode 100644 index 000000000000..4317cab9a725 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncMultimaps.java @@ -0,0 +1,63 @@ +package org.infinispan.embedded; + +import org.infinispan.api.common.CloseableIterable; +import org.infinispan.api.configuration.MultimapConfiguration; +import org.infinispan.api.sync.SyncMultimap; +import org.infinispan.api.sync.SyncMultimaps; +import org.infinispan.multimap.api.embedded.EmbeddedMultimapCacheManagerFactory; +import org.infinispan.multimap.api.embedded.MultimapCache; +import org.infinispan.multimap.api.embedded.MultimapCacheManager; + +/** + * @since 15.0 + */ +public class EmbeddedSyncMultimaps implements SyncMultimaps { + private final Embedded embedded; + private final MultimapCacheManager multimapCacheManager; + + EmbeddedSyncMultimaps(Embedded embedded) { + this.embedded = embedded; + this.multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(embedded.cacheManager); + } + + @Override + public SyncMultimap get(String name) { + MultimapCache multimapCache = multimapCacheManager.get(name); + return new EmbeddedSyncMultimap(embedded, multimapCache); + } + + @Override + public SyncMultimap create(String name, MultimapConfiguration cacheConfiguration) { + return null; + } + + @Override + public SyncMultimap create(String name, String template) { + return null; + } + + @Override + public void remove(String name) { + + } + + @Override + public CloseableIterable names() { + return null; + } + + @Override + public void createTemplate(String name, MultimapConfiguration cacheConfiguration) { + + } + + @Override + public void removeTemplate(String name) { + + } + + @Override + public CloseableIterable templateNames() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQuery.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQuery.java new file mode 100644 index 000000000000..f0298e9d086c --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQuery.java @@ -0,0 +1,68 @@ +package org.infinispan.embedded; + +import java.util.Map; +import java.util.concurrent.TimeUnit; + +import org.infinispan.api.common.CacheOptions; +import org.infinispan.api.common.process.CacheProcessor; +import org.infinispan.api.common.process.CacheProcessorOptions; +import org.infinispan.api.sync.SyncCacheEntryProcessor; +import org.infinispan.api.sync.SyncQuery; +import org.infinispan.api.sync.SyncQueryResult; +import org.infinispan.api.sync.events.cache.SyncCacheContinuousQueryListener; +import org.infinispan.commons.api.query.Query; + +/** + * @since 15.0 + */ +public class EmbeddedSyncQuery implements SyncQuery { + private final Query query; + + EmbeddedSyncQuery(Query query, CacheOptions options) { + this.query = query; + options.timeout().ifPresent(d -> query.timeout(d.toNanos(), TimeUnit.NANOSECONDS)); + } + + @Override + public SyncQuery param(String name, Object value) { + query.setParameter(name, value); + return this; + } + + @Override + public SyncQuery skip(long skip) { + query.startOffset(skip); + return this; + } + + @Override + public SyncQuery limit(int limit) { + query.maxResults(limit); + return this; + } + + @Override + public SyncQueryResult find() { + return new EmbeddedSyncQueryResult<>(query.execute()); + } + + @Override + public AutoCloseable findContinuously(SyncCacheContinuousQueryListener listener) { + return null; + } + + @Override + public int execute() { + return query.executeStatement(); + } + + @Override + public Map process(SyncCacheEntryProcessor processor, CacheProcessorOptions options) { + return null; + } + + @Override + public Map process(CacheProcessor processor, CacheProcessorOptions options) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQueryResult.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQueryResult.java new file mode 100644 index 000000000000..1da8cafd340d --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncQueryResult.java @@ -0,0 +1,34 @@ +package org.infinispan.embedded; + +import java.util.OptionalLong; + +import org.infinispan.api.common.CloseableIterable; +import org.infinispan.api.sync.SyncQueryResult; +import org.infinispan.commons.api.query.QueryResult; +import org.infinispan.embedded.impl.EmbeddedUtil; + +/** + * @param + * @since 15.0 + */ +public class EmbeddedSyncQueryResult implements SyncQueryResult { + private final QueryResult result; + + EmbeddedSyncQueryResult(QueryResult result) { + this.result = result; + } + + @Override + public OptionalLong hitCount() { + return OptionalLong.of(result.count().value()); + } + + @Override + public CloseableIterable results() { + return EmbeddedUtil.closeableIterable(result.list()); + } + + @Override + public void close() { + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStreamingCache.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStreamingCache.java new file mode 100644 index 000000000000..156479a6fd46 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStreamingCache.java @@ -0,0 +1,37 @@ +package org.infinispan.embedded; + +import java.io.InputStream; +import java.io.OutputStream; + +import org.infinispan.AdvancedCache; +import org.infinispan.api.common.CacheEntryMetadata; +import org.infinispan.api.common.CacheOptions; +import org.infinispan.api.common.CacheWriteOptions; +import org.infinispan.api.sync.SyncStreamingCache; + +/** + * @param + * @since 15.0 + */ +public class EmbeddedSyncStreamingCache implements SyncStreamingCache { + private final AdvancedCache cache; + + EmbeddedSyncStreamingCache(AdvancedCache cache) { + this.cache = cache; + } + + @Override + public T get(K key, CacheOptions options) { + return null; + } + + @Override + public OutputStream put(K key, CacheOptions options) { + return null; + } + + @Override + public OutputStream putIfAbsent(K key, CacheWriteOptions options) { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounter.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounter.java new file mode 100644 index 000000000000..44b34b4ae184 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounter.java @@ -0,0 +1,70 @@ +package org.infinispan.embedded; + +import static org.infinispan.commons.util.concurrent.CompletableFutures.uncheckedAwait; + +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; + +import org.infinispan.api.common.events.counter.CounterEvent; +import org.infinispan.api.configuration.CounterConfiguration; +import org.infinispan.api.sync.SyncContainer; +import org.infinispan.api.sync.SyncStrongCounter; +import org.infinispan.counter.api.StrongCounter; + +/** + * @since 15.0 + */ +public class EmbeddedSyncStrongCounter implements SyncStrongCounter { + private final Embedded embedded; + private final StrongCounter counter; + + EmbeddedSyncStrongCounter(Embedded embedded, StrongCounter counter) { + this.embedded = embedded; + this.counter = counter; + } + + @Override + public String name() { + return counter.getName(); + } + + @Override + public SyncContainer container() { + return embedded.sync(); + } + + @Override + public long value() { + return uncheckedAwait(counter.getValue()); + } + + @Override + public long addAndGet(long delta) { + return uncheckedAwait(counter.addAndGet(delta)); + } + + @Override + public CompletableFuture reset() { + return counter.reset(); + } + + @Override + public AutoCloseable listen(Consumer listener) { + return null; + } + + @Override + public long compareAndSwap(long expect, long update) { + return uncheckedAwait(counter.compareAndSwap(expect, update)); + } + + @Override + public long getAndSet(long value) { + return uncheckedAwait(counter.getAndSet(value)); + } + + @Override + public CounterConfiguration configuration() { + return (CounterConfiguration) counter.getConfiguration(); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounters.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounters.java new file mode 100644 index 000000000000..b334679062c9 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncStrongCounters.java @@ -0,0 +1,43 @@ +package org.infinispan.embedded; + +import org.infinispan.api.configuration.CounterConfiguration; +import org.infinispan.api.sync.SyncStrongCounter; +import org.infinispan.api.sync.SyncStrongCounters; +import org.infinispan.counter.EmbeddedCounterManagerFactory; +import org.infinispan.counter.api.CounterManager; +import org.infinispan.counter.api.StrongCounter; + +/** + * @since 15.0 + */ +public class EmbeddedSyncStrongCounters implements SyncStrongCounters { + private final Embedded embedded; + private final CounterManager counterManager; + + EmbeddedSyncStrongCounters(Embedded embedded) { + this.embedded = embedded; + this.counterManager = EmbeddedCounterManagerFactory.asCounterManager(embedded.cacheManager); + } + + @Override + public SyncStrongCounter get(String name) { + StrongCounter counter = counterManager.getStrongCounter(name); + return new EmbeddedSyncStrongCounter(embedded, counter); + } + + @Override + public SyncStrongCounter create(String name, CounterConfiguration counterConfiguration) { + return null; + } + + @Override + public void remove(String name) { + counterManager.remove(name); + } + + @Override + public Iterable names() { + //FIXME: filter strong counters + return counterManager.getCounterNames(); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounter.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounter.java new file mode 100644 index 000000000000..e36cc9618e72 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounter.java @@ -0,0 +1,38 @@ +package org.infinispan.embedded; + +import org.infinispan.api.sync.SyncContainer; +import org.infinispan.api.sync.SyncWeakCounter; +import org.infinispan.counter.api.WeakCounter; + +/** + * @since 15.0 + */ +public class EmbeddedSyncWeakCounter implements SyncWeakCounter { + private final Embedded embedded; + private final WeakCounter counter; + + EmbeddedSyncWeakCounter(Embedded embedded, WeakCounter counter) { + this.embedded = embedded; + this.counter = counter; + } + + @Override + public String name() { + return counter.getName(); + } + + @Override + public SyncContainer container() { + return embedded.sync(); + } + + @Override + public long value() { + return counter.getValue(); + } + + @Override + public void add(long delta) { + counter.add(delta); + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounters.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounters.java new file mode 100644 index 000000000000..2692988cd75f --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedSyncWeakCounters.java @@ -0,0 +1,42 @@ +package org.infinispan.embedded; + +import org.infinispan.api.configuration.CounterConfiguration; +import org.infinispan.api.sync.SyncWeakCounter; +import org.infinispan.api.sync.SyncWeakCounters; +import org.infinispan.counter.EmbeddedCounterManagerFactory; +import org.infinispan.counter.api.CounterManager; +import org.infinispan.counter.api.WeakCounter; + +/** + * @since 15.0 + */ +public class EmbeddedSyncWeakCounters implements SyncWeakCounters { + private final Embedded embedded; + private final CounterManager counterManager; + + EmbeddedSyncWeakCounters(Embedded embedded) { + this.embedded = embedded; + this.counterManager = EmbeddedCounterManagerFactory.asCounterManager(embedded.cacheManager); + } + + @Override + public SyncWeakCounter get(String name) { + WeakCounter counter = counterManager.getWeakCounter(name); + return new EmbeddedSyncWeakCounter(embedded, counter); + } + + @Override + public SyncWeakCounter create(String name, CounterConfiguration counterConfiguration) { + return null; + } + + @Override + public void remove(String name) { + + } + + @Override + public Iterable names() { + return null; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/EmbeddedURI.java b/embedded/src/main/java/org/infinispan/embedded/EmbeddedURI.java new file mode 100644 index 000000000000..0bdfed360ff2 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/EmbeddedURI.java @@ -0,0 +1,119 @@ +package org.infinispan.embedded; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; +import java.util.Properties; + +import org.infinispan.api.exception.InfinispanException; +import org.infinispan.commons.configuration.io.ConfigurationReader; +import org.infinispan.commons.configuration.io.URLConfigurationResourceResolver; +import org.infinispan.commons.dataconversion.MediaType; +import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; +import org.infinispan.configuration.parsing.ParserRegistry; +import org.infinispan.embedded.impl.logging.Log; + +/** + * EmbeddedURI represents an embedded Infinispan configuration. The following URI schemes are supported: + *
    + *
  • infinispan:file:<path> or file:<path>points to an Infinispan configuration file (XML, JSON or YAML) on the filesystem
  • + *
  • infinispan:classpath:<path> or classpath:<path> points to an Infinispan configuration file (XML, JSON or YAML) as a classpath resource
  • + *
  • <path> looks for an Infinispan configuration file (XML, JSON or YAML) first on the filesystem and then in the classpath
  • + *
  • infinispan:local://<name> A local (non-clustered) Infinispan instance
  • + *
  • infinispan:cluster://[username:[password]@][bind]:[port][?propertyName=value&...] A clustered Infinispan instance
  • + *
+ * + * @since 15.0 + **/ +public class EmbeddedURI { + private final ConfigurationBuilderHolder configuration; + private final URI uri; + + public static EmbeddedURI create(String uriString) { + return create(URI.create(uriString)); + } + + public static EmbeddedURI create(URI uri) { + if ("file".equals(uri.getScheme())) { + try { + return new EmbeddedURI(uri, parseURL(uri.toURL())); + } catch (IOException e) { + throw new InfinispanException(e); + } + } else if ("classpath".equals(uri.getScheme())) { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + URL resource = classLoader == null ? null : classLoader.getResource(uri.getPath().substring(1)); + if (resource == null) { + resource = ClassLoader.getSystemClassLoader().getResource(uri.getPath().substring(1)); + } + if (resource != null) { + try { + return new EmbeddedURI(uri, parseURL(resource)); + } catch (IOException e) { + throw new InfinispanException(e); + } + } else { + throw new InfinispanException(new FileNotFoundException(uri.toString())); + } + } else if ("infinispan".equals(uri.getScheme())) { + URI subUri = URI.create(uri.getSchemeSpecificPart()); + if ("file".equals(subUri.getScheme()) || "classpath".equals(subUri.getScheme())) { + return create(subUri); + } + ConfigurationBuilderHolder holder = new ConfigurationBuilderHolder(); + if ("local".equals(subUri.getScheme())) { + holder.getGlobalConfigurationBuilder().nonClusteredDefault().cacheManagerName(subUri.getHost()); + } else if ("cluster".equals(subUri.getScheme())) { + holder.getGlobalConfigurationBuilder().clusteredDefault(); + } else { + throw Log.EMBEDDED.notAnEmbeddedURI(uri.toString()); + } + return new EmbeddedURI(uri, holder); + } + throw Log.EMBEDDED.notAnEmbeddedURI(uri.toString()); + } + + private static ConfigurationBuilderHolder parseURL(URL url) throws IOException { + try (InputStream is = url.openStream()) { + ConfigurationReader reader = ConfigurationReader.from(is) + .withProperties(queryToProperties(url.getQuery())) + .withType(MediaType.fromExtension(url.getFile())) + .withResolver(new URLConfigurationResourceResolver(url)) + .build(); + return new ParserRegistry().parse(reader, new ConfigurationBuilderHolder()); + } + } + + private static Properties queryToProperties(String query) { + Properties properties = new Properties(); + if (query != null) { + String[] pairs = query.split("&"); + for (String pair : pairs) { + int idx = pair.indexOf("="); + properties.setProperty( + URLDecoder.decode(pair.substring(0, idx), StandardCharsets.UTF_8), + URLDecoder.decode(pair.substring(idx + 1), StandardCharsets.UTF_8) + ); + } + } + return properties; + } + + private EmbeddedURI(URI uri, ConfigurationBuilderHolder configuration) { + this.uri = uri; + this.configuration = configuration; + } + + @Override + public String toString() { + return uri.toString(); + } + + ConfigurationBuilderHolder toConfiguration() { + return configuration; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedCacheEntry.java b/embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedCacheEntry.java new file mode 100644 index 000000000000..959361987790 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedCacheEntry.java @@ -0,0 +1,52 @@ +package org.infinispan.embedded.impl; + +import java.time.Instant; +import java.util.Optional; + +import org.infinispan.api.common.CacheEntry; +import org.infinispan.api.common.CacheEntryExpiration; +import org.infinispan.api.common.CacheEntryMetadata; +import org.infinispan.api.common.CacheEntryVersion; + +public class EmbeddedCacheEntry implements CacheEntry { + private final org.infinispan.container.entries.CacheEntry entry; + + public EmbeddedCacheEntry(org.infinispan.container.entries.CacheEntry entry) { + this.entry = entry; + } + + @Override + public K key() { + return entry.getKey(); + } + + @Override + public V value() { + return entry.getValue(); + } + + @Override + public CacheEntryMetadata metadata() { + return new CacheEntryMetadata() { + @Override + public Optional creationTime() { + return Optional.empty(); + } + + @Override + public Optional lastAccessTime() { + return Optional.empty(); + } + + @Override + public CacheEntryExpiration expiration() { + return null; + } + + @Override + public CacheEntryVersion version() { + return null; + } + }; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedUtil.java b/embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedUtil.java new file mode 100644 index 000000000000..323cb16cd8e8 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/impl/EmbeddedUtil.java @@ -0,0 +1,29 @@ +package org.infinispan.embedded.impl; + +import java.util.Iterator; + +import org.infinispan.api.common.CloseableIterable; +import org.infinispan.api.common.CloseableIterator; + +public class EmbeddedUtil { + + public static CloseableIterable closeableIterable(Iterable i) { + Iterator it = i.iterator(); + return () -> new CloseableIterator<>() { + @Override + public void close() { + // no-op + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public V next() { + return it.next(); + } + }; + } +} diff --git a/embedded/src/main/java/org/infinispan/embedded/impl/logging/Log.java b/embedded/src/main/java/org/infinispan/embedded/impl/logging/Log.java new file mode 100644 index 000000000000..81c20ad8fada --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/impl/logging/Log.java @@ -0,0 +1,20 @@ +package org.infinispan.embedded.impl.logging; + +import org.jboss.logging.BasicLogger; +import org.jboss.logging.Logger; +import org.jboss.logging.annotations.Message; +import org.jboss.logging.annotations.MessageLogger; + +/** + * Log abstraction for the embedded module. + * + * @since 15.0 + */ +@MessageLogger(projectCode = "ISPN") +public interface Log extends BasicLogger { + String LOG_ROOT = "org.infinispan."; + Log EMBEDDED = Logger.getMessageLogger(Log.class, LOG_ROOT + "EMBEDDED"); + + @Message(value = "Not an Infinispan embedded URI: %s", id = 13000) + IllegalArgumentException notAnEmbeddedURI(String string); +} diff --git a/embedded/src/main/java/org/infinispan/embedded/impl/logging/LogFactory.java b/embedded/src/main/java/org/infinispan/embedded/impl/logging/LogFactory.java new file mode 100644 index 000000000000..81a25498fb33 --- /dev/null +++ b/embedded/src/main/java/org/infinispan/embedded/impl/logging/LogFactory.java @@ -0,0 +1,20 @@ +package org.infinispan.embedded.impl.logging; + +import org.jboss.logging.Logger; + +/** + * Factory that creates {@link Log} instances. + * + * @since 15.0 + */ +public class LogFactory { + + public static Log getLog(Class clazz) { + return Logger.getMessageLogger(Log.class, clazz.getName()); + } + + public static T getLog(Class clazz, Class logClass) { + return Logger.getMessageLogger(logClass, clazz.getName()); + } + +} diff --git a/embedded/src/test/java/org/infinispan/embedded/EmbeddedTest.java b/embedded/src/test/java/org/infinispan/embedded/EmbeddedTest.java new file mode 100644 index 000000000000..bd5475be05b8 --- /dev/null +++ b/embedded/src/test/java/org/infinispan/embedded/EmbeddedTest.java @@ -0,0 +1,19 @@ +package org.infinispan.embedded; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.infinispan.api.Infinispan; +import org.infinispan.api.sync.SyncCache; +import org.infinispan.configuration.cache.ConfigurationBuilder; +import org.junit.jupiter.api.Test; + +public class EmbeddedTest { + @Test + public void testEmbedded() { + try (Infinispan infinispan = Infinispan.create("infinispan:local://infinispan")) { + SyncCache cache = infinispan.sync().caches().create("test", new ConfigurationBuilder().build()); + cache.set("k1", "v1"); + assertEquals("v1", cache.get("k1")); + } + } +} diff --git a/embedded/src/test/java/org/infinispan/embedded/EmbeddedURITest.java b/embedded/src/test/java/org/infinispan/embedded/EmbeddedURITest.java new file mode 100644 index 000000000000..3a52fef90899 --- /dev/null +++ b/embedded/src/test/java/org/infinispan/embedded/EmbeddedURITest.java @@ -0,0 +1,55 @@ +package org.infinispan.embedded; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.infinispan.configuration.global.GlobalConfiguration; +import org.junit.jupiter.api.Test; + +public class EmbeddedURITest { + @Test + public void testInfinispanLocal() { + EmbeddedURI uri = EmbeddedURI.create("infinispan:local://infinispan?cache-container.jndi-name=JNDI"); + GlobalConfiguration gc = uri.toConfiguration().getGlobalConfigurationBuilder().build(); + assertEquals("infinispan", gc.cacheManagerName()); + assertFalse(gc.isClustered()); + } + + @Test + public void testInfinispanCluster() { + EmbeddedURI uri = EmbeddedURI.create("infinispan:cluster://infinispan"); + GlobalConfiguration gc = uri.toConfiguration().getGlobalConfigurationBuilder().build(); + assertTrue(gc.isClustered()); + } + + @Test + public void testInfinispanClasspath() { + EmbeddedURI uri = EmbeddedURI.create("infinispan:classpath:///infinispan-uri.xml"); + GlobalConfiguration gc = uri.toConfiguration().getGlobalConfigurationBuilder().build(); + assertEquals(gc.cacheManagerName(), "uri"); + } + + @Test + public void testClasspath() { + EmbeddedURI uri = EmbeddedURI.create("classpath:///infinispan-uri.xml"); + GlobalConfiguration gc = uri.toConfiguration().getGlobalConfigurationBuilder().build(); + assertEquals(gc.cacheManagerName(), "uri"); + } + + @Test + public void testInfinispanFile() { + String property = System.getProperty("build.directory"); + EmbeddedURI uri = EmbeddedURI.create("infinispan:file://" + property + "/test-classes/infinispan-uri.xml"); + GlobalConfiguration gc = uri.toConfiguration().getGlobalConfigurationBuilder().build(); + assertEquals(gc.cacheManagerName(), "uri"); + } + + @Test + public void testFile() { + String property = System.getProperty("build.directory"); + EmbeddedURI uri = EmbeddedURI.create("file://" + property + "/test-classes/infinispan-uri.xml"); + GlobalConfiguration gc = uri.toConfiguration().getGlobalConfigurationBuilder().build(); + assertEquals(gc.cacheManagerName(), "uri"); + } +} diff --git a/embedded/src/test/resources/infinispan-uri.xml b/embedded/src/test/resources/infinispan-uri.xml new file mode 100644 index 000000000000..6310d7d0ab11 --- /dev/null +++ b/embedded/src/test/resources/infinispan-uri.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/multimap/src/main/java/org/infinispan/multimap/api/embedded/MultimapCacheManager.java b/multimap/src/main/java/org/infinispan/multimap/api/embedded/MultimapCacheManager.java index 42ae4288801a..9ff9828e6d41 100644 --- a/multimap/src/main/java/org/infinispan/multimap/api/embedded/MultimapCacheManager.java +++ b/multimap/src/main/java/org/infinispan/multimap/api/embedded/MultimapCacheManager.java @@ -4,7 +4,7 @@ import org.infinispan.configuration.cache.Configuration; @Experimental -public interface MultimapCacheManager { +public interface MultimapCacheManager { /** * Defines a named multimap cache's configuration by using the provided configuration @@ -25,7 +25,7 @@ public interface MultimapCacheManager { * @return null if no configuration exists as per rules set above, otherwise returns a multimap cache instance * identified by cacheName and doesn't support duplicates */ - default MultimapCache get(String name) { + default MultimapCache get(String name) { return get(name, false); } @@ -37,5 +37,5 @@ default MultimapCache get(String name) { * @return null if no configuration exists as per rules set above, otherwise returns a multimap cache instance * identified by cacheName */ - MultimapCache get(String name, boolean supportsDuplicates); + MultimapCache get(String name, boolean supportsDuplicates); } diff --git a/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCache.java b/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCache.java index 09d36ffbcedf..50cbff902629 100644 --- a/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCache.java +++ b/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCache.java @@ -201,4 +201,9 @@ public boolean supportsDuplicates() { public Cache> getCache() { return cache; } + + @Override + public String getName() { + return cache.getName(); + } } diff --git a/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCacheManager.java b/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCacheManager.java index 08fd8aadfdb3..ddb7ebd89f5d 100644 --- a/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCacheManager.java +++ b/multimap/src/main/java/org/infinispan/multimap/impl/EmbeddedMultimapCacheManager.java @@ -1,7 +1,5 @@ package org.infinispan.multimap.impl; -import java.util.Collection; - import org.infinispan.Cache; import org.infinispan.configuration.cache.Configuration; import org.infinispan.manager.EmbeddedCacheManager; @@ -14,7 +12,7 @@ * @author Katia Aresti, karesti@redhat.com * @since 9.2 */ -public class EmbeddedMultimapCacheManager implements MultimapCacheManager { +public class EmbeddedMultimapCacheManager implements MultimapCacheManager { private final EmbeddedCacheManager cacheManager; @@ -28,10 +26,9 @@ public Configuration defineConfiguration(String name, Configuration configuratio } @Override - public MultimapCache get(String name, boolean supportsDuplicates) { - Cache> cache = cacheManager.getCache(name, true); - EmbeddedMultimapCache multimapCache = new EmbeddedMultimapCache(cache, supportsDuplicates); - return multimapCache; + public MultimapCache get(String name, boolean supportsDuplicates) { + Cache> cache = cacheManager.getCache(name, true); + return new EmbeddedMultimapCache<>(cache, supportsDuplicates); } /** @@ -40,7 +37,7 @@ public MultimapCache get(String name, boolean supportsDuplicates) { * @param cacheName, name of the cache * @return EmbeddedMultimapListCache */ - public EmbeddedMultimapListCache getMultimapList(String cacheName) { + public EmbeddedMultimapListCache getMultimapList(String cacheName) { Cache> cache = cacheManager.getCache(cacheName); if (cache == null) { throw new IllegalStateException("Cache must exist: " + cacheName); @@ -54,7 +51,7 @@ public EmbeddedMultimapListCache getMultimapList(String cacheName) { * @param cacheName, name of the cache * @return EmbeddedMultimapSortedSetCache */ - public EmbeddedMultimapSortedSetCache getMultimapSortedSet(String cacheName) { + public EmbeddedMultimapSortedSetCache getMultimapSortedSet(String cacheName) { Cache> cache = cacheManager.getCache(cacheName); if (cache == null) { throw new IllegalStateException("Cache must exist: " + cacheName); @@ -62,7 +59,7 @@ public EmbeddedMultimapSortedSetCache getMultimapSortedSet(String cacheNam return new EmbeddedMultimapSortedSetCache<>(cache); } - public EmbeddedMultimapPairCache getMultimapPair(String cacheName) { + public EmbeddedMultimapPairCache getMultimapPair(String cacheName) { Cache> cache = cacheManager.getCache(cacheName); if (cache == null) { throw new IllegalStateException("Cache must exist: " + cacheName); diff --git a/multimap/src/test/java/org/infinispan/multimap/impl/MultimapStoreBucketTest.java b/multimap/src/test/java/org/infinispan/multimap/impl/MultimapStoreBucketTest.java index 860ee2be050b..44ccba8d4974 100644 --- a/multimap/src/test/java/org/infinispan/multimap/impl/MultimapStoreBucketTest.java +++ b/multimap/src/test/java/org/infinispan/multimap/impl/MultimapStoreBucketTest.java @@ -32,7 +32,7 @@ public void testMultimapWithJavaSerializationMarshaller() throws Exception { config.persistence().addStore(DummyInMemoryStoreConfigurationBuilder.class); EmbeddedCacheManager cm = TestCacheManagerFactory.createCacheManager(globalBuilder, config); - MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cm); + MultimapCacheManager multimapCacheManager = EmbeddedMultimapCacheManagerFactory.from(cm); MultimapCache multimapCache = multimapCacheManager.get("test"); multimapCache.put("k1", new SuperPerson()); PersistenceMarshallerImpl pm = TestingUtil.extractPersistenceMarshaller(cm); diff --git a/pom.xml b/pom.xml index aa5704f94d62..a9195b514711 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,7 @@ jboss-marshalling counter multimap + embedded tools query-dsl query-core