本文整理汇总了Java中com.github.msemys.esjc.EventData类的典型用法代码示例。如果您正苦于以下问题:Java EventData类的具体用法?Java EventData怎么用?Java EventData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventData类属于com.github.msemys.esjc包,在下文中一共展示了EventData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendEvents
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
@Override
public void appendEvents(final String type, final DomainEventStream eventStream) {
final Map<Object, List<EventData>> identifierToEventStoreEvents = new HashMap<>();
while (eventStream.hasNext()) {
final DomainEventMessage message = eventStream.next();
final Object identifier = message.getAggregateIdentifier();
if (!identifierToEventStoreEvents.containsKey(identifier)) {
identifierToEventStoreEvents.put(identifier, new LinkedList<EventData>());
}
identifierToEventStoreEvents.get(identifier)
.add(toEvent(message));
}
for (final Entry<Object, List<EventData>> entry : identifierToEventStoreEvents.entrySet()) {
final String streamName = getStreamName(type, entry.getKey(), prefix);
final List<EventData> events = entry.getValue();
client.appendToStream(streamName, ExpectedVersion.ANY, events);
}
}
示例2: toEvent
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
private EventData toEvent(final DomainEventMessage message) {
final HashMap<String, Object> metaData = new HashMap<>();
final HashMap<String, Object> eventMetaData = new HashMap<>();
for (final Entry<String, Object> entry : message.getMetaData()
.entrySet()) {
eventMetaData.put(entry.getKey(), entry.getValue());
}
metaData.put(Constants.AGGREGATE_ID_KEY, message.getAggregateIdentifier());
metaData.put(Constants.PAYLOAD_REVISION_KEY, getPayloadRevision(message.getPayloadType()));
metaData.put(Constants.EVENT_METADATA_KEY, eventMetaData);
return EventData.newBuilder()
.eventId(UUID.fromString(message.getIdentifier())) // TODO check if it is save to assume that this can always be converted to a UUID
.jsonData(serialize(message.getPayload()))
.type(message.getPayloadType()
.getName())
.metadata(serialize(metaData))
.build();
}
示例3: matchesSafely
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
@Override
protected boolean matchesSafely(List<RecordedEvent> actual) {
if (expected.size() == actual.size()) {
for (int i = 0; i < expected.size(); i++) {
EventData expectedItem = expected.get(i);
RecordedEvent actualItem = actual.get(i);
elementMatcher = RecordedEventMatcher.equalTo(expectedItem);
elementIndex = i;
if (!elementMatcher.matches(actualItem)) {
return false;
}
}
return true;
} else {
return false;
}
}
示例4: AppendToStreamOperation
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
public AppendToStreamOperation(CompletableFuture<WriteResult> result,
boolean requireMaster,
String stream,
long expectedVersion,
Iterable<EventData> events,
UserCredentials userCredentials) {
super(result, TcpCommand.WriteEvents, TcpCommand.WriteEventsCompleted, userCredentials);
this.requireMaster = requireMaster;
this.stream = stream;
this.expectedVersion = expectedVersion;
this.events = events;
}
示例5: TransactionalWriteOperation
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
public TransactionalWriteOperation(CompletableFuture<Void> result,
boolean requireMaster,
long transactionId,
Iterable<EventData> events,
UserCredentials userCredentials) {
super(result, TcpCommand.TransactionWrite, TcpCommand.TransactionWriteCompleted, userCredentials);
this.requireMaster = requireMaster;
this.transactionId = transactionId;
this.events = events;
}
示例6: convert
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
/**
* Converts a common event into event data.
*
* @param commonEvent
* Event to convert.
*
* @return Converted event as event data.
*/
@Override
public final EventData convert(final CommonEvent commonEvent) {
// User's data
final String dataType = commonEvent.getDataType().asBaseType();
final SerializedDataType serUserDataType = new SerializedDataType(dataType);
final Serializer userDataSerializer = serRegistry.getSerializer(serUserDataType);
final byte[] serUserData = userDataSerializer.marshal(commonEvent.getData());
final byte[] serData;
if (userDataSerializer.getMimeType().matchEncoding(targetContentType)) {
serData = serUserData;
} else {
final Base64Data base64data = new Base64Data(serUserData);
final Serializer base64Serializer = serRegistry.getSerializer(Base64Data.SER_TYPE);
serData = base64Serializer.marshal(base64data);
}
// EscMeta
final EscMeta escMeta = EscSpiUtils.createEscMeta(serRegistry, targetContentType, commonEvent);
final Serializer escMetaSerializer = getSerializer(EscMeta.TYPE);
final byte[] escSerMeta = escMetaSerializer.marshal(escMeta);
// Create event data
final EventData.Builder builder = EventData.newBuilder().eventId(commonEvent.getId().asBaseType())
.type(dataType);
if (targetContentType.isJson()) {
builder.jsonData(serData);
builder.jsonMetadata(escSerMeta);
} else {
builder.data(serData);
builder.metadata(escSerMeta);
}
return builder.build();
}
示例7: asEventData
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
private List<EventData> asEventData(final List<CommonEvent> commonEvents) {
final List<EventData> list = new ArrayList<>(commonEvents.size());
for (final CommonEvent commonEvent : commonEvents) {
list.add(ce2edConv.convert(commonEvent));
}
return list;
}
示例8: main
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, ExecutionException {
EventStore es = EventStoreBuilder.newBuilder().singleNodeAddress("127.0.0.1", 1113).build();
es.connect();
try {
// Create stream by appending something to it
String streamId = "MyStream";
List<EventData> events = new ArrayList<>();
events.add(EventData.newBuilder().eventId(UUID.randomUUID()).type("baz").data("dummy content")
.build());
es.appendToStream(streamId, ExpectedVersion.any(), events).join();
// Hard delete
es.deleteStream(streamId, ExpectedVersion.any(), true).join();
// Get status
final StreamMetadataResult result = es.getStreamMetadata(streamId).get();
if (result.isStreamDeleted) {
// === THIS IS PRINTED ===
System.out.println("SOFT DELETED");
} else {
System.out.println("HARD DELETED");
}
} finally {
es.disconnect();
}
}
示例9: testConvert
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
@Test
public final void testConvert() {
// PREPARE
final EnhancedMimeType targetContentType = EnhancedMimeType.create("application", "json",
Charset.forName("utf-8"));
final SimpleSerializerDeserializerRegistry serRegistry = new SimpleSerializerDeserializerRegistry();
final JsonDeSerializer deserializer = new JsonDeSerializer();
serRegistry.addSerializer(new SerializedDataType("MyData"), deserializer);
serRegistry.addSerializer(new SerializedDataType("MyMeta"), deserializer);
serRegistry.addSerializer(new SerializedDataType(EscMeta.TYPE.asBaseType()), deserializer);
final EventId id = new EventId();
final TypeName dataType = new TypeName("MyData");
final Object data = Json.createObjectBuilder().add("id", 1).add("name", "Peter").build();
final TypeName metaType = new TypeName("MyMeta");
final Object meta = Json.createObjectBuilder().add("ip", "127.0.0.1").build();
final CommonEvent commonEvent = new SimpleCommonEvent(id, dataType, data, metaType, meta);
final CommonEvent2EventDataConverter testee = new CommonEvent2EventDataConverter(serRegistry,
targetContentType);
// TEST
final EventData eventData = testee.convert(commonEvent);
// VERIFY
assertThat(eventData.eventId).isEqualTo(commonEvent.getId().asBaseType());
assertThat(eventData.type).isEqualTo(commonEvent.getDataType().asBaseType());
assertThat(eventData.isJsonData).isTrue();
assertThat(new String(eventData.data, deserializer.getMimeType().getEncoding()))
.isEqualTo("{\"id\":1,\"name\":\"Peter\"}");
assertThat(eventData.isJsonMetadata).isTrue();
assertThat(new String(eventData.metadata, deserializer.getMimeType().getEncoding())).isEqualTo(
"{\"data-type\":\"MyData\"," + "\"data-content-type\":\"application/json; encoding=UTF-8\","
+ "\"meta-type\":\"MyMeta\",\"meta-content-type\":\"application/json; encoding=UTF-8\","
+ "\"MyMeta\":{\"ip\":\"127.0.0.1\"}}");
}
示例10: write
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
default CompletableFuture<Void> write(Transaction transaction, Iterable<EventData> events) {
return write(transaction, events, null);
}
示例11: RecordedEventMatcher
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
public RecordedEventMatcher(EventData expected) {
this.expected = expected;
}
示例12: equalTo
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
@Factory
public static Matcher<RecordedEvent> equalTo(EventData item) {
return new RecordedEventMatcher(item);
}
示例13: RecordedEventListMatcher
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
public RecordedEventListMatcher(List<EventData> expected) {
this.expected = expected;
}
示例14: containsInOrder
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
@Factory
public static Matcher<List<RecordedEvent>> containsInOrder(List<EventData> items) {
return new RecordedEventListMatcher(items);
}
示例15: getTargetType
import com.github.msemys.esjc.EventData; //导入依赖的package包/类
@Override
public final Class<EventData> getTargetType() {
return EventData.class;
}