io.fluxcapacitor.javaclient.configuration.client.InMemoryClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
Default Java client library for interfacing with Flux Capacitor.
package io.fluxcapacitor.javaclient.configuration.client;
import io.fluxcapacitor.common.MessageType;
import io.fluxcapacitor.javaclient.eventsourcing.client.EventStoreClient;
import io.fluxcapacitor.javaclient.eventsourcing.client.InMemoryEventStoreClient;
import io.fluxcapacitor.javaclient.keyvalue.client.InMemoryKeyValueClient;
import io.fluxcapacitor.javaclient.keyvalue.client.KeyValueClient;
import io.fluxcapacitor.javaclient.publishing.client.GatewayClient;
import io.fluxcapacitor.javaclient.scheduling.client.InMemorySchedulingClient;
import io.fluxcapacitor.javaclient.scheduling.client.SchedulingClient;
import io.fluxcapacitor.javaclient.tracking.client.InMemoryMessageStore;
import io.fluxcapacitor.javaclient.tracking.client.TrackingClient;
import java.lang.management.ManagementFactory;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
public class InMemoryClient extends AbstractClient {
public static InMemoryClient newInstance() {
InMemorySchedulingClient schedulingClient = new InMemorySchedulingClient();
InMemoryEventStoreClient eventStoreClient = new InMemoryEventStoreClient();
Map messageStores = new ConcurrentHashMap<>();
Function messageStoreFactory = type -> messageStores.computeIfAbsent(
type, t -> {
switch (t) {
case EVENT:
return eventStoreClient;
case SCHEDULE:
return schedulingClient;
default:
return new InMemoryMessageStore();
}
});
return new InMemoryClient("inMemory", ManagementFactory.getRuntimeMXBean().getName(), messageStoreFactory,
messageStoreFactory, eventStoreClient, schedulingClient,
new InMemoryKeyValueClient());
}
private InMemoryClient(String name, String id,
Function gatewayClients,
Function trackingClients,
EventStoreClient eventStoreClient,
SchedulingClient schedulingClient,
KeyValueClient keyValueClient) {
super(name, id, gatewayClients, trackingClients, eventStoreClient, schedulingClient, keyValueClient);
}
}