Search in sources :

Example 1 with Service

use of io.cdap.cdap.api.service.Service in project cdap by cdapio.

the class ServiceHttpServer method initializeService.

@Override
protected void initializeService() throws Exception {
    super.initializeService();
    // Instantiate service instance
    Class<?> serviceClass = program.getClassLoader().loadClass(serviceSpecification.getClassName());
    @SuppressWarnings("unchecked") TypeToken<Service> serviceType = (TypeToken<Service>) TypeToken.of(serviceClass);
    service = new InstantiatorFactory(false).get(serviceType).create();
    // Initialize service
    // Service is always using Explicit transaction
    TransactionControl txControl = Transactions.getTransactionControl(TransactionControl.EXPLICIT, Service.class, service, "initialize", ServiceContext.class);
    serviceContext.initializeProgram(service, txControl, false);
}
Also used : InstantiatorFactory(io.cdap.cdap.common.lang.InstantiatorFactory) TypeToken(com.google.common.reflect.TypeToken) TransactionControl(io.cdap.cdap.api.annotation.TransactionControl) AbstractSystemService(io.cdap.cdap.api.service.AbstractSystemService) NettyHttpService(io.cdap.http.NettyHttpService) Service(io.cdap.cdap.api.service.Service) MessagingService(io.cdap.cdap.messaging.MessagingService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService)

Example 2 with Service

use of io.cdap.cdap.api.service.Service in project cdap by caskdata.

the class ServiceHttpServer method initializeService.

@Override
protected void initializeService() throws Exception {
    super.initializeService();
    // Instantiate service instance
    Class<?> serviceClass = program.getClassLoader().loadClass(serviceSpecification.getClassName());
    @SuppressWarnings("unchecked") TypeToken<Service> serviceType = (TypeToken<Service>) TypeToken.of(serviceClass);
    service = new InstantiatorFactory(false).get(serviceType).create();
    // Initialize service
    // Service is always using Explicit transaction
    TransactionControl txControl = Transactions.getTransactionControl(TransactionControl.EXPLICIT, Service.class, service, "initialize", ServiceContext.class);
    serviceContext.initializeProgram(service, txControl, false);
}
Also used : InstantiatorFactory(io.cdap.cdap.common.lang.InstantiatorFactory) TypeToken(com.google.common.reflect.TypeToken) TransactionControl(io.cdap.cdap.api.annotation.TransactionControl) AbstractSystemService(io.cdap.cdap.api.service.AbstractSystemService) NettyHttpService(io.cdap.http.NettyHttpService) Service(io.cdap.cdap.api.service.Service) MessagingService(io.cdap.cdap.messaging.MessagingService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)2 TransactionControl (io.cdap.cdap.api.annotation.TransactionControl)2 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)2 AbstractSystemService (io.cdap.cdap.api.service.AbstractSystemService)2 Service (io.cdap.cdap.api.service.Service)2 InstantiatorFactory (io.cdap.cdap.common.lang.InstantiatorFactory)2 MessagingService (io.cdap.cdap.messaging.MessagingService)2 NettyHttpService (io.cdap.http.NettyHttpService)2