Skip to content

Commit

Permalink
WFLY-5581 Routing cache should always use REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Oct 27, 2015
1 parent b077f3a commit 79b49a3
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 4 deletions.
@@ -0,0 +1,35 @@
/*
* 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.web.infinispan.session;

import org.wildfly.clustering.spi.DistributedCacheGroupBuilderProvider;

/**
* @author Paul Ferraro
*/
public class DistributedRouteCacheGroupBuilderProvider extends RouteCacheGroupBuilderProvider implements DistributedCacheGroupBuilderProvider {

public DistributedRouteCacheGroupBuilderProvider() {
super(DistributedCacheGroupBuilderProvider.class);
}
}
Expand Up @@ -33,7 +33,6 @@
import org.wildfly.clustering.group.NodeFactory;
import org.wildfly.clustering.registry.Registry;
import org.wildfly.clustering.service.Builder;
import org.wildfly.clustering.spi.CacheGroupServiceName;
import org.wildfly.clustering.web.session.RouteLocator;

/**
Expand All @@ -50,6 +49,14 @@ public static ServiceName getCacheServiceAlias(String deploymentName) {
return getServiceName(deploymentName).append("cache");
}

public static ServiceName getNodeFactoryServiceAlias(String deploymentName) {
return getServiceName(deploymentName).append("nodes");
}

public static ServiceName getRegistryServiceAlias(String deploymentName) {
return getServiceName(deploymentName).append("registry");
}

private final String deploymentName;

@SuppressWarnings("rawtypes")
Expand All @@ -71,8 +78,8 @@ public ServiceName getServiceName() {
@Override
public ServiceBuilder<RouteLocator> build(ServiceTarget target) {
return target.addService(this.getServiceName(), new ValueService<>(this))
.addDependency(CacheGroupServiceName.NODE_FACTORY.getServiceName(InfinispanSessionManagerFactoryBuilder.DEFAULT_CACHE_CONTAINER), NodeFactory.class, this.factory)
.addDependency(CacheGroupServiceName.REGISTRY.getServiceName(InfinispanSessionManagerFactoryBuilder.DEFAULT_CACHE_CONTAINER), Registry.class, this.registry)
.addDependency(getNodeFactoryServiceAlias(this.deploymentName), NodeFactory.class, this.factory)
.addDependency(getRegistryServiceAlias(this.deploymentName), Registry.class, this.registry)
.addDependency(getCacheServiceAlias(this.deploymentName), Cache.class, this.cache)
.setInitialMode(ServiceController.Mode.ON_DEMAND)
;
Expand Down
Expand Up @@ -38,6 +38,8 @@
import org.wildfly.clustering.infinispan.spi.service.CacheBuilder;
import org.wildfly.clustering.infinispan.spi.service.CacheServiceName;
import org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationBuilder;
import org.wildfly.clustering.registry.Registry;
import org.wildfly.clustering.service.AliasServiceBuilder;
import org.wildfly.clustering.service.Builder;
import org.wildfly.clustering.service.SubGroupServiceNameFactory;
import org.wildfly.clustering.spi.CacheGroupServiceName;
Expand Down Expand Up @@ -88,6 +90,9 @@ public ServiceBuilder<SessionManagerFactory<TransactionBatch>> build(ServiceTarg
.addAliases(InfinispanRouteLocatorBuilder.getCacheServiceAlias(cacheName))
.install();

new AliasServiceBuilder<>(InfinispanRouteLocatorBuilder.getNodeFactoryServiceAlias(cacheName), CacheGroupServiceName.NODE_FACTORY.getServiceName(containerName, RouteCacheGroupBuilderProvider.CACHE_NAME), NodeFactory.class).build(target).install();
new AliasServiceBuilder<>(InfinispanRouteLocatorBuilder.getRegistryServiceAlias(cacheName), CacheGroupServiceName.REGISTRY.getServiceName(containerName, RouteCacheGroupBuilderProvider.CACHE_NAME), Registry.class).build(target).install();

return target.addService(this.getServiceName(), new ValueService<>(this))
.addDependency(CacheServiceName.CACHE.getServiceName(containerName, cacheName), Cache.class, this.cache)
.addDependency(CacheContainerServiceName.AFFINITY.getServiceName(containerName), KeyAffinityServiceFactory.class, this.affinityFactory)
Expand Down
@@ -0,0 +1,35 @@
/*
* 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.web.infinispan.session;

import org.wildfly.clustering.spi.LocalCacheGroupBuilderProvider;

/**
* @author Paul Ferraro
*/
public class LocalRouteCacheGroupBuilderProvider extends RouteCacheGroupBuilderProvider implements LocalCacheGroupBuilderProvider {

public LocalRouteCacheGroupBuilderProvider() {
super(LocalCacheGroupBuilderProvider.class);
}
}
@@ -0,0 +1,80 @@
/*
* 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.web.infinispan.session;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;

import org.infinispan.configuration.cache.CacheMode;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.wildfly.clustering.infinispan.spi.service.CacheBuilder;
import org.wildfly.clustering.infinispan.spi.service.TemplateConfigurationBuilder;
import org.wildfly.clustering.service.Builder;
import org.wildfly.clustering.service.SubGroupServiceNameFactory;
import org.wildfly.clustering.spi.CacheGroupAliasBuilderProvider;
import org.wildfly.clustering.spi.CacheGroupBuilderProvider;

/**
* Creates routing services.
* @author Paul Ferraro
*/
public class RouteCacheGroupBuilderProvider implements CacheGroupBuilderProvider, CacheGroupAliasBuilderProvider {

static final String CACHE_NAME = "routing";

private final Class<? extends CacheGroupBuilderProvider> providerClass;

RouteCacheGroupBuilderProvider(Class<? extends CacheGroupBuilderProvider> providerClass) {
this.providerClass = providerClass;
}

@Override
public Collection<Builder<?>> getBuilders(String containerName, String cacheName) {
List<Builder<?>> builders = new LinkedList<>();
if (containerName.equals(InfinispanSessionManagerFactoryBuilder.DEFAULT_CACHE_CONTAINER) && cacheName.equals(SubGroupServiceNameFactory.DEFAULT_SUB_GROUP)) {
builders.add(new TemplateConfigurationBuilder(containerName, CACHE_NAME, cacheName) {
@Override
public ConfigurationBuilder createConfigurationBuilder() {
ConfigurationBuilder builder = super.createConfigurationBuilder();
CacheMode mode = builder.clustering().cacheMode();
builder.clustering().cacheMode(mode.isClustered() ? CacheMode.REPL_SYNC : CacheMode.LOCAL);
builder.persistence().clearStores();
return builder;
}
});
builders.add(new CacheBuilder<>(containerName, CACHE_NAME));
for (CacheGroupBuilderProvider provider : ServiceLoader.load(this.providerClass, this.providerClass.getClassLoader())) {
System.out.println(String.format("RoutingCacheGroupBuilderProvider.getBuilders(%s, %s), provider = %s", containerName, cacheName, provider.getClass().getName()));
builders.addAll(provider.getBuilders(containerName, CACHE_NAME));
}
}
return builders;
}

@Override
public Collection<Builder<?>> getBuilders(String containerName, String aliasCacheName, String targetCacheName) {
return this.getBuilders(containerName, aliasCacheName);
}
}
Expand Up @@ -51,7 +51,7 @@ public RouteRegistryEntryProviderBuilder(Value<? extends Value<String>> route) {

@Override
public ServiceName getServiceName() {
return CacheGroupServiceName.REGISTRY_ENTRY.getServiceName(InfinispanSessionManagerFactoryBuilder.DEFAULT_CACHE_CONTAINER);
return CacheGroupServiceName.REGISTRY_ENTRY.getServiceName(InfinispanSessionManagerFactoryBuilder.DEFAULT_CACHE_CONTAINER, RouteCacheGroupBuilderProvider.CACHE_NAME);
}

@Override
Expand Down
@@ -0,0 +1 @@
org.wildfly.clustering.web.infinispan.session.DistributedRouteCacheGroupBuilderProvider
@@ -0,0 +1 @@
org.wildfly.clustering.web.infinispan.session.DistributedRouteCacheGroupBuilderProvider
@@ -0,0 +1 @@
org.wildfly.clustering.web.infinispan.session.LocalRouteCacheGroupBuilderProvider
Expand Up @@ -26,6 +26,9 @@

import org.junit.Test;
import org.wildfly.clustering.marshalling.Externalizer;
import org.wildfly.clustering.spi.CacheGroupAliasBuilderProvider;
import org.wildfly.clustering.spi.DistributedCacheGroupBuilderProvider;
import org.wildfly.clustering.spi.LocalCacheGroupBuilderProvider;
import org.wildfly.clustering.web.session.RouteLocatorBuilderProvider;
import org.wildfly.clustering.web.session.SessionManagerFactoryBuilderProvider;
import org.wildfly.clustering.web.sso.SSOManagerFactoryBuilderProvider;
Expand All @@ -42,6 +45,9 @@ public void load() {
load(RouteLocatorBuilderProvider.class);
load(SessionManagerFactoryBuilderProvider.class);
load(SSOManagerFactoryBuilderProvider.class);
load(DistributedCacheGroupBuilderProvider.class);
load(LocalCacheGroupBuilderProvider.class);
load(CacheGroupAliasBuilderProvider.class);
}

private static <T> void load(Class<T> targetClass) {
Expand Down
Expand Up @@ -36,5 +36,6 @@
<module name="org.jboss.msc"/>
<module name="org.wildfly.clustering.server" services="import"/>
<module name="org.wildfly.clustering.service"/>
<module name="org.wildfly.clustering.web.infinispan" services="import"/>
</dependencies>
</module>

0 comments on commit 79b49a3

Please sign in to comment.