use of org.wildfly.clustering.group.Node in project quickstart by wildfly.
the class QueryingService method start.
@Override
public void start(StartContext context) throws StartException {
LOG.info("Querying service is starting.");
executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(() -> {
@SuppressWarnings("unchecked") ServiceController<Node> service = (ServiceController<Node>) context.getController().getServiceContainer().getService(ServiceActivator.SINGLETON_SERVICE_NAME);
try {
Node node = service.awaitValue(5, TimeUnit.SECONDS);
LOG.infof("Singleton service is running on node '%s'.", node);
} catch (InterruptedException | TimeoutException | IllegalStateException e) {
LOG.warn("Failed to query singleton service.");
}
}, 5, 5, TimeUnit.SECONDS);
}
use of org.wildfly.clustering.group.Node in project quickstart by wildfly.
the class ServiceActivator method activate.
@Override
public void activate(ServiceActivatorContext serviceActivatorContext) {
try {
SingletonPolicy policy = (SingletonPolicy) serviceActivatorContext.getServiceRegistry().getRequiredService(ServiceName.parse(SingletonDefaultRequirement.SINGLETON_POLICY.getName())).awaitValue();
InjectedValue<Group> group = new InjectedValue<>();
Service<Node> primary = new SingletonService(true, group);
Service<Node> backup = new SingletonService(false, group);
policy.createSingletonServiceBuilder(SINGLETON_SERVICE_NAME, primary, backup).build(serviceActivatorContext.getServiceTarget()).addDependency(ServiceName.parse("org.wildfly.clustering.default-group"), Group.class, group).install();
LOG.info("Singleton service activated.");
} catch (InterruptedException e) {
throw new ServiceRegistryException(e);
}
}
Aggregations