Search in sources :

Example 1 with Injector

use of io.zeebe.servicecontainer.Injector in project zeebe by zeebe-io.

the class EmbeddedBrokerRule method getService.

public <S> S getService(ServiceName<S> serviceName) {
    final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer();
    final Injector<S> injector = new Injector<>();
    final ServiceName<Object> accessorServiceName = ServiceName.newServiceName("serviceAccess" + serviceName.getName(), Object.class);
    try {
        serviceContainer.createService(accessorServiceName, new NoneService()).dependency(serviceName, injector).install().get();
    } catch (InterruptedException | ExecutionException e) {
        throw new RuntimeException(e);
    }
    serviceContainer.removeService(accessorServiceName);
    return injector.getValue();
}
Also used : ServiceContainer(io.zeebe.servicecontainer.ServiceContainer) Injector(io.zeebe.servicecontainer.Injector) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Injector (io.zeebe.servicecontainer.Injector)1 ServiceContainer (io.zeebe.servicecontainer.ServiceContainer)1 ExecutionException (java.util.concurrent.ExecutionException)1