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/common/src/main/java/org/jboss/as/clustering/controller/FunctionExecutor.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.wildfly.common.function.ExceptionFunction; /** * Encapsulates execution of a function. * @author Paul Ferraro * @param <T> the type of the function argument */ public interface FunctionExecutor<T> { /** * Executes the given function. * @param <R> the return type * @param <E> the exception type * @param function a function to execute * @return the result of the function * @throws E if the function fails to execute */ <R, E extends Exception> R execute(ExceptionFunction<T, R, E> function) throws E; }
1,632
36.976744
85
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DeploymentChainContributingAddStepHandler.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.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.registry.Resource; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.dmr.ModelNode; /** * @author Paul Ferraro */ public class DeploymentChainContributingAddStepHandler extends AddStepHandler { private final Consumer<DeploymentProcessorTarget> deploymentChainContributor; public DeploymentChainContributingAddStepHandler(AddStepHandlerDescriptor descriptor, ResourceServiceHandler handler, Consumer<DeploymentProcessorTarget> deploymentChainContributor) { super(descriptor, handler); this.deploymentChainContributor = deploymentChainContributor; } @Override protected final void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { if (context.isBooting()) { context.addStep(new DeploymentChainStep(this.deploymentChainContributor), OperationContext.Stage.RUNTIME); super.performRuntime(context, operation, resource); } else { context.reloadRequired(); } } @Override protected final void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) { if (context.isBooting()) { super.rollbackRuntime(context, operation, resource); } else { context.revertReloadRequired(); } } }
2,593
38.907692
187
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DefaultSubsystemDescribeHandler.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.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; import org.jboss.as.controller.operations.common.OrderedChildTypesAttachment; import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; /** * Custom subsystem describe operation handler that works with override models. * Workaround for WFCORE-2286. * @author Paul Ferraro */ public class DefaultSubsystemDescribeHandler extends GenericSubsystemDescribeHandler implements ManagementRegistrar<ManagementResourceRegistration> { @Override protected void describe(OrderedChildTypesAttachment orderedChildTypesAttachment, Resource resource, ModelNode addressModel, ModelNode result, ImmutableManagementResourceRegistration registration) { if (resource == null || registration.isRemote() || registration.isRuntimeOnly() || resource.isProxy() || resource.isRuntime() || registration.isAlias()) return; result.add(createAddOperation(orderedChildTypesAttachment, addressModel, resource, registration.getChildAddresses(PathAddress.EMPTY_ADDRESS))); PathAddress address = PathAddress.pathAddress(addressModel); for (String type : resource.getChildTypes()) { for (Resource.ResourceEntry entry : resource.getChildren(type)) { PathElement path = entry.getPathElement(); ImmutableManagementResourceRegistration childRegistration = Optional.ofNullable(registration.getSubModel(PathAddress.pathAddress(path))).orElse(registration.getSubModel(PathAddress.pathAddress(PathElement.pathElement(path.getKey())))); PathAddress childAddress = address.append(path); this.describe(orderedChildTypesAttachment, entry, childAddress.toModelNode(), result, childRegistration); } } } @Override public void register(ManagementResourceRegistration registration) { registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, this); } }
3,334
51.936508
251
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CompositeCapabilityServiceConfigurator.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.BiConsumer; import java.util.function.Consumer; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.wildfly.clustering.service.ServiceConfigurator; /** * A {@link CapabilityServiceConfigurator} facade for collecting, configuring, and building; or removing; a set of {@link ServiceConfigurator} instances. * @author Paul Ferraro */ public class CompositeCapabilityServiceConfigurator extends CompositeServiceConfigurator implements CapabilityServiceConfigurator { private final BiConsumer<CapabilityServiceSupport, Consumer<ServiceConfigurator>> consumer; public CompositeCapabilityServiceConfigurator(BiConsumer<CapabilityServiceSupport, Consumer<ServiceConfigurator>> consumer) { this.consumer = consumer; } @Override public CompositeServiceConfigurator configure(CapabilityServiceSupport support) { this.consumer.accept(support, this); return this; } public void remove(OperationContext context) { this.consumer.accept(context.getCapabilityServiceSupport(), configurator -> context.removeService(configurator.getServiceName())); } }
2,278
42
153
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CapabilityNameResolverConfigurator.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.Function; import java.util.function.UnaryOperator; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.capability.RuntimeCapability; /** * Operator that configures a runtime capability with a given capability name resolver. * @author Paul Ferraro */ public class CapabilityNameResolverConfigurator implements UnaryOperator<RuntimeCapability.Builder<Void>> { private final Function<PathAddress, String[]> resolver; /** * Creates a new capability name resolver configurator * @param mapper a capability name resolver */ public CapabilityNameResolverConfigurator(Function<PathAddress, String[]> resolver) { this.resolver = resolver; } @Override public RuntimeCapability.Builder<Void> apply(RuntimeCapability.Builder<Void> builder) { return builder.setDynamicNameMapper(this.resolver); } }
1,971
36.923077
107
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/OperationFunction.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.function.Function; import org.jboss.as.controller.ExpressionResolver; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.wildfly.common.function.ExceptionFunction; /** * A functional view of a runtime operation. * @author Paul Ferraro * @param <T> the type of value provided by the service on which the given runtime operation operates * @param <V> the type of the value of which the given runtime operation operates */ public class OperationFunction<T, V> implements ExceptionFunction<T, ModelNode, OperationFailedException> { private final ExpressionResolver resolver; private final ModelNode operation; private final Function<T, V> mapper; private final Operation<V> executable; /** * Creates a functional view of the specified metric using the specified mapping function. * @param resolver an expression resolver * @param operation the management operation * @param mapper maps the value of a service to the value on which the given metric operates * @param executable a runtime operation */ public OperationFunction(ExpressionResolver resolver, ModelNode operation, Function<T, V> mapper, Operation<V> executable) { this.resolver = resolver; this.operation = operation; this.mapper = mapper; this.executable = executable; } @Override public ModelNode apply(T value) throws OperationFailedException { V mapped = this.mapper.apply(value); return (mapped != null) ? this.executable.execute(this.resolver, this.operation, mapped) : null; } }
2,706
40.646154
128
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ParentResourceServiceHandler.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.PathAddress; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; /** * A {@link SimpleResourceServiceHandler} that uses a recursively read model, to include child resources. * @author Paul Ferraro */ public class ParentResourceServiceHandler extends SimpleResourceServiceHandler { public ParentResourceServiceHandler(ResourceServiceConfiguratorFactory factory) { super(factory); } @Override public void installServices(OperationContext context, ModelNode model) throws OperationFailedException { super.installServices(context, Resource.Tools.readModel(context.readResource(PathAddress.EMPTY_ADDRESS))); } }
1,885
40
114
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ModulesServiceConfigurator.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.List; import org.jboss.dmr.ModelNode; import org.jboss.modules.Module; import org.jboss.msc.service.ServiceName; /** * @author Paul Ferraro */ public class ModulesServiceConfigurator extends AbstractModulesServiceConfigurator<List<Module>> { private final List<Module> defaultModules; public ModulesServiceConfigurator(ServiceName name, Attribute attribute, List<Module> defaultModules) { super(name, attribute, ModelNode::asListOrEmpty); this.defaultModules = defaultModules; } @Override public List<Module> apply(List<Module> modules) { return modules.isEmpty() ? this.defaultModules : modules; } }
1,742
35.3125
107
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CapabilityRegistrar.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 org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Registration facility for capabilities. * @author Paul Ferraro */ public class CapabilityRegistrar implements ManagementRegistrar<ManagementResourceRegistration> { private final Collection<? extends Capability> capabilities; public <E extends Enum<E> & Capability> CapabilityRegistrar(Class<E> capabilityClass) { this(EnumSet.allOf(capabilityClass)); } public CapabilityRegistrar(Capability... capabilities) { this.capabilities = Arrays.asList(capabilities); } public CapabilityRegistrar(Collection<? extends Capability> capabilities) { this.capabilities = capabilities; } @Override public void register(ManagementResourceRegistration registration) { for (Capability capability : this.capabilities) { registration.registerCapability(capability.getDefinition()); } } }
2,097
35.172414
97
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Capability.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.PathAddress; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.Requirement; /** * Interface to be implemented by capability enumerations. * @author Paul Ferraro */ public interface Capability extends Definable<RuntimeCapability<?>>, Requirement, ResourceServiceNameFactory { @Override default String getName() { return this.getDefinition().getName(); } @Override default Class<?> getType() { return this.getDefinition().getCapabilityServiceValueType(); } /** * Resolves this capability against the specified path address * @param address a path address * @return a resolved runtime capability */ default RuntimeCapability<?> resolve(PathAddress address) { RuntimeCapability<?> definition = this.getDefinition(); return definition.isDynamicallyNamed() ? definition.fromBaseCapability(address) : definition; } @Override default ServiceName getServiceName(PathAddress address) { return this.resolve(address).getCapabilityServiceName(); } }
2,244
35.803279
110
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CapabilityServiceNameProvider.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.PathAddress; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.ServiceNameProvider; /** * Service name provider for a capability. * @author Paul Ferraro */ public class CapabilityServiceNameProvider implements ServiceNameProvider { private final ServiceName name; public CapabilityServiceNameProvider(Capability capability, PathAddress address) { this.name = capability.getServiceName(address); } @Override public ServiceName getServiceName() { return this.name; } }
1,644
34.76087
86
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CompositeServiceConfigurator.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.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.function.Consumer; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.SimpleServiceNameProvider; /** * A {@link ServiceConfigurator} facade for collecting and building a set of {@link ServiceConfigurator} instances. * @author Paul Ferraro */ public class CompositeServiceConfigurator extends SimpleServiceNameProvider implements ServiceConfigurator, Consumer<ServiceConfigurator> { private final List<ServiceConfigurator> configurators = new LinkedList<>(); public CompositeServiceConfigurator() { super(null); } public CompositeServiceConfigurator(ServiceName name) { super(name); } @Override public ServiceBuilder<?> build(ServiceTarget target) { List<ServiceBuilder<?>> builders = new ArrayList<>(this.configurators.size()); for (ServiceConfigurator configurator : this.configurators) { builders.add(configurator.build(target)); } return new CompositeServiceBuilder<>(builders); } @Override public void accept(ServiceConfigurator configurator) { this.configurators.add(configurator); } }
2,456
36.227273
139
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RuntimeResourceRegistration.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.OperationContext; import org.jboss.as.controller.OperationFailedException; /** * Encapsulates logic for runtime resource registration. * @author Paul Ferraro */ public interface RuntimeResourceRegistration { /** * Registers runtime resources as part of an add operation. * @param context an operation context */ void register(OperationContext context) throws OperationFailedException; /** * Removes runtime resources created during {@link #register(OperationContext)}. * @param context an operation context */ void unregister(OperationContext context) throws OperationFailedException; }
1,738
37.644444
84
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/BinaryServiceNameFactory.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 binary requirement. * @author Paul Ferraro */ public interface BinaryServiceNameFactory { /** * Creates a {@link ServiceName} appropriate for the specified name. * @param context an operation context * @param parent a parent resource name * @param child a child resource name * @return a {@link ServiceName} */ ServiceName getServiceName(OperationContext context, String parent, String child); /** * Creates a {@link ServiceName} appropriate for the specified name. * @param support support for capability services * @param parent a parent resource name * @param child a child resource name * @return a {@link ServiceName} */ ServiceName getServiceName(CapabilityServiceSupport support, String parent, String child); /** * 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, BinaryCapabilityNameResolver resolver) { String[] parts = resolver.apply(context.getCurrentAddress()); return this.getServiceName(context.getCapabilityServiceSupport(), parts[0], parts[1]); } }
2,617
39.90625
106
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/DefaultableUnaryServiceNameFactoryProvider.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 unary requirement * as well as a factory generating a {@link ServiceName} for a default requirement. * @author Paul Ferraro */ public interface DefaultableUnaryServiceNameFactoryProvider extends UnaryServiceNameFactoryProvider { /** * The factory from which to generate a {@link ServiceName} if the requested name is null. * @return a factory for generating service names */ ServiceNameFactory getDefaultServiceNameFactory(); @Override default ServiceName getServiceName(OperationContext context, String name) { return (name != null) ? this.getServiceNameFactory().getServiceName(context, name) : this.getDefaultServiceNameFactory().getServiceName(context); } @Override default ServiceName getServiceName(CapabilityServiceSupport support, String name) { return (name != null) ? this.getServiceNameFactory().getServiceName(support, name) : this.getDefaultServiceNameFactory().getServiceName(support); } }
2,271
42.692308
153
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Attribute.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.EnumSet; import java.util.stream.Stream; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.ExpressionResolver; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * Interface to be implemented by attribute enumerations. * @author Paul Ferraro */ public interface Attribute extends Definable<AttributeDefinition> { /** * Returns the name of this attribute. * @return the attribute name */ default String getName() { return this.getDefinition().getName(); } /** * Resolves the value of this attribute from the specified model applying any default value. * @param resolver an expression resolver * @param model the resource model * @return the resolved value * @throws OperationFailedException if the value was not valid */ default ModelNode resolveModelAttribute(ExpressionResolver resolver, ModelNode model) throws OperationFailedException { return this.getDefinition().resolveModelAttribute(resolver, model); } /** * Convenience method that exposes an Attribute enum as a stream of {@link AttributeDefinition}s. * @param <E> the attribute enum type * @param enumClass the enum class * @return a stream of attribute definitions. */ static <E extends Enum<E> & Attribute> Stream<AttributeDefinition> stream(Class<E> enumClass) { return stream(EnumSet.allOf(enumClass)); } /** * Convenience method that exposes a set of attributes as a stream of {@link AttributeDefinition}s. * @param <A> the attribute type * @return a stream of attribute definitions. */ static <A extends Attribute> Stream<AttributeDefinition> stream(Collection<A> attributes) { return attributes.stream().map(Attribute::getDefinition); } }
2,975
37.153846
123
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RestartParentResourceStepHandler.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.PathAddress; import org.jboss.as.controller.RestartParentResourceHandlerBase; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceName; /** * Generic operation handler that leverages a {@link ResourceServiceBuilderFactory} to restart a parent resource.. * @author Paul Ferraro */ public class RestartParentResourceStepHandler<T> extends RestartParentResourceHandlerBase { private final ResourceServiceConfiguratorFactory parentFactory; public RestartParentResourceStepHandler(ResourceServiceConfiguratorFactory parentFactory) { super(null); this.parentFactory = parentFactory; } @Override protected boolean requiresRuntime(OperationContext context) { return context.isDefaultRequiresRuntime(); } @Override protected void updateModel(OperationContext context, ModelNode operation) throws OperationFailedException { } @Override protected void recreateParentService(OperationContext context, PathAddress parentAddress, ModelNode parentModel) throws OperationFailedException { this.parentFactory.createServiceConfigurator(parentAddress).configure(context, parentModel).build(context.getServiceTarget()).install(); } @Override protected ServiceName getParentServiceName(PathAddress parentAddress) { return this.parentFactory.createServiceConfigurator(parentAddress).getServiceName(); } @Override protected PathAddress getParentAddress(PathAddress address) { return address.getParent(); } }
2,738
38.695652
150
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Executor.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 contextual executable. * @param <C> the execution context * @param <E> the contextual executable * @author Paul Ferraro */ public interface Executor<C, E extends Executable<C>> { /** * Executes the specified executable against the specified operation context. * @param context an operation context * @param executable the contextual executable object * @return the result of the execution (possibly null). * @throws OperationFailedException if execution fails */ ModelNode execute(OperationContext context, E executable) throws OperationFailedException; }
1,845
40.022222
94
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceCapabilityReference.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.Function; import org.jboss.as.controller.CapabilityReferenceRecorder; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.PathAddress; 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.Requirement; import org.wildfly.clustering.service.UnaryRequirement; /** * {@link CapabilityReferenceRecorder} for resource-level capability references. * @author Paul Ferraro */ public class ResourceCapabilityReference extends AbstractCapabilityReference { private final Function<PathAddress, String[]> requirementNameResolver; /** * 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 ResourceCapabilityReference(Capability capability, Requirement requirement) { this(capability, requirement, SimpleCapabilityNameResolver.EMPTY); } /** * 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 requirementNameResolver function for resolving the dynamic elements of the requirement name */ public ResourceCapabilityReference(Capability capability, UnaryRequirement requirement, UnaryCapabilityNameResolver requirementNameResolver) { this(capability, (Requirement) requirement, requirementNameResolver); } /** * 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 requirementNameResolver function for resolving the dynamic elements of the requirement name */ public ResourceCapabilityReference(Capability capability, BinaryRequirement requirement, BinaryCapabilityNameResolver requirementNameResolver) { this(capability, (Requirement) requirement, requirementNameResolver); } private ResourceCapabilityReference(Capability capability, Requirement requirement, Function<PathAddress, String[]> requirementNameResolver) { super(capability, requirement); this.requirementNameResolver = requirementNameResolver; } @Override public void addCapabilityRequirements(OperationContext context, Resource resource, String attributeName, String... values) { context.registerAdditionalCapabilityRequirement(this.getRequirementName(context), this.getDependentName(context), attributeName); } @Override public void removeCapabilityRequirements(OperationContext context, Resource resource, String attributeName, String... values) { context.deregisterCapabilityRequirement(this.getRequirementName(context), this.getDependentName(context)); } private String getRequirementName(OperationContext context) { String[] parts = this.requirementNameResolver.apply(context.getCurrentAddress()); return (parts.length > 0) ? RuntimeCapability.buildDynamicCapabilityName(this.getBaseRequirementName(), parts) : this.getBaseRequirementName(); } @Override public String[] getRequirementPatternSegments(String name, PathAddress address) { String[] segments = this.requirementNameResolver.apply(address); for (int i = 0; i < segments.length; ++i) { String segment = segments[i]; if (segment.charAt(0) == '$') { segments[i] = segment.substring(1); } } return segments; } }
4,975
46.846154
151
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CommonUnaryRequirement.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.security.KeyStore; import javax.net.ssl.SSLContext; import javax.sql.DataSource; import org.jboss.as.network.OutboundSocketBinding; import org.jboss.as.network.SocketBinding; import org.wildfly.clustering.service.UnaryRequirement; import org.wildfly.security.credential.store.CredentialStore; /** * Enumerates common unary requirements for clustering resources * @author Paul Ferraro */ public enum CommonUnaryRequirement implements UnaryRequirement, UnaryServiceNameFactoryProvider { CREDENTIAL_STORE("org.wildfly.security.credential-store", CredentialStore.class), DATA_SOURCE("org.wildfly.data-source", DataSource.class), KEY_STORE("org.wildfly.security.key-store", KeyStore.class), OUTBOUND_SOCKET_BINDING("org.wildfly.network.outbound-socket-binding", OutboundSocketBinding.class), PATH("org.wildfly.management.path", String.class), SOCKET_BINDING("org.wildfly.network.socket-binding", SocketBinding.class), SSL_CONTEXT("org.wildfly.security.ssl-context", SSLContext.class), ; private final String name; private final Class<?> type; private final UnaryServiceNameFactory factory = new UnaryRequirementServiceNameFactory(this); CommonUnaryRequirement(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 UnaryServiceNameFactory getServiceNameFactory() { return this.factory; } }
2,648
35.791667
104
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceServiceNameFactory.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.PathAddress; import org.jboss.msc.service.ServiceName; /** * Generates the {@link ServiceName} for a resource service. * @author Paul Ferraro */ public interface ResourceServiceNameFactory { /** * Returns {@link ServiceName} for the specified resource address. * @param address a resource address * @return a server name */ ServiceName getServiceName(PathAddress address); }
1,507
36.7
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleCapabilityNameResolver.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.Function; import org.jboss.as.controller.PathAddress; /** * Dynamic name mapper that uses a static mapping. * @author Paul Ferraro */ public class SimpleCapabilityNameResolver implements Function<PathAddress, String[]> { public static final Function<PathAddress, String[]> EMPTY = new SimpleCapabilityNameResolver(); private final String[] names; public SimpleCapabilityNameResolver(String... names) { this.names = names; } @Override public String[] apply(PathAddress address) { return this.names; } }
1,649
34.106383
99
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/FunctionExecutorRegistry.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; /** * Registry of {@link FunctionExecutor} objects. * @author Paul Ferraro * @param <T> the argument type of the function executor */ public interface FunctionExecutorRegistry<T> { /** * Returns the function executor for the service installed using the specified name. * @param name a service name * @return a function executor */ FunctionExecutor<T> get(ServiceName name); }
1,520
37.025
88
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ComplexResource.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.Collections; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.function.BiFunction; import java.util.function.Function; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.DelegatingResource; import org.jboss.as.controller.registry.Resource; /** * A generic {@link Resource} decorator augmented to support additional runtime children. * @author Paul Ferraro */ public class ComplexResource extends DelegatingResource implements Function<String, ChildResourceProvider> { private final Map<String, ChildResourceProvider> providers; private final BiFunction<Resource, Map<String, ChildResourceProvider>, Resource> factory; /** * Constructs a new resource. * @param resource the concrete resource * @param providers a set of providers for specific child types */ public ComplexResource(Resource resource, Map<String, ChildResourceProvider> providers) { this(resource, providers, ComplexResource::new); } /** * Constructs a new resource. * @param resource the concrete resource * @param providers a set of providers for specific child types * @param factory a function used to clone this resource */ protected ComplexResource(Resource resource, Map<String, ChildResourceProvider> providers, BiFunction<Resource, Map<String, ChildResourceProvider>, Resource> factory) { super(resource); this.providers = providers; this.factory = factory; } @Override public ChildResourceProvider apply(String childType) { return this.providers.get(childType); } @Override public Resource clone() { return this.factory.apply(super.clone(), this.providers); } @Override public Resource getChild(PathElement path) { ChildResourceProvider provider = this.apply(path.getKey()); return (provider != null) ? provider.getChild(path.getValue()) : super.getChild(path); } @Override public Set<Resource.ResourceEntry> getChildren(String childType) { ChildResourceProvider provider = this.apply(childType); if (provider != null) { Set<String> names = provider.getChildren(); Set<Resource.ResourceEntry> entries = !names.isEmpty() ? new HashSet<>() : Collections.emptySet(); for (String name : names) { Resource resource = provider.getChild(name); entries.add(new SimpleResourceEntry(PathElement.pathElement(childType, name), resource)); } return entries; } return super.getChildren(childType); } @Override public Set<String> getChildrenNames(String childType) { ChildResourceProvider provider = this.apply(childType); return (provider != null) ? provider.getChildren() : super.getChildrenNames(childType); } @Override public Set<String> getChildTypes() { Set<String> childTypes = new HashSet<>(super.getChildTypes()); childTypes.addAll(this.providers.keySet()); return childTypes; } @Override public boolean hasChild(PathElement path) { ChildResourceProvider provider = this.apply(path.getKey()); return (provider != null) ? provider.getChild(path.getValue()) != null : super.hasChild(path); } @Override public boolean hasChildren(String childType) { ChildResourceProvider provider = this.apply(childType); return (provider != null) ? !provider.getChildren().isEmpty() : super.hasChildren(childType); } @Override public Resource navigate(PathAddress address) { return (address.size() == 1) ? this.requireChild(address.getLastElement()) : super.navigate(address); } @Override public Resource requireChild(PathElement path) { Resource resource = this.getChild(path); if (resource == null) { throw new NoSuchResourceException(path); } return resource; } private static class SimpleResourceEntry extends DelegatingResource implements Resource.ResourceEntry { private final PathElement path; SimpleResourceEntry(PathElement path, Resource resource) { super(resource); this.path = path; } @Override public String getName() { return this.path.getValue(); } @Override public PathElement getPathElement() { return this.path; } @Override public int hashCode() { return this.path.hashCode(); } @Override public boolean equals(Object object) { if (!(object instanceof Resource.ResourceEntry)) return false; return this.path.equals(((Resource.ResourceEntry) object).getPathElement()); } @Override public String toString() { return this.path.toString(); } } }
6,094
34.231214
172
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ReloadRequiredResourceRegistrar.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; /** * @author Paul Ferraro */ public class ReloadRequiredResourceRegistrar extends ResourceRegistrar { public ReloadRequiredResourceRegistrar(AddStepHandlerDescriptor descriptor) { super(descriptor, new ReloadRequiredAddStepHandler(descriptor), new ReloadRequiredRemoveStepHandler(descriptor), new WriteAttributeStepHandler(descriptor)); } }
1,430
41.088235
164
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/PredicateCapabilityReference.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.function.Predicate; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; import org.wildfly.clustering.service.BinaryRequirement; import org.wildfly.clustering.service.Requirement; import org.wildfly.clustering.service.UnaryRequirement; /** * A capability reference recorder that registers a given requirement conditionally based the attribute value. * @author Paul Ferraro */ public class PredicateCapabilityReference extends ResourceCapabilityReference { private static final Predicate<ModelNode> BOOLEAN = ModelNode::asBoolean; private final Predicate<ModelNode> predicate; /** * Creates a new reference between the specified capability and the specified requirement for boolean attributes. * @param capability the capability referencing the specified requirement * @param requirement the requirement of the specified capability */ public PredicateCapabilityReference(Capability capability, Requirement requirement) { this(capability, requirement, BOOLEAN); } /** * 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 predicate a predicate that determines for which values the requirement should be registered */ public PredicateCapabilityReference(Capability capability, Requirement requirement, Predicate<ModelNode> predicate) { super(capability, requirement); this.predicate = predicate; } /** * 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 requirementNameResolver function for resolving the dynamic elements of the requirement name */ public PredicateCapabilityReference(Capability capability, UnaryRequirement requirement, UnaryCapabilityNameResolver requirementNameResolver) { this(capability, requirement, requirementNameResolver, BOOLEAN); } /** * 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 requirementNameResolver function for resolving the dynamic elements of the requirement name * @param predicate a predicate that determines for which values the requirement should be registered */ public PredicateCapabilityReference(Capability capability, UnaryRequirement requirement, UnaryCapabilityNameResolver requirementNameResolver, Predicate<ModelNode> predicate) { super(capability, requirement, requirementNameResolver); this.predicate = predicate; } /** * 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 requirementNameResolver function for resolving the dynamic elements of the requirement name * @param predicate a predicate that determines for which values the requirement should be registered */ public PredicateCapabilityReference(Capability capability, BinaryRequirement requirement, BinaryCapabilityNameResolver requirementNameResolver) { this(capability, requirement, requirementNameResolver, BOOLEAN); } /** * 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 requirementNameResolver function for resolving the dynamic elements of the requirement name * @param predicate a predicate that determines for which values the requirement should be registered */ public PredicateCapabilityReference(Capability capability, BinaryRequirement requirement, BinaryCapabilityNameResolver requirementNameResolver, Predicate<ModelNode> predicate) { super(capability, requirement, requirementNameResolver); this.predicate = predicate; } @Override public void addCapabilityRequirements(OperationContext context, Resource resource, String attributeName, String... values) { for (String value : values) { if (this.predicate.test(new ModelNode(value))) { super.addCapabilityRequirements(context, resource, attributeName, value); } } } @Override public void removeCapabilityRequirements(OperationContext context, Resource resource, String attributeName, String... values) { for (String value : values) { if (this.predicate.test(new ModelNode(value))) { super.removeCapabilityRequirements(context, resource, attributeName, value); } } } }
6,295
48.968254
181
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/PropertiesAttributeDefinition.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.Locale; import java.util.ResourceBundle; import java.util.function.Consumer; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.AttributeMarshaller; import org.jboss.as.controller.AttributeParser; import org.jboss.as.controller.MapAttributeDefinition; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.controller.descriptions.ResourceDescriptionResolver; import org.jboss.as.controller.operations.validation.ModelTypeValidator; import org.jboss.as.controller.parsing.Element; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.jboss.dmr.Property; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * {@link MapAttributeDefinition} for maps with keys and values of type {@link ModelType#STRING}. * * @author Paul Ferraro */ public class PropertiesAttributeDefinition extends MapAttributeDefinition { private final Consumer<ModelNode> descriptionContributor; PropertiesAttributeDefinition(Builder builder) { super(builder); this.descriptionContributor = node -> { node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING); node.get(ModelDescriptionConstants.EXPRESSIONS_ALLOWED).set(new ModelNode(this.isAllowExpression())); }; } @Override protected void addValueTypeDescription(ModelNode node, ResourceBundle bundle) { this.descriptionContributor.accept(node); } @Override protected void addAttributeValueTypeDescription(ModelNode node, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) { this.descriptionContributor.accept(node); } @Override protected void addOperationParameterValueTypeDescription(ModelNode node, String operationName, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) { this.descriptionContributor.accept(node); } static final AttributeMarshaller MARSHALLER = new AttributeMarshaller() { @Override public boolean isMarshallableAsElement() { return true; } @Override public void marshallAsElement(AttributeDefinition attribute, ModelNode model, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { if (model.hasDefined(attribute.getName())) { for (Property property : model.get(attribute.getName()).asPropertyList()) { writer.writeStartElement(Element.PROPERTY.getLocalName()); writer.writeAttribute(Element.NAME.getLocalName(), property.getName()); // TODO if WFCORE-4625 goes in, use the util method. String content = property.getValue().asString(); if (content.indexOf('\n') > -1) { // Multiline content. Use the overloaded variant that staxmapper will format writer.writeCharacters(content); } else { // Staxmapper will just output the chars without adding newlines if this is used char[] chars = content.toCharArray(); writer.writeCharacters(chars, 0, chars.length); } writer.writeEndElement(); } } } }; static final AttributeParser PARSER = new AttributeParser() { @Override public boolean isParseAsElement() { return true; } @Override public void parseElement(AttributeDefinition attribute, XMLExtendedStreamReader reader, ModelNode operation) throws XMLStreamException { assert attribute instanceof MapAttributeDefinition; String name = reader.getAttributeValue(null, ModelDescriptionConstants.NAME); ((MapAttributeDefinition) attribute).parseAndAddParameterElement(name, reader.getElementText(), operation, reader); } }; public static class Builder extends MapAttributeDefinition.Builder<Builder, PropertiesAttributeDefinition> { public Builder(String name) { super(name); setRequired(false); this.setAllowNullElement(false); setAttributeMarshaller(MARSHALLER); setAttributeParser(PARSER); } public Builder(PropertiesAttributeDefinition basis) { super(basis); } @Override public PropertiesAttributeDefinition build() { if (this.elementValidator == null) { this.elementValidator = new ModelTypeValidator(ModelType.STRING, this.isNillable(), this.isAllowExpression()); } return new PropertiesAttributeDefinition(this); } } }
5,946
41.177305
176
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ListAttributeTranslation.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 org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; /** * An attribute translator that converts a single value to/from a list of values. * @author Paul Ferraro */ public class ListAttributeTranslation implements AttributeTranslation { private static final AttributeValueTranslator READ_TRANSLATOR = new AttributeValueTranslator() { @Override public ModelNode translate(OperationContext context, ModelNode value) throws OperationFailedException { return value.isDefined() ? value.asList().get(0) : value; } }; private static final AttributeValueTranslator WRITE_TRANSLATOR = new AttributeValueTranslator() { @Override public ModelNode translate(OperationContext context, ModelNode value) throws OperationFailedException { return new ModelNode().add(value); } }; private final Attribute targetAttribute; public ListAttributeTranslation(Attribute targetAttribute) { this.targetAttribute = targetAttribute; } @Override public Attribute getTargetAttribute() { return this.targetAttribute; } @Override public AttributeValueTranslator getReadTranslator() { return READ_TRANSLATOR; } @Override public AttributeValueTranslator getWriteTranslator() { return WRITE_TRANSLATOR; } }
2,502
35.808824
111
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ChildResourceProvider.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 org.jboss.as.controller.registry.Resource; /** * Provides child resources. * @author Paul Ferraro */ public interface ChildResourceProvider { /** * Returns a child resource with the specified name. * @param name a resource name * @return a resource */ Resource getChild(String name); /** * Returns the complete set of child resource names. * @return a set of resource names */ Set<String> getChildren(); }
1,560
32.934783
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/Described.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; /** * Exposes the descriptor of this object. * @author Paul Ferraro */ public interface Described<D> { /** * Returns the descriptor of this object * @return the descriptor of this object */ D getDescriptor(); }
1,306
35.305556
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/IdentityLegacyCapabilityServiceConfigurator.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.Function; import org.jboss.as.clustering.msc.InjectedValueDependency; import org.jboss.as.clustering.msc.ValueDependency; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.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.StopContext; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.SimpleServiceNameProvider; /** * Equivalent to {@link IdentityCapabilityServiceConfigurator}, but uses legacy service installation. * @author Paul Ferraro */ @Deprecated public class IdentityLegacyCapabilityServiceConfigurator<T> extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, Service<T> { private final Function<CapabilityServiceSupport, ServiceName> requirementNameFactory; private final Class<T> targetClass; private volatile ValueDependency<T> requirement; public IdentityLegacyCapabilityServiceConfigurator(ServiceName name, Class<T> targetClass, ServiceNameFactory targetFactory) { this(name, targetClass, new Function<CapabilityServiceSupport, ServiceName>() { @Override public ServiceName apply(CapabilityServiceSupport support) { return targetFactory.getServiceName(support); } }); } public IdentityLegacyCapabilityServiceConfigurator(ServiceName name, Class<T> targetClass, UnaryServiceNameFactory targetFactory, String requirementName) { this(name, targetClass, new Function<CapabilityServiceSupport, ServiceName>() { @Override public ServiceName apply(CapabilityServiceSupport support) { return targetFactory.getServiceName(support, requirementName); } }); } public IdentityLegacyCapabilityServiceConfigurator(ServiceName name, Class<T> targetClass, BinaryServiceNameFactory targetFactory, String requirementParent, String requirementChild) { this(name, targetClass, new Function<CapabilityServiceSupport, ServiceName>() { @Override public ServiceName apply(CapabilityServiceSupport support) { return targetFactory.getServiceName(support, requirementParent, requirementChild); } }); } private IdentityLegacyCapabilityServiceConfigurator(ServiceName name, Class<T> targetClass, Function<CapabilityServiceSupport, ServiceName> requirementNameFactory) { super(name); this.requirementNameFactory = requirementNameFactory; this.targetClass = targetClass; } @Override public ServiceConfigurator configure(CapabilityServiceSupport support) { this.requirement = new InjectedValueDependency<>(this.requirementNameFactory.apply(support), this.targetClass); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); return this.requirement.register(builder).setInstance(this).setInitialMode(ServiceController.Mode.PASSIVE); } @Override public T getValue() { return this.requirement.get(); } @Override public void start(StartContext context) { // Do nothing } @Override public void stop(StopContext context) { // Do nothing } }
4,637
40.410714
187
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CommonRequirement.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 javax.management.MBeanServer; import org.jboss.as.controller.services.path.PathManager; import org.jboss.as.naming.NamingStore; import org.jboss.as.naming.service.NamingService; import org.jboss.as.network.SocketBindingManager; import org.wildfly.clustering.service.Requirement; /** * Enumerates common requirements for clustering resources. * @author Paul Ferraro */ public enum CommonRequirement implements Requirement, ServiceNameFactoryProvider { ELYTRON("org.wildfly.security.elytron", Void.class), LOCAL_TRANSACTION_PROVIDER("org.wildfly.transactions.global-default-local-provider", Void.class), MBEAN_SERVER("org.wildfly.management.jmx", MBeanServer.class), NAMING_STORE(NamingService.CAPABILITY_NAME, NamingStore.class), PATH_MANAGER("org.wildfly.management.path-manager", PathManager.class), SOCKET_BINDING_MANAGER("org.wildfly.management.socket-binding-manager", SocketBindingManager.class), ; private final String name; private final Class<?> type; private final ServiceNameFactory factory = new RequirementServiceNameFactory(this); CommonRequirement(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,540
35.826087
104
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/MetricExecutor.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; /** * Encapsulates the execution of a runtime metric. * @author Paul Ferraro * @param <C> the metric execution context. */ public interface MetricExecutor<C> extends Executor<C, Metric<C>> { }
1,266
38.59375
70
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RemoveStepHandler.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.AbstractRemoveStepHandler; 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.PathAddress; import org.jboss.as.controller.SimpleOperationDefinitionBuilder; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; 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; /** * Generic remove operation step handler that delegates service removal/recovery to a dedicated {@link ResourceServiceHandler}. * @author Paul Ferraro */ public class RemoveStepHandler extends AbstractRemoveStepHandler implements ManagementRegistrar<ManagementResourceRegistration> { private final RemoveStepHandlerDescriptor descriptor; private final ResourceServiceHandler handler; private final OperationEntry.Flag flag; public RemoveStepHandler(RemoveStepHandlerDescriptor descriptor, ResourceServiceHandler handler) { this(descriptor, handler, OperationEntry.Flag.RESTART_RESOURCE_SERVICES); } protected RemoveStepHandler(RemoveStepHandlerDescriptor descriptor, OperationEntry.Flag flag) { this(descriptor, null, flag); } private RemoveStepHandler(RemoveStepHandlerDescriptor descriptor, ResourceServiceHandler handler, OperationEntry.Flag flag) { this.descriptor = descriptor; this.handler = handler; this.flag = flag; } @Override protected boolean requiresRuntime(OperationContext context) { return super.requiresRuntime(context) && (this.handler != null); } @Override protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); if (removeInCurrentStep(resource)) { // We need to remove capabilities *before* removing the resource, since the capability reference resolution might involve reading the resource PathAddress address = context.getCurrentAddress(); for (Map.Entry<Capability, Predicate<ModelNode>> entry : this.descriptor.getCapabilities().entrySet()) { if (entry.getValue().test(model)) { context.deregisterCapability(entry.getKey().resolve(address).getName()); } } 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.removeCapabilityRequirements(context, resource, model.get(attributeName)); } } for (CapabilityReferenceRecorder recorder : registration.getRequirements()) { recorder.removeCapabilityRequirements(context, resource, null); } if (this.requiresRuntime(context)) { for (RuntimeResourceRegistration runtimeRegistration : this.descriptor.getRuntimeResourceRegistrations()) { runtimeRegistration.unregister(context); } } } super.performRemove(context, operation, model); } /* * Determines whether resource removal happens in this step, or a subsequent step */ private static boolean removeInCurrentStep(Resource resource) { for (String childType : resource.getChildTypes()) { for (Resource.ResourceEntry entry : resource.getChildren(childType)) { if (!entry.isRuntime() && resource.hasChild(entry.getPathElement())) { return false; } } } return true; } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { if (context.isResourceServiceRestartAllowed()) { this.handler.removeServices(context, model); } else { context.reloadRequired(); } } @Override protected void recoverServices(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException { if (context.isResourceServiceRestartAllowed()) { this.handler.installServices(context, model); } else { context.revertReloadRequired(); } } @Override protected void recordCapabilitiesAndRequirements(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { // We already unregistered our capabilities in performRemove(...) } @Override public void register(ManagementResourceRegistration registration) { registration.registerOperationHandler(new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.REMOVE, this.descriptor.getDescriptionResolver()).withFlag(this.flag).build(), this.descriptor.getOperationTransformation().apply(this)); } }
6,670
44.380952
246
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RequirementServiceNameFactory.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.Requirement; /** * @author Paul Ferraro */ public class RequirementServiceNameFactory implements ServiceNameFactory { private final Requirement requirement; public RequirementServiceNameFactory(Requirement requirement) { this.requirement = requirement; } @Override public ServiceName getServiceName(OperationContext context) { return context.getCapabilityServiceName(this.requirement.getName(), this.requirement.getType()); } @Override public ServiceName getServiceName(CapabilityServiceSupport support) { return support.getCapabilityServiceName(this.requirement.getName()); } }
1,912
36.509804
104
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ManagementRegistrar.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 a management artifact that can register itself. * This allows a management object to encapsulates specific registration details (e.g. resource aliases) from the parent resource. * @author Paul Ferraro */ public interface ManagementRegistrar<R> { /** * Registers this object with a resource. * @param registration a registration for a management resource */ void register(R registration); }
1,507
39.756757
130
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/UnaryCapabilityNameResolver.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.Function; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; /** * Dynamic name mapper implementations for unary capability names. * @author Paul Ferraro */ public enum UnaryCapabilityNameResolver implements Function<PathAddress, String[]> { DEFAULT() { @Override public String[] apply(PathAddress address) { return new String[] { address.getLastElement().getValue() }; } }, PARENT() { @Override public String[] apply(PathAddress address) { return new String[] { address.getParent().getLastElement().getValue() }; } }, GRANDPARENT() { @Override public String[] apply(PathAddress address) { return new String[] { address.getParent().getParent().getLastElement().getValue() }; } }, LOCAL() { @Override public String[] apply(PathAddress address) { return new String[] { ModelDescriptionConstants.LOCAL }; } }, }
2,149
34.833333
96
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/UnaryServiceNameFactoryProvider.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 unary requirement. * @author Paul Ferraro */ public interface UnaryServiceNameFactoryProvider extends UnaryServiceNameFactory { UnaryServiceNameFactory getServiceNameFactory(); @Override default ServiceName getServiceName(OperationContext context, String name) { return this.getServiceNameFactory().getServiceName(context, name); } @Override default ServiceName getServiceName(CapabilityServiceSupport support, String name) { return this.getServiceNameFactory().getServiceName(support, name); } }
1,844
38.255319
87
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ServiceNameFactory.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 requirement. * @author Paul Ferraro */ public interface ServiceNameFactory { /** * 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); /** * 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); }
1,928
37.58
72
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/CapabilityProvider.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.PathAddress; import org.jboss.as.controller.capability.RuntimeCapability; import org.jboss.msc.service.ServiceName; /** * Provides a capability instance. * Additionally implements {@link Capability}, delegating all methods to the provided capability instance. * @author Paul Ferraro */ public interface CapabilityProvider extends Capability { Capability getCapability(); @Override default RuntimeCapability<?> getDefinition() { return this.getCapability().getDefinition(); } @Override default RuntimeCapability<?> resolve(PathAddress address) { return this.getCapability().resolve(address); } @Override default ServiceName getServiceName(PathAddress address) { return this.getCapability().getServiceName(address); } }
1,891
34.698113
106
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/BinaryCapabilityNameResolver.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.Function; import org.jboss.as.controller.PathAddress; /** * Dynamic name mapper implementations for binary capability names. * @author Paul Ferraro */ public enum BinaryCapabilityNameResolver implements Function<PathAddress, String[]> { PARENT_CHILD() { @Override public String[] apply(PathAddress address) { return new String[] { address.getParent().getLastElement().getValue(), address.getLastElement().getValue() }; } }, GRANDPARENT_PARENT() { @Override public String[] apply(PathAddress address) { PathAddress parent = address.getParent(); return new String[] { parent.getParent().getLastElement().getValue(), parent.getLastElement().getValue() }; } }, GRANDPARENT_CHILD() { @Override public String[] apply(PathAddress address) { return new String[] { address.getParent().getParent().getLastElement().getValue(), address.getLastElement().getValue() }; } }, }
2,107
38.037037
133
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ServiceValueCaptor.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.function.Consumer; import org.wildfly.clustering.service.ServiceNameProvider; /** * Captures the value of a service. * @author Paul Ferraro */ public interface ServiceValueCaptor<T> extends ServiceNameProvider, Consumer<T> { }
1,319
35.666667
81
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/MetricFunction.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.function.Function; import org.jboss.as.controller.OperationFailedException; import org.jboss.dmr.ModelNode; import org.wildfly.common.function.ExceptionFunction; /** * A functional view of a runtime metric. * @author Paul Ferraro * @param <T> the type of value provided by the service on which the given runtime metric operates * @param <V> the type of the value of which the given runtime metric operates */ public class MetricFunction<T, V> implements ExceptionFunction<T, ModelNode, OperationFailedException> { private final Function<T, V> mapper; private final Metric<V> metric; /** * Creates a functional view of the specified metric using the specified mapper. * @param mapper maps the value of a service to the value on which the given metric operates * @param metric a runtime metric */ public MetricFunction(Function<T, V> mapper, Metric<V> metric) { this.mapper = mapper; this.metric = metric; } @Override public ModelNode apply(T value) throws OperationFailedException { V mapped = this.mapper.apply(value); return (mapped != null) ? this.metric.execute(mapped) : null; } }
2,265
38.068966
104
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/UnaryRequirementServiceNameFactory.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.UnaryRequirement; /** * Factory for generating a {@link ServiceName} for a {@link UnaryRequirement}. * @author Paul Ferraro */ public class UnaryRequirementServiceNameFactory implements UnaryServiceNameFactory { private final UnaryRequirement requirement; public UnaryRequirementServiceNameFactory(UnaryRequirement requirement) { this.requirement = requirement; } @Override public ServiceName getServiceName(OperationContext context, String name) { return context.getCapabilityServiceName(this.requirement.getName(), this.requirement.getType(), name); } @Override public ServiceName getServiceName(CapabilityServiceSupport support, String name) { return support.getCapabilityServiceName(this.requirement.getName(), name); } }
2,060
38.634615
110
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleResourceDescriptorConfigurator.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.UnaryOperator; /** * {@link ResourceDescriptor} configurator for the common case of adding an enumeration of attributes. * @author Paul Ferraro */ public class SimpleResourceDescriptorConfigurator<E extends Enum<E> & Attribute> implements UnaryOperator<ResourceDescriptor> { private final Class<E> attributeClass; public SimpleResourceDescriptorConfigurator(Class<E> attributeClass) { this.attributeClass = attributeClass; } @Override public ResourceDescriptor apply(ResourceDescriptor descriptor) { return descriptor.addAttributes(this.attributeClass); } }
1,699
38.534884
127
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ChildResourceDefinition.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.ResourceDescriptionResolver; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Resource definition for child resources that performs all registration via {@link ManagementRegistrar#register(Object)}. * @author Paul Ferraro */ public abstract class ChildResourceDefinition<R extends ManagementResourceRegistration> extends AbstractResourceDefinition implements ChildResourceRegistrar<R> { protected ChildResourceDefinition(PathElement path, ResourceDescriptionResolver resolver) { super(new Parameters(path, resolver)); } protected ChildResourceDefinition(Parameters parameters) { super(parameters); } }
1,826
41.488372
161
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/RestartParentResourceWriteAttributeHandler.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; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.RestartParentWriteAttributeHandler; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelNode; import org.jboss.msc.service.ServiceName; /** * {@link org.jboss.as.controller.RestartParentWriteAttributeHandler} that leverages a {@link ResourceServiceBuilderFactory} for service recreation. * @author Paul Ferraro */ public class RestartParentResourceWriteAttributeHandler extends RestartParentWriteAttributeHandler implements ManagementRegistrar<ManagementResourceRegistration> { private final WriteAttributeStepHandlerDescriptor descriptor; private final ResourceServiceConfiguratorFactory parentFactory; public RestartParentResourceWriteAttributeHandler(ResourceServiceConfiguratorFactory parentFactory, WriteAttributeStepHandlerDescriptor descriptor) { super(null, descriptor.getAttributes()); this.descriptor = descriptor; this.parentFactory = parentFactory; } @Override protected void recreateParentService(OperationContext context, PathAddress parentAddress, ModelNode parentModel) throws OperationFailedException { this.parentFactory.createServiceConfigurator(parentAddress).configure(context, parentModel).build(context.getServiceTarget()).install(); } @Override protected ServiceName getParentServiceName(PathAddress parentAddress) { return this.parentFactory.createServiceConfigurator(parentAddress).getServiceName(); } @Override protected PathAddress getParentAddress(PathAddress address) { return address.getParent(); } @Override public void register(ManagementResourceRegistration registration) { for (AttributeDefinition attribute : this.descriptor.getAttributes()) { registration.registerReadWriteAttribute(attribute, null, this); } } }
3,148
43.352113
163
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceServiceConfiguratorFactory.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.PathAddress; /** * Factory for creating a {@link ResourceServiceConfigurator}. * @author Paul Ferraro */ public interface ResourceServiceConfiguratorFactory { /** * Creates a {@link ServiceConfigurator} for a resource * @param address the path address of this resource * @return a service configurator */ ResourceServiceConfigurator createServiceConfigurator(PathAddress address); }
1,516
36.925
79
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/SimpleAliasEntry.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.ArrayList; import java.util.List; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.AliasEntry; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Simple alias entry that converts address using the alias and target addresses with which it was initialized/registered. * @author Paul Ferraro */ public class SimpleAliasEntry extends AliasEntry { public SimpleAliasEntry(ManagementResourceRegistration registration) { super(registration); } @Override public PathAddress convertToTargetAddress(PathAddress address, AliasContext aliasContext) { PathAddress target = this.getTargetAddress(); List<PathElement> result = new ArrayList<>(address.size()); for (int i = 0; i < address.size(); ++i) { PathElement element = address.getElement(i); if (i < target.size()) { PathElement targetElement = target.getElement(i); result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement); } else { result.add(element); } } return PathAddress.pathAddress(result); } }
2,374
39.948276
141
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/WriteAttributeTranslationHandler.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.dmr.ModelNode; /** * A write-attribute operation handler that translates a value from another attribute * @author Paul Ferraro */ public class WriteAttributeTranslationHandler implements OperationStepHandler { private final AttributeTranslation translation; public WriteAttributeTranslationHandler(AttributeTranslation translation) { this.translation = translation; } @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { ModelNode value = context.resolveExpressions(operation.get(ModelDescriptionConstants.VALUE)); ModelNode targetValue = this.translation.getWriteTranslator().translate(context, value); Attribute targetAttribute = this.translation.getTargetAttribute(); PathAddress currentAddress = context.getCurrentAddress(); PathAddress targetAddress = this.translation.getPathAddressTransformation().apply(currentAddress); ModelNode targetOperation = 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(); if (targetAddress == currentAddress) { writeAttributeHandler.execute(context, targetOperation); } else { context.addStep(targetOperation, writeAttributeHandler, context.getCurrentStage()); } } }
3,405
49.835821
200
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ResourceRegistrar.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.Collection; import java.util.Map; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.ModelOnlyWriteAttributeHandler; import org.jboss.as.controller.OperationDefinition; import org.jboss.as.controller.OperationStepHandler; import org.jboss.as.controller.operations.global.ListOperations; import org.jboss.as.controller.operations.global.MapOperations; import org.jboss.as.controller.operations.global.WriteAttributeHandler; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * Registers add, remove, and write-attribute operation handlers and capabilities. * @author Paul Ferraro */ public class ResourceRegistrar implements ManagementRegistrar<ManagementResourceRegistration> { private final AddStepHandlerDescriptor descriptor; private final ManagementRegistrar<ManagementResourceRegistration> addRegistration; private final ManagementRegistrar<ManagementResourceRegistration> removeRegistration; private final ManagementRegistrar<ManagementResourceRegistration> writeAttributeRegistration; protected ResourceRegistrar(AddStepHandlerDescriptor descriptor, ResourceServiceHandler handler, ManagementRegistrar<ManagementResourceRegistration> addRegistration, ManagementRegistrar<ManagementResourceRegistration> removeRegistration) { this(descriptor, addRegistration, removeRegistration, new WriteAttributeStepHandler(descriptor, handler)); } protected ResourceRegistrar(AddStepHandlerDescriptor descriptor, ManagementRegistrar<ManagementResourceRegistration> addRegistration, ManagementRegistrar<ManagementResourceRegistration> removeRegistration, ManagementRegistrar<ManagementResourceRegistration> writeAttributeRegistration) { this.descriptor = descriptor; this.addRegistration = addRegistration; this.removeRegistration = removeRegistration; this.writeAttributeRegistration = writeAttributeRegistration; } @Override public void register(ManagementResourceRegistration registration) { new CapabilityRegistrar(this.descriptor.getCapabilities().keySet()).register(registration); registration.registerRequirements(this.descriptor.getResourceCapabilityReferences()); // Register standard attributes before add operation this.writeAttributeRegistration.register(registration); // Register attributes with custom write-attribute handlers for (Map.Entry<AttributeDefinition, OperationStepHandler> entry : this.descriptor.getCustomAttributes().entrySet()) { registration.registerReadWriteAttribute(entry.getKey(), null, entry.getValue()); } // Register attributes that will be ignored at runtime Collection<AttributeDefinition> ignoredAttributes = this.descriptor.getIgnoredAttributes(); if (!ignoredAttributes.isEmpty()) { OperationStepHandler writeHandler = new ModelOnlyWriteAttributeHandler(ignoredAttributes); for (AttributeDefinition ignoredAttribute : ignoredAttributes) { registration.registerReadWriteAttribute(ignoredAttribute, null, writeHandler); } } // Register attribute translations for (Map.Entry<AttributeDefinition, AttributeTranslation> entry : this.descriptor.getAttributeTranslations().entrySet()) { AttributeTranslation translation = entry.getValue(); registration.registerReadWriteAttribute(entry.getKey(), new ReadAttributeTranslationHandler(translation), new WriteAttributeTranslationHandler(translation)); } this.addRegistration.register(registration); this.removeRegistration.register(registration); // Override global operations with transformed operations, if necessary this.registerTransformedOperation(registration, WriteAttributeHandler.DEFINITION, WriteAttributeHandler.INSTANCE); this.registerTransformedOperation(registration, MapOperations.MAP_PUT_DEFINITION, MapOperations.MAP_PUT_HANDLER); this.registerTransformedOperation(registration, MapOperations.MAP_GET_DEFINITION, MapOperations.MAP_GET_HANDLER); this.registerTransformedOperation(registration, MapOperations.MAP_REMOVE_DEFINITION, MapOperations.MAP_REMOVE_HANDLER); this.registerTransformedOperation(registration, MapOperations.MAP_CLEAR_DEFINITION, MapOperations.MAP_CLEAR_HANDLER); this.registerTransformedOperation(registration, ListOperations.LIST_ADD_DEFINITION, ListOperations.LIST_ADD_HANDLER); this.registerTransformedOperation(registration, ListOperations.LIST_GET_DEFINITION, ListOperations.LIST_GET_HANDLER); this.registerTransformedOperation(registration, ListOperations.LIST_REMOVE_DEFINITION, ListOperations.LIST_REMOVE_HANDLER); this.registerTransformedOperation(registration, ListOperations.LIST_CLEAR_DEFINITION, ListOperations.LIST_CLEAR_HANDLER); } private void registerTransformedOperation(ManagementResourceRegistration registration, OperationDefinition definition, OperationStepHandler handler) { // Only override global operation handlers for non-identity transformations OperationStepHandler transformedHandler = this.descriptor.getOperationTransformation().apply(handler); if (handler != transformedHandler) { registration.registerOperationHandler(definition, transformedHandler); } } }
6,496
56.495575
291
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/ReloadRequiredAddStepHandler.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.OperationContext; import org.jboss.as.controller.registry.Resource; import org.jboss.dmr.ModelNode; /** * @author Paul Ferraro */ public class ReloadRequiredAddStepHandler extends AddStepHandler { public ReloadRequiredAddStepHandler(AddStepHandlerDescriptor descriptor) { super(descriptor); } @Override protected boolean requiresRuntime(OperationContext context) { return !context.isBooting() && context.isDefaultRequiresRuntime(); } @Override protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) { context.reloadRequired(); } @Override protected void rollbackRuntime(OperationContext context, ModelNode operation, Resource resource) { context.revertReloadRequired(); } }
1,896
34.792453
102
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/descriptions/SimpleResourceDescriptionResolver.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.descriptions; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.ResourceBundle; import java.util.Set; import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; /** * Simple {@link org.jboss.as.controller.descriptions.ResourceDescriptionResolver} implementation * that uses a static name/description mapping. * @author Paul Ferraro */ public class SimpleResourceDescriptionResolver extends StandardResourceDescriptionResolver { final Map<String, String> descriptions = new HashMap<>(); public SimpleResourceDescriptionResolver(String name, String description) { super(name, null, SimpleResourceDescriptionResolver.class.getClassLoader()); this.descriptions.put(name, description); } @Override public ResourceBundle getResourceBundle(Locale locale) { return new ResourceBundle() { @Override protected Object handleGetObject(String key) { return SimpleResourceDescriptionResolver.this.descriptions.get(key); } @Override protected Set<String> handleKeySet() { return SimpleResourceDescriptionResolver.this.descriptions.keySet(); } @Override public Enumeration<String> getKeys() { return Collections.enumeration(this.handleKeySet()); } }; } public void addDescription(String key, String description) { this.descriptions.put(String.join(".", this.getKeyPrefix(), key), description); } }
2,711
36.666667
97
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/SimpleAttributeConverter.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.transform; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.as.controller.transform.description.AttributeConverter; import org.jboss.dmr.ModelNode; /** * Simple {@link AttributeConverter} that provides the operation or model context to a {@link Converter}. * @author Paul Ferraro */ public class SimpleAttributeConverter implements AttributeConverter { public interface Converter { void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context); } private final Converter converter; public SimpleAttributeConverter(Converter converter) { this.converter = converter; } @Override public final void convertOperationParameter(PathAddress address, String name, ModelNode value, ModelNode operation, TransformationContext context) { this.converter.convert(address, name, value, operation, context); } @Override public final void convertResourceAttribute(PathAddress address, String name, ModelNode value, TransformationContext context) { this.converter.convert(address, name, value, context.readResource(PathAddress.EMPTY_ADDRESS).getModel(), context); } }
2,328
41.345455
152
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/SingletonListAttributeConverter.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.transform; import java.util.List; import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.dmr.ModelNode; /** * Converts a singleton list to a single value. * @author Paul Ferraro */ public class SingletonListAttributeConverter extends SimpleAttributeConverter { public SingletonListAttributeConverter(Attribute listAttribute) { this(listAttribute.getDefinition()); } public SingletonListAttributeConverter(AttributeDefinition listAttribute) { super(new Converter() { @Override public void convert(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) { if (model.hasDefined(listAttribute.getName())) { List<ModelNode> list = model.get(listAttribute.getName()).asList(); if (!list.isEmpty()) { value.set(list.get(0)); } } } }); } }
2,217
37.912281
132
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/RequiredChildResourceDiscardPolicy.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.transform; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.ImmutableManagementResourceRegistration; import org.jboss.as.controller.registry.Resource; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.as.controller.transform.description.DiscardPolicy; import org.jboss.as.controller.transform.description.DynamicDiscardPolicy; import org.jboss.dmr.ModelNode; /** * Implementation of a generic {@link DynamicDiscardPolicy} that discards child resources which have all their attribute undefined and have no children. * Conditionally rejects or leaves resource for further transformation. It is to be used for required child resources that are auto-created. * * @author Radoslav Husar */ public enum RequiredChildResourceDiscardPolicy implements DynamicDiscardPolicy { /** * Policy that discards if all attributes are undefined and resource has no children; rejects otherwise. */ REJECT_AND_WARN(DiscardPolicy.REJECT_AND_WARN), /** * Policy that discards if all attributes are undefined and resource has no children; * never discards otherwise ({@link DiscardPolicy#NEVER}) in order to proceed with resource transformations. */ NEVER(DiscardPolicy.NEVER), ; private final DiscardPolicy policy; RequiredChildResourceDiscardPolicy(DiscardPolicy policy) { this.policy = policy; } /** * @return contextual discard policy if any resource attributes are undefined and has no children; {@link DiscardPolicy#SILENT} otherwise. */ @Override public DiscardPolicy checkResource(TransformationContext context, PathAddress address) { Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS); ImmutableManagementResourceRegistration registration = context.getResourceRegistration(PathAddress.EMPTY_ADDRESS); ModelNode model = resource.getModel(); if (model.isDefined()) { for (String attribute : registration.getAttributeNames(PathAddress.EMPTY_ADDRESS)) { if (model.hasDefined(attribute)) { return this.policy; } } } for (PathElement path : registration.getChildAddresses(PathAddress.EMPTY_ADDRESS)) { if (path.isWildcard() ? resource.hasChildren(path.getKey()) : resource.hasChild(path)) { return this.policy; } } return DiscardPolicy.SILENT; } }
3,605
41.423529
152
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/RejectNonSingletonListAttributeChecker.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.transform; import java.util.Map; import java.util.Set; import org.jboss.as.clustering.logging.ClusteringLogger; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.as.controller.transform.description.RejectAttributeChecker; import org.jboss.dmr.ModelNode; /** * Rejects a list attribute if it contains more than one element. * @author Paul Ferraro */ public enum RejectNonSingletonListAttributeChecker implements RejectAttributeChecker { INSTANCE; private final RejectAttributeChecker checker = new org.jboss.as.clustering.controller.transform.SimpleRejectAttributeChecker(new org.jboss.as.clustering.controller.transform.SimpleRejectAttributeChecker.Rejecter() { @Override public boolean reject(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context) { return value.isDefined() && value.asList().size() > 1; } @Override public String getRejectedMessage(Set<String> attributes) { return ClusteringLogger.ROOT_LOGGER.rejectedMultipleValues(attributes); } }); @Override public boolean rejectOperationParameter(PathAddress address, String attributeName, ModelNode attributeValue, ModelNode operation, TransformationContext context) { return this.checker.rejectOperationParameter(address, attributeName, attributeValue, operation, context); } @Override public boolean rejectResourceAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { return this.checker.rejectResourceAttribute(address, attributeName, attributeValue, context); } @Override public String getRejectionLogMessageId() { return this.checker.getRejectionLogMessageId(); } @Override public String getRejectionLogMessage(Map<String, ModelNode> attributes) { return this.checker.getRejectionLogMessage(attributes); } }
3,093
40.810811
219
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/UndefinedAttributesDiscardPolicy.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.transform; import java.util.Arrays; import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.registry.Resource; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.as.controller.transform.description.DiscardPolicy; import org.jboss.as.controller.transform.description.DynamicDiscardPolicy; import org.jboss.dmr.ModelNode; /** * Convenience implementation of {@link DynamicDiscardPolicy} that silently discards (i.e. {@link DiscardPolicy#SILENT}) if none of the attributes are defined; * rejects otherwise (i.e. {@link DiscardPolicy#REJECT_AND_WARN}. * * @author Radoslav Husar * @version August 2015 */ public class UndefinedAttributesDiscardPolicy implements DynamicDiscardPolicy { private final Iterable<Attribute> attributes; public UndefinedAttributesDiscardPolicy(Attribute... attributes) { this(Arrays.asList(attributes)); } public UndefinedAttributesDiscardPolicy(Iterable<Attribute> attributes) { this.attributes = attributes; } @Override public DiscardPolicy checkResource(TransformationContext context, PathAddress address) { ModelNode model = Resource.Tools.readModel(context.readResourceFromRoot(address)); for (Attribute attribute : this.attributes) { if (model.hasDefined(attribute.getName())) { return DiscardPolicy.REJECT_AND_WARN; } } return DiscardPolicy.SILENT; } }
2,585
38.784615
159
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/DiscardSingletonListAttributeChecker.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.transform; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.as.controller.transform.description.DiscardAttributeChecker; import org.jboss.dmr.ModelNode; /** * Discards an attribute if its list value contains a single entry. * @author Paul Ferraro */ public enum DiscardSingletonListAttributeChecker implements DiscardAttributeChecker { INSTANCE; private final DiscardAttributeChecker checker = new DiscardAttributeChecker.DefaultDiscardAttributeChecker() { @Override protected boolean isValueDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { return !attributeValue.isDefined() || attributeValue.asList().size() <= 1; } }; @Override public boolean isDiscardExpressions() { return this.checker.isDiscardExpressions(); } @Override public boolean isDiscardUndefined() { return this.checker.isDiscardUndefined(); } @Override public boolean isOperationParameterDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, ModelNode operation, TransformationContext context) { return this.checker.isOperationParameterDiscardable(address, attributeName, attributeValue, operation, context); } @Override public boolean isResourceAttributeDiscardable(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { return this.checker.isResourceAttributeDiscardable(address, attributeName, attributeValue, context); } }
2,713
41.40625
173
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/RejectAttributeValueChecker.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.transform; import java.util.Map; import org.jboss.as.clustering.logging.ClusteringLogger; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.as.controller.transform.description.RejectAttributeChecker; import org.jboss.dmr.ModelNode; /** * @author Paul Ferraro */ public enum RejectAttributeValueChecker implements RejectAttributeChecker { NEGATIVE() { @Override boolean isRejected(ModelNode value) { return value.asLong() < 0; } @Override public String getRejectionLogMessage(Map<String, ModelNode> attributes) { return ClusteringLogger.ROOT_LOGGER.attributesDoNotSupportNegativeValues(attributes.keySet()); } }, ZERO() { @Override boolean isRejected(ModelNode value) { return value.asLong() == 0L; } @Override public String getRejectionLogMessage(Map<String, ModelNode> attributes) { return ClusteringLogger.ROOT_LOGGER.attributesDoNotSupportNegativeValues(attributes.keySet()); } }, ; @Override public boolean rejectOperationParameter(PathAddress address, String attributeName, ModelNode attributeValue, ModelNode operation, TransformationContext context) { return attributeValue.isDefined() && !RejectAttributeChecker.SIMPLE_EXPRESSIONS.rejectOperationParameter(address, attributeName, attributeValue, operation, context) && this.isRejected(attributeValue); } @Override public boolean rejectResourceAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { return attributeValue.isDefined() && !RejectAttributeChecker.SIMPLE_EXPRESSIONS.rejectResourceAttribute(address, attributeName, attributeValue, context) && this.isRejected(attributeValue); } @Override public String getRejectionLogMessageId() { return this.getClass().getName(); } abstract boolean isRejected(ModelNode value); }
3,122
39.038462
208
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/transform/SimpleRejectAttributeChecker.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.transform; import java.util.Map; import java.util.Set; import java.util.UUID; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.transform.TransformationContext; import org.jboss.as.controller.transform.description.RejectAttributeChecker; import org.jboss.dmr.ModelNode; /** * Simple {@link RejectAttributeChecker} that provides the operation or model context to a {@link Rejecter}. * @author Paul Ferraro */ public class SimpleRejectAttributeChecker implements RejectAttributeChecker { public interface Rejecter { boolean reject(PathAddress address, String name, ModelNode value, ModelNode model, TransformationContext context); String getRejectedMessage(Set<String> attributes); } private final String logMessageId = UUID.randomUUID().toString(); private final Rejecter rejecter; public SimpleRejectAttributeChecker(Rejecter rejecter) { this.rejecter = rejecter; } @Override public boolean rejectOperationParameter(PathAddress address, String name, ModelNode value, ModelNode operation, TransformationContext context) { return this.rejecter.reject(address, name, value, operation, context); } @Override public boolean rejectResourceAttribute(PathAddress address, String name, ModelNode value, TransformationContext context) { return this.rejecter.reject(address, name, value, context.readResource(PathAddress.EMPTY_ADDRESS).getModel(), context); } @Override public String getRejectionLogMessageId() { return this.logMessageId; } @Override public String getRejectionLogMessage(Map<String, ModelNode> attributes) { return this.rejecter.getRejectedMessage(attributes.keySet()); } }
2,813
38.083333
148
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/validation/LongRangeValidatorBuilder.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.validation; import org.jboss.as.controller.operations.validation.LongRangeValidator; import org.jboss.as.controller.operations.validation.ParameterValidator; /** * @author Paul Ferraro */ public class LongRangeValidatorBuilder extends AbstractParameterValidatorBuilder { private volatile long min = Long.MIN_VALUE; private volatile long max = Long.MAX_VALUE; public LongRangeValidatorBuilder min(long min) { this.min = min; return this; } public LongRangeValidatorBuilder max(long max) { this.max = max; return this; } @Override public ParameterValidator build() { return new LongRangeValidator(this.min, this.max, this.allowsUndefined, this.allowsExpressions); } }
1,817
34.647059
104
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/validation/IntRangeValidatorBuilder.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.validation; import org.jboss.as.controller.operations.validation.IntRangeValidator; import org.jboss.as.controller.operations.validation.ParameterValidator; /** * @author Paul Ferraro */ public class IntRangeValidatorBuilder extends AbstractParameterValidatorBuilder { private volatile int min = Integer.MIN_VALUE; private volatile int max = Integer.MAX_VALUE; public IntRangeValidatorBuilder min(int min) { this.min = min; return this; } public IntRangeValidatorBuilder max(int max) { this.max = max; return this; } @Override public ParameterValidator build() { return new IntRangeValidator(this.min, this.max, this.allowsUndefined, this.allowsExpressions); } }
1,814
34.588235
103
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/validation/ModuleIdentifierValidatorBuilder.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.validation; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.operations.validation.ModelTypeValidator; import org.jboss.as.controller.operations.validation.ParameterValidator; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * {@link ParameterValidatorBuilder} that builds a validator that validates that a given value is a valid {@link ModuleIdentifier}. * @author Paul Ferraro */ public class ModuleIdentifierValidatorBuilder extends AbstractParameterValidatorBuilder { @Override public ParameterValidator build() { return new ModuleIdentifierValidator(this.allowsUndefined, this.allowsExpressions); } private static class ModuleIdentifierValidator extends ModelTypeValidator { ModuleIdentifierValidator(boolean allowsUndefined, boolean allowsExpression) { super(ModelType.STRING, allowsUndefined, allowsExpression); } @SuppressWarnings("deprecation") @Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined()) { String module = value.asString(); try { org.jboss.modules.ModuleIdentifier.fromString(module); } catch (IllegalArgumentException e) { throw new OperationFailedException(e.getMessage() + ": " + module, e); } } } } }
2,616
40.539683
131
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/validation/DoubleRangeValidatorBuilder.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 org.jboss.as.clustering.logging.ClusteringLogger; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.operations.validation.ModelTypeValidator; import org.jboss.as.controller.operations.validation.ParameterValidator; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; /** * A builder for creating a range validator for {@link ModelType#DOUBLE} parameters. * @author Paul Ferraro */ public class DoubleRangeValidatorBuilder extends AbstractParameterValidatorBuilder { private Bound upperBound; private Bound lowerBound; /** * Sets an inclusive lower bound of this validator. * @param value the lower bound */ public DoubleRangeValidatorBuilder lowerBound(double value) { this.lowerBound = new Bound(value, false); return this; } /** * Sets an exclusive lower bound of this validator. * @param value the lower bound */ public DoubleRangeValidatorBuilder lowerBoundExclusive(double value) { this.lowerBound = new Bound(value, true); return this; } /** * Sets the inclusive upper bound of this validator. * @param value the upper bound */ public DoubleRangeValidatorBuilder upperBound(double value) { this.upperBound = new Bound(value, false); return this; } /** * Sets the exclusive upper bound of this validator. * @param value the upper bound */ public DoubleRangeValidatorBuilder upperBoundExclusive(double value) { this.upperBound = new Bound(value, true); return this; } @Override public ParameterValidator build() { return new DoubleRangeValidator(this.lowerBound, this.upperBound, this.allowsUndefined, this.allowsExpressions); } private static class Bound { private final double value; private final boolean exclusive; Bound(double value, boolean exclusive) { this.value = value; this.exclusive = exclusive; } double getValue() { return this.value; } boolean isExclusive() { return this.exclusive; } } private static class DoubleRangeValidator extends ModelTypeValidator { private final Bound lowerBound; private final Bound upperBound; /** * Creates an upper- and lower-bounded validator. * @param lowerBound the lower bound * @param upperBound the upper bound * @param nullable indicates whether {@link ModelType#UNDEFINED} is allowed * @param allowExpressions whether {@link ModelType#EXPRESSION} is allowed */ DoubleRangeValidator(Bound lowerBound, Bound upperBound, boolean nullable, boolean allowExpressions) { super(ModelType.DOUBLE, nullable, allowExpressions, false); this.lowerBound = lowerBound; this.upperBound = upperBound; } @Override public void validateParameter(String parameterName, ModelNode parameterValue) throws OperationFailedException { super.validateParameter(parameterName, parameterValue); if (parameterValue.isDefined() && parameterValue.getType() != ModelType.EXPRESSION) { double value = parameterValue.asDouble(); if (this.lowerBound != null) { double bound = this.lowerBound.getValue(); boolean exclusive = this.lowerBound.isExclusive(); if ((value < bound) || (exclusive && (value == bound))) { throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? ">" : ">=", bound); } } if (this.upperBound != null) { double bound = this.upperBound.getValue(); boolean exclusive = this.upperBound.isExclusive(); if ((value > bound) || (exclusive && (value == bound))) { throw ClusteringLogger.ROOT_LOGGER.parameterValueOutOfBounds(parameterName, value, exclusive ? "<" : "<=", bound); } } } } } }
5,319
37.550725
138
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/validation/ParameterValidatorBuilder.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 org.jboss.as.controller.AbstractAttributeDefinitionBuilder; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.operations.validation.ParameterValidator; /** * Builder for a {@link ParameterValidator}. * @author Paul Ferraro */ public interface ParameterValidatorBuilder { /** * Configures this validator builder using the configuration of the specified attribute definition * @param definition an attribute definition * @return a reference to this builder */ ParameterValidatorBuilder configure(AttributeDefinition definition); /** * Configures this validator builder using the configuration of the specified attribute definition builder * @param builder an attribute definition builder * @return a reference to this builder */ ParameterValidatorBuilder configure(AbstractAttributeDefinitionBuilder<?, ?> builder); /** * Builds the validator. * @return a parameter validator */ ParameterValidator build(); }
2,112
38.12963
110
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/controller/validation/AbstractParameterValidatorBuilder.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.validation; import org.jboss.as.controller.AbstractAttributeDefinitionBuilder; import org.jboss.as.controller.AttributeDefinition; /** * @author Paul Ferraro */ public abstract class AbstractParameterValidatorBuilder implements ParameterValidatorBuilder { boolean allowsUndefined = false; boolean allowsExpressions = false; @Override public ParameterValidatorBuilder configure(AttributeDefinition definition) { this.allowsExpressions = definition.isAllowExpression(); this.allowsUndefined = !definition.isRequired(); return this; } @Override public ParameterValidatorBuilder configure(AbstractAttributeDefinitionBuilder<?, ?> builder) { this.allowsExpressions = builder.isAllowExpression(); this.allowsUndefined = builder.isNillable(); return this; } }
1,907
37.16
98
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/logging/ClusteringLogger.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.logging; import static org.jboss.logging.Logger.Level.WARN; import java.util.Set; import org.jboss.as.controller.OperationFailedException; import org.jboss.logging.BasicLogger; import org.jboss.logging.Logger; import org.jboss.logging.annotations.Cause; import org.jboss.logging.annotations.LogMessage; import org.jboss.logging.annotations.Message; import org.jboss.logging.annotations.MessageLogger; /** * @author Paul Ferraro */ @MessageLogger(projectCode = "WFLYCLCOM", length = 4) public interface ClusteringLogger extends BasicLogger { String ROOT_LOGGER_CATEGORY = "org.jboss.as.clustering"; /** * The root logger. */ ClusteringLogger ROOT_LOGGER = Logger.getMessageLogger(ClusteringLogger.class, ROOT_LOGGER_CATEGORY); @Message(id = 1, value = "%2$g is not a valid value for parameter %1$s. The value must be %3$s %4$g") OperationFailedException parameterValueOutOfBounds(String name, double value, String relationalOperator, double bound); @Message(id = 2, value = "Failed to close %s") @LogMessage(level = WARN) void failedToClose(@Cause Throwable cause, Object value); @Message(id = 3, value = "The following attributes do not support negative values: %s") String attributesDoNotSupportNegativeValues(Set<String> attributes); @Message(id = 4, value = "The following attributes do not support zero values: %s") String attributesDoNotSupportZeroValues(Set<String> attributes); @Message(id = 5, value = "Legacy host does not support multiple values for attributes: %s") String rejectedMultipleValues(Set<String> attributes); @LogMessage(level = WARN) @Message(id = 6, value = "The '%s' attribute of the '%s' element is no longer supported and will be ignored") void attributeIgnored(String attribute, String element); @LogMessage(level = WARN) @Message(id = 7, value = "The '%s' element is no longer supported and will be ignored") void elementIgnored(String element); @Message(id = 8, value = "%s:%s operation is only supported in admin-only mode.") OperationFailedException operationNotSupportedInNormalServerMode(String address, String operation); }
3,230
40.961039
123
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/naming/NamespaceContextualizerFactory.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.naming; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.context.Contextualizer; import org.wildfly.clustering.context.ContextualizerFactory; /** * @author Paul Ferraro */ @MetaInfServices(ContextualizerFactory.class) public class NamespaceContextualizerFactory implements ContextualizerFactory { @Override public Contextualizer createContextualizer(ClassLoader loader) { return new NamespaceContextExecutor(); } }
1,513
36.85
78
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/naming/NamespaceContextExecutor.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.naming; import java.util.concurrent.Callable; import java.util.function.Supplier; import org.jboss.as.naming.context.NamespaceContextSelector; import org.wildfly.clustering.context.ContextualExecutor; import org.wildfly.common.function.ExceptionRunnable; import org.wildfly.common.function.ExceptionSupplier; /** * A contextual executor that applies namespace context that was active when this object was constructed. * @author Paul Ferraro */ public class NamespaceContextExecutor implements ContextualExecutor { private final NamespaceContextSelector selector = NamespaceContextSelector.getCurrentSelector(); @Override public void execute(Runnable runner) { if (this.selector != null) { NamespaceContextSelector.pushCurrentSelector(this.selector); } try { runner.run(); } finally { if (this.selector != null) { NamespaceContextSelector.popCurrentSelector(); } } } @Override public <E extends Exception> void execute(ExceptionRunnable<E> runner) throws E { if (this.selector != null) { NamespaceContextSelector.pushCurrentSelector(this.selector); } try { runner.run(); } finally { if (this.selector != null) { NamespaceContextSelector.popCurrentSelector(); } } } @Override public <T> T execute(Callable<T> caller) throws Exception { if (this.selector != null) { NamespaceContextSelector.pushCurrentSelector(this.selector); } try { return caller.call(); } finally { if (this.selector != null) { NamespaceContextSelector.popCurrentSelector(); } } } @Override public <T> T execute(Supplier<T> supplier) { if (this.selector != null) { NamespaceContextSelector.pushCurrentSelector(this.selector); } try { return supplier.get(); } finally { if (this.selector != null) { NamespaceContextSelector.popCurrentSelector(); } } } @Override public <T, E extends Exception> T execute(ExceptionSupplier<T, E> supplier) throws E { if (this.selector != null) { NamespaceContextSelector.pushCurrentSelector(this.selector); } try { return supplier.get(); } finally { if (this.selector != null) { NamespaceContextSelector.popCurrentSelector(); } } } @Override public Runnable contextualize(Runnable runner) { return (this.selector != null) ? ContextualExecutor.super.contextualize(runner) : runner; } @Override public <E extends Exception> ExceptionRunnable<E> contextualize(ExceptionRunnable<E> runner) { return (this.selector != null) ? ContextualExecutor.super.contextualize(runner) : runner; } @Override public <T> Callable<T> contextualize(Callable<T> caller) { return (this.selector != null) ? ContextualExecutor.super.contextualize(caller) : caller; } @Override public <T> Supplier<T> contextualize(Supplier<T> supplier) { return (this.selector != null) ? ContextualExecutor.super.contextualize(supplier) : supplier; } @Override public <T, E extends Exception> ExceptionSupplier<T, E> contextualize(ExceptionSupplier<T, E> supplier) { return (this.selector != null) ? ContextualExecutor.super.contextualize(supplier) : supplier; } }
4,677
33.397059
109
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/naming/BinderServiceConfigurator.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.naming; import java.util.LinkedList; import java.util.List; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.clustering.controller.CommonRequirement; import org.jboss.as.controller.OperationContext; import org.jboss.as.naming.ManagedReferenceFactory; import org.jboss.as.naming.ManagedReferenceInjector; import org.jboss.as.naming.ServiceBasedNamingStore; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.service.BinderService; 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.ServiceConfigurator; import org.wildfly.clustering.service.SimpleServiceNameProvider; /** * Configures a service providing a ManagedReferenceFactory JNDI binding. * @author Paul Ferraro */ public class BinderServiceConfigurator extends SimpleServiceNameProvider implements CapabilityServiceConfigurator { private final ContextNames.BindInfo binding; private final ServiceName targetServiceName; private final List<ContextNames.BindInfo> aliases = new LinkedList<>(); private volatile boolean enabled = true; public BinderServiceConfigurator(ContextNames.BindInfo binding, ServiceName targetServiceName) { super(binding.getBinderServiceName()); this.binding = binding; this.targetServiceName = targetServiceName; } public BinderServiceConfigurator alias(ContextNames.BindInfo alias) { this.aliases.add(alias); return this; } @Override public ServiceConfigurator configure(OperationContext context) { this.enabled = context.hasOptionalCapability(CommonRequirement.NAMING_STORE.getName(), null, null); return this; } @SuppressWarnings("deprecation") @Override public ServiceBuilder<?> build(ServiceTarget target) { if (!this.enabled) { // If naming is not enabled, just install a dummy service that never starts return target.addService(this.getServiceName()).setInitialMode(ServiceController.Mode.NEVER); } String name = this.binding.getBindName(); BinderService binder = new BinderService(name); // Until ServiceBasedNamingStore works with new MSC API, we need to use deprecated ServiceBuilder methods ServiceBuilder<ManagedReferenceFactory> builder = target.addService(this.getServiceName(), binder) .addAliases(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(name)) .addDependency(this.targetServiceName, Object.class, new ManagedReferenceInjector<>(binder.getManagedObjectInjector())) .addDependency(this.binding.getParentContextServiceName(), ServiceBasedNamingStore.class, binder.getNamingStoreInjector()) ; for (ContextNames.BindInfo alias : this.aliases) { builder.addAliases(alias.getBinderServiceName(), ContextNames.JAVA_CONTEXT_SERVICE_NAME.append(alias.getBindName())); } return builder.setInitialMode(ServiceController.Mode.PASSIVE); } }
4,214
44.815217
138
java
null
wildfly-main/clustering/common/src/main/java/org/jboss/as/clustering/naming/JndiNameFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2013, 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.naming; import org.jboss.as.naming.deployment.JndiName; /** * Factory methods for creating a JndiName. * @author Paul Ferraro */ public class JndiNameFactory { public static final String DEFAULT_JNDI_NAMESPACE = "java:jboss"; public static final String DEFAULT_LOCAL_NAME = "default"; public static JndiName parse(String value) { return value.startsWith("java:") ? JndiName.of(value) : createJndiName(DEFAULT_JNDI_NAMESPACE, value.startsWith("/") ? value.substring(1) : value); } public static JndiName createJndiName(String namespace, String... contexts) { JndiName name = JndiName.of(namespace); for (String context: contexts) { name = name.append((context != null) ? context : DEFAULT_LOCAL_NAME); } return name; } private JndiNameFactory() { // Hide } }
1,913
37.28
155
java
null
wildfly-main/clustering/web/extension/src/test/java/org/wildfly/extension/clustering/web/DistributableWebTransformerTestCase.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.wildfly.extension.clustering.web; import java.util.EnumSet; import java.util.List; import org.jboss.as.clustering.subsystem.AdditionalInitialization; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PathAddress; import org.jboss.as.controller.descriptions.ModelDescriptionConstants; import org.jboss.as.model.test.FailedOperationTransformationConfig; import org.jboss.as.model.test.ModelTestControllerVersion; import org.jboss.as.model.test.ModelTestUtils; import org.jboss.as.subsystem.test.AbstractSubsystemTest; import org.jboss.as.subsystem.test.KernelServices; import org.jboss.as.subsystem.test.KernelServicesBuilder; import org.jboss.dmr.ModelNode; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.wildfly.clustering.infinispan.client.service.InfinispanClientRequirement; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement; import org.wildfly.clustering.infinispan.service.InfinispanRequirement; /** * Transformer tests for distributable-web subsystem. * @author Paul Ferraro */ @RunWith(value = Parameterized.class) public class DistributableWebTransformerTestCase extends AbstractSubsystemTest { @Parameters public static Iterable<ModelTestControllerVersion> parameters() { return EnumSet.of(ModelTestControllerVersion.EAP_7_4_0); } private final ModelTestControllerVersion controller; private final org.jboss.as.subsystem.test.AdditionalInitialization additionalInitialization; private final ModelVersion version; public DistributableWebTransformerTestCase(ModelTestControllerVersion controller) { super(DistributableWebExtension.SUBSYSTEM_NAME, new DistributableWebExtension()); this.controller = controller; this.version = this.getModelVersion().getVersion(); this.additionalInitialization = new AdditionalInitialization() .require(InfinispanRequirement.CONTAINER.resolve("foo")) .require(InfinispanDefaultCacheRequirement.CACHE.resolve("foo")) .require(InfinispanDefaultCacheRequirement.CONFIGURATION.resolve("foo")) .require(InfinispanCacheRequirement.CACHE.resolve("foo", "bar")) .require(InfinispanCacheRequirement.CONFIGURATION.resolve("foo", "bar")) .require(InfinispanClientRequirement.REMOTE_CONTAINER.resolve("foo")) .require(InfinispanCacheRequirement.CACHE.resolve("foo", "routing")) .require(InfinispanCacheRequirement.CONFIGURATION.resolve("foo", "routing")) ; } private String formatSubsystemArtifact() { return this.formatArtifact("org.jboss.eap:wildfly-clustering-web-extension:%s"); } private String formatArtifact(String pattern) { return String.format(pattern, this.controller.getMavenGavVersion()); } private DistributableWebSubsystemModel getModelVersion() { switch (this.controller) { case EAP_7_4_0: return DistributableWebSubsystemModel.VERSION_2_0_0; default: throw new IllegalArgumentException(); } } private String[] getDependencies() { switch (this.controller) { case EAP_7_4_0: return new String[] { formatSubsystemArtifact(), formatArtifact("org.jboss.eap:wildfly-clustering-common:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-ee-hotrod:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-ee-infinispan:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-ee-spi:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-infinispan-client:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-infinispan-spi:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-marshalling-spi:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-service:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-web-container:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-web-hotrod:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-web-infinispan:%s"), formatArtifact("org.jboss.eap:wildfly-clustering-web-spi:%s"), }; default: throw new IllegalArgumentException(); } } /** * Tests transformation of model from current version into specified version. */ @Test public void testTransformation() throws Exception { String subsystemXmlResource = String.format("wildfly-distributable-web-transform-%d_%d_%d.xml", this.version.getMajor(), this.version.getMinor(), this.version.getMicro()); // create builder for current subsystem version KernelServicesBuilder builder = createKernelServicesBuilder(this.additionalInitialization) .setSubsystemXmlResource(subsystemXmlResource); // initialize the legacy services and add required jars builder.createLegacyKernelServicesBuilder(this.additionalInitialization, this.controller, this.version) .addMavenResourceURL(this.getDependencies()) .addSingleChildFirstClass(AdditionalInitialization.class) .skipReverseControllerCheck() .dontPersistXml(); KernelServices services = builder.build(); Assert.assertTrue(services.isSuccessfulBoot()); Assert.assertTrue(services.getLegacyServices(this.version).isSuccessfulBoot()); // check that both versions of the legacy model are the same and valid checkSubsystemModelTransformation(services, this.version, null, false); } /** * Tests rejected transformation of the model from current version into specified version. */ @Test public void testRejections() throws Exception { // create builder for current subsystem version KernelServicesBuilder builder = createKernelServicesBuilder(this.additionalInitialization); // initialize the legacy services and add required jars builder.createLegacyKernelServicesBuilder(this.additionalInitialization, this.controller, this.version) .addMavenResourceURL(this.getDependencies()) .addSingleChildFirstClass(AdditionalInitialization.class) .dontPersistXml(); KernelServices services = builder.build(); Assert.assertTrue(services.isSuccessfulBoot()); KernelServices legacyServices = services.getLegacyServices(this.version); Assert.assertNotNull(legacyServices); Assert.assertTrue(legacyServices.isSuccessfulBoot()); List<ModelNode> operations = builder.parseXmlResource("wildfly-distributable-web-transform-reject.xml"); ModelTestUtils.checkFailedTransformedBootOperations(services, this.version, operations, this.createFailedOperationTransformationConfig()); } private FailedOperationTransformationConfig createFailedOperationTransformationConfig() { FailedOperationTransformationConfig config = new FailedOperationTransformationConfig(); PathAddress subsystemAddress = PathAddress.pathAddress(ModelDescriptionConstants.SUBSYSTEM, DistributableWebExtension.SUBSYSTEM_NAME); if (DistributableWebSubsystemModel.VERSION_3_0_0.requiresTransformation(this.version)) { config.addFailedAttribute(subsystemAddress.append(InfinispanSessionManagementResourceDefinition.pathElement("protostream")), new FailedOperationTransformationConfig.NewAttributesConfig(SessionManagementResourceDefinition.Attribute.MARSHALLER.getName())); config.addFailedAttribute(subsystemAddress.append(HotRodSessionManagementResourceDefinition.pathElement("remote-protostream")), new FailedOperationTransformationConfig.NewAttributesConfig(SessionManagementResourceDefinition.Attribute.MARSHALLER.getName())); } return config; } }
9,354
49.842391
269
java
null
wildfly-main/clustering/web/extension/src/test/java/org/wildfly/extension/clustering/web/DistributableWebSubsystemTestCase.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.wildfly.extension.clustering.web; import java.util.EnumSet; import org.jboss.as.clustering.subsystem.AdditionalInitialization; import org.jboss.as.subsystem.test.AbstractSubsystemSchemaTest; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.wildfly.clustering.infinispan.client.service.InfinispanClientRequirement; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement; /** * Unit test for distributable-web subsystem. * @author Paul Ferraro */ @RunWith(value = Parameterized.class) public class DistributableWebSubsystemTestCase extends AbstractSubsystemSchemaTest<DistributableWebSubsystemSchema> { @Parameters public static Iterable<DistributableWebSubsystemSchema> parameters() { return EnumSet.allOf(DistributableWebSubsystemSchema.class); } public DistributableWebSubsystemTestCase(DistributableWebSubsystemSchema schema) { super(DistributableWebExtension.SUBSYSTEM_NAME, new DistributableWebExtension(), schema, DistributableWebSubsystemSchema.CURRENT); } @Override protected org.jboss.as.subsystem.test.AdditionalInitialization createAdditionalInitialization() { return new AdditionalInitialization() .require(InfinispanDefaultCacheRequirement.CONFIGURATION, "foo") .require(InfinispanCacheRequirement.CONFIGURATION, "foo", "bar") .require(InfinispanClientRequirement.REMOTE_CONTAINER, "foo") ; } }
2,662
43.383333
138
java
null
wildfly-main/clustering/web/extension/src/test/java/org/wildfly/extension/clustering/web/deployment/DistributableWebDeploymentXMLReaderTestCase.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.wildfly.extension.clustering.web.deployment; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Arrays; import java.util.EnumSet; import java.util.Locale; import java.util.UUID; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.metadata.property.PropertyReplacers; import org.jboss.staxmapper.XMLMapper; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; import org.wildfly.clustering.web.infinispan.routing.RankedRoutingConfiguration; import org.wildfly.clustering.web.infinispan.session.InfinispanSessionManagementConfiguration; import org.wildfly.clustering.web.service.session.DistributableSessionManagementProvider; import org.wildfly.clustering.web.session.DistributableSessionManagementConfiguration; import org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy; import org.wildfly.extension.clustering.web.routing.NullRouteLocatorServiceConfiguratorFactory; import org.wildfly.extension.clustering.web.routing.infinispan.RankedRouteLocatorServiceConfiguratorFactory; import org.wildfly.extension.clustering.web.session.hotrod.HotRodSessionManagementConfiguration; import org.wildfly.extension.clustering.web.session.hotrod.HotRodSessionManagementProvider; import org.wildfly.extension.clustering.web.session.infinispan.InfinispanSessionManagementProvider; /** * @author Paul Ferraro */ @RunWith(value = Parameterized.class) public class DistributableWebDeploymentXMLReaderTestCase { @Parameters public static Iterable<DistributableWebDeploymentSchema> parameters() { return EnumSet.allOf(DistributableWebDeploymentSchema.class); } private final DistributableWebDeploymentSchema schema; public DistributableWebDeploymentXMLReaderTestCase(DistributableWebDeploymentSchema schema) { this.schema = schema; } @Test public void test() throws IOException, XMLStreamException { URL url = this.getClass().getResource(String.format("distributable-web-%d.%d.xml", this.schema.getVersion().major(), this.schema.getVersion().minor())); XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(this.schema.getQualifiedName(), this.schema); try (InputStream input = url.openStream()) { XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input); MutableDistributableWebDeploymentConfiguration config = new MutableDistributableWebDeploymentConfiguration(PropertyReplacers.noop()); mapper.parseDocument(config, reader); Assert.assertNull(config.getSessionManagement()); Assert.assertEquals("foo", config.getSessionManagementName()); Assert.assertNotNull(config.getImmutableClasses()); Assert.assertEquals(Arrays.asList(Locale.class.getName(), UUID.class.getName()), config.getImmutableClasses()); } finally { mapper.unregisterRootAttribute(this.schema.getQualifiedName()); } } @Test public void testInfinispan() throws IOException, XMLStreamException { URL url = this.getClass().getResource(String.format("distributable-web-infinispan-%d.%d.xml", this.schema.getVersion().major(), this.schema.getVersion().minor())); XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(this.schema.getQualifiedName(), this.schema); try (InputStream input = url.openStream()) { XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input); MutableDistributableWebDeploymentConfiguration config = new MutableDistributableWebDeploymentConfiguration(PropertyReplacers.noop()); mapper.parseDocument(config, reader); Assert.assertNull(config.getSessionManagementName()); DistributableSessionManagementProvider<? extends DistributableSessionManagementConfiguration<DeploymentUnit>> result = config.getSessionManagement(); Assert.assertNotNull(result); Assert.assertTrue(result instanceof InfinispanSessionManagementProvider); InfinispanSessionManagementProvider provider = (InfinispanSessionManagementProvider) result; InfinispanSessionManagementConfiguration<DeploymentUnit> configuration = provider.getSessionManagementConfiguration(); Assert.assertEquals("foo", configuration.getContainerName()); Assert.assertEquals("bar", configuration.getCacheName()); Assert.assertSame(SessionAttributePersistenceStrategy.FINE, configuration.getAttributePersistenceStrategy()); if (this.schema.since(DistributableWebDeploymentSchema.VERSION_2_0)) { Assert.assertTrue(provider.getRouteLocatorServiceConfiguratorFactory() instanceof RankedRouteLocatorServiceConfiguratorFactory); RankedRoutingConfiguration routing = ((RankedRouteLocatorServiceConfiguratorFactory<InfinispanSessionManagementConfiguration<DeploymentUnit>>) provider.getRouteLocatorServiceConfiguratorFactory()).getConfiguration(); Assert.assertEquals(":", routing.getDelimiter()); Assert.assertEquals(4, routing.getMaxRoutes()); } else { Assert.assertTrue(provider.getRouteLocatorServiceConfiguratorFactory() instanceof NullRouteLocatorServiceConfiguratorFactory); } Assert.assertNotNull(config.getImmutableClasses()); Assert.assertEquals(Arrays.asList(Locale.class.getName(), UUID.class.getName()), config.getImmutableClasses()); } finally { mapper.unregisterRootAttribute(this.schema.getQualifiedName()); } } @Test public void testHotRod() throws IOException, XMLStreamException { URL url = this.getClass().getResource(String.format("distributable-web-hotrod-%d.%d.xml", this.schema.getVersion().major(), this.schema.getVersion().minor())); XMLMapper mapper = XMLMapper.Factory.create(); mapper.registerRootElement(this.schema.getQualifiedName(), new DistributableWebDeploymentXMLReader(this.schema)); try (InputStream input = url.openStream()) { XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(input); MutableDistributableWebDeploymentConfiguration config = new MutableDistributableWebDeploymentConfiguration(PropertyReplacers.noop()); mapper.parseDocument(config, reader); Assert.assertNull(config.getSessionManagementName()); DistributableSessionManagementProvider<? extends DistributableSessionManagementConfiguration<DeploymentUnit>> result = config.getSessionManagement(); Assert.assertNotNull(result); Assert.assertTrue(result instanceof HotRodSessionManagementProvider); HotRodSessionManagementConfiguration<DeploymentUnit> configuration = ((HotRodSessionManagementProvider) result).getSessionManagementConfiguration(); Assert.assertEquals("foo", configuration.getContainerName()); Assert.assertSame(SessionAttributePersistenceStrategy.FINE, configuration.getAttributePersistenceStrategy()); } finally { mapper.unregisterRootAttribute(this.schema.getQualifiedName()); } } }
8,547
55.609272
232
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/InfinispanRoutingProviderResourceDefinition.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.wildfly.extension.clustering.web; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.CapabilityProvider; import org.jboss.as.clustering.controller.CapabilityReference; import org.jboss.as.clustering.controller.RequirementCapability; import org.jboss.as.clustering.controller.ResourceDescriptor; 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.Flag; import org.jboss.dmr.ModelType; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement; import org.wildfly.clustering.service.Requirement; import org.wildfly.clustering.web.service.WebRequirement; /** * Definition of the /subsystem=distributable-web/routing=infinispan resource. * @author Paul Ferraro */ public class InfinispanRoutingProviderResourceDefinition extends RoutingProviderResourceDefinition { static final PathElement PATH = pathElement("infinispan"); enum Capability implements CapabilityProvider, UnaryOperator<RuntimeCapability.Builder<Void>> { INFINISPAN_ROUTING_PROVIDER(WebRequirement.INFINISPAN_ROUTING_PROVIDER), ; private final org.jboss.as.clustering.controller.Capability capability; Capability(Requirement requirement) { this.capability = new RequirementCapability(requirement); } @Override public org.jboss.as.clustering.controller.Capability getCapability() { return this.capability; } @Override public RuntimeCapability.Builder<Void> apply(RuntimeCapability.Builder<Void> builder) { return builder.setAllowMultipleRegistrations(true); } } enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> { CACHE_CONTAINER("cache-container", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setAllowExpression(false) .setRequired(true) .setCapabilityReference(new CapabilityReference(Capability.INFINISPAN_ROUTING_PROVIDER, InfinispanDefaultCacheRequirement.CONFIGURATION)) ; } }, CACHE("cache", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setAllowExpression(false) .setCapabilityReference(new CapabilityReference(Capability.INFINISPAN_ROUTING_PROVIDER, InfinispanCacheRequirement.CONFIGURATION, CACHE_CONTAINER)) ; } }, ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type) .setAllowExpression(true) .setRequired(false) .setFlags(Flag.RESTART_RESOURCE_SERVICES) ).build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> { @Override public ResourceDescriptor apply(ResourceDescriptor descriptor) { return descriptor.addAttributes(Attribute.class).addCapabilities(Capability.class); } } InfinispanRoutingProviderResourceDefinition() { super(PATH, new ResourceDescriptorConfigurator(), InfinispanRoutingProviderServiceConfigurator::new); } }
5,023
42.310345
171
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/HotRodSessionManagementServiceConfigurator.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.wildfly.extension.clustering.web; import static org.wildfly.extension.clustering.web.HotRodSessionManagementResourceDefinition.Attribute.CACHE_CONFIGURATION; import static org.wildfly.extension.clustering.web.HotRodSessionManagementResourceDefinition.Attribute.REMOTE_CACHE_CONTAINER; import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.PathAddress; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.dmr.ModelNode; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.web.service.session.DistributableSessionManagementProvider; import org.wildfly.extension.clustering.web.session.hotrod.HotRodSessionManagementConfiguration; import org.wildfly.extension.clustering.web.session.hotrod.HotRodSessionManagementProvider; /** * @author Paul Ferraro */ public class HotRodSessionManagementServiceConfigurator extends SessionManagementServiceConfigurator<HotRodSessionManagementConfiguration<DeploymentUnit>> implements HotRodSessionManagementConfiguration<DeploymentUnit> { private volatile String containerName; private volatile String configurationName; HotRodSessionManagementServiceConfigurator(PathAddress address) { super(address); } @Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.containerName = REMOTE_CACHE_CONTAINER.resolveModelAttribute(context, model).asString(); this.configurationName = CACHE_CONFIGURATION.resolveModelAttribute(context, model).asStringOrNull(); return super.configure(context, model); } @Override public DistributableSessionManagementProvider<HotRodSessionManagementConfiguration<DeploymentUnit>> get() { return new HotRodSessionManagementProvider(this); } @Override public String getContainerName() { return this.containerName; } @Override public String getConfigurationName() { return this.configurationName; } }
3,132
42.513889
220
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/NoAffinityServiceConfigurator.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.wildfly.extension.clustering.web; import org.jboss.as.controller.PathAddress; import org.wildfly.clustering.web.service.routing.RouteLocatorServiceConfiguratorFactory; import org.wildfly.extension.clustering.web.routing.NullRouteLocatorServiceConfiguratorFactory; /** * @author Paul Ferraro */ public class NoAffinityServiceConfigurator<C> extends AffinityServiceConfigurator<C> { public NoAffinityServiceConfigurator(PathAddress address) { super(NoAffinityResourceDefinition.Capability.AFFINITY, address); } @Override public RouteLocatorServiceConfiguratorFactory<C> get() { return new NullRouteLocatorServiceConfiguratorFactory<>(); } }
1,717
38.953488
95
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/RoutingProviderServiceConfigurator.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.wildfly.extension.clustering.web; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import org.jboss.as.clustering.controller.CapabilityServiceNameProvider; import org.jboss.as.clustering.controller.ResourceServiceConfigurator; import org.jboss.as.controller.PathAddress; 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.web.service.routing.RoutingProvider; /** * Abstract service configurator for routing providers. * @author Paul Ferraro */ public abstract class RoutingProviderServiceConfigurator extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, Supplier<RoutingProvider> { private final ServiceName alias; public RoutingProviderServiceConfigurator(PathAddress address) { this(address, null); } public RoutingProviderServiceConfigurator(PathAddress address, ServiceName alias) { super(RoutingProviderResourceDefinition.Capability.ROUTING_PROVIDER, address); this.alias = alias; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceName name = this.getServiceName(); ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<RoutingProvider> provider = builder.provides((this.alias != null) ? new ServiceName[] { name, this.alias } : new ServiceName[] { name }); Service service = new FunctionalService<>(provider, Function.identity(), this); return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND); } }
2,853
42.242424
162
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/AffinityResourceDefinition.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.wildfly.extension.clustering.web; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.Capability; import org.jboss.as.clustering.controller.ChildResourceDefinition; 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.SimpleResourceServiceHandler; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.registry.ManagementResourceRegistration; /** * @author Paul Ferraro */ public class AffinityResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> { static PathElement pathElement(String value) { return PathElement.pathElement("affinity", value); } private final Iterable<? extends Capability> capabilities; private final UnaryOperator<ResourceDescriptor> configurator; private final ResourceServiceConfiguratorFactory factory; AffinityResourceDefinition(PathElement path, Iterable<? extends Capability> capabilities, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory factory) { super(path, DistributableWebExtension.SUBSYSTEM_RESOLVER.createChildResolver(path, pathElement(PathElement.WILDCARD_VALUE))); this.capabilities = capabilities; this.configurator = configurator; this.factory = factory; } @Override public ManagementResourceRegistration register(ManagementResourceRegistration parent) { ManagementResourceRegistration registration = parent.registerSubModel(this); ResourceDescriptor descriptor = this.configurator.apply(new ResourceDescriptor(this.getResourceDescriptionResolver())).addCapabilities(this.capabilities); ResourceServiceHandler handler = new SimpleResourceServiceHandler(this.factory); new SimpleResourceRegistrar(descriptor, handler).register(registration); return registration; } }
3,150
46.742424
187
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/InfinispanSSOManagementResourceDefinition.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.wildfly.extension.clustering.web; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.CapabilityReference; 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.Flag; import org.jboss.dmr.ModelType; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement; /** * Definition of the /subsystem=distributable-web/infinispan-single-sign-on-management=* resource. * @author Paul Ferraro */ public class InfinispanSSOManagementResourceDefinition extends SSOManagementResourceDefinition { static final PathElement WILDCARD_PATH = PathElement.pathElement("infinispan-single-sign-on-management"); enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> { CACHE_CONTAINER("cache-container", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setAllowExpression(false) .setRequired(true) .setCapabilityReference(new CapabilityReference(Capability.SSO_MANAGEMENT_PROVIDER, InfinispanDefaultCacheRequirement.CONFIGURATION)) ; } }, CACHE("cache", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setAllowExpression(false) .setCapabilityReference(new CapabilityReference(Capability.SSO_MANAGEMENT_PROVIDER, InfinispanCacheRequirement.CONFIGURATION, CACHE_CONTAINER)) ; } }, ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type) .setAllowExpression(true) .setRequired(false) .setFlags(Flag.RESTART_RESOURCE_SERVICES) ).build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } InfinispanSSOManagementResourceDefinition() { super(WILDCARD_PATH, new SimpleResourceDescriptorConfigurator<>(Attribute.class), InfinispanSSOManagementServiceConfigurator::new); } }
3,790
44.130952
167
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/LocalRoutingProviderResourceDefinition.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.wildfly.extension.clustering.web; import java.util.function.UnaryOperator; import org.jboss.as.controller.PathElement; /** * Definition of the /subsystem=distributable-web/routing=local resource. * @author Paul Ferraro */ public class LocalRoutingProviderResourceDefinition extends RoutingProviderResourceDefinition { static final PathElement PATH = pathElement("local"); LocalRoutingProviderResourceDefinition() { super(PATH, UnaryOperator.identity(), LocalRoutingProviderServiceConfigurator::new); } }
1,568
37.268293
95
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/InfinispanSessionManagementResourceDefinition.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.wildfly.extension.clustering.web; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.CapabilityReference; import org.jboss.as.clustering.controller.ResourceDescriptor; 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.Flag; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.dmr.ModelType; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement; /** * Definition of the /subsystem=distributable-web/infinispan-session-management=* resource. * @author Paul Ferraro */ public class InfinispanSessionManagementResourceDefinition extends SessionManagementResourceDefinition { static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE); static PathElement pathElement(String name) { return PathElement.pathElement("infinispan-session-management", name); } enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> { CACHE_CONTAINER("cache-container", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setAllowExpression(false) .setRequired(true) .setCapabilityReference(new CapabilityReference(Capability.SESSION_MANAGEMENT_PROVIDER, InfinispanDefaultCacheRequirement.CONFIGURATION)) ; } }, CACHE("cache", ModelType.STRING) { @Override public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) { return builder.setAllowExpression(false) .setCapabilityReference(new CapabilityReference(Capability.SESSION_MANAGEMENT_PROVIDER, InfinispanCacheRequirement.CONFIGURATION, CACHE_CONTAINER)) ; } }, ; private final AttributeDefinition definition; Attribute(String name, ModelType type) { this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type) .setAllowExpression(true) .setRequired(false) .setFlags(Flag.RESTART_RESOURCE_SERVICES) ).build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } private static final UnaryOperator<ResourceDescriptor> CONFIGURATOR = new UnaryOperator<>() { @Override public ResourceDescriptor apply(ResourceDescriptor descriptor) { return descriptor.addAttributes(Attribute.class) .addRequiredSingletonChildren(PrimaryOwnerAffinityResourceDefinition.PATH) ; } }; InfinispanSessionManagementResourceDefinition() { super(WILDCARD_PATH, CONFIGURATOR, InfinispanSessionManagementServiceConfigurator::new); } @Override public ManagementResourceRegistration register(ManagementResourceRegistration parent) { ManagementResourceRegistration registration = super.register(parent); new PrimaryOwnerAffinityResourceDefinition().register(registration); new RankedAffinityResourceDefinition().register(registration); return registration; } }
4,680
42.747664
171
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/DistributableWebResourceTransformer.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.wildfly.extension.clustering.web; import java.util.function.Function; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder; /** * @author Paul Ferraro */ public class DistributableWebResourceTransformer implements Function<ModelVersion, TransformationDescriptionBuilder> { @Override public ResourceTransformationDescriptionBuilder apply(ModelVersion version) { ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance(); new InfinispanSessionManagementResourceTransformer(builder).accept(version); new HotRodSessionManagementResourceTransformer(builder).accept(version); return builder; } }
1,911
40.565217
126
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/InfinispanSSOManagementServiceConfigurator.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.wildfly.extension.clustering.web; import static org.wildfly.extension.clustering.web.InfinispanSSOManagementResourceDefinition.Attribute.CACHE; import static org.wildfly.extension.clustering.web.InfinispanSSOManagementResourceDefinition.Attribute.CACHE_CONTAINER; 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; import org.wildfly.clustering.web.service.sso.DistributableSSOManagementProvider; import org.wildfly.extension.clustering.web.sso.infinispan.InfinispanSSOManagementConfiguration; import org.wildfly.extension.clustering.web.sso.infinispan.InfinispanSSOManagementProvider; /** * Service configurator for Infinispan single sign-on management providers. * @author Paul Ferraro */ public class InfinispanSSOManagementServiceConfigurator extends SSOManagementServiceConfigurator implements InfinispanSSOManagementConfiguration { private volatile String containerName; private volatile String cacheName; public InfinispanSSOManagementServiceConfigurator(PathAddress address) { super(address); } @Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.containerName = CACHE_CONTAINER.resolveModelAttribute(context, model).asString(); this.cacheName = CACHE.resolveModelAttribute(context, model).asStringOrNull(); return this; } @Override public DistributableSSOManagementProvider get() { return new InfinispanSSOManagementProvider(this); } @Override public String getContainerName() { return this.containerName; } @Override public String getCacheName() { return this.cacheName; } }
2,920
39.569444
146
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/PrimaryOwnerAffinityServiceConfigurator.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.wildfly.extension.clustering.web; import org.jboss.as.controller.PathAddress; import org.wildfly.clustering.ee.infinispan.InfinispanCacheConfiguration; import org.wildfly.clustering.web.service.routing.RouteLocatorServiceConfiguratorFactory; import org.wildfly.extension.clustering.web.routing.infinispan.PrimaryOwnerRouteLocatorServiceConfiguratorFactory; /** * @author Paul Ferraro */ public class PrimaryOwnerAffinityServiceConfigurator<C extends InfinispanCacheConfiguration> extends AffinityServiceConfigurator<C> { public PrimaryOwnerAffinityServiceConfigurator(PathAddress address) { super(PrimaryOwnerAffinityResourceDefinition.Capability.AFFINITY, address); } @Override public RouteLocatorServiceConfiguratorFactory<C> get() { return new PrimaryOwnerRouteLocatorServiceConfiguratorFactory<>(); } }
1,885
41.863636
133
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/RankedAffinityServiceConfigurator.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.wildfly.extension.clustering.web; import static org.wildfly.extension.clustering.web.RankedAffinityResourceDefinition.Attribute.DELIMITER; import static org.wildfly.extension.clustering.web.RankedAffinityResourceDefinition.Attribute.MAX_ROUTES; 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.ee.infinispan.InfinispanCacheConfiguration; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.web.infinispan.routing.RankedRoutingConfiguration; import org.wildfly.clustering.web.service.routing.RouteLocatorServiceConfiguratorFactory; import org.wildfly.extension.clustering.web.routing.infinispan.RankedRouteLocatorServiceConfiguratorFactory; /** * @author Paul Ferraro */ public class RankedAffinityServiceConfigurator<C extends InfinispanCacheConfiguration> extends AffinityServiceConfigurator<C> implements RankedRoutingConfiguration { private volatile String delimiter; private volatile int maxRoutes; public RankedAffinityServiceConfigurator(PathAddress address) { super(RankedAffinityResourceDefinition.Capability.AFFINITY, address); } @Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.delimiter = DELIMITER.resolveModelAttribute(context, model).asString(); this.maxRoutes = MAX_ROUTES.resolveModelAttribute(context, model).asInt(); return this; } @Override public RouteLocatorServiceConfiguratorFactory<C> get() { return new RankedRouteLocatorServiceConfiguratorFactory<>(this); } @Override public String getDelimiter() { return this.delimiter; } @Override public int getMaxRoutes() { return this.maxRoutes; } }
2,962
40.152778
165
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/DistributableWebResourceDefinition.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.wildfly.extension.clustering.web; import java.util.EnumSet; import java.util.function.Consumer; import org.jboss.as.clustering.controller.CapabilityProvider; import org.jboss.as.clustering.controller.CapabilityReference; import org.jboss.as.clustering.controller.DefaultSubsystemDescribeHandler; import org.jboss.as.clustering.controller.DeploymentChainContributingResourceRegistrar; 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.SubsystemRegistration; import org.jboss.as.clustering.controller.SubsystemResourceDefinition; import org.jboss.as.controller.AttributeDefinition; import org.jboss.as.controller.CapabilityReferenceRecorder; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.SimpleAttributeDefinitionBuilder; import org.jboss.as.controller.registry.AttributeAccess.Flag; import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.server.DeploymentProcessorTarget; import org.jboss.as.server.deployment.Phase; import org.jboss.as.server.deployment.jbossallxml.JBossAllSchema; import org.jboss.dmr.ModelType; import org.wildfly.clustering.service.Requirement; import org.wildfly.clustering.web.service.WebDefaultProviderRequirement; import org.wildfly.clustering.web.service.WebProviderRequirement; import org.wildfly.extension.clustering.web.deployment.DistributableWebDeploymentDependencyProcessor; import org.wildfly.extension.clustering.web.deployment.DistributableWebDeploymentParsingProcessor; import org.wildfly.extension.clustering.web.deployment.DistributableWebDeploymentProcessor; import org.wildfly.extension.clustering.web.deployment.DistributableWebDeploymentSchema; /** * Definition of the /subsystem=distributable-web resource. * @author Paul Ferraro */ public class DistributableWebResourceDefinition extends SubsystemResourceDefinition implements Consumer<DeploymentProcessorTarget> { static final PathElement PATH = pathElement(DistributableWebExtension.SUBSYSTEM_NAME); enum Capability implements CapabilityProvider { DEFAULT_SESSION_MANAGEMENT_PROVIDER(WebDefaultProviderRequirement.SESSION_MANAGEMENT_PROVIDER), DEFAULT_SSO_MANAGEMENT_PROVIDER(WebDefaultProviderRequirement.SSO_MANAGEMENT_PROVIDER), ; private final org.jboss.as.clustering.controller.Capability capability; Capability(Requirement requirement) { this.capability = new RequirementCapability(requirement); } @Override public org.jboss.as.clustering.controller.Capability getCapability() { return this.capability; } } enum Attribute implements org.jboss.as.clustering.controller.Attribute { DEFAULT_SESSION_MANAGEMENT("default-session-management", ModelType.STRING, new CapabilityReference(Capability.DEFAULT_SESSION_MANAGEMENT_PROVIDER, WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER)), DEFAULT_SSO_MANAGEMENT("default-single-sign-on-management", ModelType.STRING, new CapabilityReference(Capability.DEFAULT_SSO_MANAGEMENT_PROVIDER, WebProviderRequirement.SSO_MANAGEMENT_PROVIDER)), ; private final AttributeDefinition definition; Attribute(String name, ModelType type, CapabilityReferenceRecorder reference) { this.definition = new SimpleAttributeDefinitionBuilder(name, type) .setAllowExpression(false) .setRequired(true) .setCapabilityReference(reference) .setFlags(Flag.RESTART_RESOURCE_SERVICES) .build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } DistributableWebResourceDefinition() { super(PATH, DistributableWebExtension.SUBSYSTEM_RESOLVER); } @Override public void register(SubsystemRegistration parent) { ManagementResourceRegistration registration = parent.registerSubsystemModel(this); new DefaultSubsystemDescribeHandler().register(registration); ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()) .addAttributes(Attribute.class) .addCapabilities(Capability.class) .addRequiredSingletonChildren(LocalRoutingProviderResourceDefinition.PATH) ; ResourceServiceHandler handler = new DistributableWebResourceServiceHandler(); new DeploymentChainContributingResourceRegistrar(descriptor, handler, this).register(registration); new LocalRoutingProviderResourceDefinition().register(registration); new InfinispanRoutingProviderResourceDefinition().register(registration); new InfinispanSessionManagementResourceDefinition().register(registration); new InfinispanSSOManagementResourceDefinition().register(registration); new HotRodSessionManagementResourceDefinition().register(registration); new HotRodSSOManagementResourceDefinition().register(registration); } @Override public void accept(DeploymentProcessorTarget target) { target.addDeploymentProcessor(DistributableWebExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_REGISTER_JBOSS_ALL_DISTRIBUTABLE_WEB, JBossAllSchema.createDeploymentUnitProcessor(EnumSet.allOf(DistributableWebDeploymentSchema.class), DistributableWebDeploymentDependencyProcessor.CONFIGURATION_KEY)); target.addDeploymentProcessor(DistributableWebExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_DISTRIBUTABLE_WEB, new DistributableWebDeploymentParsingProcessor()); target.addDeploymentProcessor(DistributableWebExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_DISTRIBUTABLE_WEB, new DistributableWebDeploymentDependencyProcessor()); target.addDeploymentProcessor(DistributableWebExtension.SUBSYSTEM_NAME, Phase.CONFIGURE_MODULE, Phase.CONFIGURE_DISTRIBUTABLE_WEB, new DistributableWebDeploymentProcessor()); } }
7,198
51.933824
317
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/RankedAffinityResourceDefinition.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.wildfly.extension.clustering.web; import java.util.EnumSet; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.CapabilityProvider; import org.jboss.as.clustering.controller.ResourceDescriptor; import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver; 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.capability.RuntimeCapability; import org.jboss.dmr.ModelNode; import org.jboss.dmr.ModelType; import org.wildfly.clustering.service.UnaryRequirement; import org.wildfly.clustering.web.service.WebProviderRequirement; import org.wildfly.clustering.web.service.WebRequirement; /** * @author Paul Ferraro */ public class RankedAffinityResourceDefinition extends AffinityResourceDefinition { static final PathElement PATH = pathElement("ranked"); enum Capability implements CapabilityProvider, UnaryOperator<RuntimeCapability.Builder<Void>> { AFFINITY(WebProviderRequirement.AFFINITY), ; private final org.jboss.as.clustering.controller.Capability capability; Capability(UnaryRequirement requirement) { this.capability = new UnaryRequirementCapability(requirement, this); } @Override public org.jboss.as.clustering.controller.Capability getCapability() { return this.capability; } @Override public RuntimeCapability.Builder<Void> apply(RuntimeCapability.Builder<Void> builder) { return builder.setAllowMultipleRegistrations(true) .setDynamicNameMapper(UnaryCapabilityNameResolver.PARENT) .addRequirements(WebRequirement.INFINISPAN_ROUTING_PROVIDER.getName()); } } public enum Attribute implements org.jboss.as.clustering.controller.Attribute { DELIMITER("delimiter", ModelType.STRING, new ModelNode(".")), MAX_ROUTES("max-routes", ModelType.STRING, new ModelNode(3)), ; private final AttributeDefinition definition; Attribute(String name, ModelType type, ModelNode defaultValue) { this.definition = new SimpleAttributeDefinitionBuilder(name, type) .setAllowExpression(false) .setDefaultValue(defaultValue) .setRequired(false) .build(); } @Override public AttributeDefinition getDefinition() { return this.definition; } } static class ResourceDescriptorConfigurator implements UnaryOperator<ResourceDescriptor> { @Override public ResourceDescriptor apply(ResourceDescriptor descriptor) { return descriptor.addCapabilities(Capability.class).addAttributes(Attribute.class); } } RankedAffinityResourceDefinition() { super(PATH, EnumSet.allOf(Capability.class), new ResourceDescriptorConfigurator(), RankedAffinityServiceConfigurator::new); } }
4,164
39.833333
131
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/DistributableWebResourceServiceHandler.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.wildfly.extension.clustering.web; import java.util.EnumSet; import org.jboss.as.clustering.controller.IdentityCapabilityServiceConfigurator; import org.jboss.as.clustering.controller.ResourceServiceHandler; 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.ServiceTarget; import org.wildfly.clustering.web.service.WebProviderRequirement; import org.wildfly.extension.clustering.web.DistributableWebResourceDefinition.Attribute; import org.wildfly.extension.clustering.web.DistributableWebResourceDefinition.Capability; /** * {@link ResourceRuntimeHandler} for the /subsystem=distributable-web resource. * @author Paul Ferraro */ public class DistributableWebResourceServiceHandler implements ResourceServiceHandler { @Override public void installServices(OperationContext context, ModelNode model) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); ServiceTarget target = context.getServiceTarget(); String defaultSessionManagement = Attribute.DEFAULT_SESSION_MANAGEMENT.resolveModelAttribute(context, model).asString(); new IdentityCapabilityServiceConfigurator<>(Capability.DEFAULT_SESSION_MANAGEMENT_PROVIDER.getServiceName(address), WebProviderRequirement.SESSION_MANAGEMENT_PROVIDER, defaultSessionManagement) .configure(context) .build(target) .install(); String defaultSSOManagement = Attribute.DEFAULT_SSO_MANAGEMENT.resolveModelAttribute(context, model).asString(); new IdentityCapabilityServiceConfigurator<>(Capability.DEFAULT_SSO_MANAGEMENT_PROVIDER.getServiceName(address), WebProviderRequirement.SSO_MANAGEMENT_PROVIDER, defaultSSOManagement) .configure(context) .build(target) .install(); } @Override public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException { PathAddress address = context.getCurrentAddress(); for (Capability capability : EnumSet.allOf(Capability.class)) { context.removeService(capability.getServiceName(address)); } } }
3,345
46.8
201
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/NoAffinityResourceDefinition.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.wildfly.extension.clustering.web; import java.util.EnumSet; import java.util.function.UnaryOperator; import org.jboss.as.clustering.controller.CapabilityProvider; import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver; import org.jboss.as.clustering.controller.UnaryRequirementCapability; import org.jboss.as.controller.PathElement; import org.jboss.as.controller.capability.RuntimeCapability; import org.wildfly.clustering.service.UnaryRequirement; import org.wildfly.clustering.web.service.WebProviderRequirement; /** * @author Paul Ferraro */ public class NoAffinityResourceDefinition extends AffinityResourceDefinition { static final PathElement PATH = pathElement("none"); enum Capability implements CapabilityProvider, UnaryOperator<RuntimeCapability.Builder<Void>> { AFFINITY(WebProviderRequirement.AFFINITY), ; private final org.jboss.as.clustering.controller.Capability capability; Capability(UnaryRequirement requirement) { this.capability = new UnaryRequirementCapability(requirement, this); } @Override public org.jboss.as.clustering.controller.Capability getCapability() { return this.capability; } @Override public RuntimeCapability.Builder<Void> apply(RuntimeCapability.Builder<Void> builder) { return builder.setAllowMultipleRegistrations(true) .setDynamicNameMapper(UnaryCapabilityNameResolver.PARENT); } } NoAffinityResourceDefinition() { super(PATH, EnumSet.allOf(Capability.class), UnaryOperator.identity(), NoAffinityServiceConfigurator::new); } }
2,703
38.764706
115
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/DistributableWebExtension.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.wildfly.extension.clustering.web; import org.jboss.as.clustering.controller.PersistentSubsystemExtension; import org.jboss.as.controller.Extension; import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver; import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver; import org.kohsuke.MetaInfServices; /** * Extension that registers the distributable-web subsystem. * @author Paul Ferraro */ @MetaInfServices(Extension.class) public class DistributableWebExtension extends PersistentSubsystemExtension<DistributableWebSubsystemSchema> { static final String SUBSYSTEM_NAME = "distributable-web"; static final ParentResourceDescriptionResolver SUBSYSTEM_RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME, DistributableWebExtension.class); public DistributableWebExtension() { super(SUBSYSTEM_NAME, DistributableWebSubsystemModel.CURRENT, DistributableWebResourceDefinition::new, DistributableWebSubsystemSchema.CURRENT); } }
2,050
44.577778
162
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/SessionManagementServiceConfigurator.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.wildfly.extension.clustering.web; import static org.wildfly.extension.clustering.web.SessionManagementResourceDefinition.Attribute.GRANULARITY; import static org.wildfly.extension.clustering.web.SessionManagementResourceDefinition.Attribute.MARSHALLER; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; 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.as.server.deployment.DeploymentUnit; import org.jboss.dmr.ModelNode; 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.marshalling.spi.ByteBufferMarshaller; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.web.service.WebProviderRequirement; import org.wildfly.clustering.web.service.routing.RouteLocatorServiceConfiguratorFactory; import org.wildfly.clustering.web.service.session.DistributableSessionManagementProvider; import org.wildfly.clustering.web.session.DistributableSessionManagementConfiguration; import org.wildfly.clustering.web.session.SessionAttributePersistenceStrategy; /** * Abstract service configurator for session management providers. * @author Paul Ferraro */ public abstract class SessionManagementServiceConfigurator<C extends DistributableSessionManagementConfiguration<DeploymentUnit>> extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, DistributableSessionManagementConfiguration<DeploymentUnit>, Supplier<DistributableSessionManagementProvider<C>> { private volatile SessionGranularity granularity; private volatile SessionMarshallerFactory marshallerFactory; private volatile SupplierDependency<RouteLocatorServiceConfiguratorFactory<C>> factory; SessionManagementServiceConfigurator(PathAddress address) { super(SessionManagementResourceDefinition.Capability.SESSION_MANAGEMENT_PROVIDER, address); } @Override public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException { this.granularity = SessionGranularity.valueOf(GRANULARITY.resolveModelAttribute(context, model).asString()); this.marshallerFactory = SessionMarshallerFactory.valueOf(MARSHALLER.resolveModelAttribute(context, model).asString()); this.factory = new ServiceSupplierDependency<>(WebProviderRequirement.AFFINITY.getServiceName(context, this.getServiceName().getSimpleName())); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceName name = this.getServiceName(); ServiceBuilder<?> builder = target.addService(name); Consumer<DistributableSessionManagementProvider<C>> provider = this.factory.register(builder).provides(name); Service service = new FunctionalService<>(provider, Function.identity(), this); return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND); } @Override public SessionAttributePersistenceStrategy getAttributePersistenceStrategy() { return this.granularity.getAttributePersistenceStrategy(); } @Override public Function<DeploymentUnit, ByteBufferMarshaller> getMarshallerFactory() { return this.marshallerFactory; } public RouteLocatorServiceConfiguratorFactory<C> getRouteLocatorServiceConfiguratorFactory() { return this.factory.get(); } }
5,018
49.19
322
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/DistributableWebXMLDescriptionFactory.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.wildfly.extension.clustering.web; import static org.jboss.as.controller.PersistentResourceXMLDescription.builder; import java.util.function.Function; import java.util.stream.Stream; import org.jboss.as.clustering.controller.Attribute; import org.jboss.as.controller.PersistentResourceXMLDescription; import org.jboss.as.controller.PersistentResourceXMLDescription.PersistentResourceXMLBuilder; /** * XML description factory for the distributable-web subsystem. * @author Paul Ferraro */ public enum DistributableWebXMLDescriptionFactory implements Function<DistributableWebSubsystemSchema, PersistentResourceXMLDescription> { INSTANCE; @Override public PersistentResourceXMLDescription apply(DistributableWebSubsystemSchema schema) { return builder(DistributableWebResourceDefinition.PATH, schema.getNamespace()).addAttributes(Attribute.stream(DistributableWebResourceDefinition.Attribute.class)) .addChild(getInfinispanSessionManagementResourceXMLBuilder(schema)) .addChild(getHotRodSessionManagementResourceXMLBuilder(schema)) .addChild(builder(InfinispanSSOManagementResourceDefinition.WILDCARD_PATH).addAttributes(Attribute.stream(InfinispanSSOManagementResourceDefinition.Attribute.class))) .addChild(builder(HotRodSSOManagementResourceDefinition.WILDCARD_PATH).addAttributes(Attribute.stream(HotRodSSOManagementResourceDefinition.Attribute.class))) .addChild(builder(LocalRoutingProviderResourceDefinition.PATH).setXmlElementName("local-routing")) .addChild(builder(InfinispanRoutingProviderResourceDefinition.PATH).addAttributes(Attribute.stream(InfinispanRoutingProviderResourceDefinition.Attribute.class)).setXmlElementName("infinispan-routing")) .build(); } private static PersistentResourceXMLBuilder getInfinispanSessionManagementResourceXMLBuilder(DistributableWebSubsystemSchema schema) { PersistentResourceXMLBuilder builder = builder(InfinispanSessionManagementResourceDefinition.WILDCARD_PATH).addAttributes(Stream.concat(Attribute.stream(InfinispanSessionManagementResourceDefinition.Attribute.class), Attribute.stream(SessionManagementResourceDefinition.Attribute.class))); addAffinityChildren(builder).addChild(builder(PrimaryOwnerAffinityResourceDefinition.PATH).setXmlElementName("primary-owner-affinity")); if (schema.since(DistributableWebSubsystemSchema.VERSION_2_0)) { builder.addChild(builder(RankedAffinityResourceDefinition.PATH).addAttributes(Attribute.stream(RankedAffinityResourceDefinition.Attribute.class)).setXmlElementName("ranked-affinity")); } return builder; } private static PersistentResourceXMLBuilder getHotRodSessionManagementResourceXMLBuilder(DistributableWebSubsystemSchema schema) { return addAffinityChildren(builder(HotRodSessionManagementResourceDefinition.WILDCARD_PATH).addAttributes(Stream.concat(Attribute.stream(HotRodSessionManagementResourceDefinition.Attribute.class), Attribute.stream(SessionManagementResourceDefinition.Attribute.class)))); } private static PersistentResourceXMLBuilder addAffinityChildren(PersistentResourceXMLBuilder builder) { return builder .addChild(builder(NoAffinityResourceDefinition.PATH).setXmlElementName("no-affinity")) .addChild(builder(LocalAffinityResourceDefinition.PATH).setXmlElementName("local-affinity")) ; } }
4,532
61.09589
297
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/LocalRoutingProviderServiceConfigurator.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.wildfly.extension.clustering.web; import org.jboss.as.controller.PathAddress; import org.wildfly.clustering.web.service.routing.RoutingProvider; import org.wildfly.extension.clustering.web.routing.LocalRoutingProvider; /** * Service configurator for the local routing provider. * @author Paul Ferraro */ public class LocalRoutingProviderServiceConfigurator extends RoutingProviderServiceConfigurator { public LocalRoutingProviderServiceConfigurator(PathAddress address) { super(address); } @Override public RoutingProvider get() { return new LocalRoutingProvider(); } }
1,649
36.5
97
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/DistributableWebSubsystemSchema.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.wildfly.extension.clustering.web; import org.jboss.as.controller.PersistentResourceXMLDescription; import org.jboss.as.controller.PersistentSubsystemSchema; import org.jboss.as.controller.SubsystemSchema; import org.jboss.as.controller.xml.VersionedNamespace; import org.jboss.staxmapper.IntVersion; /** * Enumerates the schema versions for the distributable-web subsystem. * @author Paul Ferraro */ public enum DistributableWebSubsystemSchema implements PersistentSubsystemSchema<DistributableWebSubsystemSchema> { VERSION_1_0(1, 0), // WildFly 17 VERSION_2_0(2, 0), // WildFly 18-26.1 VERSION_3_0(3, 0), // WildFly 27 ; static final DistributableWebSubsystemSchema CURRENT = VERSION_3_0; private final VersionedNamespace<IntVersion, DistributableWebSubsystemSchema> namespace; DistributableWebSubsystemSchema(int major, int minor) { this.namespace = SubsystemSchema.createLegacySubsystemURN(DistributableWebExtension.SUBSYSTEM_NAME, new IntVersion(major, minor)); } @Override public VersionedNamespace<IntVersion, DistributableWebSubsystemSchema> getNamespace() { return this.namespace; } @Override public PersistentResourceXMLDescription getXMLDescription() { return DistributableWebXMLDescriptionFactory.INSTANCE.apply(this); } }
2,360
39.016949
138
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/HotRodSessionManagementResourceTransformer.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.wildfly.extension.clustering.web; import java.util.function.Consumer; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; /** * @author Paul Ferraro */ public class HotRodSessionManagementResourceTransformer extends SessionManagementResourceTransformer implements Consumer<ModelVersion> { private final ResourceTransformationDescriptionBuilder parent; public HotRodSessionManagementResourceTransformer(ResourceTransformationDescriptionBuilder parent) { this.parent = parent; } @Override public void accept(ModelVersion version) { ResourceTransformationDescriptionBuilder builder = this.parent.addChildResource(HotRodSessionManagementResourceDefinition.WILDCARD_PATH); this.accept(version, builder); } }
1,884
38.270833
145
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/SessionMarshallerFactory.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.wildfly.extension.clustering.web; import java.util.IdentityHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.function.Function; import org.infinispan.protostream.FileDescriptorSource; import org.infinispan.protostream.SerializationContext; import org.infinispan.protostream.SerializationContextInitializer; import org.jboss.as.ee.component.ComponentConfiguration; import org.jboss.as.ee.component.EEModuleConfiguration; import org.jboss.as.ee.component.ViewConfiguration; import org.jboss.as.ee.component.serialization.WriteReplaceInterface; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.modules.Module; import org.wildfly.clustering.marshalling.jboss.JBossByteBufferMarshaller; import org.wildfly.clustering.marshalling.jboss.SimpleMarshallingConfigurationRepository; import org.wildfly.clustering.marshalling.protostream.ModuleClassLoaderMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamByteBufferMarshaller; import org.wildfly.clustering.marshalling.protostream.SerializationContextBuilder; import org.wildfly.clustering.marshalling.protostream.reflect.ProxyMarshaller; import org.wildfly.clustering.marshalling.spi.ByteBufferMarshaller; /** * @author Paul Ferraro */ public enum SessionMarshallerFactory implements Function<DeploymentUnit, ByteBufferMarshaller> { JBOSS() { @Override public ByteBufferMarshaller apply(DeploymentUnit unit) { Module module = unit.getAttachment(Attachments.MODULE); return new JBossByteBufferMarshaller(new SimpleMarshallingConfigurationRepository(JBossMarshallingVersion.class, JBossMarshallingVersion.CURRENT, module), module.getClassLoader()); } }, PROTOSTREAM() { @Override public ByteBufferMarshaller apply(DeploymentUnit unit) { Module module = unit.getAttachment(Attachments.MODULE); SerializationContextBuilder builder = new SerializationContextBuilder(new ModuleClassLoaderMarshaller(module.getModuleLoader())).load(module.getClassLoader()); EEModuleConfiguration configuration = unit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_CONFIGURATION); // Sort component views by view class Map<Class<?>, List<ViewConfiguration>> components = new IdentityHashMap<>(); for (ComponentConfiguration component : configuration.getComponentConfigurations()) { for (ViewConfiguration view : component.getViews()) { Class<?> proxyClass = view.getProxyFactory().defineClass(); // Find components with views implementing WriteReplaceInterface if (WriteReplaceInterface.class.isAssignableFrom(proxyClass)) { List<ViewConfiguration> views = components.get(view.getViewClass()); if (views == null) { views = new LinkedList<>(); components.put(view.getViewClass(), views); } views.add(view); } } } // Create schemas/marshallers for component view proxies if (!components.isEmpty()) { for (Map.Entry<Class<?>, List<ViewConfiguration>> entry : components.entrySet()) { String viewClassName = entry.getKey().getName(); StringBuilder schemaBuilder = new StringBuilder(); schemaBuilder.append("package ").append(viewClassName).append(';').append(System.lineSeparator()); for (ViewConfiguration view : entry.getValue()) { schemaBuilder.append("message ").append(view.getComponentConfiguration().getComponentName()).append(" { optional bytes proxy = 1; }").append(System.lineSeparator()); } String schema = schemaBuilder.toString(); builder.register(new SerializationContextInitializer() { @Deprecated @Override public String getProtoFileName() { return null; } @Deprecated @Override public String getProtoFile() { return null; } @Override public void registerSchema(SerializationContext context) { context.registerProtoFiles(FileDescriptorSource.fromString(viewClassName + ".proto", schema)); } @Override public void registerMarshallers(SerializationContext context) { for (ViewConfiguration view : entry.getValue()) { context.registerMarshaller(new ProxyMarshaller<Object>(view.getProxyFactory().defineClass()) { @Override public String getTypeName() { return viewClassName + "." + view.getComponentConfiguration().getComponentName(); } }); } } }); } } return new ProtoStreamByteBufferMarshaller(builder.build()); } }, ; }
6,652
49.022556
192
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/DistributableWebSubsystemModel.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.wildfly.extension.clustering.web; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.SubsystemModel; /** * Enumerates the model versions for the distributable-web subsystem. * @author Paul Ferraro */ public enum DistributableWebSubsystemModel implements SubsystemModel { /* List of unsupported versions commented out for reference purposes: VERSION_1_0_0(1, 0, 0), // WildFly 17 */ VERSION_2_0_0(2, 0, 0), // WildFly 18-26 VERSION_3_0_0(3, 0, 0), // WildFly 27 ; public static final DistributableWebSubsystemModel CURRENT = VERSION_3_0_0; private final ModelVersion version; DistributableWebSubsystemModel(int major, int minor, int micro) { this.version = ModelVersion.create(major, minor, micro); } @Override public ModelVersion getVersion() { return this.version; } }
1,914
33.818182
79
java
null
wildfly-main/clustering/web/extension/src/main/java/org/wildfly/extension/clustering/web/InfinispanSessionManagementResourceTransformer.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.wildfly.extension.clustering.web; import java.util.function.Consumer; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder; /** * @author Paul Ferraro */ public class InfinispanSessionManagementResourceTransformer extends SessionManagementResourceTransformer implements Consumer<ModelVersion> { private final ResourceTransformationDescriptionBuilder parent; InfinispanSessionManagementResourceTransformer(ResourceTransformationDescriptionBuilder parent) { this.parent = parent; } @Override public void accept(ModelVersion version) { ResourceTransformationDescriptionBuilder builder = this.parent.addChildResource(InfinispanSessionManagementResourceDefinition.WILDCARD_PATH); this.accept(version, builder); } }
1,889
38.375
149
java