Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WFLY-16038 Extract MSC-related classes within wildfly-clustering-infinispan-client into separate module #15266

Merged
merged 3 commits into from Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions clustering/ee/cache/pom.xml
Expand Up @@ -61,10 +61,6 @@
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-marshalling-protostream</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-service</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
Expand Down
@@ -0,0 +1,102 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.clustering.ee.cache.concurrent;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.StampedLock;
import java.util.function.Supplier;

import org.wildfly.clustering.ee.concurrent.ServiceExecutor;
import org.wildfly.common.function.ExceptionRunnable;
import org.wildfly.common.function.ExceptionSupplier;

/**
* {@link ServiceExecutor} implemented via a {@link StampedLock}.
* @author Paul Ferraro
*/
public class StampedLockServiceExecutor implements ServiceExecutor {

private final StampedLock lock = new StampedLock();
private final AtomicBoolean closed = new AtomicBoolean(false);

@Override
public void execute(Runnable executeTask) {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
executeTask.run();
} finally {
this.lock.unlock(stamp);
}
}
}

@Override
public <E extends Exception> void execute(ExceptionRunnable<E> executeTask) throws E {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
executeTask.run();
} finally {
this.lock.unlock(stamp);
}
}
}

@Override
public <R> Optional<R> execute(Supplier<R> executeTask) {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
return Optional.of(executeTask.get());
} finally {
this.lock.unlock(stamp);
}
}
return Optional.empty();
}

@Override
public <R, E extends Exception> Optional<R> execute(ExceptionSupplier<R, E> executeTask) throws E {
long stamp = this.lock.tryReadLock();
if (stamp != 0L) {
try {
return Optional.of(executeTask.get());
} finally {
this.lock.unlock(stamp);
}
}
return Optional.empty();
}

@Override
public void close(Runnable closeTask) {
// Allow only one thread to close
if (this.closed.compareAndSet(false, true)) {
// Closing is final - we don't need the stamp
this.lock.writeLock();
closeTask.run();
}
}
}
Expand Up @@ -20,7 +20,7 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.clustering.service.concurrent;
package org.wildfly.clustering.ee.cache.concurrent;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
Expand All @@ -34,6 +34,7 @@
import java.util.function.Supplier;

import org.junit.Test;
import org.wildfly.clustering.ee.concurrent.ServiceExecutor;
import org.wildfly.common.function.ExceptionRunnable;
import org.wildfly.common.function.ExceptionSupplier;

Expand Down
2 changes: 1 addition & 1 deletion clustering/ee/infinispan/pom.xml
Expand Up @@ -51,7 +51,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-infinispan-spi</artifactId>
<artifactId>wildfly-clustering-infinispan-embedded-spi</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Expand Up @@ -27,8 +27,8 @@
import org.infinispan.Cache;
import org.infinispan.remoting.transport.Address;
import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.infinispan.spi.distribution.CacheKeyDistribution;
import org.wildfly.clustering.infinispan.spi.distribution.KeyDistribution;
import org.wildfly.clustering.infinispan.distribution.CacheKeyDistribution;
import org.wildfly.clustering.infinispan.distribution.KeyDistribution;
import org.wildfly.clustering.spi.NodeFactory;

/**
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.wildfly.clustering.ee.Key;
import org.wildfly.clustering.ee.cache.IdentifierFactory;
import org.wildfly.clustering.ee.infinispan.GroupedKey;
import org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory;
import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory;

/**
* An {@link IdentifierFactory} that uses a {@link KeyAffinityService} to pre-generate locally hashing identifiers from a supplier.
Expand Down
Expand Up @@ -31,7 +31,7 @@
import org.infinispan.Cache;
import org.infinispan.context.Flag;
import org.wildfly.clustering.ee.Key;
import org.wildfly.clustering.infinispan.spi.distribution.Locality;
import org.wildfly.clustering.infinispan.distribution.Locality;

/**
* A task which schedules newly owned entries.
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.infinispan.Cache;
import org.infinispan.context.Flag;
import org.wildfly.clustering.ee.Key;
import org.wildfly.clustering.infinispan.spi.distribution.Locality;
import org.wildfly.clustering.infinispan.distribution.Locality;

/**
* A task which schedules newly owned keys.
Expand Down
Expand Up @@ -22,7 +22,7 @@

package org.wildfly.clustering.ee.infinispan.scheduler;

import org.wildfly.clustering.infinispan.spi.distribution.Locality;
import org.wildfly.clustering.infinispan.distribution.Locality;

/**
* A task scheduler.
Expand Down
Expand Up @@ -45,8 +45,8 @@
import org.wildfly.clustering.context.DefaultExecutorService;
import org.wildfly.clustering.context.DefaultThreadFactory;
import org.wildfly.clustering.ee.Key;
import org.wildfly.clustering.infinispan.spi.distribution.ConsistentHashLocality;
import org.wildfly.clustering.infinispan.spi.distribution.Locality;
import org.wildfly.clustering.infinispan.distribution.ConsistentHashLocality;
import org.wildfly.clustering.infinispan.distribution.Locality;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.infinispan.remoting.transport.Address;
import org.junit.Test;
import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.infinispan.spi.distribution.KeyDistribution;
import org.wildfly.clustering.infinispan.distribution.KeyDistribution;
import org.wildfly.clustering.spi.NodeFactory;

/**
Expand Down
Expand Up @@ -45,7 +45,7 @@
import org.wildfly.clustering.ee.Key;
import org.wildfly.clustering.ee.cache.IdentifierFactory;
import org.wildfly.clustering.ee.infinispan.GroupedKey;
import org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory;
import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory;

/**
* Unit test for {@link AffinityIdentifierFactory}
Expand Down
@@ -0,0 +1,71 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2015, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.wildfly.clustering.ee.concurrent;

import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.function.Supplier;

import org.wildfly.common.function.ExceptionRunnable;
import org.wildfly.common.function.ExceptionSupplier;

/**
* Allows safe invocation of tasks that require resources not available after {@link #close(Runnable)} to block a service from stopping.
* @author Paul Ferraro
*/
public interface ServiceExecutor extends Executor {

/**
* Executes the specified runner.
* @param <E> the exception type
* @param runner a runnable task
* @throws E if execution fails
*/
<E extends Exception> void execute(ExceptionRunnable<E> runner) throws E;

/**
* Executes the specified task, but only if the service was not already closed.
* If service is already closed, the task is not run.
* If executed, the specified task must return a non-null value, to be distinguishable from a non-execution.
* @param executeTask a task to execute
* @return an optional value that is present only if the specified task was run.
*/
<R> Optional<R> execute(Supplier<R> executeTask);

/**
* Executes the specified task, but only if the service was not already closed.
* If service is already closed, the task is not run.
* If executed, the specified task must return a non-null value, to be distinguishable from a non-execution.
* @param executeTask a task to execute
* @return an optional value that is present only if the specified task was run.
* @throws E if the task execution failed
*/
<R, E extends Exception> Optional<R> execute(ExceptionSupplier<R, E> executeTask) throws E;

/**
* Closes the service, executing the specified task, first waiting for any concurrent executions to complete.
* The specified task will only execute once, irrespective on subsequent {@link #close(Runnable)} invocations.
* @param closeTask a task which closes the service
*/
void close(Runnable closeTask);
}
Expand Up @@ -39,8 +39,8 @@
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelType;
import org.wildfly.clustering.ejb.EjbProviderRequirement;
import org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.spi.InfinispanDefaultCacheRequirement;
import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement;
import org.wildfly.clustering.service.UnaryRequirement;

import java.util.function.UnaryOperator;
Expand Down
Expand Up @@ -28,8 +28,8 @@
import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
import org.jboss.as.controller.registry.AttributeAccess;
import org.jboss.dmr.ModelType;
import org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.spi.InfinispanDefaultCacheRequirement;
import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement;

import java.util.function.UnaryOperator;

Expand Down
Expand Up @@ -32,8 +32,8 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.spi.InfinispanDefaultCacheRequirement;
import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.service.InfinispanDefaultCacheRequirement;

import java.util.EnumSet;

Expand Down
8 changes: 6 additions & 2 deletions clustering/ejb/infinispan/pom.xml
Expand Up @@ -67,7 +67,11 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-infinispan-spi</artifactId>
<artifactId>wildfly-clustering-infinispan-embedded-service</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-infinispan-embedded-spi</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -101,7 +105,7 @@
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-clustering-infinispan-spi</artifactId>
<artifactId>wildfly-clustering-infinispan-embedded-spi</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
Expand Down
Expand Up @@ -36,7 +36,7 @@
import org.wildfly.clustering.ejb.infinispan.bean.InfinispanBeanKey;
import org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger;
import org.wildfly.clustering.group.Group;
import org.wildfly.clustering.infinispan.spi.distribution.Locality;
import org.wildfly.clustering.infinispan.distribution.Locality;

/**
* Schedules a bean for expiration.
Expand Down
Expand Up @@ -37,15 +37,15 @@
import org.jboss.as.server.deployment.Services;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.ee.CompositeIterable;
import org.wildfly.clustering.ejb.StatefulBeanConfiguration;
import org.wildfly.clustering.ejb.BeanManagerFactory;
import org.wildfly.clustering.ejb.BeanManagerFactoryServiceConfiguratorConfiguration;
import org.wildfly.clustering.ejb.BeanManagementProvider;
import org.wildfly.clustering.ejb.StatefulBeanConfiguration;
import org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger;
import org.wildfly.clustering.infinispan.spi.DataContainerConfigurationBuilder;
import org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.spi.service.CacheServiceConfigurator;
import org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationServiceConfigurator;
import org.wildfly.clustering.infinispan.container.DataContainerConfigurationBuilder;
import org.wildfly.clustering.infinispan.service.CacheServiceConfigurator;
import org.wildfly.clustering.infinispan.service.InfinispanCacheRequirement;
import org.wildfly.clustering.infinispan.service.TemplateConfigurationServiceConfigurator;
import org.wildfly.clustering.service.ServiceDependency;
import org.wildfly.clustering.service.ServiceNameRegistry;
import org.wildfly.clustering.spi.CacheServiceConfiguratorProvider;
Expand Down
Expand Up @@ -56,9 +56,9 @@
import org.wildfly.clustering.ejb.infinispan.logging.InfinispanEjbLogger;
import org.wildfly.clustering.group.Group;
import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.infinispan.spi.distribution.CacheLocality;
import org.wildfly.clustering.infinispan.spi.distribution.Locality;
import org.wildfly.clustering.infinispan.spi.distribution.SimpleLocality;
import org.wildfly.clustering.infinispan.distribution.CacheLocality;
import org.wildfly.clustering.infinispan.distribution.Locality;
import org.wildfly.clustering.infinispan.distribution.SimpleLocality;
import org.wildfly.clustering.spi.dispatcher.CommandDispatcherFactory;

/**
Expand Down
Expand Up @@ -26,7 +26,7 @@

import org.infinispan.remoting.transport.Address;
import org.wildfly.clustering.ee.cache.CacheProperties;
import org.wildfly.clustering.infinispan.spi.affinity.KeyAffinityServiceFactory;
import org.wildfly.clustering.infinispan.affinity.KeyAffinityServiceFactory;
import org.wildfly.clustering.spi.dispatcher.CommandDispatcherFactory;
import org.wildfly.clustering.spi.group.Group;

Expand Down