use of co.cask.cdap.internal.app.runtime.service.http.HttpHandlerFactory in project cdap by caskdata.
the class ServiceHttpServer method createNettyHttpService.
/**
* Creates a {@link NettyHttpService} from the given host, and list of {@link HandlerDelegatorContext}s
*
* @param program Program that contains the handler
* @param host the host which the service will run on
* @param delegatorContexts the list {@link HandlerDelegatorContext}
* @param metricsContext a {@link MetricsContext} for metrics collection
*
* @return a NettyHttpService which delegates to the {@link HttpServiceHandler}s to handle the HTTP requests
*/
private NettyHttpService createNettyHttpService(Program program, String host, Iterable<HandlerDelegatorContext> delegatorContexts, MetricsContext metricsContext) {
// The service URI is always prefixed for routing purpose
String pathPrefix = String.format("%s/namespaces/%s/apps/%s/services/%s/methods", Constants.Gateway.API_VERSION_3, program.getNamespaceId(), program.getApplicationId(), program.getName());
String versionId = program.getId().getVersion();
String versionedPathPrefix = String.format("%s/namespaces/%s/apps/%s/versions/%s/services/%s/methods", Constants.Gateway.API_VERSION_3, program.getNamespaceId(), program.getApplicationId(), versionId, program.getName());
// Create HttpHandlers which delegate to the HttpServiceHandlers
HttpHandlerFactory factory = new HttpHandlerFactory(pathPrefix, metricsContext);
HttpHandlerFactory versionedFactory = new HttpHandlerFactory(versionedPathPrefix, metricsContext);
List<HttpHandler> nettyHttpHandlers = Lists.newArrayList();
// get the runtime args from the twill context
for (HandlerDelegatorContext context : delegatorContexts) {
nettyHttpHandlers.add(factory.createHttpHandler(context.getHandlerType(), context));
nettyHttpHandlers.add(versionedFactory.createHttpHandler(context.getHandlerType(), context));
}
NettyHttpService.Builder builder = NettyHttpService.builder(program.getName() + "-http").setHost(host).setPort(0).addHttpHandlers(nettyHttpHandlers);
// These properties are for unit-test only. Currently they are not controllable by the user program
String threadPoolSize = System.getProperty(THREAD_POOL_SIZE);
if (threadPoolSize != null) {
builder.setExecThreadPoolSize(Integer.parseInt(threadPoolSize));
}
String threadAliveSec = System.getProperty(THREAD_KEEP_ALIVE_SECONDS);
if (threadAliveSec != null) {
builder.setExecThreadKeepAliveSeconds(Long.parseLong(threadAliveSec));
}
return builder.build();
}
use of co.cask.cdap.internal.app.runtime.service.http.HttpHandlerFactory in project cdap by caskdata.
the class DefaultServiceConfigurer method verifyHandlers.
private void verifyHandlers(List<? extends HttpServiceHandler> handlers) {
Preconditions.checkArgument(!handlers.isEmpty(), "Service %s should have at least one handler", name);
new HttpHandlerFactory("", TransactionControl.IMPLICIT).validateHttpHandler(handlers);
}
use of co.cask.cdap.internal.app.runtime.service.http.HttpHandlerFactory in project cdap by caskdata.
the class DefaultServiceConfigurer method createHttpHandler.
private <T extends HttpServiceHandler> HttpHandler createHttpHandler(T handler) {
MetricsContext noOpsMetricsContext = new NoOpMetricsCollectionService().getContext(new HashMap<String, String>());
HttpHandlerFactory factory = new HttpHandlerFactory("", noOpsMetricsContext);
@SuppressWarnings("unchecked") TypeToken<T> type = (TypeToken<T>) TypeToken.of(handler.getClass());
return factory.createHttpHandler(type, new VerificationDelegateContext<>(handler));
}
Aggregations