use of com.yahoo.messagebus.Message in project vespa by vespa-engine.
the class DocumentOperationMessageV3 method newRemoveMessage.
static DocumentOperationMessageV3 newRemoveMessage(VespaXMLFeedReader.Operation op, String operationId) {
DocumentRemove remove = new DocumentRemove(op.getRemove());
remove.setCondition(op.getCondition());
Message msg = new RemoveDocumentMessage(remove);
String id = (operationId == null) ? remove.getId().toString() : operationId;
return new DocumentOperationMessageV3(id, msg);
}
use of com.yahoo.messagebus.Message in project vespa by vespa-engine.
the class Feeder method feed.
void feed() throws InterruptedException {
while (true) {
Result result;
String operationId;
try {
operationId = getNextOperationId();
} catch (IOException ioe) {
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, Exceptions.toMessageString(ioe), ioe);
}
break;
}
// noinspection StringEquality
if (operationId == EOF) {
break;
}
Tuple2<String, Message> msg;
try {
msg = getNextMessage(operationId);
setRoute(msg);
} catch (Exception e) {
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, Exceptions.toMessageString(e), e);
}
// noinspection StringEquality
if (operationId != null) {
// v1 always returns null, all others return something useful, or throw an exception above
msg = newErrorMessage(operationId, e);
} else {
break;
}
}
if (msg == null) {
break;
}
setMessageParameters(msg);
while (true) {
try {
msg.second.pushHandler(feedReplyHandler);
if (settings.denyIfBusy) {
result = sourceSession.getResource().sendMessage(msg.second);
} else {
result = sourceSession.getResource().sendMessageBlocking(msg.second);
}
} catch (RuntimeException e) {
enqueue(msg.first, Exceptions.toMessageString(e), ErrorCode.ERROR, false, msg.second);
return;
}
if (result.isAccepted() || result.getError().getCode() != SEND_QUEUE_FULL) {
break;
}
if (settings.denyIfBusy) {
break;
} else {
// This will never happen
Thread.sleep(100);
}
}
if (result.isAccepted()) {
++numPending;
updateMetrics(msg.second);
updateOpsPerSec();
log(LogLevel.DEBUG, "Sent message successfully, document id: ", msg.first);
} else if (!result.getError().isFatal()) {
enqueue(msg.first, result.getError().getMessage(), ErrorCode.TRANSIENT_ERROR, false, msg.second);
break;
} else {
// should probably not happen, but everybody knows stuff that
// shouldn't happen, happens all the time
boolean isConditionNotMet = result.getError().getCode() == DocumentProtocol.ERROR_TEST_AND_SET_CONDITION_FAILED;
enqueue(msg.first, result.getError().getMessage(), ErrorCode.ERROR, isConditionNotMet, msg.second);
break;
}
}
}
use of com.yahoo.messagebus.Message in project vespa by vespa-engine.
the class Feeder method newRemoveMessage.
private Tuple2<String, Message> newRemoveMessage(Operation op, String operationId) {
DocumentRemove remove = new DocumentRemove(op.getRemove());
remove.setCondition(op.getCondition());
Message msg = new RemoveDocumentMessage(remove);
String id = (operationId == null) ? remove.getId().toString() : operationId;
return new Tuple2<>(id, msg);
}
use of com.yahoo.messagebus.Message in project vespa by vespa-engine.
the class DocumentRouteSelectorPolicy method select.
/**
* This method runs the selector associated with the given location on the content of the message. If the selector
* validates the location, this method returns true.
*
* @param context The routing context that contains the necessary data.
* @param routeName The candidate route whose selector to run.
* @return Whether or not to send to the given recipient.
*/
private boolean select(RoutingContext context, String routeName) {
if (config == null) {
return true;
}
DocumentSelector selector = config.get(routeName);
if (selector == null) {
return true;
}
// Select based on message content.
Message msg = context.getMessage();
switch(msg.getType()) {
case DocumentProtocol.MESSAGE_PUTDOCUMENT:
return selector.accepts(((PutDocumentMessage) msg).getDocumentPut()) == Result.TRUE;
case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
return selector.accepts(((UpdateDocumentMessage) msg).getDocumentUpdate()) != Result.FALSE;
case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
{
RemoveDocumentMessage removeMsg = (RemoveDocumentMessage) msg;
if (removeMsg.getDocumentId().hasDocType()) {
return selector.accepts(removeMsg.getDocumentRemove()) != Result.FALSE;
} else {
return true;
}
}
case DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE:
BatchDocumentUpdateMessage bdu = (BatchDocumentUpdateMessage) msg;
for (int i = 0; i < bdu.getUpdates().size(); i++) {
if (selector.accepts(bdu.getUpdates().get(i)) == Result.FALSE) {
return false;
}
}
return true;
default:
return true;
}
}
use of com.yahoo.messagebus.Message in project vespa by vespa-engine.
the class ServerThreadingTestCase method requireThatServerIsThreadSafe.
@Test
public void requireThatServerIsThreadSafe() throws Exception {
final LocalWire wire = new LocalWire();
final Client client = new Client(wire);
final Server server = new Server(wire);
for (int i = 0; i < NUM_REQUESTS; ++i) {
final Message msg = new SimpleMessage("foo");
msg.setRoute(Route.parse(server.delegate.connectionSpec()));
msg.pushHandler(client);
assertThat(client.session.send(msg).isAccepted(), is(true));
}
for (int i = 0; i < NUM_REQUESTS; ++i) {
final Reply reply = client.replies.poll(600, TimeUnit.SECONDS);
assertThat(reply, instanceOf(EmptyReply.class));
assertThat(reply.hasErrors(), is(false));
}
assertThat(client.close(), is(true));
assertThat(server.close(), is(true));
}
Aggregations