use of org.mule.runtime.api.service.Service in project mule by mulesoft.
the class MuleServiceManagerTestCase method registerServices.
@Test
public void registerServices() throws Exception {
final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
Pair<ArtifactClassLoader, Service> service1 = new Pair(mock(ArtifactClassLoader.class), mock(Service.class));
Pair<ArtifactClassLoader, Service> service2 = new Pair(mock(ArtifactClassLoader.class), mock(Service.class));
services.add(service1);
services.add(service2);
when(serviceDiscoverer.discoverServices()).thenReturn(services);
final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
muleServiceManager.start();
assertThat(muleServiceManager.getServices().size(), equalTo(2));
assertThat(muleServiceManager.getServices().get(0), equalTo(service1.getSecond()));
assertThat(muleServiceManager.getServices().get(1), equalTo(service2.getSecond()));
}
use of org.mule.runtime.api.service.Service in project mule by mulesoft.
the class MuleServiceManagerTestCase method stopsOnlyStoppableServices.
@Test
public void stopsOnlyStoppableServices() throws Exception {
final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
Pair<ArtifactClassLoader, Service> service1Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StoppableService.class));
Pair<ArtifactClassLoader, Service> service2Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StoppableService.class));
services.add(service1Pairs);
services.add(service2Pairs);
when(serviceDiscoverer.discoverServices()).thenReturn(services);
final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
muleServiceManager.start();
muleServiceManager.stop();
InOrder inOrder = inOrder(service1Pairs.getSecond(), service2Pairs.getSecond());
inOrder.verify((StoppableService) service2Pairs.getSecond()).stop();
inOrder.verify((StoppableService) service1Pairs.getSecond()).stop();
}
use of org.mule.runtime.api.service.Service in project mule by mulesoft.
the class MuleServiceManagerTestCase method stopsStartableStoppableServices.
@Test
public void stopsStartableStoppableServices() throws Exception {
final ServiceDiscoverer serviceDiscoverer = mock(ServiceDiscoverer.class);
final List<Pair<ArtifactClassLoader, Service>> services = new ArrayList<>();
Pair<ArtifactClassLoader, Service> service1Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StartableStoppableService.class));
Pair<ArtifactClassLoader, Service> service2Pairs = new Pair(mock(ArtifactClassLoader.class), mock(StartableStoppableService.class));
services.add(service1Pairs);
services.add(service2Pairs);
when(serviceDiscoverer.discoverServices()).thenReturn(services);
final MuleServiceManager muleServiceManager = new MuleServiceManager(serviceDiscoverer);
muleServiceManager.start();
muleServiceManager.stop();
InOrder inOrder = inOrder(service1Pairs.getSecond(), service2Pairs.getSecond());
inOrder.verify((StartableStoppableService) service2Pairs.getSecond()).stop();
inOrder.verify((StartableStoppableService) service1Pairs.getSecond()).stop();
}
use of org.mule.runtime.api.service.Service in project mule by mulesoft.
the class LifecycleFilterServiceProxy method createLifecycleFilterServiceProxy.
/**
* Creates a proxy for the provided service instance.
*
* @param service service to wrap. Non null.
* @return a new proxy instance.
*/
public static Service createLifecycleFilterServiceProxy(Service service) {
checkArgument(service != null, "service cannot be null");
InvocationHandler handler = new LifecycleFilterServiceProxy(service);
return (Service) newProxyInstance(service.getClass().getClassLoader(), findImplementedInterfaces(service.getClass()), handler);
}
use of org.mule.runtime.api.service.Service in project mule by mulesoft.
the class MuleServiceManager method startServices.
private void startServices() throws MuleException {
for (Pair<ArtifactClassLoader, Service> pair : registeredServices) {
Service service = pair.getSecond();
if (service instanceof Startable) {
ClassLoader originalContextClassLoader = currentThread().getContextClassLoader();
try {
currentThread().setContextClassLoader(service.getClass().getClassLoader());
((Startable) service).start();
startedServices.add(service);
if (isNotEmpty(service.getSplashMessage())) {
logger.info(new ServiceSplashScreen(service).toString());
}
} finally {
currentThread().setContextClassLoader(originalContextClassLoader);
}
}
}
}
Aggregations