/** * Resource description for the addressable resource * /subsystem=infinispan/cache-container=X/cache=Y/loader=LOADER * * @author Tristan Tarrant */ public class LoaderResource extends BaseLoaderResource { private static final PathElement LOADER_PATH = PathElement.pathElement(ModelKeys.LOADER); // attributes static final SimpleAttributeDefinition CLASS = new SimpleAttributeDefinitionBuilder(ModelKeys.CLASS, ModelType.STRING, false) .setXmlName(Attribute.CLASS.getLocalName()) .setAllowExpression(true) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) .build(); static final AttributeDefinition[] LOADER_ATTRIBUTES = {CLASS}; static final SimpleAttributeDefinition NAME = new SimpleAttributeDefinitionBuilder(BaseStoreResource.NAME) .setDefaultValue(new ModelNode().set(ModelKeys.LOADER_NAME)) .build(); // operations private static final OperationDefinition LOADER_ADD_DEFINITION = new SimpleOperationDefinitionBuilder( ADD, new InfinispanResourceDescriptionResolver(ModelKeys.LOADER)) .setParameters(COMMON_LOADER_PARAMETERS) .addParameter(CLASS) .setAttributeResolver(new InfinispanResourceDescriptionResolver(ModelKeys.LOADER)) .build(); public LoaderResource(CacheResource cacheResource) { super(LOADER_PATH, ModelKeys.LOADER, cacheResource, LOADER_ATTRIBUTES); } @Override public void registerOperations(ManagementResourceRegistration resourceRegistration) { super.registerOperations(resourceRegistration); } // override the add operation to provide a custom definition (for the optional PROPERTIES // parameter to add()) @Override protected void registerAddOperation( final ManagementResourceRegistration registration, final OperationStepHandler handler, OperationEntry.Flag... flags) { registration.registerOperationHandler(LOADER_ADD_DEFINITION, handler); } }
/** * {@inheritDoc} * * @see * org.jboss.staxmapper.XMLElementWriter#writeContent(org.jboss.staxmapper.XMLExtendedStreamWriter, * java.lang.Object) */ @Override public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { context.startSubsystemElement(Namespace.CURRENT.getUri(), false); ModelNode model = context.getModelNode(); if (model.isDefined()) { for (Property entry : model.get(ModelKeys.CACHE_CONTAINER).asPropertyList()) { String containerName = entry.getName(); ModelNode container = entry.getValue(); writer.writeStartElement(Element.CACHE_CONTAINER.getLocalName()); writer.writeAttribute(Attribute.NAME.getLocalName(), containerName); // AS7-3488 make default-cache a non required attribute // this.writeRequired(writer, Attribute.DEFAULT_CACHE, container, ModelKeys.DEFAULT_CACHE); this.writeListAsAttribute(writer, Attribute.ALIASES, container, ModelKeys.ALIASES); this.writeOptional(writer, Attribute.ASYNC_EXECUTOR, container, ModelKeys.ASYNC_EXECUTOR); this.writeOptional(writer, Attribute.DEFAULT_CACHE, container, ModelKeys.DEFAULT_CACHE); this.writeOptional( writer, Attribute.EVICTION_EXECUTOR, container, ModelKeys.EVICTION_EXECUTOR); this.writeOptional(writer, Attribute.JNDI_NAME, container, ModelKeys.JNDI_NAME); this.writeOptional( writer, Attribute.LISTENER_EXECUTOR, container, ModelKeys.LISTENER_EXECUTOR); this.writeOptional( writer, Attribute.REPLICATION_QUEUE_EXECUTOR, container, ModelKeys.REPLICATION_QUEUE_EXECUTOR); this.writeOptional( writer, Attribute.STATE_TRANSFER_EXECUTOR, container, ModelKeys.STATE_TRANSFER_EXECUTOR); this.writeOptional(writer, Attribute.START, container, ModelKeys.START); this.writeOptional(writer, Attribute.MODULE, container, ModelKeys.MODULE); this.writeOptional(writer, Attribute.STATISTICS, container, ModelKeys.STATISTICS); if (container.hasDefined(ModelKeys.TRANSPORT)) { writer.writeStartElement(Element.TRANSPORT.getLocalName()); ModelNode transport = container.get(ModelKeys.TRANSPORT, ModelKeys.TRANSPORT_NAME); this.writeOptional(writer, Attribute.STACK, transport, ModelKeys.STACK); this.writeOptional(writer, Attribute.CLUSTER, transport, ModelKeys.CLUSTER); this.writeOptional(writer, Attribute.EXECUTOR, transport, ModelKeys.EXECUTOR); this.writeOptional(writer, Attribute.LOCK_TIMEOUT, transport, ModelKeys.LOCK_TIMEOUT); this.writeOptional( writer, Attribute.REMOTE_COMMAND_EXECUTOR, transport, ModelKeys.REMOTE_COMMAND_EXECUTOR); this.writeOptional( writer, Attribute.STRICT_PEER_TO_PEER, transport, ModelKeys.STRICT_PEER_TO_PEER); this.writeOptional( writer, Attribute.TOTAL_ORDER_EXECUTOR, transport, ModelKeys.TOTAL_ORDER_EXECUTOR); writer.writeEndElement(); } if (container.hasDefined(ModelKeys.SECURITY)) { writer.writeStartElement(Element.SECURITY.getLocalName()); ModelNode security = container.get(ModelKeys.SECURITY, ModelKeys.SECURITY_NAME); if (security.hasDefined(ModelKeys.AUTHORIZATION)) { writer.writeStartElement(Element.AUTHORIZATION.getLocalName()); ModelNode authorization = security.get(ModelKeys.AUTHORIZATION, ModelKeys.AUTHORIZATION_NAME); if (authorization.hasDefined(ModelKeys.MAPPER)) { String mapper = authorization.get(ModelKeys.MAPPER).asString(); if (CommonNameRoleMapper.class.getName().equals(mapper)) { writer.writeEmptyElement(Element.COMMON_NAME_ROLE_MAPPER.getLocalName()); } else if (ClusterRoleMapper.class.getName().equals(mapper)) { writer.writeEmptyElement(Element.CLUSTER_ROLE_MAPPER.getLocalName()); } else if (IdentityRoleMapper.class.getName().equals(mapper)) { writer.writeEmptyElement(Element.IDENTITY_ROLE_MAPPER.getLocalName()); } else { writer.writeStartElement(Element.CUSTOM_ROLE_MAPPER.getLocalName()); writer.writeAttribute(Attribute.CLASS.getLocalName(), mapper); writer.writeEndElement(); } } ModelNode roles = authorization.get(ModelKeys.ROLE); for (ModelNode roleNode : roles.asList()) { ModelNode role = roleNode.get(0); writer.writeStartElement(Element.ROLE.getLocalName()); AuthorizationRoleResource.NAME.marshallAsAttribute(role, writer); this.writeListAsAttribute(writer, Attribute.PERMISSIONS, role, ModelKeys.PERMISSIONS); writer.writeEndElement(); } writer.writeEndElement(); } writer.writeEndElement(); } // write any existent cache types if (container.get(ModelKeys.LOCAL_CACHE).isDefined()) { for (Property localCacheEntry : container.get(ModelKeys.LOCAL_CACHE).asPropertyList()) { String localCacheName = localCacheEntry.getName(); ModelNode localCache = localCacheEntry.getValue(); writer.writeStartElement(Element.LOCAL_CACHE.getLocalName()); // write identifier before other attributes writer.writeAttribute(Attribute.NAME.getLocalName(), localCacheName); processCommonCacheAttributesElements(writer, localCache); writer.writeEndElement(); } } if (container.get(ModelKeys.INVALIDATION_CACHE).isDefined()) { for (Property invalidationCacheEntry : container.get(ModelKeys.INVALIDATION_CACHE).asPropertyList()) { String invalidationCacheName = invalidationCacheEntry.getName(); ModelNode invalidationCache = invalidationCacheEntry.getValue(); writer.writeStartElement(Element.INVALIDATION_CACHE.getLocalName()); // write identifier before other attributes writer.writeAttribute(Attribute.NAME.getLocalName(), invalidationCacheName); processCommonClusteredCacheAttributes(writer, invalidationCache); processCommonCacheAttributesElements(writer, invalidationCache); writer.writeEndElement(); } } if (container.get(ModelKeys.REPLICATED_CACHE).isDefined()) { for (Property replicatedCacheEntry : container.get(ModelKeys.REPLICATED_CACHE).asPropertyList()) { String replicatedCacheName = replicatedCacheEntry.getName(); ModelNode replicatedCache = replicatedCacheEntry.getValue(); writer.writeStartElement(Element.REPLICATED_CACHE.getLocalName()); // write identifier before other attributes writer.writeAttribute(Attribute.NAME.getLocalName(), replicatedCacheName); processCommonClusteredCacheAttributes(writer, replicatedCache); processCommonCacheAttributesElements(writer, replicatedCache); writer.writeEndElement(); } } if (container.get(ModelKeys.DISTRIBUTED_CACHE).isDefined()) { for (Property distributedCacheEntry : container.get(ModelKeys.DISTRIBUTED_CACHE).asPropertyList()) { String distributedCacheName = distributedCacheEntry.getName(); ModelNode distributedCache = distributedCacheEntry.getValue(); writer.writeStartElement(Element.DISTRIBUTED_CACHE.getLocalName()); // write identifier before other attributes writer.writeAttribute(Attribute.NAME.getLocalName(), distributedCacheName); // distributed cache attributes this.writeOptional(writer, Attribute.OWNERS, distributedCache, ModelKeys.OWNERS); this.writeOptional(writer, Attribute.SEGMENTS, distributedCache, ModelKeys.SEGMENTS); this.writeOptional( writer, Attribute.CAPACITY_FACTOR, distributedCache, ModelKeys.CAPACITY_FACTOR); this.writeOptional( writer, Attribute.L1_LIFESPAN, distributedCache, ModelKeys.L1_LIFESPAN); processCommonClusteredCacheAttributes(writer, distributedCache); processCommonCacheAttributesElements(writer, distributedCache); writer.writeEndElement(); } } writer.writeEndElement(); } } writer.writeEndElement(); }