use of org.jboss.msc.service.ServiceNotFoundException in project wildfly by wildfly.
the class ServiceReferenceObjectFactory method getObjectInstance.
@SuppressWarnings("unchecked")
@Override
public final Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
final Reference reference = (Reference) obj;
final ServiceNameRefAdr nameAdr = (ServiceNameRefAdr) reference.get("srof");
if (nameAdr == null) {
throw NamingLogger.ROOT_LOGGER.invalidContextReference("srof");
}
final ServiceName serviceName = (ServiceName) nameAdr.getContent();
try {
final ServiceController<?> controller = serviceRegistry.getRequiredService(serviceName);
return getObjectInstance(controller.awaitValue(), obj, name, nameCtx, environment);
} catch (ServiceNotFoundException e) {
throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName);
} catch (InterruptedException e) {
throw NamingLogger.ROOT_LOGGER.threadInterrupt(serviceName);
} catch (Throwable t) {
throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName, getClass().getName(), "START_FAILED");
}
}
use of org.jboss.msc.service.ServiceNotFoundException in project wildfly by wildfly.
the class ServiceLifecycle method transition.
private void transition(Transition transition) {
// Short-circuit if the service is already at the target state
if (this.isComplete(transition))
return;
CountDownLatch latch = new CountDownLatch(1);
LifecycleListener listener = new CountDownLifecycleListener(latch, transition.targetEvents);
this.controller.addListener(listener);
try {
if (this.isComplete(transition))
return;
// Force service to transition to desired state
Mode currentMode = this.controller.getMode();
if (currentMode == ServiceController.Mode.REMOVE) {
throw new IllegalStateException(new ServiceNotFoundException(this.controller.getName().getCanonicalName()));
}
Mode targetMode = transition.modeTransitions.get(currentMode);
if (targetMode == null) {
throw new IllegalStateException(currentMode.name());
}
this.controller.setMode(targetMode);
latch.await();
if (this.controller.getState() == State.START_FAILED) {
throw new IllegalStateException(this.controller.getStartException());
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
this.controller.removeListener(listener);
}
}
use of org.jboss.msc.service.ServiceNotFoundException in project wildfly by wildfly.
the class ExceptionTestCase method test.
@Test
public void test() throws IOException {
Tester<Throwable> tester = ProtoStreamTesterFactory.INSTANCE.createTester();
tester.test(new StartException(), ExceptionTestCase::assertEquals);
tester.test(new StartException("message"), ExceptionTestCase::assertEquals);
tester.test(new StartException(new Exception()), ExceptionTestCase::assertEquals);
tester.test(new StartException("message", new Exception()), ExceptionTestCase::assertEquals);
tester.test(new ServiceNotFoundException(), ExceptionTestCase::assertEquals);
tester.test(new ServiceNotFoundException("message"), ExceptionTestCase::assertEquals);
tester.test(new ServiceNotFoundException(new Exception()), ExceptionTestCase::assertEquals);
tester.test(new ServiceNotFoundException("message", new Exception()), ExceptionTestCase::assertEquals);
}
use of org.jboss.msc.service.ServiceNotFoundException in project wildfly by wildfly.
the class ServiceReferenceObjectFactory method getObjectInstance.
@SuppressWarnings("unchecked")
@Override
public final Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
final Reference reference = (Reference) obj;
final ServiceNameRefAdr nameAdr = (ServiceNameRefAdr) reference.get("srof");
if (nameAdr == null) {
throw NamingLogger.ROOT_LOGGER.invalidContextReference("srof");
}
final ServiceName serviceName = (ServiceName) nameAdr.getContent();
final ServiceController<?> controller;
try {
controller = serviceRegistry.getRequiredService(serviceName);
} catch (ServiceNotFoundException e) {
throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName);
}
final StabilityMonitor monitor = new StabilityMonitor();
monitor.addController(controller);
try {
monitor.awaitStability();
} catch (InterruptedException e) {
throw NamingLogger.ROOT_LOGGER.threadInterrupt(serviceName);
} finally {
monitor.removeController(controller);
}
switch(controller.getState()) {
case UP:
return getObjectInstance(controller.getValue(), obj, name, nameCtx, environment);
case START_FAILED:
throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName, getClass().getName(), "START_FAILED");
case REMOVED:
throw NamingLogger.ROOT_LOGGER.cannotResolveService(serviceName, getClass().getName(), "REMOVED");
}
// we should never get here, as the listener should not notify unless the state was one of the above
throw NamingLogger.ROOT_LOGGER.cannotResolveServiceBug(serviceName, getClass().getName(), controller.getState().toString());
}
use of org.jboss.msc.service.ServiceNotFoundException in project wildfly by wildfly.
the class AbstractDistributedSingletonService method providersChanged.
@Override
public synchronized void providersChanged(Set<Node> nodes) {
Group group = this.registry.get().getGroup();
List<Node> candidates = new ArrayList<>(group.getMembership().getMembers());
candidates.retainAll(nodes);
// Only run election on a single node
if (candidates.isEmpty() || candidates.get(0).equals(group.getLocalMember())) {
// First validate that quorum was met
int size = candidates.size();
boolean quorumMet = size >= this.quorum;
if ((this.quorum > 1) && (size == this.quorum)) {
// Log fragility of singleton availability
ClusteringServerLogger.ROOT_LOGGER.quorumJustReached(this.name.getCanonicalName(), this.quorum);
}
Node elected = quorumMet ? this.electionPolicy.elect(candidates) : null;
try {
if (elected != null) {
// Stop service on every node except elected node
for (Map.Entry<Node, CompletionStage<Void>> entry : this.dispatcher.executeOnGroup(new StopCommand(), elected).entrySet()) {
try {
entry.getValue().toCompletableFuture().join();
} catch (CancellationException e) {
ClusteringServerLogger.ROOT_LOGGER.tracef("Singleton service %s is not installed on %s", this.name.getCanonicalName(), entry.getKey().getName());
} catch (CompletionException e) {
Throwable cause = e.getCause();
if ((cause instanceof IllegalStateException) && (cause.getCause() instanceof ServiceNotFoundException)) {
ClusteringServerLogger.ROOT_LOGGER.debugf("Singleton service %s is no longer installed on %s", this.name.getCanonicalName(), entry.getKey().getName());
} else {
throw e;
}
}
}
// Start service on elected node
try {
this.dispatcher.executeOnMember(new StartCommand(), elected).toCompletableFuture().join();
} catch (CancellationException e) {
ClusteringServerLogger.ROOT_LOGGER.debugf("Singleton service %s could not be started on the elected primary singleton provider (%s) because it left the cluster. A new primary provider election will take place.", this.name.getCanonicalName(), elected.getName());
} catch (CompletionException e) {
Throwable cause = e.getCause();
if ((cause instanceof IllegalStateException) && (cause.getCause() instanceof ServiceNotFoundException)) {
ClusteringServerLogger.ROOT_LOGGER.debugf("Service % is no longer installed on the elected primary singleton provider (%s). A new primary provider election will take place.", this.name.getCanonicalName(), elected.getName());
} else {
throw e;
}
}
} else {
if (!quorumMet) {
ClusteringServerLogger.ROOT_LOGGER.quorumNotReached(this.name.getCanonicalName(), this.quorum);
}
// Stop service on every node
for (Map.Entry<Node, CompletionStage<Void>> entry : this.dispatcher.executeOnGroup(new StopCommand()).entrySet()) {
try {
entry.getValue().toCompletableFuture().join();
} catch (CancellationException e) {
ClusteringServerLogger.ROOT_LOGGER.tracef("Singleton service %s is not installed on %s", this.name.getCanonicalName(), entry.getKey().getName());
} catch (CompletionException e) {
Throwable cause = e.getCause();
if ((cause instanceof IllegalStateException) && (cause.getCause() instanceof ServiceNotFoundException)) {
ClusteringServerLogger.ROOT_LOGGER.debugf("Singleton service %s is no longer installed on %s", this.name.getCanonicalName(), entry.getKey().getName());
} else {
throw e;
}
}
}
}
if (this.electionListener != null) {
for (CompletionStage<Void> stage : this.dispatcher.executeOnGroup(new SingletonElectionCommand(candidates, elected)).values()) {
try {
stage.toCompletableFuture().join();
} catch (CancellationException e) {
// Ignore
}
}
}
} catch (CommandDispatcherException e) {
throw new IllegalStateException(e);
}
}
}
Aggregations