use of io.nats.client.support.Status in project nats.java by nats-io.
the class PushStatusMessageManager method manage.
boolean manage(Message msg) {
if (msg.isStatusMessage()) {
// this checks fc, hb and unknown
// only process fc and hb if those flags are set
// otherwise they are simply known statuses
Status status = msg.getStatus();
if (status.isFlowControl()) {
if (fc) {
_processFlowControl(msg.getReplyTo(), ErrorListener.FlowControlSource.FLOW_CONTROL);
}
return true;
}
if (status.isHeartbeat()) {
if (fc) {
// status flowControlSubject is set in the beforeQueueProcessor
_processFlowControl(extractFcSubject(msg), ErrorListener.FlowControlSource.HEARTBEAT);
}
return true;
}
// this status is unknown to us, always use the error handler.
// If it's a sync call, also throw an exception
conn.getOptions().getErrorListener().unhandledStatus(conn, sub, status);
if (syncMode) {
throw new JetStreamStatusException(sub, status);
}
return true;
}
// JS Message
lastStreamSeq = msg.metaData().streamSequence();
lastConsumerSeq = msg.metaData().consumerSequence();
return false;
}
use of io.nats.client.support.Status in project nats.java by nats-io.
the class ErrorListenerTests method testCoverage.
@Test
public void testCoverage() {
// this exercises default interface implementation
_cover(new ErrorListener() {
});
// exercises the default implementation
_cover(new ErrorListenerLoggerImpl());
// exercises a little more than the defaults
AtomicBoolean errorOccurredFlag = new AtomicBoolean();
AtomicBoolean exceptionOccurredFlag = new AtomicBoolean();
AtomicBoolean slowConsumerDetectedFlag = new AtomicBoolean();
AtomicBoolean messageDiscardedFlag = new AtomicBoolean();
AtomicBoolean heartbeatAlarmFlag = new AtomicBoolean();
AtomicBoolean unhandledStatusFlag = new AtomicBoolean();
AtomicBoolean flowControlProcessedFlag = new AtomicBoolean();
_cover(new ErrorListener() {
@Override
public void errorOccurred(Connection conn, String error) {
errorOccurredFlag.set(true);
}
@Override
public void exceptionOccurred(Connection conn, Exception exp) {
exceptionOccurredFlag.set(true);
}
@Override
public void slowConsumerDetected(Connection conn, Consumer consumer) {
slowConsumerDetectedFlag.set(true);
}
@Override
public void messageDiscarded(Connection conn, Message msg) {
messageDiscardedFlag.set(true);
}
@Override
public void heartbeatAlarm(Connection conn, JetStreamSubscription sub, long lastStreamSequence, long lastConsumerSequence) {
heartbeatAlarmFlag.set(true);
}
@Override
public void unhandledStatus(Connection conn, JetStreamSubscription sub, Status status) {
unhandledStatusFlag.set(true);
}
@Override
public void flowControlProcessed(Connection conn, JetStreamSubscription sub, String subject, FlowControlSource source) {
flowControlProcessedFlag.set(true);
}
});
assertTrue(errorOccurredFlag.get());
assertTrue(exceptionOccurredFlag.get());
assertTrue(slowConsumerDetectedFlag.get());
assertTrue(messageDiscardedFlag.get());
assertTrue(heartbeatAlarmFlag.get());
assertTrue(unhandledStatusFlag.get());
assertTrue(flowControlProcessedFlag.get());
}
use of io.nats.client.support.Status in project nats.java by nats-io.
the class HeadersTests method assertValidStatus.
private IncomingHeadersProcessor assertValidStatus(IncomingHeadersProcessor ihp, int code, String msg) {
Status status = ihp.getStatus();
assertNotNull(status);
assertEquals(code, status.getCode());
if (msg != null) {
assertEquals(msg, status.getMessage());
}
NatsMessage.InternalMessageFactory imf = new NatsMessage.InternalMessageFactory("sid", "sub", "rt", 0, false);
imf.setHeaders(ihp);
assertTrue(imf.getMessage().isStatusMessage());
return ihp;
}
use of io.nats.client.support.Status in project nats.java by nats-io.
the class HeadersTests method verifyStatusBooleans.
@Test
public void verifyStatusBooleans() {
Status status = new Status(Status.FLOW_OR_HEARTBEAT_STATUS_CODE, Status.FLOW_CONTROL_TEXT);
assertTrue(status.isFlowControl());
assertFalse(status.isHeartbeat());
assertFalse(status.isNoResponders());
status = new Status(Status.FLOW_OR_HEARTBEAT_STATUS_CODE, Status.HEARTBEAT_TEXT);
assertFalse(status.isFlowControl());
assertTrue(status.isHeartbeat());
assertFalse(status.isNoResponders());
status = new Status(Status.NO_RESPONDERS_CODE, Status.NO_RESPONDERS_TEXT);
assertFalse(status.isFlowControl());
assertFalse(status.isHeartbeat());
assertTrue(status.isNoResponders());
// path coverage
status = new Status(Status.NO_RESPONDERS_CODE, "not no responders text");
assertFalse(status.isNoResponders());
}
Aggregations