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/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentConfiguration.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.wildfly.extension.clustering.singleton.deployment; /** * Configuration of a singleton deployment. * @author Paul Ferraro */ public interface SingletonDeploymentConfiguration { String getPolicy(); }
1,244
35.617647
70
java
null
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentSchema.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.wildfly.extension.clustering.singleton.deployment; import java.util.List; import javax.xml.stream.XMLStreamException; import org.jboss.as.controller.xml.IntVersionSchema; import org.jboss.as.controller.xml.VersionedNamespace; import org.jboss.as.controller.xml.XMLElementSchema; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.jbossallxml.JBossAllSchema; import org.jboss.staxmapper.IntVersion; import org.jboss.staxmapper.XMLExtendedStreamReader; /** * Enumerates the singleton deployment configuration schemas. * @author Paul Ferraro */ public enum SingletonDeploymentSchema implements XMLElementSchema<SingletonDeploymentSchema, MutableSingletonDeploymentConfiguration>, JBossAllSchema<SingletonDeploymentSchema, SingletonDeploymentConfiguration> { VERSION_1_0(1, 0), ; public static final SingletonDeploymentSchema CURRENT = VERSION_1_0; private final VersionedNamespace<IntVersion, SingletonDeploymentSchema> namespace; SingletonDeploymentSchema(int major, int minor) { this.namespace = IntVersionSchema.createURN(List.of(IntVersionSchema.JBOSS_IDENTIFIER, this.getLocalName()), new IntVersion(major, minor)); } @Override public String getLocalName() { return "singleton-deployment"; } @Override public VersionedNamespace<IntVersion, SingletonDeploymentSchema> getNamespace() { return this.namespace; } @Override public void readElement(XMLExtendedStreamReader reader, MutableSingletonDeploymentConfiguration configuration) throws XMLStreamException { new SingletonDeploymentXMLReader(this).readElement(reader, configuration); } @Override public SingletonDeploymentConfiguration parse(XMLExtendedStreamReader reader, DeploymentUnit unit) throws XMLStreamException { MutableSingletonDeploymentConfiguration configuration = new MutableSingletonDeploymentConfiguration(unit); this.readElement(reader, configuration); return configuration; } }
3,067
39.906667
212
java
null
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentProcessor.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.wildfly.extension.clustering.singleton.deployment; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceController.Mode; import org.wildfly.clustering.singleton.SingletonPolicy; import org.wildfly.extension.clustering.singleton.SingletonLogger; /** * DUP that attaches the singleton DeploymentUnitPhaseBuilder if a deployment policy is attached. * @author Paul Ferraro */ @SuppressWarnings("removal") public class SingletonDeploymentProcessor implements DeploymentUnitProcessor, LifecycleListener { public static final AttachmentKey<SingletonPolicy> POLICY_KEY = AttachmentKey.create(SingletonPolicy.class); @Override public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException { DeploymentUnit unit = context.getDeploymentUnit(); if (unit.getParent() == null) { SingletonPolicy policy = context.getAttachment(POLICY_KEY); if (policy != null) { CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); // Ideally, we would just install the next phase using the singleton policy, however deployment unit phases do not currently support restarts // Restart the deployment using the attached phase builder, but only if a builder was not already attached if (unit.putAttachment(Attachments.DEPLOYMENT_UNIT_PHASE_BUILDER, new SingletonDeploymentUnitPhaseBuilder(support, policy)) == null) { SingletonLogger.ROOT_LOGGER.singletonDeploymentDetected(policy); ServiceController<?> controller = context.getServiceRegistry().getRequiredService(unit.getServiceName()); controller.addListener(this); controller.setMode(Mode.NEVER); } } } } @Override public void handleEvent(ServiceController<?> controller, LifecycleEvent event) { if (event == LifecycleEvent.DOWN) { controller.setMode(Mode.ACTIVE); controller.removeListener(this); } } }
3,676
48.026667
157
java
null
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentParsingProcessor.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.wildfly.extension.clustering.singleton.deployment; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.EnumSet; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.jboss.as.controller.xml.XMLElementSchema; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.jboss.as.server.logging.ServerLogger; import org.jboss.staxmapper.XMLMapper; import org.jboss.vfs.VirtualFile; /** * Parses a deployment descriptor defining the singleton deployment policy. * @author Paul Ferraro */ public class SingletonDeploymentParsingProcessor implements DeploymentUnitProcessor { private static final String SINGLETON_DEPLOYMENT_DESCRIPTOR = "META-INF/singleton-deployment.xml"; private static final XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance(); private final XMLMapper mapper = XMLElementSchema.createXMLMapper(EnumSet.allOf(SingletonDeploymentSchema.class)); @Override public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException { DeploymentUnit unit = context.getDeploymentUnit(); if (!unit.hasAttachment(SingletonDeploymentDependencyProcessor.CONFIGURATION_KEY)) { VirtualFile file = unit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot().getChild(SINGLETON_DEPLOYMENT_DESCRIPTOR); if (file.exists()) { try { unit.putAttachment(SingletonDeploymentDependencyProcessor.CONFIGURATION_KEY, this.parse(unit, file.getPhysicalFile())); } catch (IOException e) { throw new DeploymentUnitProcessingException(e); } } } } @Override public void undeploy(DeploymentUnit unit) { unit.removeAttachment(SingletonDeploymentDependencyProcessor.CONFIGURATION_KEY); } private SingletonDeploymentConfiguration parse(DeploymentUnit unit, File file) throws DeploymentUnitProcessingException { try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) { XMLStreamReader xmlReader = XML_INPUT_FACTORY.createXMLStreamReader(reader); try { MutableSingletonDeploymentConfiguration config = new MutableSingletonDeploymentConfiguration(unit); this.mapper.parseDocument(config, xmlReader); return config; } finally { xmlReader.close(); } } catch (XMLStreamException e) { throw ServerLogger.ROOT_LOGGER.errorLoadingDeploymentStructureFile(file.getPath(), e); } catch (FileNotFoundException e) { throw ServerLogger.ROOT_LOGGER.deploymentStructureFileNotFound(file); } catch (IOException e) { throw ServerLogger.ROOT_LOGGER.deploymentStructureFileNotFound(file); } } }
4,347
43.824742
139
java
null
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentDependencyProcessor.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.wildfly.extension.clustering.singleton.deployment; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.server.deployment.AttachmentKey; import org.jboss.as.server.deployment.Attachments; import org.jboss.as.server.deployment.DeploymentPhaseContext; import org.jboss.as.server.deployment.DeploymentUnit; import org.jboss.as.server.deployment.DeploymentUnitProcessingException; import org.jboss.as.server.deployment.DeploymentUnitProcessor; import org.wildfly.extension.clustering.singleton.SingletonServiceNameFactory; /** * DUP that adds a dependency on a configured deployment policy service to the next phase. * @author Paul Ferraro */ public class SingletonDeploymentDependencyProcessor implements DeploymentUnitProcessor { public static final AttachmentKey<SingletonDeploymentConfiguration> CONFIGURATION_KEY = AttachmentKey.create(SingletonDeploymentConfiguration.class); @Override public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException { DeploymentUnit unit = context.getDeploymentUnit(); if (unit.getParent() == null) { SingletonDeploymentConfiguration config = unit.getAttachment(CONFIGURATION_KEY); if (config != null) { CapabilityServiceSupport support = unit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT); context.addDependency(SingletonServiceNameFactory.SINGLETON_POLICY.getServiceName(support, config.getPolicy()), SingletonDeploymentProcessor.POLICY_KEY); } } } }
2,611
47.37037
169
java
null
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentUnitPhaseBuilder.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.wildfly.extension.clustering.singleton.deployment; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.server.deployment.DeploymentUnitPhaseBuilder; 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.wildfly.clustering.singleton.SingletonPolicy; /** * Builds a singleton service for the next phase in the deployment chain, if configured. * @author Paul Ferraro */ @SuppressWarnings({ "removal", "deprecation" }) public class SingletonDeploymentUnitPhaseBuilder implements DeploymentUnitPhaseBuilder { private static final String EJB_REMOTE_CAPABILITY = "org.wildfly.ejb.remote"; private final CapabilityServiceSupport support; private final SingletonPolicy policy; public SingletonDeploymentUnitPhaseBuilder(CapabilityServiceSupport support, SingletonPolicy policy) { this.support = support; this.policy = policy; } @Override public <T> ServiceBuilder<T> build(ServiceTarget target, ServiceName name, Service<T> service) { ServiceBuilder<T> builder = this.policy.createSingletonServiceBuilder(name, service).build(target).setInitialMode(ServiceController.Mode.ACTIVE); if (this.support.hasCapability(EJB_REMOTE_CAPABILITY)) { builder.requires(this.support.getCapabilityServiceName(EJB_REMOTE_CAPABILITY)); } return builder; } }
2,577
42.694915
153
java
null
wildfly-main/clustering/singleton/service/src/main/java/org/wildfly/clustering/singleton/service/SingletonCacheRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.service; import org.jboss.as.clustering.controller.BinaryRequirementServiceNameFactory; import org.jboss.as.clustering.controller.BinaryServiceNameFactory; import org.jboss.as.clustering.controller.DefaultableBinaryServiceNameFactoryProvider; import org.jboss.as.clustering.controller.UnaryServiceNameFactory; import org.wildfly.clustering.service.BinaryRequirement; /** * @author Paul Ferraro */ public enum SingletonCacheRequirement implements DefaultableBinaryServiceNameFactoryProvider { @Deprecated(forRemoval = true) SINGLETON_SERVICE_BUILDER_FACTORY(org.wildfly.clustering.singleton.SingletonCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY, SingletonDefaultCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY), SINGLETON_SERVICE_CONFIGURATOR_FACTORY(org.wildfly.clustering.singleton.SingletonCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY, SingletonDefaultCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY), ; private final BinaryServiceNameFactory factory; private final SingletonDefaultCacheRequirement defaultRequirement; SingletonCacheRequirement(BinaryRequirement requirement, SingletonDefaultCacheRequirement defaultRequirement) { this.factory = new BinaryRequirementServiceNameFactory(requirement); this.defaultRequirement = defaultRequirement; } @Override public BinaryServiceNameFactory getServiceNameFactory() { return this.factory; } @Override public UnaryServiceNameFactory getDefaultServiceNameFactory() { return this.defaultRequirement; } }
2,634
46.909091
231
java
null
wildfly-main/clustering/singleton/service/src/main/java/org/wildfly/clustering/singleton/service/SingletonDefaultCacheRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.service; import org.jboss.as.clustering.controller.UnaryRequirementServiceNameFactory; import org.jboss.as.clustering.controller.UnaryServiceNameFactory; import org.jboss.as.clustering.controller.UnaryServiceNameFactoryProvider; import org.wildfly.clustering.service.UnaryRequirement; /** * @author Paul Ferraro */ public enum SingletonDefaultCacheRequirement implements UnaryServiceNameFactoryProvider { @Deprecated(forRemoval = true) SINGLETON_SERVICE_BUILDER_FACTORY(org.wildfly.clustering.singleton.SingletonDefaultCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY), SINGLETON_SERVICE_CONFIGURATOR_FACTORY(org.wildfly.clustering.singleton.SingletonDefaultCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY), ; private final UnaryServiceNameFactory factory; SingletonDefaultCacheRequirement(UnaryRequirement requirement) { this.factory = new UnaryRequirementServiceNameFactory(requirement); } @Override public UnaryServiceNameFactory getServiceNameFactory() { return this.factory; } }
2,116
44.042553
170
java
null
wildfly-main/clustering/singleton/api/src/test/java/org/wildfly/clustering/server/singleton/election/PreferredSingletonElectionPolicyTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.server.singleton.election; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.List; import org.junit.Test; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.SingletonElectionPolicy; import org.wildfly.clustering.singleton.election.Preference; import org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy; /** * @author Paul Ferraro */ public class PreferredSingletonElectionPolicyTestCase { @Test public void elect() { SingletonElectionPolicy policy = mock(SingletonElectionPolicy.class); Preference preference1 = mock(Preference.class); Preference preference2 = mock(Preference.class); Node node1 = mock(Node.class); Node node2 = mock(Node.class); Node node3 = mock(Node.class); Node node4 = mock(Node.class); when(preference1.preferred(same(node1))).thenReturn(true); when(preference1.preferred(same(node2))).thenReturn(false); when(preference1.preferred(same(node3))).thenReturn(false); when(preference1.preferred(same(node4))).thenReturn(false); when(preference2.preferred(same(node1))).thenReturn(false); when(preference2.preferred(same(node2))).thenReturn(true); when(preference2.preferred(same(node3))).thenReturn(false); when(preference2.preferred(same(node4))).thenReturn(false); assertSame(node1, new PreferredSingletonElectionPolicy(policy, preference1, preference2).elect(Arrays.asList(node1, node2, node3, node4))); assertSame(node1, new PreferredSingletonElectionPolicy(policy, preference1, preference2).elect(Arrays.asList(node4, node3, node2, node1))); assertSame(node2, new PreferredSingletonElectionPolicy(policy, preference1, preference2).elect(Arrays.asList(node2, node3, node4))); assertSame(node2, new PreferredSingletonElectionPolicy(policy, preference1, preference2).elect(Arrays.asList(node4, node3, node2))); List<Node> nodes = Arrays.asList(node3, node4); when(policy.elect(nodes)).thenReturn(node3); assertSame(node3, new PreferredSingletonElectionPolicy(policy, preference1, preference2).elect(nodes)); when(policy.elect(nodes)).thenReturn(node4); assertSame(node4, new PreferredSingletonElectionPolicy(policy, preference1, preference2).elect(nodes)); when(policy.elect(nodes)).thenReturn(null); assertNull(new PreferredSingletonElectionPolicy(policy, preference1, preference2).elect(nodes)); } }
3,784
44.60241
147
java
null
wildfly-main/clustering/singleton/api/src/test/java/org/wildfly/clustering/server/singleton/election/SocketAddressPreferenceTestCase.java
package org.wildfly.clustering.server.singleton.election; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; import org.junit.Test; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.election.Preference; import org.wildfly.clustering.singleton.election.SocketAddressPreference; public class SocketAddressPreferenceTestCase { @Test public void test() throws UnknownHostException { InetSocketAddress preferredAddress = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 1); InetSocketAddress otherAddress1 = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2); InetSocketAddress otherAddress2 = new InetSocketAddress(InetAddress.getByName("127.0.0.2"), 1); Preference preference = new SocketAddressPreference(preferredAddress); Node preferredNode = mock(Node.class); Node otherNode1 = mock(Node.class); Node otherNode2 = mock(Node.class); when(preferredNode.getSocketAddress()).thenReturn(preferredAddress); when(otherNode1.getSocketAddress()).thenReturn(otherAddress1); when(otherNode2.getSocketAddress()).thenReturn(otherAddress2); assertTrue(preference.preferred(preferredNode)); assertFalse(preference.preferred(otherNode1)); assertFalse(preference.preferred(otherNode2)); } }
1,568
39.230769
106
java
null
wildfly-main/clustering/singleton/api/src/test/java/org/wildfly/clustering/server/singleton/election/NamePreferenceTestCase.java
package org.wildfly.clustering.server.singleton.election; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.election.NamePreference; import org.wildfly.clustering.singleton.election.Preference; public class NamePreferenceTestCase { @Test public void test() { Preference preference = new NamePreference("node1"); Node node1 = mock(Node.class); Node node2 = mock(Node.class); when(node1.getName()).thenReturn("node1"); when(node2.getName()).thenReturn("node2"); assertTrue(preference.preferred(node1)); assertFalse(preference.preferred(node2)); } }
843
29.142857
64
java
null
wildfly-main/clustering/singleton/api/src/test/java/org/wildfly/clustering/server/singleton/election/SimpleSingletonElectionPolicyTestCase.java
/* * JBoss, Home of Professional Open Source. * Copyright 2008, Red Hat Middleware LLC, and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.server.singleton.election; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.mockito.Mockito.mock; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Test; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy; /** * @author Paul Ferraro */ public class SimpleSingletonElectionPolicyTestCase { @Test public void elect() { Node node1 = mock(Node.class); Node node2 = mock(Node.class); Node node3 = mock(Node.class); List<Node> nodes = Arrays.asList(node1, node2, node3); assertSame(node1, new SimpleSingletonElectionPolicy().elect(nodes)); assertSame(node1, new SimpleSingletonElectionPolicy(0).elect(nodes)); assertSame(node2, new SimpleSingletonElectionPolicy(1).elect(nodes)); assertSame(node3, new SimpleSingletonElectionPolicy(2).elect(nodes)); assertSame(node1, new SimpleSingletonElectionPolicy(3).elect(nodes)); assertNull(new SimpleSingletonElectionPolicy().elect(Collections.<Node>emptyList())); } }
2,237
38.964286
93
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonElectionListener.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.clustering.singleton; import java.util.List; import org.wildfly.clustering.group.Node; /** * Listener for singleton election results. * @author Paul Ferraro */ public interface SingletonElectionListener { /** * Triggered when a singleton election completes, electing the specified member from the specified list of candidates. * @param candidateMembers the list of candidate members * @param electedMember the elected primary provider of a singleton service */ void elected(List<Node> candidateMembers, Node electedMember); }
1,604
38.146341
122
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/Singleton.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton; import java.util.Set; import org.wildfly.clustering.group.Node; /** * @author Paul Ferraro */ public interface Singleton { /** * Indicates whether this node is the primary provider of the singleton. * @return true, if this node is the primary node, false if it is a backup node. */ boolean isPrimary(); /** * Returns the current primary provider of the singleton. * @return a cluster member */ Node getPrimaryProvider(); /** * Returns the providers on which the given singleton is available. * @return a set of cluster members */ Set<Node> getProviders(); }
1,700
32.352941
84
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonServiceBuilderFactory.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.wildfly.clustering.singleton; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory; /** * Factory for creating a singleton service builder. * @author Paul Ferraro * @deprecated Replaced by {@link SingletonServiceConfiguratorFactory} */ @Deprecated(forRemoval = true) public interface SingletonServiceBuilderFactory extends SingletonPolicy, SingletonServiceConfiguratorFactory { @Override <T> SingletonServiceBuilder<T> createSingletonServiceBuilder(ServiceName name, Service<T> service); @Override <T> SingletonServiceBuilder<T> createSingletonServiceBuilder(ServiceName name, Service<T> primaryService, Service<T> backupService); }
1,803
41.952381
136
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton; import org.jboss.msc.service.Service; /** * Implemented by the instrumented singleton service. * @author Paul Ferraro * @deprecated Replaced by {@link org.wildfly.clustering.singleton.service.SingletonService}. */ @Deprecated(forRemoval = true) public interface SingletonService<T> extends org.wildfly.clustering.singleton.service.SingletonService, Service<T> { }
1,437
38.944444
116
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonCacheRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton; import org.wildfly.clustering.service.DefaultableBinaryRequirement; import org.wildfly.clustering.service.UnaryRequirement; /** * @author Paul Ferraro */ public enum SingletonCacheRequirement implements DefaultableBinaryRequirement { /** * @deprecated Use {@link SingletonCacheRequirement#SINGLETON_SERVICE_CONFIGURATOR_FACTORY} instead. */ @Deprecated(forRemoval = true) SINGLETON_SERVICE_BUILDER_FACTORY("org.wildfly.clustering.cache.singleton-service-builder-factory", SingletonDefaultCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY), SINGLETON_SERVICE_CONFIGURATOR_FACTORY("org.wildfly.clustering.cache.singleton-service-configurator-factory", SingletonDefaultCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY), ; private final String name; private final UnaryRequirement defaultRequirement; SingletonCacheRequirement(String name, UnaryRequirement defaultRequirement) { this.name = name; this.defaultRequirement = defaultRequirement; } @Override public String getName() { return this.name; } @Override public UnaryRequirement getDefaultRequirement() { return this.defaultRequirement; } }
2,273
38.894737
203
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonElectionPolicy.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton; import java.util.List; import org.wildfly.clustering.group.Node; /** * Used by a singleton service to elect the primary node from among the list of nodes that can provide the given service. * @author Paul Ferraro */ public interface SingletonElectionPolicy { /** * Elect a single node from the specified list of candidate nodes. * @param nodes a list of candidate nodes. * @return the elected node */ Node elect(List<Node> nodes); }
1,533
36.414634
121
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton; import org.wildfly.clustering.service.DefaultableUnaryRequirement; import org.wildfly.clustering.service.Requirement; /** * @author Paul Ferraro */ public enum SingletonRequirement implements DefaultableUnaryRequirement { /** * @deprecated Use {@link SingletonRequirement#POLICY} instead. */ @Deprecated(forRemoval = true) SINGLETON_POLICY("org.wildfly.clustering.singleton.policy", SingletonDefaultRequirement.SINGLETON_POLICY), POLICY("org.wildfly.clustering.singleton-policy", SingletonDefaultRequirement.POLICY), ; private final String name; private final Requirement defaultRequirement; SingletonRequirement(String name, Requirement defaultRequirement) { this.name = name; this.defaultRequirement = defaultRequirement; } @Override public String getName() { return this.name; } @Override public Requirement getDefaultRequirement() { return this.defaultRequirement; } }
2,044
35.517857
141
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonDefaultCacheRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton; import org.wildfly.clustering.service.UnaryRequirement; import org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory; /** * @author Paul Ferraro */ public enum SingletonDefaultCacheRequirement implements UnaryRequirement { /** * @deprecated Use {@link SingletonDefaultCacheRequirement#SINGLETON_SERVICE_CONFIGURATOR_FACTORY} instead. */ @Deprecated(forRemoval = true) SINGLETON_SERVICE_BUILDER_FACTORY("org.wildfly.clustering.cache.default-singleton-service-builder-factory", SingletonServiceBuilderFactory.class), SINGLETON_SERVICE_CONFIGURATOR_FACTORY("org.wildfly.clustering.cache.default-singleton-service-configurator-factory", SingletonServiceConfiguratorFactory.class), ; private final String name; private final Class<?> type; SingletonDefaultCacheRequirement(String name, Class<?> type) { this.name = name; this.type = type; } @Override public String getName() { return this.name; } @Override public Class<?> getType() { return this.type; } }
2,147
36.684211
181
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonDefaultRequirement.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton; import org.wildfly.clustering.service.Requirement; /** * Enumerates capability requirements for default singleton resources * @author Paul Ferraro */ public enum SingletonDefaultRequirement implements Requirement { /** * @deprecated Use {@link SingletonDefaultRequirement#POLICY} instead. */ @Deprecated(forRemoval = true) SINGLETON_POLICY("org.wildfly.clustering.singleton.default-policy", org.wildfly.clustering.singleton.SingletonPolicy.class), POLICY("org.wildfly.clustering.default-singleton-policy", org.wildfly.clustering.singleton.service.SingletonPolicy.class), ; private final String name; private final Class<?> type; SingletonDefaultRequirement(String name, Class<?> type) { this.name = name; this.type = type; } @Override public String getName() { return this.name; } @Override public Class<?> getType() { return this.type; } }
2,013
34.964286
159
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonServiceBuilder.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.wildfly.clustering.singleton; import org.wildfly.clustering.service.Builder; import org.wildfly.clustering.singleton.service.SingletonServiceConfigurator; /** * Builds a singleton service. * @author Paul Ferraro * @param <T> the singleton service value type * @deprecated Replaced by {@link SingletonServiceConfigurator}. */ @Deprecated(forRemoval = true) public interface SingletonServiceBuilder<T> extends Builder<T> { /** * Defines the minimum number of members required before a singleton election will take place. * @param quorum the quorum required for electing a primary singleton provider * @return a reference to this builder */ SingletonServiceBuilder<T> requireQuorum(int quorum); /** * Defines the policy for electing a primary singleton provider. * @param policy an election policy * @return a reference to this builder */ SingletonServiceBuilder<T> electionPolicy(SingletonElectionPolicy policy); /** * Defines a listener to trigger following the election of a primary singleton provider. * @param listener an election listener * @return a reference to this builder */ SingletonServiceBuilder<T> electionListener(SingletonElectionListener listener); }
2,295
39.280702
98
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/SingletonPolicy.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.wildfly.clustering.singleton; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.Builder; /** * Defines a singleton policy. * @author Paul Ferraro * @deprecated Replaced by {@link org.wildfly.clustering.singleton.service.SingletonPolicy}. */ @Deprecated(forRemoval = true) public interface SingletonPolicy extends org.wildfly.clustering.singleton.service.SingletonPolicy { /** * Creates a singleton service builder. * @param name the name of the service * @param service the service to run when elected as the primary node * @return a builder * @deprecated Use {@link #createSingletonServiceConfigurator(ServiceName)} instead. */ @Deprecated <T> Builder<T> createSingletonServiceBuilder(ServiceName name, Service<T> service); /** * Creates a singleton service builder. * @param name the name of the service * @param primaryService the service to run when elected as the primary node * @param backupService the service to run when not elected as the primary node * @return a builder * @deprecated Use {@link #createSingletonServiceConfigurator(ServiceName)} instead. */ @Deprecated <T> Builder<T> createSingletonServiceBuilder(ServiceName name, Service<T> primaryService, Service<T> backupService); }
2,400
40.396552
120
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/service/ImmutableSingletonServiceConfigurator.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.clustering.singleton.service; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.service.ServiceConfigurator; /** * An immutable {@link ServiceConfigurator} used to build a singleton service. * @author Paul Ferraro */ public interface ImmutableSingletonServiceConfigurator extends ServiceConfigurator { @Override SingletonServiceBuilder<?> build(ServiceTarget target); }
1,452
38.27027
84
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/service/SingletonService.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.clustering.singleton.service; import org.jboss.msc.Service; import org.wildfly.clustering.singleton.Singleton; /** * Implemented by the instrumented singleton service. * @author Paul Ferraro */ public interface SingletonService extends Singleton, Service { }
1,309
36.428571
70
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/service/SingletonServiceConfiguratorFactory.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.clustering.singleton.service; import org.jboss.msc.service.ServiceName; /** * Extension of {@link SingletonPolicy} for customizing singleton service behavior. * @author Paul Ferraro */ public interface SingletonServiceConfiguratorFactory extends SingletonPolicy { @Override SingletonServiceConfigurator createSingletonServiceConfigurator(ServiceName name); }
1,417
38.388889
86
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/service/SingletonServiceConfigurator.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.clustering.singleton.service; import org.wildfly.clustering.singleton.SingletonElectionListener; import org.wildfly.clustering.singleton.SingletonElectionPolicy; /** * Extension of {@link ImmutableSingletonServiceConfigurator} for customizing singleton service behavior. * @author Paul Ferraro */ public interface SingletonServiceConfigurator extends ImmutableSingletonServiceConfigurator { /** * Defines the minimum number of members required before a singleton election will take place. * @param quorum the quorum required for electing a primary singleton provider * @return a reference to this configurator */ SingletonServiceConfigurator requireQuorum(int quorum); /** * Defines the policy for electing a primary singleton provider. * @param policy an election policy * @return a reference to this configurator */ SingletonServiceConfigurator electionPolicy(SingletonElectionPolicy policy); /** * Defines a listener to trigger following the election of a primary singleton provider. * @param listener an election listener * @return a reference to this configurator */ SingletonServiceConfigurator electionListener(SingletonElectionListener listener); }
2,292
41.462963
105
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/service/SingletonServiceBuilder.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.clustering.singleton.service; import org.jboss.msc.service.ServiceBuilder; /** * Extends {@link ServiceBuilder} to facilitate building singleton services. * @author Paul Ferraro */ public interface SingletonServiceBuilder<T> extends ServiceBuilder<T> { }
1,305
37.411765
76
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/service/SingletonPolicy.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.wildfly.clustering.singleton.service; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.service.ServiceConfigurator; /** * Defines a policy for creating singleton services. * @author Paul Ferraro */ public interface SingletonPolicy { ServiceConfigurator createSingletonServiceConfigurator(ServiceName name); }
1,378
37.305556
77
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/election/NamePreference.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.wildfly.clustering.singleton.election; import org.wildfly.clustering.group.Node; public class NamePreference implements Preference { private final String name; public NamePreference(String name) { this.name = name; } @Override public boolean preferred(Node node) { return node.getName().equals(this.name); } @Override public String toString() { return this.name; } }
1,467
33.139535
70
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/election/SimpleSingletonElectionPolicy.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.wildfly.clustering.singleton.election; import java.util.List; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.SingletonElectionPolicy; /** * A simple concrete policy service that decides which node in the cluster should be the primary node to run certain HASingleton * service based on attribute "Position". The value will be divided by partition size and only remainder will be used. * * Let's say partition size is n: 0 means the first oldest node. 1 means the 2nd oldest node. ... n-1 means the nth oldest node. * * -1 means the youngest node. -2 means the 2nd youngest node. ... -n means the nth youngest node. * * E.g. the following attribute says the singleton will be running on the 3rd oldest node of the current partition: <attribute * name="Position">2</attribute> * * If no election policy is defined, the oldest node in the cluster runs the singleton. This behavior can be achieved with this * policy when "position" is set to 0. * * @author <a href="mailto:Alex.Fu@novell.com">Alex Fu</a> * @author <a href="mailto:galder.zamarreno@jboss.com">Galder Zamarreno</a> * @author Paul Ferraro */ public class SimpleSingletonElectionPolicy implements SingletonElectionPolicy { private final int position; public SimpleSingletonElectionPolicy() { this(0); } public SimpleSingletonElectionPolicy(int position) { this.position = position; } @Override public Node elect(List<Node> candidates) { int size = candidates.size(); return (size > 0) ? candidates.get(((this.position % size) + size) % size) : null; } }
2,671
40.107692
128
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/election/SocketAddressPreference.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.wildfly.clustering.singleton.election; import java.net.InetSocketAddress; import org.wildfly.clustering.group.Node; public class SocketAddressPreference implements Preference { private final InetSocketAddress address; public SocketAddressPreference(InetSocketAddress address) { this.address = address; } @Override public boolean preferred(Node node) { return node.getSocketAddress().getAddress().getHostAddress().equals(this.address.getAddress().getHostAddress()) && (node.getSocketAddress().getPort() == this.address.getPort()); } @Override public String toString() { return this.address.toString(); } }
1,706
36.933333
185
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/election/Preference.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.wildfly.clustering.singleton.election; import org.wildfly.clustering.group.Node; public interface Preference { boolean preferred(Node node); }
1,184
39.862069
70
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/election/PreferredSingletonElectionPolicy.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.wildfly.clustering.singleton.election; import java.util.Arrays; import java.util.List; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.SingletonElectionPolicy; /** * An election policy that always elects a preferred node, and defers to a default policy * if the preferred node is not a candidate. The means of specifying the preferred node is * the responsibility of the extending class. * @author Paul Ferraro */ public class PreferredSingletonElectionPolicy implements SingletonElectionPolicy { private final List<Preference> preferences; private final SingletonElectionPolicy policy; public PreferredSingletonElectionPolicy(SingletonElectionPolicy policy, Preference... preferences) { this(policy, Arrays.asList(preferences)); } public PreferredSingletonElectionPolicy(SingletonElectionPolicy policy, List<Preference> preferences) { this.policy = policy; this.preferences = preferences; } @Override public Node elect(List<Node> candidates) { for (Preference preference: this.preferences) { for (Node candidate: candidates) { if (preference.preferred(candidate)) { return candidate; } } } return this.policy.elect(candidates); } }
2,374
37.934426
107
java
null
wildfly-main/clustering/singleton/api/src/main/java/org/wildfly/clustering/singleton/election/RandomSingletonElectionPolicy.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.wildfly.clustering.singleton.election; import java.util.List; import java.util.Random; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.SingletonElectionPolicy; /** * {@link SingletonElectionPolicy} that elects a random member. * @author Paul Ferraro */ public class RandomSingletonElectionPolicy implements SingletonElectionPolicy { private final Random random = new Random(System.currentTimeMillis()); /** * {@inheritDoc} */ @Override public Node elect(List<Node> nodes) { int size = nodes.size(); return (size > 0) ? nodes.get(this.random.nextInt(size)) : null; } }
1,692
34.270833
79
java
null
wildfly-main/clustering/singleton/server/src/test/java/org/wildfly/clustering/singleton/server/ExceptionTestCase.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.clustering.singleton.server; import java.io.IOException; import org.jboss.msc.service.ServiceNotFoundException; import org.jboss.msc.service.StartException; import org.junit.Assert; import org.junit.Test; import org.wildfly.clustering.marshalling.Tester; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; /** * Unit test for marshalling of singleton service exceptions. * @author Paul Ferraro */ public class ExceptionTestCase { @Test public void test() throws IOException { Tester<Throwable> tester = ProtoStreamTesterFactory.INSTANCE.createTester(); tester.test(new StartException(), ExceptionTestCase::assertEquals); tester.test(new StartException("message"), ExceptionTestCase::assertEquals); tester.test(new StartException(new Exception()), ExceptionTestCase::assertEquals); tester.test(new StartException("message", new Exception()), ExceptionTestCase::assertEquals); tester.test(new ServiceNotFoundException(), ExceptionTestCase::assertEquals); tester.test(new ServiceNotFoundException("message"), ExceptionTestCase::assertEquals); tester.test(new ServiceNotFoundException(new Exception()), ExceptionTestCase::assertEquals); tester.test(new ServiceNotFoundException("message", new Exception()), ExceptionTestCase::assertEquals); } private static void assertEquals(Throwable exception1, Throwable exception2) { if ((exception1 != null) && (exception2 != null)) { Assert.assertSame(exception1.getClass(), exception2.getClass()); Assert.assertEquals(exception1.getMessage(), exception2.getMessage()); assertEquals(exception1.getCause(), exception2.getCause()); } else { Assert.assertSame(exception1, exception2); } } }
2,870
43.859375
111
java
null
wildfly-main/clustering/singleton/server/src/test/java/org/wildfly/clustering/singleton/server/ServiceNameFormatterTestCase.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.wildfly.clustering.singleton.server; import java.io.IOException; import org.jboss.msc.service.ServiceName; import org.junit.Test; import org.wildfly.clustering.infinispan.persistence.DynamicKeyFormatMapper; import org.wildfly.clustering.infinispan.persistence.KeyMapperTester; import org.wildfly.clustering.marshalling.ExternalizerTester; import org.wildfly.clustering.marshalling.jboss.JBossMarshallingTesterFactory; import org.wildfly.clustering.marshalling.protostream.ProtoStreamTesterFactory; import org.wildfly.clustering.marshalling.spi.FormatterTester; import org.wildfly.clustering.singleton.server.ServiceNameFormatter.ServiceNameExternalizer; /** * Unit test for {@link ServiceNameFormatter}. * @author Paul Ferraro */ public class ServiceNameFormatterTestCase { private final ServiceName name = ServiceName.JBOSS.append("foo", "bar"); @Test public void test() throws IOException { new ExternalizerTester<>(new ServiceNameExternalizer()).test(this.name); new FormatterTester<>(new ServiceNameFormatter()).test(this.name); new KeyMapperTester(new DynamicKeyFormatMapper(Thread.currentThread().getContextClassLoader())).test(this.name); JBossMarshallingTesterFactory.INSTANCE.createTester().test(this.name); ProtoStreamTesterFactory.INSTANCE.createTester().test(this.name); } }
2,387
43.222222
120
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/AbstractDistributedSingletonService.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.clustering.singleton.server; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.function.Supplier; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceNotFoundException; import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.wildfly.clustering.dispatcher.CommandDispatcher; import org.wildfly.clustering.dispatcher.CommandDispatcherException; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.provider.ServiceProviderRegistration; import org.wildfly.clustering.provider.ServiceProviderRegistration.Listener; import org.wildfly.clustering.provider.ServiceProviderRegistry; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.singleton.SingletonElectionListener; import org.wildfly.clustering.singleton.SingletonElectionPolicy; import org.wildfly.clustering.singleton.service.SingletonService; import org.wildfly.security.manager.WildFlySecurityManager; /** * Logic common to current and legacy {@link SingletonService} implementations. * @author Paul Ferraro */ public abstract class AbstractDistributedSingletonService<C extends SingletonContext> implements SingletonService, SingletonContext, Listener, Supplier<C> { private final ServiceName name; private final Supplier<ServiceProviderRegistry<ServiceName>> registry; private final Supplier<CommandDispatcherFactory> dispatcherFactory; private final SingletonElectionPolicy electionPolicy; private final SingletonElectionListener electionListener; private final int quorum; private final Function<ServiceTarget, Lifecycle> primaryLifecycleFactory; private final AtomicBoolean primary = new AtomicBoolean(false); private volatile Lifecycle primaryLifecycle; private volatile CommandDispatcher<C> dispatcher; private volatile ServiceProviderRegistration<ServiceName> registration; public AbstractDistributedSingletonService(DistributedSingletonServiceContext context, Function<ServiceTarget, Lifecycle> primaryLifecycleFactory) { this.name = context.getServiceName(); this.registry = context.getServiceProviderRegistry(); this.dispatcherFactory = context.getCommandDispatcherFactory(); this.electionPolicy = context.getElectionPolicy(); this.electionListener = context.getElectionListener(); this.quorum = context.getQuorum(); this.primaryLifecycleFactory = primaryLifecycleFactory; } @Override public void start(StartContext context) throws StartException { ServiceTarget target = context.getChildTarget(); this.primaryLifecycle = this.primaryLifecycleFactory.apply(target); this.dispatcher = this.dispatcherFactory.get().createCommandDispatcher(this.name.getCanonicalName(), this.get(), WildFlySecurityManager.getClassLoaderPrivileged(this.getClass())); this.registration = this.registry.get().register(this.name, this); } @Override public void stop(StopContext context) { this.registration.close(); this.dispatcher.close(); } @Override public synchronized void providersChanged(Set<Node> nodes) { Group group = this.registry.get().getGroup(); List<Node> candidates = new ArrayList<>(group.getMembership().getMembers()); candidates.retainAll(nodes); // Only run election on a single node if (candidates.isEmpty() || candidates.get(0).equals(group.getLocalMember())) { // First validate that quorum was met int size = candidates.size(); boolean quorumMet = size >= this.quorum; if ((this.quorum > 1) && (size == this.quorum)) { // Log fragility of singleton availability SingletonLogger.ROOT_LOGGER.quorumJustReached(this.name.getCanonicalName(), this.quorum); } Node elected = quorumMet ? this.electionPolicy.elect(candidates) : null; try { if (elected != null) { // Stop service on every node except elected node for (Map.Entry<Node, CompletionStage<Void>> entry : this.dispatcher.executeOnGroup(new StopCommand(), elected).entrySet()) { try { entry.getValue().toCompletableFuture().join(); } catch (CancellationException e) { SingletonLogger.ROOT_LOGGER.tracef("Singleton service %s is not installed on %s", this.name.getCanonicalName(), entry.getKey().getName()); } catch (CompletionException e) { Throwable cause = e.getCause(); if ((cause instanceof IllegalStateException) && (cause.getCause() instanceof ServiceNotFoundException)) { SingletonLogger.ROOT_LOGGER.debugf("Singleton service %s is no longer installed on %s", this.name.getCanonicalName(), entry.getKey().getName()); } else { throw e; } } } // Start service on elected node try { this.dispatcher.executeOnMember(new StartCommand(), elected).toCompletableFuture().join(); } catch (CancellationException e) { SingletonLogger.ROOT_LOGGER.debugf("Singleton service %s could not be started on the elected primary singleton provider (%s) because it left the cluster. A new primary provider election will take place.", this.name.getCanonicalName(), elected.getName()); } catch (CompletionException e) { Throwable cause = e.getCause(); if ((cause instanceof IllegalStateException) && (cause.getCause() instanceof ServiceNotFoundException)) { SingletonLogger.ROOT_LOGGER.debugf("Service % is no longer installed on the elected primary singleton provider (%s). A new primary provider election will take place.", this.name.getCanonicalName(), elected.getName()); } else { throw e; } } } else { if (!quorumMet) { SingletonLogger.ROOT_LOGGER.quorumNotReached(this.name.getCanonicalName(), this.quorum); } // Stop service on every node for (Map.Entry<Node, CompletionStage<Void>> entry : this.dispatcher.executeOnGroup(new StopCommand()).entrySet()) { try { entry.getValue().toCompletableFuture().join(); } catch (CancellationException e) { SingletonLogger.ROOT_LOGGER.tracef("Singleton service %s is not installed on %s", this.name.getCanonicalName(), entry.getKey().getName()); } catch (CompletionException e) { Throwable cause = e.getCause(); if ((cause instanceof IllegalStateException) && (cause.getCause() instanceof ServiceNotFoundException)) { SingletonLogger.ROOT_LOGGER.debugf("Singleton service %s is no longer installed on %s", this.name.getCanonicalName(), entry.getKey().getName()); } else { throw e; } } } } if (this.electionListener != null) { for (CompletionStage<Void> stage : this.dispatcher.executeOnGroup(new SingletonElectionCommand(candidates, elected)).values()) { try { stage.toCompletableFuture().join(); } catch (CancellationException e) { // Ignore } } } } catch (CommandDispatcherException e) { throw new IllegalStateException(e); } } } @Override public synchronized void start() { // If we were not already the primary node if (this.primary.compareAndSet(false, true)) { this.primaryLifecycle.start(); } } @Override public synchronized void stop() { // If we were the previous the primary node if (this.primary.compareAndSet(true, false)) { this.primaryLifecycle.stop(); } } @Override public void elected(List<Node> candidates, Node elected) { try { this.electionListener.elected(candidates, elected); } catch (Throwable e) { SingletonLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } @Override public boolean isPrimary() { return this.primary.get(); } @Override public Node getPrimaryProvider() { if (this.isPrimary()) return this.registry.get().getGroup().getLocalMember(); List<Node> primaryMembers = new LinkedList<>(); try { for (Map.Entry<Node, CompletionStage<Boolean>> entry : this.dispatcher.executeOnGroup(new PrimaryProviderCommand()).entrySet()) { try { if (entry.getValue().toCompletableFuture().join()) { primaryMembers.add(entry.getKey()); } } catch (CancellationException e) { // Ignore } } if (primaryMembers.size() > 1) { throw SingletonLogger.ROOT_LOGGER.multiplePrimaryProvidersDetected(this.name.getCanonicalName(), primaryMembers); } return !primaryMembers.isEmpty() ? primaryMembers.get(0) : null; } catch (CommandDispatcherException e) { throw new IllegalStateException(e); } } @Override public Set<Node> getProviders() { return this.registration.getProviders(); } int getQuorum() { return this.quorum; } CommandDispatcher<C> getCommandDispatcher() { return this.dispatcher; } ServiceProviderRegistration<ServiceName> getServiceProviderRegistration() { return this.registration; } }
11,920
45.027027
279
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceBuilder.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.wildfly.clustering.singleton.server; import java.util.function.Supplier; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.SingletonElectionListener; import org.wildfly.clustering.singleton.SingletonElectionPolicy; import org.wildfly.clustering.singleton.SingletonService; import org.wildfly.clustering.singleton.SingletonServiceBuilder; import org.wildfly.clustering.singleton.service.SingletonServiceConfigurator; /** * Local {@link SingletonServiceConfigurator} implementation that uses JBoss MSC 1.3.x service installation. * @author Paul Ferraro */ @Deprecated public class LocalSingletonServiceBuilder<T> extends SimpleServiceNameProvider implements SingletonServiceBuilder<T>, LocalSingletonServiceContext { private final Service<T> service; private final SupplierDependency<Group> group; private volatile SingletonElectionListener listener; public LocalSingletonServiceBuilder(ServiceName name, Service<T> service, LocalSingletonServiceConfiguratorContext context) { super(name); this.service = service; this.group = context.getGroupDependency(); this.listener = new DefaultSingletonElectionListener(name, this.group); } @Override public SingletonServiceBuilder<T> requireQuorum(int quorum) { // Quorum requirements are inconsequential to a local singleton return this; } @Override public SingletonServiceBuilder<T> electionPolicy(SingletonElectionPolicy policy) { // Election policies are inconsequential to a local singleton return this; } @Override public SingletonServiceBuilder<T> electionListener(SingletonElectionListener listener) { this.listener = listener; return this; } @Override public ServiceBuilder<T> build(ServiceTarget target) { SingletonService<T> service = new LocalLegacySingletonService<>(this.service, this); return this.group.register(target.addService(this.getServiceName(), service)); } @Override public Supplier<Group> getGroup() { return this.group; } @Override public SingletonElectionListener getElectionListener() { return this.listener; } }
3,560
37.706522
148
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/StopCommand.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.wildfly.clustering.singleton.server; import org.wildfly.clustering.dispatcher.Command; /** * Command to stop a singleton service. * @author Paul Ferraro */ public class StopCommand implements Command<Void, Lifecycle> { private static final long serialVersionUID = 3194143912789013071L; @Override public Void execute(Lifecycle context) throws Exception { context.stop(); return null; } }
1,461
35.55
70
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceConfigurator.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.clustering.singleton.server; import java.util.function.Supplier; import org.jboss.msc.Service; import org.jboss.msc.service.DelegatingServiceBuilder; 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.group.Group; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.SingletonElectionListener; import org.wildfly.clustering.singleton.SingletonElectionPolicy; import org.wildfly.clustering.singleton.service.SingletonServiceBuilder; import org.wildfly.clustering.singleton.service.SingletonServiceConfigurator; /** * Local {@link SingletonServiceConfigurator} implementation that uses JBoss MSC 1.4.x service installation. * @author Paul Ferraro */ public class LocalSingletonServiceConfigurator extends SimpleServiceNameProvider implements SingletonServiceConfigurator, LocalSingletonServiceContext { private final SupplierDependency<Group> group; private volatile SingletonElectionListener listener; public LocalSingletonServiceConfigurator(ServiceName name, LocalSingletonServiceConfiguratorContext context) { super(name); this.group = context.getGroupDependency(); this.listener = new DefaultSingletonElectionListener(name, this.group); } @Override public SingletonServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); return new LocalSingletonServiceBuilder<>(this.group.register(builder), this); } @Override public SingletonServiceConfigurator requireQuorum(int quorum) { // Quorum requirements are inconsequential to a local singleton return this; } @Override public SingletonServiceConfigurator electionPolicy(SingletonElectionPolicy policy) { // Election policies are inconsequential to a local singleton return this; } @Override public SingletonServiceConfigurator electionListener(SingletonElectionListener listener) { this.listener = listener; return this; } @Override public Supplier<Group> getGroup() { return this.group; } @Override public SingletonElectionListener getElectionListener() { return this.listener; } private static class LocalSingletonServiceBuilder<T> extends DelegatingServiceBuilder<T> implements SingletonServiceBuilder<T> { private final LocalSingletonServiceContext context; private Service service = Service.NULL; LocalSingletonServiceBuilder(ServiceBuilder<T> builder, LocalSingletonServiceContext context) { super(builder); this.context = context; } @Override public ServiceBuilder<T> setInstance(Service service) { this.service = service; return this; } @Override public ServiceController<T> install() { return this.getDelegate().setInstance(new LocalSingletonService(this.service, this.context)).install(); } } }
4,287
37.285714
152
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonElectionCommandMarshaller.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.clustering.singleton.server; import java.io.IOException; import java.util.LinkedList; import java.util.List; import org.infinispan.protostream.descriptors.WireType; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader; import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter; /** * @author Paul Ferraro */ public class SingletonElectionCommandMarshaller implements ProtoStreamMarshaller<SingletonElectionCommand> { private static final int CANDIDATE_INDEX = 1; private static final int ELECTED_INDEX = 2; @Override public SingletonElectionCommand readFrom(ProtoStreamReader reader) throws IOException { List<Node> candidates = new LinkedList<>(); Integer elected = null; while (!reader.isAtEnd()) { int tag = reader.readTag(); switch (WireType.getTagFieldNumber(tag)) { case CANDIDATE_INDEX: candidates.add(reader.readAny(Node.class)); break; case ELECTED_INDEX: elected = reader.readUInt32(); break; default: reader.skipField(tag); } } return new SingletonElectionCommand(candidates, elected); } @Override public void writeTo(ProtoStreamWriter writer, SingletonElectionCommand command) throws IOException { for (Node candidate : command.getCandidates()) { writer.writeAny(CANDIDATE_INDEX, candidate); } Integer elected = command.getIndex(); if (elected != null) { writer.writeUInt32(ELECTED_INDEX, elected); } } @Override public Class<? extends SingletonElectionCommand> getJavaClass() { return SingletonElectionCommand.class; } }
2,979
36.721519
108
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/PrimaryProxyService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Optional; import java.util.function.Supplier; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; import org.jboss.msc.service.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StopContext; import org.wildfly.clustering.dispatcher.CommandDispatcherException; import org.wildfly.clustering.group.Node; /** * Service that proxies the value from the primary node. * @author Paul Ferraro */ @Deprecated public class PrimaryProxyService<T> implements Service<T> { private final Supplier<PrimaryProxyContext<T>> contextFactory; private volatile boolean started = false; public PrimaryProxyService(Supplier<PrimaryProxyContext<T>> contextFactory) { this.contextFactory = contextFactory; } @Override public T getValue() { PrimaryProxyContext<T> context = this.contextFactory.get(); if (!this.started) { throw SingletonLogger.ROOT_LOGGER.notStarted(context.getServiceName().getCanonicalName()); } try { Map<Node, CompletionStage<Optional<T>>> responses = context.getCommandDispatcher().executeOnGroup(new SingletonValueCommand<>()); // Prune non-primary (i.e. null) results Map<Node, Optional<T>> results = new HashMap<>(); try { for (Map.Entry<Node, CompletionStage<Optional<T>>> entry : responses.entrySet()) { try { Optional<T> response = entry.getValue().toCompletableFuture().join(); if (response != null) { results.put(entry.getKey(), response); } } catch (CancellationException e) { // Ignore } } } catch (CompletionException e) { throw new IllegalArgumentException(e); } // We expect only 1 result if (results.size() > 1) { // This would mean there are multiple primary nodes! throw SingletonLogger.ROOT_LOGGER.multiplePrimaryProvidersDetected(context.getServiceName().getCanonicalName(), results.keySet()); } Iterator<Optional<T>> values = results.values().iterator(); if (!values.hasNext()) { throw SingletonLogger.ROOT_LOGGER.noResponseFromPrimary(context.getServiceName().getCanonicalName()); } return values.next().orElse(null); } catch (CommandDispatcherException e) { throw new IllegalArgumentException(e); } } @Override public void start(StartContext context) { this.started = true; } @Override public void stop(StopContext context) { this.started = false; } }
4,053
37.980769
146
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/ServiceLifecycle.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.clustering.singleton.server; import java.util.EnumMap; import java.util.EnumSet; import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; import org.jboss.msc.service.LifecycleEvent; import org.jboss.msc.service.LifecycleListener; import org.jboss.msc.service.ServiceController; import org.wildfly.clustering.service.CountDownLifecycleListener; import org.jboss.msc.service.ServiceController.Mode; import org.jboss.msc.service.ServiceController.State; import org.jboss.msc.service.ServiceNotFoundException; /** * Starts/stops a given {@link ServiceController}. * @author Paul Ferraro */ public class ServiceLifecycle implements Lifecycle { private enum Transition { START(EnumSet.of(State.UP, State.START_FAILED, State.REMOVED), LifecycleEvent.DOWN), STOP(EnumSet.of(State.DOWN, State.REMOVED), LifecycleEvent.UP), ; Set<State> targetStates; Set<LifecycleEvent> targetEvents; Map<Mode, Mode> modeTransitions; Transition(Set<State> targetStates, LifecycleEvent sourceEvent) { this.targetStates = targetStates; this.targetEvents = EnumSet.complementOf(EnumSet.of(sourceEvent)); this.modeTransitions = new EnumMap<>(Mode.class); boolean up = this.targetStates.contains(State.UP); this.modeTransitions.put(up ? Mode.NEVER : Mode.ACTIVE, up ? Mode.ACTIVE : Mode.NEVER); this.modeTransitions.put(up ? Mode.ON_DEMAND : Mode.PASSIVE, up ? Mode.PASSIVE : Mode.ON_DEMAND); } } private final ServiceController<?> controller; public ServiceLifecycle(ServiceController<?> controller) { this.controller = controller; } @Override public void start() { this.transition(Transition.START); } @Override public void stop() { this.transition(Transition.STOP); } private void transition(Transition transition) { // Short-circuit if the service is already at the target state if (this.isComplete(transition)) return; CountDownLatch latch = new CountDownLatch(1); LifecycleListener listener = new CountDownLifecycleListener(latch, transition.targetEvents); this.controller.addListener(listener); try { if (this.isComplete(transition)) return; // Force service to transition to desired state Mode currentMode = this.controller.getMode(); if (currentMode == ServiceController.Mode.REMOVE) { throw new IllegalStateException(new ServiceNotFoundException(this.controller.getName().getCanonicalName())); } Mode targetMode = transition.modeTransitions.get(currentMode); if (targetMode == null) { throw new IllegalStateException(currentMode.name()); } this.controller.setMode(targetMode); latch.await(); if (this.controller.getState() == State.START_FAILED) { throw new IllegalStateException(this.controller.getStartException()); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { this.controller.removeListener(listener); } } private boolean isComplete(Transition transition) { State state = this.controller.getState(); if (transition.targetStates.contains(state)) { if (state == State.START_FAILED) { throw new IllegalStateException(this.controller.getStartException()); } return true; } return false; } }
4,696
36.879032
124
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonValueCommand.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.wildfly.clustering.singleton.server; import java.util.Optional; import org.wildfly.clustering.dispatcher.Command; public class SingletonValueCommand<T> implements Command<Optional<T>, LegacySingletonContext<T>> { private static final long serialVersionUID = -2849349352107418635L; @Override public Optional<T> execute(LegacySingletonContext<T> context) { return context.getLocalValue(); } }
1,454
39.416667
98
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonServiceBuilder.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.wildfly.clustering.singleton.server; import java.util.function.Supplier; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.provider.ServiceProviderRegistry; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.service.CompositeDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.SingletonElectionListener; import org.wildfly.clustering.singleton.SingletonElectionPolicy; import org.wildfly.clustering.singleton.SingletonService; import org.wildfly.clustering.singleton.SingletonServiceBuilder; import org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy; /** * Distributed {@link SingletonServiceBuilder} implementation that uses JBoss MSC 1.3.x service installation. * @author Paul Ferraro */ @Deprecated public class DistributedSingletonServiceBuilder<T> extends SimpleServiceNameProvider implements SingletonServiceBuilder<T>, DistributedSingletonServiceContext, Supplier<Group> { private final SupplierDependency<ServiceProviderRegistry<ServiceName>> registry; private final SupplierDependency<CommandDispatcherFactory> dispatcherFactory; private final Service<T> primaryService; private final Service<T> backupService; private volatile SingletonElectionPolicy electionPolicy = new SimpleSingletonElectionPolicy(); private volatile SingletonElectionListener electionListener; private volatile int quorum = 1; public DistributedSingletonServiceBuilder(ServiceName serviceName, Service<T> primaryService, Service<T> backupService, DistributedSingletonServiceConfiguratorContext context) { super(serviceName); this.registry = context.getServiceProviderRegistryDependency(); this.dispatcherFactory = context.getCommandDispatcherFactoryDependency(); this.primaryService = primaryService; this.backupService = backupService; this.electionListener = new DefaultSingletonElectionListener(serviceName, this); } @Override public Group get() { return this.registry.get().getGroup(); } @Override public ServiceBuilder<T> build(ServiceTarget target) { SingletonService<T> service = new LegacyDistributedSingletonService<>(this, this.primaryService, this.backupService); ServiceBuilder<T> installer = new AsynchronousServiceBuilder<>(this.getServiceName(), service).build(target); return new CompositeDependency(this.registry, this.dispatcherFactory).register(installer); } @Override public SingletonServiceBuilder<T> requireQuorum(int quorum) { if (quorum < 1) { throw SingletonLogger.ROOT_LOGGER.invalidQuorum(quorum); } this.quorum = quorum; return this; } @Override public SingletonServiceBuilder<T> electionPolicy(SingletonElectionPolicy electionPolicy) { this.electionPolicy = electionPolicy; return this; } @Override public SingletonServiceBuilder<T> electionListener(SingletonElectionListener listener) { this.electionListener = listener; return this; } @Override public Supplier<ServiceProviderRegistry<ServiceName>> getServiceProviderRegistry() { return this.registry; } @Override public Supplier<CommandDispatcherFactory> getCommandDispatcherFactory() { return this.dispatcherFactory; } @Override public SingletonElectionPolicy getElectionPolicy() { return this.electionPolicy; } @Override public SingletonElectionListener getElectionListener() { return this.electionListener; } @Override public int getQuorum() { return this.quorum; } }
5,031
38.936508
181
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalLegacySingletonService.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.clustering.singleton.server; import org.jboss.msc.service.Service; import org.wildfly.clustering.singleton.SingletonService; /** * Local {@link SingletonService} implementation created using JBoss MSC 1.3.x service installation. * @author Paul Ferraro */ @Deprecated public class LocalLegacySingletonService<T> extends LocalSingletonService implements SingletonService<T> { private final Service<T> service; public LocalLegacySingletonService(Service<T> service, LocalSingletonServiceContext context) { super(service, context); this.service = service; } @Override public T getValue() { return this.service.getValue(); } }
1,722
35.659574
106
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/StartCommand.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.wildfly.clustering.singleton.server; import org.wildfly.clustering.dispatcher.Command; /** * Command to start a singleton service. * @author Paul Ferraro */ public class StartCommand implements Command<Void, Lifecycle> { private static final long serialVersionUID = 3194143912789013071L; @Override public Void execute(Lifecycle context) throws Exception { context.start(); return null; } }
1,464
35.625
70
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LegacyDistributedSingletonService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceRegistry; import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.wildfly.clustering.dispatcher.CommandDispatcher; import org.wildfly.clustering.singleton.SingletonService; /** * Distributed {@link SingletonService} implementation that uses JBoss MSC 1.3.x service installation. * Decorates an MSC service ensuring that it is only started on one node in the cluster at any given time. * @author Paul Ferraro */ @Deprecated public class LegacyDistributedSingletonService<T> extends AbstractDistributedSingletonService<LegacySingletonContext<T>> implements SingletonService<T>, LegacySingletonContext<T>, PrimaryProxyContext<T> { private final ServiceName name; private volatile boolean started = false; private volatile ServiceController<T> primaryController; private volatile ServiceController<T> backupController; public LegacyDistributedSingletonService(DistributedSingletonServiceContext context, Service<T> primaryService, Service<T> backupService) { this(context, primaryService, backupService, new LazySupplier<>()); } private LegacyDistributedSingletonService(DistributedSingletonServiceContext context, Service<T> primaryService, Service<T> backupService, LazySupplier<PrimaryProxyContext<T>> contextFactory) { super(context, new ServiceLifecycleFactory<>(context.getServiceName(), primaryService, (backupService != null) ? backupService : new PrimaryProxyService<>(contextFactory))); contextFactory.accept(this); this.name = context.getServiceName(); } @Override public ServiceName getServiceName() { return this.name; } @Override public LegacySingletonContext<T> get() { return this; } @SuppressWarnings("unchecked") @Override public void start(StartContext context) throws StartException { super.start(context); ServiceRegistry registry = context.getController().getServiceContainer(); this.primaryController = (ServiceController<T>) registry.getService(this.getServiceName().append("primary")); this.backupController = (ServiceController<T>) registry.getService(this.getServiceName().append("backup")); this.started = true; } @Override public void stop(StopContext context) { this.started = false; super.stop(context); } @Override public T getValue() { while (this.started) { try { return (this.isPrimary() ? this.primaryController : this.backupController).getValue(); } catch (IllegalStateException e) { // Verify whether ISE is due to unmet quorum in the previous election if (this.getServiceProviderRegistration().getProviders().size() < this.getQuorum()) { throw SingletonLogger.ROOT_LOGGER.notStarted(this.getServiceName().getCanonicalName()); } if (Thread.currentThread().isInterrupted()) { throw e; } // Otherwise, we're in the midst of a new election, so just try again Thread.yield(); } } throw SingletonLogger.ROOT_LOGGER.notStarted(this.getServiceName().getCanonicalName()); } @Override public CommandDispatcher<LegacySingletonContext<T>> getCommandDispatcher() { return super.getCommandDispatcher(); } @Override public Optional<T> getLocalValue() { try { return this.isPrimary() ? Optional.ofNullable(this.primaryController.getValue()) : null; } catch (IllegalStateException e) { // This might happen if primary service has not yet started, or if node is no longer the primary node return null; } } static class LazySupplier<T> implements Supplier<T>, Consumer<T> { private volatile T value; @Override public void accept(T value) { this.value = value; } @Override public T get() { return this.value; } } private static class ServiceLifecycleFactory<T> implements Function<ServiceTarget, Lifecycle> { private final ServiceName name; private final Service<T> primaryService; private final Service<T> backupService; ServiceLifecycleFactory(ServiceName name, Service<T> primaryService, Service<T> backupService) { this.name = name; this.primaryService = primaryService; this.backupService = backupService; } @Override public Lifecycle apply(ServiceTarget target) { Lifecycle primaryLifecycle = new ServiceLifecycle(target.addService(this.name.append("primary"), this.primaryService).setInitialMode(ServiceController.Mode.NEVER).install()); Lifecycle backupLifecycle = new ServiceLifecycle(target.addService(this.name.append("backup"), this.backupService).setInitialMode(ServiceController.Mode.ACTIVE).install()); return new PrimaryBackupLifecycle(primaryLifecycle, backupLifecycle); } } private static class PrimaryBackupLifecycle implements Lifecycle { private final Lifecycle primaryLifecycle; private final Lifecycle backupLifecycle; PrimaryBackupLifecycle(Lifecycle primaryLifecycle, Lifecycle backupLifecycle) { this.primaryLifecycle = primaryLifecycle; this.backupLifecycle = backupLifecycle; } @Override public void start() { this.backupLifecycle.stop(); this.primaryLifecycle.start(); } @Override public void stop() { this.primaryLifecycle.stop(); this.backupLifecycle.start(); } } }
7,253
39.077348
204
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonLogger.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import static org.jboss.logging.Logger.Level.ERROR; import static org.jboss.logging.Logger.Level.INFO; import static org.jboss.logging.Logger.Level.WARN; import java.util.Collection; 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; import org.jboss.msc.service.StartException; import org.wildfly.clustering.group.Node; /** * @author <a href="mailto:pferraro@redhat.com">Paul Ferraro</a> */ @MessageLogger(projectCode = "WFLYCLSN", length = 4) public interface SingletonLogger extends BasicLogger { String ROOT_LOGGER_CATEGORY = "org.wildfly.clustering.singleton.server"; /** * The root logger. */ SingletonLogger ROOT_LOGGER = Logger.getMessageLogger(SingletonLogger.class, ROOT_LOGGER_CATEGORY); @LogMessage(level = INFO) @Message(id = 1, value = "This node will now operate as the singleton provider of the %s service") void startSingleton(String service); @LogMessage(level = INFO) @Message(id = 2, value = "This node will no longer operate as the singleton provider of the %s service") void stopSingleton(String service); @LogMessage(level = INFO) @Message(id = 3, value = "%s elected as the singleton provider of the %s service") void elected(String node, String service); @Message(id = 4, value = "No response received from primary provider of the %s service, retrying...") IllegalStateException noResponseFromPrimary(String service); @LogMessage(level = ERROR) @Message(id = 5, value = "Failed to start %s service") void serviceStartFailed(@Cause StartException e, String service); @LogMessage(level = WARN) @Message(id = 6, value = "Failed to reach quorum of %2$d for %1$s service. No primary singleton provider will be elected.") void quorumNotReached(String service, int quorum); @LogMessage(level = INFO) @Message(id = 7, value = "Just reached required quorum of %2$d for %1$s service. If this cluster loses another member, no node will be chosen to provide this service.") void quorumJustReached(String service, int quorum); @Message(id = 8, value = "Detected multiple primary providers for %s service: %s") IllegalArgumentException multiplePrimaryProvidersDetected(String serviceName, Collection<Node> nodes); @Message(id = 9, value = "Singleton service %s is not started.") IllegalStateException notStarted(String serviceName); @LogMessage(level = WARN) @Message(id = 10, value = "No node was elected as the singleton provider of the %s service") void noPrimaryElected(String service); @Message(id = 11, value = "Specified quorum %d must be greater than zero") IllegalArgumentException invalidQuorum(int quorum); }
3,970
42.637363
172
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/AsynchronousServiceBuilder.java
/* * JBoss, Home of Professional Open Source. * Copyright 2011, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; import java.util.function.Supplier; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.jboss.msc.value.InjectedValue; import org.wildfly.clustering.service.AsyncServiceConfigurator; import org.wildfly.clustering.service.Builder; /** * Builder for asynchronously started/stopped services. * @author Paul Ferraro * @param <T> the type of value provided by services built by this builder * @deprecated Replaced by {@link AsyncServiceConfigurator}. */ @Deprecated public class AsynchronousServiceBuilder<T> implements Builder<T>, Service<T>, Supplier<Service<T>> { private static final ServiceName EXECUTOR_SERVICE_NAME = ServiceName.JBOSS.append("as", "server-executor"); private final InjectedValue<ExecutorService> executor = new InjectedValue<>(); private final Service<T> service; private final ServiceName name; private volatile boolean startAsynchronously = true; private volatile boolean stopAsynchronously = true; /** * Constructs a new builder for building asynchronous service * @param name the target service name * @param service the target service */ public AsynchronousServiceBuilder(ServiceName name, Service<T> service) { this.name = name; this.service = service; } @Override public ServiceName getServiceName() { return this.name; } @Override public ServiceBuilder<T> build(ServiceTarget target) { return target.addService(this.name, this).addDependency(EXECUTOR_SERVICE_NAME, ExecutorService.class, this.executor); } /** * Return the underlying service for this builder * @return an MSC service */ @Override public Service<T> get() { return this.service; } /** * Indicates that this service should *not* be started asynchronously. * @return a reference to this builder */ public AsynchronousServiceBuilder<T> startSynchronously() { this.startAsynchronously = false; return this; } /** * Indicates that this service should *not* be stopped asynchronously. * @return a reference to this builder */ public AsynchronousServiceBuilder<T> stopSynchronously() { this.stopAsynchronously = false; return this; } @Override public T getValue() { return this.service.getValue(); } @Override public void start(final StartContext context) throws StartException { if (this.startAsynchronously) { Runnable task = () -> { try { this.service.start(context); context.complete(); } catch (StartException e) { context.failed(e); } catch (Throwable e) { context.failed(new StartException(e)); } }; try { this.executor.getValue().execute(task); } catch (RejectedExecutionException e) { task.run(); } finally { context.asynchronous(); } } else { this.service.start(context); } } @Override public void stop(final StopContext context) { if (this.stopAsynchronously) { Runnable task = () -> { try { this.service.stop(context); } finally { context.complete(); } }; try { this.executor.getValue().execute(task); } catch (RejectedExecutionException e) { task.run(); } finally { context.asynchronous(); } } else { this.service.stop(context); } } }
5,208
32.606452
125
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DefaultSingletonElectionListener.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.clustering.singleton.server; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.SingletonElectionListener; /** * Default singleton election listener that logs the results of the singleton election. * @author Paul Ferraro */ public class DefaultSingletonElectionListener implements SingletonElectionListener { private final ServiceName name; private final Supplier<Group> group; private final AtomicReference<Node> primaryMember = new AtomicReference<>(); public DefaultSingletonElectionListener(ServiceName name, Supplier<Group> group) { this.name = name; this.group = group; } @Override public void elected(List<Node> candidateMembers, Node electedMember) { Node localMember = this.group.get().getLocalMember(); Node previousElectedMember = this.primaryMember.getAndSet(electedMember); if (electedMember != null) { SingletonLogger.ROOT_LOGGER.elected(electedMember.getName(), this.name.getCanonicalName()); } else { SingletonLogger.ROOT_LOGGER.noPrimaryElected(this.name.getCanonicalName()); } if (localMember.equals(electedMember)) { SingletonLogger.ROOT_LOGGER.startSingleton(this.name.getCanonicalName()); } else if (localMember.equals(previousElectedMember)) { SingletonLogger.ROOT_LOGGER.stopSingleton(this.name.getCanonicalName()); } } }
2,686
39.712121
103
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/PrimaryProviderCommand.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.clustering.singleton.server; import org.wildfly.clustering.dispatcher.Command; import org.wildfly.clustering.singleton.Singleton; /** * @author Paul Ferraro */ public class PrimaryProviderCommand implements Command<Boolean, Singleton> { private static final long serialVersionUID = 3194143912789013072L; @Override public Boolean execute(Singleton singleton) { return singleton.isPrimary(); } }
1,467
36.641026
76
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonServiceConfiguratorContext.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.provider.ServiceProviderRegistry; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.service.SupplierDependency; /** * Context for building singleton services. * @author Paul Ferraro */ public interface DistributedSingletonServiceConfiguratorContext { SupplierDependency<ServiceProviderRegistry<ServiceName>> getServiceProviderRegistryDependency(); SupplierDependency<CommandDispatcherFactory> getCommandDispatcherFactoryDependency(); }
1,648
42.394737
100
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonServiceConfigurator.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.clustering.singleton.server; import java.util.AbstractMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; import org.jboss.msc.Service; import org.jboss.msc.service.DelegatingServiceBuilder; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.provider.ServiceProviderRegistry; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.service.AsyncServiceConfigurator; import org.wildfly.clustering.service.CompositeDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.Singleton; import org.wildfly.clustering.singleton.SingletonElectionListener; import org.wildfly.clustering.singleton.SingletonElectionPolicy; import org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy; import org.wildfly.clustering.singleton.service.SingletonServiceBuilder; import org.wildfly.clustering.singleton.service.SingletonServiceConfigurator; /** * Distributed {@link SingletonServiceConfigurator} implementation that uses JBoss MSC 1.4.x service installation. * @author Paul Ferraro */ public class DistributedSingletonServiceConfigurator extends SimpleServiceNameProvider implements SingletonServiceConfigurator, DistributedSingletonServiceContext, Supplier<Group> { private final SupplierDependency<ServiceProviderRegistry<ServiceName>> registry; private final SupplierDependency<CommandDispatcherFactory> dispatcherFactory; private volatile SingletonElectionPolicy electionPolicy = new SimpleSingletonElectionPolicy(); private volatile SingletonElectionListener electionListener; private volatile int quorum = 1; public DistributedSingletonServiceConfigurator(ServiceName name, DistributedSingletonServiceConfiguratorContext context) { super(name); this.registry = context.getServiceProviderRegistryDependency(); this.dispatcherFactory = context.getCommandDispatcherFactoryDependency(); this.electionListener = new DefaultSingletonElectionListener(name, this); } @Override public Group get() { return this.registry.get().getGroup(); } @Override public SingletonServiceBuilder<?> build(ServiceTarget target) { ServiceName name = this.getServiceName().append("singleton"); ServiceBuilder<?> builder = new AsyncServiceConfigurator(name).build(target); Consumer<Singleton> singleton = builder.provides(name); return new DistributedSingletonServiceBuilder<>(this, new CompositeDependency(this.registry, this.dispatcherFactory).register(builder), singleton); } @Override public SingletonServiceConfigurator requireQuorum(int quorum) { this.quorum = quorum; return this; } @Override public SingletonServiceConfigurator electionPolicy(SingletonElectionPolicy policy) { this.electionPolicy = policy; return this; } @Override public SingletonServiceConfigurator electionListener(SingletonElectionListener listener) { this.electionListener = listener; return this; } @Override public Supplier<ServiceProviderRegistry<ServiceName>> getServiceProviderRegistry() { return this.registry; } @Override public Supplier<CommandDispatcherFactory> getCommandDispatcherFactory() { return this.dispatcherFactory; } @Override public SingletonElectionPolicy getElectionPolicy() { return this.electionPolicy; } @Override public SingletonElectionListener getElectionListener() { return this.electionListener; } @Override public int getQuorum() { return this.quorum; } private static class DistributedSingletonServiceBuilder<T> extends DelegatingServiceBuilder<T> implements SingletonServiceBuilder<T> { private final DistributedSingletonServiceContext context; private final Consumer<Singleton> singleton; private final List<Map.Entry<ServiceName[], DeferredInjector<?>>> injectors = new LinkedList<>(); private Service service = Service.NULL; DistributedSingletonServiceBuilder(DistributedSingletonServiceContext context, ServiceBuilder<T> builder, Consumer<Singleton> singleton) { super(builder); this.context = context; this.singleton = singleton; } @Override public <V> Consumer<V> provides(ServiceName... names) { DeferredInjector<V> injector = new DeferredInjector<>(); this.injectors.add(new AbstractMap.SimpleImmutableEntry<>(names, injector)); return injector; } @Override public ServiceBuilder<T> setInstance(Service service) { this.service = service; return this; } @Override public ServiceController<T> install() { return this.getDelegate().setInstance(new DistributedSingletonService(this.context, this.service, this.singleton, this.injectors)).install(); } } }
6,432
39.20625
181
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceConfiguratorFactory.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.clustering.singleton.server; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.service.SingletonServiceConfigurator; import org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory; /** * Factory for creating local {@link SingletonServiceConfigurator} instances. * @author Paul Ferraro */ public class LocalSingletonServiceConfiguratorFactory implements SingletonServiceConfiguratorFactory, LocalSingletonServiceConfiguratorContext { private final LocalSingletonServiceConfiguratorFactoryContext context; public LocalSingletonServiceConfiguratorFactory(LocalSingletonServiceConfiguratorFactoryContext context) { this.context = context; } @Override public SingletonServiceConfigurator createSingletonServiceConfigurator(ServiceName name) { return new LocalSingletonServiceConfigurator(name, this); } @Override public SupplierDependency<Group> getGroupDependency() { return new ServiceSupplierDependency<>(this.context.getGroupServiceName()); } }
2,276
41.166667
144
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonServiceContext.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import java.util.function.Supplier; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.provider.ServiceProviderRegistry; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.singleton.SingletonElectionPolicy; /** * @author Paul Ferraro */ public interface DistributedSingletonServiceContext extends SingletonServiceContext { Supplier<ServiceProviderRegistry<ServiceName>> getServiceProviderRegistry(); Supplier<CommandDispatcherFactory> getCommandDispatcherFactory(); SingletonElectionPolicy getElectionPolicy(); int getQuorum(); }
1,698
40.439024
85
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonServiceBuilderFactory.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.wildfly.clustering.singleton.server; import org.jboss.as.clustering.msc.InjectedValueDependency; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.provider.ServiceProviderRegistry; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.SingletonServiceBuilder; import org.wildfly.clustering.singleton.SingletonServiceBuilderFactory; /** * Factory for creating distributed {@link SingletonServiceBuilder} instances. * @author Paul Ferraro */ @Deprecated public class DistributedSingletonServiceBuilderFactory extends DistributedSingletonServiceConfiguratorFactory implements SingletonServiceBuilderFactory { private final DistributedSingletonServiceConfiguratorContext context; public DistributedSingletonServiceBuilderFactory(DistributedSingletonServiceConfiguratorFactoryContext context) { super(context); this.context = new LegacyDistributedSingletonServiceConfiguratorContext(context); } @Override public <T> SingletonServiceBuilder<T> createSingletonServiceBuilder(ServiceName name, Service<T> service) { return this.createSingletonServiceBuilder(name, service, null); } @Override public <T> SingletonServiceBuilder<T> createSingletonServiceBuilder(ServiceName name, Service<T> primaryService, Service<T> backupService) { return new DistributedSingletonServiceBuilder<>(name, primaryService, backupService, this.context); } private class LegacyDistributedSingletonServiceConfiguratorContext implements DistributedSingletonServiceConfiguratorContext { private final DistributedSingletonServiceConfiguratorFactoryContext context; LegacyDistributedSingletonServiceConfiguratorContext(DistributedSingletonServiceConfiguratorFactoryContext context) { this.context = context; } @SuppressWarnings("unchecked") @Override public SupplierDependency<ServiceProviderRegistry<ServiceName>> getServiceProviderRegistryDependency() { return new InjectedValueDependency<>(this.context.getServiceProviderRegistryServiceName(), (Class<ServiceProviderRegistry<ServiceName>>) (Class<?>) ServiceProviderRegistry.class); } @Override public SupplierDependency<CommandDispatcherFactory> getCommandDispatcherFactoryDependency() { return new InjectedValueDependency<>(this.context.getCommandDispatcherFactoryServiceName(), CommandDispatcherFactory.class); } } }
3,656
47.118421
191
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonContext.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.clustering.singleton.server; import org.wildfly.clustering.singleton.Singleton; import org.wildfly.clustering.singleton.SingletonElectionListener; /** * @author Paul Ferraro */ public interface SingletonContext extends Lifecycle, Singleton, SingletonElectionListener { }
1,319
39
91
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceContext.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.clustering.singleton.server; import java.util.function.Supplier; import org.wildfly.clustering.group.Group; /** * Context for local singleton services. * @author Paul Ferraro */ public interface LocalSingletonServiceContext extends SingletonServiceContext { Supplier<Group> getGroup(); }
1,342
36.305556
79
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonService.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.clustering.singleton.server; import java.util.List; import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.wildfly.clustering.singleton.Singleton; /** * Distributed {@link org.wildfly.clustering.singleton.service.SingletonService} implementation that uses JBoss MSC 1.4.x service installation. * @author Paul Ferraro */ public class DistributedSingletonService extends AbstractDistributedSingletonService<SingletonContext> { private final Consumer<Singleton> singleton; public DistributedSingletonService(DistributedSingletonServiceContext context, Service service, Consumer<Singleton> singleton, List<Map.Entry<ServiceName[], DeferredInjector<?>>> injectors) { super(context, new PrimaryServiceLifecycleFactory(context.getServiceName(), service, injectors)); this.singleton = singleton; } @Override public void start(StartContext context) throws StartException { super.start(context); this.singleton.accept(this); } @Override public SingletonContext get() { return this; } private static class PrimaryServiceLifecycleFactory implements Function<ServiceTarget, Lifecycle> { private final ServiceName name; private final Service service; private final List<Map.Entry<ServiceName[], DeferredInjector<?>>> injectors; PrimaryServiceLifecycleFactory(ServiceName name, Service service, List<Map.Entry<ServiceName[], DeferredInjector<?>>> injectors) { this.name = name; this.service = service; this.injectors = injectors; } @Override public Lifecycle apply(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.name); for (Map.Entry<ServiceName[], DeferredInjector<?>> entry : this.injectors) { entry.getValue().setConsumer(builder.provides(entry.getKey())); } return new ServiceLifecycle(builder.setInstance(this.service).setInitialMode(ServiceController.Mode.NEVER).install()); } } }
3,452
40.107143
195
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonSerializationContextInitializerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import org.infinispan.protostream.SerializationContext; import org.infinispan.protostream.SerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.ProviderSerializationContextInitializer; import org.wildfly.clustering.marshalling.protostream.SerializationContextInitializerProvider; import org.wildfly.clustering.marshalling.protostream.ValueMarshaller; /** * Provider of the {@link SerializationContextInitializer} instances for this module. * @author Paul Ferraro */ public enum SingletonSerializationContextInitializerProvider implements SerializationContextInitializerProvider { SERVICE(new ProviderSerializationContextInitializer<>("org.jboss.msc.service.proto", ServiceMarshallerProvider.class)), SINGLETON(new AbstractSerializationContextInitializer() { @Override public void registerMarshallers(SerializationContext context) { context.registerMarshaller(new SingletonElectionCommandMarshaller()); context.registerMarshaller(new ValueMarshaller<>(new StartCommand())); context.registerMarshaller(new ValueMarshaller<>(new StopCommand())); context.registerMarshaller(new ValueMarshaller<>(new PrimaryProviderCommand())); context.registerMarshaller(new ValueMarshaller<>(new SingletonValueCommand<>())); } }), ; private final SerializationContextInitializer initializer; SingletonSerializationContextInitializerProvider(SerializationContextInitializer initializer) { this.initializer = initializer; } @Override public SerializationContextInitializer getInitializer() { return this.initializer; } }
2,848
46.483333
123
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/PrimaryProxyContext.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import org.wildfly.clustering.dispatcher.CommandDispatcher; import org.wildfly.clustering.service.ServiceNameProvider; /** * @author Paul Ferraro */ public interface PrimaryProxyContext<T> extends ServiceNameProvider { CommandDispatcher<LegacySingletonContext<T>> getCommandDispatcher(); }
1,371
39.352941
72
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceConfiguratorFactoryServiceConfigurator.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.wildfly.clustering.singleton.server; import java.io.Serializable; import java.util.function.Consumer; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.server.service.ClusteringCacheRequirement; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory; /** * Configures a service providing a local {@link org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory}. * @author Paul Ferraro */ public class LocalSingletonServiceConfiguratorFactoryServiceConfigurator<T extends Serializable> extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, LocalSingletonServiceConfiguratorFactoryContext { private final String containerName; private final String cacheName; private volatile ServiceName groupServiceName; public LocalSingletonServiceConfiguratorFactoryServiceConfigurator(ServiceName name, String containerName, String cacheName) { super(name); this.containerName = containerName; this.cacheName = cacheName; } @Override public ServiceConfigurator configure(CapabilityServiceSupport support) { this.groupServiceName = ClusteringCacheRequirement.GROUP.getServiceName(support, this.containerName, this.cacheName); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<SingletonServiceConfiguratorFactory> factory = builder.provides(this.getServiceName()); Service service = Service.newInstance(factory, new LocalSingletonServiceBuilderFactory(this)); return builder.setInstance(service); } @Override public ServiceName getGroupServiceName() { return this.groupServiceName; } }
3,240
42.213333
222
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LegacySingletonContext.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.wildfly.clustering.singleton.server; import java.util.Optional; /** * Context for singleton commands. * @author Paul Ferraro */ public interface LegacySingletonContext<T> extends SingletonContext { Optional<T> getLocalValue(); }
1,274
36.5
70
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonElectionCommand.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.clustering.singleton.server; import java.util.List; import org.wildfly.clustering.dispatcher.Command; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.SingletonElectionListener; /** * @author Paul Ferraro */ public class SingletonElectionCommand implements Command<Void, SingletonElectionListener> { private static final long serialVersionUID = 8457549139382922406L; private final List<Node> candidates; private final Integer index; public SingletonElectionCommand(List<Node> candidates, Node elected) { this(candidates, (elected != null) ? candidates.indexOf(elected) : null); } SingletonElectionCommand(List<Node> candidates, Integer index) { this.candidates = candidates; this.index = index; } List<Node> getCandidates() { return this.candidates; } Integer getIndex() { return this.index; } @Override public Void execute(SingletonElectionListener context) { context.elected(this.candidates, (this.index != null) ? this.candidates.get(this.index) : null); return null; } }
2,175
33.539683
104
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/ServiceNameFormatter.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.wildfly.clustering.singleton.server; import org.jboss.msc.service.ServiceName; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.marshalling.Externalizer; import org.wildfly.clustering.marshalling.spi.Formatter; import org.wildfly.clustering.marshalling.spi.SimpleFormatter; import org.wildfly.clustering.marshalling.spi.StringExternalizer; /** * {@link Externalizer} for a {@link ServiceName}. * @author Paul Ferraro */ @MetaInfServices(Formatter.class) public class ServiceNameFormatter extends SimpleFormatter<ServiceName> { public ServiceNameFormatter() { super(ServiceName.class, ServiceName::parse, ServiceName::getCanonicalName); } @MetaInfServices(Externalizer.class) public static class ServiceNameExternalizer extends StringExternalizer<ServiceName> { public ServiceNameExternalizer() { super(new ServiceNameFormatter()); } } }
1,952
38.857143
89
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/IdentitySingletonServiceBuilderFactoryBuilderProvider.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.wildfly.clustering.singleton.server; import java.util.List; import org.jboss.as.clustering.controller.IdentityLegacyCapabilityServiceConfigurator; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.server.service.IdentityCacheServiceConfiguratorProvider; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.singleton.SingletonServiceBuilderFactory; import org.wildfly.clustering.singleton.service.SingletonCacheRequirement; /** * @author Paul Ferraro */ @Deprecated @MetaInfServices(IdentityCacheServiceConfiguratorProvider.class) public class IdentitySingletonServiceBuilderFactoryBuilderProvider implements IdentityCacheServiceConfiguratorProvider { @Override public Iterable<ServiceConfigurator> getServiceConfigurators(CapabilityServiceSupport support, String containerName, String cacheName, String targetCacheName) { ServiceName name = SingletonCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY.getServiceName(support, containerName, cacheName); return List.of(new IdentityLegacyCapabilityServiceConfigurator<>(name, SingletonServiceBuilderFactory.class, SingletonCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY, containerName, targetCacheName).configure(support)); } @Override public String toString() { return this.getClass().getName(); } }
2,506
45.425926
230
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/Lifecycle.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.clustering.singleton.server; /** * Encapsulates behavior associated with a lifecycle sensitive object. * @author Paul Ferraro */ public interface Lifecycle { /** * Start this object. */ void start(); /** * Stop this object. */ void stop(); }
1,327
32.2
70
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/IdentitySingletonServiceConfiguratorFactoryServiceConfiguratorProvider.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.wildfly.clustering.singleton.server; import java.util.List; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.server.service.IdentityCacheServiceConfiguratorProvider; import org.wildfly.clustering.service.IdentityServiceConfigurator; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.singleton.service.SingletonCacheRequirement; /** * @author Paul Ferraro */ @MetaInfServices(IdentityCacheServiceConfiguratorProvider.class) public class IdentitySingletonServiceConfiguratorFactoryServiceConfiguratorProvider implements IdentityCacheServiceConfiguratorProvider { @Override public Iterable<ServiceConfigurator> getServiceConfigurators(CapabilityServiceSupport support, String containerName, String cacheName, String targetCacheName) { ServiceName name = SingletonCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY.getServiceName(support, containerName, cacheName); ServiceName targetName = SingletonCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY.getServiceName(support, containerName, targetCacheName); ServiceConfigurator configurator = new IdentityServiceConfigurator<>(name, targetName); return List.of(configurator); } }
2,388
47.755102
164
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonSerializationContextInitializer.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.clustering.singleton.server; import org.infinispan.protostream.SerializationContextInitializer; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.marshalling.protostream.CompositeSerializationContextInitializer; /** * {@link org.infinispan.protostream.SerializationContextInitializer} for this package. * @author Paul Ferraro */ @MetaInfServices(SerializationContextInitializer.class) public class SingletonSerializationContextInitializer extends CompositeSerializationContextInitializer { public SingletonSerializationContextInitializer() { super(SingletonSerializationContextInitializerProvider.class); } }
1,691
41.3
104
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/ServiceMarshallerProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2021, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceNotFoundException; import org.jboss.msc.service.StartException; import org.wildfly.clustering.marshalling.protostream.ExceptionMarshaller; import org.wildfly.clustering.marshalling.protostream.FunctionalScalarMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller; import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshallerProvider; import org.wildfly.clustering.marshalling.protostream.Scalar; import org.wildfly.common.function.Functions; /** * Provider of marshallers for the org.jboss.msc.service package. * @author Paul Ferraro */ public enum ServiceMarshallerProvider implements ProtoStreamMarshallerProvider { SERVICE_NAME(new FunctionalScalarMarshaller<>(Scalar.STRING.cast(String.class), Functions.constantSupplier(ServiceName.JBOSS), ServiceName::getCanonicalName, ServiceName::parse)), SERVICE_NOT_FOUND_EXCEPTION(new ExceptionMarshaller<>(ServiceNotFoundException.class)), START_EXCEPTION(new ExceptionMarshaller<>(StartException.class)), ; private final ProtoStreamMarshaller<?> marshaller; ServiceMarshallerProvider(ProtoStreamMarshaller<?> marshaller) { this.marshaller = marshaller; } @Override public ProtoStreamMarshaller<?> getMarshaller() { return this.marshaller; } }
2,453
43.618182
183
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonServiceContext.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.clustering.singleton.server; import org.wildfly.clustering.service.ServiceNameProvider; import org.wildfly.clustering.singleton.SingletonElectionListener; /** * @author Paul Ferraro */ public interface SingletonServiceContext extends ServiceNameProvider { SingletonElectionListener getElectionListener(); }
1,359
39
70
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/CacheSingletonServiceConfiguratorFactoryServiceConfigurator.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.wildfly.clustering.singleton.server; import java.util.function.Consumer; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.server.service.ClusteringCacheRequirement; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory; /** * Configures a service providing a distributed {@link org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory}. * @author Paul Ferraro */ public class CacheSingletonServiceConfiguratorFactoryServiceConfigurator extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, DistributedSingletonServiceConfiguratorFactoryContext { private final String containerName; private final String cacheName; private volatile ServiceName registryServiceName; private volatile ServiceName dispatcherFactoryServiceName; public CacheSingletonServiceConfiguratorFactoryServiceConfigurator(ServiceName name, String containerName, String cacheName) { super(name); this.containerName = containerName; this.cacheName = cacheName; } @Override public ServiceConfigurator configure(CapabilityServiceSupport support) { this.registryServiceName = ClusteringCacheRequirement.SERVICE_PROVIDER_REGISTRY.getServiceName(support, this.containerName, this.cacheName); this.dispatcherFactoryServiceName = ClusteringRequirement.COMMAND_DISPATCHER_FACTORY.getServiceName(support, this.containerName); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<SingletonServiceConfiguratorFactory> factory = builder.provides(this.getServiceName()); @SuppressWarnings("deprecation") Service service = Service.newInstance(factory, new DistributedSingletonServiceBuilderFactory(this)); return builder.setInstance(service); } @Override public ServiceName getServiceProviderRegistryServiceName() { return this.registryServiceName; } @Override public ServiceName getCommandDispatcherFactoryServiceName() { return this.dispatcherFactoryServiceName; } }
3,699
43.578313
204
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/CacheSingletonServiceConfiguratorFactoryServiceConfiguratorProvider.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.wildfly.clustering.singleton.server; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.server.service.DistributedCacheServiceConfiguratorProvider; /** * Provides the requisite service configurators for installing a service providing a distributed {@link org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory}. * @author Paul Ferraro */ @MetaInfServices(DistributedCacheServiceConfiguratorProvider.class) public class CacheSingletonServiceConfiguratorFactoryServiceConfiguratorProvider extends SingletonServiceConfiguratorFactoryServiceConfiguratorProvider implements DistributedCacheServiceConfiguratorProvider { public CacheSingletonServiceConfiguratorFactoryServiceConfiguratorProvider() { super(CacheSingletonServiceConfiguratorFactoryServiceConfigurator::new); } }
1,865
48.105263
208
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DeferredInjector.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.clustering.singleton.server; import java.util.function.Consumer; /** * An injector whose source can be defined after service installation, but before the service is started. * @author Paul Ferraro */ public class DeferredInjector<T> implements Consumer<T> { private volatile Consumer<? super T> consumer; @Override public void accept(T value) { this.consumer.accept(value); } void setConsumer(Consumer<? super T> consumer) { this.consumer = consumer; } }
1,547
34.181818
105
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonService.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import java.util.Collections; import java.util.Set; import java.util.function.Supplier; import org.jboss.msc.Service; import org.jboss.msc.service.StartContext; import org.jboss.msc.service.StartException; import org.jboss.msc.service.StopContext; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.group.Node; import org.wildfly.clustering.singleton.SingletonElectionListener; import org.wildfly.clustering.singleton.service.SingletonService; /** * Local {@link SingletonService} implementation created using JBoss MSC 1.4.x service installation. * @author Paul Ferraro */ public class LocalSingletonService implements SingletonService { private final Service service; private final Supplier<Group> group; private final SingletonElectionListener listener; public LocalSingletonService(Service service, LocalSingletonServiceContext context) { this.service = service; this.group = context.getGroup(); this.listener = context.getElectionListener(); } @Override public void start(StartContext context) throws StartException { this.service.start(context); Node localMember = this.group.get().getLocalMember(); try { this.listener.elected(Collections.singletonList(localMember), localMember); } catch (Throwable e) { SingletonLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e); } } @Override public void stop(StopContext context) { this.service.stop(context); } @Override public boolean isPrimary() { // A local singleton is always primary return true; } @Override public Node getPrimaryProvider() { return this.group.get().getLocalMember(); } @Override public Set<Node> getProviders() { return Collections.singleton(this.group.get().getLocalMember()); } }
2,969
33.534884
100
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonServiceConfiguratorFactoryContext.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.clustering.singleton.server; import org.jboss.msc.service.ServiceName; /** * @author Paul Ferraro */ public interface DistributedSingletonServiceConfiguratorFactoryContext { ServiceName getServiceProviderRegistryServiceName(); ServiceName getCommandDispatcherFactoryServiceName(); }
1,339
38.411765
72
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/SingletonServiceConfiguratorFactoryServiceConfiguratorProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.clustering.singleton.server; import java.util.List; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.server.service.CacheCapabilityServiceConfiguratorFactory; import org.wildfly.clustering.server.service.CacheServiceConfiguratorProvider; import org.wildfly.clustering.service.IdentityServiceConfigurator; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.singleton.service.SingletonCacheRequirement; import org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory; /** * @author Paul Ferraro */ public class SingletonServiceConfiguratorFactoryServiceConfiguratorProvider implements CacheServiceConfiguratorProvider { private final CacheCapabilityServiceConfiguratorFactory<SingletonServiceConfiguratorFactory> factory; protected SingletonServiceConfiguratorFactoryServiceConfiguratorProvider(CacheCapabilityServiceConfiguratorFactory<SingletonServiceConfiguratorFactory> factory) { this.factory = factory; } @Override public Iterable<ServiceConfigurator> getServiceConfigurators(CapabilityServiceSupport support, String containerName, String cacheName) { ServiceName name = SingletonCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY.getServiceName(support, containerName, cacheName); ServiceConfigurator configurator = this.factory.createServiceConfigurator(name, containerName, cacheName).configure(support); @SuppressWarnings("removal") ServiceName legacyName = SingletonCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY.getServiceName(support, containerName, cacheName); ServiceConfigurator legacyConfigurator = new IdentityServiceConfigurator<>(legacyName, name); return List.of(configurator, legacyConfigurator); } }
2,911
50.087719
166
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/DistributedSingletonServiceConfiguratorFactory.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.clustering.singleton.server; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.provider.ServiceProviderRegistry; import org.wildfly.clustering.server.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.service.SingletonServiceConfigurator; import org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory; /** * Factory for creating distributed {@link SingletonServiceConfigurator} instances. * @author Paul Ferraro */ public class DistributedSingletonServiceConfiguratorFactory implements SingletonServiceConfiguratorFactory, DistributedSingletonServiceConfiguratorContext { private final DistributedSingletonServiceConfiguratorFactoryContext context; public DistributedSingletonServiceConfiguratorFactory(DistributedSingletonServiceConfiguratorFactoryContext context) { this.context = context; } @Override public SingletonServiceConfigurator createSingletonServiceConfigurator(ServiceName name) { return new DistributedSingletonServiceConfigurator(name, this); } @Override public SupplierDependency<ServiceProviderRegistry<ServiceName>> getServiceProviderRegistryDependency() { return new ServiceSupplierDependency<>(this.context.getServiceProviderRegistryServiceName()); } @Override public SupplierDependency<CommandDispatcherFactory> getCommandDispatcherFactoryDependency() { return new ServiceSupplierDependency<>(this.context.getCommandDispatcherFactoryServiceName()); } }
2,702
44.05
156
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceBuilderFactory.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.wildfly.clustering.singleton.server; import org.jboss.as.clustering.msc.InjectedValueDependency; import org.jboss.msc.service.Service; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.service.SupplierDependency; import org.wildfly.clustering.singleton.SingletonServiceBuilder; import org.wildfly.clustering.singleton.SingletonServiceBuilderFactory; /** * Factory for creating local {@link SingletonServiceBuilder} instances. * @author Paul Ferraro */ @SuppressWarnings({ "removal", "deprecation" }) public class LocalSingletonServiceBuilderFactory extends LocalSingletonServiceConfiguratorFactory implements SingletonServiceBuilderFactory { private final LegacyLocalSingletonServiceConfiguratorContext context; public LocalSingletonServiceBuilderFactory(LocalSingletonServiceConfiguratorFactoryContext context) { super(context); this.context = new LegacyLocalSingletonServiceConfiguratorContext(context); } @Override public <T> SingletonServiceBuilder<T> createSingletonServiceBuilder(ServiceName name, Service<T> service) { return new LocalSingletonServiceBuilder<>(name, service, this.context); } @Override public <T> SingletonServiceBuilder<T> createSingletonServiceBuilder(ServiceName name, Service<T> primaryService, Service<T> backupService) { return this.createSingletonServiceBuilder(name, primaryService); } private class LegacyLocalSingletonServiceConfiguratorContext implements LocalSingletonServiceConfiguratorContext { private final LocalSingletonServiceConfiguratorFactoryContext context; LegacyLocalSingletonServiceConfiguratorContext(LocalSingletonServiceConfiguratorFactoryContext context) { this.context = context; } @Override public SupplierDependency<Group> getGroupDependency() { return new InjectedValueDependency<>(this.context.getGroupServiceName(), Group.class); } } }
3,055
43.289855
144
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceConfiguratorFactoryContext.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.clustering.singleton.server; import org.jboss.msc.service.ServiceName; /** * @author Paul Ferraro */ public interface LocalSingletonServiceConfiguratorFactoryContext { ServiceName getGroupServiceName(); }
1,257
37.121212
70
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceConfiguratorFactoryServiceConfiguratorProvider.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.wildfly.clustering.singleton.server; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.server.service.LocalCacheServiceConfiguratorProvider; /** * Provides the requisite service configurators for installing a service providing a local {@link org.wildfly.clustering.singleton.service.SingletonServiceConfiguratorFactory}. * @author Paul Ferraro */ @MetaInfServices(LocalCacheServiceConfiguratorProvider.class) public class LocalSingletonServiceConfiguratorFactoryServiceConfiguratorProvider extends SingletonServiceConfiguratorFactoryServiceConfiguratorProvider implements LocalCacheServiceConfiguratorProvider { public LocalSingletonServiceConfiguratorFactoryServiceConfiguratorProvider() { super(LocalSingletonServiceConfiguratorFactoryServiceConfigurator::new); } }
1,841
47.473684
202
java
null
wildfly-main/clustering/singleton/server/src/main/java/org/wildfly/clustering/singleton/server/LocalSingletonServiceConfiguratorContext.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.clustering.singleton.server; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.service.SupplierDependency; /** * @author Paul Ferraro */ public interface LocalSingletonServiceConfiguratorContext { SupplierDependency<Group> getGroupDependency(); }
1,322
37.911765
70
java
null
wildfly-main/clustering/server/extension/src/test/java/org/wildfly/extension/clustering/ServiceLoaderTestCase.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.wildfly.extension.clustering; import java.util.ServiceLoader; import org.jboss.logging.Logger; import org.junit.Test; import org.wildfly.clustering.server.service.DistributedCacheServiceConfiguratorProvider; import org.wildfly.clustering.server.service.DistributedGroupServiceConfiguratorProvider; import org.wildfly.clustering.server.service.IdentityCacheServiceConfiguratorProvider; import org.wildfly.clustering.server.service.IdentityGroupServiceConfiguratorProvider; import org.wildfly.clustering.server.service.LocalCacheServiceConfiguratorProvider; import org.wildfly.clustering.server.service.LocalGroupServiceConfiguratorProvider; /** * Validates loading of services. * @author Paul Ferraro */ public class ServiceLoaderTestCase { private static final Logger LOGGER = Logger.getLogger(ServiceLoaderTestCase.class); @Test public void load() { load(IdentityGroupServiceConfiguratorProvider.class); load(IdentityCacheServiceConfiguratorProvider.class); load(DistributedGroupServiceConfiguratorProvider.class); load(DistributedCacheServiceConfiguratorProvider.class); load(LocalGroupServiceConfiguratorProvider.class); load(LocalCacheServiceConfiguratorProvider.class); } private static <T> void load(Class<T> targetClass) { ServiceLoader.load(targetClass, ServiceLoaderTestCase.class.getClassLoader()) .forEach(object -> LOGGER.tracef("\t" + object.getClass().getName())); } }
2,523
42.517241
89
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/CacheJndiNameFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.extension.clustering.server; import java.util.function.BiFunction; import org.jboss.as.clustering.naming.JndiNameFactory; import org.jboss.as.naming.deployment.JndiName; /** * @author Paul Ferraro */ public enum CacheJndiNameFactory implements BiFunction<String, String, JndiName> { REGISTRY_FACTORY("registry"), SERVICE_PROVIDER_REGISTRY("providers"), ; private final String component; CacheJndiNameFactory(String component) { this.component = component; } @Override public JndiName apply(String containerName, String cacheName) { return JndiNameFactory.createJndiName(JndiNameFactory.DEFAULT_JNDI_NAMESPACE, "clustering", this.component, containerName, cacheName); } }
1,774
35.979167
142
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/GroupRequirementServiceConfiguratorProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.extension.clustering.server; import java.util.List; import java.util.function.Function; import org.jboss.as.clustering.naming.BinderServiceConfigurator; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.deployment.JndiName; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.server.service.GroupCapabilityServiceConfiguratorFactory; import org.wildfly.clustering.server.service.GroupServiceConfiguratorProvider; import org.wildfly.clustering.service.ServiceConfigurator; /** * @author Paul Ferraro */ public class GroupRequirementServiceConfiguratorProvider<T> implements GroupServiceConfiguratorProvider { private final ClusteringRequirement requirement; private final GroupCapabilityServiceConfiguratorFactory<T> factory; private final Function<String, JndiName> jndiNameFactory; protected GroupRequirementServiceConfiguratorProvider(ClusteringRequirement requirement, GroupCapabilityServiceConfiguratorFactory<T> factory) { this(requirement, factory, null); } protected GroupRequirementServiceConfiguratorProvider(ClusteringRequirement requirement, GroupCapabilityServiceConfiguratorFactory<T> factory, Function<String, JndiName> jndiNameFactory) { this.requirement = requirement; this.factory = factory; this.jndiNameFactory = jndiNameFactory; } @Override public Iterable<ServiceConfigurator> getServiceConfigurators(CapabilityServiceSupport support, String group) { ServiceName name = this.requirement.getServiceName(support, group); ServiceConfigurator configurator = this.factory.createServiceConfigurator(name, group).configure(support); if (this.jndiNameFactory == null) { return List.of(configurator); } ContextNames.BindInfo binding = ContextNames.bindInfoFor(this.jndiNameFactory.apply(group).getAbsoluteName()); ServiceConfigurator binderConfigurator = new BinderServiceConfigurator(binding, configurator.getServiceName()).configure(support); return List.of(configurator, binderConfigurator); } @Override public String toString() { return this.getClass().getName(); } }
3,383
44.72973
192
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/IdentityCacheRequirementServiceConfiguratorProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.extension.clustering.server; import java.util.List; import java.util.function.BiFunction; import org.jboss.as.clustering.naming.BinderServiceConfigurator; import org.jboss.as.clustering.naming.JndiNameFactory; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.deployment.JndiName; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.server.service.ClusteringCacheRequirement; import org.wildfly.clustering.server.service.IdentityCacheServiceConfiguratorProvider; import org.wildfly.clustering.service.IdentityServiceConfigurator; import org.wildfly.clustering.service.ServiceConfigurator; /** * @author Paul Ferraro */ public class IdentityCacheRequirementServiceConfiguratorProvider implements IdentityCacheServiceConfiguratorProvider { private final ClusteringCacheRequirement requirement; private final BiFunction<String, String, JndiName> jndiNameFactory; protected IdentityCacheRequirementServiceConfiguratorProvider(ClusteringCacheRequirement requirement) { this(requirement, null); } protected IdentityCacheRequirementServiceConfiguratorProvider(ClusteringCacheRequirement requirement, BiFunction<String, String, JndiName> jndiNameFactory) { this.requirement = requirement; this.jndiNameFactory = jndiNameFactory; } @Override public Iterable<ServiceConfigurator> getServiceConfigurators(CapabilityServiceSupport support, String containerName, String cacheName, String targetCacheName) { ServiceName name = this.requirement.getServiceName(support, containerName, cacheName); ServiceName targetName = this.requirement.getServiceName(support, containerName, targetCacheName); ServiceConfigurator configurator = new IdentityServiceConfigurator<>(name, targetName); if ((this.jndiNameFactory == null) || JndiNameFactory.DEFAULT_LOCAL_NAME.equals(targetCacheName)) { return List.of(configurator); } ContextNames.BindInfo binding = ContextNames.bindInfoFor(this.jndiNameFactory.apply(containerName, cacheName).getAbsoluteName()); ServiceConfigurator binderConfigurator = new BinderServiceConfigurator(binding, configurator.getServiceName()).configure(support); return List.of(configurator, binderConfigurator); } @Override public String toString() { return this.getClass().getName(); } }
3,515
46.513514
164
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/CacheRequirementServiceConfiguratorProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.extension.clustering.server; import java.util.List; import java.util.function.BiFunction; import org.jboss.as.clustering.naming.BinderServiceConfigurator; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.deployment.JndiName; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.server.service.CacheCapabilityServiceConfiguratorFactory; import org.wildfly.clustering.server.service.CacheServiceConfiguratorProvider; import org.wildfly.clustering.server.service.ClusteringCacheRequirement; import org.wildfly.clustering.service.ServiceConfigurator; /** * @author Paul Ferraro */ public class CacheRequirementServiceConfiguratorProvider<T> implements CacheServiceConfiguratorProvider { private final ClusteringCacheRequirement requirement; private final CacheCapabilityServiceConfiguratorFactory<T> factory; private final BiFunction<String, String, JndiName> jndiNameFactory; protected CacheRequirementServiceConfiguratorProvider(ClusteringCacheRequirement requirement, CacheCapabilityServiceConfiguratorFactory<T> factory) { this(requirement, factory, null); } protected CacheRequirementServiceConfiguratorProvider(ClusteringCacheRequirement requirement, CacheCapabilityServiceConfiguratorFactory<T> factory, BiFunction<String, String, JndiName> jndiNameFactory) { this.requirement = requirement; this.factory = factory; this.jndiNameFactory = jndiNameFactory; } @Override public Iterable<ServiceConfigurator> getServiceConfigurators(CapabilityServiceSupport support, String containerName, String cacheName) { ServiceName name = this.requirement.getServiceName(support, containerName, cacheName); ServiceConfigurator configurator = this.factory.createServiceConfigurator(name, containerName, cacheName).configure(support); if (this.jndiNameFactory == null) { return List.of(configurator); } ContextNames.BindInfo binding = ContextNames.bindInfoFor(this.jndiNameFactory.apply(containerName, cacheName).getAbsoluteName()); ServiceConfigurator binderConfigurator = new BinderServiceConfigurator(binding, configurator.getServiceName()).configure(support); return List.of(configurator, binderConfigurator); } @Override public String toString() { return this.getClass().getName(); } }
3,508
46.418919
207
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/GroupJndiNameFactory.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.extension.clustering.server; import java.util.function.Function; import org.jboss.as.clustering.naming.JndiNameFactory; import org.jboss.as.naming.deployment.JndiName; /** * @author Paul Ferraro */ public enum GroupJndiNameFactory implements Function<String, JndiName> { COMMAND_DISPATCHER_FACTORY("dispatcher"), GROUP("group"), ; private final String component; GroupJndiNameFactory(String component) { this.component = component; } @Override public JndiName apply(String group) { return JndiNameFactory.createJndiName(JndiNameFactory.DEFAULT_JNDI_NAMESPACE, "clustering", this.component, group); } }
1,705
34.541667
123
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/IdentityGroupRequirementServiceConfiguratorProvider.java
/* * JBoss, Home of Professional Open Source. * Copyright 2016, Red Hat, Inc., and individual contributors * as indicated by the @author tags. See the copyright.txt file in the * distribution for a full listing of individual contributors. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2.1 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ package org.wildfly.extension.clustering.server; import java.util.List; import java.util.function.Function; import org.jboss.as.clustering.naming.BinderServiceConfigurator; import org.jboss.as.clustering.naming.JndiNameFactory; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.naming.deployment.ContextNames; import org.jboss.as.naming.deployment.JndiName; import org.jboss.msc.service.ServiceName; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.server.service.IdentityGroupServiceConfiguratorProvider; import org.wildfly.clustering.service.IdentityServiceConfigurator; import org.wildfly.clustering.service.ServiceConfigurator; /** * @author Paul Ferraro */ public class IdentityGroupRequirementServiceConfiguratorProvider implements IdentityGroupServiceConfiguratorProvider { private final ClusteringRequirement requirement; private final Function<String, JndiName> jndiNameFactory; protected IdentityGroupRequirementServiceConfiguratorProvider(ClusteringRequirement requirement) { this(requirement, null); } protected IdentityGroupRequirementServiceConfiguratorProvider(ClusteringRequirement requirement, Function<String, JndiName> jndiNameFactory) { this.requirement = requirement; this.jndiNameFactory = jndiNameFactory; } @Override public Iterable<ServiceConfigurator> getServiceConfigurators(CapabilityServiceSupport support, String group, String targetGroup) { ServiceName name = this.requirement.getServiceName(support, group); ServiceName targetName = this.requirement.getServiceName(support, targetGroup); ServiceConfigurator configurator = new IdentityServiceConfigurator<>(name, targetName); if ((this.jndiNameFactory == null) || JndiNameFactory.DEFAULT_LOCAL_NAME.equals(targetGroup)) { return List.of(configurator); } ContextNames.BindInfo binding = ContextNames.bindInfoFor(this.jndiNameFactory.apply(group).getAbsoluteName()); ServiceConfigurator binderConfigurator = new BinderServiceConfigurator(binding, configurator.getServiceName()).configure(support); return List.of(configurator, binderConfigurator); } @Override public String toString() { return this.getClass().getName(); } }
3,382
44.716216
146
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/LocalGroupServiceConfigurator.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.server.group; import java.util.function.Consumer; import java.util.function.Function; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.server.ServerEnvironment; import org.jboss.as.server.ServerEnvironmentService; 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.group.Group; import org.wildfly.clustering.server.infinispan.group.LocalGroup; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; /** * Builds a non-clustered {@link Group}. * @author Paul Ferraro */ public class LocalGroupServiceConfigurator extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, Function<ServerEnvironment, Group> { private final SupplierDependency<ServerEnvironment> environment; public LocalGroupServiceConfigurator(ServiceName name) { super(name); this.environment = new ServiceSupplierDependency<>(ServerEnvironmentService.SERVICE_NAME); } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<Group> group = this.environment.register(builder).provides(this.getServiceName()); Service service = new FunctionalService<>(group, this, this.environment); return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND); } @Override public Group apply(ServerEnvironment environment) { return new LocalGroup(environment.getNodeName(), org.wildfly.clustering.server.service.LocalGroupServiceConfiguratorProvider.LOCAL); } }
3,030
42.927536
155
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/IdentityCacheGroupServiceConfiguratorProvider.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.wildfly.extension.clustering.server.group; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.server.service.ClusteringCacheRequirement; import org.wildfly.clustering.server.service.IdentityCacheServiceConfiguratorProvider; import org.wildfly.extension.clustering.server.IdentityCacheRequirementServiceConfiguratorProvider; /** * @author Paul Ferraro */ @MetaInfServices(IdentityCacheServiceConfiguratorProvider.class) public class IdentityCacheGroupServiceConfiguratorProvider extends IdentityCacheRequirementServiceConfiguratorProvider { public IdentityCacheGroupServiceConfiguratorProvider() { super(ClusteringCacheRequirement.GROUP); } }
1,714
41.875
120
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/GroupServiceConfiguratorProvider.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.wildfly.extension.clustering.server.group; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.server.service.GroupCapabilityServiceConfiguratorFactory; import org.wildfly.extension.clustering.server.GroupJndiNameFactory; import org.wildfly.extension.clustering.server.GroupRequirementServiceConfiguratorProvider; /** * Provides the requisite builders for a {@link Group} service created from a specified factory. * @author Paul Ferraro */ public class GroupServiceConfiguratorProvider extends GroupRequirementServiceConfiguratorProvider<Group> { public GroupServiceConfiguratorProvider(GroupCapabilityServiceConfiguratorFactory<Group> factory) { super(ClusteringRequirement.GROUP, factory, GroupJndiNameFactory.GROUP); } }
1,871
44.658537
106
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/IdentityGroupServiceConfiguratorProvider.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.wildfly.extension.clustering.server.group; import org.jboss.as.clustering.naming.JndiNameFactory; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.extension.clustering.server.IdentityGroupRequirementServiceConfiguratorProvider; /** * @author Paul Ferraro */ @MetaInfServices(org.wildfly.clustering.server.service.IdentityGroupServiceConfiguratorProvider.class) public class IdentityGroupServiceConfiguratorProvider extends IdentityGroupRequirementServiceConfiguratorProvider { public IdentityGroupServiceConfiguratorProvider() { super(ClusteringRequirement.GROUP, alias -> JndiNameFactory.createJndiName(JndiNameFactory.DEFAULT_JNDI_NAMESPACE, "clustering", "group", alias)); } }
1,811
44.3
154
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/LocalCacheGroupServiceConfiguratorProvider.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.wildfly.extension.clustering.server.group; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.server.service.LocalCacheServiceConfiguratorProvider; /** * Provides the requisite builders for a non-clustered cache-based {@link Group} service. * @author Paul Ferraro */ @MetaInfServices({ LocalCacheServiceConfiguratorProvider.class, org.wildfly.clustering.server.service.group.LocalCacheGroupServiceConfiguratorProvider.class }) public class LocalCacheGroupServiceConfiguratorProvider extends CacheGroupServiceConfiguratorProvider implements org.wildfly.clustering.server.service.group.LocalCacheGroupServiceConfiguratorProvider { public LocalCacheGroupServiceConfiguratorProvider() { super((name, containerName, cacheName) -> new LocalGroupServiceConfigurator(name)); } }
1,887
46.2
201
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/DistributedCacheGroupServiceConfiguratorProvider.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.wildfly.extension.clustering.server.group; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.server.service.DistributedCacheServiceConfiguratorProvider; /** * Provides the requisite builders for a clustered cache-based {@link org.wildfly.clustering.group.Group} service. * @author Paul Ferraro */ @MetaInfServices({ DistributedCacheServiceConfiguratorProvider.class, org.wildfly.clustering.server.service.group.DistributedCacheGroupServiceConfiguratorProvider.class }) public class DistributedCacheGroupServiceConfiguratorProvider extends CacheGroupServiceConfiguratorProvider implements org.wildfly.clustering.server.service.group.DistributedCacheGroupServiceConfiguratorProvider { public DistributedCacheGroupServiceConfiguratorProvider() { super(CacheGroupServiceConfigurator::new); } }
1,864
46.820513
213
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/CacheGroupServiceConfigurator.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.wildfly.extension.clustering.server.group; import java.util.function.Consumer; import java.util.function.Supplier; import org.infinispan.Cache; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.clustering.function.Consumers; import org.jboss.as.clustering.function.Functions; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.as.server.ServerEnvironment; import org.jboss.as.server.ServerEnvironmentService; 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.jgroups.Address; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement; import org.wildfly.clustering.server.NodeFactory; import org.wildfly.clustering.server.infinispan.group.AutoCloseableGroup; import org.wildfly.clustering.server.infinispan.group.CacheGroup; import org.wildfly.clustering.server.infinispan.group.CacheGroupConfiguration; import org.wildfly.clustering.server.infinispan.group.LocalGroup; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.service.AsyncServiceConfigurator; import org.wildfly.clustering.service.CompositeDependency; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; /** * Builds a {@link Group} service for a cache. * @author Paul Ferraro */ public class CacheGroupServiceConfigurator extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, CacheGroupConfiguration, Supplier<AutoCloseableGroup<?>> { private final String containerName; private final String cacheName; private final SupplierDependency<ServerEnvironment> environment; private volatile SupplierDependency<Cache<?, ?>> cache; private volatile SupplierDependency<NodeFactory<Address>> factory; public CacheGroupServiceConfigurator(ServiceName name, String containerName, String cacheName) { super(name); this.containerName = containerName; this.cacheName = cacheName; this.environment = new ServiceSupplierDependency<>(ServerEnvironmentService.SERVICE_NAME); } @Override public AutoCloseableGroup<?> get() { Cache<?, ?> cache = this.cache.get(); return cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? new CacheGroup(this) : new LocalGroup(this.environment.get().getNodeName(), this.containerName); } @Override public ServiceConfigurator configure(CapabilityServiceSupport support) { this.cache = new ServiceSupplierDependency<>(InfinispanCacheRequirement.CACHE.getServiceName(support, this.containerName, this.cacheName)); this.factory = new ServiceSupplierDependency<>(ClusteringRequirement.GROUP.getServiceName(support, this.containerName)); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceName name = this.getServiceName(); ServiceBuilder<?> builder = new AsyncServiceConfigurator(name).build(target); Consumer<Group> group = new CompositeDependency(this.cache, this.factory, this.environment).register(builder).provides(name); Service service = new FunctionalService<>(group, Functions.identity(), this, Consumers.close()); return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND); } @SuppressWarnings("unchecked") @Override public <K, V> Cache<K, V> getCache() { return (Cache<K, V>) this.cache.get(); } @Override public NodeFactory<Address> getMemberFactory() { return this.factory.get(); } }
5,047
45.311927
182
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/ChannelGroupServiceConfiguratorProvider.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.wildfly.extension.clustering.server.group; import org.kohsuke.MetaInfServices; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.server.service.DistributedGroupServiceConfiguratorProvider; /** * Provides the requisite builders for a channel-based {@link Group} service. * @author Paul Ferraro */ @MetaInfServices(DistributedGroupServiceConfiguratorProvider.class) public class ChannelGroupServiceConfiguratorProvider extends GroupServiceConfiguratorProvider implements DistributedGroupServiceConfiguratorProvider { public ChannelGroupServiceConfiguratorProvider() { super((registry, group) -> new ChannelGroupServiceConfigurator(registry, group)); } }
1,732
43.435897
150
java
null
wildfly-main/clustering/server/extension/src/main/java/org/wildfly/extension/clustering/server/group/ChannelGroupServiceConfigurator.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.wildfly.extension.clustering.server.group; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import org.jboss.as.clustering.controller.CapabilityServiceConfigurator; import org.jboss.as.controller.capability.CapabilityServiceSupport; import org.jboss.msc.Service; import org.jboss.msc.service.ServiceBuilder; import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; import org.jboss.msc.service.ServiceTarget; import org.wildfly.clustering.dispatcher.CommandDispatcherFactory; import org.wildfly.clustering.group.Group; import org.wildfly.clustering.server.service.ClusteringRequirement; import org.wildfly.clustering.service.FunctionalService; import org.wildfly.clustering.service.ServiceConfigurator; import org.wildfly.clustering.service.ServiceSupplierDependency; import org.wildfly.clustering.service.SimpleServiceNameProvider; import org.wildfly.clustering.service.SupplierDependency; /** * Builds a channel-based {@link Group} service. * @author Paul Ferraro */ public class ChannelGroupServiceConfigurator extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, Supplier<Group> { private final String group; private volatile SupplierDependency<CommandDispatcherFactory> factory; public ChannelGroupServiceConfigurator(ServiceName name, String group) { super(name); this.group = group; } @Override public Group get() { return this.factory.get().getGroup(); } @Override public ServiceConfigurator configure(CapabilityServiceSupport support) { this.factory = new ServiceSupplierDependency<>(ClusteringRequirement.COMMAND_DISPATCHER_FACTORY.getServiceName(support, this.group)); return this; } @Override public ServiceBuilder<?> build(ServiceTarget target) { ServiceBuilder<?> builder = target.addService(this.getServiceName()); Consumer<Group> group = this.factory.register(builder).provides(this.getServiceName()); Service service = new FunctionalService<>(group, Function.identity(), this); return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND); } }
3,271
40.948718
141
java