repo
stringlengths
1
191
file
stringlengths
23
351
code
stringlengths
0
5.32M
file_length
int64
0
5.32M
avg_line_length
float64
0
2.9k
max_line_length
int64
0
288k
extension_type
stringclasses
1 value
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/EncryptProtocolResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import java.security.KeyStore; import java.util.EnumSet; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.CapabilityReference; import org.jboss.as.clustering.controller.CommonUnaryRequirement; import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceServiceConfigurator; import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.security.CredentialReference; import org.jboss.as.controller.security.CredentialReferenceWriteAttributeHandler; import org.jboss.dmr.ModelType; /** * Resource definition override for protocols that require an encryption key. * @author Paul Ferraro */ public class EncryptProtocolResourceDefinition<E extends KeyStore.Entry> extends ProtocolResourceDefinition { enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> { KEY_CREDENTIAL(CredentialReference.getAttributeBuilder("key-credential-reference", null, false, new CapabilityReference(Capability.PROTOCOL, CommonUnaryRequirement.CREDENTIAL_STORE)).build()), KEY_ALIAS("key-alias", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setAllowExpression(true); } }, KEY_STORE("key-store", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setCapabilityReference(new CapabilityReference(Capability.PROTOCOL, CommonUnaryRequirement.KEY_STORE)); } }, ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type) .setRequired(true) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) ).build(); } Attribute(AttributeDefinition definition) { this.definition = definition; } @Override public AttributeDefinition getDefinition() { return this.definition; } @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder; } } private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> { private final UnaryOperator<ResourceDescriptor> configurator; ResourceDescriptorConfigurator(UnaryOperator<ResourceDescriptor> configurator) { this.configurator = configurator; } @Override public ResourceDescriptor apply(ResourceDescriptor descriptor) { return this.configurator.apply(descriptor) .addAttributes(EnumSet.complementOf(EnumSet.of(Attribute.KEY_CREDENTIAL))) .addAttribute(Attribute.KEY_CREDENTIAL, new CredentialReferenceWriteAttributeHandler(Attribute.KEY_CREDENTIAL.getDefinition())) .setAddOperationTransformation(new LegacyAddOperationTransformation(Attribute.class)) .setOperationTransformation(LEGACY_OPERATION_TRANSFORMER) ; } } private static class EncryptProtocolConfigurationConfiguratorFactory<E extends KeyStore.Entry> implements ResourceServiceConfiguratorFactory { private final Class<E> entryClass; EncryptProtocolConfigurationConfiguratorFactory(Class<E> entryClass) { this.entryClass = entryClass; } @Override public ResourceServiceConfigurator createServiceConfigurator(PathAddress address) { return new EncryptProtocolConfigurationServiceConfigurator<>(address, this.entryClass); } } public EncryptProtocolResourceDefinition(String name, Class<E> entryClass, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) { super(pathElement(name), new ResourceDescriptorConfigurator(configurator), new EncryptProtocolConfigurationConfiguratorFactory<>(entryClass), parentServiceConfiguratorFactory); } }
5,669
45.47541
200
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelClusterServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import static org.jboss.as.clustering.jgroups.subsystem.ChannelResourceDefinition.Attribute.CLUSTER; import java.util.function.Consumer; import org.jboss.as.clustering.controller.CapabilityServiceNameProvider; import org.jboss.as.clustering.controller.ResourceServiceConfigurator; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.service.ServiceConfigurator; /** * Builds a service providing the cluster name of a channel. * @author Paul Ferraro */ public class ChannelClusterServiceConfigurator extends CapabilityServiceNameProvider implements ResourceServiceConfigurator { private final String name; private volatile String cluster; public ChannelClusterServiceConfigurator(PathAddress address) { super(ChannelResourceDefinition.Capability.JCHANNEL_CLUSTER, address); this.name = address.getLastElement().getValue(); } @Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.cluster = CLUSTER.resolveModelAttribute(context, model).asString(this.name); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<String> cluster = builder.provides(this.getServiceName()); Service service = Service.newInstance(cluster, this.cluster); return builder.setInstance(service); } }
2,821
39.898551
125
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/PlainAuthTokenServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import org.jboss.as.clustering.jgroups.auth.BinaryAuthToken; import org.jboss.as.controller.PathAddress; import java.nio.charset.StandardCharsets; /** * @author Paul Ferraro */ public class PlainAuthTokenServiceConfigurator extends AuthTokenServiceConfigurator<BinaryAuthToken> { public PlainAuthTokenServiceConfigurator(PathAddress address) { super(address); } @Override public BinaryAuthToken apply(String sharedSecret) { return new BinaryAuthToken(sharedSecret.getBytes(StandardCharsets.UTF_8)); } }
1,621
35.863636
102
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ThreadPoolServiceNameProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.ServiceNameProvider; /** * @author Paul Ferraro */ public class ThreadPoolServiceNameProvider implements ServiceNameProvider { private final ServiceName name; public ThreadPoolServiceNameProvider(PathAddress address) { this(address.getParent(), address.getLastElement()); } public ThreadPoolServiceNameProvider(PathAddress transportAddress, PathElement path) { this.name = new SingletonProtocolServiceNameProvider(transportAddress).getServiceName().append(path.getValue()); } @Override public ServiceName getServiceName() { return this.name; } }
1,853
36.08
120
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/StackResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.CapabilityProvider; import org.jboss.as.clustering.controller.ChildResourceDefinition; import org.jboss.as.clustering.controller.ManagementResourceRegistration; import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory; import org.jboss.as.clustering.controller.ResourceServiceHandler; import org.jboss.as.clustering.controller.SimpleResourceRegistrar; import org.jboss.as.clustering.controller.UnaryRequirementCapability; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.wildfly.clustering.jgroups.spi.JGroupsRequirement; import org.wildfly.clustering.service.UnaryRequirement; /** * Resource description for the addressable resource /subsystem=jgroups/stack=X * * @author Richard Achmatowicz (c) 2011 Red Hat Inc. * @author Paul Ferraro */ public class StackResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> { public static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE); public static PathElement pathElement(String name) { return PathElement.pathElement("stack", name); } enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> { STATISTICS_ENABLED(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setDefaultValue(ModelNode.FALSE); } }, ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type) .setRequired(false) .setAllowExpression(true) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) ).build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } enum Capability implements CapabilityProvider { JCHANNEL_FACTORY(JGroupsRequirement.CHANNEL_FACTORY), ; private final org.jboss.as.clustering.controller.Capability capability; Capability(UnaryRequirement requirement) { this.capability = new UnaryRequirementCapability(requirement); } @Override public org.jboss.as.clustering.controller.Capability getCapability() { return this.capability; } } private final ResourceServiceConfiguratorFactory serviceConfiguratorFactory = JChannelFactoryServiceConfigurator::new; // registration public StackResourceDefinition() { super(WILDCARD_PATH, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH)); } @Override public ManagementResourceRegistration register(ManagementResourceRegistration parent) { ManagementResourceRegistration registration = parent.registerSubModel(this); ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()) .addAttributes(Attribute.class) .addCapabilities(Capability.class) ; ResourceServiceHandler handler = new StackServiceHandler(this.serviceConfiguratorFactory); new SimpleResourceRegistrar(descriptor, handler).register(registration); if (registration.isRuntimeOnlyRegistrationValid()) { new StackOperationHandler().register(registration); } new TransportResourceRegistrar(this.serviceConfiguratorFactory).register(registration); new ProtocolResourceRegistrar(this.serviceConfiguratorFactory).register(registration); new RelayResourceDefinition(this.serviceConfiguratorFactory).register(registration); return registration; } }
5,423
41.708661
125
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/DigestAuthTokenServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import static org.jboss.as.clustering.jgroups.subsystem.DigestAuthTokenResourceDefinition.Attribute.ALGORITHM; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import org.jboss.as.clustering.jgroups.auth.BinaryAuthToken; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.dmr.ModelNode; import org.wildfly.clustering.service.ServiceConfigurator; /** * Builds an AUTH token, functionally equivalent to {@link org.jgroups.auth.MD5Token}, but can use any digest algorithm supported by the default security provider. * @author Paul Ferraro */ public class DigestAuthTokenServiceConfigurator extends AuthTokenServiceConfigurator<BinaryAuthToken> { private volatile String algorithm; public DigestAuthTokenServiceConfigurator(PathAddress address) { super(address); } @Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.algorithm = ALGORITHM.resolveModelAttribute(context, model).asString(); return super.configure(context, model); } @Override public BinaryAuthToken apply(String sharedSecret) { try { MessageDigest digest = MessageDigest.getInstance(this.algorithm); return new BinaryAuthToken(digest.digest(sharedSecret.getBytes(StandardCharsets.UTF_8))); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException(e); } } }
2,710
40.075758
163
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import java.util.ArrayList; import java.util.EnumMap; import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.Capability; import org.jboss.as.clustering.controller.CapabilityReference; import org.jboss.as.clustering.controller.DefaultSubsystemDescribeHandler; import org.jboss.as.clustering.controller.ManagementResourceRegistration; import org.jboss.as.clustering.controller.RequirementCapability; import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceServiceHandler; import org.jboss.as.clustering.controller.SimpleResourceRegistrar; import org.jboss.as.clustering.controller.SubsystemRegistration; import org.jboss.as.clustering.controller.SubsystemResourceDefinition; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.dmr.ModelType; import org.wildfly.clustering.jgroups.spi.JGroupsRequirement; import org.wildfly.clustering.server.service.ClusteringRequirement; /** * The root resource of the JGroups subsystem. * * @author Richard Achmatowicz (c) 2012 Red Hat Inc. */ public class JGroupsSubsystemResourceDefinition extends SubsystemResourceDefinition { public static final PathElement PATH = pathElement(JGroupsExtension.SUBSYSTEM_NAME); static final Map<JGroupsRequirement, Capability> CAPABILITIES = new EnumMap<>(JGroupsRequirement.class); static { for (JGroupsRequirement requirement : EnumSet.allOf(JGroupsRequirement.class)) { CAPABILITIES.put(requirement, new RequirementCapability(requirement.getDefaultRequirement())); } } public enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> { DEFAULT_CHANNEL("default-channel", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setCapabilityReference(new CapabilityReference(CAPABILITIES.get(JGroupsRequirement.CHANNEL_FACTORY), JGroupsRequirement.CHANNEL_FACTORY)); } }, ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type) .setRequired(false) .setAllowExpression(false) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) .setXmlName(XMLAttribute.DEFAULT.getLocalName()) ).build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } JGroupsSubsystemResourceDefinition() { super(PATH, JGroupsExtension.SUBSYSTEM_RESOLVER); } @Override public void register(SubsystemRegistration parentRegistration) { ManagementResourceRegistration registration = parentRegistration.registerSubsystemModel(this); new DefaultSubsystemDescribeHandler().register(registration); Set<ClusteringRequirement> requirements = EnumSet.allOf(ClusteringRequirement.class); List<Capability> capabilities = new ArrayList<>(requirements.size()); UnaryOperator<RuntimeCapability.Builder<Void>> configurator = builder -> builder.setAllowMultipleRegistrations(true); for (ClusteringRequirement requirement : requirements) { capabilities.add(new RequirementCapability(requirement.getDefaultRequirement(), configurator)); } ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()) .addAttributes(Attribute.class) .addCapabilities(model -> model.hasDefined(Attribute.DEFAULT_CHANNEL.getName()), CAPABILITIES.values()) .addCapabilities(model -> model.hasDefined(Attribute.DEFAULT_CHANNEL.getName()), capabilities) ; ResourceServiceHandler handler = new JGroupsSubsystemServiceHandler(); new SimpleResourceRegistrar(descriptor, handler).register(registration); new ChannelResourceDefinition().register(registration); new StackResourceDefinition().register(registration); } }
5,652
45.719008
169
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolResourceRegistrar.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import java.net.InetSocketAddress; import java.security.KeyStore; import java.util.EnumSet; import java.util.function.Function; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.ManagementRegistrar; import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory; import org.jboss.as.clustering.controller.RuntimeResourceRegistration; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jgroups.Global; import org.jgroups.PhysicalAddress; import org.jgroups.stack.IpAddress; import org.jgroups.stack.Protocol; /** * Registers protocol resource definitions, including any overrides. * @author Paul Ferraro */ public class ProtocolResourceRegistrar implements ManagementRegistrar<ManagementResourceRegistration> { enum AuthProtocol { AUTH; } enum EncryptProtocol { ASYM_ENCRYPT(KeyStore.PrivateKeyEntry.class), SYM_ENCRYPT(KeyStore.SecretKeyEntry.class), ; final Class<? extends KeyStore.Entry> entryClass; EncryptProtocol(Class<? extends KeyStore.Entry> entryClass) { this.entryClass = entryClass; } } enum InitialHostsProtocol { TCPGOSSIP(InetSocketAddress.class, Function.identity()), TCPPING(PhysicalAddress.class, address -> new IpAddress(address.getAddress(), address.getPort())), ; final Function<InetSocketAddress, ?> hostTransformer; <A> InitialHostsProtocol(Class<A> hostClass, Function<InetSocketAddress, A> hostTransformer) { this.hostTransformer = hostTransformer; } } enum JdbcProtocol { JDBC_PING; } enum MulticastProtocol { MPING; } enum SocketProtocol { FD_SOCK(LegacyFailureDetectionProtocolConfigurationServiceConfigurator::new), FD_SOCK2(FailureDetectionProtocolConfigurationServiceConfigurator::new), ; private final ResourceServiceConfiguratorFactory factory; SocketProtocol(ResourceServiceConfiguratorFactory factory) { this.factory = factory; } ResourceServiceConfiguratorFactory getResourceServiceConfiguratorFactory() { return this.factory; } } enum LegacyProtocol { ; final String name; final String targetName; final JGroupsSubsystemModel deprecation; LegacyProtocol(Class<? extends Protocol> targetProtocol, JGroupsSubsystemModel deprecation) { this(null, targetProtocol, deprecation); } LegacyProtocol(String name, Class<? extends Protocol> targetProtocol, JGroupsSubsystemModel deprecation) { this.name = (name != null) ? name : this.name(); this.targetName = targetProtocol.getName().substring(Global.PREFIX.length()); this.deprecation = deprecation; } } private static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> { private final RuntimeResourceRegistration runtimeResourceRegistration; ResourceDescriptorConfigurator(RuntimeResourceRegistration runtimeResourceRegistration) { this.runtimeResourceRegistration = runtimeResourceRegistration; } @Override public ResourceDescriptor apply(ResourceDescriptor descriptor) { return descriptor.addRuntimeResourceRegistration(this.runtimeResourceRegistration); } } private final ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory; private final UnaryOperator<ResourceDescriptor> configurator; ProtocolResourceRegistrar(ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) { this.parentServiceConfiguratorFactory = parentServiceConfiguratorFactory; this.configurator = UnaryOperator.identity(); } ProtocolResourceRegistrar(ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory, RuntimeResourceRegistration runtimeResourceRegistration) { this.parentServiceConfiguratorFactory = parentServiceConfiguratorFactory; this.configurator = new ResourceDescriptorConfigurator(runtimeResourceRegistration); } @Override public void register(ManagementResourceRegistration registration) { new GenericProtocolResourceDefinition(this.configurator, this.parentServiceConfiguratorFactory).register(registration); // Override definitions for protocol types for (SocketProtocol protocol : EnumSet.allOf(SocketProtocol.class)) { new SocketProtocolResourceDefinition(protocol.name(), this.configurator, protocol.getResourceServiceConfiguratorFactory(), this.parentServiceConfiguratorFactory).register(registration); } for (MulticastProtocol protocol : EnumSet.allOf(MulticastProtocol.class)) { new MulticastProtocolResourceDefinition(protocol.name(), this.configurator, this.parentServiceConfiguratorFactory).register(registration); } for (JdbcProtocol protocol : EnumSet.allOf(JdbcProtocol.class)) { new JDBCProtocolResourceDefinition(protocol.name(), this.configurator, this.parentServiceConfiguratorFactory).register(registration); // Add deprecated override definition for legacy variant new GenericProtocolResourceDefinition(protocol.name(), JGroupsSubsystemModel.VERSION_5_0_0, this.configurator, this.parentServiceConfiguratorFactory).register(registration); } for (EncryptProtocol protocol : EnumSet.allOf(EncryptProtocol.class)) { new EncryptProtocolResourceDefinition<>(protocol.name(), protocol.entryClass, this.configurator, this.parentServiceConfiguratorFactory).register(registration); // Add deprecated override definition for legacy variant new GenericProtocolResourceDefinition(protocol.name(), JGroupsSubsystemModel.VERSION_5_0_0, this.configurator, this.parentServiceConfiguratorFactory).register(registration); } for (InitialHostsProtocol protocol : EnumSet.allOf(InitialHostsProtocol.class)) { new SocketDiscoveryProtocolResourceDefinition<>(protocol.name(), protocol.hostTransformer, this.configurator, this.parentServiceConfiguratorFactory).register(registration); // Add deprecated override definition for legacy variant new GenericProtocolResourceDefinition(protocol.name(), JGroupsSubsystemModel.VERSION_5_0_0, this.configurator, this.parentServiceConfiguratorFactory).register(registration); } for (AuthProtocol protocol : EnumSet.allOf(AuthProtocol.class)) { new AuthProtocolResourceDefinition(protocol.name(), this.configurator, this.parentServiceConfiguratorFactory).register(registration); // Add deprecated override definition for legacy variant new GenericProtocolResourceDefinition(protocol.name(), JGroupsSubsystemModel.VERSION_5_0_0, this.configurator, this.parentServiceConfiguratorFactory).register(registration); } if (registration.getProcessType().isServer()) { // only auto-update legacy protocols in server processes for (LegacyProtocol protocol : EnumSet.allOf(LegacyProtocol.class)) { new LegacyProtocolResourceDefinition(protocol.name, protocol.targetName, protocol.deprecation, this.configurator, this.parentServiceConfiguratorFactory).register(registration); } } } }
8,578
46.137363
197
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemServiceHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import static org.jboss.as.clustering.jgroups.logging.JGroupsLogger.ROOT_LOGGER; import static org.jboss.as.clustering.jgroups.subsystem.JGroupsSubsystemResourceDefinition.CAPABILITIES; import static org.jboss.as.clustering.jgroups.subsystem.JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL; import java.util.Map; import org.jboss.as.clustering.controller.Capability; import org.jboss.as.clustering.controller.ResourceServiceHandler; import org.jboss.as.clustering.naming.BinderServiceConfigurator; import org.jboss.as.clustering.naming.JndiNameFactory; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceTarget; import org.jgroups.Version; import org.wildfly.clustering.jgroups.spi.JGroupsRequirement; import org.wildfly.clustering.server.service.ProvidedIdentityGroupServiceConfigurator; import org.wildfly.clustering.service.IdentityServiceConfigurator; /** * @author Paul Ferraro */ public class JGroupsSubsystemServiceHandler implements ResourceServiceHandler { @Override public void installServices(OperationContext context, ModelNode model) throws OperationFailedException { ROOT_LOGGER.activatingSubsystem(Version.printVersion()); ServiceTarget target = context.getServiceTarget(); PathAddress address = context.getCurrentAddress(); // Handle case where JGroups subsystem is added to a running server // In this case, the Infinispan subsystem may have already registered default group capabilities if (context.getProcessType().isServer() && !context.isBooting()) { if (context.readResourceFromRoot(address.getParent(),false).hasChild(PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "infinispan"))) { // Following restart, default group services will be installed by this handler, rather than the infinispan subsystem handler context.addStep((ctx, operation) -> { ctx.reloadRequired(); ctx.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER); }, OperationContext.Stage.RUNTIME); return; } } new ProtocolDefaultsServiceConfigurator().build(target).install(); String defaultChannel = DEFAULT_CHANNEL.resolveModelAttribute(context, model).asStringOrNull(); if (defaultChannel != null) { for (Map.Entry<JGroupsRequirement, Capability> entry : CAPABILITIES.entrySet()) { new IdentityServiceConfigurator<>(entry.getValue().getServiceName(address), entry.getKey().getServiceName(context, defaultChannel)).build(target).install(); } if (!defaultChannel.equals(JndiNameFactory.DEFAULT_LOCAL_NAME)) { new BinderServiceConfigurator(JGroupsBindingFactory.createChannelBinding(JndiNameFactory.DEFAULT_LOCAL_NAME), JGroupsRequirement.CHANNEL.getServiceName(context, defaultChannel)).build(target).install(); new BinderServiceConfigurator(JGroupsBindingFactory.createChannelFactoryBinding(JndiNameFactory.DEFAULT_LOCAL_NAME), JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, defaultChannel)).build(target).install(); } new ProvidedIdentityGroupServiceConfigurator(null, defaultChannel).configure(context).build(target).install(); } } @Override public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); String defaultChannel = DEFAULT_CHANNEL.resolveModelAttribute(context, model).asStringOrNull(); if (defaultChannel != null) { new ProvidedIdentityGroupServiceConfigurator(null, defaultChannel).remove(context); if (!defaultChannel.equals(JndiNameFactory.DEFAULT_LOCAL_NAME)) { context.removeService(JGroupsBindingFactory.createChannelFactoryBinding(JndiNameFactory.DEFAULT_LOCAL_NAME).getBinderServiceName()); context.removeService(JGroupsBindingFactory.createChannelBinding(JndiNameFactory.DEFAULT_LOCAL_NAME).getBinderServiceName()); } for (Capability capability : CAPABILITIES.values()) { context.removeService(capability.getServiceName(address)); } } context.removeService(ProtocolDefaultsServiceConfigurator.SERVICE_NAME); } }
5,762
51.87156
233
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsSubsystemXMLWriter.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import java.util.Collection; import java.util.EnumSet; import java.util.stream.Stream; import javax.xml.stream.XMLStreamException; import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.dmr.Property; import org.jboss.staxmapper.XMLElementWriter; import org.jboss.staxmapper.XMLExtendedStreamWriter; /** * @author Paul Ferraro * @author Richard Achmatowicz (c) 2011 Red Hat Inc. * @author Tristan Tarrant */ public class JGroupsSubsystemXMLWriter implements XMLElementWriter<SubsystemMarshallingContext> { @Override public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { context.startSubsystemElement(JGroupsSubsystemSchema.CURRENT.getNamespace().getUri(), false); ModelNode model = context.getModelNode(); if (model.isDefined()) { if (model.hasDefined(ChannelResourceDefinition.WILDCARD_PATH.getKey())) { writer.writeStartElement(XMLElement.CHANNELS.getLocalName()); writeAttribute(writer, model, JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL); for (Property property: model.get(ChannelResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) { writer.writeStartElement(XMLElement.CHANNEL.getLocalName()); writer.writeAttribute(XMLAttribute.NAME.getLocalName(), property.getName()); ModelNode channel = property.getValue(); writeAttributes(writer, channel, ChannelResourceDefinition.Attribute.class); if (channel.hasDefined(ForkResourceDefinition.WILDCARD_PATH.getKey())) { for (Property forkProperty: channel.get(ForkResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) { writer.writeStartElement(XMLElement.FORK.getLocalName()); writer.writeAttribute(XMLAttribute.NAME.getLocalName(), forkProperty.getName()); ModelNode fork = forkProperty.getValue(); if (fork.hasDefined(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) { for (Property protocol: fork.get(ProtocolResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) { writeProtocol(writer, protocol); } } writer.writeEndElement(); } } writer.writeEndElement(); } writer.writeEndElement(); } if (model.hasDefined(StackResourceDefinition.WILDCARD_PATH.getKey())) { writer.writeStartElement(XMLElement.STACKS.getLocalName()); for (Property property: model.get(StackResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) { writer.writeStartElement(XMLElement.STACK.getLocalName()); writer.writeAttribute(XMLAttribute.NAME.getLocalName(), property.getName()); ModelNode stack = property.getValue(); writeAttributes(writer, stack, StackResourceDefinition.Attribute.class); if (stack.hasDefined(TransportResourceDefinition.WILDCARD_PATH.getKey())) { writeTransport(writer, stack.get(TransportResourceDefinition.WILDCARD_PATH.getKey()).asProperty()); } if (stack.hasDefined(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) { for (Property protocol: stack.get(ProtocolResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) { writeProtocol(writer, protocol); } } if (stack.get(RelayResourceDefinition.PATH.getKeyValuePair()).isDefined()) { writeRelay(writer, stack.get(RelayResourceDefinition.PATH.getKeyValuePair())); } writer.writeEndElement(); } writer.writeEndElement(); } } writer.writeEndElement(); } private static void writeTransport(XMLExtendedStreamWriter writer, Property property) throws XMLStreamException { writer.writeStartElement(XMLElement.TRANSPORT.getLocalName()); writeGenericProtocolAttributes(writer, property); ModelNode transport = property.getValue(); writeAttributes(writer, transport, TransportResourceDefinition.Attribute.class); if (containsName(TransportResourceRegistrar.SocketTransport.class, property.getName())) { writeAttributes(writer, property.getValue(), SocketTransportResourceDefinition.Attribute.class); } writeElement(writer, transport, AbstractProtocolResourceDefinition.Attribute.PROPERTIES); writeThreadPoolElements(XMLElement.DEFAULT_THREAD_POOL, ThreadPoolResourceDefinition.DEFAULT, writer, transport); writer.writeEndElement(); } private static void writeProtocol(XMLExtendedStreamWriter writer, Property property) throws XMLStreamException { writer.writeStartElement(XMLElement.forProtocolName(property).getLocalName()); writeProtocolAttributes(writer, property); writeElement(writer, property.getValue(), AbstractProtocolResourceDefinition.Attribute.PROPERTIES); writer.writeEndElement(); } private static void writeGenericProtocolAttributes(XMLExtendedStreamWriter writer, Property property) throws XMLStreamException { writer.writeAttribute(XMLAttribute.TYPE.getLocalName(), property.getName()); writeAttributes(writer, property.getValue(), EnumSet.complementOf(EnumSet.of(AbstractProtocolResourceDefinition.Attribute.PROPERTIES))); } private static void writeProtocolAttributes(XMLExtendedStreamWriter writer, Property property) throws XMLStreamException { writeGenericProtocolAttributes(writer, property); String protocol = property.getName(); if (containsName(ProtocolResourceRegistrar.MulticastProtocol.class, protocol)) { writeAttributes(writer, property.getValue(), MulticastProtocolResourceDefinition.Attribute.class); } else if (containsName(ProtocolResourceRegistrar.SocketProtocol.class, protocol)) { writeAttributes(writer, property.getValue(), SocketProtocolResourceDefinition.Attribute.class); } else if (containsName(ProtocolResourceRegistrar.JdbcProtocol.class, protocol)) { writeAttributes(writer, property.getValue(), JDBCProtocolResourceDefinition.Attribute.class); } else if (containsName(ProtocolResourceRegistrar.EncryptProtocol.class, protocol)) { writeAttributes(writer, property.getValue(), EncryptProtocolResourceDefinition.Attribute.class); } else if (containsName(ProtocolResourceRegistrar.InitialHostsProtocol.class, protocol)) { writeAttributes(writer, property.getValue(), SocketDiscoveryProtocolResourceDefinition.Attribute.class); } else if (containsName(ProtocolResourceRegistrar.AuthProtocol.class, protocol)) { writeAuthToken(writer, property.getValue().get(AuthTokenResourceDefinition.WILDCARD_PATH.getKey()).asProperty()); } } private static <E extends Enum<E>> boolean containsName(Class<E> enumClass, String name) { for (E protocol : EnumSet.allOf(enumClass)) { if (name.equals(protocol.name())) { return true; } } return false; } private static void writeAuthToken(XMLExtendedStreamWriter writer, Property token) throws XMLStreamException { writer.writeStartElement(XMLElement.forAuthTokenName(token.getName()).getLocalName()); if (PlainAuthTokenResourceDefinition.PATH.getValue().equals(token.getName())) { writeAttributes(writer, token.getValue(), AuthTokenResourceDefinition.Attribute.class); } if (DigestAuthTokenResourceDefinition.PATH.getValue().equals(token.getName())) { writeAttributes(writer, token.getValue(), Stream.concat(EnumSet.allOf(AuthTokenResourceDefinition.Attribute.class).stream(), EnumSet.allOf(DigestAuthTokenResourceDefinition.Attribute.class).stream())); } if (CipherAuthTokenResourceDefinition.PATH.getValue().equals(token.getName())) { writeAttributes(writer, token.getValue(), Stream.concat(EnumSet.allOf(AuthTokenResourceDefinition.Attribute.class).stream(), EnumSet.allOf(CipherAuthTokenResourceDefinition.Attribute.class).stream())); } writer.writeEndElement(); } private static void writeThreadPoolElements(XMLElement element, ThreadPoolResourceDefinition pool, XMLExtendedStreamWriter writer, ModelNode transport) throws XMLStreamException { PathElement path = pool.getPathElement(); if (transport.get(path.getKey()).hasDefined(path.getValue())) { ModelNode threadPool = transport.get(path.getKeyValuePair()); if (hasDefined(threadPool, pool.getAttributes())) { writer.writeStartElement(element.getLocalName()); writeAttributes(writer, threadPool, pool.getAttributes()); writer.writeEndElement(); } } } private static void writeRelay(XMLExtendedStreamWriter writer, ModelNode relay) throws XMLStreamException { writer.writeStartElement(XMLElement.RELAY.getLocalName()); writeAttributes(writer, relay, RelayResourceDefinition.Attribute.class); if (relay.hasDefined(RemoteSiteResourceDefinition.WILDCARD_PATH.getKey())) { for (Property property: relay.get(RemoteSiteResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) { writer.writeStartElement(XMLElement.REMOTE_SITE.getLocalName()); writer.writeAttribute(XMLAttribute.NAME.getLocalName(), property.getName()); writeAttributes(writer, property.getValue(), EnumSet.allOf(RemoteSiteResourceDefinition.Attribute.class)); writer.writeEndElement(); } } writer.writeEndElement(); } private static boolean hasDefined(ModelNode model, Collection<? extends Attribute> attributes) { for (Attribute attribute : attributes) { if (model.hasDefined(attribute.getName())) return true; } return false; } private static <A extends Enum<A> & Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Class<A> attributeClass) throws XMLStreamException { writeAttributes(writer, model, EnumSet.allOf(attributeClass)); } private static void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Collection<? extends Attribute> attributes) throws XMLStreamException { writeAttributes(writer, model, attributes.stream()); } private static <A extends Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Stream<A> stream) throws XMLStreamException { // Write attributes before elements Stream.Builder<Attribute> objectAttributes = Stream.builder(); Iterable<A> attributes = stream::iterator; for (Attribute attribute : attributes) { if (attribute.getDefinition().getType() == ModelType.OBJECT) { objectAttributes.add(attribute); } else { writeAttribute(writer, model, attribute); } } Iterable<Attribute> elementAttributes = objectAttributes.build()::iterator; for (Attribute attribute : elementAttributes) { writeElement(writer, model, attribute); } } private static void writeAttribute(XMLExtendedStreamWriter writer, ModelNode model, Attribute attribute) throws XMLStreamException { attribute.getDefinition().getMarshaller().marshallAsAttribute(attribute.getDefinition(), model, true, writer); } private static void writeElement(XMLExtendedStreamWriter writer, ModelNode model, Attribute attribute) throws XMLStreamException { attribute.getDefinition().getMarshaller().marshallAsElement(attribute.getDefinition(), model, true, writer); } }
13,570
55.545833
213
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/RelayResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory; import org.jboss.as.clustering.controller.SimpleResourceDescriptorConfigurator; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelType; import org.wildfly.clustering.jgroups.spi.RelayConfiguration; /** * Resource definition for /subsystem=jgroups/stack=X/relay=RELAY * * @author Paul Ferraro */ public class RelayResourceDefinition extends AbstractProtocolResourceDefinition { static final PathElement PATH = pathElement(RelayConfiguration.PROTOCOL_NAME); static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE); public static PathElement pathElement(String name) { return PathElement.pathElement("relay", name); } enum Attribute implements org.jboss.as.clustering.controller.Attribute { SITE("site", ModelType.STRING), ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = new SimpleAttributeDefinitionBuilder(name, type) .setAllowExpression(true) .setRequired(true) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) .build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } private final ResourceServiceConfiguratorFactory serviceConfiguratorFactory; RelayResourceDefinition(ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) { this(RelayConfigurationServiceConfigurator::new, parentServiceConfiguratorFactory); } private RelayResourceDefinition(ResourceServiceConfiguratorFactory serviceConfiguratorFactory, ResourceServiceConfiguratorFactory parentServiceConfiguratorFactory) { super(new Parameters(PATH, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH, ProtocolResourceDefinition.WILDCARD_PATH)), new SimpleResourceDescriptorConfigurator<>(Attribute.class), serviceConfiguratorFactory, parentServiceConfiguratorFactory); this.serviceConfiguratorFactory = serviceConfiguratorFactory; } @Override public ManagementResourceRegistration register(ManagementResourceRegistration parent) { ManagementResourceRegistration registration = super.register(parent); new RemoteSiteResourceDefinition(this.serviceConfiguratorFactory).register(registration); return registration; } }
3,851
43.275862
273
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ChannelResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import java.util.EnumSet; import java.util.function.UnaryOperator; import java.util.stream.Collectors; import org.jboss.as.clustering.controller.CapabilityProvider; import org.jboss.as.clustering.controller.CapabilityReference; import org.jboss.as.clustering.controller.ChildResourceDefinition; import org.jboss.as.clustering.controller.ManagementResourceRegistration; import org.jboss.as.clustering.controller.MetricHandler; import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.ResourceServiceHandler; import org.jboss.as.clustering.controller.ServiceValueExecutorRegistry; import org.jboss.as.clustering.controller.SimpleResourceRegistrar; import org.jboss.as.clustering.controller.UnaryRequirementCapability; import org.jboss.as.clustering.controller.validation.ModuleIdentifierValidatorBuilder; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jgroups.JChannel; import org.wildfly.clustering.jgroups.spi.JGroupsRequirement; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.service.UnaryRequirement; /** * Definition for /subsystem=jgroups/channel=* resources * * @author Paul Ferraro */ public class ChannelResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> { public static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE); public static PathElement pathElement(String name) { return PathElement.pathElement("channel", name); } enum Capability implements CapabilityProvider { JCHANNEL(JGroupsRequirement.CHANNEL), FORK_CHANNEL_FACTORY(JGroupsRequirement.CHANNEL_FACTORY), JCHANNEL_FACTORY(JGroupsRequirement.CHANNEL_SOURCE), JCHANNEL_MODULE(JGroupsRequirement.CHANNEL_MODULE), JCHANNEL_CLUSTER(JGroupsRequirement.CHANNEL_CLUSTER), ; private org.jboss.as.clustering.controller.Capability capability; Capability(UnaryRequirement requirement) { this.capability = new UnaryRequirementCapability(requirement); } @Override public org.jboss.as.clustering.controller.Capability getCapability() { return this.capability; } } public enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> { STACK("stack", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setRequired(true) .setAllowExpression(false) .setCapabilityReference(new CapabilityReference(Capability.JCHANNEL_FACTORY, JGroupsRequirement.CHANNEL_FACTORY)) ; } }, MODULE(ModelDescriptionConstants.MODULE, ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setDefaultValue(new ModelNode("org.wildfly.clustering.server")) .setValidator(new ModuleIdentifierValidatorBuilder().configure(builder).build()) ; } }, CLUSTER("cluster", ModelType.STRING), STATISTICS_ENABLED(ModelDescriptionConstants.STATISTICS_ENABLED, ModelType.BOOLEAN) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setDefaultValue(ModelNode.FALSE); } }, ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type) .setAllowExpression(true) .setRequired(false) .setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) ).build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder; } } ChannelResourceDefinition() { super(WILDCARD_PATH, JGroupsExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH)); } @Override public ManagementResourceRegistration register(ManagementResourceRegistration parent) { ManagementResourceRegistration registration = parent.registerSubModel(this); ServiceValueExecutorRegistry<JChannel> executors = new ServiceValueExecutorRegistry<>(); ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()) .addAttributes(Attribute.class) .addCapabilities(Capability.class) .addCapabilities(EnumSet.allOf(ClusteringRequirement.class).stream().map(UnaryRequirementCapability::new).collect(Collectors.toList())) .addRuntimeResourceRegistration(new ChannelRuntimeResourceRegistration(executors)) .setAddOperationTransformation(DefaultStackOperationStepHandler::new) ; ResourceServiceHandler handler = new ChannelServiceHandler(executors); new SimpleResourceRegistrar(descriptor, handler).register(registration); if (registration.isRuntimeOnlyRegistrationValid()) { new MetricHandler<>(new ChannelMetricExecutor(executors), ChannelMetric.class).register(registration); } new ForkResourceDefinition(executors).register(registration); return registration; } private static class DefaultStackOperationStepHandler implements OperationStepHandler { private final OperationStepHandler handler; DefaultStackOperationStepHandler(OperationStepHandler handler) { this.handler = handler; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // Add operations emitted by legacy Infinispan subsystem may not have a stack specified // In this case, fix operation to use stack of default channel if (!operation.hasDefined(Attribute.STACK.getName())) { PathAddress subsystemAddress = context.getCurrentAddress().getParent(); Resource root = context.readResourceFromRoot(subsystemAddress.getParent(), false); if (!root.hasChild(subsystemAddress.getLastElement())) { // Subsystem not yet added - defer operation execution context.addStep(operation, this, context.getCurrentStage()); return; } Resource subsystem = context.readResourceFromRoot(subsystemAddress, false); ModelNode subsystemModel = subsystem.getModel(); if (subsystemModel.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName())) { String defaultChannel = subsystemModel.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_CHANNEL.getName()).asString(); if (!context.getCurrentAddressValue().equals(defaultChannel)) { PathElement defaultChannelPath = pathElement(defaultChannel); if (!subsystem.hasChild(defaultChannelPath)) { // Default channel was not yet added, defer operation execution context.addStep(operation, this, context.getCurrentStage()); return; } Resource channel = context.readResourceFromRoot(subsystemAddress.append(defaultChannelPath), false); ModelNode channelModel = channel.getModel(); String defaultStack = channelModel.get(Attribute.STACK.getName()).asString(); operation.get(Attribute.STACK.getName()).set(defaultStack); } } } this.handler.execute(context, operation); } } }
9,911
47.588235
151
java
null
wildfly-main/clustering/jgroups/extension/src/main/java/org/jboss/as/clustering/jgroups/subsystem/ProtocolServiceNameProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.jgroups.subsystem; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.ServiceNameProvider; /** * @author Paul Ferraro */ public class ProtocolServiceNameProvider implements ServiceNameProvider { private final ServiceName name; public ProtocolServiceNameProvider(PathAddress address) { this(address.getParent(), address.getLastElement()); } public ProtocolServiceNameProvider(PathAddress stackAddress, PathElement path) { this.name = StackResourceDefinition.Capability.JCHANNEL_FACTORY.getServiceName(stackAddress).append(path.getValue()); } @Override public ServiceName getServiceName() { return this.name; } }
1,848
35.98
125
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/RemoteSiteConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; /** * Configuration of a channel to a remote site, used by the RELAY2 protocol. * @author Paul Ferraro */ public interface RemoteSiteConfiguration { String getName(); ChannelFactory getChannelFactory(); String getClusterName(); }
1,315
36.6
76
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/JGroupsRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; import org.jboss.as.clustering.controller.DefaultableUnaryServiceNameFactoryProvider; import org.jboss.as.clustering.controller.ServiceNameFactory; import org.jboss.as.clustering.controller.UnaryRequirementServiceNameFactory; import org.jboss.as.clustering.controller.UnaryServiceNameFactory; import org.wildfly.clustering.service.DefaultableUnaryRequirement; import org.wildfly.clustering.service.Requirement; /** * @author Paul Ferraro */ public enum JGroupsRequirement implements DefaultableUnaryRequirement, DefaultableUnaryServiceNameFactoryProvider { CHANNEL("org.wildfly.clustering.jgroups.channel", JGroupsDefaultRequirement.CHANNEL), CHANNEL_CLUSTER("org.wildfly.clustering.jgroups.channel-cluster", JGroupsDefaultRequirement.CHANNEL_CLUSTER), CHANNEL_FACTORY("org.wildfly.clustering.jgroups.channel-factory", JGroupsDefaultRequirement.CHANNEL_FACTORY), CHANNEL_MODULE("org.wildfly.clustering.jgroups.channel-module", JGroupsDefaultRequirement.CHANNEL_MODULE), CHANNEL_SOURCE("org.wildfly.clustering.jgroups.channel-source", JGroupsDefaultRequirement.CHANNEL_SOURCE), ; private final String name; private final UnaryServiceNameFactory factory = new UnaryRequirementServiceNameFactory(this); private final JGroupsDefaultRequirement defaultRequirement; JGroupsRequirement(String name, JGroupsDefaultRequirement defaultRequirement) { this.name = name; this.defaultRequirement = defaultRequirement; } @Override public String getName() { return this.name; } @Override public Requirement getDefaultRequirement() { return this.defaultRequirement; } @Override public UnaryServiceNameFactory getServiceNameFactory() { return this.factory; } @Override public ServiceNameFactory getDefaultServiceNameFactory() { return this.defaultRequirement; } }
2,963
40.746479
115
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/ProtocolStackConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; import java.util.List; import java.util.Optional; import org.jboss.as.network.SocketBindingManager; import org.jgroups.protocols.TP; import org.jgroups.stack.Protocol; /** * Defines the configuration of a JGroups protocol stack. * @author Paul Ferraro */ public interface ProtocolStackConfiguration { String getName(); boolean isStatisticsEnabled(); TransportConfiguration<? extends TP> getTransport(); List<ProtocolConfiguration<? extends Protocol>> getProtocols(); String getNodeName(); Optional<RelayConfiguration> getRelay(); SocketBindingManager getSocketBindingManager(); }
1,688
32.117647
70
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/ChannelFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; import org.jgroups.Message; /** * Factory for creating JGroups channels. * @author Paul Ferraro */ public interface ChannelFactory extends org.wildfly.clustering.jgroups.ChannelFactory { /** * Returns the protocol stack configuration of this channel factory. * @return the protocol stack configuration of this channel factory */ ProtocolStackConfiguration getProtocolStackConfiguration(); /** * Determines whether or not the specified message response indicates the fork stack or fork channel * required to handle a request does not exist on the recipient node. * @param response a message response * @return true, if the response indicates a missing fork stack or channel. */ boolean isUnknownForkResponse(Message response); }
1,858
39.413043
104
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/ProtocolConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; import java.util.Map; import org.jboss.as.network.SocketBinding; import org.jgroups.stack.Protocol; /** * Defines the configuration of a JGroups protocol. * @author Paul Ferraro */ public interface ProtocolConfiguration<P extends Protocol> { String getName(); P createProtocol(ProtocolStackConfiguration stackConfiguration); default Map<String, SocketBinding> getSocketBindings() { return Map.of(); } }
1,503
33.976744
70
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/RelayConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2012, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; import java.util.List; import org.jgroups.protocols.relay.RELAY2; /** * Configuration of the RELAY2 protocol. * @author Paul Ferraro */ public interface RelayConfiguration extends ProtocolConfiguration<RELAY2> { String PROTOCOL_NAME = "relay.RELAY2"; String getSiteName(); List<RemoteSiteConfiguration> getRemoteSites(); }
1,410
35.179487
75
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/JGroupsDefaultRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; import org.jboss.as.clustering.controller.RequirementServiceNameFactory; import org.jboss.as.clustering.controller.ServiceNameFactory; import org.jboss.as.clustering.controller.ServiceNameFactoryProvider; import org.jboss.modules.Module; import org.jgroups.JChannel; import org.wildfly.clustering.service.Requirement; /** * @author Paul Ferraro */ public enum JGroupsDefaultRequirement implements Requirement, ServiceNameFactoryProvider { CHANNEL("org.wildfly.clustering.jgroups.default-channel", JChannel.class), CHANNEL_CLUSTER("org.wildfly.clustering.jgroups.default-channel-cluster", String.class), CHANNEL_FACTORY("org.wildfly.clustering.jgroups.default-channel-factory", ChannelFactory.class), CHANNEL_MODULE("org.wildfly.clustering.jgroups.default-channel-module", Module.class), CHANNEL_SOURCE("org.wildfly.clustering.jgroups.default-channel-source", ChannelFactory.class), ; private final String name; private final Class<?> type; private final ServiceNameFactory factory = new RequirementServiceNameFactory(this); JGroupsDefaultRequirement(String name, Class<?> type) { this.name = name; this.type = type; } @Override public String getName() { return this.name; } @Override public Class<?> getType() { return this.type; } @Override public ServiceNameFactory getServiceNameFactory() { return this.factory; } }
2,514
37.692308
100
java
null
wildfly-main/clustering/jgroups/spi/src/main/java/org/wildfly/clustering/jgroups/spi/TransportConfiguration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups.spi; import org.jboss.as.network.SocketBinding; import org.jgroups.protocols.TP; /** * Defines the configuration of a JGroups transport protocol. * @author Paul Ferraro */ public interface TransportConfiguration<T extends TP> extends ProtocolConfiguration<T> { Topology getTopology(); SocketBinding getSocketBinding(); interface Topology { String getMachine(); String getRack(); String getSite(); } }
1,511
34.162791
88
java
null
wildfly-main/clustering/jgroups/api/src/main/java/org/wildfly/clustering/jgroups/ChannelFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.jgroups; import org.jgroups.JChannel; /** * Factory for creating JGroups channels. * @author Paul Ferraro */ public interface ChannelFactory { /** * Creates a JGroups channel * @param id the unique identifier of this channel * @return a JGroups channel * @throws Exception if there was a failure setting up the protocol stack */ JChannel createChannel(String id) throws Exception; }
1,475
36.846154
77
java
null
wildfly-main/clustering/common/src/test/java/org/jboss/as/clustering/controller/PropertiesTestUtil.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.INCLUDE_DEFAULTS; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RECURSIVE; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.controller.transform.OperationTransformer; import org.jboss.as.model.test.ModelTestUtils; import org.jboss.as.subsystem.test.KernelServices; import org.jboss.dmr.ModelNode; import org.junit.Assert; /** * Set of utility methods for testing properties transformations for EAP 6.x versions. * * @author Kabir Khan * @author Radoslav Husar * @version October 2015 */ public class PropertiesTestUtil { private PropertiesTestUtil() { // Hide utility class } public static void checkMapResults(KernelServices services, ModelNode expected, ModelVersion version, ModelNode operation) throws Exception { ModelNode main = ModelTestUtils.checkOutcome(services.executeOperation(operation.clone())).get(ModelDescriptionConstants.RESULT); ModelNode legacyResult = services.executeOperation(version, services.transformOperation(version, operation.clone())); ModelNode legacy; if (expected.isDefined()) { legacy = ModelTestUtils.checkOutcome(legacyResult).get(ModelDescriptionConstants.RESULT); } else { ModelTestUtils.checkFailed(legacyResult); legacy = new ModelNode(); } Assert.assertEquals(main, legacy); Assert.assertEquals(expected, legacy); } public static void checkMainMapModel(ModelNode model, String... properties) { Assert.assertEquals(0, properties.length % 2); ModelNode props = model.get("properties"); Assert.assertEquals(properties.length / 2, props.isDefined() ? props.keys().size() : 0); for (int i = 0; i < properties.length; i += 2) { Assert.assertEquals(properties[i + 1], props.get(properties[i]).asString()); } } public static void checkLegacyChildResourceModel(ModelNode model, String... properties) { Assert.assertEquals(0, properties.length % 2); ModelNode props = model.get("property"); Assert.assertEquals(properties.length / 2, props.isDefined() ? props.keys().size() : 0); for (int i = 0; i < properties.length; i += 2) { ModelNode property = props.get(properties[i]); Assert.assertTrue(property.isDefined()); Assert.assertEquals(1, property.keys().size()); Assert.assertEquals(properties[i + 1], property.get("value").asString()); } } public static void checkMapModels(KernelServices services, ModelVersion version, PathAddress address, String... properties) throws Exception { final ModelNode readResource = Util.createEmptyOperation(READ_RESOURCE_OPERATION, address); readResource.get(RECURSIVE).set(true); readResource.get(INCLUDE_DEFAULTS).set(false); ModelNode mainModel = services.executeForResult(readResource.clone()); checkMainMapModel(mainModel, properties); final ModelNode legacyModel; if (address.getLastElement().getKey().equals("transport")) { //TODO get rid of this once the PathAddress transformer works properly //Temporary workaround readResource.get(OP_ADDR).set(address.subAddress(0, address.size() - 1).append("transport", "TRANSPORT").toModelNode()); legacyModel = services.getLegacyServices(version).executeForResult(readResource); } else { legacyModel = ModelTestUtils.checkResultAndGetContents(services.executeOperation(version, services.transformOperation(version, readResource.clone()))); } checkLegacyChildResourceModel(legacyModel, properties); } public static ModelNode success() { final ModelNode result = new ModelNode(); result.get(OUTCOME).set(SUCCESS); result.get(RESULT); return result; } /** * Executes a given operation asserting that an attachment has been created. Given {@link KernelServices} must have enabled attachment grabber. * * @return {@link ModelNode} result of the transformed operation */ public static ModelNode executeOpInBothControllersWithAttachments(KernelServices services, ModelVersion version, ModelNode operation) throws Exception { OperationTransformer.TransformedOperation op = services.executeInMainAndGetTheTransformedOperation(operation, version); Assert.assertFalse(op.rejectOperation(success())); // System.out.println(operation + "\nbecomes\n" + op.getTransformedOperation()); if (op.getTransformedOperation() != null) { return ModelTestUtils.checkOutcome(services.getLegacyServices(version).executeOperation(op.getTransformedOperation())); } return null; } }
6,556
47.213235
163
java
null
wildfly-main/clustering/common/src/test/java/org/jboss/as/clustering/controller/validation/DoubleRangeValidatorTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller.validation; import static org.junit.Assert.*; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.operations.validation.ParameterValidator; import org.jboss.dmr.ModelNode; import org.junit.Test; /** * @author Paul Ferraro */ public class DoubleRangeValidatorTestCase { @Test public void testFloat() { ParameterValidator validator = new DoubleRangeValidatorBuilder().lowerBound(Float.MIN_VALUE).upperBound(Float.MAX_VALUE).build(); assertFalse(isValid(validator, new ModelNode(Double.MAX_VALUE))); assertFalse(isValid(validator, new ModelNode(Double.MIN_VALUE))); assertTrue(isValid(validator, new ModelNode(Float.MAX_VALUE))); assertTrue(isValid(validator, new ModelNode(Float.MIN_VALUE))); } @Test public void testExclusive() { int lower = 0; ParameterValidator validator = new DoubleRangeValidatorBuilder().lowerBoundExclusive(lower).build(); assertFalse(isValid(validator, ModelNode.ZERO)); assertTrue(isValid(validator, new ModelNode(0.1))); assertTrue(isValid(validator, new ModelNode(Double.MAX_VALUE))); int upper = 1; validator = new DoubleRangeValidatorBuilder().upperBoundExclusive(upper).build(); assertTrue(isValid(validator, new ModelNode(Double.MIN_VALUE))); assertTrue(isValid(validator, new ModelNode(0.99))); assertFalse(isValid(validator, new ModelNode(1))); } static boolean isValid(ParameterValidator validator, ModelNode value) { try { validator.validateParameter("test", value); return true; } catch (OperationFailedException e) { return false; } } }
2,797
38.971429
137
java
null
wildfly-main/clustering/common/src/test/java/org/jboss/as/clustering/subsystem/AdditionalInitialization.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.subsystem; import java.io.Serializable; import java.util.LinkedList; import java.util.List; import java.util.stream.Stream; import org.jboss.as.controller.RunningMode; import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry; import org.jboss.as.controller.extension.ExtensionRegistry; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.wildfly.clustering.service.BinaryRequirement; import org.wildfly.clustering.service.Requirement; import org.wildfly.clustering.service.UnaryRequirement; /** * {@link AdditionalInitialization} extension that simplifies setup of required capabilities. * @author Paul Ferraro */ public class AdditionalInitialization extends org.jboss.as.subsystem.test.AdditionalInitialization implements Serializable { private static final long serialVersionUID = 7496922674294804719L; private final RunningMode mode; private final List<String> requirements = new LinkedList<>(); public AdditionalInitialization() { this(RunningMode.ADMIN_ONLY); } public AdditionalInitialization(RunningMode mode) { this.mode = mode; } @Override protected RunningMode getRunningMode() { return this.mode; } @Override protected void initializeExtraSubystemsAndModel(ExtensionRegistry registry, Resource root, ManagementResourceRegistration registration, RuntimeCapabilityRegistry capabilityRegistry) { registerCapabilities(capabilityRegistry, this.requirements.stream().toArray(String[]::new)); } public AdditionalInitialization require(String requirement) { this.requirements.add(requirement); return this; } public AdditionalInitialization require(Requirement requirement) { this.requirements.add(requirement.getName()); return this; } public AdditionalInitialization require(UnaryRequirement requirement, String... names) { Stream.of(names).forEach(name -> this.requirements.add(requirement.resolve(name))); return this; } public AdditionalInitialization require(BinaryRequirement requirement, String parent, String child) { this.requirements.add(requirement.resolve(parent, child)); return this; } }
3,359
37.62069
187
java
null
wildfly-main/clustering/common/src/test/java/org/jboss/as/clustering/subsystem/RejectedValueConfig.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.subsystem; import java.util.function.Predicate; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.model.test.FailedOperationTransformationConfig.AttributesPathAddressConfig; import org.jboss.dmr.ModelNode; /** * Generic {@link AttributesPathAddressConfig} for a rejected attribute. * @author Paul Ferraro */ public class RejectedValueConfig extends AttributesPathAddressConfig<RejectedValueConfig> { private final Predicate<ModelNode> rejection; private final UnaryOperator<ModelNode> corrector; public RejectedValueConfig(Attribute attribute, Predicate<ModelNode> rejection) { this(attribute, rejection, value -> attribute.getDefinition().getDefaultValue()); } public RejectedValueConfig(Attribute attribute, Predicate<ModelNode> rejection, UnaryOperator<ModelNode> corrector) { super(attribute.getDefinition().getName()); this.rejection = rejection; this.corrector = corrector; } @Override protected boolean isAttributeWritable(String attributeName) { return true; } @Override protected boolean checkValue(String attrName, ModelNode attribute, boolean isGeneratedWriteAttribute) { return this.rejection.test(attribute); } @Override protected ModelNode correctValue(ModelNode toResolve, boolean isGeneratedWriteAttribute) { return this.corrector.apply(toResolve); } }
2,517
37.151515
121
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/function/Functions.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.function; import java.util.function.Function; /** * {@link Function} utility methods. * @author Paul Ferraro */ public class Functions { /** * Returns a function that always returns its input argument. * * @param <T> the input type to the function * @param <R> the output type of the function * @return a function that always returns its input argument * @see {@link Function#identity()} */ public static <R, T extends R> Function<T, R> identity() { return value -> value; } private Functions() { // Hide } }
1,643
32.55102
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/function/Consumers.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.function; import java.util.function.Consumer; import org.jboss.as.clustering.logging.ClusteringLogger; /** * {@link Consumer} utility methods. * @author Paul Ferraro */ public class Consumers { /** * Returns a consumer that closes its input. * @return a consumer that closes its input. */ public static <T extends AutoCloseable> Consumer<T> close() { return value -> { try { value.close(); } catch (Throwable e) { ClusteringLogger.ROOT_LOGGER.failedToClose(e, value); } }; } private Consumers() { // Hide } }
1,700
31.09434
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/msc/InjectedValueDependency.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.msc; import org.jboss.msc.service.ServiceName; import org.jboss.msc.value.InjectedValue; import org.wildfly.clustering.service.ServiceNameProvider; import org.wildfly.clustering.service.ServiceSupplierDependency; /** * Service dependency whose provided value is made available via injection. * @author Paul Ferraro * @deprecated Replaced by {@link ServiceSupplierDependency}. */ @Deprecated(forRemoval = true) public class InjectedValueDependency<T> extends InjectorDependency<T> implements ValueDependency<T> { private final InjectedValue<T> value; public InjectedValueDependency(ServiceNameProvider provider, Class<T> targetClass) { this(provider.getServiceName(), targetClass, new InjectedValue<T>()); } public InjectedValueDependency(ServiceName name, Class<T> targetClass) { this(name, targetClass, new InjectedValue<T>()); } private InjectedValueDependency(ServiceName name, Class<T> targetClass, InjectedValue<T> value) { super(name, targetClass, value); this.value = value; } @Override public T getValue() { return this.value.getValue(); } }
2,197
36.896552
101
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/msc/InjectorDependency.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.msc; import org.jboss.msc.inject.Injector; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.Dependency; import org.wildfly.clustering.service.ServiceNameProvider; import org.wildfly.clustering.service.ServiceSupplierDependency; /** * Service dependency requiring an injector. * @author Paul Ferraro * @deprecated Replaced by {@link ServiceSupplierDependency}. */ @Deprecated(forRemoval = true) public class InjectorDependency<T> implements Dependency { private final ServiceName name; private final Class<T> targetClass; private final Injector<T> injector; public InjectorDependency(ServiceNameProvider provider, Class<T> targetClass, Injector<T> injector) { this(provider.getServiceName(), targetClass, injector); } public InjectorDependency(ServiceName name, Class<T> targetClass, Injector<T> injector) { this.name = name; this.targetClass = targetClass; this.injector = injector; } @Override public <X> ServiceBuilder<X> register(ServiceBuilder<X> builder) { return builder.addDependency(this.name, this.targetClass, this.injector); } }
2,261
38
105
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/msc/ValueDependency.java
/* * JBoss, Home of Professional Open Source. * Copyright 2014, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.msc; import org.jboss.msc.value.Value; import org.wildfly.clustering.service.SupplierDependency; /** * Service dependency that provides a value. * @author Paul Ferraro * @param <T> the dependency type * @deprecated Replaced by {@link SupplierDependency}. */ @Deprecated(forRemoval = true) public interface ValueDependency<T> extends Value<T>, SupplierDependency<T> { @Override default T get() { return this.getValue(); } }
1,506
35.756098
77
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AbstractCapabilityReference.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.CapabilityReferenceRecorder; import org.jboss.as.controller.OperationContext; import org.wildfly.clustering.service.Requirement; /** * Abstract {@link CapabilityReferenceRecorder} containing logic common to attribute and resource capability references * @author Paul Ferraro */ public abstract class AbstractCapabilityReference implements CapabilityReferenceRecorder { private final Capability capability; private final Requirement requirement; protected AbstractCapabilityReference(Capability capability, Requirement requirement) { this.capability = capability; this.requirement = requirement; } @Override public String getBaseDependentName() { return this.capability.getName(); } @Override public String getBaseRequirementName() { return this.requirement.getName(); } protected String getDependentName(OperationContext context) { return this.capability.resolve(context.getCurrentAddress()).getName(); } @Override public int hashCode() { return this.capability.getName().hashCode(); } @Override public boolean equals(Object object) { return (object instanceof AbstractCapabilityReference) ? this.capability.getName().equals(((AbstractCapabilityReference) object).capability.getName()) : false; } }
2,438
35.402985
167
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ServiceValueExecutorRegistry.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.jboss.msc.service.ServiceName; /** * A registry of captured service value executors. * @author Paul Ferraro */ public class ServiceValueExecutorRegistry<T> implements ServiceValueRegistry<T>, FunctionExecutorRegistry<T> { private final Map<ServiceName, ServiceValueExecutor<T>> executors = new ConcurrentHashMap<>(); @Override public ServiceValueCaptor<T> add(ServiceName name) { ServiceValueExecutor<T> executor = new ServiceValueExecutor<>(name); ServiceValueExecutor<T> existing = this.executors.putIfAbsent(name, executor); return (existing != null) ? existing : executor; } @Override public ServiceValueCaptor<T> remove(ServiceName name) { return this.executors.remove(name); } @Override public FunctionExecutor<T> get(ServiceName name) { return this.executors.get(name); } }
2,019
35.727273
110
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ManagementRegistrationContext.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Optional; import org.jboss.as.controller.ProcessType; import org.jboss.as.controller.services.path.PathManager; /** * Context used for conditional registration. * @author Paul Ferraro */ public interface ManagementRegistrationContext { /** * Gets whether it is valid for the extension to register resources, attributes or operations that do not * involve the persistent configuration, but rather only involve runtime services. Extensions should use this * method before registering such "runtime only" resources, attributes or operations. This * method is intended to avoid registering resources, attributes or operations on process types that * can not install runtime services. * * @return whether it is valid to register runtime resources, attributes, or operations. * @see org.jboss.as.controller.ExtensionContext#isRuntimeOnlyRegistrationValid() */ boolean isRuntimeOnlyRegistrationValid(); /** * Returns the optional {@link PathManager} of the process that is only present if the process is a {@link ProcessType#isServer() server}. * * @return an optional PathManager. * @see org.jboss.as.controller.ExtensionContext#getPathManager() */ Optional<PathManager> getPathManager(); }
2,363
41.981818
142
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.wildfly.clustering.service.ServiceConfigurator; /** * Configures a {@link org.jboss.msc.Service} using the model of a resource. * @author Paul Ferraro */ public interface ResourceServiceConfigurator extends ServiceConfigurator { /** * Configures a service using the specified operation context and model. * @param context an operation context, used to resolve capabilities and expressions * @param model the resource model * @return the reference to this configurator * @throws OperationFailedException if there was a failure reading the model or resolving expressions/capabilities */ default ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { return this; } }
1,990
41.361702
118
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/FunctionalCapabilityServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.SimpleServiceNameProvider; /** * Configures a service that provides a value created from a generic factory and mapper. * @author Paul Ferraro * @param <T> the source type of the mapped value provided by the installed service * @param <V> the type of the value provided by the installed service */ public class FunctionalCapabilityServiceConfigurator<T, V> extends SimpleServiceNameProvider implements CapabilityServiceConfigurator { private final Function<T, V> mapper; private final Supplier<T> factory; public FunctionalCapabilityServiceConfigurator(ServiceName name, Function<T, V> mapper, Supplier<T> factory) { super(name); this.mapper = mapper; this.factory = factory; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceName name = this.getServiceName(); ServiceBuilder<?> builder = target.addService(name); Consumer<V> injector = builder.provides(name); return builder.setInstance(new FunctionalService<>(injector, this.mapper, this.factory)); } }
2,475
40.266667
135
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/BinaryRequirementServiceNameFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.BinaryRequirement; /** * Factory for generating a {@link ServiceName} for a {@link BinaryRequirement}. * @author Paul Ferraro */ public class BinaryRequirementServiceNameFactory implements BinaryServiceNameFactory { private final BinaryRequirement requirement; public BinaryRequirementServiceNameFactory(BinaryRequirement requirement) { this.requirement = requirement; } @Override public ServiceName getServiceName(OperationContext context, String parent, String child) { return context.getCapabilityServiceName(this.requirement.getName(), this.requirement.getType(), parent, child); } @Override public ServiceName getServiceName(CapabilityServiceSupport support, String parent, String child) { return support.getCapabilityServiceName(this.requirement.getName(), parent, child); } }
2,118
38.981132
119
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DeploymentChainStep.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Consumer; import org.jboss.as.server.AbstractDeploymentChainStep; import org.jboss.as.server.DeploymentProcessorTarget; /** * Deployment chain step that delegates to a {@link DeploymentProcessorTarget} consumer. * @author Paul Ferraro */ public class DeploymentChainStep extends AbstractDeploymentChainStep { private final Consumer<DeploymentProcessorTarget> deploymentChainContributor; public DeploymentChainStep(Consumer<DeploymentProcessorTarget> deploymentChainContributor) { this.deploymentChainContributor = deploymentChainContributor; } @Override protected void execute(DeploymentProcessorTarget target) { this.deploymentChainContributor.accept(target); } }
1,808
37.489362
96
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/PersistentSubsystemExtension.java
/* * JBoss, Home of Professional Open Source. * Copyright 2023, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Supplier; import org.jboss.as.controller.PersistentResourceXMLDescription; import org.jboss.as.controller.PersistentResourceXMLDescriptionReader; import org.jboss.as.controller.PersistentResourceXMLDescriptionWriter; import org.jboss.as.controller.PersistentSubsystemSchema; import org.jboss.as.controller.SubsystemModel; /** * Generic extension implementation that registers a single subsystem whose XML readers/writer are created from a {@link PersistentResourceXMLDescription}. * @author Paul Ferraro */ public class PersistentSubsystemExtension<S extends Enum<S> & PersistentSubsystemSchema<S>> extends SubsystemExtension<S> { /** * Constructs a new extension using a reader/writer factory. * @param name the subsystem name * @param currentModel the current model * @param registrarFactory a factory for creating the subsystem resource registrar * @param currentSchema the current schema * @param descriptionFactory an XML description factory */ protected PersistentSubsystemExtension(String name, SubsystemModel currentModel, Supplier<ManagementRegistrar<SubsystemRegistration>> registrarFactory, S currentSchema) { // Build xml description for current schema only once this(name, currentModel, registrarFactory, currentSchema, currentSchema.getXMLDescription()); } private PersistentSubsystemExtension(String name, SubsystemModel currentModel, Supplier<ManagementRegistrar<SubsystemRegistration>> registrarFactory, S currentSchema, PersistentResourceXMLDescription currentDescription) { // Reuse current xml description between reader and writer super(name, currentModel, registrarFactory, currentSchema, new PersistentResourceXMLDescriptionWriter(currentDescription), new PersistentResourceXMLDescriptionReader(currentDescription)); } }
2,933
50.473684
225
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DescribedAddStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationStepHandler; /** * A described add operation handler. * @author Paul Ferraro */ public interface DescribedAddStepHandler extends OperationStepHandler, Described<AddStepHandlerDescriptor> { }
1,305
37.411765
108
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CapabilityServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.wildfly.clustering.service.ServiceConfigurator; /** * @author Paul Ferraro */ public interface CapabilityServiceConfigurator extends ServiceConfigurator { default ServiceConfigurator configure(CapabilityServiceSupport support) { return this; } default ServiceConfigurator configure(OperationContext context) { return this.configure(context.getCapabilityServiceSupport()); } }
1,610
37.357143
77
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RemoveStepHandlerDescriptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Collection; import java.util.Collections; import java.util.Set; import java.util.function.UnaryOperator; import org.jboss.as.controller.CapabilityReferenceRecorder; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; /** * Describes the common properties of a remove operation handler. * @author Paul Ferraro */ @FunctionalInterface public interface RemoveStepHandlerDescriptor extends OperationStepHandlerDescriptor { /** * The description resolver for the operation. * @return a description resolver */ ResourceDescriptionResolver getDescriptionResolver(); /** * Returns a collection of handlers that register runtime resources * Runtime resource registrations are executed in a separate MODEL stage step. * @return a collection of operation step handlers */ default Collection<RuntimeResourceRegistration> getRuntimeResourceRegistrations() { return Collections.emptyList(); } /** * Returns a mapping of capability references to an ancestor resource. * @return a tuple of capability references and requirement resolvers. */ default Set<CapabilityReferenceRecorder> getResourceCapabilityReferences() { return Collections.emptySet(); } /** * Returns a transformer to be applied to all operations that operate on an existing resource. * This is typically used to adapt legacy operations to conform to the current version of the model. * @return an operation handler transformer. */ default UnaryOperator<OperationStepHandler> getOperationTransformation() { return UnaryOperator.identity(); } }
2,798
38.422535
104
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ContextualSubsystemRegistration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Optional; import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.services.path.PathManager; /** * @author Paul Ferraro */ public class ContextualSubsystemRegistration extends DecoratingSubsystemRegistration<ManagementResourceRegistration> implements SubsystemRegistration { private final ManagementRegistrationContext context; public ContextualSubsystemRegistration(org.jboss.as.controller.SubsystemRegistration registration, ExtensionContext context) { this(registration, new ExtensionRegistrationContext(context)); } public ContextualSubsystemRegistration(org.jboss.as.controller.SubsystemRegistration registration, ManagementRegistrationContext context) { super(registration, r -> new ContextualResourceRegistration(r, context)); this.context = context; } @Override public boolean isRuntimeOnlyRegistrationValid() { return this.context.isRuntimeOnlyRegistrationValid(); } @Override public Optional<PathManager> getPathManager() { return this.context.getPathManager(); } }
2,179
37.928571
151
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleResourceRegistrar.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; /** * Registers a {@link AddStepHandler}, {@link RemoveStepHandler}, and {@link WriteAttributeStepHandler} on behalf of a resource definition. * @author Paul Ferraro */ public class SimpleResourceRegistrar extends ResourceRegistrar { public SimpleResourceRegistrar(ResourceDescriptor descriptor, ResourceServiceHandler handler) { super(descriptor, new AddStepHandler(descriptor, handler), new RemoveStepHandler(descriptor, handler), new WriteAttributeStepHandler(descriptor, handler)); } }
1,579
44.142857
163
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ServiceValueExecutor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.msc.service.ServiceName; import org.wildfly.common.function.ExceptionFunction; /** * Executes a given function against the captured value of a service. * @author Paul Ferraro */ public class ServiceValueExecutor<T> implements ServiceValueCaptor<T>, FunctionExecutor<T> { private final ServiceName name; private T value = null; public ServiceValueExecutor(ServiceName name) { this.name = name; } @Override public ServiceName getServiceName() { return this.name; } @Override public synchronized void accept(T value) { this.value = value; } @Override public synchronized <R, E extends Exception> R execute(ExceptionFunction<T, R, E> function) throws E { return (this.value != null) ? function.apply(this.value) : null; } }
1,900
32.350877
106
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DefaultableBinaryServiceNameFactoryProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; /** * Provides a factory for generating a {@link ServiceName} for a binary requirement * as well as a factory generating a {@link ServiceName} for a unary requirement. * @author Paul Ferraro */ public interface DefaultableBinaryServiceNameFactoryProvider extends BinaryServiceNameFactoryProvider { /** * The factory from which to generate a {@link ServiceName} if the requested name is null. * @return a factory for generating service names */ UnaryServiceNameFactory getDefaultServiceNameFactory(); @Override default ServiceName getServiceName(OperationContext context, String parent, String child) { return (child != null) ? this.getServiceNameFactory().getServiceName(context, parent, child) : this.getDefaultServiceNameFactory().getServiceName(context, parent); } @Override default ServiceName getServiceName(CapabilityServiceSupport support, String parent, String child) { return (child != null) ? this.getServiceNameFactory().getServiceName(support, parent, child) : this.getDefaultServiceNameFactory().getServiceName(support, parent); } }
2,345
44.115385
171
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DecoratingResourceRegistration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Function; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.descriptions.OverrideDescriptionProvider; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Generic {@link ManagementResourceRegistration} decorator. * @author Paul Ferraro */ public class DecoratingResourceRegistration<R extends ManagementResourceRegistration> extends org.jboss.as.controller.registry.DelegatingManagementResourceRegistration { private final Function<ManagementResourceRegistration, R> decorator; public DecoratingResourceRegistration(ManagementResourceRegistration delegate, Function<ManagementResourceRegistration, R> decorator) { super(delegate); this.decorator = decorator; } @Override public R registerSubModel(ResourceDefinition definition) { return this.decorator.apply(super.registerSubModel(definition)); } @Override public R registerOverrideModel(String name, OverrideDescriptionProvider descriptionProvider) { return this.decorator.apply(super.registerOverrideModel(name, descriptionProvider)); } }
2,220
40.12963
169
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AttributeTranslation.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.UnaryOperator; import org.jboss.as.controller.PathAddress; /** * Defines an attribute translation. * @author Paul Ferraro */ @FunctionalInterface public interface AttributeTranslation { // The translator used by an attribute alias AttributeValueTranslator IDENTITY_TRANSLATOR = (context, value) -> value; UnaryOperator<PathAddress> IDENTITY_ADDRESS_TRANSFORMATION = UnaryOperator.identity(); Attribute getTargetAttribute(); default AttributeValueTranslator getReadTranslator() { return IDENTITY_TRANSLATOR; } default AttributeValueTranslator getWriteTranslator() { return IDENTITY_TRANSLATOR; } default UnaryOperator<PathAddress> getPathAddressTransformation() { return IDENTITY_ADDRESS_TRANSFORMATION; } }
1,875
34.396226
90
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleChildResourceProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Set; import java.util.function.Supplier; import org.jboss.as.controller.registry.PlaceholderResource; import org.jboss.as.controller.registry.Resource; import org.wildfly.common.function.Functions; /** * A simple {@link ChildResourceProvider} containing a predefined set of children. * @author Paul Ferraro */ public class SimpleChildResourceProvider implements ChildResourceProvider { private final Set<String> children; private final Supplier<Resource> provider; public SimpleChildResourceProvider(Set<String> children) { this(children, Functions.constantSupplier(PlaceholderResource.INSTANCE)); } public SimpleChildResourceProvider(Set<String> children, Supplier<Resource> provider) { this.children = children; this.provider = provider; } @Override public Resource getChild(String name) { return this.children.contains(name) ? this.provider.get() : null; } @Override public Set<String> getChildren() { return this.children; } }
2,115
34.266667
91
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CompositeServiceBuilder.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Consumer; import java.util.function.Supplier; import org.jboss.msc.Service; import org.jboss.msc.service.DelegatingServiceBuilder; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; /** * A {@link ServiceBuilder} facade for installing a set of {@link ServiceBuilder} instances. * @author Paul Ferraro */ public class CompositeServiceBuilder<T> extends DelegatingServiceBuilder<T> { private final Iterable<ServiceBuilder<?>> builders; public CompositeServiceBuilder(Iterable<ServiceBuilder<?>> builders) { super(null); this.builders = builders; } @Override public ServiceBuilder<T> setInitialMode(ServiceController.Mode mode) { for (ServiceBuilder<?> builder : this.builders) { builder.setInitialMode(mode); } return this; } @Override public ServiceBuilder<T> addListener(LifecycleListener listener) { for (ServiceBuilder<?> builder : this.builders) { builder.addListener(listener); } return this; } @Override public ServiceController<T> install() { for (ServiceBuilder<?> builder : this.builders) { builder.install(); } return null; } @Override public <V> Supplier<V> requires(ServiceName name) { throw new UnsupportedOperationException(); } @Override public <V> Consumer<V> provides(ServiceName... names) { throw new UnsupportedOperationException(); } @Override public ServiceBuilder<T> setInstance(Service service) { throw new UnsupportedOperationException(); } }
2,838
31.632184
92
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Executable.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Generic interface for some object capable of execution. * @author Paul Ferraro * @param <C> the execution context */ public interface Executable<C> { /** * Execute against the specified context. * @param context an execution context * @return the execution result (possibly null). */ ModelNode execute(C context) throws OperationFailedException; }
1,545
36.707317
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SubsystemRegistration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.ResourceDefinition; /** * Enhanced {@link org.jboss.as.controller.SubsystemRegistration} that also exposes the registration context. * @author Paul Ferraro */ public interface SubsystemRegistration extends org.jboss.as.controller.SubsystemRegistration, ManagementRegistrationContext { @Override ManagementResourceRegistration registerSubsystemModel(ResourceDefinition definition); @Override ManagementResourceRegistration registerDeploymentModel(ResourceDefinition definition); }
1,602
40.102564
125
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleAttribute.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.AttributeDefinition; /** * Adapts an {@link AttributeDefinition} to the {@link Attribute} interface. * @author Paul Ferraro */ public class SimpleAttribute implements Attribute { private final AttributeDefinition definition; public SimpleAttribute(AttributeDefinition definition) { this.definition = definition; } @Override public AttributeDefinition getDefinition() { return this.definition; } }
1,544
34.113636
76
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleCapabilityServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.SimpleServiceConfigurator; /** * A {@link CapabilityServiceConfigurator} that provides a static value. * @author Paul Ferraro */ public class SimpleCapabilityServiceConfigurator<T> extends SimpleServiceConfigurator<T> implements CapabilityServiceConfigurator { /** * Constructs a new {@link CapabilityServiceConfigurator}. * @param name the service name * @param value the static value provided by the service */ public SimpleCapabilityServiceConfigurator(ServiceName name, T value) { super(name, value); } }
1,703
38.627907
131
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CapabilityReference.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Function; import org.jboss.as.controller.CapabilityReferenceRecorder; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.as.controller.registry.Resource; import org.wildfly.clustering.service.BinaryRequirement; import org.wildfly.clustering.service.UnaryRequirement; /** * {@link CapabilityReferenceRecorder} that delegates to {@link Capability#resolve(org.jboss.as.controller.PathAddress)} to generate the name of the dependent capability. * @author Paul Ferraro */ public class CapabilityReference extends AbstractCapabilityReference { private final Function<OperationContext, String> parentNameResolver; private final String parentSegment; /** * Creates a new reference between the specified capability and the specified requirement * @param capability the capability referencing the specified requirement * @param requirement the requirement of the specified capability */ public CapabilityReference(Capability capability, UnaryRequirement requirement) { super(capability, requirement); this.parentNameResolver = null; this.parentSegment = null; } /** * Creates a new reference between the specified capability and the specified requirement * @param capability the capability referencing the specified requirement * @param requirement the requirement of the specified capability */ public CapabilityReference(Capability capability, BinaryRequirement requirement, PathElement path) { this(capability, requirement, OperationContext::getCurrentAddressValue, path.getKey()); } /** * Creates a new reference between the specified capability and the specified requirement * @param capability the capability referencing the specified requirement * @param requirement the requirement of the specified capability * @param parentAttribute the attribute containing the value of the parent dynamic component of the requirement */ public CapabilityReference(Capability capability, BinaryRequirement requirement, Attribute parentAttribute) { this(capability, requirement, context -> context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel().get(parentAttribute.getName()).asString(), parentAttribute.getName()); } /** * Creates a new reference between the specified capability and the specified requirement * @param capability the capability referencing the specified requirement * @param requirement the requirement of the specified capability * @param parentNameResolver the resolver of the parent dynamic component of the requirement */ private CapabilityReference(Capability capability, BinaryRequirement requirement, Function<OperationContext, String> parentNameResolver, String parentSegment) { super(capability, requirement); this.parentNameResolver = parentNameResolver; this.parentSegment = parentSegment; } @Override public void addCapabilityRequirements(OperationContext context, Resource resource, String attributeName, String... values) { String dependentName = this.getDependentName(context); for (String value : values) { if (value != null) { context.registerAdditionalCapabilityRequirement(this.getRequirementName(context, value), dependentName, attributeName); } } } @Override public void removeCapabilityRequirements(OperationContext context, Resource resource, String attributeName, String... values) { String dependentName = this.getDependentName(context); for (String value : values) { if (value != null) { context.deregisterCapabilityRequirement(this.getRequirementName(context, value), dependentName); } } } private String getRequirementName(OperationContext context, String value) { String[] parts = (this.parentNameResolver != null) ? new String[] { this.parentNameResolver.apply(context), value } : new String[] { value }; return RuntimeCapability.buildDynamicCapabilityName(this.getBaseRequirementName(), parts); } @Override public String[] getRequirementPatternSegments(String name, PathAddress address) { return (this.parentSegment != null) ? new String[] { this.parentSegment, name } : new String[] { name }; } }
5,620
47.042735
185
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SubsystemResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; /** * Resource definition for subsystem resources that performs all registration via {@link #register(SubsystemRegistration)}. * @author Paul Ferraro */ public abstract class SubsystemResourceDefinition extends AbstractResourceDefinition implements ManagementRegistrar<SubsystemRegistration> { protected static PathElement pathElement(String name) { return PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, name); } protected SubsystemResourceDefinition(PathElement path, ResourceDescriptionResolver resolver) { super(path, resolver); } }
1,845
41.930233
140
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RequirementCapability.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.UnaryOperator; import org.jboss.as.controller.capability.RuntimeCapability; import org.wildfly.clustering.service.Requirement; /** * Provides a capability definition provider built from a requirement. * @author Paul Ferraro */ public class RequirementCapability implements Capability { private final RuntimeCapability<Void> definition; /** * Creates a new capability based on the specified requirement * @param requirement the requirement basis */ public RequirementCapability(Requirement requirement) { this(requirement, UnaryOperator.identity()); } /** * Creates a new capability based on the specified requirement * @param requirement the requirement basis * @param configurator configures the capability */ public RequirementCapability(Requirement requirement, UnaryOperator<RuntimeCapability.Builder<Void>> configurator) { this.definition = configurator.apply(RuntimeCapability.Builder.of(requirement.getName()).setServiceType(requirement.getType())).build(); } @Override public RuntimeCapability<Void> getDefinition() { return this.definition; } }
2,257
36.633333
144
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ServiceValueRegistry.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.msc.service.ServiceName; /** * A registry of service values. * @author Paul Ferraro */ public interface ServiceValueRegistry<T> { /** * Adds a service to this registry. * @param name a service name * @return a mechanism for capturing the value of the service */ ServiceValueCaptor<T> add(ServiceName name); /** * Removes a service from this registry * @param name a service name */ ServiceValueCaptor<T> remove(ServiceName name); }
1,575
33.26087
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleResourceServiceHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Simple {@link ResourceServiceHandler} that installs/removes a single service via a {@link ResourceServiceConfiguratorFactory}. * @author Paul Ferraro */ public class SimpleResourceServiceHandler implements ResourceServiceHandler { private ResourceServiceConfiguratorFactory factory; public SimpleResourceServiceHandler(ResourceServiceConfiguratorFactory factory) { this.factory = factory; } @Override public void installServices(OperationContext context, ModelNode model) throws OperationFailedException { this.factory.createServiceConfigurator(context.getCurrentAddress()).configure(context, model).build(context.getServiceTarget()).install(); } @Override public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException { context.removeService(this.factory.createServiceConfigurator(context.getCurrentAddress()).getServiceName()); } }
2,155
41.27451
146
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Operation.java
/* * JBoss, Home of Professional Open Source * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors * as indicated by the @author tags. All rights reserved. * See the copyright.txt in the distribution for a * full listing of individual contributors. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions * of the GNU Lesser General Public License, v. 2.1. * This program is distributed in the hope that it will be useful, but WITHOUT A * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License, * v.2.1 along with this distribution; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.ExpressionResolver; import org.jboss.as.controller.OperationDefinition; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.registry.OperationEntry; import org.jboss.dmr.ModelNode; /** * Interface to be implemented by operation enumerations. * * @param <C> operation context * @author Paul Ferraro * @author Radoslav Husar */ public interface Operation<C> extends Definable<OperationDefinition> { final AttributeDefinition[] NO_ATTRIBUTES = new AttributeDefinition[0]; default String getName() { return this.getDefinition().getName(); } default boolean isReadOnly() { return this.getDefinition().getFlags().contains(OperationEntry.Flag.READ_ONLY); } default AttributeDefinition[] getParameters() { return NO_ATTRIBUTES; } /** * Execute against the specified context. * * @param expressionResolver an expression resolver * @param operation original operation model to resolve parameters from * @param context an execution context * @return the execution result (possibly null). */ ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, C context) throws OperationFailedException; }
2,340
37.377049
125
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Metric.java
/* * JBoss, Home of Professional Open Source * Copyright 2014 Red Hat Inc. and/or its affiliates and other contributors * as indicated by the @author tags. All rights reserved. * See the copyright.txt in the distribution for a * full listing of individual contributors. * * This copyrighted material is made available to anyone wishing to use, * modify, copy, or redistribute it subject to the terms and conditions * of the GNU Lesser General Public License, v. 2.1. * This program is distributed in the hope that it will be useful, but WITHOUT A * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. * You should have received a copy of the GNU Lesser General Public License, * v.2.1 along with this distribution; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. */ package org.jboss.as.clustering.controller; /** * Interface to be implemented by metric enumerations. * @author Paul Ferraro * @param <C> metric context */ public interface Metric<C> extends Attribute, Executable<C> { }
1,190
41.535714
83
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/OperationExecutor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Encapsulates the execution of a runtime operation. * * @param <C> the operation execution context. * @author Paul Ferraro * @author Radoslav Husar */ public interface OperationExecutor<C> { /** * Executes the specified executable against the specified operation context. * * @param context an operation context * @param operation operation model for resolving operation parameters * @param executable the contextual executable object * @return the result of the execution (possibly null). * @throws OperationFailedException if execution fails */ ModelNode execute(OperationContext context, ModelNode operation, Operation<C> executable) throws OperationFailedException; }
1,944
38.693878
126
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RestartParentResourceRegistrar.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; /** * Registers a {@link RestartParentResourceAddStepHandler}, {@link RestartParentResourceRemoveStepHandler}, and {@link RestartParentResourceWriteAttributeHandler} on behalf of a resource definition. * Users of this class should ensure that the {@link ResourceServiceConfigurator} returned by the specified factory sets the appropriate initial mode of the parent service it configures. * Neglecting to do this may result in use of the default initial mode (i.e. ACTIVE), which would result in the parent service starting inadvertently. * @author Paul Ferraro */ public class RestartParentResourceRegistrar extends ResourceRegistrar { public RestartParentResourceRegistrar(ResourceServiceConfiguratorFactory parentFactory, ResourceDescriptor descriptor) { this(parentFactory, descriptor, null); } public RestartParentResourceRegistrar(ResourceServiceConfiguratorFactory parentFactory, ResourceDescriptor descriptor, ResourceServiceHandler handler) { super(descriptor, new RestartParentResourceAddStepHandler(parentFactory, descriptor, handler), new RestartParentResourceRemoveStepHandler(parentFactory, descriptor, handler), new RestartParentResourceWriteAttributeHandler(parentFactory, descriptor)); } }
2,314
55.463415
258
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DecoratingSubsystemRegistration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Function; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.ModelVersionRange; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.SubsystemRegistration; import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.transform.CombinedTransformer; import org.jboss.as.controller.transform.OperationTransformer; import org.jboss.as.controller.transform.ResourceTransformer; import org.jboss.as.controller.transform.TransformersSubRegistration; import org.jboss.staxmapper.XMLElementWriter; /** * Generic {@link SubsystemRegistration} decorator. * @author Paul Ferraro */ public class DecoratingSubsystemRegistration<R extends ManagementResourceRegistration> implements SubsystemRegistration { private final SubsystemRegistration registration; private final Function<ManagementResourceRegistration, R> decorator; public DecoratingSubsystemRegistration(SubsystemRegistration registration, Function<ManagementResourceRegistration, R> decorator) { this.registration = registration; this.decorator = decorator; } @Override public void setHostCapable() { this.registration.setHostCapable(); } @Deprecated // note that since https://issues.redhat.com/browse/WFCORE-3441 this method is no longer deprecated in the interface @Override public void registerXMLElementWriter(XMLElementWriter<SubsystemMarshallingContext> writer) { this.registration.registerXMLElementWriter(writer); } /** * Do not use. Always throws {@code UnsupportedOperationException}. See https://issues.redhat.com/browse/WFLY-17319 */ @Deprecated public TransformersSubRegistration registerModelTransformers(ModelVersionRange version, ResourceTransformer resourceTransformer) { throw new UnsupportedOperationException("WFLY-17319"); } /** * Do not use. Always throws {@code UnsupportedOperationException}. See https://issues.redhat.com/browse/WFLY-17319 */ @Deprecated public TransformersSubRegistration registerModelTransformers(ModelVersionRange version, ResourceTransformer resourceTransformer, OperationTransformer operationTransformer) { throw new UnsupportedOperationException("WFLY-17319"); } /** * Do not use. Always throws {@code UnsupportedOperationException}. See https://issues.redhat.com/browse/WFLY-17319 */ @Deprecated public TransformersSubRegistration registerModelTransformers(ModelVersionRange version, ResourceTransformer resourceTransformer, OperationTransformer operationTransformer, boolean placeholder) { throw new UnsupportedOperationException("WFLY-17319"); } /** * Do not use. Always throws {@code UnsupportedOperationException}. See https://issues.redhat.com/browse/WFLY-17319 */ @Deprecated public TransformersSubRegistration registerModelTransformers(ModelVersionRange version, CombinedTransformer combinedTransformer) { throw new UnsupportedOperationException("WFLY-17319"); } @Override public ModelVersion getSubsystemVersion() { return this.registration.getSubsystemVersion(); } @Override public R registerSubsystemModel(ResourceDefinition definition) { return this.decorator.apply(this.registration.registerSubsystemModel(definition)); } @Override public R registerDeploymentModel(ResourceDefinition definition) { return this.decorator.apply(this.registration.registerDeploymentModel(definition)); } }
4,746
41.765766
198
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ReloadRequiredRemoveStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.registry.OperationEntry; import org.jboss.dmr.ModelNode; /** * @author Paul Ferraro */ public class ReloadRequiredRemoveStepHandler extends RemoveStepHandler { public ReloadRequiredRemoveStepHandler(RemoveStepHandlerDescriptor descriptor) { super(descriptor, OperationEntry.Flag.RESTART_ALL_SERVICES); } @Override protected boolean requiresRuntime(OperationContext context) { return context.isDefaultRequiresRuntime(); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) { context.reloadRequired(); } @Override protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) { context.revertReloadRequired(); } }
1,930
35.433962
100
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RestartParentResourceRemoveStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.dmr.ModelNode; /** * Remove operation handler that leverages a {@link ResourceServiceBuilderFactory} to restart a parent resource.. * @author Paul Ferraro */ public class RestartParentResourceRemoveStepHandler extends RemoveStepHandler { private final OperationStepHandler handler; public RestartParentResourceRemoveStepHandler(ResourceServiceConfiguratorFactory parentFactory, RemoveStepHandlerDescriptor descriptor) { this(parentFactory, descriptor, null); } public RestartParentResourceRemoveStepHandler(ResourceServiceConfiguratorFactory parentFactory, RemoveStepHandlerDescriptor descriptor, ResourceServiceHandler handler) { super(descriptor, handler); this.handler = new RestartParentResourceStepHandler<>(parentFactory); } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { super.execute(context, operation); this.handler.execute(context, operation); } }
2,249
40.666667
173
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/IdentityCapabilityServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Consumer; import java.util.function.Function; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.service.ServiceSupplierDependency; /** * Similar to {@link org.wildfly.clustering.service.IdentityServiceConfigurator}, but resolves the {@link ServiceName} of the requirement during {@link #configure(CapabilityServiceSupport)}. * @author Paul Ferraro */ public class IdentityCapabilityServiceConfigurator<T> extends SimpleServiceNameProvider implements CapabilityServiceConfigurator { private final Function<CapabilityServiceSupport, ServiceName> requirementNameFactory; private volatile SupplierDependency<T> requirement; public IdentityCapabilityServiceConfigurator(ServiceName name, ServiceNameFactory targetFactory) { this(name, new Function<CapabilityServiceSupport, ServiceName>() { @Override public ServiceName apply(CapabilityServiceSupport support) { return targetFactory.getServiceName(support); } }); } public IdentityCapabilityServiceConfigurator(ServiceName name, UnaryServiceNameFactory targetFactory, String requirementName) { this(name, new Function<CapabilityServiceSupport, ServiceName>() { @Override public ServiceName apply(CapabilityServiceSupport support) { return targetFactory.getServiceName(support, requirementName); } }); } public IdentityCapabilityServiceConfigurator(ServiceName name, BinaryServiceNameFactory targetFactory, String requirementParent, String requirementChild) { this(name, new Function<CapabilityServiceSupport, ServiceName>() { @Override public ServiceName apply(CapabilityServiceSupport support) { return targetFactory.getServiceName(support, requirementParent, requirementChild); } }); } private IdentityCapabilityServiceConfigurator(ServiceName name, Function<CapabilityServiceSupport, ServiceName> requirementNameFactory) { super(name); this.requirementNameFactory = requirementNameFactory; } @Override public ServiceConfigurator configure(CapabilityServiceSupport support) { this.requirement = new ServiceSupplierDependency<>(this.requirementNameFactory.apply(support)); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<T> consumer = this.requirement.register(builder).provides(this.getServiceName()); Service service = new FunctionalService<>(consumer, Function.identity(), this.requirement); return builder.setInstance(service).setInitialMode(ServiceController.Mode.PASSIVE); } }
4,376
44.59375
190
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ServiceNameFactoryProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; /** * Provides a factory for generating a {@link ServiceName} for a capability. * @author Paul Ferraro */ public interface ServiceNameFactoryProvider extends ServiceNameFactory { ServiceNameFactory getServiceNameFactory(); @Override default ServiceName getServiceName(OperationContext context) { return this.getServiceNameFactory().getServiceName(context); } @Override default ServiceName getServiceName(CapabilityServiceSupport support) { return this.getServiceNameFactory().getServiceName(support); } }
1,784
36.978723
76
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Definable.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; /** * Implemented by objects with a definition. * @author Paul Ferraro */ public interface Definable<D> { /** * Returns the definition of this object. * @return this object's definition */ D getDefinition(); }
1,305
35.277778
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ContextualResourceRegistration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Optional; import org.jboss.as.controller.services.path.PathManager; /** * @author Paul Ferraro */ public class ContextualResourceRegistration extends DecoratingResourceRegistration<ManagementResourceRegistration> implements ManagementResourceRegistration { private final ManagementRegistrationContext context; public ContextualResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration registration, ManagementRegistrationContext context) { super(registration, r -> new ContextualResourceRegistration(r, context)); this.context = context; } @Override public boolean isRuntimeOnlyRegistrationValid() { return this.context.isRuntimeOnlyRegistrationValid(); } @Override public Optional<PathManager> getPathManager() { return this.context.getPathManager(); } }
1,945
37.156863
160
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/BinaryServiceNameFactoryProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; /** * Provides a factory for generating a {@link ServiceName} for a binary requirement. * @author Paul Ferraro */ public interface BinaryServiceNameFactoryProvider extends BinaryServiceNameFactory { BinaryServiceNameFactory getServiceNameFactory(); @Override default ServiceName getServiceName(OperationContext context, String parent, String child) { return this.getServiceNameFactory().getServiceName(context, parent, child); } @Override default ServiceName getServiceName(CapabilityServiceSupport support, String parent, String child) { return this.getServiceNameFactory().getServiceName(support, parent, child); } }
1,899
38.583333
103
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RuntimeResourceRegistrationStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.dmr.ModelNode; /** * {@link OperationStepHandler} that registers runtime resources. * @author Paul Ferraro */ public class RuntimeResourceRegistrationStepHandler implements OperationStepHandler { private final RuntimeResourceRegistration registration; public RuntimeResourceRegistrationStepHandler(RuntimeResourceRegistration registration) { this.registration = registration; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { this.registration.register(context); } }
1,822
37.787234
104
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/UnaryServiceNameFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; /** * Factory for generating a {@link ServiceName} for a unary requirement. * @author Paul Ferraro */ public interface UnaryServiceNameFactory { /** * Creates a {@link ServiceName} appropriate for the specified name. * @param context an operation context * @param name a potentially null name * @return a {@link ServiceName} */ ServiceName getServiceName(OperationContext context, String name); /** * Creates a {@link ServiceName} appropriate for the specified name. * @param support support for capability services * @param name a potentially null name * @return a {@link ServiceName} */ ServiceName getServiceName(CapabilityServiceSupport support, String name); /** * Creates a {@link ServiceName} appropriate for the address of the specified {@link OperationContext} * @param context an operation context * @param resolver a capability name resolver * @return a {@link ServiceName} */ default ServiceName getServiceName(OperationContext context, UnaryCapabilityNameResolver resolver) { String[] parts = resolver.apply(context.getCurrentAddress()); return this.getServiceName(context.getCapabilityServiceSupport(), parts[0]); } }
2,485
39.754098
106
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AttributeValueTranslator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Translates an attribute value. * @author Paul Ferraro */ @FunctionalInterface public interface AttributeValueTranslator { ModelNode translate(OperationContext context, ModelNode value) throws OperationFailedException; }
1,441
37.972973
99
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CredentialSourceDependency.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.function.Supplier; import org.jboss.as.controller.ObjectTypeAttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.security.CredentialReference; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.DelegatingServiceBuilder; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.Dependency; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.common.function.ExceptionSupplier; import org.wildfly.security.credential.source.CredentialSource; /** * @author Paul Ferraro * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a> */ public class CredentialSourceDependency implements SupplierDependency<CredentialSource> { private final ExceptionSupplier<CredentialSource, Exception> supplier; private final Iterable<Dependency> dependencies; public CredentialSourceDependency(OperationContext context, Attribute attribute, ModelNode model) throws OperationFailedException { DependencyCollectingServiceBuilder builder = new DependencyCollectingServiceBuilder(); this.supplier = CredentialReference.getCredentialSourceSupplier(context, (ObjectTypeAttributeDefinition) attribute.getDefinition(), model, builder); this.dependencies = builder; } @Override public <T> ServiceBuilder<T> register(ServiceBuilder<T> builder) { for (Dependency dependency : this.dependencies) { dependency.register(builder); } return builder; } @Override public CredentialSource get() { try { return this.supplier.get(); } catch (Exception e) { throw new IllegalArgumentException(e); } } static class DependencyCollectingServiceBuilder extends DelegatingServiceBuilder<Object> implements Iterable<Dependency> { private final List<Dependency> dependencies = new LinkedList<>(); DependencyCollectingServiceBuilder() { super(null); } @Override protected ServiceBuilder<Object> getDelegate() { throw new UnsupportedOperationException(); } @Override public Iterator<Dependency> iterator() { return this.dependencies.iterator(); } @Override public <V> Supplier<V> requires(ServiceName name) { SupplierDependency<V> dependency = new ServiceSupplierDependency<>(name); this.dependencies.add(dependency); return dependency; } } }
3,873
37.356436
156
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ChildResourceRegistrar.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Registration interface for child resource definitions. * @author Paul Ferraro */ public interface ChildResourceRegistrar<R extends ManagementResourceRegistration> { /** * Registers this child resource, returning the new registration * @param parent the parent registration * @return the child resource registration */ R register(R parent); }
1,521
38.025641
83
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AddStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.function.BiPredicate; import java.util.function.Predicate; import java.util.function.UnaryOperator; import org.jboss.as.controller.AbstractAddStepHandler; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.CapabilityReferenceRecorder; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.logging.ControllerLogger; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.OperationEntry; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * Generic add operation step handler that delegates service installation/rollback to a {@link ResourceServiceHandler}. * @author Paul Ferraro */ public class AddStepHandler extends AbstractAddStepHandler implements ManagementRegistrar<ManagementResourceRegistration>, DescribedAddStepHandler { private final AddStepHandlerDescriptor descriptor; private final ResourceServiceHandler handler; public AddStepHandler(AddStepHandlerDescriptor descriptor) { this(descriptor, null); } public AddStepHandler(AddStepHandlerDescriptor descriptor, ResourceServiceHandler handler) { this.descriptor = descriptor; this.handler = handler; } @Override protected boolean requiresRuntime(OperationContext context) { return super.requiresRuntime(context) && (this.handler != null); } @Override public AddStepHandlerDescriptor getDescriptor() { return this.descriptor; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); PathAddress parentAddress = address.getParent(); PathElement path = address.getLastElement(); OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD); if (parentHandler instanceof DescribedAddStepHandler) { AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor(); if (parentDescriptor.getRequiredChildren().contains(path)) { if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) { // If we are a required child resource of our parent, we need to remove the auto-created resource first context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); context.addStep(operation, this, OperationContext.Stage.MODEL); return; } } for (PathElement requiredPath : parentDescriptor.getRequiredSingletonChildren()) { String requiredPathKey = requiredPath.getKey(); if (requiredPath.getKey().equals(path.getKey())) { Set<String> childrenNames = context.readResourceFromRoot(parentAddress, false).getChildrenNames(requiredPathKey); if (!childrenNames.isEmpty()) { // If there is a required singleton sibling resource, we need to remove it first for (String childName : childrenNames) { PathAddress singletonAddress = parentAddress.append(requiredPathKey, childName); context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL); } context.addStep(operation, this, OperationContext.Stage.MODEL); return; } } } } super.execute(context, operation); if (this.requiresRuntime(context)) { for (RuntimeResourceRegistration registration : this.descriptor.getRuntimeResourceRegistrations()) { context.addStep(new RuntimeResourceRegistrationStepHandler(registration), OperationContext.Stage.MODEL); } } } @Override protected Resource createResource(OperationContext context) { Resource resource = Resource.Factory.create(context.getResourceRegistration().isRuntimeOnly()); if (context.isDefaultRequiresRuntime()) { resource = this.descriptor.getResourceTransformation().apply(resource); } context.addResource(PathAddress.EMPTY_ADDRESS, resource); return resource; } @Override protected Resource createResource(OperationContext context, ModelNode operation) { UnaryOperator<Resource> transformation = context.isDefaultRequiresRuntime() ? this.descriptor.getResourceTransformation() : UnaryOperator.identity(); ImmutableManagementResourceRegistration registration = context.getResourceRegistration(); Resource resource = transformation.apply(Resource.Factory.create(registration.isRuntimeOnly(), registration.getOrderedChildTypes())); Integer index = registration.isOrderedChildResource() && operation.hasDefined(ModelDescriptionConstants.ADD_INDEX) ? operation.get(ModelDescriptionConstants.ADD_INDEX).asIntOrNull() : null; if (index == null) { context.addResource(PathAddress.EMPTY_ADDRESS, resource); } else { context.addResource(PathAddress.EMPTY_ADDRESS, index, resource); } return resource; } @Override protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { // Validate extra add operation parameters for (AttributeDefinition definition : this.descriptor.getExtraParameters()) { definition.validateOperation(operation); } PathAddress currentAddress = context.getCurrentAddress(); // Validate and apply attribute translations Map<AttributeDefinition, AttributeTranslation> translations = this.descriptor.getAttributeTranslations(); for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : translations.entrySet()) { AttributeDefinition sourceParameter = entry.getKey(); AttributeTranslation translation = entry.getValue(); if (operation.hasDefined(sourceParameter.getName())) { ModelNode value = sourceParameter.validateOperation(operation); ModelNode targetValue = translation.getWriteTranslator().translate(context, value); Attribute targetAttribute = translation.getTargetAttribute(); PathAddress targetAddress = translation.getPathAddressTransformation().apply(currentAddress); // If target attribute exists in the current resource, just fix the operation // Otherwise, we need a separate write-attribute operation if (targetAddress == currentAddress) { String targetName = targetAttribute.getName(); if (!operation.hasDefined(targetName)) { operation.get(targetName).set(targetValue); } } else { ModelNode writeAttributeOperation = Util.getWriteAttributeOperation(targetAddress, targetAttribute.getName(), targetValue); ImmutableManagementResourceRegistration registration = (currentAddress == targetAddress) ? context.getResourceRegistration() : context.getRootResourceRegistration().getSubModel(targetAddress); if (registration == null) { throw new OperationFailedException(ControllerLogger.MGMT_OP_LOGGER.noSuchResourceType(targetAddress)); } OperationStepHandler writeAttributeHandler = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getWriteHandler(); context.addStep(writeAttributeOperation, writeAttributeHandler, OperationContext.Stage.MODEL); } } } // Validate proper attributes ModelNode model = resource.getModel(); ImmutableManagementResourceRegistration registration = context.getResourceRegistration(); for (String attributeName : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { AttributeAccess attribute = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName); AttributeDefinition definition = attribute.getAttributeDefinition(); if ((attribute.getStorageType() == AttributeAccess.Storage.CONFIGURATION) && !translations.containsKey(definition)) { OperationStepHandler writeHandler = this.descriptor.getCustomAttributes().get(definition); if (writeHandler != null) { // If attribute has custom handling, perform a separate write-attribute operation ModelNode writeAttributeOperation = Util.getWriteAttributeOperation(currentAddress, definition.getName(), definition.validateOperation(operation)); context.addStep(writeAttributeOperation, writeHandler, OperationContext.Stage.MODEL); } else { definition.validateAndSet(operation, model); } } } // Auto-create required child resources as necessary addRequiredChildren(context, this.descriptor.getRequiredChildren(), (Resource parent, PathElement path) -> parent.hasChild(path)); addRequiredChildren(context, this.descriptor.getRequiredSingletonChildren(), (Resource parent, PathElement path) -> parent.hasChildren(path.getKey())); // Don't leave model undefined if (!model.isDefined()) { model.setEmptyObject(); } } private static void addRequiredChildren(OperationContext context, Collection<PathElement> paths, BiPredicate<Resource, PathElement> present) { for (PathElement path : paths) { context.addStep(Util.createAddOperation(context.getCurrentAddress().append(path)), new AddIfAbsentStepHandler(present), OperationContext.Stage.MODEL); } } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { this.handler.installServices(context, model); } @Override protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) { try { this.handler.removeServices(context, resource.getModel()); } catch (OperationFailedException e) { throw new IllegalStateException(e); } } @Override protected void recordCapabilitiesAndRequirements(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); ModelNode model = resource.getModel(); // The super implementation assumes that the capability name is a simple extension of the base name - we do not. // Only register capabilities when allowed by the associated predicate for (Map.Entry<Capability, Predicate<ModelNode>> entry : this.descriptor.getCapabilities().entrySet()) { if (entry.getValue().test(model)) { context.registerCapability(entry.getKey().resolve(address)); } } ImmutableManagementResourceRegistration registration = context.getResourceRegistration(); for (String attributeName : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { AttributeDefinition attribute = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, attributeName).getAttributeDefinition(); if (attribute.hasCapabilityRequirements()) { attribute.addCapabilityRequirements(context, resource, model.get(attributeName)); } } for (CapabilityReferenceRecorder recorder : registration.getRequirements()) { recorder.addCapabilityRequirements(context, resource, null); } } @Override public void register(ManagementResourceRegistration registration) { SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.ADD, this.descriptor.getDescriptionResolver()).withFlag(OperationEntry.Flag.RESTART_NONE); if (registration.isOrderedChildResource()) { builder.addParameter(SimpleAttributeDefinitionBuilder.create(ModelDescriptionConstants.ADD_INDEX, ModelType.INT, true).build()); } for (AttributeDefinition attribute : this.descriptor.getAttributes()) { builder.addParameter(attribute); } for (AttributeDefinition attribute : this.descriptor.getCustomAttributes().keySet()) { builder.addParameter(attribute); } for (AttributeDefinition attribute : this.descriptor.getIgnoredAttributes()) { builder.addParameter(attribute); } for (AttributeDefinition parameter : this.descriptor.getExtraParameters()) { builder.addParameter(parameter); } for (AttributeDefinition attribute : this.descriptor.getAttributeTranslations().keySet()) { builder.addParameter(attribute); } registration.registerOperationHandler(builder.build(), this.descriptor.getAddOperationTransformation().apply(this)); } }
15,440
53.950178
231
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/WriteAttributeStepHandlerDescriptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Collection; import java.util.Collections; import org.jboss.as.controller.AttributeDefinition; /** * @author Paul Ferraro */ public interface WriteAttributeStepHandlerDescriptor extends OperationStepHandlerDescriptor { /** * Attributes of the add operation. * @return a collection of attributes */ Collection<AttributeDefinition> getAttributes(); /** * Attributes (not specified by {@link #getAttributes()}) will be ignored at runtime.. * @return a collection of ignored attributes */ default Collection<AttributeDefinition> getIgnoredAttributes() { return Collections.emptySet(); } }
1,734
34.408163
93
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ReadAttributeTranslationHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.logging.ControllerLogger; import org.jboss.as.controller.operations.common.Util; import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; /** * A read-attribute operation handler that translates a value from another attribute * @author Paul Ferraro */ public class ReadAttributeTranslationHandler implements OperationStepHandler { private final AttributeTranslation translation; public ReadAttributeTranslationHandler(AttributeTranslation translation) { this.translation = translation; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress currentAddress = context.getCurrentAddress(); PathAddress targetAddress = this.translation.getPathAddressTransformation().apply(currentAddress); Attribute targetAttribute = this.translation.getTargetAttribute(); ModelNode targetOperation = Util.getReadAttributeOperation(targetAddress, targetAttribute.getName()); if (operation.hasDefined(ModelDescriptionConstants.INCLUDE_DEFAULTS)) { targetOperation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS)); } ImmutableManagementResourceRegistration registration = (currentAddress == targetAddress) ? context.getResourceRegistration() : context.getRootResourceRegistration().getSubModel(targetAddress); if (registration == null) { throw new OperationFailedException(ControllerLogger.MGMT_OP_LOGGER.noSuchResourceType(targetAddress)); } OperationStepHandler readAttributeHandler = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getReadHandler(); OperationStepHandler readTranslatedAttributeHandler = new ReadTranslatedAttributeStepHandler(readAttributeHandler, targetAttribute, this.translation.getReadTranslator()); // If targetOperation applies to the current resource, we can execute in the current step if (targetAddress == currentAddress) { readTranslatedAttributeHandler.execute(context, targetOperation); } else { if (registration.isRuntimeOnly()) { try { context.readResourceFromRoot(targetAddress, false); } catch (Resource.NoSuchResourceException ignore) { // If the target runtime resource does not exist return UNDEFINED return; } } context.addStep(targetOperation, readTranslatedAttributeHandler, context.getCurrentStage(), true); } } private static class ReadTranslatedAttributeStepHandler implements OperationStepHandler { private final OperationStepHandler readHandler; private final Attribute targetAttribute; private final AttributeValueTranslator translator; ReadTranslatedAttributeStepHandler(OperationStepHandler readHandler, Attribute targetAttribute, AttributeValueTranslator translator) { this.readHandler = readHandler; this.targetAttribute = targetAttribute; this.translator = translator; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (this.readHandler != null) { this.readHandler.execute(context, operation); } else { try { // If attribute has no read handler, simulate one ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); ModelNode result = context.getResult(); if (model.hasDefined(this.targetAttribute.getName())) { result.set(model.get(this.targetAttribute.getName())); } else if (operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).asBoolean(true)) { ModelNode defaultValue = this.targetAttribute.getDefinition().getDefaultValue(); if (defaultValue != null) { result.set(defaultValue); } } } catch (Resource.NoSuchResourceException ignore) { // If the target resource does not exist return UNDEFINED return; } } ModelNode result = context.getResult(); result.set(this.translator.translate(context, result)); } } }
6,051
50.726496
200
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/WriteAttributeStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Map; import java.util.function.Predicate; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler; import org.jboss.as.controller.registry.AttributeAccess; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; /** * Convenience extension of {@link org.jboss.as.controller.ReloadRequiredWriteAttributeHandler} that can be initialized with an {@link Attribute} set. * @author Paul Ferraro */ public class WriteAttributeStepHandler extends ReloadRequiredWriteAttributeHandler implements ManagementRegistrar<ManagementResourceRegistration> { private final WriteAttributeStepHandlerDescriptor descriptor; private final ResourceServiceHandler handler; public WriteAttributeStepHandler(WriteAttributeStepHandlerDescriptor descriptor) { this(descriptor, null); } public WriteAttributeStepHandler(WriteAttributeStepHandlerDescriptor descriptor, ResourceServiceHandler handler) { super(descriptor.getAttributes()); this.descriptor = descriptor; this.handler = handler; } @Override public void register(ManagementResourceRegistration registration) { for (AttributeDefinition attribute : this.descriptor.getAttributes()) { registration.registerReadWriteAttribute(attribute, null, this); } } @Override protected void recordCapabilitiesAndRequirements(OperationContext context, AttributeDefinition attribute, ModelNode newValue, ModelNode oldValue) { Map<Capability, Predicate<ModelNode>> capabilities = this.descriptor.getCapabilities(); if (!capabilities.isEmpty()) { PathAddress address = context.getCurrentAddress(); // newValue is already applied to the model ModelNode newModel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode oldModel = newModel.clone(); oldModel.get(attribute.getName()).set(oldValue); for (Map.Entry<Capability, Predicate<ModelNode>> entry : capabilities.entrySet()) { Capability capability = entry.getKey(); Predicate<ModelNode> predicate = entry.getValue(); boolean registered = predicate.test(oldModel); boolean shouldRegister = predicate.test(newModel); if (!registered && shouldRegister) { // Attribute change enables capability registration context.registerCapability(capability.resolve(address)); } else if (registered && !shouldRegister) { // Attribute change disables capability registration context.deregisterCapability(capability.resolve(address).getName()); } } } super.recordCapabilitiesAndRequirements(context, attribute, newValue, oldValue); } @Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> handback) throws OperationFailedException { boolean updated = super.applyUpdateToRuntime(context, operation, attributeName, resolvedValue, currentValue, handback); if (updated && (this.handler != null)) { PathAddress address = context.getCurrentAddress(); if (context.isResourceServiceRestartAllowed() && this.getAttributeDefinition(attributeName).getFlags().contains(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) && context.markResourceRestarted(address, this.handler)) { this.handler.removeServices(context, context.getOriginalRootResource().navigate(context.getCurrentAddress()).getModel()); this.handler.installServices(context, context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()); // Returning false prevents going into reload required state return false; } } return updated; } @Override protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode resolvedValue, Void handback) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); if (context.isResourceServiceRestartAllowed() && this.getAttributeDefinition(attributeName).getFlags().contains(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES) && context.revertResourceRestarted(address, this.handler)) { this.handler.removeServices(context, context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel()); this.handler.installServices(context, context.getOriginalRootResource().navigate(context.getCurrentAddress()).getModel()); } } }
6,085
52.858407
230
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AdminOnlyOperationStepHandlerTransformer.java
/* * JBoss, Home of Professional Open Source. * Copyright 2023, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.UnaryOperator; import org.jboss.as.clustering.logging.ClusteringLogger; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.dmr.ModelNode; /** * An {@link OperationStepHandler} decorator that fails when not running in admin-only mode. * @author Paul Ferraro */ public enum AdminOnlyOperationStepHandlerTransformer implements UnaryOperator<OperationStepHandler> { INSTANCE; @Override public OperationStepHandler apply(OperationStepHandler handler) { return new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (context.isNormalServer()) { throw ClusteringLogger.ROOT_LOGGER.operationNotSupportedInNormalServerMode(context.getCurrentAddress().toCLIStyleString(), context.getCurrentOperationName()); } handler.execute(context, operation); } }; } }
2,196
40.45283
178
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ServiceValueCaptorServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2019, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SupplierDependency; /** * Configures a service that captures the value of a target service. * @author Paul Ferraro */ public class ServiceValueCaptorServiceConfigurator<T> implements ServiceConfigurator, Service { private final ServiceValueCaptor<T> captor; private final SupplierDependency<T> dependency; public ServiceValueCaptorServiceConfigurator(ServiceValueCaptor<T> captor) { this.dependency = new ServiceSupplierDependency<>(captor.getServiceName()); this.captor = captor; } @Override public ServiceName getServiceName() { return this.captor.getServiceName().append("captor"); } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); return this.dependency.register(builder) .setInstance(this) .setInitialMode(ServiceController.Mode.PASSIVE); } @Override public void start(StartContext context) throws StartException { this.captor.accept(this.dependency.get()); } @Override public void stop(StopContext context) { this.captor.accept(null); } }
2,764
36.364865
95
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/MetricHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import org.jboss.as.controller.AbstractRuntimeOnlyHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; /** * Generic {@link org.jboss.as.controller.OperationStepHandler} for runtime metrics. * @author Paul Ferraro */ public class MetricHandler<C> extends AbstractRuntimeOnlyHandler implements ManagementRegistrar<ManagementResourceRegistration> { private final Collection<? extends Metric<C>> metrics; private final Map<String, Metric<C>> executables = new HashMap<>(); private final Executor<C, Metric<C>> executor; public <M extends Enum<M> & Metric<C>> MetricHandler(MetricExecutor<C> executor, Class<M> metricClass) { this(executor, EnumSet.allOf(metricClass)); } public MetricHandler(MetricExecutor<C> executor, Metric<C>[] metrics) { this(executor, Arrays.asList(metrics)); } public MetricHandler(MetricExecutor<C> executor, Collection<? extends Metric<C>> metrics) { this.executor = executor; for (Metric<C> executable : metrics) { this.executables.put(executable.getName(), executable); } this.metrics = metrics; } @Override public void register(ManagementResourceRegistration registration) { for (Metric<C> metric : this.metrics) { registration.registerMetric(metric.getDefinition(), this); } } @Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) { String name = operation.get(ModelDescriptionConstants.NAME).asString(); Metric<C> executable = this.executables.get(name); try { ModelNode result = this.executor.execute(context, executable); if (result != null) { context.getResult().set(result); } } catch (OperationFailedException e) { context.getFailureDescription().set(e.getLocalizedMessage()); } context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER); } }
3,432
38.918605
129
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ModuleServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2018, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Collections; import java.util.List; import org.jboss.modules.Module; import org.jboss.msc.service.ServiceName; /** * Configures a service providing a {@link Module}. * @author Paul Ferraro */ public class ModuleServiceConfigurator extends AbstractModulesServiceConfigurator<Module> { public ModuleServiceConfigurator(ServiceName name, Attribute attribute) { super(name, attribute, Collections::singletonList); } @Override public Module apply(List<Module> modules) { return !modules.isEmpty() ? modules.get(0) : null; } }
1,650
34.891304
91
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AddIfAbsentStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.BiPredicate; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; /** * Adds a given child resource if absent. * @author Paul Ferraro */ public class AddIfAbsentStepHandler implements OperationStepHandler { private final BiPredicate<Resource, PathElement> present; public AddIfAbsentStepHandler(BiPredicate<Resource, PathElement> present) { this.present = present; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); Resource parentResource = context.readResourceFromRoot(address.getParent(), false); if (!this.present.test(parentResource, address.getLastElement())) { context.getResourceRegistration().getOperationHandler(PathAddress.EMPTY_ADDRESS, ModelDescriptionConstants.ADD).execute(context, operation); } } }
2,354
40.315789
152
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ManagementResourceRegistration.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.descriptions.OverrideDescriptionProvider; /** * Enhanced {@link org.jboss.as.controller.registry.ManagementResourceRegistration} that also exposes the registration context. * @author Paul Ferraro */ public interface ManagementResourceRegistration extends org.jboss.as.controller.registry.ManagementResourceRegistration, ManagementRegistrationContext { @Override ManagementResourceRegistration registerSubModel(ResourceDefinition resourceDefinition); @Override ManagementResourceRegistration registerOverrideModel(String name, OverrideDescriptionProvider descriptionProvider); }
1,751
42.8
152
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/BinaryRequirementCapability.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.UnaryOperator; import org.jboss.as.controller.capability.RuntimeCapability; import org.wildfly.clustering.service.BinaryRequirement; /** * Provides a capability definition provider built from a binary requirement. * @author Paul Ferraro */ public class BinaryRequirementCapability implements Capability { private final RuntimeCapability<Void> definition; /** * Creates a new capability based on the specified requirement * @param requirement the requirement basis */ public BinaryRequirementCapability(BinaryRequirement requirement) { this(requirement, BinaryCapabilityNameResolver.PARENT_CHILD); } /** * Creates a new capability based on the specified requirement * @param requirement the requirement basis * @param resolver a capability name resolver */ public BinaryRequirementCapability(BinaryRequirement requirement, BinaryCapabilityNameResolver resolver) { this(requirement, new CapabilityNameResolverConfigurator(resolver)); } /** * Creates a new capability based on the specified requirement * @param requirement the requirement basis * @param configurator configures the capability */ public BinaryRequirementCapability(BinaryRequirement requirement, UnaryOperator<RuntimeCapability.Builder<Void>> configurator) { this.definition = configurator.apply(RuntimeCapability.Builder.of(requirement.getName(), true).setServiceType(requirement.getType())).build(); } @Override public RuntimeCapability<Void> getDefinition() { return this.definition; } }
2,699
38.130435
150
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AbstractResourceDefinition.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleResourceDefinition; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Resource definition for resources that performs all registration via {@link ManagementRegistrar#register(Object)}. * All other registerXXX(...) methods have been made final - to prevent misuse. * @author Paul Ferraro */ public abstract class AbstractResourceDefinition extends SimpleResourceDefinition { protected AbstractResourceDefinition(PathElement path, ResourceDescriptionResolver resolver) { super(new Parameters(path, resolver)); } protected AbstractResourceDefinition(Parameters parameters) { super(parameters); } @Override public final void registerOperations(ManagementResourceRegistration resourceRegistration) { } @Override public final void registerAttributes(ManagementResourceRegistration resourceRegistration) { } @Override public final void registerNotifications(ManagementResourceRegistration resourceRegistration) { } @Override public final void registerChildren(ManagementResourceRegistration resourceRegistration) { } @Override public final void registerCapabilities(ManagementResourceRegistration resourceRegistration) { } }
2,473
37.061538
117
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceServiceHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Handles service installation and removal for use by {@link AddStepHandler} and {@link RemoveStepHandler}. * @author Paul Ferraro */ public interface ResourceServiceHandler { /** * Installs runtime services for a resource, configured from the specified model. * @param context the context of the add/remove operation * @param model the resource model * @throws OperationFailedException if service installation fails */ void installServices(OperationContext context, ModelNode model) throws OperationFailedException; /** * Removes runtime services for a resource. * @param context the context of the add/remove operation * @param model the resource model * @throws OperationFailedException if service installation fails */ void removeServices(OperationContext context, ModelNode model) throws OperationFailedException; }
2,104
40.27451
108
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/OperationHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import org.jboss.as.controller.AbstractRuntimeOnlyHandler; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; /** * Generic {@link org.jboss.as.controller.OperationStepHandler} for runtime operations. * @author Paul Ferraro */ public class OperationHandler<C> extends AbstractRuntimeOnlyHandler implements ManagementRegistrar<ManagementResourceRegistration> { private final Collection<? extends Operation<C>> operations; private final Map<String, Operation<C>> executables = new HashMap<>(); private final OperationExecutor<C> executor; public <O extends Enum<O> & Operation<C>> OperationHandler(OperationExecutor<C> executor, Class<O> operationClass) { this(executor, EnumSet.allOf(operationClass)); } public OperationHandler(OperationExecutor<C> executor, Operation<C>[] operations) { this(executor, Arrays.asList(operations)); } public OperationHandler(OperationExecutor<C> executor, Collection<? extends Operation<C>> operations) { this.executor = executor; for (Operation<C> executable : operations) { this.executables.put(executable.getName(), executable); } this.operations = operations; } @Override public void register(ManagementResourceRegistration registration) { for (Operation<C> operation : this.operations) { registration.registerOperationHandler(operation.getDefinition(), this); } } @Override protected void executeRuntimeStep(OperationContext context, ModelNode operation) { String name = operation.get(ModelDescriptionConstants.OP).asString(); Operation<C> executable = this.executables.get(name); try { ModelNode result = this.executor.execute(context, operation, executable); if (result != null) { context.getResult().set(result); } } catch (OperationFailedException e) { context.getFailureDescription().set(e.getLocalizedMessage()); } context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER); } }
3,533
40.093023
132
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ExtensionRegistrationContext.java
/* * JBoss, Home of Professional Open Source. * Copyright 2017, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Optional; import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.services.path.PathManager; /** * @author Paul Ferraro */ public class ExtensionRegistrationContext implements ManagementRegistrationContext { private final boolean runtimeOnlyRegistrationValid; private final Optional<PathManager> pathManager; public ExtensionRegistrationContext(ExtensionContext context) { this.runtimeOnlyRegistrationValid = context.isRuntimeOnlyRegistrationValid(); this.pathManager = context.getProcessType().isServer() ? Optional.of(context.getPathManager()) : Optional.empty(); } @Override public boolean isRuntimeOnlyRegistrationValid() { return this.runtimeOnlyRegistrationValid; } @Override public Optional<PathManager> getPathManager() { return this.pathManager; } }
1,949
35.792453
122
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceDefinitionProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Provides a {@link ResourceDefinition} and handles its registration. * @author Paul Ferraro */ public interface ResourceDefinitionProvider extends ManagementRegistrar<ManagementResourceRegistration> { /** * The registration path of the provided resource definition. * @return a path element */ PathElement getPathElement(); }
1,594
38.875
105
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DeploymentChainContributingResourceRegistrar.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.Consumer; import org.jboss.as.server.DeploymentProcessorTarget; /** * Registers a {@link DeploymentChainContributingAddStepHandler}, {@link ReloadRequiredRemoveStepHandler}, and {@link WriteAttributeStepHandler} on behalf of a resource definition. * @author Paul Ferraro */ public class DeploymentChainContributingResourceRegistrar extends ResourceRegistrar { public DeploymentChainContributingResourceRegistrar(ResourceDescriptor descriptor, ResourceServiceHandler handler, Consumer<DeploymentProcessorTarget> contributor) { super(descriptor, handler, new DeploymentChainContributingAddStepHandler(descriptor, handler, contributor), new ReloadRequiredRemoveStepHandler(descriptor)); } }
1,805
45.307692
180
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/OperationStepHandlerDescriptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Collections; import java.util.Map; import java.util.function.Predicate; import org.jboss.dmr.ModelNode; /** * @author Paul Ferraro */ public interface OperationStepHandlerDescriptor { /** * The capabilities provided by this resource, paired with the condition under which they should be [un]registered * @return a map of capabilities to predicates */ default Map<Capability, Predicate<ModelNode>> getCapabilities() { return Collections.emptyMap(); } }
1,578
34.886364
118
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AddStepHandlerDescriptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.function.UnaryOperator; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.Resource; /** * Describes the common properties of a remove operation handler. * @author Paul Ferraro */ public interface AddStepHandlerDescriptor extends WriteAttributeStepHandlerDescriptor, RemoveStepHandlerDescriptor { /** * Custom attributes of the add operation, processed using a specific write-attribute handler. * @return a map of attributes and their write-attribute handler */ Map<AttributeDefinition, OperationStepHandler> getCustomAttributes(); /** * Extra parameters (not specified by {@link #getAttributes()}) for the add operation. * @return a collection of attributes */ Collection<AttributeDefinition> getExtraParameters(); /** * Returns the required child resources for this resource description. * @return a collection of resource paths */ Set<PathElement> getRequiredChildren(); /** * Returns the required singleton child resources for this resource description. * This means only one child resource should exist for the given child type. * @return a collection of resource paths */ Set<PathElement> getRequiredSingletonChildren(); /** * Returns a mapping of attribute translations * @return an attribute translation mapping */ Map<AttributeDefinition, AttributeTranslation> getAttributeTranslations(); /** * Returns a transformer for the add operation handler. * This is typically used to adapt legacy operations to conform to the current version of the model. * @return an operation handler transformer. */ UnaryOperator<OperationStepHandler> getAddOperationTransformation(); /** * Returns a transformation for a newly created resource. * @return a resource transformation */ UnaryOperator<Resource> getResourceTransformation(); }
3,208
36.752941
116
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SubsystemExtension.java
/* * JBoss, Home of Professional Open Source. * Copyright 2022, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.EnumSet; import java.util.List; import java.util.function.Supplier; import org.jboss.as.controller.Extension; import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.SubsystemModel; import org.jboss.as.controller.SubsystemSchema; import org.jboss.as.controller.parsing.ExtensionParsingContext; import org.jboss.as.controller.persistence.SubsystemMarshallingContext; import org.jboss.dmr.ModelNode; import org.jboss.staxmapper.XMLElementReader; import org.jboss.staxmapper.XMLElementWriter; /** * Generic extension implementation that registers a single subsystem. * @author Paul Ferraro */ public class SubsystemExtension<S extends Enum<S> & SubsystemSchema<S>> implements Extension { private final String name; private final SubsystemModel currentModel; private final Supplier<ManagementRegistrar<SubsystemRegistration>> registrarFactory; private final S currentSchema; private final XMLElementWriter<SubsystemMarshallingContext> writer; private final XMLElementReader<List<ModelNode>> currentReader; /** * Constructs a new extension using a reader factory and a separate writer implementation. * @param name the subsystem name * @param currentModel the current model * @param registrarFactory a factory for creating the subsystem resource definition registrar * @param currentSchema the current schema * @param readerFactory a factory for creating an XML reader * @param writer an XML writer */ protected SubsystemExtension(String name, SubsystemModel currentModel, Supplier<ManagementRegistrar<SubsystemRegistration>> registrarFactory, S currentSchema, XMLElementWriter<SubsystemMarshallingContext> writer) { this(name, currentModel, registrarFactory, currentSchema, writer, currentSchema); } SubsystemExtension(String name, SubsystemModel currentModel, Supplier<ManagementRegistrar<SubsystemRegistration>> registrarFactory, S currentSchema, XMLElementWriter<SubsystemMarshallingContext> writer, XMLElementReader<List<ModelNode>> currentReader) { this.name = name; this.currentModel = currentModel; this.registrarFactory = registrarFactory; this.currentSchema = currentSchema; this.writer = writer; this.currentReader = currentReader; } @Override public void initialize(ExtensionContext context) { SubsystemRegistration registration = new ContextualSubsystemRegistration(context.registerSubsystem(this.name, this.currentModel.getVersion()), context); // Construct subsystem resource definition here so that instance can be garbage collected following registration this.registrarFactory.get().register(registration); registration.registerXMLElementWriter(this.writer); } @Override public void initializeParsers(ExtensionParsingContext context) { for (S schema : EnumSet.allOf(this.currentSchema.getDeclaringClass())) { context.setSubsystemXmlMapping(this.name, schema.getNamespace().getUri(), (schema == this.currentSchema) ? this.currentReader: schema); } } }
4,207
46.280899
257
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceDescriptor.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.Arrays; import java.util.Collection; import java.util.Comparator; import java.util.EnumSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; import java.util.function.Predicate; import java.util.function.UnaryOperator; import java.util.stream.Stream; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.CapabilityReferenceRecorder; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.ResourceDefinition; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; /** * Describes the properties of resource used by {@link AddStepHandler}. * Supports supplying attributes and capabilities via enumerations. * Also supports defining extra parameters that are not actually attributes of the target resource. * @author Paul Ferraro */ public class ResourceDescriptor implements AddStepHandlerDescriptor { private static final Comparator<PathElement> PATH_COMPARATOR = new Comparator<>() { @Override public int compare(PathElement path1, PathElement path2) { int result = path1.getKey().compareTo(path2.getKey()); return (result == 0) ? path1.getValue().compareTo(path2.getValue()) : result; } }; private static final Comparator<AttributeDefinition> ATTRIBUTE_COMPARATOR = Comparator.comparing(AttributeDefinition::getName); private static final Comparator<Capability> CAPABILITY_COMPARATOR = Comparator.comparing(Capability::getName); @SuppressWarnings("deprecation") private static final Comparator<CapabilityReferenceRecorder> CAPABILITY_REFERENCE_COMPARATOR = Comparator.comparing(CapabilityReferenceRecorder::getBaseDependentName); private final ResourceDescriptionResolver resolver; private Map<Capability, Predicate<ModelNode>> capabilities = Map.of(); private List<AttributeDefinition> attributes = List.of(); private Map<AttributeDefinition, OperationStepHandler> customAttributes = Map.of(); private List<AttributeDefinition> ignoredAttributes = List.of(); private List<AttributeDefinition> parameters = List.of(); private Set<PathElement> requiredChildren = Set.of(); private Set<PathElement> requiredSingletonChildren = Set.of(); private Map<AttributeDefinition, AttributeTranslation> attributeTranslations = Map.of(); private List<RuntimeResourceRegistration> runtimeResourceRegistrations = List.of(); private Set<CapabilityReferenceRecorder> resourceCapabilityReferences = Set.of(); private UnaryOperator<OperationStepHandler> addOperationTransformer = UnaryOperator.identity(); private UnaryOperator<OperationStepHandler> operationTransformer = UnaryOperator.identity(); private UnaryOperator<Resource> resourceTransformer = UnaryOperator.identity(); public ResourceDescriptor(ResourceDescriptionResolver resolver) { this.resolver = resolver; } @Override public ResourceDescriptionResolver getDescriptionResolver() { return this.resolver; } @Override public Map<Capability, Predicate<ModelNode>> getCapabilities() { return this.capabilities; } @Override public Collection<AttributeDefinition> getAttributes() { return this.attributes; } @Override public Collection<AttributeDefinition> getIgnoredAttributes() { return this.ignoredAttributes; } @Override public Collection<AttributeDefinition> getExtraParameters() { return this.parameters; } @Override public Set<PathElement> getRequiredChildren() { return this.requiredChildren; } @Override public Set<PathElement> getRequiredSingletonChildren() { return this.requiredSingletonChildren; } @Override public Map<AttributeDefinition, AttributeTranslation> getAttributeTranslations() { return this.attributeTranslations; } @Override public Map<AttributeDefinition, OperationStepHandler> getCustomAttributes() { return this.customAttributes; } @Override public Collection<RuntimeResourceRegistration> getRuntimeResourceRegistrations() { return this.runtimeResourceRegistrations; } @Override public Set<CapabilityReferenceRecorder> getResourceCapabilityReferences() { return this.resourceCapabilityReferences; } @Override public UnaryOperator<OperationStepHandler> getOperationTransformation() { return this.operationTransformer; } @Override public UnaryOperator<Resource> getResourceTransformation() { return this.resourceTransformer; } @Override public UnaryOperator<OperationStepHandler> getAddOperationTransformation() { return this.addOperationTransformer; } public ResourceDescriptor addAttribute(Attribute attribute, OperationStepHandler writeAttributeHandler) { return this.addAttribute(attribute.getDefinition(), writeAttributeHandler); } public ResourceDescriptor addAttribute(AttributeDefinition attribute, OperationStepHandler writeAttributeHandler) { if (this.customAttributes.isEmpty()) { this.customAttributes = Map.of(attribute, writeAttributeHandler); } else { if (this.customAttributes.size() == 1) { Map<AttributeDefinition, OperationStepHandler> existing = this.customAttributes; this.customAttributes = new TreeMap<>(ATTRIBUTE_COMPARATOR); this.customAttributes.putAll(existing); } this.customAttributes.put(attribute, writeAttributeHandler); } return this; } public <E extends Enum<E> & Attribute> ResourceDescriptor addAttributes(Class<E> enumClass) { return this.addAttributes(EnumSet.allOf(enumClass)); } public ResourceDescriptor addAttributes(Set<? extends Attribute> attributes) { return this.addAttributes(attributes.stream()); } public ResourceDescriptor addAttributes(Attribute... attributes) { return this.addAttributes(List.of(attributes).stream()); } private ResourceDescriptor addAttributes(Stream<? extends Attribute> attributes) { return this.addAttributes(attributes.map(Attribute::getDefinition)::iterator); } public ResourceDescriptor addAttributes(AttributeDefinition... attributes) { return this.addAttributes(List.of(attributes)); } public ResourceDescriptor addAttributes(Iterable<AttributeDefinition> attributes) { if (this.attributes.isEmpty()) { this.attributes = new LinkedList<>(); } for (AttributeDefinition attribute : attributes) { this.attributes.add(attribute); } return this; } public <E extends Enum<E> & Attribute> ResourceDescriptor addIgnoredAttributes(Class<E> enumClass) { return this.addIgnoredAttributes(EnumSet.allOf(enumClass)); } public ResourceDescriptor addIgnoredAttributes(Set<? extends Attribute> attributes) { return this.addIgnoredAttributes(attributes.stream()); } public ResourceDescriptor addIgnoredAttributes(Attribute... attributes) { return this.addIgnoredAttributes(List.of(attributes).stream()); } private ResourceDescriptor addIgnoredAttributes(Stream<? extends Attribute> attributes) { return this.addIgnoredAttributes(attributes.map(Attribute::getDefinition)::iterator); } public ResourceDescriptor addIgnoredAttributes(AttributeDefinition... attributes) { return this.addIgnoredAttributes(List.of(attributes)); } public ResourceDescriptor addIgnoredAttributes(Iterable<AttributeDefinition> attributes) { if (this.ignoredAttributes.isEmpty()) { this.ignoredAttributes = new LinkedList<>(); } for (AttributeDefinition attribute : attributes) { this.ignoredAttributes.add(attribute); } return this; } public <E extends Enum<E> & Attribute> ResourceDescriptor addExtraParameters(Class<E> enumClass) { return this.addExtraParameters(EnumSet.allOf(enumClass)); } public ResourceDescriptor addExtraParameters(Set<? extends Attribute> parameters) { return this.addExtraParameters(parameters.stream()); } public ResourceDescriptor addExtraParameters(Attribute... parameters) { return this.addExtraParameters(List.of(parameters).stream()); } private ResourceDescriptor addExtraParameters(Stream<? extends Attribute> parameters) { return this.addExtraParameters(parameters.map(Attribute::getDefinition)::iterator); } public ResourceDescriptor addExtraParameters(AttributeDefinition... parameters) { return this.addExtraParameters(List.of(parameters)); } public ResourceDescriptor addExtraParameters(Iterable<AttributeDefinition> parameters) { if (this.parameters.isEmpty()) { this.parameters = new LinkedList<>(); } for (AttributeDefinition parameter : parameters) { this.parameters.add(parameter); } return this; } public <E extends Enum<E> & Capability> ResourceDescriptor addCapabilities(Class<E> enumClass) { return this.addCapabilities(ModelNode::isDefined, enumClass); } public ResourceDescriptor addCapabilities(Capability... capabilities) { return this.addCapabilities(ModelNode::isDefined, capabilities); } public ResourceDescriptor addCapabilities(Iterable<? extends Capability> capabilities) { return this.addCapabilities(ModelNode::isDefined, capabilities); } public <E extends Enum<E> & Capability> ResourceDescriptor addCapabilities(Predicate<ModelNode> predicate, Class<E> enumClass) { return this.addCapabilities(predicate, EnumSet.allOf(enumClass)); } public ResourceDescriptor addCapabilities(Predicate<ModelNode> predicate, Capability... capabilities) { return this.addCapabilities(predicate, Arrays.asList(capabilities)); } public ResourceDescriptor addCapabilities(Predicate<ModelNode> predicate, Iterable<? extends Capability> capabilities) { if (this.capabilities.isEmpty()) { this.capabilities = new TreeMap<>(CAPABILITY_COMPARATOR); } for (Capability capability : capabilities) { this.capabilities.put(capability, predicate); } return this; } public <E extends Enum<E> & ResourceDefinitionProvider> ResourceDescriptor addRequiredChildren(Class<E> enumClass) { return this.addRequiredChildren(EnumSet.allOf(enumClass)); } public ResourceDescriptor addRequiredChildren(Set<? extends ResourceDefinitionProvider> providers) { return this.addRequiredChildren(providers.stream().map(ResourceDefinitionProvider::getPathElement)::iterator); } public ResourceDescriptor addRequiredChildren(PathElement... paths) { return this.addRequiredChildren(List.of(paths)); } public ResourceDescriptor addRequiredChildren(Iterable<PathElement> paths) { if (this.requiredChildren.isEmpty()) { this.requiredChildren = new TreeSet<>(PATH_COMPARATOR); } for (PathElement path : paths) { this.requiredChildren.add(path); } return this; } public <E extends Enum<E> & ResourceDefinition> ResourceDescriptor addRequiredSingletonChildren(Class<E> enumClass) { return this.addRequiredSingletonChildren(EnumSet.allOf(enumClass)); } public ResourceDescriptor addRequiredSingletonChildren(Set<? extends ResourceDefinition> definitions) { return this.addRequiredSingletonChildren(definitions.stream().map(ResourceDefinition::getPathElement)::iterator); } public ResourceDescriptor addRequiredSingletonChildren(PathElement... paths) { return this.addRequiredSingletonChildren(List.of(paths)); } public ResourceDescriptor addRequiredSingletonChildren(Iterable<PathElement> paths) { if (this.requiredSingletonChildren.isEmpty()) { this.requiredSingletonChildren = new TreeSet<>(PATH_COMPARATOR); } for (PathElement path : paths) { this.requiredSingletonChildren.add(path); } return this; } public ResourceDescriptor addAlias(Attribute alias, Attribute target) { return this.addAttributeTranslation(alias, () -> target); } public ResourceDescriptor addAttributeTranslation(Attribute sourceAttribute, AttributeTranslation translation) { if (this.attributeTranslations.isEmpty()) { this.attributeTranslations = Map.of(sourceAttribute.getDefinition(), translation); } else { if (this.attributeTranslations.size() == 1) { Map<AttributeDefinition, AttributeTranslation> existing = this.attributeTranslations; this.attributeTranslations = new TreeMap<>(ATTRIBUTE_COMPARATOR); this.attributeTranslations.putAll(existing); } this.attributeTranslations.put(sourceAttribute.getDefinition(), translation); } return this; } public ResourceDescriptor addRuntimeResourceRegistration(RuntimeResourceRegistration registration) { if (this.runtimeResourceRegistrations.isEmpty()) { this.runtimeResourceRegistrations = List.of(registration); } else { if (this.runtimeResourceRegistrations.size() == 1) { List<RuntimeResourceRegistration> existing = this.runtimeResourceRegistrations; this.runtimeResourceRegistrations = new LinkedList<>(); this.runtimeResourceRegistrations.addAll(existing); } this.runtimeResourceRegistrations.add(registration); } return this; } public ResourceDescriptor addResourceCapabilityReference(CapabilityReferenceRecorder reference) { if (this.resourceCapabilityReferences.isEmpty()) { this.resourceCapabilityReferences = Set.of(reference); } else { if (this.resourceCapabilityReferences.size() == 1) { Set<CapabilityReferenceRecorder> existing = this.resourceCapabilityReferences; this.resourceCapabilityReferences = new TreeSet<>(CAPABILITY_REFERENCE_COMPARATOR); this.resourceCapabilityReferences.addAll(existing); } this.resourceCapabilityReferences.add(reference); } return this; } public ResourceDescriptor setAddOperationTransformation(UnaryOperator<OperationStepHandler> transformation) { this.addOperationTransformer = transformation; return this; } public ResourceDescriptor setOperationTransformation(UnaryOperator<OperationStepHandler> transformation) { this.operationTransformer = transformation; return this; } public ResourceDescriptor setResourceTransformation(UnaryOperator<Resource> transformation) { this.resourceTransformer = transformation; return this; } }
16,375
39.94
171
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RestartParentResourceAddStepHandler.java
/* * JBoss, Home of Professional Open Source. * Copyright 2015, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; import org.jboss.dmr.ModelNode; /** * Add operation handler that leverages a {@link ResourceServiceBuilderFactory} to restart a parent resource.. * @author Paul Ferraro */ public class RestartParentResourceAddStepHandler extends AddStepHandler { private final OperationStepHandler handler; public RestartParentResourceAddStepHandler(ResourceServiceConfiguratorFactory parentFactory, AddStepHandlerDescriptor descriptor, ResourceServiceHandler handler) { super(descriptor, handler); this.handler = new RestartParentResourceStepHandler<>(parentFactory); } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { super.execute(context, operation); this.handler.execute(context, operation); } }
2,038
39.78
167
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/AbstractModulesServiceConfigurator.java
/* * JBoss, Home of Professional Open Source. * Copyright 2020, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.server.Services; import org.jboss.dmr.ModelNode; import org.jboss.modules.Module; import org.jboss.modules.ModuleLoadException; import org.jboss.modules.ModuleLoader; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; /** * @author Paul Ferraro */ public abstract class AbstractModulesServiceConfigurator<T> extends SimpleServiceNameProvider implements ResourceServiceConfigurator, Supplier<List<Module>>, Function<List<Module>, T> { private final Attribute attribute; private final SupplierDependency<ModuleLoader> loader = new ServiceSupplierDependency<>(Services.JBOSS_SERVICE_MODULE_LOADER); private final Function<ModelNode, List<ModelNode>> toList; private volatile List<ModelNode> identifiers = Collections.emptyList(); AbstractModulesServiceConfigurator(ServiceName name, Attribute attribute, Function<ModelNode, List<ModelNode>> toList) { super(name); this.attribute = attribute; this.toList = toList; } @Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.identifiers = this.toList.apply(this.attribute.resolveModelAttribute(context, model)); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<T> modules = this.loader.register(builder).provides(this.getServiceName()); Service service = new FunctionalService<>(modules, this, this); return builder.setInstance(service); } @Override public List<Module> get() { List<ModelNode> identifiers = this.identifiers; List<Module> modules = !identifiers.isEmpty() ? new ArrayList<>(identifiers.size()) : Collections.emptyList(); for (ModelNode identifier : identifiers) { try { modules.add(this.loader.get().loadModule(identifier.asString())); } catch (ModuleLoadException e) { throw new IllegalArgumentException(e); } } return modules; } }
3,924
40.755319
185
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/UnaryRequirementCapability.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.jboss.as.clustering.controller; import java.util.function.UnaryOperator; import org.jboss.as.controller.capability.RuntimeCapability; import org.wildfly.clustering.service.UnaryRequirement; /** * Provides a capability definition provider built from a unary requirement. * @author Paul Ferraro */ public class UnaryRequirementCapability implements Capability { private final RuntimeCapability<Void> definition; /** * Creates a new capability based on the specified unary requirement * @param requirement the unary requirement basis */ public UnaryRequirementCapability(UnaryRequirement requirement) { this(requirement, UnaryCapabilityNameResolver.DEFAULT); } /** * Creates a new capability based on the specified unary requirement * @param requirement the unary requirement basis * @param resolver a capability name resolver */ public UnaryRequirementCapability(UnaryRequirement requirement, UnaryCapabilityNameResolver resolver) { this(requirement, new CapabilityNameResolverConfigurator(resolver)); } /** * Creates a new capability based on the specified unary requirement * @param requirement the unary requirement basis * @param configurator configures the runtime capability */ public UnaryRequirementCapability(UnaryRequirement requirement, UnaryOperator<RuntimeCapability.Builder<Void>> configurator) { this.definition = configurator.apply(RuntimeCapability.Builder.of(requirement.getName(), true).setServiceType(requirement.getType())).build(); } @Override public RuntimeCapability<Void> getDefinition() { return this.definition; } }
2,727
38.536232
150
java