本文整理汇总了Java中org.jeeventstore.WritableEventStream类的典型用法代码示例。如果您正苦于以下问题:Java WritableEventStream类的具体用法?Java WritableEventStream怎么用?Java WritableEventStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WritableEventStream类属于org.jeeventstore包,在下文中一共展示了WritableEventStream类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testOpenStreamForWritingConcurrency
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Test
public void testOpenStreamForWritingConcurrency() throws Exception {
cleanup();
fill(BUCKET_ID, "FOO", 10);
caught = false;
caughtCS = null;
WritableEventStream wes = eventStore.openStreamForWriting(BUCKET_ID, "FOO", 8);
wes.append("bla");
try {
wes.commit(UUID.randomUUID().toString());
fail("Should have failed by now");
} catch (ConcurrencyException e) {
// expected
}
assertTrue(!caught);
assertTrue(caughtCS == null);
assertEquals(BUCKET_ID, wes.bucketId());
assertEquals("FOO", wes.streamId());
}
示例2: log
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Override
@Asynchronous
public void log(Command<?> command, Map<String, String> metadata) {
Validate.notNull(command, "command must not be null");
Validate.notNull(metadata, "metadata must not be null");
String commandId = command.id().toString();
WritableEventStream stream = streamFor(command);
CommandLogEnvelope<Command<?>> envelope = new CommandLogEnvelope<Command<?>>(command,
new HashMap<>(metadata));
log.log(Level.FINE, "Logging command: {0}", envelope);
stream.append(envelope);
try {
stream.commit(commandId);
} catch (DuplicateCommitException | ConcurrencyException e) {
throw new RuntimeException(e);
}
}
示例3: dispatch
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Override
public void dispatch(Event event) {
log.fine("Dispatch event #" + event.id() + ", " + event);
String eventId = event.id().toString();
String streamId = String.format("%s:%s", event.getClass().getCanonicalName(), eventId);
WritableEventStream stream = eventStore.createStream(sagaTimeoutEventBucketId, streamId);
stream.append(event);
try {
stream.commit(streamId);
} catch (ConcurrencyException | DuplicateCommitException e) {
// this simply means the event has been stored already, this is good,
// we can ignore these errors
log.log(Level.FINE, "Caught exception saving stream with id {0}, but ignored on purpose: {1}",
new Object[]{streamId, e});
}
}
开发者ID:JEEventStore,项目名称:JEECQRS-JCommonDomain-Integration,代码行数:17,代码来源:SagaTrackerPersistingEventBusService.java
示例4: fill
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
private void fill(String bucketId, String streamId, int count) throws Exception {
WritableEventStream wes = eventStore.createStream(bucketId, streamId);
for (int i = 0; i < count; i++) {
List<Integer> data = TestUtils.randomdata(i % 5 + 1);
for (Integer ii : data)
wes.append(ii);
wes.commit(UUID.randomUUID().toString());
}
}
示例5: testCreateStream
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Test
public void testCreateStream() throws Exception {
cleanup();
WritableEventStream wes = eventStore.createStream(BUCKET_ID, "CREATED");
assertEquals(wes.version(), 0);
testWriting(wes);
assertEquals(BUCKET_ID, wes.bucketId());
assertEquals("CREATED", wes.streamId());
}
示例6: testOpenStreamForWriting
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Test
public void testOpenStreamForWriting() throws Exception {
cleanup();
fill(BUCKET_ID, "FOO", 10);
WritableEventStream wes = eventStore.openStreamForWriting(BUCKET_ID, "FOO", 10);
assertEquals(wes.version(), 10);
testWriting(wes);
assertEquals(BUCKET_ID, wes.bucketId());
assertEquals("FOO", wes.streamId());
}
示例7: test_create_writeable
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Test
public void test_create_writeable() {
WritableEventStream oes = OptimisticEventStream.createWritable(BUCKET_ID, STREAM_ID, 28l, persistence);
assertEquals(oes.bucketId(), BUCKET_ID);
assertEquals(oes.streamId(), STREAM_ID);
assertEquals(28l, oes.version());
}
示例8: busForStream
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
private EventSourcingBus<Event> busForStream(final WritableEventStream stream) {
return new EventSourcingBus<Event>() {
@Override
public void store(Event event) {
appendToStream(stream, event);
}
@Override
public void commit(String commitId) {
commitChanges(stream, commitId);
}
};
}
示例9: commitChanges
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
protected void commitChanges(WritableEventStream stream, String commitId) {
try {
stream.commit(commitId);
} catch (DuplicateCommitException | ConcurrencyException e) {
throw new RuntimeException("committing changes failed: " + e.getMessage(), e);
}
}
示例10: busForAdd
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Override
protected EventSourcingBus<Event> busForAdd(String streamId) {
WritableEventStream stream = eventStore().createStream(bucketId(), streamId);
return busForStream(stream);
}
示例11: busForSave
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
@Override
protected EventSourcingBus<Event> busForSave(String streamId, long version) {
WritableEventStream stream = eventStore().openStreamForWriting(bucketId(), streamId, version);
return busForStream(stream);
}
示例12: appendToStream
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
protected void appendToStream(WritableEventStream stream, Event event) {
stream.append(event);
}
示例13: streamFor
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
protected WritableEventStream streamFor(Command command) {
return eventStore.createStream(commandBucketId, streamIdFor(command));
}
示例14: createWritable
import org.jeeventstore.WritableEventStream; //导入依赖的package包/类
/**
* Factory method to create a new writable event stream supporting optimistic locking.
* Does not query the persistence layer upon creation.
*
* @param bucketId the identifier of the bucket the stream belongs to
* @param streamId the identifier of the stream
* @param version the version of the stream
* @param persistence the persistence layer to which changes are to be committed
* @return the stream
*/
protected static WritableEventStream createWritable(
String bucketId,
String streamId,
long version,
EventStorePersistence persistence) {
return new OptimisticEventStream(bucketId, streamId, version, persistence);
}