use of com.yahoo.docproc.DocprocService 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.docproc.DocprocService in project vespa by vespa-engine.
the class MessagePropertyProcessor method getDocprocServiceRegistry.
public synchronized ComponentRegistry<DocprocService> getDocprocServiceRegistry(HttpRequest request) {
String docprocChain = getDocprocChainParameter(request);
if (docprocChain == null) {
return null;
}
Container container = Container.get();
if (container == null) {
throw new IllegalStateException("Could not get Container instance.");
}
ComponentRegistry<RequestHandler> requestHandlerRegistry = container.getRequestHandlerRegistry();
if (requestHandlerRegistry == null) {
throw new IllegalStateException("Could not get requesthandlerregistry.");
}
DocumentProcessingHandler handler = (DocumentProcessingHandler) requestHandlerRegistry.getComponent(DocumentProcessingHandler.class.getName());
if (handler == null) {
return null;
}
ComponentRegistry<DocprocService> services = handler.getDocprocServiceRegistry();
if (services == null) {
throw new IllegalStateException("Could not get DocprocServiceRegistry.");
}
return services;
}
use of com.yahoo.docproc.DocprocService in project vespa by vespa-engine.
the class DocumentProcessingHandler method handleRequest.
@Override
public ContentChannel handleRequest(Request request, ResponseHandler handler) {
RequestContext requestContext;
if (request instanceof MbusRequest) {
requestContext = new MbusRequestContext((MbusRequest) request, handler, docprocServiceRegistry, docFactoryRegistry, containerDocConfig);
} else {
// Other types can be added here in the future
throw new IllegalArgumentException("Request type not supported: " + request);
}
if (!requestContext.isProcessable()) {
requestContext.skip();
return null;
}
DocprocService service = docprocServiceRegistry.getComponent(requestContext.getServiceName());
// No need to enqueue a task if the docproc chain is empty, just forward requestContext
if (service == null) {
log.log(LogLevel.ERROR, "DocprocService for session '" + requestContext.getServiceName() + "' not found, returning request '" + requestContext + "'.");
requestContext.processingFailed(RequestContext.ErrorCode.ERROR_PROCESSING_FAILURE, "DocprocService " + requestContext.getServiceName() + " not found.");
return null;
} else if (service.getExecutor().getCallStack().size() == 0) {
// call stack was empty, just forward message
requestContext.skip();
return null;
}
DocumentProcessingTask task = new DocumentProcessingTask(requestContext, this, service);
submit(task);
return null;
}
Aggregations