use of com.yahoo.messagebus.Protocol in project vespa by vespa-engine.
the class DocumentProcessingHandlerTestBase method createHandler.
@Before
public void createHandler() {
documentTypeManager.register(getType());
Protocol protocol = new DocumentProtocol(documentTypeManager);
driver = ServerTestDriver.newInactiveInstanceWithProtocol(protocol);
sessionCache = new SessionCache("raw:", driver.client().slobrokId(), "test", "raw:", null, "raw:", documentTypeManager);
ContainerBuilder builder = driver.parent().newContainerBuilder();
ComponentRegistry<DocprocService> registry = new ComponentRegistry<>();
handler = new DocumentProcessingHandler(registry, new ComponentRegistry<>(), new ComponentRegistry<>(), new DocumentProcessingHandlerParameters().setDocumentTypeManager(documentTypeManager).setContainerDocumentConfig(new ContainerDocumentConfig(new ContainerDocumentConfig.Builder())));
builder.serverBindings().bind("mbus://*/*", handler);
ReferencedResource<SharedSourceSession> sessionRef = sessionCache.retainSource(new SourceSessionParams());
MbusClient sourceClient = new MbusClient(sessionRef.getResource());
builder.clientBindings().bind("mbus://*/source", sourceClient);
builder.clientBindings().bind("mbus://*/" + MbusRequestContext.internalNoThrottledSource, sourceClient);
sourceClient.start();
List<Pair<String, CallStack>> callStacks = getCallStacks();
List<AbstractResource> resources = new ArrayList<>();
for (Pair<String, CallStack> callStackPair : callStacks) {
DocprocService service = new DocprocService(callStackPair.getFirst());
service.setCallStack(callStackPair.getSecond());
service.setInService(true);
ComponentId serviceId = new ComponentId(service.getName());
registry.register(serviceId, service);
ComponentId sessionName = ComponentId.fromString("chain." + serviceId);
MbusServerProvider serviceProvider = new MbusServerProvider(sessionName, sessionCache, driver.parent());
serviceProvider.get().start();
serviceProviders.add(serviceProvider);
MbusClient intermediateClient = new MbusClient(serviceProvider.getSession());
builder.clientBindings().bind("mbus://*/" + sessionName.stringValue(), intermediateClient);
intermediateClient.start();
resources.add(intermediateClient);
}
driver.parent().activateContainer(builder);
sessionRef.getReference().close();
sourceClient.release();
for (AbstractResource resource : resources) {
resource.release();
}
remoteServer = RemoteServer.newInstance(driver.client().slobrokId(), "foobar", protocol);
}
use of com.yahoo.messagebus.Protocol in project vespa by vespa-engine.
the class RPCSend method doInvoke.
private void doInvoke(Request request) {
Params p = toParams(request.parameters());
// allow garbage collection of request parameters
request.discardParameters();
// Make sure that the owner understands the protocol.
Protocol protocol = net.getOwner().getProtocol(p.protocolName);
if (protocol == null) {
replyError(request, p.version, p.traceLevel, new Error(ErrorCode.UNKNOWN_PROTOCOL, "Protocol '" + p.protocolName + "' is not known by " + serverIdent + "."));
return;
}
Routable routable = protocol.decode(p.version, p.payload);
if (routable == null) {
replyError(request, p.version, p.traceLevel, new Error(ErrorCode.DECODE_ERROR, "Protocol '" + protocol.getName() + "' failed to decode routable."));
return;
}
if (routable instanceof Reply) {
replyError(request, p.version, p.traceLevel, new Error(ErrorCode.DECODE_ERROR, "Payload decoded to a reply when expecting a message."));
return;
}
Message msg = (Message) routable;
if (p.route != null && p.route.length() > 0) {
msg.setRoute(net.getRoute(p.route));
}
msg.setContext(new ReplyContext(request, p.version));
msg.pushHandler(this);
msg.setRetryEnabled(p.retryEnabled);
msg.setRetry(p.retry);
msg.setTimeReceivedNow();
msg.setTimeRemaining(p.timeRemaining);
msg.getTrace().setLevel(p.traceLevel);
if (msg.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) {
msg.getTrace().trace(TraceLevel.SEND_RECEIVE, "Message (type " + msg.getType() + ") received at " + serverIdent + " for session '" + p.session + "'.");
}
net.getOwner().deliverMessage(msg, p.session);
}
use of com.yahoo.messagebus.Protocol in project vespa by vespa-engine.
the class RPCSend method handleReply.
@Override
public final void handleReply(Reply reply) {
ReplyContext ctx = (ReplyContext) reply.getContext();
reply.setContext(null);
// Add trace information.
if (reply.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) {
reply.getTrace().trace(TraceLevel.SEND_RECEIVE, "Sending reply (version " + ctx.version + ") from " + serverIdent + ".");
}
// Encode and return the reply through the RPC request.
byte[] payload = new byte[0];
if (reply.getType() != 0) {
Protocol protocol = net.getOwner().getProtocol(reply.getProtocol());
if (protocol != null) {
payload = protocol.encode(ctx.version, reply);
}
if (payload == null || payload.length == 0) {
reply.addError(new Error(ErrorCode.ENCODE_ERROR, "An error occured while encoding the reply."));
}
}
createResponse(ctx.request.returnValues(), reply, ctx.version, payload);
ctx.request.returnRequest();
}
Aggregations