Skip to content

Commit

Permalink
Fix usage of deprecated wildfly-clustering-common/service API in wild…
Browse files Browse the repository at this point in the history
…fly-ejb3 and wildfly-clustering-ejb-spi
  • Loading branch information
pferraro committed Jun 8, 2018
1 parent 786efe9 commit 92c14f9
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 152 deletions.
Expand Up @@ -40,7 +40,7 @@ public interface CacheFactoryBuilder<K, V extends Identifiable<K>> {

void installDeploymentUnitDependencies(CapabilityServiceSupport support, ServiceTarget target, ServiceName deploymentUnitServiceName);

ServiceBuilder<? extends CacheFactory<K, V>> build(ServiceTarget target, ServiceName name, BeanContext context, StatefulTimeoutInfo timeout);
ServiceBuilder<?> build(ServiceTarget target, ServiceName name, BeanContext context, StatefulTimeoutInfo timeout);

/**
* Indicates whether or not cache factories built by this object can support passivation.
Expand Down
Expand Up @@ -22,15 +22,15 @@
package org.jboss.as.ejb3.cache.distributable;

import java.util.ServiceLoader;
import java.util.function.Consumer;

import org.jboss.as.clustering.controller.CapabilityServiceConfigurator;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.ejb3.cache.CacheFactory;
import org.jboss.as.ejb3.cache.CacheFactoryBuilderService;
import org.jboss.as.ejb3.cache.Contextual;
import org.jboss.as.ejb3.cache.Identifiable;
import org.jboss.as.ejb3.component.stateful.StatefulTimeoutInfo;
import org.jboss.msc.service.AbstractService;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
Expand All @@ -40,20 +40,20 @@
import org.wildfly.clustering.ejb.BeanManagerFactoryServiceConfiguratorFactory;
import org.wildfly.clustering.ejb.BeanManagerFactoryServiceConfiguratorFactoryProvider;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.SimpleServiceNameProvider;

/**
* Service that returns a distributable {@link org.jboss.as.ejb3.cache.CacheFactoryBuilder}.
* @author Paul Ferraro
* @param <K> the cache key type
* @param <V> the cache value type
*/
public class DistributableCacheFactoryBuilderService<K, V extends Identifiable<K> & Contextual<Batch>> extends AbstractService<DistributableCacheFactoryBuilder<K, V>> implements DistributableCacheFactoryBuilder<K, V> {
public class DistributableCacheFactoryBuilderService<K, V extends Identifiable<K> & Contextual<Batch>> extends SimpleServiceNameProvider implements ServiceConfigurator, DistributableCacheFactoryBuilder<K, V> {

public static ServiceName getServiceName(String name) {
return CacheFactoryBuilderService.BASE_CACHE_FACTORY_SERVICE_NAME.append("distributable", name);
}

private final String name;
private final BeanManagerFactoryServiceConfiguratorFactory builder;
private final BeanManagerFactoryServiceConfiguratorConfiguration config;

Expand All @@ -69,18 +69,17 @@ private static BeanManagerFactoryServiceConfiguratorFactoryProvider load() {
}

public DistributableCacheFactoryBuilderService(CapabilityServiceSupport support, String name, BeanManagerFactoryServiceConfiguratorFactoryProvider provider, BeanManagerFactoryServiceConfiguratorConfiguration config) {
this.name = name;
super(getServiceName(name));
this.config = config;
this.builder = provider.getBeanManagerFactoryBuilder(support, name, config);
}

public ServiceBuilder<DistributableCacheFactoryBuilder<K, V>> build(ServiceTarget target) {
return target.addService(getServiceName(this.name), this);
}

@Override
public DistributableCacheFactoryBuilder<K, V> getValue() {
return this;
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.getServiceName());
Consumer<DistributableCacheFactoryBuilder<K, V>> cacheFactoryBuilder = builder.provides(this.getServiceName());
Service service = Service.newInstance(cacheFactoryBuilder, this);
return builder.setInstance(service);
}

@Override
Expand All @@ -96,7 +95,7 @@ public void installDeploymentUnitDependencies(CapabilityServiceSupport support,
}

@Override
public ServiceBuilder<? extends CacheFactory<K, V>> build(ServiceTarget target, ServiceName serviceName, BeanContext context, StatefulTimeoutInfo statefulTimeout) {
public ServiceBuilder<?> build(ServiceTarget target, ServiceName serviceName, BeanContext context, StatefulTimeoutInfo statefulTimeout) {
ServiceConfigurator configurator = this.builder.getBeanManagerFactoryServiceConfigurator(context);
return new DistributableCacheFactoryService<K, V>(serviceName, configurator).build(target);
}
Expand Down
Expand Up @@ -4,6 +4,9 @@
*/
package org.jboss.as.ejb3.cache.distributable;

import java.util.function.Consumer;
import java.util.function.Supplier;

import javax.transaction.TransactionSynchronizationRegistry;

import org.jboss.as.ejb3.cache.Cache;
Expand All @@ -12,19 +15,17 @@
import org.jboss.as.ejb3.cache.Identifiable;
import org.jboss.as.ejb3.cache.StatefulObjectFactory;
import org.jboss.as.txn.service.TxnServices;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.ValueService;
import org.jboss.msc.value.InjectedValue;
import org.jboss.msc.value.Value;
import org.wildfly.clustering.ee.Batch;
import org.wildfly.clustering.ejb.BeanManager;
import org.wildfly.clustering.ejb.BeanManagerFactory;
import org.wildfly.clustering.ejb.IdentifierFactory;
import org.wildfly.clustering.ejb.PassivationListener;
import org.wildfly.clustering.service.Builder;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.SimpleServiceNameProvider;

/**
* Service that provides a distributable {@link CacheFactory}.
Expand All @@ -33,41 +34,31 @@
* @param <K> the cache key type
* @param <V> the cache value type
*/
public class DistributableCacheFactoryService<K, V extends Identifiable<K> & Contextual<Batch>> implements Builder<CacheFactory<K, V>>, Value<CacheFactory<K, V>>, CacheFactory<K, V> {
public class DistributableCacheFactoryService<K, V extends Identifiable<K> & Contextual<Batch>> extends SimpleServiceNameProvider implements ServiceConfigurator, CacheFactory<K, V> {

private final ServiceName name;
private final ServiceConfigurator configurator;
@SuppressWarnings("rawtypes")
private final InjectedValue<BeanManagerFactory> factory = new InjectedValue<>();
private final InjectedValue<TransactionSynchronizationRegistry> tsr = new InjectedValue<>();
private volatile Supplier<BeanManagerFactory<K, V, Batch>> factory;
private volatile Supplier<TransactionSynchronizationRegistry> tsr;

public DistributableCacheFactoryService(ServiceName name, ServiceConfigurator configurator) {
this.name = name;
super(name);
this.configurator = configurator;
}

@Override
public ServiceName getServiceName() {
return this.name;
}

@Override
public ServiceBuilder<CacheFactory<K, V>> build(ServiceTarget target) {
public ServiceBuilder<?> build(ServiceTarget target) {
this.configurator.build(target).install();
return target.addService(this.name, new ValueService<>(this))
.addDependency(this.configurator.getServiceName(), BeanManagerFactory.class, this.factory)
.addDependency(TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY, TransactionSynchronizationRegistry.class, this.tsr)
;
}

@Override
public CacheFactory<K, V> getValue() {
return this;
ServiceBuilder<?> builder = target.addService(this.getServiceName());
this.factory = builder.requires(this.configurator.getServiceName());
this.tsr = builder.requires(TxnServices.JBOSS_TXN_SYNCHRONIZATION_REGISTRY);
Consumer<CacheFactory<K, V>> factory = builder.provides(this.getServiceName());
Service service = Service.newInstance(factory, this);
return builder.setInstance(service);
}

@Override
public Cache<K, V> createCache(IdentifierFactory<K> identifierFactory, StatefulObjectFactory<V> factory, PassivationListener<V> passivationListener) {
BeanManager<K, V, Batch> manager = this.factory.getValue().createBeanManager(identifierFactory, passivationListener, new RemoveListenerAdapter<>(factory));
return new DistributableCache<>(manager, factory, this.tsr.getValue());
BeanManager<K, V, Batch> manager = this.factory.get().createBeanManager(identifierFactory, passivationListener, new RemoveListenerAdapter<>(factory));
return new DistributableCache<>(manager, factory, this.tsr.get());
}
}

This file was deleted.

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

import java.util.List;

import org.jboss.as.clustering.controller.IdentityCapabilityServiceConfigurator;
import org.jboss.as.network.ClientMapping;
import org.jboss.msc.service.ServiceName;
import org.wildfly.clustering.ejb.BeanManagerFactoryServiceConfiguratorConfiguration;
import org.wildfly.clustering.registry.Registry;
import org.wildfly.clustering.spi.ClusteringCacheRequirement;

/**
* Builds a service providing client mappings for a remote EJB connector.
* @author Paul Ferraro
*/
public class ClientMappingsRegistryServiceConfigurator extends IdentityCapabilityServiceConfigurator<Registry<String, List<ClientMapping>>> {

public static final ServiceName SERVICE_NAME = ServiceName.JBOSS.append("ejb", "remoting", "connector", "client-mappings");

public ClientMappingsRegistryServiceConfigurator(String clientMappingsClusterName) {
super(SERVICE_NAME, ClusteringCacheRequirement.REGISTRY, clientMappingsClusterName, BeanManagerFactoryServiceConfiguratorConfiguration.CLIENT_MAPPINGS_CACHE_NAME);
}
}
Expand Up @@ -28,40 +28,42 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

import org.jboss.as.clustering.controller.CapabilityServiceBuilder;
import org.jboss.as.clustering.controller.CapabilityServiceConfigurator;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.network.ClientMapping;
import org.jboss.as.remoting.RemotingConnectorBindingInfoService;
import org.jboss.msc.Service;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.msc.service.ValueService;
import org.jboss.msc.value.InjectedValue;
import org.jboss.msc.value.Value;
import org.wildfly.clustering.ejb.BeanManagerFactoryServiceConfiguratorConfiguration;
import org.wildfly.clustering.group.Group;
import org.wildfly.clustering.service.Builder;
import org.wildfly.clustering.service.InjectedValueDependency;
import org.wildfly.clustering.service.ValueDependency;
import org.wildfly.clustering.service.CompositeDependency;
import org.wildfly.clustering.service.FunctionalService;
import org.wildfly.clustering.service.ServiceConfigurator;
import org.wildfly.clustering.service.ServiceSupplierDependency;
import org.wildfly.clustering.service.SupplierDependency;
import org.wildfly.clustering.spi.ClusteringCacheRequirement;
import org.wildfly.clustering.spi.ClusteringRequirement;

/**
* @author Jaikiran Pai
*/
public class EJBRemotingConnectorClientMappingsEntryProviderService implements CapabilityServiceBuilder<Map.Entry<String, List<ClientMapping>>>, Value<Map.Entry<String, List<ClientMapping>>> {
public class EJBRemotingConnectorClientMappingsEntryProviderService implements CapabilityServiceConfigurator, Supplier<Map.Entry<String, List<ClientMapping>>> {

private final InjectedValue<RemotingConnectorBindingInfoService.RemotingConnectorInfo> remotingConnectorInfo = new InjectedValue<>();
private final ServiceName remotingServerInfoServiceName;
private final SupplierDependency<RemotingConnectorBindingInfoService.RemotingConnectorInfo> remotingConnectorInfo;

private volatile ValueDependency<Group> group;
private volatile SupplierDependency<Group> group;
private volatile String clientMappingsClusterName;
private volatile ServiceName name;

public EJBRemotingConnectorClientMappingsEntryProviderService(String clientMappingsClusterName, ServiceName remotingServerInfoServiceName) {
public EJBRemotingConnectorClientMappingsEntryProviderService(String clientMappingsClusterName, ServiceName remotingConnectorInfoServiceName) {
this.clientMappingsClusterName = clientMappingsClusterName;
this.remotingServerInfoServiceName = remotingServerInfoServiceName;
this.remotingConnectorInfo = new ServiceSupplierDependency<>(remotingConnectorInfoServiceName);
}

@Override
Expand All @@ -70,28 +72,28 @@ public ServiceName getServiceName() {
}

@Override
public Builder<Map.Entry<String, List<ClientMapping>>> configure(OperationContext context) {
public ServiceConfigurator configure(OperationContext context) {
this.name = ClusteringCacheRequirement.REGISTRY_ENTRY.getServiceName(context, this.clientMappingsClusterName, BeanManagerFactoryServiceConfiguratorConfiguration.CLIENT_MAPPINGS_CACHE_NAME);
this.group = new InjectedValueDependency<>(ClusteringRequirement.GROUP.getServiceName(context, this.clientMappingsClusterName), Group.class);
this.group = new ServiceSupplierDependency<>(ClusteringRequirement.GROUP.getServiceName(context, this.clientMappingsClusterName));
return this;
}

@Override
public ServiceBuilder<Map.Entry<String, List<ClientMapping>>> build(ServiceTarget target) {
ServiceBuilder<Map.Entry<String, List<ClientMapping>>> builder = target.addService(this.name, new ValueService<>(this))
.addDependency(this.remotingServerInfoServiceName, RemotingConnectorBindingInfoService.RemotingConnectorInfo.class, this.remotingConnectorInfo)
;
return this.group.register(builder);
public ServiceBuilder<?> build(ServiceTarget target) {
ServiceBuilder<?> builder = target.addService(this.name);
Consumer<Map.Entry<String, List<ClientMapping>>> entry = new CompositeDependency(this.group, this.remotingConnectorInfo).register(builder).provides(this.name);
Service service = new FunctionalService<>(entry, Function.identity(), this);
return builder.setInstance(service);
}

@Override
public Map.Entry<String, List<ClientMapping>> getValue() {
return new AbstractMap.SimpleImmutableEntry<>(this.group.getValue().getLocalMember().getName(), this.getClientMappings());
public Map.Entry<String, List<ClientMapping>> get() {
return new AbstractMap.SimpleImmutableEntry<>(this.group.get().getLocalMember().getName(), this.getClientMappings());
}

List<ClientMapping> getClientMappings() {
final List<ClientMapping> ret = new ArrayList<>();
RemotingConnectorBindingInfoService.RemotingConnectorInfo info = this.remotingConnectorInfo.getValue();
RemotingConnectorBindingInfoService.RemotingConnectorInfo info = this.remotingConnectorInfo.get();
if (info.getSocketBinding().getClientMappings() != null && !info.getSocketBinding().getClientMappings().isEmpty()) {
ret.addAll(info.getSocketBinding().getClientMappings());
} else {
Expand Down

0 comments on commit 92c14f9

Please sign in to comment.