Skip to content

Instantly share code, notes, and snippets.

@jen20
Created May 19, 2015 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jen20/f061db530ae401765aeb to your computer and use it in GitHub Desktop.
Save jen20/f061db530ae401765aeb to your computer and use it in GitHub Desktop.
A first stab at an EventStoreConnection interface for a new pure Java client
package com.geteventstore.client;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
public interface EventStoreConnection {
CompletableFuture connect();
void close();
CompletableFuture<WriteResult> appendToStream(String streamName, int expectedVersion, EventData[] events);
CompletableFuture<DeleteResult> deleteStream(String streamName, int expectedVersion);
CompletableFuture<StreamEventsSlice> readEventsForward(String streamName, int start, int count, Boolean resolveLinks);
CompletableFuture<StreamEventsSlice> readEventsBackward(String streamName, int start, int count, Boolean resolveLinks);
CompletableFuture<SingleReadResult> readEvent(String streamName, int eventNumber, Boolean resolveLinks);
CompletableFuture<Subscription> subscribeToStreamLive(String streamName,
LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop);
CompletableFuture<Subscription> subscribeToStreamLive(String streamName,
LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop,
Executor executor);
CompletableFuture<Subscription> subscribeToAllLive(LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop);
CompletableFuture<Subscription> subscribeToAllLive(LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop,
Executor executor);
CompletableFuture<Subscription> subscribeToStreamFromEventNumber(String stream,
int eventNumber,
LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop,
Consumer<Subscription> onLiveProcessingStart);
CompletableFuture<Subscription> subscribeToStreamFromEventNumber(String stream,
int eventNumber,
LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop,
Consumer<Subscription> onLiveProcessingStart,
Executor executor);
CompletableFuture<Subscription> subscribeToAllFromPosition(Position position,
LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop,
Consumer<Subscription> onLiveProcessingStart);
CompletableFuture<Subscription> subscribeToAllFromPosition(Position position,
LinkAction linkAction,
BiConsumer<Subscription, ResolvedEvent> onEvent,
BiConsumer<Subscription, DropReason> onDrop,
Consumer<Subscription> onLiveProcessingStart,
Executor executor);
}
@jen20
Copy link
Author

jen20 commented May 27, 2015

@michael-schnell yes I'll create a repository for it and put the entire interface in there. Stand by for the repository address. Sorry for the delay, it was a holiday weekend.

To address your specific points:

  • Using varargs for the EventData is probably a good idea
  • A collection version is likely also a good idea
  • Constants are likely a good idea. Unlike the .NET client we're not bound by backwards compatibility constraints, so we don't need to deal with Empty stream which is an artefact of a feature which no longer exists.
  • LinkAction is an enumeration of NoAction and ResolveLinks - if you choose to resolve them then link events will be dereferenced in the server which reduces the number of roundtrips required.

@jen20
Copy link
Author

jen20 commented May 27, 2015

@michael-schnell the repository is here: https://github.com/jen20/EventStore.Java - let's move this discussion to the issues section of that repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment