use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class EntityProviderService method getService.
public static EntityProviderService getService(OperationContext context, String alias) {
// We assume the mgmt ops that trigger IdentityProviderAddHandler or ServiceProviderAddHandler
// run before the OperationStepHandler that triggers deploy. If not, that's a user mistake.
// Since those handlers run first, we can count on MSC having services *registered* even
// though we cannot count on them being *started*.
ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
ServiceController<EntityProviderService> service = (ServiceController<EntityProviderService>) serviceRegistry.getService(IdentityProviderService.createServiceName(alias));
if (service == null) {
service = (ServiceController<EntityProviderService>) serviceRegistry.getService(ServiceProviderService.createServiceName(alias));
}
if (service == null) {
return null;
}
return service.getValue();
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class WritableServiceBasedNamingStoreTestCase method setup.
@Before
public void setup() throws Exception {
container = ServiceContainer.Factory.create();
installOwnerService(OWNER_FOO);
installOwnerService(OWNER_BAR);
final CountDownLatch latch2 = new CountDownLatch(1);
final NamingStoreService namingStoreService = new NamingStoreService();
container.addService(ContextNames.JAVA_CONTEXT_SERVICE_NAME, namingStoreService).setInitialMode(ServiceController.Mode.ACTIVE).addListener(new AbstractServiceListener<NamingStore>() {
public void transition(ServiceController<? extends NamingStore> controller, ServiceController.Transition transition) {
switch(transition) {
case STARTING_to_UP:
{
latch2.countDown();
break;
}
case STARTING_to_START_FAILED:
{
latch2.countDown();
fail("Did not install store service - " + controller.getStartException().getMessage());
break;
}
default:
break;
}
}
}).install();
latch2.await(10, TimeUnit.SECONDS);
store = (WritableServiceBasedNamingStore) namingStoreService.getValue();
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class WritableServiceBasedNamingStoreTestCase method installOwnerService.
private void installOwnerService(ServiceName owner) throws InterruptedException {
final CountDownLatch latch1 = new CountDownLatch(1);
container.addService(JndiNamingDependencyProcessor.serviceName(owner), new RuntimeBindReleaseService()).setInitialMode(ServiceController.Mode.ACTIVE).addListener(new AbstractServiceListener<Object>() {
public void transition(ServiceController<?> controller, ServiceController.Transition transition) {
switch(transition) {
case STARTING_to_UP:
{
latch1.countDown();
break;
}
case STARTING_to_START_FAILED:
{
latch1.countDown();
fail("Did not install store service - " + controller.getStartException().getMessage());
break;
}
default:
break;
}
}
}).install();
latch1.await(10, TimeUnit.SECONDS);
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class KeyStoreProviderResourceDefinition method createAttributeWriterHandler.
@Override
protected OperationStepHandler createAttributeWriterHandler() {
List<SimpleAttributeDefinition> attributes = getAttributes();
return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {
@Override
protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, false);
return false;
}
@Override
protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
updateConfiguration(context, pathAddress, true);
}
private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
ServiceController<KeyStoreProviderService> serviceController = (ServiceController<KeyStoreProviderService>) serviceRegistry.getService(KeyStoreProviderService.createServiceName(federationAlias));
if (serviceController != null) {
KeyStoreProviderService service = serviceController.getValue();
ModelNode keyStoreProviderNode;
if (!rollback) {
keyStoreProviderNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
} else {
Resource rc = context.getOriginalRootResource().navigate(pathAddress);
keyStoreProviderNode = rc.getModel();
}
ModelNode relativeToNode = KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keyStoreProviderNode);
String relativeTo = null;
if (relativeToNode.isDefined()) {
relativeTo = relativeToNode.asString();
}
String file = KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, keyStoreProviderNode).asString();
service.setKeyProviderType(KeyStoreProviderAddHandler.toKeyProviderType(context, keyStoreProviderNode), file, relativeTo);
}
}
};
}
use of org.jboss.msc.service.ServiceController in project wildfly by wildfly.
the class CacheFactoryAdd method installRuntimeServices.
Collection<ServiceController<?>> installRuntimeServices(OperationContext context, ModelNode operation, ModelNode model, ServiceVerificationHandler verificationHandler) throws OperationFailedException {
final String name = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.ADDRESS)).getLastElement().getValue();
ModelNode passivationStoreModel = CacheFactoryResourceDefinition.PASSIVATION_STORE.resolveModelAttribute(context, model);
String passivationStore = passivationStoreModel.isDefined() ? passivationStoreModel.asString() : null;
final Collection<String> unwrappedAliasValues = CacheFactoryResourceDefinition.ALIASES.unwrap(context, model);
final Set<String> aliases = unwrappedAliasValues != null ? new HashSet<>(unwrappedAliasValues) : Collections.<String>emptySet();
ServiceTarget target = context.getServiceTarget();
ServiceBuilder<?> builder = buildCacheFactoryBuilder(target, name, passivationStore);
for (String alias : aliases) {
builder.addAliases(CacheFactoryBuilderService.getServiceName(alias));
}
if (verificationHandler != null) {
builder.addListener(verificationHandler);
}
return Collections.<ServiceController<?>>singleton(builder.install());
}
Aggregations