use of org.agrona.collections.ObjectHashSet in project simple-binary-encoding by real-logic.
the class Message method parseFieldsAndGroups.
private List<Field> parseFieldsAndGroups(final Node node) throws XPathExpressionException {
final XPath xPath = XPathFactory.newInstance().newXPath();
final NodeList list = (NodeList) xPath.compile(FIELD_OR_GROUP_OR_DATA_EXPR).evaluate(node, NODESET);
boolean groupEncountered = false, dataEncountered = false;
final ObjectHashSet<String> distinctNames = new ObjectHashSet<>();
final List<Field> fieldList = new ArrayList<>();
for (int i = 0, size = list.getLength(); i < size; i++) {
final Field field;
final String nodeName = list.item(i).getNodeName();
switch(nodeName) {
case "group":
if (dataEncountered) {
handleError(node, "group node specified after data node");
}
field = parseGroupField(list, i);
groupEncountered = true;
break;
case "data":
field = parseDataField(list, i);
dataEncountered = true;
break;
case "field":
if (groupEncountered || dataEncountered) {
handleError(node, "field node specified after group or data node specified");
}
field = parseField(list, i);
break;
default:
throw new IllegalStateException("Unknown node name: " + nodeName);
}
if (!distinctNames.add(field.name())) {
handleError(node, "duplicate name found: " + field.name());
}
fieldList.add(field);
}
return fieldList;
}
use of org.agrona.collections.ObjectHashSet in project aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateStoppedRecording.
@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecording() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long srcRecordingId;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
final CountersReader counters = srcAeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
srcRecordingId = RecordingPos.getRecordingId(counters, counterId);
offer(publication, messageCount, messagePrefix);
awaitPosition(counters, counterId, publication.position());
}
srcAeronArchive.stopRecording(subscriptionId);
final MutableLong dstRecordingId = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
final ObjectHashSet<RecordingSignal> transitionEventsSet = new ObjectHashSet<>();
transitionEventsSet.add(awaitSignal(signalRef, adapter));
transitionEventsSet.add(awaitSignal(signalRef, adapter));
assertTrue(transitionEventsSet.contains(RecordingSignal.STOP));
assertTrue(transitionEventsSet.contains(RecordingSignal.SYNC));
}
use of org.agrona.collections.ObjectHashSet in project Aeron by real-logic.
the class ReplicateRecordingTest method shouldReplicateStoppedRecording.
@Test
@InterruptAfter(10)
public void shouldReplicateStoppedRecording() {
final String messagePrefix = "Message-Prefix-";
final int messageCount = 10;
final long srcRecordingId;
final long subscriptionId = srcAeronArchive.startRecording(LIVE_CHANNEL, LIVE_STREAM_ID, LOCAL);
try (Publication publication = srcAeron.addPublication(LIVE_CHANNEL, LIVE_STREAM_ID)) {
final CountersReader counters = srcAeron.countersReader();
final int counterId = awaitRecordingCounterId(counters, publication.sessionId());
srcRecordingId = RecordingPos.getRecordingId(counters, counterId);
offer(publication, messageCount, messagePrefix);
awaitPosition(counters, counterId, publication.position());
}
srcAeronArchive.stopRecording(subscriptionId);
final MutableLong dstRecordingId = new MutableLong();
final MutableReference<RecordingSignal> signalRef = new MutableReference<>();
final RecordingSignalAdapter adapter = newRecordingSignalAdapter(signalRef, dstRecordingId);
dstAeronArchive.replicate(srcRecordingId, NULL_VALUE, SRC_CONTROL_STREAM_ID, SRC_CONTROL_REQUEST_CHANNEL, null);
assertEquals(RecordingSignal.REPLICATE, awaitSignal(signalRef, adapter));
assertEquals(RecordingSignal.EXTEND, awaitSignal(signalRef, adapter));
final ObjectHashSet<RecordingSignal> transitionEventsSet = new ObjectHashSet<>();
transitionEventsSet.add(awaitSignal(signalRef, adapter));
transitionEventsSet.add(awaitSignal(signalRef, adapter));
assertTrue(transitionEventsSet.contains(RecordingSignal.STOP));
assertTrue(transitionEventsSet.contains(RecordingSignal.SYNC));
}
Aggregations