use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class InfinispanCacheDeploymentListener method startCache.
@Override
public Wrapper startCache(Classification classification, Properties properties) throws Exception {
String cache_type = properties.getProperty(CACHE_TYPE);
String container = properties.getProperty(CONTAINER);
// TODO Figure out how to access CapabilityServiceSupport from here
ServiceName containerServiceName = ServiceName.parse(InfinispanRequirement.CONTAINER.resolve(container));
EmbeddedCacheManager embeddedCacheManager;
ServiceName serviceName;
if (CACHE_PRIVATE.equals(cache_type)) {
// need a private cache for non-jpa application use
String name = properties.getProperty(NAME);
serviceName = ServiceName.JBOSS.append(DEFAULT_CACHE_CONTAINER, (name != null) ? name : UUID.randomUUID().toString());
ServiceContainer target = currentServiceContainer();
// Create a mock service that represents this session factory instance
ServiceBuilder<EmbeddedCacheManager> builder = new AliasServiceBuilder<>(serviceName, containerServiceName, EmbeddedCacheManager.class).build(target).setInitialMode(ServiceController.Mode.ACTIVE);
embeddedCacheManager = ServiceContainerHelper.getValue(builder.install());
} else {
// need a shared cache for jpa applications
serviceName = containerServiceName;
ServiceRegistry registry = currentServiceContainer();
embeddedCacheManager = (EmbeddedCacheManager) registry.getRequiredService(serviceName).getValue();
}
return new CacheWrapper(embeddedCacheManager, serviceName);
}
use of org.jboss.msc.service.ServiceRegistry in project wildfly by wildfly.
the class SAMLResourceDefinition 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<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
if (serviceController != null) {
SAMLService service = serviceController.getValue();
ModelNode samlNode;
if (!rollback) {
samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
} else {
Resource rc = context.getOriginalRootResource().navigate(pathAddress);
samlNode = rc.getModel();
}
service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
}
}
};
}
use of org.jboss.msc.service.ServiceRegistry 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.ServiceRegistry 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.ServiceRegistry in project teiid by teiid.
the class EngineStatistics method updateServices.
static void updateServices(OperationContext context, RuntimeVDB vdb, String dsName, ReplaceResult rr) {
if (rr.isNew) {
VDBDeployer.addDataSourceListener(context.getServiceTarget(), new VDBKey(vdb.getVdb().getName(), vdb.getVdb().getVersion()), dsName);
}
if (rr.removedDs != null) {
final ServiceRegistry registry = context.getServiceRegistry(true);
ServiceName serviceName;
try {
serviceName = TeiidServiceNames.dsListenerServiceName(vdb.getVdb().getName(), vdb.getVdb().getVersion(), rr.removedDs);
} catch (InvalidServiceNameException e) {
// the old isn't valid
return;
}
final ServiceController<?> controller = registry.getService(serviceName);
if (controller != null) {
context.removeService(serviceName);
}
}
}
Aggregations