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/infinispan/embedded/service/src/main/java/org/wildfly/clustering/infinispan/service/ConfigurationServiceConfigurator.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.infinispan.service;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.cache.StorageType;
import org.infinispan.manager.EmbeddedCacheManager;
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.service.CompositeDependency;
import org.wildfly.clustering.service.Dependency;
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;
/**
* Configures a {@link Service} providing a cache {@link Configuration}.
* @author Paul Ferraro
*/
public class ConfigurationServiceConfigurator extends SimpleServiceNameProvider implements CapabilityServiceConfigurator, Supplier<Configuration>, Consumer<Configuration> {
private final String containerName;
private final String cacheName;
private final Consumer<ConfigurationBuilder> consumer;
private volatile SupplierDependency<EmbeddedCacheManager> container;
private volatile Dependency dependency;
public ConfigurationServiceConfigurator(ServiceName name, String containerName, String cacheName, Consumer<ConfigurationBuilder> consumer) {
super(name);
this.containerName = containerName;
this.cacheName = cacheName;
this.consumer = consumer;
}
public ConfigurationServiceConfigurator require(Dependency dependency) {
this.dependency = dependency;
return this;
}
@Override
public ServiceConfigurator configure(CapabilityServiceSupport support) {
this.container = new ServiceSupplierDependency<>(InfinispanRequirement.CONTAINER.getServiceName(support, this.containerName));
return this;
}
@Override
public final ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<Configuration> configuration = new CompositeDependency(this.container, this.dependency).register(builder).provides(this.getServiceName());
Service service = new FunctionalService<>(configuration, Function.identity(), this, this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.ON_DEMAND);
}
@Override
public Configuration get() {
ConfigurationBuilder builder = new ConfigurationBuilder();
this.consumer.accept(builder);
// Auto-enable simple cache optimization if cache is local, on-heap, non-transactional, and non-persistent, and statistics are disabled
builder.simpleCache((builder.clustering().cacheMode() == CacheMode.LOCAL) && (builder.memory().storage() == StorageType.HEAP) && !builder.transaction().transactionMode().isTransactional() && builder.persistence().stores().isEmpty() && !builder.statistics().create().enabled());
// Set media-type appropriate for the configured memory store
builder.encoding().mediaType(builder.memory().storage().canStoreReferences() ? MediaType.APPLICATION_OBJECT_TYPE : this.container.get().getCacheManagerConfiguration().serialization().marshaller().mediaType().toString());
Configuration configuration = builder.build();
EmbeddedCacheManager container = this.container.get();
container.defineConfiguration(this.cacheName, configuration);
return configuration;
}
@Override
public void accept(Configuration configuration) {
EmbeddedCacheManager container = this.container.get();
container.undefineConfiguration(this.cacheName);
}
}
| 5,320
| 47.372727
| 285
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/service/src/main/java/org/wildfly/clustering/infinispan/service/InfinispanCacheRequirement.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.infinispan.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.DefaultableBinaryRequirement;
import org.wildfly.clustering.service.UnaryRequirement;
/**
* @author Paul Ferraro
*/
public enum InfinispanCacheRequirement implements DefaultableBinaryRequirement, DefaultableBinaryServiceNameFactoryProvider {
CACHE("org.wildfly.clustering.infinispan.cache", InfinispanDefaultCacheRequirement.CACHE),
CONFIGURATION("org.wildfly.clustering.infinispan.cache-configuration", InfinispanDefaultCacheRequirement.CONFIGURATION),
;
private final String name;
private final BinaryServiceNameFactory factory = new BinaryRequirementServiceNameFactory(this);
private final InfinispanDefaultCacheRequirement defaultRequirement;
InfinispanCacheRequirement(String name, InfinispanDefaultCacheRequirement defaultRequirement) {
this.name = name;
this.defaultRequirement = defaultRequirement;
}
@Override
public String getName() {
return this.name;
}
@Override
public UnaryRequirement getDefaultRequirement() {
return this.defaultRequirement;
}
@Override
public BinaryServiceNameFactory getServiceNameFactory() {
return this.factory;
}
@Override
public UnaryServiceNameFactory getDefaultServiceNameFactory() {
return this.defaultRequirement;
}
}
| 2,712
| 38.318841
| 125
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/service/src/main/java/org/wildfly/clustering/infinispan/service/InfinispanRequirement.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.infinispan.service;
import org.infinispan.configuration.global.GlobalConfiguration;
import org.infinispan.manager.EmbeddedCacheManager;
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.infinispan.affinity.KeyAffinityServiceFactory;
import org.wildfly.clustering.service.UnaryRequirement;
/**
* @author Paul Ferraro
*/
public enum InfinispanRequirement implements UnaryRequirement, UnaryServiceNameFactoryProvider {
CONTAINER("org.wildfly.clustering.infinispan.cache-container", EmbeddedCacheManager.class),
CONFIGURATION("org.wildfly.clustering.infinispan.cache-container-configuration", GlobalConfiguration.class),
KEY_AFFINITY_FACTORY("org.wildfly.clustering.infinispan.key-affinity-factory", KeyAffinityServiceFactory.class),
;
private final String name;
private final Class<?> type;
private final UnaryServiceNameFactory factory = new UnaryRequirementServiceNameFactory(this);
InfinispanRequirement(String name, Class<?> type) {
this.name = name;
this.type = type;
}
@Override
public String getName() {
return this.name;
}
@Override
public Class<?> getType() {
return this.type;
}
@Override
public UnaryServiceNameFactory getServiceNameFactory() {
return this.factory;
}
}
| 2,554
| 37.712121
| 116
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/distribution/ConsistentHashKeyDistributionTestCase.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.infinispan.distribution;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.remoting.transport.Address;
import org.junit.Test;
/**
* @author Paul Ferraro
*/
public class ConsistentHashKeyDistributionTestCase {
@Test
public void test() {
KeyPartitioner partitioner = mock(KeyPartitioner.class);
ConsistentHash hash = mock(ConsistentHash.class);
KeyDistribution distribution = new ConsistentHashKeyDistribution(partitioner, hash);
Address address = mock(Address.class);
Object key = new Object();
int segment = 128;
when(partitioner.getSegment(key)).thenReturn(segment);
when(hash.locatePrimaryOwnerForSegment(segment)).thenReturn(address);
Address result = distribution.getPrimaryOwner(key);
assertSame(address, result);
}
}
| 2,083
| 35.561404
| 92
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/distribution/ConsistentHashLocalityTestCase.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.infinispan.distribution;
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.infinispan.remoting.transport.Address;
import org.junit.Test;
/**
* @author Paul Ferraro
*/
public class ConsistentHashLocalityTestCase {
@Test
public void test() {
KeyDistribution distribution = mock(KeyDistribution.class);
Address localAddress = mock(Address.class);
Address remoteAddress = mock(Address.class);
Object localKey = new Object();
Object remoteKey = new Object();
Locality locality = new ConsistentHashLocality(distribution, localAddress);
when(distribution.getPrimaryOwner(localKey)).thenReturn(localAddress);
when(distribution.getPrimaryOwner(remoteKey)).thenReturn(remoteAddress);
assertTrue(locality.isLocal(localKey));
assertFalse(locality.isLocal(remoteKey));
}
}
| 2,044
| 36.181818
| 83
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/affinity/impl/SimpleKeyAffinityServiceTestCase.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.infinispan.affinity.impl;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.UUID;
import org.infinispan.affinity.KeyAffinityService;
import org.infinispan.affinity.KeyGenerator;
import org.infinispan.remoting.transport.Address;
import org.junit.Test;
/**
* @author Paul Ferraro
*/
public class SimpleKeyAffinityServiceTestCase {
private final KeyGenerator<UUID> generator = mock(KeyGenerator.class);
private final KeyAffinityService<UUID> service = new SimpleKeyAffinityService<>(this.generator);
@Test
public void getKeyForAddress() {
Address address = mock(Address.class);
UUID key = UUID.randomUUID();
when(this.generator.getKey()).thenReturn(key);
UUID result = this.service.getKeyForAddress(address);
assertSame(key, result);
}
@Test
public void getCollocatedKey() {
UUID key = UUID.randomUUID();
when(this.generator.getKey()).thenReturn(key);
UUID result = this.service.getCollocatedKey(UUID.randomUUID());
assertSame(key, result);
}
}
| 2,206
| 31.940299
| 100
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/affinity/impl/DefaultKeyAffinityServiceTestCase.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.infinispan.affinity.impl;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import org.infinispan.AdvancedCache;
import org.infinispan.affinity.KeyAffinityService;
import org.infinispan.affinity.KeyGenerator;
import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.distribution.LocalizedCacheTopology;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.remoting.transport.Address;
import org.infinispan.topology.CacheTopology;
import org.infinispan.topology.PersistentUUID;
import org.junit.Test;
import org.mockito.stubbing.OngoingStubbing;
/**
* Unit test for {@link DefaultKeyAffinityService}.
* @author Paul Ferraro
*/
public class DefaultKeyAffinityServiceTestCase {
private static final int SEGMENTS = 3;
private static final int LOCAL_SEGMENT = 0;
private static final int REMOTE_SEGMENT = 1;
private static final int FILTERED_SEGMENT = 2;
@Test
public void test() {
KeyPartitioner partitioner = mock(KeyPartitioner.class);
KeyGenerator<UUID> generator = mock(KeyGenerator.class);
AdvancedCache<UUID, Object> cache = mock(AdvancedCache.class);
Address local = mock(Address.class);
Address remote = mock(Address.class);
Address standby = mock(Address.class);
Address ignored = mock(Address.class);
KeyAffinityService<UUID> service = new DefaultKeyAffinityService<>(cache, partitioner, generator, address -> (address != ignored));
DistributionManager dist = mock(DistributionManager.class);
CacheTopology topology = mock(CacheTopology.class);
ConsistentHash hash = mock(ConsistentHash.class);
List<Address> members = Arrays.asList(local, remote, standby, ignored);
when(cache.getAdvancedCache()).thenReturn(cache);
when(cache.getDistributionManager()).thenReturn(dist);
when(topology.getActualMembers()).thenReturn(members);
when(topology.getCurrentCH()).thenReturn(hash);
when(topology.getMembers()).thenReturn(members);
when(topology.getMembersPersistentUUIDs()).thenReturn(Arrays.asList(PersistentUUID.randomUUID(), PersistentUUID.randomUUID(), PersistentUUID.randomUUID(), PersistentUUID.randomUUID()));
when(topology.getPendingCH()).thenReturn(null);
when(topology.getPhase()).thenReturn(CacheTopology.Phase.NO_REBALANCE);
when(topology.getReadConsistentHash()).thenReturn(hash);
when(topology.getRebalanceId()).thenReturn(0);
when(topology.getTopologyId()).thenReturn(0);
when(topology.getUnionCH()).thenReturn(null);
when(topology.getWriteConsistentHash()).thenReturn(hash);
when(hash.getMembers()).thenReturn(members);
when(hash.getNumSegments()).thenReturn(SEGMENTS);
when(hash.locatePrimaryOwnerForSegment(LOCAL_SEGMENT)).thenReturn(local);
when(hash.locatePrimaryOwnerForSegment(REMOTE_SEGMENT)).thenReturn(remote);
when(hash.locatePrimaryOwnerForSegment(FILTERED_SEGMENT)).thenReturn(ignored);
when(hash.locateOwnersForSegment(LOCAL_SEGMENT)).thenReturn(Collections.singletonList(local));
when(hash.locateOwnersForSegment(REMOTE_SEGMENT)).thenReturn(Collections.singletonList(remote));
when(hash.locateOwnersForSegment(FILTERED_SEGMENT)).thenReturn(Collections.singletonList(ignored));
when(hash.getPrimarySegmentsForOwner(local)).thenReturn(Collections.singleton(LOCAL_SEGMENT));
when(hash.getPrimarySegmentsForOwner(remote)).thenReturn(Collections.singleton(REMOTE_SEGMENT));
when(hash.getPrimarySegmentsForOwner(standby)).thenReturn(Collections.emptySet());
when(hash.getPrimarySegmentsForOwner(ignored)).thenReturn(Collections.singleton(FILTERED_SEGMENT));
when(hash.getSegmentsForOwner(local)).thenReturn(Collections.singleton(LOCAL_SEGMENT));
when(hash.getSegmentsForOwner(remote)).thenReturn(Collections.singleton(REMOTE_SEGMENT));
when(hash.getSegmentsForOwner(standby)).thenReturn(Collections.emptySet());
when(hash.getSegmentsForOwner(ignored)).thenReturn(Collections.singleton(FILTERED_SEGMENT));
LocalizedCacheTopology localizedTopology = new LocalizedCacheTopology(CacheMode.DIST_SYNC, topology, partitioner, local, true);
when(dist.getCacheTopology()).thenReturn(localizedTopology);
// Mock a sufficient number of keys
OngoingStubbing<UUID> stub = when(generator.getKey());
for (int i = 0; i < 1000; ++i) {
UUID key = UUID.randomUUID();
int segment = getSegment(key);
stub = stub.thenReturn(key);
when(partitioner.getSegment(key)).thenReturn(segment);
}
assertThrows(IllegalStateException.class, () -> service.getKeyForAddress(local));
assertThrows(IllegalStateException.class, () -> service.getKeyForAddress(remote));
assertThrows(IllegalStateException.class, () -> service.getKeyForAddress(standby));
// This should throw IAE, since address does not pass filter
assertThrows(IllegalArgumentException.class, () -> service.getKeyForAddress(ignored));
service.start();
try {
for (int i = 0; i < 50; ++i) {
UUID key = service.getKeyForAddress(local);
int segment = getSegment(key);
assertEquals(LOCAL_SEGMENT, segment);
key = service.getCollocatedKey(key);
segment = getSegment(key);
assertEquals(LOCAL_SEGMENT, segment);
key = service.getKeyForAddress(remote);
segment = getSegment(key);
assertEquals(REMOTE_SEGMENT, segment);
key = service.getCollocatedKey(key);
segment = getSegment(key);
assertEquals(REMOTE_SEGMENT, segment);
}
// This should return a random key
assertNotNull(service.getKeyForAddress(standby));
// This should throw IAE, since address does not pass filter
assertThrows(IllegalArgumentException.class, () -> service.getKeyForAddress(ignored));
} finally {
service.stop();
}
}
private static int getSegment(UUID key) {
return Math.abs(key.hashCode()) % SEGMENTS;
}
}
| 7,631
| 46.7
| 193
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/affinity/impl/ConsistentHashKeyRegistryTestCase.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.infinispan.affinity.impl;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.BlockingQueue;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.remoting.transport.Address;
import org.junit.Test;
/**
* @author Paul Ferraro
*/
public class ConsistentHashKeyRegistryTestCase {
@Test
public void test() {
ConsistentHash hash = mock(ConsistentHash.class);
Predicate<Address> filter = mock(Predicate.class);
Supplier<BlockingQueue<Object>> queueFactory = mock(Supplier.class);
Address local = mock(Address.class);
Address filtered = mock(Address.class);
Address standby = mock(Address.class);
BlockingQueue<Object> queue = mock(BlockingQueue.class);
when(hash.getMembers()).thenReturn(Arrays.asList(local, filtered, standby));
when(filter.test(local)).thenReturn(true);
when(filter.test(filtered)).thenReturn(false);
when(filter.test(standby)).thenReturn(true);
when(hash.getPrimarySegmentsForOwner(local)).thenReturn(Collections.singleton(1));
when(hash.getPrimarySegmentsForOwner(standby)).thenReturn(Collections.emptySet());
when(queueFactory.get()).thenReturn(queue);
KeyRegistry<Object> registry = new ConsistentHashKeyRegistry<>(hash, filter, queueFactory);
assertTrue(registry.getAddresses().contains(local));
assertFalse(registry.getAddresses().contains(filtered));
assertFalse(registry.getAddresses().contains(standby));
assertEquals(Collections.singleton(local), registry.getAddresses());
assertSame(queue, registry.getKeys(local));
assertNull(registry.getKeys(standby));
assertNull(registry.getKeys(filtered));
}
}
| 2,973
| 40.305556
| 99
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/persistence/IndexedKeyFormatMapperTestCase.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.infinispan.persistence;
import java.util.List;
import java.util.stream.Collectors;
import org.infinispan.persistence.keymappers.TwoWayKey2StringMapper;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.marshalling.spi.Formatter;
import org.wildfly.clustering.marshalling.spi.SimpleFormatter;
/**
* @author Paul Ferraro
*/
public class IndexedKeyFormatMapperTestCase {
enum Type {
TYPE00 {},
TYPE01 {},
TYPE02 {},
TYPE03 {},
TYPE04 {},
TYPE05 {},
TYPE06 {},
TYPE07 {},
TYPE08 {},
TYPE09 {},
TYPE10 {},
TYPE11 {},
TYPE12 {},
TYPE13 {},
TYPE14 {},
TYPE15 {},
TYPE16 {},
TYPE17 {},
}
@Test
public void testSinglePadding() {
TwoWayKey2StringMapper mapper = new IndexedKeyFormatMapper(createPersistenceList(16));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE00.getClass()));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE15.getClass()));
Assert.assertFalse(mapper.isSupportedType(Type.TYPE16.getClass()));
Assert.assertFalse(mapper.isSupportedType(Type.TYPE17.getClass()));
String result = mapper.getStringMapping(Type.TYPE00);
Assert.assertSame(Type.TYPE00, mapper.getKeyMapping(result));
Assert.assertEquals("0TYPE00", result);
result = mapper.getStringMapping(Type.TYPE15);
Assert.assertSame(Type.TYPE15, mapper.getKeyMapping(result));
Assert.assertEquals("FTYPE15", result);
}
@Test
public void testDoublePadding() {
TwoWayKey2StringMapper mapper = new IndexedKeyFormatMapper(createPersistenceList(17));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE00.getClass()));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE15.getClass()));
Assert.assertTrue(mapper.isSupportedType(Type.TYPE16.getClass()));
Assert.assertFalse(mapper.isSupportedType(Type.TYPE17.getClass()));
String result = mapper.getStringMapping(Type.TYPE00);
Assert.assertSame(Type.TYPE00, mapper.getKeyMapping(result));
Assert.assertEquals("00TYPE00", result);
result = mapper.getStringMapping(Type.TYPE15);
Assert.assertSame(Type.TYPE15, mapper.getKeyMapping(result));
Assert.assertEquals("0FTYPE15", result);
result = mapper.getStringMapping(Type.TYPE16);
Assert.assertSame(Type.TYPE16, mapper.getKeyMapping(result));
Assert.assertEquals("10TYPE16", result);
}
@SuppressWarnings("unchecked")
private static List<? extends Formatter<?>> createPersistenceList(int size) {
return java.util.stream.IntStream.range(0, size).mapToObj(index -> new SimpleFormatter<>((Class<Type>) Type.values()[index].getClass(), value -> Type.valueOf(value), Type::name)).collect(Collectors.toList());
}
}
| 3,956
| 36.685714
| 216
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/persistence/KeyMapperTester.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.infinispan.persistence;
import static org.junit.Assert.assertTrue;
import java.util.function.BiConsumer;
import org.infinispan.persistence.keymappers.TwoWayKey2StringMapper;
import org.junit.Assert;
import org.wildfly.clustering.marshalling.Tester;
/**
* Tester for a {@link TwoWayKey2StringMapper}.
* @author Paul Ferraro
*/
public class KeyMapperTester implements Tester<Object> {
private final TwoWayKey2StringMapper mapper;
public KeyMapperTester(TwoWayKey2StringMapper mapper) {
this.mapper = mapper;
}
@Override
public void test(Object key) {
this.test(key, Assert::assertEquals);
}
@Override
public void test(Object key, BiConsumer<Object, Object> assertion) {
assertTrue(this.mapper.isSupportedType(key.getClass()));
String mapping = this.mapper.getStringMapping(key);
Object result = this.mapper.getKeyMapping(mapping);
assertion.accept(key, result);
}
}
| 2,017
| 32.081967
| 72
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/test/java/org/wildfly/clustering/infinispan/persistence/SimpleKeyFormatMapperTestCase.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.infinispan.persistence;
import static org.mockito.Mockito.*;
import org.infinispan.persistence.keymappers.TwoWayKey2StringMapper;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.marshalling.spi.Formatter;
/**
* @author Paul Ferraro
*/
public class SimpleKeyFormatMapperTestCase {
@Test
public void test() {
Formatter<Object> keyFormat = mock(Formatter.class);
TwoWayKey2StringMapper mapper = new SimpleKeyFormatMapper(keyFormat);
Object key = new Object();
String formatted = "foo";
when(keyFormat.getTargetClass()).thenReturn(Object.class);
when(keyFormat.format(key)).thenReturn(formatted);
when(keyFormat.parse(formatted)).thenReturn(key);
Assert.assertSame(formatted, mapper.getStringMapping(key));
Assert.assertSame(key, mapper.getKeyMapping(formatted));
Assert.assertTrue(mapper.isSupportedType(Object.class));
Assert.assertFalse(mapper.isSupportedType(Integer.class));
}
}
| 2,074
| 36.727273
| 77
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/configuration/ConfigurationBuilderAttributesAccessor.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.configuration;
import java.lang.reflect.Field;
import java.security.PrivilegedAction;
import java.util.function.Function;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* @author Paul Ferraro
*/
public enum ConfigurationBuilderAttributesAccessor implements Function<Object, AttributeSet> {
INSTANCE;
@Override
public AttributeSet apply(Object builder) {
PrivilegedAction<AttributeSet> action = new PrivilegedAction<>() {
@Override
public AttributeSet run() {
NoSuchFieldException exception = null;
Class<?> targetClass = builder.getClass();
while (targetClass != Object.class) {
try {
Field field = builder.getClass().getDeclaredField("attributes");
try {
field.setAccessible(true);
return (AttributeSet) field.get(builder);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
} finally {
field.setAccessible(false);
}
} catch (NoSuchFieldException e) {
if (exception == null) {
exception = e;
}
targetClass = targetClass.getSuperclass();
}
}
throw new IllegalStateException(exception);
}
};
return WildFlySecurityManager.doUnchecked(action);
}
}
| 2,775
| 38.657143
| 94
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/globalstate/GlobalStateManagerFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.globalstate;
import org.infinispan.factories.AbstractComponentFactory;
import org.infinispan.factories.AutoInstantiableFactory;
import org.infinispan.factories.annotations.DefaultFactoryFor;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
import org.infinispan.globalstate.GlobalStateManager;
import org.infinispan.globalstate.impl.GlobalStateManagerImpl;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* Workaround for ISPN-14051.
* @author Paul Ferraro
*/
@DefaultFactoryFor(classes = GlobalStateManager.class)
@Scope(Scopes.GLOBAL)
public class GlobalStateManagerFactory extends AbstractComponentFactory implements AutoInstantiableFactory {
@Override
public Object construct(String componentName) {
return WildFlySecurityManager.isChecking() ? new PrivilegedGlobalStateManager() : new GlobalStateManagerImpl();
}
}
| 1,971
| 41.869565
| 119
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/globalstate/PrivilegedGlobalStateManager.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.globalstate;
import java.security.PrivilegedAction;
import java.util.Optional;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
import org.infinispan.globalstate.ScopedPersistentState;
import org.infinispan.globalstate.impl.GlobalStateManagerImpl;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* Workaround for ISPN-14051.
* @author Paul Ferraro
*/
@Scope(Scopes.GLOBAL)
@SuppressWarnings("synthetic-access")
public class PrivilegedGlobalStateManager extends GlobalStateManagerImpl {
@Override
public void start() {
WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() {
@Override
public Void run() {
PrivilegedGlobalStateManager.super.start();
return null;
}
});
}
@Override
public void stop() {
WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() {
@Override
public Void run() {
PrivilegedGlobalStateManager.super.stop();
return null;
}
});
}
@Override
public void writeGlobalState() {
WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() {
@Override
public Void run() {
PrivilegedGlobalStateManager.super.writeGlobalState();
return null;
}
});
}
@Override
public void writeScopedState(ScopedPersistentState state) {
WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() {
@Override
public Void run() {
PrivilegedGlobalStateManager.super.writeScopedState(state);
return null;
}
});
}
@Override
public void deleteScopedState(String scope) {
WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() {
@Override
public Void run() {
PrivilegedGlobalStateManager.super.deleteScopedState(scope);
return null;
}
});
}
@Override
public Optional<ScopedPersistentState> readScopedState(String scope) {
return WildFlySecurityManager.doUnchecked(new PrivilegedAction<>() {
@Override
public Optional<ScopedPersistentState> run() {
return PrivilegedGlobalStateManager.super.readScopedState(scope);
}
});
}
}
| 3,526
| 32.273585
| 81
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/globalstate/WildFlyLocalConfigurationStorage.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.infinispan.globalstate;
import static org.infinispan.factories.KnownComponentNames.CACHE_DEPENDENCY_GRAPH;
import java.util.EnumSet;
import java.util.concurrent.CompletionStage;
import org.infinispan.Cache;
import org.infinispan.commons.api.CacheContainerAdmin;
import org.infinispan.configuration.ConfigurationManager;
import org.infinispan.factories.GlobalComponentRegistry;
import org.infinispan.util.DependencyGraph;
/**
* Custom {@link org.infinispan.globalstate.impl.VolatileLocalConfigurationStorage} that doesn't mess with the {@link org.infinispan.eviction.impl.PassivationManager} or {@link org.infinispan.persistence.manager.PersistenceManager}.
* @author Paul Ferraro
*/
public class WildFlyLocalConfigurationStorage extends org.infinispan.globalstate.impl.VolatileLocalConfigurationStorage {
@SuppressWarnings("deprecation")
@Override
public CompletionStage<Void> removeCache(String name, EnumSet<CacheContainerAdmin.AdminFlag> flags) {
return this.blockingManager.<Void>supplyBlocking(() -> {
GlobalComponentRegistry globalComponentRegistry = this.cacheManager.getGlobalComponentRegistry();
Cache<?, ?> cache = this.cacheManager.getCache(name, false);
if (cache != null) {
cache.stop();
}
globalComponentRegistry.removeCache(name);
// Remove cache configuration and remove it from the computed cache name list
globalComponentRegistry.getComponent(ConfigurationManager.class).removeConfiguration(name);
// Remove cache from dependency graph
globalComponentRegistry.getComponent(DependencyGraph.class, CACHE_DEPENDENCY_GRAPH).remove(name);
return null;
}, name).toCompletableFuture();
}
}
| 2,832
| 46.216667
| 232
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/reactive/LocalClusterPublisherManager.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.infinispan.reactive;
import java.lang.reflect.Field;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
import org.infinispan.reactive.publisher.impl.LocalClusterPublisherManagerImpl;
/**
* Overrides Infinispan's {@link org.infinispan.factories.PublisherManagerFactory.LOCAL_CLUSTER_PUBLISHER} to align its segmentation logic with WildFly's key partitioner for non-tx invalidation caches.
* @author Paul Ferraro
*/
@Scope(Scopes.NAMED_CACHE)
public class LocalClusterPublisherManager<K, V> extends LocalClusterPublisherManagerImpl<K, V> {
@Inject Configuration configuration;
@Override
public void start() {
try {
Field field = LocalClusterPublisherManagerImpl.class.getDeclaredField("maxSegment");
field.setAccessible(true);
try {
field.set(this, this.configuration.clustering().hash().numSegments());
} finally {
field.setAccessible(false);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}
}
| 2,304
| 40.160714
| 201
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/reactive/PublisherManagerFactory.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.infinispan.reactive;
import org.infinispan.factories.annotations.DefaultFactoryFor;
import org.infinispan.reactive.publisher.impl.ClusterPublisherManager;
import org.infinispan.reactive.publisher.impl.LocalPublisherManager;
/**
* Because we override Infinispan's KeyPartition for non-tx invalidation-caches, we need to make sure the {@link org.infinispan.factories.PublisherManagerFactory.LOCAL_CLUSTER_PUBLISHER}
* handles segmentation in the same way.
* @author Paul Ferraro
*/
@DefaultFactoryFor(classes = { LocalPublisherManager.class, ClusterPublisherManager.class }, names = org.infinispan.factories.PublisherManagerFactory.LOCAL_CLUSTER_PUBLISHER)
public class PublisherManagerFactory extends org.infinispan.factories.PublisherManagerFactory {
@Override
public Object construct(String componentName) {
if (componentName.equals(LOCAL_CLUSTER_PUBLISHER)) {
return new LocalClusterPublisherManager<>();
}
return super.construct(componentName);
}
}
| 2,060
| 45.840909
| 186
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/container/DataContainerConfiguration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.container;
import java.util.function.Predicate;
import org.infinispan.commons.configuration.BuiltBy;
import org.infinispan.commons.configuration.attributes.Attribute;
import org.infinispan.commons.configuration.attributes.AttributeDefinition;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.commons.configuration.attributes.IdentityAttributeCopier;
import org.infinispan.commons.configuration.attributes.Matchable;
/**
* @author Paul Ferraro
*/
@BuiltBy(DataContainerConfigurationBuilder.class)
public class DataContainerConfiguration implements Matchable<DataContainerConfiguration> {
private static final Predicate<Object> ALWAYS = new Predicate<>() {
@Override
public boolean test(Object key) {
return true;
}
};
@SuppressWarnings("rawtypes")
static final AttributeDefinition<Predicate> EVICTABLE_PREDICATE = AttributeDefinition.builder("evictable", ALWAYS, Predicate.class)
.copier(IdentityAttributeCopier.identityCopier())
.immutable()
.build();
@SuppressWarnings("rawtypes")
private final Attribute<Predicate> evictable;
DataContainerConfiguration(AttributeSet attributes) {
this.evictable = attributes.attribute(EVICTABLE_PREDICATE);
}
public <K> Predicate<K> evictable() {
return this.evictable.get();
}
@Override
public boolean matches(DataContainerConfiguration configuration) {
return this.evictable() == configuration.evictable();
}
}
| 2,614
| 37.455882
| 135
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/container/DataContainerFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.container;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.infinispan.commons.marshall.WrappedBytes;
import org.infinispan.commons.util.EntrySizeCalculator;
import org.infinispan.configuration.cache.ClusteringConfiguration;
import org.infinispan.configuration.cache.MemoryConfiguration;
import org.infinispan.container.DataContainer;
import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.container.impl.BoundedSegmentedDataContainer;
import org.infinispan.container.impl.DefaultDataContainer;
import org.infinispan.container.impl.DefaultSegmentedDataContainer;
import org.infinispan.container.impl.InternalDataContainer;
import org.infinispan.container.impl.L1SegmentedDataContainer;
import org.infinispan.container.impl.PeekableTouchableContainerMap;
import org.infinispan.container.impl.PeekableTouchableMap;
import org.infinispan.container.offheap.BoundedOffHeapDataContainer;
import org.infinispan.container.offheap.OffHeapConcurrentMap;
import org.infinispan.container.offheap.OffHeapDataContainer;
import org.infinispan.container.offheap.OffHeapEntryFactory;
import org.infinispan.container.offheap.OffHeapMemoryAllocator;
import org.infinispan.container.offheap.SegmentedBoundedOffHeapDataContainer;
import org.infinispan.eviction.EvictionStrategy;
import org.infinispan.factories.AbstractNamedCacheComponentFactory;
import org.infinispan.factories.AutoInstantiableFactory;
import org.infinispan.factories.annotations.DefaultFactoryFor;
import org.infinispan.factories.annotations.SurvivesRestarts;
/**
* @author Paul Ferraro
*/
@DefaultFactoryFor(classes = InternalDataContainer.class)
@SurvivesRestarts
public class DataContainerFactory<K, V> extends AbstractNamedCacheComponentFactory implements AutoInstantiableFactory {
@Override
public Object construct(String componentName) {
MemoryConfiguration memory = this.configuration.memory();
EvictionStrategy strategy = memory.whenFull();
// handle case when < 0 value signifies unbounded container or when we are not removal based
if (strategy.isExceptionBased() || !strategy.isEnabled()) {
return this.createUnboundedContainer();
}
DataContainer<?, ?> container = this.createBoundedDataContainer();
memory.attributes().attribute(MemoryConfiguration.MAX_COUNT).addListener((newSize, oldSize) -> container.resize(newSize.get()));
return container;
}
private DataContainer<?, ?> createUnboundedContainer() {
ClusteringConfiguration clustering = this.configuration.clustering();
boolean segmented = clustering.cacheMode().needsStateTransfer();
int level = this.configuration.locking().concurrencyLevel();
boolean offHeap = this.configuration.memory().isOffHeap();
if (segmented) {
Supplier<PeekableTouchableMap<WrappedBytes, WrappedBytes>> mapSupplier = offHeap ? this::createAndStartOffHeapConcurrentMap : PeekableTouchableContainerMap::new;
int segments = clustering.hash().numSegments();
return clustering.l1().enabled() ? new L1SegmentedDataContainer<>(mapSupplier, segments) : new DefaultSegmentedDataContainer<>(mapSupplier, segments);
}
return offHeap ? new OffHeapDataContainer() : DefaultDataContainer.unBoundedDataContainer(level);
}
@SuppressWarnings("deprecation")
private DataContainer<?, ?> createBoundedDataContainer() {
ClusteringConfiguration clustering = this.configuration.clustering();
boolean segmented = clustering.cacheMode().needsStateTransfer();
int level = this.configuration.locking().concurrencyLevel();
MemoryConfiguration memory = this.configuration.memory();
boolean offHeap = memory.isOffHeap();
long maxEntries = memory.maxCount();
long maxBytes = memory.maxSizeBytes();
org.infinispan.eviction.EvictionType type = memory.evictionType();
DataContainerConfiguration config = this.configuration.module(DataContainerConfiguration.class);
Predicate<?> evictable = (config != null) ? config.evictable() : DataContainerConfiguration.EVICTABLE_PREDICATE.getDefaultValue();
if (segmented) {
int segments = clustering.hash().numSegments();
if (offHeap) {
return new SegmentedBoundedOffHeapDataContainer(segments, maxEntries, type);
}
return (maxEntries > 0) ? new BoundedSegmentedDataContainer<>(segments, maxEntries, new EvictableEntrySizeCalculator<>(evictable)) : new BoundedSegmentedDataContainer<>(segments, maxBytes, type);
}
if (offHeap) {
return new BoundedOffHeapDataContainer(maxEntries, type);
}
return (maxEntries > 0) ? new EvictableDataContainer<>(maxEntries, new EvictableEntrySizeCalculator<>(evictable)) : DefaultDataContainer.boundedDataContainer(level, maxBytes, type);
}
private OffHeapConcurrentMap createAndStartOffHeapConcurrentMap() {
OffHeapEntryFactory entryFactory = this.basicComponentRegistry.getComponent(OffHeapEntryFactory.class).wired();
OffHeapMemoryAllocator memoryAllocator = this.basicComponentRegistry.getComponent(OffHeapMemoryAllocator.class).wired();
return new OffHeapConcurrentMap(memoryAllocator, entryFactory, null);
}
public static class EvictableDataContainer<K, V> extends DefaultDataContainer<K, V> {
EvictableDataContainer(long size, EntrySizeCalculator<? super K, ? super InternalCacheEntry<K, V>> calculator) {
super(size, calculator);
}
}
private static class EvictableEntrySizeCalculator<K, V> implements EntrySizeCalculator<K, InternalCacheEntry<K, V>> {
private final Predicate<K> evictable;
EvictableEntrySizeCalculator(Predicate<K> evictable) {
this.evictable = evictable;
}
@Override
public long calculateSize(K key, InternalCacheEntry<K, V> value) {
return this.evictable.test(key) ? 1 : 0;
}
}
}
| 7,128
| 49.204225
| 207
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/container/DataContainerConfigurationBuilder.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.container;
import static org.wildfly.clustering.infinispan.container.DataContainerConfiguration.*;
import java.util.function.Predicate;
import org.infinispan.commons.configuration.Builder;
import org.infinispan.commons.configuration.attributes.AttributeSet;
import org.infinispan.configuration.cache.ConfigurationBuilder;
/**
* @author Paul Ferraro
*/
public class DataContainerConfigurationBuilder implements Builder<DataContainerConfiguration> {
private final AttributeSet attributes;
public DataContainerConfigurationBuilder(ConfigurationBuilder builder) {
this.attributes = new AttributeSet(DataContainerConfiguration.class, EVICTABLE_PREDICATE);
}
public <K> DataContainerConfigurationBuilder evictable(Predicate<K> evictable) {
this.attributes.attribute(EVICTABLE_PREDICATE).set((evictable != null) ? evictable : EVICTABLE_PREDICATE.getDefaultValue());
return this;
}
@Override
public void validate() {
}
@Override
public DataContainerConfiguration create() {
return new DataContainerConfiguration(this.attributes);
}
@Override
public DataContainerConfigurationBuilder read(DataContainerConfiguration template) {
return this.evictable(template.evictable());
}
@Override
public AttributeSet attributes() {
return this.attributes;
}
}
| 2,434
| 34.808824
| 132
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/ConsistentHashLocality.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.infinispan.distribution;
import org.infinispan.Cache;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.remoting.transport.Address;
/**
* {@link Locality} implementation based on a {@link ConsistentHash}.
* @author Paul Ferraro
*/
public class ConsistentHashLocality implements Locality {
private final KeyDistribution distribution;
private final Address localAddress;
@SuppressWarnings("deprecation")
public ConsistentHashLocality(Cache<?, ?> cache, ConsistentHash hash) {
this(cache.getAdvancedCache().getComponentRegistry().getLocalComponent(KeyPartitioner.class), hash, cache.getAdvancedCache().getDistributionManager().getCacheTopology().getLocalAddress());
}
public ConsistentHashLocality(KeyPartitioner partitioner, ConsistentHash hash, Address localAddress) {
this(new ConsistentHashKeyDistribution(partitioner, hash), localAddress);
}
ConsistentHashLocality(KeyDistribution distribution, Address localAddress) {
this.distribution = distribution;
this.localAddress = localAddress;
}
@Override
public boolean isLocal(Object key) {
Address primary = this.distribution.getPrimaryOwner(key);
return this.localAddress.equals(primary);
}
}
| 2,382
| 40.086207
| 196
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/CacheLocality.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.infinispan.distribution;
import org.infinispan.Cache;
import org.infinispan.distribution.DistributionManager;
/**
* A {@link Locality} implementation that delegates to either a {@link ConsistentHashLocality} or {@link SimpleLocality} depending on the cache mode.
* Instances of this object should not be retained for longer than a single unit of work, since this object holds a final reference to the current ConsistentHash, which will become stale on topology change.
* @author Paul Ferraro
*/
public class CacheLocality implements Locality {
private final Locality locality;
public CacheLocality(Cache<?, ?> cache) {
DistributionManager dist = cache.getAdvancedCache().getDistributionManager();
this.locality = (dist != null) ? new ConsistentHashLocality(cache, dist.getCacheTopology().getWriteConsistentHash()) : new SimpleLocality(true);
}
@Override
public boolean isLocal(Object key) {
return this.locality.isLocal(key);
}
}
| 2,042
| 42.468085
| 206
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/LocalKeyDistribution.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.infinispan.distribution;
import java.util.Collections;
import java.util.List;
import org.infinispan.remoting.transport.Address;
import org.infinispan.remoting.transport.LocalModeAddress;
/**
* Key distribution implementation for a local cache.
* @author Paul Ferraro
*/
public enum LocalKeyDistribution implements KeyDistribution {
INSTANCE;
@Override
public Address getPrimaryOwner(Object key) {
return LocalModeAddress.INSTANCE;
}
@Override
public List<Address> getOwners(Object key) {
return Collections.singletonList(LocalModeAddress.INSTANCE);
}
}
| 1,660
| 33.604167
| 70
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/KeyDistribution.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.infinispan.distribution;
import java.util.List;
import org.infinispan.remoting.transport.Address;
/**
* Provides key distribution functions.
* @author Paul Ferraro
*/
public interface KeyDistribution {
/**
* Returns the primary owner of the specified key.
* @param key a cache key
* @return the address of the primary owner
*/
Address getPrimaryOwner(Object key);
/**
* Returns the owners of the specified key.
* @param key a cache key
* @return a list of addresses for each owner
*/
List<Address> getOwners(Object key);
}
| 1,642
| 32.530612
| 70
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/KeyGroup.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.distribution;
/**
* Implemented by keys that should be logical grouped by a common identifier.
* Keys with the same group identifier will be stored within the same segment.
* This is analogous to Infinispan's {@link org.infinispan.distribution.group.Group} logic, but avoids a potentially unnecessary String conversion.
* @author Paul Ferraro
*/
public interface KeyGroup<I> {
/**
* The identifier of this group of keys.
* @return an group identifier
*/
I getId();
}
| 1,562
| 40.131579
| 147
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/CacheKeyDistribution.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.infinispan.distribution;
import java.util.List;
import org.infinispan.Cache;
import org.infinispan.distribution.DistributionManager;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.remoting.transport.Address;
/**
* Key distribution appropriate for any cache mode.
* @author Paul Ferraro
*/
public class CacheKeyDistribution implements KeyDistribution {
private final DistributionManager distribution;
private final KeyPartitioner partitioner;
@SuppressWarnings("deprecation")
public CacheKeyDistribution(Cache<?, ?> cache) {
this.distribution = cache.getAdvancedCache().getDistributionManager();
this.partitioner = cache.getAdvancedCache().getComponentRegistry().getLocalComponent(KeyPartitioner.class);
}
@Override
public Address getPrimaryOwner(Object key) {
return this.getCurrentKeyDistribution().getPrimaryOwner(key);
}
@Override
public List<Address> getOwners(Object key) {
return this.getCurrentKeyDistribution().getOwners(key);
}
private KeyDistribution getCurrentKeyDistribution() {
return (this.distribution != null) ? new ConsistentHashKeyDistribution(this.partitioner, this.distribution.getCacheTopology().getWriteConsistentHash()) : LocalKeyDistribution.INSTANCE;
}
}
| 2,367
| 37.819672
| 192
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/Locality.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.infinispan.distribution;
/**
* Facility for determining the primary ownership/location of a given cache key.
* @author Paul Ferraro
*/
public interface Locality {
/**
* Indicates whether the current node is the primary owner of the specified cache key.
* For local caches, this method will always return true.
* @param key a cache key
* @return true, if the current node is the primary owner of the specified cache key, false otherwise
*/
boolean isLocal(Object key);
}
| 1,561
| 41.216216
| 105
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/ConsistentHashKeyDistribution.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.infinispan.distribution;
import java.util.List;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.remoting.transport.Address;
/**
* Key distribution functions for a specific {@link ConsistentHash}.
* @author Paul Ferraro
*/
public class ConsistentHashKeyDistribution implements KeyDistribution {
private final KeyPartitioner partitioner;
private final ConsistentHash hash;
public ConsistentHashKeyDistribution(KeyPartitioner partitioner, ConsistentHash hash) {
this.partitioner = partitioner;
this.hash = hash;
}
@Override
public Address getPrimaryOwner(Object key) {
int segment = this.partitioner.getSegment(key);
return this.hash.locatePrimaryOwnerForSegment(segment);
}
@Override
public List<Address> getOwners(Object key) {
int segment = this.partitioner.getSegment(key);
return this.hash.locateOwnersForSegment(segment);
}
}
| 2,064
| 35.22807
| 91
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/KeyPartitionerFactory.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.infinispan.distribution;
import org.infinispan.configuration.cache.HashConfiguration;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.distribution.ch.impl.SingleSegmentKeyPartitioner;
import org.infinispan.factories.AbstractNamedCacheComponentFactory;
import org.infinispan.factories.AutoInstantiableFactory;
import org.infinispan.factories.annotations.DefaultFactoryFor;
/**
* Custom key partitioner factory that uses the same key partitioner for all clustered caches, including non-tx invalidation caches.
* @author Paul Ferraro
*/
@DefaultFactoryFor(classes = KeyPartitioner.class)
public class KeyPartitionerFactory extends AbstractNamedCacheComponentFactory implements AutoInstantiableFactory {
@Override
public Object construct(String componentName) {
if (!this.configuration.clustering().cacheMode().isClustered() && !this.configuration.persistence().usingSegmentedStore()) {
return SingleSegmentKeyPartitioner.getInstance();
}
HashConfiguration hashConfiguration = this.configuration.clustering().hash();
KeyPartitioner partitioner = hashConfiguration.keyPartitioner();
partitioner.init(hashConfiguration);
this.basicComponentRegistry.wireDependencies(partitioner, false);
return new KeyPartitioner() {
@Override
public int getSegment(Object key) {
return partitioner.getSegment((key instanceof KeyGroup) ? ((KeyGroup<?>) key).getId() : key);
}
};
}
}
| 2,591
| 43.689655
| 132
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/distribution/SimpleLocality.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.infinispan.distribution;
/**
* Simple {@link Locality} implementation that uses a static value.
* @author Paul Ferraro
*/
public class SimpleLocality implements Locality {
private final boolean local;
public SimpleLocality(boolean local) {
this.local = local;
}
@Override
public boolean isLocal(Object key) {
return this.local;
}
}
| 1,434
| 33.166667
| 70
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/affinity/impl/KeyRegistry.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.infinispan.affinity.impl;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import org.infinispan.remoting.transport.Address;
/**
* A registry of keys with affinity to a given address.
* @author Paul Ferraro
*/
public interface KeyRegistry<K> {
/**
* Returns the addresses for which pre-generated keys are available.
* @return a set of cluster members
*/
Set<Address> getAddresses();
/**
* Returns a queue of pre-generated keys with affinity for the specified address.
* @param address the address of a cluster member.
* @return a queue of pre-generated keys
*/
BlockingQueue<K> getKeys(Address address);
}
| 1,736
| 34.44898
| 85
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/affinity/impl/SimpleKeyAffinityService.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.infinispan.affinity.impl;
import org.infinispan.affinity.KeyAffinityService;
import org.infinispan.affinity.KeyGenerator;
import org.infinispan.remoting.transport.Address;
/**
* Simple {@link KeyAffinityService} implementation for use when co-location is not a requirement.
* @author Paul Ferraro
*/
public class SimpleKeyAffinityService<K> implements KeyAffinityService<K> {
private final KeyGenerator<K> generator;
private volatile boolean started = false;
SimpleKeyAffinityService(KeyGenerator<K> generator) {
this.generator = generator;
}
@Override
public void start() {
this.started = true;
}
@Override
public void stop() {
this.started = false;
}
@Override
public K getKeyForAddress(Address address) {
return this.generator.getKey();
}
@Override
public K getCollocatedKey(K otherKey) {
return this.generator.getKey();
}
@Override
public boolean isStarted() {
return this.started;
}
}
| 2,081
| 30.074627
| 98
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/affinity/impl/DefaultKeyAffinityService.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.infinispan.affinity.impl;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.infinispan.Cache;
import org.infinispan.affinity.KeyAffinityService;
import org.infinispan.affinity.KeyGenerator;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.distribution.ch.KeyPartitioner;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.Listener.Observation;
import org.infinispan.notifications.cachelistener.annotation.TopologyChanged;
import org.infinispan.notifications.cachelistener.event.TopologyChangedEvent;
import org.infinispan.remoting.transport.Address;
import org.jboss.logging.Logger;
import org.wildfly.clustering.context.DefaultExecutorService;
import org.wildfly.clustering.context.DefaultThreadFactory;
import org.wildfly.clustering.infinispan.distribution.ConsistentHashKeyDistribution;
import org.wildfly.clustering.infinispan.distribution.KeyDistribution;
import org.wildfly.security.manager.WildFlySecurityManager;
/**
* A custom key affinity service implementation with the following distinct characteristics (as compared to {@link org.infinispan.affinity.impl.KeyAffinityServiceImpl}):
* <ul>
* <li>{@link #getKeyForAddress(Address)} will return a random key (instead of throwing an ISE) if the specified address does not own any segments.</li>
* <li>Uses a worker thread per address for which to generate keys.</li>
* <li>Minimal CPU utilization when key queues are full.</li>
* <li>Non-blocking topology change event handler.</li>
* <li>{@link #getKeyForAddress(Address)} calls will not block during topology change events.</li>
* </ul>
* @author Paul Ferraro
*/
@Listener(observation = Observation.POST)
public class DefaultKeyAffinityService<K> implements KeyAffinityService<K>, Supplier<BlockingQueue<K>> {
private static final Logger LOGGER = Logger.getLogger(DefaultKeyAffinityService.class);
private final Cache<? extends K, ?> cache;
private final KeyGenerator<? extends K> generator;
private final AtomicReference<KeyAffinityState<K>> currentState = new AtomicReference<>();
private final KeyPartitioner partitioner;
private final Predicate<Address> filter;
private volatile int queueSize = 100;
private volatile Duration timeout = Duration.ofMillis(100L);
private volatile ExecutorService executor;
private interface KeyAffinityState<K> {
KeyDistribution getDistribution();
KeyRegistry<K> getRegistry();
Iterable<Future<?>> getFutures();
}
/**
* Constructs a key affinity service that generates keys hashing to the members matching the specified filter.
* @param cache the target cache
* @param generator a key generator
*/
@SuppressWarnings("deprecation")
public DefaultKeyAffinityService(Cache<? extends K, ?> cache, KeyGenerator<? extends K> generator, Predicate<Address> filter) {
this(cache, cache.getAdvancedCache().getComponentRegistry().getLocalComponent(KeyPartitioner.class), generator, filter);
}
DefaultKeyAffinityService(Cache<? extends K, ?> cache, KeyPartitioner partitioner, KeyGenerator<? extends K> generator, Predicate<Address> filter) {
this.cache = cache;
this.partitioner = partitioner;
this.generator = generator;
this.filter = filter;
}
/**
* Overrides the maximum number of keys with affinity to a given member to pre-generate.
* @param size a queue size threshold
*/
public void setQueueSize(int size) {
this.queueSize = size;
}
/**
* Overrides the duration of time for which calls to {@link #getKeyForAddress(Address)} will wait for an available pre-generated key,
* after which a random key will be returned.
* @param timeout a queue poll timeout
*/
public void setPollTimeout(Duration timeout) {
this.timeout = timeout;
}
@Override
public BlockingQueue<K> get() {
return new ArrayBlockingQueue<>(this.queueSize);
}
@Override
public boolean isStarted() {
ExecutorService executor = this.executor;
return (executor != null) && !executor.isShutdown();
}
@Override
public void start() {
this.executor = Executors.newCachedThreadPool(new DefaultThreadFactory(this.getClass()));
this.accept(this.cache.getAdvancedCache().getDistributionManager().getCacheTopology().getWriteConsistentHash());
this.cache.addListener(this);
}
@Override
public void stop() {
this.cache.removeListener(this);
WildFlySecurityManager.doUnchecked(this.executor, DefaultExecutorService.SHUTDOWN_NOW_ACTION);
}
@Override
public K getCollocatedKey(K otherKey) {
KeyAffinityState<K> currentState = this.currentState.get();
if (currentState == null) {
// Not yet started!
throw new IllegalStateException();
}
return this.getCollocatedKey(currentState, otherKey);
}
private K getCollocatedKey(KeyAffinityState<K> state, K otherKey) {
K key = this.poll(state.getRegistry(), state.getDistribution().getPrimaryOwner(otherKey));
if (key != null) {
return key;
}
KeyAffinityState<K> currentState = this.currentState.get();
// If state is out-dated, retry
if (state != currentState) {
return this.getCollocatedKey(currentState, otherKey);
}
LOGGER.debugf("Could not obtain pre-generated key with same affinity as %s -- generating random key", otherKey);
return this.generator.getKey();
}
@Override
public K getKeyForAddress(Address address) {
if (!this.filter.test(address)) {
throw new IllegalArgumentException(address.toString());
}
KeyAffinityState<K> currentState = this.currentState.get();
if (currentState == null) {
// Not yet started!
throw new IllegalStateException();
}
return this.getKeyForAddress(currentState, address);
}
private K getKeyForAddress(KeyAffinityState<K> state, Address address) {
K key = this.poll(state.getRegistry(), address);
if (key != null) {
return key;
}
KeyAffinityState<K> currentState = this.currentState.get();
// If state is out-dated, retry
if (state != currentState) {
return this.getKeyForAddress(currentState, address);
}
LOGGER.debugf("Could not obtain pre-generated key with affinity for %s -- generating random key", address);
return this.generator.getKey();
}
private K poll(KeyRegistry<K> registry, Address address) {
BlockingQueue<K> keys = registry.getKeys(address);
if (keys != null) {
Duration timeout = this.timeout;
long nanos = (timeout.getSeconds() == 0) ? timeout.getNano() : timeout.toNanos();
try {
return keys.poll(nanos, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
return null;
}
@TopologyChanged
public CompletionStage<Void> topologyChanged(TopologyChangedEvent<?, ?> event) {
if (!this.getSegments(event.getWriteConsistentHashAtStart()).equals(this.getSegments(event.getWriteConsistentHashAtEnd()))) {
LOGGER.debugf("Restarting key generation based on new consistent hash for topology %d", event.getNewTopologyId());
this.accept(event.getWriteConsistentHashAtEnd());
}
return CompletableFuture.completedStage(null);
}
private Map<Address, Set<Integer>> getSegments(ConsistentHash hash) {
Map<Address, Set<Integer>> segments = new TreeMap<>();
for (Address address : hash.getMembers()) {
if (this.filter.test(address)) {
segments.put(address, hash.getPrimarySegmentsForOwner(address));
}
}
return segments;
}
private void accept(ConsistentHash hash) {
KeyDistribution distribution = new ConsistentHashKeyDistribution(this.partitioner, hash);
KeyRegistry<K> registry = new ConsistentHashKeyRegistry<>(hash, this.filter, this);
Set<Address> addresses = registry.getAddresses();
List<Future<?>> futures = !addresses.isEmpty() ? new ArrayList<>(addresses.size()) : Collections.emptyList();
try {
for (Address address : addresses) {
BlockingQueue<K> keys = registry.getKeys(address);
futures.add(this.executor.submit(new GenerateKeysTask<>(this.generator, distribution, address, keys)));
}
KeyAffinityState<K> previousState = this.currentState.getAndSet(new KeyAffinityState<K>() {
@Override
public KeyDistribution getDistribution() {
return distribution;
}
@Override
public KeyRegistry<K> getRegistry() {
return registry;
}
@Override
public Iterable<Future<?>> getFutures() {
return futures;
}
});
if (previousState != null) {
for (Future<?> future : previousState.getFutures()) {
future.cancel(true);
}
}
} catch (RejectedExecutionException e) {
// Executor was shutdown. Cancel any tasks that were already submitted
for (Future<?> future : futures) {
future.cancel(true);
}
}
}
private static class GenerateKeysTask<K> implements Runnable {
private final KeyGenerator<? extends K> generator;
private final KeyDistribution distribution;
private final Address address;
private final BlockingQueue<K> keys;
GenerateKeysTask(KeyGenerator<? extends K> generator, KeyDistribution distribution, Address address, BlockingQueue<K> keys) {
this.generator = generator;
this.distribution = distribution;
this.address = address;
this.keys = keys;
}
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
K key = this.generator.getKey();
if (this.distribution.getPrimaryOwner(key).equals(this.address)) {
try {
this.keys.put(key);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
}
}
| 12,425
| 40.009901
| 169
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/affinity/impl/ConsistentHashKeyRegistry.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.infinispan.affinity.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.infinispan.distribution.ch.ConsistentHash;
import org.infinispan.remoting.transport.Address;
/**
* Registry of queues of keys with affinity to the members of a consistent hash.
* @author Paul Ferraro
*/
public class ConsistentHashKeyRegistry<K> implements KeyRegistry<K> {
private final Map<Address, BlockingQueue<K>> keys;
public ConsistentHashKeyRegistry(ConsistentHash hash, Predicate<Address> filter, Supplier<BlockingQueue<K>> queueFactory) {
List<Address> members = new ArrayList<>(hash.getMembers().size());
for (Address address : hash.getMembers()) {
// Only create queues for members that own segments
if (filter.test(address) && !hash.getPrimarySegmentsForOwner(address).isEmpty()) {
members.add(address);
}
}
if (members.size() == 0) {
this.keys = Collections.emptyMap();
} else if (members.size() == 1) {
Address member = members.get(0);
this.keys = Collections.singletonMap(member, queueFactory.get());
} else {
this.keys = new HashMap<>();
for (Address member : members) {
this.keys.put(member, queueFactory.get());
}
}
}
@Override
public Set<Address> getAddresses() {
return this.keys.keySet();
}
@Override
public BlockingQueue<K> getKeys(Address address) {
return this.keys.get(address);
}
}
| 2,825
| 35.701299
| 127
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/affinity/impl/DefaultKeyAffinityServiceFactory.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.infinispan.affinity.impl;
import java.util.function.Predicate;
import org.infinispan.Cache;
import org.infinispan.affinity.KeyAffinityService;
import org.infinispan.affinity.KeyGenerator;
import org.infinispan.remoting.transport.Address;
import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory;
/**
* Factory for a {@link KeyAffinityService} whose implementation varies depending on cache mode.
* @author Paul Ferraro
*/
public class DefaultKeyAffinityServiceFactory implements KeyAffinityServiceFactory {
@Override
public <K> KeyAffinityService<K> createService(Cache<? extends K, ?> cache, KeyGenerator<K> generator, Predicate<Address> filter) {
return cache.getCacheConfiguration().clustering().cacheMode().isClustered() ? new DefaultKeyAffinityService<>(cache, generator, filter) : new SimpleKeyAffinityService<>(generator);
}
}
| 1,935
| 43
| 188
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/lifecycle/WildFlyInfinispanModuleLifecycle.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2019, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.lifecycle;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.PersistenceConfiguration;
import org.infinispan.configuration.cache.StoreConfiguration;
import org.infinispan.eviction.impl.PassivationManager;
import org.infinispan.factories.ComponentRegistry;
import org.infinispan.factories.annotations.InfinispanModule;
import org.infinispan.lifecycle.ModuleLifecycle;
import org.infinispan.persistence.manager.PersistenceManager;
/**
* @author Paul Ferraro
*/
@InfinispanModule(name = "wildfly", requiredModules = "core")
public class WildFlyInfinispanModuleLifecycle implements ModuleLifecycle {
@Override
public void cacheStarting(ComponentRegistry registry, Configuration configuration, String cacheName) {
PersistenceConfiguration persistence = configuration.persistence();
// If we purge passivation stores on startup, passivating entries on stop is a waste of time
if (persistence.usingStores() && persistence.passivation()) {
PassivationManager passivation = registry.getLocalComponent(PassivationManager.class);
passivation.skipPassivationOnStop(persistence.stores().stream().allMatch(StoreConfiguration::purgeOnStartup));
}
registry.getLocalComponent(PersistenceManager.class).setClearOnStop(false);
}
}
| 2,408
| 46.235294
| 122
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/persistence/DynamicKeyFormatMapper.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.infinispan.persistence;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;
import java.util.UUID;
import java.util.function.Function;
import org.wildfly.clustering.marshalling.spi.Formatter;
import org.wildfly.clustering.marshalling.spi.SimpleFormatter;
/**
* {@link org.infinispan.persistence.keymappers.TwoWayKey2StringMapper} implementation that based on a set of dynamically loaded {@link Formatter} instances.
* @author Paul Ferraro
*/
public class DynamicKeyFormatMapper extends IndexedKeyFormatMapper {
public DynamicKeyFormatMapper(ClassLoader loader) {
super(load(loader));
}
private static List<Formatter<?>> load(ClassLoader loader) {
List<Formatter<?>> keyFormats = new LinkedList<>();
for (Formatter<?> keyFormat : ServiceLoader.load(Formatter.class, loader)) {
keyFormats.add(keyFormat);
}
List<Formatter<?>> result = new ArrayList<>(keyFormats.size() + 6);
// Add key formats for common key types
result.add(new SimpleFormatter<>(String.class, Function.identity()));
result.add(new SimpleFormatter<>(Byte.class, Byte::valueOf));
result.add(new SimpleFormatter<>(Short.class, Short::valueOf));
result.add(new SimpleFormatter<>(Integer.class, Integer::valueOf));
result.add(new SimpleFormatter<>(Long.class, Long::valueOf));
result.add(new SimpleFormatter<>(UUID.class, UUID::fromString));
result.addAll(keyFormats);
return result;
}
}
| 2,615
| 39.875
| 157
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/persistence/IndexedKeyFormatMapper.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.infinispan.persistence;
import static org.wildfly.common.Assert.checkNotNullParam;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import org.infinispan.persistence.keymappers.TwoWayKey2StringMapper;
import org.wildfly.clustering.marshalling.spi.Formatter;
/**
* {@link TwoWayKey2StringMapper} implementation that maps multiple {@link Formatter} instances.
* Key is mapped to an padded hexadecimal index + the formatted key.
* @author Paul Ferraro
*/
public class IndexedKeyFormatMapper implements TwoWayKey2StringMapper {
private static final int HEX_RADIX = 16;
private final Map<Class<?>, Integer> indexes = new IdentityHashMap<>();
private final List<Formatter<Object>> keyFormats;
private final int padding;
@SuppressWarnings("unchecked")
public IndexedKeyFormatMapper(List<? extends Formatter<?>> keyFormats) {
this.keyFormats = (List<Formatter<Object>>) (List<?>) keyFormats;
for (int i = 0; i < this.keyFormats.size(); ++i) {
this.indexes.put(this.keyFormats.get(i).getTargetClass(), i);
}
// Determine number of characters to reserve for index
this.padding = (int) (Math.log((double) this.keyFormats.size() - 1) / Math.log(HEX_RADIX)) + 1;
}
@Override
public boolean isSupportedType(Class<?> keyType) {
return this.indexes.containsKey(keyType);
}
@Override
public String getStringMapping(Object key) {
checkNotNullParam("key", key);
Integer index = this.indexes.get(key.getClass());
if (index == null) {
throw new IllegalArgumentException(key.getClass().getName());
}
Formatter<Object> keyFormat = this.keyFormats.get(index);
return String.format("%0" + this.padding + "X%s", index, keyFormat.format(key));
}
@Override
public Object getKeyMapping(String value) {
int index = Integer.parseUnsignedInt(value.substring(0, this.padding), HEX_RADIX);
Formatter<Object> keyFormat = this.keyFormats.get(index);
return keyFormat.parse(value.substring(this.padding));
}
}
| 3,179
| 39.253165
| 103
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/persistence/SimpleKeyFormatMapper.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.infinispan.persistence;
import org.infinispan.persistence.keymappers.TwoWayKey2StringMapper;
import org.wildfly.clustering.marshalling.spi.Formatter;
/**
* Simple {@link TwoWayKey2StringMapper} based on a single {@link Formatter}.
* @author Paul Ferraro
*/
public class SimpleKeyFormatMapper implements TwoWayKey2StringMapper {
private final Formatter<Object> format;
@SuppressWarnings("unchecked")
public SimpleKeyFormatMapper(Formatter<?> format) {
this.format = (Formatter<Object>) format;
}
@Override
public boolean isSupportedType(Class<?> keyType) {
return this.format.getTargetClass().equals(keyType);
}
@Override
public String getStringMapping(Object key) {
return this.format.format(key);
}
@Override
public Object getKeyMapping(String value) {
return this.format.parse(value);
}
}
| 1,940
| 33.660714
| 77
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/BlockingCacheEventListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import java.util.concurrent.CompletionStage;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.infinispan.Cache;
import org.infinispan.notifications.cachelistener.event.CacheEntryEvent;
import org.infinispan.util.concurrent.BlockingManager;
/**
* Generic non-blocking event listener that delegates to a blocking event consumer.
* @author Paul Ferraro
*/
public class BlockingCacheEventListener<K, V> extends NonBlockingCacheEventListener<K, V> {
private final BlockingManager blocking;
private final String name;
public BlockingCacheEventListener(Cache<K, V> cache, Consumer<K> consumer) {
this(cache, (key, value) -> consumer.accept(key), consumer.getClass());
}
public BlockingCacheEventListener(Cache<K, V> cache, BiConsumer<K, V> consumer) {
this(cache, consumer, consumer.getClass());
}
@SuppressWarnings("deprecation")
private BlockingCacheEventListener(Cache<K, V> cache, BiConsumer<K, V> consumer, Class<?> consumerClass) {
super(consumer);
this.blocking = cache.getCacheManager().getGlobalComponentRegistry().getComponent(BlockingManager.class);
this.name = consumerClass.getName();
}
@Override
public CompletionStage<Void> apply(CacheEntryEvent<K, V> event) {
return this.blocking.runBlocking(() -> super.accept(event), this.name);
}
@Override
public void accept(CacheEntryEvent<K, V> event) {
this.blocking.asExecutor(this.name).execute(() -> super.accept(event));
}
}
| 2,619
| 38.104478
| 113
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/NonBlockingCacheEventListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import org.infinispan.notifications.cachelistener.event.CacheEntryEvent;
/**
* Generic non-blocking event listener that delegates to a non-blocking event consumer.
* @author Paul Ferraro
*/
public class NonBlockingCacheEventListener<K, V> implements Function<CacheEntryEvent<K, V>, CompletionStage<Void>>, Consumer<CacheEntryEvent<K, V>> {
private final BiConsumer<K, V> consumer;
public NonBlockingCacheEventListener(Consumer<K> consumer) {
this((key, value) -> consumer.accept(key));
}
public NonBlockingCacheEventListener(BiConsumer<K, V> consumer) {
this.consumer = consumer;
}
@Override
public CompletionStage<Void> apply(CacheEntryEvent<K, V> event) {
try {
this.accept(event);
return CompletableFuture.completedStage(null);
} catch (RuntimeException | Error e) {
return CompletableFuture.failedStage(e);
}
}
@Override
public void accept(CacheEntryEvent<K, V> event) {
this.consumer.accept(event.getKey(), event.getValue());
}
}
| 2,352
| 35.765625
| 149
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/CacheEventListenerRegistrar.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import org.infinispan.Cache;
import org.infinispan.notifications.cachelistener.filter.CacheEventFilter;
/**
* A registering cache event listener.
* @author Paul Ferraro
*/
public class CacheEventListenerRegistrar<K, V> extends EventListenerRegistrar implements CacheListenerRegistrar<K, V> {
private final Cache<K, V> cache;
private final Object listener;
public CacheEventListenerRegistrar(Cache<K, V> cache) {
super(cache);
this.cache = cache;
this.listener = this;
}
public CacheEventListenerRegistrar(Cache<K, V> cache, Object listener) {
super(cache, listener);
this.cache = cache;
this.listener = listener;
}
@Override
public ListenerRegistration register(CacheEventFilter<? super K, ? super V> filter) {
this.cache.addListener(this.listener, filter, null);
return () -> this.cache.removeListener(this.listener);
}
}
| 2,008
| 35.527273
| 119
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/KeyFilter.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.infinispan.listener;
import java.util.function.Predicate;
import org.infinispan.metadata.Metadata;
import org.infinispan.notifications.cachelistener.filter.CacheEventFilter;
import org.infinispan.notifications.cachelistener.filter.EventType;
/**
* A {@link CacheEventFilter} for filtering events based on the cache key.
* @author Paul Ferraro
*/
public class KeyFilter<K> implements CacheEventFilter<K, Object> {
private final Predicate<? super K> predicate;
public KeyFilter(Class<? super K> keyClass) {
this(keyClass::isInstance);
}
public KeyFilter(Predicate<? super K> predicate) {
this.predicate = predicate;
}
@Override
public boolean accept(K key, Object oldValue, Metadata oldMetadata, Object newValue, Metadata newMetadata, EventType eventType) {
return this.predicate.test(key);
}
}
| 1,914
| 35.826923
| 133
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/PrePassivateBlockingListener.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.infinispan.listener;
import java.util.function.BiConsumer;
import org.infinispan.Cache;
/**
* Generic non-blocking pre-passivation listener that delegates to a blocking consumer.
* @author Paul Ferraro
*/
public class PrePassivateBlockingListener<K, V> extends CacheEventListenerRegistrar<K, V> {
public PrePassivateBlockingListener(Cache<K, V> cache, BiConsumer<K, V> consumer) {
super(cache, new PrePassivateListener<>(new BlockingCacheEventListener<>(cache, consumer)));
}
}
| 1,556
| 38.923077
| 100
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/EventListenerRegistrar.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import org.infinispan.notifications.Listenable;
/**
* A registering Infinispan listener.
* @author Paul Ferraro
*/
public class EventListenerRegistrar implements ListenerRegistrar {
private final Listenable listenable;
private final Object listener;
public EventListenerRegistrar(Listenable listenable) {
this.listenable = listenable;
this.listener = this;
}
public EventListenerRegistrar(Listenable listenable, Object listener) {
this.listenable = listenable;
this.listener = listener;
}
@Override
public ListenerRegistration register() {
this.listenable.addListener(this.listener);
return () -> this.listenable.removeListener(this.listener);
}
}
| 1,817
| 33.961538
| 75
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/CacheListenerRegistrar.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import java.util.function.Predicate;
import org.infinispan.notifications.cachelistener.filter.CacheEventFilter;
/**
* A registering cache listener.
* @author Paul Ferraro
*/
public interface CacheListenerRegistrar<K, V> extends ListenerRegistrar {
/**
* Registers this listener events for cache entries whose key is an instance of the specified class.
* @param keyClass a key class
* @return a listener registration
*/
default ListenerRegistration register(Class<? super K> keyClass) {
return this.register(new KeyFilter<>(keyClass));
}
/**
* Registers this listener events for cache entries whose key matches the specified predicate.
* @param keyClass a key class
* @return a listener registration
*/
default ListenerRegistration register(Predicate<? super K> keyPredicate) {
return this.register(new KeyFilter<>(keyPredicate));
}
/**
* Registers this listener events for cache entries that match the specified filter.
* @param filter a cache event filter
* @return a listener registration
*/
ListenerRegistration register(CacheEventFilter<? super K, ? super V> filter);
}
| 2,267
| 36.8
| 104
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/PostActivateBlockingListener.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.infinispan.listener;
import java.util.concurrent.CompletionStage;
import java.util.function.BiConsumer;
import java.util.function.Function;
import org.infinispan.Cache;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryActivated;
import org.infinispan.notifications.cachelistener.event.CacheEntryActivatedEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryEvent;
/**
* Generic non-blocking post-activation listener that delegates to a blocking consumer.
* @author Paul Ferraro
*/
@Listener(observation = Listener.Observation.POST)
public class PostActivateBlockingListener<K, V> extends CacheEventListenerRegistrar<K, V> {
private final Function<CacheEntryEvent<K, V>, CompletionStage<Void>> listener;
public PostActivateBlockingListener(Cache<K, V> cache, BiConsumer<K, V> consumer) {
super(cache);
this.listener = new BlockingCacheEventListener<>(cache, consumer);
}
@CacheEntryActivated
public CompletionStage<Void> postActivate(CacheEntryActivatedEvent<K, V> event) {
return this.listener.apply(event);
}
}
| 2,212
| 39.981481
| 91
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/ListenerRegistrar.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
/**
* A registering Infinispan listener.
* @author Paul Ferraro
*/
public interface ListenerRegistrar {
/**
* Registers this listener for a Infinispan events.
* @return a listener registration
*/
ListenerRegistration register();
}
| 1,335
| 35.108108
| 70
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/PrePassivateListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import java.util.concurrent.CompletionStage;
import java.util.function.Function;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryPassivated;
import org.infinispan.notifications.cachelistener.event.CacheEntryEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryPassivatedEvent;
/**
* Generic non-blocking pre-passivation listener that delegates to a generic cache event listener.
* @author Paul Ferraro
*/
@Listener(observation = Listener.Observation.PRE)
public class PrePassivateListener<K, V> {
private final Function<CacheEntryEvent<K, V>, CompletionStage<Void>> listener;
public PrePassivateListener(Function<CacheEntryEvent<K, V>, CompletionStage<Void>> listener) {
this.listener = listener;
}
@CacheEntryPassivated
public CompletionStage<Void> prePassivate(CacheEntryPassivatedEvent<K, V> event) {
return this.listener.apply(event);
}
}
| 2,057
| 39.352941
| 98
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/ListenerRegistration.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
/**
* An Infinispan listener registration that unregisters on {@link #close()}.
* @author Paul Ferraro
*/
public interface ListenerRegistration extends AutoCloseable {
@Override
void close();
}
| 1,282
| 37.878788
| 76
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/PrePassivateNonBlockingListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import java.util.function.BiConsumer;
import org.infinispan.Cache;
/**
* Generic non-blocking pre-passivation listener that delegates to a non-blocking consumer.
* @author Paul Ferraro
*/
public class PrePassivateNonBlockingListener<K, V> extends CacheEventListenerRegistrar<K, V> {
public PrePassivateNonBlockingListener(Cache<K, V> cache, BiConsumer<K, V> consumer) {
super(cache, new PrePassivateListener<>(new NonBlockingCacheEventListener<>(consumer)));
}
}
| 1,562
| 39.076923
| 96
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/listener/PostPassivateBlockingListener.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.listener;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Consumer;
import org.infinispan.Cache;
import org.infinispan.notifications.Listener;
import org.infinispan.notifications.cachelistener.annotation.CacheEntryPassivated;
import org.infinispan.notifications.cachelistener.event.CacheEntryEvent;
import org.infinispan.notifications.cachelistener.event.CacheEntryPassivatedEvent;
/**
* Generic non-blocking post-passivation listener that delegates to a blocking consumer.
* @author Paul Ferraro
*/
@Listener(observation = Listener.Observation.POST)
public class PostPassivateBlockingListener<K, V> extends CacheEventListenerRegistrar<K, V> {
private Consumer<CacheEntryEvent<K, V>> listener;
public PostPassivateBlockingListener(Cache<K, V> cache, Consumer<K> listener) {
super(cache);
this.listener = new BlockingCacheEventListener<>(cache, listener);
}
@CacheEntryPassivated
public CompletionStage<Void> postPassivate(CacheEntryPassivatedEvent<K, V> event) {
this.listener.accept(event);
return CompletableFuture.completedStage(null);
}
}
| 2,244
| 39.818182
| 92
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/marshall/DefaultEncoderRegistry.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.marshall;
import static org.infinispan.util.logging.Log.CONTAINER;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.dataconversion.Transcoder;
import org.infinispan.commons.dataconversion.Wrapper;
import org.infinispan.commons.dataconversion.WrapperIds;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
/**
* Customer {@link EncoderRegistry} that supports transcoder removal.
* @author Paul Ferraro
*/
@Scope(Scopes.GLOBAL)
public class DefaultEncoderRegistry implements EncoderRegistry {
@SuppressWarnings("deprecation")
private final Map<Short, org.infinispan.commons.dataconversion.Encoder> encoders = new ConcurrentHashMap<>();
private final Map<Byte, Wrapper> wrappers = new ConcurrentHashMap<>();
private final List<Transcoder> transcoders = Collections.synchronizedList(new ArrayList<>());
private final Map<MediaType, Map<MediaType, Transcoder>> transcoderCache = new ConcurrentHashMap<>();
@Override
public void registerTranscoder(Transcoder transcoder) {
this.transcoders.add(transcoder);
}
@Override
public Transcoder getTranscoder(MediaType fromType, MediaType toType) {
Transcoder transcoder = this.findTranscoder(fromType, toType);
if (transcoder == null) {
throw CONTAINER.cannotFindTranscoder(fromType, toType);
}
return transcoder;
}
@Override
public <T extends Transcoder> T getTranscoder(Class<T> targetClass) {
return targetClass.cast(this.transcoders.stream().filter(p -> p.getClass().equals(targetClass)).findAny().orElse(null));
}
@Override
public boolean isConversionSupported(MediaType fromType, MediaType toType) {
return fromType.match(toType) || this.findTranscoder(fromType, toType) != null;
}
@Override
public Object convert(Object object, MediaType fromType, MediaType toType) {
if (object == null) return null;
return this.getTranscoder(fromType, toType).transcode(object, fromType, toType);
}
@Override
public void unregisterTranscoder(MediaType type) {
synchronized (this.transcoders) {
Iterator<Transcoder> transcoders = this.transcoders.iterator();
while (transcoders.hasNext()) {
if (transcoders.next().getSupportedMediaTypes().contains(type)) {
transcoders.remove();
}
}
}
this.transcoderCache.remove(type);
for (Map<MediaType, Transcoder> map : this.transcoderCache.values()) {
map.remove(type);
}
}
private Transcoder findTranscoder(MediaType fromType, MediaType toType) {
return this.transcoderCache.computeIfAbsent(fromType, mt -> new ConcurrentHashMap<>(4)).computeIfAbsent(toType, mt -> this.transcoders.stream().filter(t -> t.supportsConversion(fromType, toType)).findFirst().orElse(null));
}
@Deprecated
@Override
public org.infinispan.commons.dataconversion.Encoder getEncoder(Class<? extends org.infinispan.commons.dataconversion.Encoder> encoderClass, short encoderId) {
if (encoderId != org.infinispan.commons.dataconversion.EncoderIds.NO_ENCODER) {
org.infinispan.commons.dataconversion.Encoder encoder = this.encoders.get(encoderId);
if (encoder == null) {
throw CONTAINER.encoderIdNotFound(encoderId);
}
return encoder;
}
org.infinispan.commons.dataconversion.Encoder encoder = this.encoders.values().stream().filter(e -> e.getClass().equals(encoderClass)).findFirst().orElse(null);
if (encoder == null) {
throw CONTAINER.encoderClassNotFound(encoderClass);
}
return encoder;
}
@Deprecated
@Override
public boolean isRegistered(Class<? extends org.infinispan.commons.dataconversion.Encoder> encoderClass) {
return this.encoders.values().stream().anyMatch(e -> e.getClass().equals(encoderClass));
}
@Deprecated
@Override
public Wrapper getWrapper(Class<? extends Wrapper> wrapperClass, byte wrapperId) {
if (wrapperClass == null && wrapperId == WrapperIds.NO_WRAPPER) {
return null;
}
if (wrapperId != WrapperIds.NO_WRAPPER) {
Wrapper wrapper = this.wrappers.get(wrapperId);
if (wrapper == null) {
throw CONTAINER.wrapperIdNotFound(wrapperId);
}
return wrapper;
}
Wrapper wrapper = this.wrappers.values().stream().filter(e -> e.getClass().equals(wrapperClass)).findAny().orElse(null);
if (wrapper == null) {
throw CONTAINER.wrapperClassNotFound(wrapperClass);
}
return wrapper;
}
@Deprecated
@Override
public void registerEncoder(org.infinispan.commons.dataconversion.Encoder encoder) {
short id = encoder.id();
if (this.encoders.putIfAbsent(id, encoder) != null) {
throw CONTAINER.duplicateIdEncoder(id);
}
}
@Deprecated
@Override
public void registerWrapper(Wrapper wrapper) {
byte id = wrapper.id();
if (this.wrappers.putIfAbsent(id, wrapper) != null) {
throw CONTAINER.duplicateIdWrapper(id);
}
}
}
| 6,566
| 39.042683
| 230
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/marshall/InfinispanProtoStreamMarshaller.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.infinispan.marshall;
import java.util.function.UnaryOperator;
import org.wildfly.clustering.infinispan.marshalling.protostream.ProtoStreamMarshaller;
import org.wildfly.clustering.infinispan.metadata.MetadataSerializationContextInitializer;
import org.wildfly.clustering.marshalling.protostream.ClassLoaderMarshaller;
import org.wildfly.clustering.marshalling.protostream.SerializationContextBuilder;
/**
* @author Paul Ferraro
*/
public class InfinispanProtoStreamMarshaller extends ProtoStreamMarshaller {
public InfinispanProtoStreamMarshaller(ClassLoaderMarshaller loaderMarshaller, UnaryOperator<SerializationContextBuilder> operator) {
super(loaderMarshaller, new UnaryOperator<SerializationContextBuilder>() {
@Override
public SerializationContextBuilder apply(SerializationContextBuilder builder) {
return operator.apply(builder.register(new MetadataSerializationContextInitializer()));
}
});
}
}
| 2,042
| 43.413043
| 137
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/marshall/EncoderRegistryFactory.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.marshall;
import org.infinispan.commons.dataconversion.ByteArrayWrapper;
import org.infinispan.commons.dataconversion.DefaultTranscoder;
import org.infinispan.commons.dataconversion.IdentityWrapper;
import org.infinispan.commons.dataconversion.TranscoderMarshallerAdapter;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.encoding.ProtostreamTranscoder;
import org.infinispan.factories.AbstractComponentFactory;
import org.infinispan.factories.AutoInstantiableFactory;
import org.infinispan.factories.KnownComponentNames;
import org.infinispan.factories.annotations.ComponentName;
import org.infinispan.factories.annotations.DefaultFactoryFor;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.impl.ComponentRef;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.marshall.protostream.impl.SerializationContextRegistry;
/**
* Overrides Infinispan's default encoder registry.
* @author Paul Ferraro
*/
@DefaultFactoryFor(classes = { org.infinispan.marshall.core.EncoderRegistry.class })
public class EncoderRegistryFactory extends AbstractComponentFactory implements AutoInstantiableFactory {
// Must not start the global marshaller or it will be too late for modules to register their externalizers
@Inject @ComponentName(KnownComponentNames.INTERNAL_MARSHALLER)
ComponentRef<Marshaller> internalMarshaller;
@Inject @ComponentName(KnownComponentNames.USER_MARSHALLER)
Marshaller marshaller;
@Inject EmbeddedCacheManager manager;
@Inject SerializationContextRegistry ctxRegistry;
@SuppressWarnings("deprecation")
@Override
public Object construct(String componentName) {
ClassLoader classLoader = this.globalConfiguration.classLoader();
EncoderRegistry encoderRegistry = new DefaultEncoderRegistry();
encoderRegistry.registerEncoder(org.infinispan.commons.dataconversion.IdentityEncoder.INSTANCE);
encoderRegistry.registerEncoder(org.infinispan.commons.dataconversion.UTF8Encoder.INSTANCE);
encoderRegistry.registerEncoder(new org.infinispan.commons.dataconversion.GlobalMarshallerEncoder(this.internalMarshaller.wired()));
// Default and binary transcoder use the user marshaller to convert data to/from a byte array
encoderRegistry.registerTranscoder(new DefaultTranscoder(this.marshaller));
// Handle application/unknown
encoderRegistry.registerTranscoder(new org.infinispan.commons.dataconversion.BinaryTranscoder(this.marshaller));
// Core transcoders are always available
encoderRegistry.registerTranscoder(new ProtostreamTranscoder(this.ctxRegistry, classLoader));
// Wraps the GlobalMarshaller so that it can be used as a transcoder
// Keeps application/x-infinispan-marshalling available for backwards compatibility
encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(this.internalMarshaller.wired()));
// Make the user marshaller's media type available as well
encoderRegistry.registerTranscoder(new TranscoderMarshallerAdapter(this.marshaller));
encoderRegistry.registerWrapper(ByteArrayWrapper.INSTANCE);
encoderRegistry.registerWrapper(IdentityWrapper.INSTANCE);
return encoderRegistry;
}
}
| 4,374
| 49.872093
| 140
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/marshall/EncoderRegistry.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2022, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.wildfly.clustering.infinispan.marshall;
import org.infinispan.commons.dataconversion.MediaType;
/**
* Extends Infinispan's {@link EncoderRegistry} adding the ability to unregister transcoders.
* @author Paul Ferraro
*/
public interface EncoderRegistry extends org.infinispan.marshall.core.EncoderRegistry {
void unregisterTranscoder(MediaType type);
}
| 1,398
| 38.971429
| 93
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/marshall/PersistenceMarshaller.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.infinispan.marshall;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.infinispan.commons.dataconversion.MediaType;
import org.infinispan.commons.marshall.Marshaller;
import org.infinispan.commons.marshall.StreamAwareMarshaller;
import org.infinispan.factories.GlobalComponentRegistry;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Start;
import org.infinispan.factories.scopes.Scope;
import org.infinispan.factories.scopes.Scopes;
import org.infinispan.marshall.protostream.impl.SerializationContextRegistry;
import org.infinispan.marshall.protostream.impl.SerializationContextRegistry.MarshallerType;
import org.infinispan.protostream.SerializationContextInitializer;
import org.wildfly.clustering.infinispan.marshalling.AbstractMarshaller;
/**
* @author Paul Ferraro
*/
@Scope(Scopes.GLOBAL)
public class PersistenceMarshaller extends AbstractMarshaller implements org.infinispan.marshall.persistence.PersistenceMarshaller {
@Inject GlobalComponentRegistry registry;
@Inject SerializationContextRegistry contextRegistry;
private StreamAwareMarshaller streamAwareUserMarshaller;
private Marshaller userMarshaller;
@Start
@Override
public void start() {
this.userMarshaller = this.registry.getGlobalConfiguration().serialization().marshaller();
this.streamAwareUserMarshaller = (StreamAwareMarshaller) this.userMarshaller;
}
@Override
public boolean isMarshallable(Object object){
return this.streamAwareUserMarshaller.isMarshallable(object);
}
@Override
public MediaType mediaType() {
return this.userMarshaller.mediaType();
}
@Override
public void writeObject(Object object, OutputStream output) throws IOException {
this.streamAwareUserMarshaller.writeObject(object, output);
}
@Override
public Object readObject(InputStream input) throws ClassNotFoundException, IOException {
return this.streamAwareUserMarshaller.readObject(input);
}
@Override
public void register(SerializationContextInitializer initializer) {
this.contextRegistry.addContextInitializer(MarshallerType.PERSISTENCE, initializer);
}
@Override
public Marshaller getUserMarshaller() {
return this.userMarshaller;
}
}
| 3,420
| 36.593407
| 132
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/marshall/InfinispanMarshallerFactory.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.infinispan.marshall;
import java.util.List;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import org.infinispan.commons.marshall.Marshaller;
import org.jboss.modules.Module;
import org.jboss.modules.ModuleLoader;
import org.wildfly.clustering.infinispan.marshalling.MarshallerFactory;
import org.wildfly.clustering.marshalling.protostream.ModuleClassLoaderMarshaller;
import org.wildfly.clustering.marshalling.protostream.SerializationContextBuilder;
/**
* @author Paul Ferraro
*/
public enum InfinispanMarshallerFactory implements BiFunction<ModuleLoader, List<Module>, Marshaller> {
LEGACY() {
private final Set<String> protoStreamModules = Set.of("org.wildfly.clustering.server", "org.wildfly.clustering.ejb.infinispan", "org.wildfly.clustering.web.infinispan");
private final Predicate<String> protoStreamPredicate = this.protoStreamModules::contains;
@Override
public Marshaller apply(ModuleLoader moduleLoader, List<Module> modules) {
// Choose marshaller based on the associated modules
return (modules.stream().map(Module::getName).anyMatch(this.protoStreamPredicate) ? PROTOSTREAM : JBOSS).apply(moduleLoader, modules);
}
},
JBOSS() {
@Override
public Marshaller apply(ModuleLoader moduleLoader, List<Module> modules) {
return MarshallerFactory.JBOSS.apply(moduleLoader, modules);
}
},
PROTOSTREAM() {
@Override
public Marshaller apply(ModuleLoader moduleLoader, List<Module> modules) {
return new InfinispanProtoStreamMarshaller(new ModuleClassLoaderMarshaller(moduleLoader), new UnaryOperator<SerializationContextBuilder>() {
@Override
public SerializationContextBuilder apply(SerializationContextBuilder builder) {
for (Module module : modules) {
builder.load(module.getClassLoader());
}
return builder;
}
});
}
},
;
}
| 3,193
| 41.586667
| 177
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/metadata/EntryVersionExternalizer.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.infinispan.metadata;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.infinispan.container.versioning.EntryVersion;
import org.infinispan.container.versioning.NumericVersion;
import org.infinispan.container.versioning.SimpleClusteredVersion;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.Externalizer;
/**
* @author Paul Ferraro
*/
public interface EntryVersionExternalizer<V extends EntryVersion> extends Externalizer<V> {
@MetaInfServices(Externalizer.class)
public static class NumericVersionExternalizer implements EntryVersionExternalizer<NumericVersion> {
@Override
public void writeObject(ObjectOutput output, NumericVersion version) throws IOException {
output.writeLong(version.getVersion());
}
@Override
public NumericVersion readObject(ObjectInput input) throws IOException, ClassNotFoundException {
return new NumericVersion(input.readLong());
}
@Override
public Class<NumericVersion> getTargetClass() {
return NumericVersion.class;
}
}
@MetaInfServices(Externalizer.class)
public class SimpleClusteredVersionExternalizer implements EntryVersionExternalizer<SimpleClusteredVersion> {
@Override
public void writeObject(ObjectOutput output, SimpleClusteredVersion version) throws IOException {
output.writeInt(version.getTopologyId());
output.writeLong(version.getVersion());
}
@Override
public SimpleClusteredVersion readObject(ObjectInput input) throws IOException, ClassNotFoundException {
return new SimpleClusteredVersion(input.readInt(), input.readLong());
}
@Override
public Class<SimpleClusteredVersion> getTargetClass() {
return SimpleClusteredVersion.class;
}
}
}
| 2,983
| 36.772152
| 113
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/metadata/MetadataSerializationContextInitializer.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.infinispan.metadata;
import org.infinispan.metadata.EmbeddedMetadata;
import org.infinispan.metadata.EmbeddedMetadata.EmbeddedExpirableMetadata;
import org.infinispan.metadata.EmbeddedMetadata.EmbeddedLifespanExpirableMetadata;
import org.infinispan.metadata.EmbeddedMetadata.EmbeddedMaxIdleExpirableMetadata;
import org.infinispan.protostream.SerializationContext;
import org.wildfly.clustering.marshalling.protostream.AbstractSerializationContextInitializer;
/**
* @author Paul Ferraro
*/
public class MetadataSerializationContextInitializer extends AbstractSerializationContextInitializer {
public MetadataSerializationContextInitializer() {
super("org.infinispan.metadata.proto");
}
@Override
public void registerMarshallers(SerializationContext context) {
context.registerMarshaller(new EmbeddedMetadataMarshaller<>(EmbeddedMetadata.class));
context.registerMarshaller(new EmbeddedMetadataMarshaller<>(EmbeddedExpirableMetadata.class));
context.registerMarshaller(new EmbeddedMetadataMarshaller<>(EmbeddedLifespanExpirableMetadata.class));
context.registerMarshaller(new EmbeddedMetadataMarshaller<>(EmbeddedMaxIdleExpirableMetadata.class));
}
}
| 2,272
| 45.387755
| 110
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/metadata/MetadataExternalizer.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.infinispan.metadata;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.infinispan.container.versioning.EntryVersion;
import org.infinispan.metadata.EmbeddedMetadata;
import org.infinispan.metadata.Metadata;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.marshalling.Externalizer;
/**
* @author Paul Ferraro
*/
public class MetadataExternalizer<M extends Metadata> implements Externalizer<M> {
private final Class<M> metadataClass;
private final boolean hasLifespan;
private final boolean hasMaxIdle;
MetadataExternalizer(Class<M> metadataClass, boolean hasLifespan, boolean hasMaxIdle) {
this.metadataClass = metadataClass;
this.hasLifespan = hasLifespan;
this.hasMaxIdle = hasMaxIdle;
}
@Override
public void writeObject(ObjectOutput output, M metadata) throws IOException {
output.writeObject(metadata.version());
if (this.hasLifespan) {
output.writeLong(metadata.lifespan());
}
if (this.hasMaxIdle) {
output.writeLong(metadata.maxIdle());
}
}
@SuppressWarnings("unchecked")
@Override
public M readObject(ObjectInput input) throws IOException, ClassNotFoundException {
EmbeddedMetadata.Builder builder = new EmbeddedMetadata.Builder();
builder.version((EntryVersion) input.readObject());
if (this.hasLifespan) {
builder.lifespan(input.readLong());
}
if (this.hasMaxIdle) {
builder.maxIdle(input.readLong());
}
return (M) builder.build();
}
@Override
public Class<M> getTargetClass() {
return this.metadataClass;
}
@MetaInfServices(Externalizer.class)
public static class EmbeddedMetadataExternalizer extends MetadataExternalizer<EmbeddedMetadata> {
public EmbeddedMetadataExternalizer() {
super(EmbeddedMetadata.class, false, false);
}
}
@MetaInfServices(Externalizer.class)
public static class EmbeddedExpirableMetadataExternalizer extends MetadataExternalizer<EmbeddedMetadata.EmbeddedExpirableMetadata> {
public EmbeddedExpirableMetadataExternalizer() {
super(EmbeddedMetadata.EmbeddedExpirableMetadata.class, true, true);
}
}
@MetaInfServices(Externalizer.class)
public static class EmbeddedLifespanExpirableMetadataExternalizer extends MetadataExternalizer<EmbeddedMetadata.EmbeddedLifespanExpirableMetadata> {
public EmbeddedLifespanExpirableMetadataExternalizer() {
super(EmbeddedMetadata.EmbeddedLifespanExpirableMetadata.class, true, false);
}
}
@MetaInfServices(Externalizer.class)
public static class EmbeddedMaxIdleExpirableMetadataExternalizer extends MetadataExternalizer<EmbeddedMetadata.EmbeddedMaxIdleExpirableMetadata> {
public EmbeddedMaxIdleExpirableMetadataExternalizer() {
super(EmbeddedMetadata.EmbeddedMaxIdleExpirableMetadata.class, false, true);
}
}
}
| 4,110
| 37.064815
| 152
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/spi/src/main/java/org/wildfly/clustering/infinispan/metadata/EmbeddedMetadataMarshaller.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.infinispan.metadata;
import java.io.IOException;
import org.infinispan.container.versioning.NumericVersion;
import org.infinispan.container.versioning.SimpleClusteredVersion;
import org.infinispan.metadata.EmbeddedMetadata;
import org.infinispan.protostream.descriptors.WireType;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamMarshaller;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamReader;
import org.wildfly.clustering.marshalling.protostream.ProtoStreamWriter;
/**
* Marshaller for EmbeddedMetaData types.
* @author Paul Ferraro
*/
public class EmbeddedMetadataMarshaller<MD extends EmbeddedMetadata> implements ProtoStreamMarshaller<EmbeddedMetadata> {
private static final int VERSION_INDEX = 1;
private static final int TOPOLOGY_INDEX = 2;
private static final int LIFESPAN_INDEX = 3;
private static final int MAX_IDLE_INDEX = 4;
private Class<MD> targetClass;
EmbeddedMetadataMarshaller(Class<MD> targetClass) {
this.targetClass = targetClass;
}
@Override
public EmbeddedMetadata readFrom(ProtoStreamReader reader) throws IOException {
EmbeddedMetadata.Builder builder = new EmbeddedMetadata.Builder();
Long version = null;
Integer topologyId = null;
while (!reader.isAtEnd()) {
int tag = reader.readTag();
switch (WireType.getTagFieldNumber(tag)) {
case VERSION_INDEX: {
version = reader.readSInt64();
break;
}
case TOPOLOGY_INDEX: {
topologyId = reader.readSInt32();
break;
}
case LIFESPAN_INDEX: {
builder.lifespan(reader.readUInt64());
break;
}
case MAX_IDLE_INDEX: {
builder.maxIdle(reader.readUInt64());
break;
}
default: {
reader.skipField(tag);
}
}
}
if (version != null) {
builder.version((topologyId != null) ? new SimpleClusteredVersion(topologyId, version) : new NumericVersion(version));
}
return (EmbeddedMetadata) builder.build();
}
@Override
public void writeTo(ProtoStreamWriter writer, EmbeddedMetadata metadata) throws IOException {
if (metadata.getClusteredVersion() != null) {
writer.writeSInt64(VERSION_INDEX, metadata.getClusteredVersion().getVersion());
writer.writeSInt32(TOPOLOGY_INDEX, metadata.getClusteredVersion().getTopologyId());
} else if (metadata.getNumericVersion() != null) {
writer.writeSInt64(VERSION_INDEX, metadata.getNumericVersion().getVersion());
}
if (metadata.lifespan() != -1) {
writer.writeUInt64(LIFESPAN_INDEX, metadata.lifespan());
}
if (metadata.maxIdle() != -1) {
writer.writeUInt64(MAX_IDLE_INDEX, metadata.maxIdle());
}
}
@Override
public Class<? extends EmbeddedMetadata> getJavaClass() {
return this.targetClass;
}
}
| 4,235
| 38.222222
| 130
|
java
|
null |
wildfly-main/clustering/infinispan/embedded/api/src/main/java/org/wildfly/clustering/infinispan/affinity/KeyAffinityServiceFactory.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.infinispan.affinity;
import java.util.function.Predicate;
import org.infinispan.Cache;
import org.infinispan.affinity.KeyAffinityService;
import org.infinispan.affinity.KeyGenerator;
import org.infinispan.remoting.transport.Address;
/**
* Factory for creating a key affinity service.
* @author Paul Ferraro
*/
public interface KeyAffinityServiceFactory {
/**
* Creates a key affinity service for use with the specified cache, that generates local key using the specified generator.
* @param cache
* @param generator
* @return a key affinity service
*/
@SuppressWarnings("resource")
default <K> KeyAffinityService<K> createService(Cache<? extends K, ?> cache, KeyGenerator<K> generator) {
return this.createService(cache, generator, cache.getCacheManager().getAddress()::equals);
}
/**
* Creates a key affinity service for use with the specified cache, that generates key for members matching the specified filter, using the specified generator.
* @param cache
* @param generator
* @return a key affinity service
*/
<K> KeyAffinityService<K> createService(Cache<? extends K, ?> cache, KeyGenerator<K> generator, Predicate<Address> filter);
}
| 2,285
| 39.821429
| 164
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/test/java/org/wildfly/extension/clustering/singleton/SingletonTransformersTestCase.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.singleton;
import java.util.List;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.subsystem.AdditionalInitialization;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.model.test.FailedOperationTransformationConfig;
import org.jboss.as.model.test.ModelTestControllerVersion;
import org.jboss.as.model.test.ModelTestUtils;
import org.jboss.as.subsystem.test.AbstractSubsystemTest;
import org.jboss.as.subsystem.test.KernelServices;
import org.jboss.as.subsystem.test.KernelServicesBuilder;
import org.jboss.dmr.ModelNode;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.clustering.singleton.SingletonCacheRequirement;
import org.wildfly.clustering.singleton.SingletonDefaultCacheRequirement;
/**
* @author Radoslav Husar
*/
public class SingletonTransformersTestCase extends AbstractSubsystemTest {
public SingletonTransformersTestCase() {
super(SingletonExtension.SUBSYSTEM_NAME, new SingletonExtension());
}
private static String formatArtifact(String pattern, ModelTestControllerVersion version) {
return String.format(pattern, version.getMavenGavVersion());
}
private static String formatEAP7SubsystemArtifact(ModelTestControllerVersion version) {
return formatArtifact("org.jboss.eap:wildfly-clustering-singleton-extension:%s", version);
}
private static SingletonSubsystemModel getModelVersion(ModelTestControllerVersion controllerVersion) {
switch (controllerVersion) {
case EAP_7_4_0:
return SingletonSubsystemModel.VERSION_3_0_0;
default:
throw new IllegalArgumentException();
}
}
private static String[] getDependencies(ModelTestControllerVersion version) {
switch (version) {
case EAP_7_4_0:
return new String[] {
formatEAP7SubsystemArtifact(version),
formatArtifact("org.jboss.eap:wildfly-clustering-api:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-common:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-server:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-service:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-singleton-api:%s", version),
formatArtifact("org.jboss.eap:wildfly-clustering-spi:%s", version),
};
default:
throw new IllegalArgumentException();
}
}
@SuppressWarnings("removal")
protected org.jboss.as.subsystem.test.AdditionalInitialization createAdditionalInitialization() {
return new AdditionalInitialization()
.require(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING, "binding0", "binding1")
.require(SingletonDefaultCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY, "singleton-container")
.require(SingletonCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY, "singleton-container", "singleton-cache")
.require(SingletonDefaultCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY, "singleton-container")
.require(SingletonCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY, "singleton-container", "singleton-cache")
;
}
@Test
public void testTransformerEAP740() throws Exception {
this.testTransformation(ModelTestControllerVersion.EAP_7_4_0);
}
private void testTransformation(final ModelTestControllerVersion controller) throws Exception {
final ModelVersion version = getModelVersion(controller).getVersion();
final String[] dependencies = getDependencies(controller);
KernelServices services = this.buildKernelServices("subsystem-transform.xml", controller, version, dependencies);
checkSubsystemModelTransformation(services, version, null, false);
}
@Test
public void testRejectionsEAP740() throws Exception {
this.testRejections(ModelTestControllerVersion.EAP_7_4_0);
}
private void testRejections(final ModelTestControllerVersion controller) throws Exception {
ModelVersion version = getModelVersion(controller).getVersion();
String[] dependencies = getDependencies(controller);
// create builder for current subsystem version
KernelServicesBuilder builder = createKernelServicesBuilder();
// initialize the legacy services
builder.createLegacyKernelServicesBuilder(this.createAdditionalInitialization(), controller, version)
.addSingleChildFirstClass(AdditionalInitialization.class)
.addMavenResourceURL(dependencies)
;
KernelServices services = builder.build();
KernelServices legacyServices = services.getLegacyServices(version);
Assert.assertNotNull(legacyServices);
Assert.assertTrue(services.isSuccessfulBoot());
Assert.assertTrue(legacyServices.isSuccessfulBoot());
// test failed operations involving backups
List<ModelNode> xmlOps = builder.parseXmlResource("subsystem-reject.xml");
ModelTestUtils.checkFailedTransformedBootOperations(services, version, xmlOps, createFailedOperationConfig(version));
}
private static FailedOperationTransformationConfig createFailedOperationConfig(ModelVersion version) {
return new FailedOperationTransformationConfig();
}
private KernelServicesBuilder createKernelServicesBuilder() {
return this.createKernelServicesBuilder(createAdditionalInitialization());
}
private KernelServices buildKernelServices(String subsystemXml, ModelTestControllerVersion controllerVersion, ModelVersion version, String... mavenResourceURLs) throws Exception {
KernelServicesBuilder builder = this.createKernelServicesBuilder().setSubsystemXmlResource(subsystemXml);
builder.createLegacyKernelServicesBuilder(this.createAdditionalInitialization(), controllerVersion, version)
.addSingleChildFirstClass(AdditionalInitialization.class)
.addMavenResourceURL(mavenResourceURLs)
.skipReverseControllerCheck()
;
KernelServices services = builder.build();
Assert.assertTrue(ModelTestControllerVersion.MASTER + " boot failed", services.isSuccessfulBoot());
Assert.assertTrue(controllerVersion.getMavenGavVersion() + " boot failed", services.getLegacyServices(version).isSuccessfulBoot());
return services;
}
}
| 7,708
| 46.58642
| 183
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/test/java/org/wildfly/extension/clustering/singleton/SingletonSubsystemTestCase.java
|
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, 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.extension.clustering.singleton;
import java.util.EnumSet;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.subsystem.AdditionalInitialization;
import org.jboss.as.subsystem.test.AbstractSubsystemSchemaTest;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.wildfly.clustering.singleton.SingletonCacheRequirement;
import org.wildfly.clustering.singleton.SingletonDefaultCacheRequirement;
/**
* @author Paul Ferraro
*/
@RunWith(Parameterized.class)
public class SingletonSubsystemTestCase extends AbstractSubsystemSchemaTest<SingletonSubsystemSchema> {
@Parameters
public static Iterable<SingletonSubsystemSchema> parameters() {
return EnumSet.allOf(SingletonSubsystemSchema.class);
}
public SingletonSubsystemTestCase(SingletonSubsystemSchema schema) {
super(SingletonExtension.SUBSYSTEM_NAME, new SingletonExtension(), schema, SingletonSubsystemSchema.CURRENT);
}
@Override
protected org.jboss.as.subsystem.test.AdditionalInitialization createAdditionalInitialization() {
return new AdditionalInitialization()
.require(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING, "binding0", "binding1")
.require(SingletonDefaultCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY, "singleton-container")
.require(SingletonCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY, "singleton-container", "singleton-cache")
;
}
}
| 2,612
| 43.288136
| 132
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonExtension.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;
import org.jboss.as.clustering.controller.SubsystemExtension;
import org.jboss.as.controller.Extension;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver;
import org.kohsuke.MetaInfServices;
/**
* Extension point for singleton subsystem.
* @author Paul Ferraro
*/
@MetaInfServices(Extension.class)
public class SingletonExtension extends SubsystemExtension<SingletonSubsystemSchema> {
static final String SUBSYSTEM_NAME = "singleton";
static final ParentResourceDescriptionResolver SUBSYSTEM_RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME, SingletonExtension.class);
public SingletonExtension() {
super(SUBSYSTEM_NAME, SingletonSubsystemModel.CURRENT, SingletonResourceDefinition::new, SingletonSubsystemSchema.CURRENT, new SingletonXMLWriter());
}
}
| 1,988
| 43.2
| 157
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SimpleElectionPolicyServiceConfigurator.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;
import static org.wildfly.extension.clustering.singleton.SimpleElectionPolicyResourceDefinition.Attribute.POSITION;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.singleton.SingletonElectionPolicy;
import org.wildfly.clustering.singleton.election.SimpleSingletonElectionPolicy;
/**
* Builds a service that provides a simple election policy.
* @author Paul Ferraro
*/
public class SimpleElectionPolicyServiceConfigurator extends ElectionPolicyServiceConfigurator {
private volatile int position;
public SimpleElectionPolicyServiceConfigurator(PathAddress policyAddress) {
super(policyAddress);
}
@Override
public SingletonElectionPolicy get() {
return new SimpleSingletonElectionPolicy(this.position);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
this.position = POSITION.resolveModelAttribute(context, model).asInt();
return super.configure(context, model);
}
}
| 2,321
| 39.034483
| 117
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonDeploymentResourceDefinition.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.singleton;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.ManagementResourceRegistration;
import org.jboss.as.clustering.controller.MetricHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.singleton.Singleton;
/**
* @author Paul Ferraro
*/
public class SingletonDeploymentResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
static PathElement pathElement(ServiceName name) {
return pathElement(name.getParent().getSimpleName());
}
static PathElement pathElement(String name) {
return PathElement.pathElement("deployment", name);
}
private final FunctionExecutorRegistry<Singleton> executors;
public SingletonDeploymentResourceDefinition(FunctionExecutorRegistry<Singleton> executors) {
super(new Parameters(WILDCARD_PATH, SingletonExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH)).setRuntime());
this.executors = executors;
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
new MetricHandler<>(new SingletonDeploymentMetricExecutor(this.executors), SingletonMetric.class).register(registration);
return registration;
}
}
| 2,657
| 41.870968
| 132
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonServiceHandler.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;
import static org.wildfly.extension.clustering.singleton.SingletonResourceDefinition.Attribute.DEFAULT;
import java.util.EnumSet;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.service.IdentityServiceConfigurator;
import org.wildfly.clustering.singleton.SingletonRequirement;
import org.wildfly.extension.clustering.singleton.SingletonResourceDefinition.Capability;
/**
* @author Paul Ferraro
*/
@SuppressWarnings({ "removal", "deprecation" })
public class SingletonServiceHandler implements ResourceServiceHandler {
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
String defaultPolicy = DEFAULT.resolveModelAttribute(context, model).asString();
ServiceTarget target = context.getServiceTarget();
ServiceName serviceName = Capability.DEFAULT_POLICY.getServiceName(context.getCurrentAddress());
ServiceName targetServiceName = SingletonServiceNameFactory.SINGLETON_POLICY.getServiceName(context, defaultPolicy);
new IdentityServiceConfigurator<>(serviceName, targetServiceName).build(target).install();
// Use legacy service installation for legacy capability
ServiceName legacyServiceName = Capability.DEFAULT_LEGACY_POLICY.getServiceName(context.getCurrentAddress());
new AliasServiceBuilder<>(legacyServiceName, targetServiceName, SingletonRequirement.SINGLETON_POLICY.getType()).build(target).install();
}
@Override
public void removeServices(OperationContext context, ModelNode model) {
PathAddress address = context.getCurrentAddress();
for (Capability capability : EnumSet.allOf(Capability.class)) {
context.removeService(capability.getServiceName(address));
}
}
}
| 3,166
| 44.898551
| 145
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/XMLElement.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;
import java.util.HashMap;
import java.util.Map;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Enumeration of XML elements.
* @author Paul Ferraro
*/
public enum XMLElement {
SINGLETON_POLICIES("singleton-policies"),
SINGLETON_POLICY(SingletonPolicyResourceDefinition.WILDCARD_PATH),
NAME_PREFERENCES(ElectionPolicyResourceDefinition.Attribute.NAME_PREFERENCES),
RANDOM_ELECTION_POLICY("random-election-policy"),
SIMPLE_ELECTION_POLICY("simple-election-policy"),
SOCKET_BINDING_PREFERENCES(ElectionPolicyResourceDefinition.Attribute.SOCKET_BINDING_PREFERENCES),
;
private final String localName;
XMLElement(PathElement path) {
this(path.getKey());
}
XMLElement(Attribute attribute) {
this(attribute.getDefinition().getXmlName());
}
XMLElement(String localName) {
this.localName = localName;
}
public String getLocalName() {
return this.localName;
}
private static final Map<String, XMLElement> map = new HashMap<>();
static {
for (XMLElement element : XMLElement.values()) {
map.put(element.getLocalName(), element);
}
}
static XMLElement forName(XMLExtendedStreamReader reader) throws XMLStreamException {
XMLElement element = map.get(reader.getLocalName());
if (element == null) {
throw ParseUtils.unexpectedElement(reader);
}
return element;
}
}
| 2,731
| 32.728395
| 102
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/AliasServiceBuilder.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.singleton;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StopContext;
import org.jboss.msc.value.InjectedValue;
import org.wildfly.clustering.service.Builder;
import org.wildfly.clustering.service.IdentityServiceConfigurator;
/**
* Builds an alias to another service.
* @author Paul Ferraro
* @param <T> the type of the target service
* @deprecated Replaced by {@link IdentityServiceConfigurator}.
*/
@Deprecated
public class AliasServiceBuilder<T> implements Builder<T>, Service<T> {
private final InjectedValue<T> value = new InjectedValue<>();
private final ServiceName name;
private final ServiceName targetName;
private final Class<T> targetClass;
/**
* Constructs a new builder
* @param name the target service name
* @param targetName the target service
* @param targetClass the target service class
*/
public AliasServiceBuilder(ServiceName name, ServiceName targetName, Class<T> targetClass) {
this.name = name;
this.targetName = targetName;
this.targetClass = targetClass;
}
@Override
public ServiceName getServiceName() {
return this.name;
}
@Override
public ServiceBuilder<T> build(ServiceTarget target) {
return target.addService(this.name, this)
.addDependency(this.targetName, this.targetClass, this.value)
.setInitialMode(ServiceController.Mode.PASSIVE);
}
@Override
public T getValue() {
return this.value.getValue();
}
@Override
public void start(StartContext context) {
// Do nothing
}
@Override
public void stop(StopContext context) {
// Do nothing
}
}
| 3,004
| 32.764045
| 96
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonSubsystemModel.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;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.SubsystemModel;
/**
* Enumeration of supported versions of management model.
* @author Paul Ferraro
*/
public enum SingletonSubsystemModel implements SubsystemModel {
/* Unsupported model versions - for reference purposes only
VERSION_1_0_0(1, 0, 0), // WildFly 10, EAP 7.0
VERSION_2_0_0(2, 0, 0), // WildFly 11-14, EAP 7.1-7.2
*/
VERSION_3_0_0(3, 0, 0), // WildFly 15-present, EAP 7.3-present
;
static final SingletonSubsystemModel CURRENT = VERSION_3_0_0;
private final ModelVersion version;
SingletonSubsystemModel(int major, int minor, int micro) {
this.version = ModelVersion.create(major, minor, micro);
}
@Override
public ModelVersion getVersion() {
return this.version;
}
}
| 1,903
| 35.615385
| 70
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonPolicyServiceHandler.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.singleton;
import static org.wildfly.extension.clustering.singleton.SingletonPolicyResourceDefinition.Capability.LEGACY_POLICY;
import java.util.EnumSet;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.ServiceValueRegistry;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.singleton.Singleton;
import org.wildfly.clustering.singleton.SingletonRequirement;
import org.wildfly.extension.clustering.singleton.SingletonPolicyResourceDefinition.Capability;
/**
* @author Paul Ferraro
*/
@SuppressWarnings({ "removal", "deprecation" })
public class SingletonPolicyServiceHandler implements ResourceServiceHandler {
private final ServiceValueRegistry<Singleton> registry;
SingletonPolicyServiceHandler(ServiceValueRegistry<Singleton> registry) {
this.registry = registry;
}
@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
ServiceTarget target = context.getServiceTarget();
ServiceConfigurator configurator = new SingletonPolicyServiceConfigurator(address, this.registry).configure(context, model);
configurator.build(target).install();
// Use legacy service installation for legacy capability
new AliasServiceBuilder<>(LEGACY_POLICY.getServiceName(address), configurator.getServiceName(), SingletonRequirement.SINGLETON_POLICY.getType()).build(target).install();
}
@Override
public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException {
PathAddress address = context.getCurrentAddress();
for (Capability capability : EnumSet.allOf(Capability.class)) {
context.removeService(capability.getServiceName(address));
}
}
}
| 3,201
| 42.863014
| 177
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/XMLAttribute.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;
import java.util.HashMap;
import java.util.Map;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Enumeration of XML attributes.
* @author Paul Ferraro
*/
public enum XMLAttribute {
CACHE(SingletonPolicyResourceDefinition.Attribute.CACHE),
CACHE_CONTAINER(SingletonPolicyResourceDefinition.Attribute.CACHE_CONTAINER),
DEFAULT(SingletonResourceDefinition.Attribute.DEFAULT),
NAME(ModelDescriptionConstants.NAME),
POSITION(SimpleElectionPolicyResourceDefinition.Attribute.POSITION),
QUORUM(SingletonPolicyResourceDefinition.Attribute.QUORUM),
;
private final String localName;
XMLAttribute(Attribute attribute) {
this(attribute.getDefinition().getXmlName());
}
XMLAttribute(String localName) {
this.localName = localName;
}
public String getLocalName() {
return this.localName;
}
public String require(XMLExtendedStreamReader reader) throws XMLStreamException {
String value = reader.getAttributeValue(null, this.localName);
if (value == null) {
throw ParseUtils.missingRequired(reader, this.localName);
}
return value;
}
private static final Map<String, XMLAttribute> map = new HashMap<>();
static {
for (XMLAttribute attribute : XMLAttribute.values()) {
map.put(attribute.getLocalName(), attribute);
}
}
static XMLAttribute forName(XMLExtendedStreamReader reader, int index) throws XMLStreamException {
XMLAttribute attribute = map.get(reader.getAttributeLocalName(index));
if (attribute == null) {
throw ParseUtils.unexpectedAttribute(reader, index);
}
return attribute;
}
}
| 3,018
| 34.517647
| 102
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonXMLReader.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;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parses singleton deployer subsystem configuration from XML.
* @author Paul Ferraro
*/
public class SingletonXMLReader implements XMLElementReader<List<ModelNode>> {
@SuppressWarnings("unused")
private final SingletonSubsystemSchema schema;
public SingletonXMLReader(SingletonSubsystemSchema schema) {
this.schema = schema;
}
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> result) throws XMLStreamException {
Map<PathAddress, ModelNode> operations = new LinkedHashMap<>();
PathAddress address = PathAddress.pathAddress(SingletonResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
while (reader.hasNext() && reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
XMLElement element = XMLElement.forName(reader);
switch (element) {
case SINGLETON_POLICIES: {
this.parseSingletonPolicies(reader, address, operations);
break;
}
default : {
throw ParseUtils.unexpectedElement(reader);
}
}
}
result.addAll(operations.values());
}
private void parseSingletonPolicies(XMLExtendedStreamReader reader, PathAddress address, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
ModelNode operation = operations.get(address);
for (int i = 0; i < reader.getAttributeCount(); ++i) {
XMLAttribute attribute = XMLAttribute.forName(reader, i);
switch (attribute) {
case DEFAULT: {
readAttribute(reader, i, operation, SingletonResourceDefinition.Attribute.DEFAULT);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
XMLElement element = XMLElement.forName(reader);
switch (element) {
case SINGLETON_POLICY: {
this.parseSingletonPolicy(reader, address, operations);
break;
}
default : {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseSingletonPolicy(XMLExtendedStreamReader reader, PathAddress subsystemAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
String name = XMLAttribute.NAME.require(reader);
PathAddress address = subsystemAddress.append(SingletonPolicyResourceDefinition.pathElement(name));
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); ++i) {
XMLAttribute attribute = XMLAttribute.forName(reader, i);
switch (attribute) {
case NAME: {
// Already parsed
break;
}
case CACHE_CONTAINER: {
readAttribute(reader, i, operation, SingletonPolicyResourceDefinition.Attribute.CACHE_CONTAINER);
break;
}
case CACHE: {
readAttribute(reader, i, operation, SingletonPolicyResourceDefinition.Attribute.CACHE);
break;
}
case QUORUM: {
readAttribute(reader, i, operation, SingletonPolicyResourceDefinition.Attribute.QUORUM);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
while (reader.hasNext() && reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
XMLElement element = XMLElement.forName(reader);
switch (element) {
case RANDOM_ELECTION_POLICY: {
this.parseRandomElectionPolicy(reader, address, operations);
break;
}
case SIMPLE_ELECTION_POLICY: {
this.parseSimpleElectionPolicy(reader, address, operations);
break;
}
default : {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private void parseRandomElectionPolicy(XMLExtendedStreamReader reader, PathAddress policyAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = policyAddress.append(RandomElectionPolicyResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
ParseUtils.requireNoAttributes(reader);
this.parsePreferences(reader, operation);
}
private void parseSimpleElectionPolicy(XMLExtendedStreamReader reader, PathAddress policyAddress, Map<PathAddress, ModelNode> operations) throws XMLStreamException {
PathAddress address = policyAddress.append(SimpleElectionPolicyResourceDefinition.PATH);
ModelNode operation = Util.createAddOperation(address);
operations.put(address, operation);
for (int i = 0; i < reader.getAttributeCount(); ++i) {
XMLAttribute attribute = XMLAttribute.forName(reader, i);
switch (attribute) {
case POSITION: {
readAttribute(reader, i, operation, SimpleElectionPolicyResourceDefinition.Attribute.POSITION);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
this.parsePreferences(reader, operation);
}
@SuppressWarnings("static-method")
private void parsePreferences(XMLExtendedStreamReader reader, ModelNode operation) throws XMLStreamException {
while (reader.hasNext() && reader.nextTag() != XMLStreamConstants.END_ELEMENT) {
XMLElement element = XMLElement.forName(reader);
switch (element) {
case NAME_PREFERENCES: {
readElement(reader, operation, ElectionPolicyResourceDefinition.Attribute.NAME_PREFERENCES);
break;
}
case SOCKET_BINDING_PREFERENCES: {
readElement(reader, operation, ElectionPolicyResourceDefinition.Attribute.SOCKET_BINDING_PREFERENCES);
break;
}
default : {
throw ParseUtils.unexpectedElement(reader);
}
}
}
}
private static void readAttribute(XMLExtendedStreamReader reader, int index, ModelNode operation, Attribute attribute) throws XMLStreamException {
attribute.getDefinition().getParser().parseAndSetParameter(attribute.getDefinition(), reader.getAttributeValue(index), operation, reader);
}
private static void readElement(XMLExtendedStreamReader reader, ModelNode operation, Attribute attribute) throws XMLStreamException {
attribute.getDefinition().getParser().parseAndSetParameter(attribute.getDefinition(), reader.getElementText(), operation, reader);
}
}
| 9,057
| 40.360731
| 169
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonLogger.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.extension.clustering.singleton;
import static org.jboss.logging.Logger.Level.INFO;
import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.wildfly.clustering.singleton.service.SingletonPolicy;
/**
* @author Paul Ferraro
*/
@MessageLogger(projectCode = "WFLYCLSNG", length = 4)
public interface SingletonLogger extends BasicLogger {
String ROOT_LOGGER_CATEGORY = "org.wildfly.extension.clustering.singleton";
SingletonLogger ROOT_LOGGER = Logger.getMessageLogger(SingletonLogger.class, ROOT_LOGGER_CATEGORY);
@LogMessage(level = INFO)
@Message(id = 1, value = "Singleton deployment detected. Deployment will reset using %s policy.")
void singletonDeploymentDetected(SingletonPolicy policy);
}
| 1,936
| 40.212766
| 103
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonResourceDefinition.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;
import java.util.EnumSet;
import java.util.function.Consumer;
import org.jboss.as.clustering.controller.CapabilityProvider;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.DeploymentChainContributingResourceRegistrar;
import org.jboss.as.clustering.controller.ManagementResourceRegistration;
import org.jboss.as.clustering.controller.RequirementCapability;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.SubsystemRegistration;
import org.jboss.as.clustering.controller.SubsystemResourceDefinition;
import org.jboss.as.controller.CapabilityReferenceRecorder;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler;
import org.jboss.as.controller.registry.AttributeAccess.Flag;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.server.deployment.jbossallxml.JBossAllSchema;
import org.jboss.dmr.ModelType;
import org.wildfly.clustering.service.Requirement;
import org.wildfly.clustering.singleton.SingletonDefaultRequirement;
import org.wildfly.clustering.singleton.SingletonRequirement;
import org.wildfly.extension.clustering.singleton.deployment.SingletonDeploymentDependencyProcessor;
import org.wildfly.extension.clustering.singleton.deployment.SingletonDeploymentParsingProcessor;
import org.wildfly.extension.clustering.singleton.deployment.SingletonDeploymentProcessor;
import org.wildfly.extension.clustering.singleton.deployment.SingletonDeploymentSchema;
/**
* Definition of the singleton deployer resource.
* @author Paul Ferraro
*/
public class SingletonResourceDefinition extends SubsystemResourceDefinition implements Consumer<DeploymentProcessorTarget> {
static final PathElement PATH = pathElement(SingletonExtension.SUBSYSTEM_NAME);
enum Capability implements CapabilityProvider {
@Deprecated DEFAULT_LEGACY_POLICY(SingletonDefaultRequirement.SINGLETON_POLICY),
DEFAULT_POLICY(SingletonDefaultRequirement.POLICY),
;
private final org.jboss.as.clustering.controller.Capability capability;
Capability(Requirement requirement) {
this.capability = new RequirementCapability(requirement);
}
@Override
public org.jboss.as.clustering.controller.Capability getCapability() {
return this.capability;
}
}
enum Attribute implements org.jboss.as.clustering.controller.Attribute {
DEFAULT("default", ModelType.STRING, new CapabilityReference(Capability.DEFAULT_POLICY, SingletonRequirement.POLICY)),
;
private final SimpleAttributeDefinition definition;
Attribute(String name, ModelType type, CapabilityReferenceRecorder reference) {
this.definition = new SimpleAttributeDefinitionBuilder(name, type)
.setCapabilityReference(reference)
.setFlags(Flag.RESTART_RESOURCE_SERVICES)
.build();
}
@Override
public SimpleAttributeDefinition getDefinition() {
return this.definition;
}
}
SingletonResourceDefinition() {
super(PATH, SingletonExtension.SUBSYSTEM_RESOLVER);
}
@Override
public void register(SubsystemRegistration parentRegistration) {
ManagementResourceRegistration registration = parentRegistration.registerSubsystemModel(this);
registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver())
.addAttributes(Attribute.class)
.addCapabilities(Capability.class)
;
ResourceServiceHandler handler = new SingletonServiceHandler();
new DeploymentChainContributingResourceRegistrar(descriptor, handler, this).register(registration);
new SingletonPolicyResourceDefinition().register(registration);
}
@Override
public void accept(DeploymentProcessorTarget target) {
target.addDeploymentProcessor(SingletonExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_REGISTER_JBOSS_ALL_SINGLETON_DEPLOYMENT, JBossAllSchema.createDeploymentUnitProcessor(EnumSet.allOf(SingletonDeploymentSchema.class), SingletonDeploymentDependencyProcessor.CONFIGURATION_KEY));
target.addDeploymentProcessor(SingletonExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_SINGLETON_DEPLOYMENT, new SingletonDeploymentParsingProcessor());
target.addDeploymentProcessor(SingletonExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_SINGLETON_DEPLOYMENT, new SingletonDeploymentDependencyProcessor());
target.addDeploymentProcessor(SingletonExtension.SUBSYSTEM_NAME, Phase.CONFIGURE_MODULE, Phase.CONFIGURE_SINGLETON_DEPLOYMENT, new SingletonDeploymentProcessor());
}
}
| 6,279
| 49.24
| 299
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/RandomElectionPolicyResourceDefinition.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;
import java.util.function.UnaryOperator;
import org.jboss.as.controller.PathElement;
/**
* @author Paul Ferraro
*/
public class RandomElectionPolicyResourceDefinition extends ElectionPolicyResourceDefinition {
static final String PATH_VALUE = "random";
static final PathElement PATH = pathElement(PATH_VALUE);
RandomElectionPolicyResourceDefinition() {
super(PATH, SingletonExtension.SUBSYSTEM_RESOLVER.createChildResolver(PATH, WILDCARD_PATH), UnaryOperator.identity(), RandomElectionPolicyServiceConfigurator::new);
}
}
| 1,629
| 38.756098
| 172
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonServiceMetricExecutor.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.singleton;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.singleton.Singleton;
/**
* Executor for singleton service metrics.
* @author Paul Ferraro
*/
public class SingletonServiceMetricExecutor extends SingletonMetricExecutor {
public SingletonServiceMetricExecutor(FunctionExecutorRegistry<Singleton> executors) {
super(ServiceName::parse, executors);
}
}
| 1,538
| 38.461538
| 90
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonDeploymentMetricExecutor.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.singleton;
import java.util.function.Function;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.server.deployment.Services;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.singleton.Singleton;
/**
* Executor for singleton deployment metrics.
* @author Paul Ferraro
*/
public class SingletonDeploymentMetricExecutor extends SingletonMetricExecutor {
public SingletonDeploymentMetricExecutor(FunctionExecutorRegistry<Singleton> executors) {
super(new Function<String, ServiceName>() {
@Override
public ServiceName apply(String deployment) {
return Services.deploymentUnitName(deployment).append("installer");
}
}, executors);
}
}
| 1,839
| 38.148936
| 93
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonSubsystemSchema.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;
import java.util.List;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.SubsystemSchema;
import org.jboss.as.controller.xml.VersionedNamespace;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.IntVersion;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Enumeration of supported subsystem schemas.
* @author Paul Ferraro
*/
public enum SingletonSubsystemSchema implements SubsystemSchema<SingletonSubsystemSchema> {
VERSION_1_0(1, 0),
;
static final SingletonSubsystemSchema CURRENT = VERSION_1_0;
private final VersionedNamespace<IntVersion, SingletonSubsystemSchema> namespace;
SingletonSubsystemSchema(int major, int minor) {
this.namespace = SubsystemSchema.createLegacySubsystemURN(SingletonExtension.SUBSYSTEM_NAME, new IntVersion(major, minor));
}
@Override
public VersionedNamespace<IntVersion, SingletonSubsystemSchema> getNamespace() {
return this.namespace;
}
@Override
public void readElement(XMLExtendedStreamReader reader, List<ModelNode> operations) throws XMLStreamException {
new SingletonXMLReader(this).readElement(reader, operations);
}
}
| 2,265
| 36.766667
| 131
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonPolicyServiceConfigurator.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;
import static org.wildfly.extension.clustering.singleton.SingletonPolicyResourceDefinition.Attribute.CACHE;
import static org.wildfly.extension.clustering.singleton.SingletonPolicyResourceDefinition.Attribute.CACHE_CONTAINER;
import static org.wildfly.extension.clustering.singleton.SingletonPolicyResourceDefinition.Attribute.QUORUM;
import static org.wildfly.extension.clustering.singleton.SingletonPolicyResourceDefinition.Capability.POLICY;
import java.util.function.Consumer;
import org.jboss.as.clustering.controller.CapabilityServiceNameProvider;
import org.jboss.as.clustering.controller.ServiceValueCaptorServiceConfigurator;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.clustering.controller.ServiceValueRegistry;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.LifecycleEvent;
import org.jboss.msc.service.LifecycleListener;
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.Registrar;
import org.wildfly.clustering.Registration;
import org.wildfly.clustering.service.Builder;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
import org.wildfly.clustering.singleton.Singleton;
import org.wildfly.clustering.singleton.SingletonElectionPolicy;
import org.wildfly.clustering.singleton.SingletonPolicy;
import org.wildfly.clustering.singleton.SingletonServiceBuilderFactory;
import org.wildfly.clustering.singleton.service.SingletonCacheRequirement;
/**
* Builds a service that provides a {@link SingletonPolicy}.
* @author Paul Ferraro
*/
@SuppressWarnings({ "removal", "deprecation" })
public class SingletonPolicyServiceConfigurator extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, SingletonPolicy {
private final ServiceValueRegistry<Singleton> registry;
private final SupplierDependency<SingletonElectionPolicy> policy;
private volatile Registrar<ServiceName> registrar;
private volatile SupplierDependency<SingletonServiceBuilderFactory> factory;
private volatile int quorum;
public SingletonPolicyServiceConfigurator(PathAddress address, ServiceValueRegistry<Singleton> registry) {
super(POLICY, address);
this.policy = new ServiceSupplierDependency<>(ElectionPolicyResourceDefinition.Capability.ELECTION_POLICY.getServiceName(address.append(ElectionPolicyResourceDefinition.WILDCARD_PATH)));
this.registry = registry;
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<SingletonPolicy> policy = new CompositeDependency(this.policy, this.factory).register(builder).provides(this.getServiceName());
Service service = Service.newInstance(policy, this);
return builder.setInstance(service).setInitialMode(ServiceController.Mode.PASSIVE);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
String containerName = CACHE_CONTAINER.resolveModelAttribute(context, model).asString();
String cacheName = CACHE.resolveModelAttribute(context, model).asStringOrNull();
this.factory = new ServiceSupplierDependency<>(SingletonCacheRequirement.SINGLETON_SERVICE_BUILDER_FACTORY.getServiceName(context, containerName, cacheName));
this.quorum = QUORUM.resolveModelAttribute(context, model).asInt();
this.registrar = (SingletonPolicyResource) context.readResource(PathAddress.EMPTY_ADDRESS);
return this;
}
@Override
public ServiceConfigurator createSingletonServiceConfigurator(ServiceName name) {
ServiceConfigurator configurator = this.factory.get().createSingletonServiceConfigurator(name)
.electionPolicy(this.policy.get())
.requireQuorum(this.quorum)
;
return new SingletonServiceConfigurator(configurator, new SingletonServiceLifecycleListener(name, this.registrar), this.registry);
}
@Override
public <T> Builder<T> createSingletonServiceBuilder(ServiceName name, org.jboss.msc.service.Service<T> service) {
Builder<T> builder = this.factory.get().createSingletonServiceBuilder(name, service)
.electionPolicy(this.policy.get())
.requireQuorum(this.quorum)
;
return new SingletonServiceBuilder<>(builder, new SingletonServiceLifecycleListener(name, this.registrar));
}
@Override
public <T> Builder<T> createSingletonServiceBuilder(ServiceName name, org.jboss.msc.service.Service<T> primaryService, org.jboss.msc.service.Service<T> backupService) {
Builder<T> builder = this.factory.get().createSingletonServiceBuilder(name, primaryService, backupService)
.electionPolicy(this.policy.get())
.requireQuorum(this.quorum)
;
return new SingletonServiceBuilder<>(builder, new SingletonServiceLifecycleListener(name, this.registrar));
}
@Override
public String toString() {
return this.getServiceName().getSimpleName();
}
private class SingletonServiceConfigurator implements ServiceConfigurator, LifecycleListener {
private final ServiceConfigurator configurator;
private final LifecycleListener listener;
private final ServiceValueRegistry<Singleton> registry;
SingletonServiceConfigurator(ServiceConfigurator configurator, LifecycleListener listener, ServiceValueRegistry<Singleton> registry) {
this.configurator = configurator;
this.listener = listener;
this.registry = registry;
}
@Override
public ServiceName getServiceName() {
return this.configurator.getServiceName();
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
new ServiceValueCaptorServiceConfigurator<>(this.registry.add(this.getServiceName().append("singleton"))).build(target).install();
return this.configurator.build(target).addListener(this.listener).addListener(this);
}
@Override
public void handleEvent(ServiceController<?> controller, LifecycleEvent event) {
if (event == LifecycleEvent.REMOVED) {
this.registry.remove(controller.getName());
}
}
}
private class SingletonServiceBuilder<T> implements Builder<T> {
private final Builder<T> builder;
private final LifecycleListener listener;
SingletonServiceBuilder(Builder<T> builder, LifecycleListener listener) {
this.builder = builder;
this.listener = listener;
}
@Override
public ServiceName getServiceName() {
return this.builder.getServiceName();
}
@Override
public ServiceBuilder<T> build(ServiceTarget target) {
return this.builder.build(target).addListener(this.listener);
}
}
private class SingletonServiceLifecycleListener implements LifecycleListener {
private final ServiceName name;
private final Registrar<ServiceName> registrar;
private Registration registration;
SingletonServiceLifecycleListener(ServiceName name, Registrar<ServiceName> registrar) {
this.name = name;
this.registrar = registrar;
}
@Override
public synchronized void handleEvent(ServiceController<?> controller, LifecycleEvent event) {
switch (event) {
case UP: {
this.registration = this.registrar.register(this.name);
break;
}
default: {
if (this.registration != null) {
this.registration.close();
}
break;
}
}
}
}
}
| 9,517
| 44.54067
| 194
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonPolicyResource.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.singleton;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jboss.as.clustering.controller.ChildResourceProvider;
import org.jboss.as.clustering.controller.ComplexResource;
import org.jboss.as.clustering.controller.SimpleChildResourceProvider;
import org.jboss.as.controller.registry.Resource;
import org.jboss.as.server.deployment.Services;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.Registrar;
import org.wildfly.clustering.Registration;
/**
* Custom resource that additionally reports runtime singleton deployments and services.
* @author Paul Ferraro
*/
public class SingletonPolicyResource extends ComplexResource implements Registrar<ServiceName> {
private static final String DEPLOYMENT_CHILD_TYPE = SingletonDeploymentResourceDefinition.WILDCARD_PATH.getKey();
private static final String SERVICE_CHILD_TYPE = SingletonServiceResourceDefinition.WILDCARD_PATH.getKey();
private static Map<String, ChildResourceProvider> createProviders() {
Map<String, ChildResourceProvider> providers = new HashMap<>();
providers.put(DEPLOYMENT_CHILD_TYPE, new SimpleChildResourceProvider(ConcurrentHashMap.newKeySet()));
providers.put(SERVICE_CHILD_TYPE, new SimpleChildResourceProvider(ConcurrentHashMap.newKeySet()));
return Collections.unmodifiableMap(providers);
}
public SingletonPolicyResource(Resource resource) {
this(resource, createProviders());
}
private SingletonPolicyResource(Resource resource, Map<String, ChildResourceProvider> providers) {
super(resource, providers, SingletonPolicyResource::new);
}
@Override
public Registration register(ServiceName service) {
boolean deployment = Services.JBOSS_DEPLOYMENT.isParentOf(service);
ChildResourceProvider provider = this.apply(deployment ? DEPLOYMENT_CHILD_TYPE : SERVICE_CHILD_TYPE);
String name = (deployment ? SingletonDeploymentResourceDefinition.pathElement(service) : SingletonServiceResourceDefinition.pathElement(service)).getValue();
provider.getChildren().add(name);
return new Registration() {
@Override
public void close() {
provider.getChildren().remove(name);
}
};
}
}
| 3,423
| 43.467532
| 165
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonServiceNameFactory.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.singleton;
import org.jboss.as.clustering.controller.DefaultableUnaryServiceNameFactoryProvider;
import org.jboss.as.clustering.controller.RequirementServiceNameFactory;
import org.jboss.as.clustering.controller.ServiceNameFactory;
import org.jboss.as.clustering.controller.UnaryRequirementServiceNameFactory;
import org.jboss.as.clustering.controller.UnaryServiceNameFactory;
import org.wildfly.clustering.service.DefaultableUnaryRequirement;
import org.wildfly.clustering.singleton.SingletonRequirement;
/**
* @author Paul Ferraro
*/
public enum SingletonServiceNameFactory implements DefaultableUnaryServiceNameFactoryProvider {
@Deprecated LEGACY_SINGLETON_POLICY(SingletonRequirement.SINGLETON_POLICY),
SINGLETON_POLICY(SingletonRequirement.POLICY),
;
private final UnaryServiceNameFactory factory;
private final ServiceNameFactory defaultFactory;
SingletonServiceNameFactory(DefaultableUnaryRequirement requirement) {
this.factory = new UnaryRequirementServiceNameFactory(requirement);
this.defaultFactory = new RequirementServiceNameFactory(requirement.getDefaultRequirement());
}
@Override
public UnaryServiceNameFactory getServiceNameFactory() {
return this.factory;
}
@Override
public ServiceNameFactory getDefaultServiceNameFactory() {
return this.defaultFactory;
}
}
| 2,435
| 41
| 101
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/RandomElectionPolicyServiceConfigurator.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;
import org.jboss.as.controller.PathAddress;
import org.wildfly.clustering.singleton.SingletonElectionPolicy;
import org.wildfly.clustering.singleton.election.RandomSingletonElectionPolicy;
/**
* @author Paul Ferraro
*/
public class RandomElectionPolicyServiceConfigurator extends ElectionPolicyServiceConfigurator {
public RandomElectionPolicyServiceConfigurator(PathAddress policyAddress) {
super(policyAddress);
}
@Override
public SingletonElectionPolicy get() {
return new RandomSingletonElectionPolicy();
}
}
| 1,631
| 36.953488
| 96
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonXMLWriter.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;
import java.util.EnumSet;
import javax.xml.stream.XMLStreamException;
import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.persistence.SubsystemMarshallingContext;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.jboss.staxmapper.XMLElementWriter;
import org.jboss.staxmapper.XMLExtendedStreamWriter;
/**
* Marshals singleton deployer subsystem configuration to XML.
* @author Paul Ferraro
*/
public class SingletonXMLWriter implements XMLElementWriter<SubsystemMarshallingContext> {
@Override
public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException {
context.startSubsystemElement(SingletonSubsystemSchema.CURRENT.getNamespace().getUri(), false);
writeSingletonPolicies(writer, context.getModelNode());
writer.writeEndElement();
}
private static void writeSingletonPolicies(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException {
writer.writeStartElement(XMLElement.SINGLETON_POLICIES.getLocalName());
writeAttributes(writer, model, SingletonResourceDefinition.Attribute.class);
for (Property property : model.get(SingletonPolicyResourceDefinition.WILDCARD_PATH.getKey()).asPropertyList()) {
writeSingletonPolicy(writer, property.getName(), property.getValue());
}
writer.writeEndElement();
}
private static void writeSingletonPolicy(XMLExtendedStreamWriter writer, String name, ModelNode policy) throws XMLStreamException {
writer.writeStartElement(XMLElement.SINGLETON_POLICY.getLocalName());
writer.writeAttribute(XMLAttribute.NAME.getLocalName(), name);
writeAttributes(writer, policy, SingletonPolicyResourceDefinition.Attribute.class);
if (policy.hasDefined(ElectionPolicyResourceDefinition.WILDCARD_PATH.getKey())) {
Property property = policy.get(ElectionPolicyResourceDefinition.WILDCARD_PATH.getKey()).asProperty();
writeElectionPolicy(writer, property.getName(), property.getValue());
}
writer.writeEndElement();
}
private static void writeElectionPolicy(XMLExtendedStreamWriter writer, String name, ModelNode policy) throws XMLStreamException {
switch (name) {
case RandomElectionPolicyResourceDefinition.PATH_VALUE: {
writer.writeStartElement(XMLElement.RANDOM_ELECTION_POLICY.getLocalName());
break;
}
case SimpleElectionPolicyResourceDefinition.PATH_VALUE: {
writer.writeStartElement(XMLElement.SIMPLE_ELECTION_POLICY.getLocalName());
writeAttributes(writer, policy, SimpleElectionPolicyResourceDefinition.Attribute.class);
break;
}
default: {
throw new IllegalArgumentException(name);
}
}
writeElements(writer, policy, ElectionPolicyResourceDefinition.Attribute.class);
writer.writeEndElement();
}
private static <A extends Enum<A> & Attribute> void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Class<A> attributeClass) throws XMLStreamException {
writeAttributes(writer, model, EnumSet.allOf(attributeClass));
}
private static void writeAttributes(XMLExtendedStreamWriter writer, ModelNode model, Iterable<? extends Attribute> attributes) throws XMLStreamException {
for (Attribute attribute : attributes) {
writeAttribute(writer, model, attribute);
}
}
private static void writeAttribute(XMLExtendedStreamWriter writer, ModelNode model, Attribute attribute) throws XMLStreamException {
attribute.getDefinition().getMarshaller().marshallAsAttribute(attribute.getDefinition(), model, false, writer);
}
private static <A extends Enum<A> & Attribute> void writeElements(XMLExtendedStreamWriter writer, ModelNode model, Class<A> attributeClass) throws XMLStreamException {
writeElements(writer, model, EnumSet.allOf(attributeClass));
}
private static void writeElements(XMLExtendedStreamWriter writer, ModelNode model, Iterable<? extends Attribute> attributes) throws XMLStreamException {
for (Attribute attribute : attributes) {
writeElement(writer, model, attribute);
}
}
private static void writeElement(XMLExtendedStreamWriter writer, ModelNode model, Attribute attribute) throws XMLStreamException {
attribute.getDefinition().getMarshaller().marshallAsElement(attribute.getDefinition(), model, false, writer);
}
}
| 5,718
| 44.031496
| 173
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/ElectionPolicyResourceDefinition.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;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ResourceServiceConfiguratorFactory;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.SimpleResourceRegistrar;
import org.jboss.as.clustering.controller.SimpleResourceServiceHandler;
import org.jboss.as.clustering.controller.UnaryCapabilityNameResolver;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.StringListAttributeDefinition;
import org.jboss.as.controller.capability.RuntimeCapability;
import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.wildfly.clustering.singleton.SingletonElectionPolicy;
/**
* Definition of an election policy resource.
* @author Paul Ferraro
*/
public abstract class ElectionPolicyResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
static PathElement pathElement(String value) {
return PathElement.pathElement("election-policy", value);
}
enum Capability implements org.jboss.as.clustering.controller.Capability {
ELECTION_POLICY("org.wildfly.clustering.singleton-policy.election", SingletonElectionPolicy.class),
;
private final RuntimeCapability<Void> definition;
Capability(String name, Class<?> type) {
this.definition = RuntimeCapability.Builder.of(name, true).setServiceType(type).setDynamicNameMapper(UnaryCapabilityNameResolver.PARENT).build();
}
@Override
public RuntimeCapability<Void> getDefinition() {
return this.definition;
}
}
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<StringListAttributeDefinition.Builder> {
NAME_PREFERENCES("name-preferences", "socket-binding-preferences"),
SOCKET_BINDING_PREFERENCES("socket-binding-preferences", "name-preferences") {
@Override
public StringListAttributeDefinition.Builder apply(StringListAttributeDefinition.Builder builder) {
return builder.setAllowExpression(false)
.setCapabilityReference(new CapabilityReference(Capability.ELECTION_POLICY, CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING))
;
}
}
;
private final AttributeDefinition definition;
Attribute(String name, String alternative) {
this.definition = this.apply(new StringListAttributeDefinition.Builder(name).setAllowExpression(true))
.setAlternatives(alternative)
.setRequired(false)
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
@Override
public StringListAttributeDefinition.Builder apply(StringListAttributeDefinition.Builder builder) {
return builder;
}
}
private final UnaryOperator<ResourceDescriptor> configurator;
private final ResourceServiceConfiguratorFactory serviceConfiguratorFactory;
ElectionPolicyResourceDefinition(PathElement path, ResourceDescriptionResolver resolver, UnaryOperator<ResourceDescriptor> configurator, ResourceServiceConfiguratorFactory serviceConfiguratorFactory) {
super(path, resolver);
this.configurator = configurator;
this.serviceConfiguratorFactory = serviceConfiguratorFactory;
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = this.configurator.apply(new ResourceDescriptor(this.getResourceDescriptionResolver()))
.addAttributes(ElectionPolicyResourceDefinition.Attribute.class)
.addCapabilities(ElectionPolicyResourceDefinition.Capability.class)
;
ResourceServiceHandler handler = new SimpleResourceServiceHandler(this.serviceConfiguratorFactory);
new SimpleResourceRegistrar(descriptor, handler).register(registration);
return registration;
}
}
| 5,879
| 45.299213
| 205
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/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.extension.clustering.singleton;
import org.jboss.msc.service.LifecycleListener;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.service.ServiceConfigurator;
/**
* @author Paul Ferraro
*/
public class SingletonServiceConfigurator implements ServiceConfigurator {
private final ServiceConfigurator configurator;
private final LifecycleListener listener;
public SingletonServiceConfigurator(ServiceConfigurator configurator, LifecycleListener listener) {
this.configurator = configurator;
this.listener = listener;
}
@Override
public ServiceName getServiceName() {
return this.configurator.getServiceName();
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
return this.configurator.build(target).addListener(this.listener);
}
}
| 1,980
| 35.685185
| 103
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonPolicyResourceDefinition.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;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityProvider;
import org.jboss.as.clustering.controller.CapabilityReference;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.ManagementResourceRegistration;
import org.jboss.as.clustering.controller.ResourceDescriptor;
import org.jboss.as.clustering.controller.ServiceValueExecutorRegistry;
import org.jboss.as.clustering.controller.ResourceServiceHandler;
import org.jboss.as.clustering.controller.SimpleResourceRegistrar;
import org.jboss.as.clustering.controller.UnaryRequirementCapability;
import org.jboss.as.clustering.controller.validation.IntRangeValidatorBuilder;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.clustering.service.UnaryRequirement;
import org.wildfly.clustering.singleton.Singleton;
import org.wildfly.clustering.singleton.SingletonCacheRequirement;
import org.wildfly.clustering.singleton.SingletonDefaultCacheRequirement;
import org.wildfly.clustering.singleton.SingletonRequirement;
/**
* Definition of a singleton policy resource.
* @author Paul Ferraro
*/
public class SingletonPolicyResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
static PathElement pathElement(String value) {
return PathElement.pathElement("singleton-policy", value);
}
enum Capability implements CapabilityProvider {
@Deprecated LEGACY_POLICY(SingletonRequirement.SINGLETON_POLICY),
POLICY(SingletonRequirement.POLICY),
;
private final org.jboss.as.clustering.controller.Capability capability;
Capability(UnaryRequirement requirement) {
this.capability = new UnaryRequirementCapability(requirement);
}
@Override
public org.jboss.as.clustering.controller.Capability getCapability() {
return this.capability;
}
}
enum Attribute implements org.jboss.as.clustering.controller.Attribute, UnaryOperator<SimpleAttributeDefinitionBuilder> {
CACHE_CONTAINER("cache-container", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setRequired(true)
.setCapabilityReference(new CapabilityReference(Capability.POLICY, SingletonDefaultCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY))
;
}
},
CACHE("cache", ModelType.STRING) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setRequired(false)
.setCapabilityReference(new CapabilityReference(Capability.POLICY, SingletonCacheRequirement.SINGLETON_SERVICE_CONFIGURATOR_FACTORY, CACHE_CONTAINER))
;
}
},
QUORUM("quorum", ModelType.INT) {
@Override
public SimpleAttributeDefinitionBuilder apply(SimpleAttributeDefinitionBuilder builder) {
return builder.setRequired(false)
.setAllowExpression(true)
.setDefaultValue(new ModelNode(1))
.setValidator(new IntRangeValidatorBuilder().min(1).configure(builder).build())
;
}
},
;
private final AttributeDefinition definition;
Attribute(String name, ModelType type) {
this.definition = this.apply(new SimpleAttributeDefinitionBuilder(name, type))
.setFlags(AttributeAccess.Flag.RESTART_RESOURCE_SERVICES)
.build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
SingletonPolicyResourceDefinition() {
super(WILDCARD_PATH, SingletonExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH));
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver())
.addAttributes(Attribute.class)
.addCapabilities(Capability.class)
.addRequiredSingletonChildren(SimpleElectionPolicyResourceDefinition.PATH)
.setResourceTransformation(SingletonPolicyResource::new)
;
ServiceValueExecutorRegistry<Singleton> executors = new ServiceValueExecutorRegistry<>();
ResourceServiceHandler handler = new SingletonPolicyServiceHandler(executors);
new SimpleResourceRegistrar(descriptor, handler).register(registration);
new RandomElectionPolicyResourceDefinition().register(registration);
new SimpleElectionPolicyResourceDefinition().register(registration);
if (registration.isRuntimeOnlyRegistrationValid()) {
new SingletonDeploymentResourceDefinition(executors).register(registration);
new SingletonServiceResourceDefinition(executors).register(registration);
}
return registration;
}
}
| 6,730
| 44.47973
| 174
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SimpleElectionPolicyResourceDefinition.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;
import org.jboss.as.clustering.controller.SimpleResourceDescriptorConfigurator;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.SimpleAttributeDefinition;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
/**
* Definition of a simple election policy resource.
* @author Paul Ferraro
*/
public class SimpleElectionPolicyResourceDefinition extends ElectionPolicyResourceDefinition {
static final String PATH_VALUE = "simple";
static final PathElement PATH = pathElement(PATH_VALUE);
enum Attribute implements org.jboss.as.clustering.controller.Attribute {
POSITION("position", ModelType.INT, ModelNode.ZERO),
;
private final SimpleAttributeDefinition definition;
Attribute(String name, ModelType type, ModelNode defaultValue) {
this.definition = new SimpleAttributeDefinitionBuilder(name, type)
.setAllowExpression(true)
.setRequired(false)
.setDefaultValue(defaultValue)
.build();
}
@Override
public SimpleAttributeDefinition getDefinition() {
return this.definition;
}
}
SimpleElectionPolicyResourceDefinition() {
super(PATH, SingletonExtension.SUBSYSTEM_RESOLVER.createChildResolver(PATH, WILDCARD_PATH), new SimpleResourceDescriptorConfigurator<>(Attribute.class), SimpleElectionPolicyServiceConfigurator::new);
}
}
| 2,610
| 39.796875
| 207
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonResourceTransformer.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.extension.clustering.singleton;
import java.util.function.Function;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
import org.jboss.as.controller.transform.description.TransformationDescription;
import org.jboss.as.controller.transform.description.TransformationDescriptionBuilder;
/**
* @author Paul Ferraro
*/
public class SingletonResourceTransformer implements Function<ModelVersion, TransformationDescription> {
private final ResourceTransformationDescriptionBuilder builder = TransformationDescriptionBuilder.Factory.createSubsystemInstance();
@Override
public TransformationDescription apply(ModelVersion version) {
new SingletonPolicyResourceTransformer(this.builder).accept(version);
return this.builder.build();
}
}
| 1,903
| 40.391304
| 136
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonServiceResourceDefinition.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.singleton;
import org.jboss.as.clustering.controller.ChildResourceDefinition;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.ManagementResourceRegistration;
import org.jboss.as.clustering.controller.MetricHandler;
import org.jboss.as.controller.PathElement;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.singleton.Singleton;
/**
* @author Paul Ferraro
*/
public class SingletonServiceResourceDefinition extends ChildResourceDefinition<ManagementResourceRegistration> {
static final PathElement WILDCARD_PATH = pathElement(PathElement.WILDCARD_VALUE);
static PathElement pathElement(ServiceName name) {
return pathElement(name.getCanonicalName());
}
static PathElement pathElement(String name) {
return PathElement.pathElement("service", name);
}
private final FunctionExecutorRegistry<Singleton> executors;
public SingletonServiceResourceDefinition(FunctionExecutorRegistry<Singleton> executors) {
super(new Parameters(WILDCARD_PATH, SingletonExtension.SUBSYSTEM_RESOLVER.createChildResolver(WILDCARD_PATH)).setRuntime());
this.executors = executors;
}
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = parent.registerSubModel(this);
new MetricHandler<>(new SingletonServiceMetricExecutor(this.executors), SingletonMetric.class).register(registration);
return registration;
}
}
| 2,636
| 41.532258
| 132
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonPolicyResourceTransformer.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.extension.clustering.singleton;
import java.util.function.Consumer;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder;
/**
* Transforms the singleton policy resource.
* @author Paul Ferraro
*/
public class SingletonPolicyResourceTransformer implements Consumer<ModelVersion> {
private final ResourceTransformationDescriptionBuilder builder;
SingletonPolicyResourceTransformer(ResourceTransformationDescriptionBuilder parent) {
this.builder = parent.addChildResource(SingletonPolicyResourceDefinition.WILDCARD_PATH);
}
@Override
public void accept(ModelVersion version) {
if (SingletonSubsystemModel.VERSION_3_0_0.requiresTransformation(version)) {
this.builder.discardChildResource(SingletonDeploymentResourceDefinition.WILDCARD_PATH);
this.builder.discardChildResource(SingletonServiceResourceDefinition.WILDCARD_PATH);
}
}
}
| 2,041
| 39.84
| 99
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonMetricExecutor.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.singleton;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jboss.as.clustering.controller.FunctionExecutor;
import org.jboss.as.clustering.controller.FunctionExecutorRegistry;
import org.jboss.as.clustering.controller.Metric;
import org.jboss.as.clustering.controller.MetricExecutor;
import org.jboss.as.clustering.controller.MetricFunction;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.singleton.Singleton;
import org.wildfly.common.function.ExceptionFunction;
/**
* Generic executor for singleton metrics.
* @author Paul Ferraro
*/
public class SingletonMetricExecutor implements MetricExecutor<Singleton> {
private final Function<String, ServiceName> serviceNameFactory;
private final FunctionExecutorRegistry<Singleton> executors;
public SingletonMetricExecutor(Function<String, ServiceName> serviceNameFactory, FunctionExecutorRegistry<Singleton> executors) {
this.serviceNameFactory = serviceNameFactory;
this.executors = executors;
}
@Override
public ModelNode execute(OperationContext context, Metric<Singleton> metric) throws OperationFailedException {
ServiceName name = this.serviceNameFactory.apply(context.getCurrentAddressValue());
FunctionExecutor<Singleton> executor = this.executors.get(name.append("singleton"));
return ((executor != null) ? executor : new LegacySingletonFunctionExecutor(context, name)).execute(new MetricFunction<>(Function.identity(), metric));
}
@Deprecated
private static class LegacySingletonFunctionExecutor implements FunctionExecutor<Singleton> {
private final Singleton singleton;
@SuppressWarnings("unchecked")
LegacySingletonFunctionExecutor(OperationContext context, ServiceName name) {
this.singleton = (Singleton) ((Supplier<org.jboss.msc.service.Service<?>>) context.getServiceRegistry(false).getRequiredService(name).getService()).get();
}
@Override
public <R, E extends Exception> R execute(ExceptionFunction<Singleton, R, E> function) throws E {
return function.apply(this.singleton);
}
}
}
| 3,382
| 43.513158
| 166
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/ElectionPolicyServiceConfigurator.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;
import static org.wildfly.extension.clustering.singleton.ElectionPolicyResourceDefinition.Attribute.NAME_PREFERENCES;
import static org.wildfly.extension.clustering.singleton.ElectionPolicyResourceDefinition.Attribute.SOCKET_BINDING_PREFERENCES;
import static org.wildfly.extension.clustering.singleton.ElectionPolicyResourceDefinition.Capability.ELECTION_POLICY;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import org.jboss.as.clustering.controller.CapabilityServiceNameProvider;
import org.jboss.as.clustering.controller.CommonUnaryRequirement;
import org.jboss.as.clustering.controller.ResourceServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.network.OutboundSocketBinding;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.service.Dependency;
import org.wildfly.clustering.service.FunctionalService;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
import org.wildfly.clustering.singleton.SingletonElectionPolicy;
import org.wildfly.clustering.singleton.election.NamePreference;
import org.wildfly.clustering.singleton.election.Preference;
import org.wildfly.clustering.singleton.election.PreferredSingletonElectionPolicy;
import org.wildfly.extension.clustering.singleton.election.OutboundSocketBindingPreference;
/**
* Builds a service that provides an election policy.
* @author Paul Ferraro
*/
public abstract class ElectionPolicyServiceConfigurator extends CapabilityServiceNameProvider implements ResourceServiceConfigurator, Supplier<SingletonElectionPolicy>, UnaryOperator<SingletonElectionPolicy> {
private volatile List<Preference> preferences;
private volatile List<Dependency> dependencies;
protected ElectionPolicyServiceConfigurator(PathAddress address) {
super(ELECTION_POLICY, address);
}
@Override
public SingletonElectionPolicy apply(SingletonElectionPolicy policy) {
return this.preferences.isEmpty() ? policy : new PreferredSingletonElectionPolicy(policy, this.preferences);
}
@Override
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<SingletonElectionPolicy> policy = builder.provides(this.getServiceName());
for (Dependency dependency : this.dependencies) {
dependency.register(builder);
}
Service service = new FunctionalService<>(policy, this, this);
return builder.setInstance(service);
}
@Override
public ServiceConfigurator configure(OperationContext context, ModelNode model) throws OperationFailedException {
List<ModelNode> socketBindingPreferences = SOCKET_BINDING_PREFERENCES.resolveModelAttribute(context, model).asListOrEmpty();
List<ModelNode> namePreferences = NAME_PREFERENCES.resolveModelAttribute(context, model).asListOrEmpty();
List<Preference> preferences = new ArrayList<>(socketBindingPreferences.size() + namePreferences.size());
List<Dependency> dependencies = new ArrayList<>(socketBindingPreferences.size());
for (ModelNode preference : socketBindingPreferences) {
SupplierDependency<OutboundSocketBinding> binding = new ServiceSupplierDependency<>(CommonUnaryRequirement.OUTBOUND_SOCKET_BINDING.getServiceName(context, preference.asString()));
preferences.add(new OutboundSocketBindingPreference(binding));
dependencies.add(binding);
}
for (ModelNode preference : namePreferences) {
preferences.add(new NamePreference(preference.asString()));
}
this.dependencies = dependencies;
this.preferences = preferences;
return this;
}
}
| 5,245
| 48.961905
| 209
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonExtensionTransformerRegistration.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.singleton;
import java.util.EnumSet;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.transform.ExtensionTransformerRegistration;
import org.jboss.as.controller.transform.SubsystemTransformerRegistration;
import org.jboss.as.controller.transform.description.TransformationDescription;
import org.kohsuke.MetaInfServices;
/**
* Transformer registration for the singleton subsystem.
* @author Paul Ferraro
*/
@MetaInfServices(ExtensionTransformerRegistration.class)
public class SingletonExtensionTransformerRegistration implements ExtensionTransformerRegistration {
@Override
public String getSubsystemName() {
return SingletonExtension.SUBSYSTEM_NAME;
}
@Override
public void registerTransformers(SubsystemTransformerRegistration registration) {
// Register transformers for all but the current model
for (SingletonSubsystemModel model : EnumSet.complementOf(EnumSet.of(SingletonSubsystemModel.CURRENT))) {
ModelVersion version = model.getVersion();
TransformationDescription.Tools.register(new SingletonResourceTransformer().apply(version), registration, version);
}
}
}
| 2,252
| 40.722222
| 127
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/SingletonMetric.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.singleton;
import org.jboss.as.clustering.controller.Metric;
import org.jboss.as.controller.AttributeDefinition;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.StringListAttributeDefinition;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.singleton.Singleton;
/**
* Metrics for singleton deployments and services.
* @author Paul Ferraro
*/
public enum SingletonMetric implements Metric<Singleton> {
IS_PRIMARY("is-primary", ModelType.BOOLEAN) {
@Override
public ModelNode execute(Singleton singleton) throws OperationFailedException {
return new ModelNode(singleton.isPrimary());
}
},
PRIMARY_PROVIDER("primary-provider", ModelType.STRING) {
@Override
public ModelNode execute(Singleton singleton) throws OperationFailedException {
Node primary = singleton.getPrimaryProvider();
return (primary != null) ? new ModelNode(primary.getName()) : null;
}
},
PROVIDERS("providers") {
@Override
public ModelNode execute(Singleton singleton) throws OperationFailedException {
ModelNode result = new ModelNode();
for (Node provider : singleton.getProviders()) {
result.add(provider.getName());
}
return result;
}
}
;
private final AttributeDefinition definition;
SingletonMetric(String name, ModelType type) {
this.definition = new SimpleAttributeDefinitionBuilder(name, type).setStorageRuntime().build();
}
SingletonMetric(String name) {
this.definition = new StringListAttributeDefinition.Builder(name).setStorageRuntime().build();
}
@Override
public AttributeDefinition getDefinition() {
return this.definition;
}
}
| 3,033
| 36.925
| 103
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/election/OutboundSocketBindingPreference.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.election;
import java.net.UnknownHostException;
import java.util.function.Supplier;
import org.jboss.as.network.OutboundSocketBinding;
import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.singleton.election.Preference;
/**
* An election policy preference defined as an outbound socket binding.
* @author Paul Ferraro
*/
public class OutboundSocketBindingPreference implements Preference {
private final Supplier<OutboundSocketBinding> binding;
public OutboundSocketBindingPreference(Supplier<OutboundSocketBinding> binding) {
this.binding = binding;
}
@Override
public boolean preferred(Node node) {
OutboundSocketBinding binding = this.binding.get();
try {
return binding.getResolvedDestinationAddress().equals(node.getSocketAddress().getAddress()) && (binding.getDestinationPort() == node.getSocketAddress().getPort());
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e);
}
}
}
| 2,093
| 37.777778
| 175
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/SingletonDeploymentXMLReader.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 javax.xml.stream.XMLStreamException;
import org.jboss.as.controller.parsing.ParseUtils;
import org.jboss.staxmapper.XMLElementReader;
import org.jboss.staxmapper.XMLExtendedStreamReader;
/**
* Parses singleton deployment configuration from XML.
* @author Paul Ferraro
*/
public class SingletonDeploymentXMLReader implements XMLElementReader<MutableSingletonDeploymentConfiguration> {
@SuppressWarnings("unused")
private final SingletonDeploymentSchema schema;
public SingletonDeploymentXMLReader(SingletonDeploymentSchema schema) {
this.schema = schema;
}
@Override
public void readElement(XMLExtendedStreamReader reader, MutableSingletonDeploymentConfiguration config) throws XMLStreamException {
for (int i = 0; i < reader.getAttributeCount(); ++i) {
String value = reader.getAttributeValue(i);
switch (reader.getAttributeLocalName(i)) {
case "policy": {
config.setPolicy(value);
break;
}
default: {
throw ParseUtils.unexpectedAttribute(reader, i);
}
}
}
ParseUtils.requireNoContent(reader);
}
}
| 2,323
| 35.888889
| 135
|
java
|
null |
wildfly-main/clustering/singleton/extension/src/main/java/org/wildfly/extension/clustering/singleton/deployment/MutableSingletonDeploymentConfiguration.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.ee.structure.JBossDescriptorPropertyReplacement;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.metadata.property.PropertyReplacer;
/**
* Mutable configuration for a singleton deployment.
* @author Paul Ferraro
*/
public class MutableSingletonDeploymentConfiguration implements SingletonDeploymentConfiguration {
private final PropertyReplacer replacer;
private volatile String policy;
public MutableSingletonDeploymentConfiguration(DeploymentUnit unit) {
this(JBossDescriptorPropertyReplacement.propertyReplacer(unit));
}
public MutableSingletonDeploymentConfiguration(PropertyReplacer replacer) {
this.replacer = replacer;
}
public void setPolicy(String value) {
this.policy = this.replacer.replaceProperties(value);
}
@Override
public String getPolicy() {
return this.policy;
}
}
| 2,001
| 34.75
| 98
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.