Skip to content

Commit

Permalink
Deprecate RegistryEntryProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Oct 18, 2016
1 parent 8122ec7 commit a83abbd
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 42 deletions.
Expand Up @@ -99,7 +99,7 @@ interface Listener<K, V> {
Map.Entry<K, V> getEntry(Node node);

/**
* Returns the local registry entry from the {@link RegistryEntryProvider}.
* Returns the local registry entry.
*
* @return the registry entry of the local node
* @deprecated Use {@link #getEntry(Node)} instead.
Expand Down
Expand Up @@ -21,26 +21,20 @@
*/
package org.wildfly.clustering.registry;

import java.util.Map;

/**
* Provides the registry entry for the local node.
*
* @param <K> the type of the registry entry key
* @param <V> the type of the registry entry value
* @author Paul Ferraro
*/
public interface RegistryEntryProvider<K, V> {

/**
* Supplies the unique key for this node's registry entry.
*
* @return a registry entry key
*/
K getKey();
@Deprecated
public interface RegistryEntryProvider<K, V> extends Map.Entry<K, V> {

/**
* Supplies the value for this node's registry entry.
*
* @return a registry entry value
*/
V getValue();
@Override
default V setValue(V value) {
throw new UnsupportedOperationException();
}
}
Expand Up @@ -21,6 +21,8 @@
*/
package org.wildfly.clustering.registry;

import java.util.Map;

/**
* Factory for creating a clustered registry.
*
Expand All @@ -31,10 +33,10 @@
public interface RegistryFactory<K, V> {

/**
* Creates a registry for the group associated with this factory.
* Creates a registry using the specified entry.
*
* @param provider the provider of the local registry entry
* @param entry the local registry entry
* @return a registry
*/
Registry<K, V> createRegistry(RegistryEntryProvider<K, V> provider);
Registry<K, V> createRegistry(Map.Entry<K, V> entry);
}
Expand Up @@ -51,7 +51,6 @@
import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.group.NodeFactory;
import org.wildfly.clustering.registry.Registry;
import org.wildfly.clustering.registry.RegistryEntryProvider;
import org.wildfly.clustering.server.logging.ClusteringServerLogger;
import org.wildfly.clustering.service.concurrent.ServiceExecutor;
import org.wildfly.clustering.service.concurrent.StampedLockServiceExecutor;
Expand All @@ -72,22 +71,22 @@ public class CacheRegistry<K, V> implements Registry<K, V>, KeyFilter<Object> {
private final NodeFactory<Address> factory;
private final Runnable closeTask;
private final ServiceExecutor executor = new StampedLockServiceExecutor();
private final Map.Entry<K, V> registryEntry;
private final Map.Entry<K, V> entry;

public CacheRegistry(CacheRegistryConfiguration<K, V> config, RegistryEntryProvider<K, V> provider, Runnable closeTask) {
public CacheRegistry(CacheRegistryConfiguration<K, V> config, Map.Entry<K, V> entry, Runnable closeTask) {
this.cache = config.getCache();
this.batcher = config.getBatcher();
this.group = config.getGroup();
this.factory = config.getNodeFactory();
this.closeTask = closeTask;
this.registryEntry = new AbstractMap.SimpleImmutableEntry<>(provider.getKey(), provider.getValue());
this.entry = new AbstractMap.SimpleImmutableEntry<>(entry);
this.populateRegistry();
this.cache.addListener(this, new CacheRegistryFilter());
}

private void populateRegistry() {
try (Batch batch = this.batcher.createBatch()) {
this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put(this.group.getLocalNode(), registryEntry);
this.cache.getAdvancedCache().withFlags(Flag.IGNORE_RETURN_VALUES).put(this.group.getLocalNode(), this.entry);
}
}

Expand Down Expand Up @@ -178,7 +177,7 @@ public void topologyChanged(TopologyChangedEvent<Node, Map.Entry<K, V>> event) {
this.populateRegistry();

// Invoke listeners outside above tx context
this.notifyListeners(Event.Type.CACHE_ENTRY_CREATED, registryEntry);
this.notifyListeners(Event.Type.CACHE_ENTRY_CREATED, this.entry);
}
}
});
Expand Down
Expand Up @@ -84,7 +84,7 @@ public Builder<RegistryFactory<K, V>> configure(CapabilityServiceSupport support

@Override
public ServiceBuilder<RegistryFactory<K, V>> build(ServiceTarget target) {
Value<RegistryFactory<K, V>> value = () -> new FunctionalRegistryFactory<>((provider, closeTask) -> new CacheRegistry<>(this, provider, closeTask));
Value<RegistryFactory<K, V>> value = () -> new FunctionalRegistryFactory<>((entry, closeTask) -> new CacheRegistry<>(this, entry, closeTask));
ServiceBuilder<RegistryFactory<K, V>> builder = target.addService(this.name, new ValueService<>(value)).setInitialMode(ServiceController.Mode.ON_DEMAND);
Stream.of(this.cache, this.factory, this.group).forEach(dependency -> dependency.register(builder));
return builder;
Expand Down
Expand Up @@ -22,31 +22,31 @@

package org.wildfly.clustering.server.registry;

import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiFunction;

import org.wildfly.clustering.registry.Registry;
import org.wildfly.clustering.registry.RegistryEntryProvider;
import org.wildfly.clustering.registry.RegistryFactory;

/**
* @author Paul Ferraro
*/
public class FunctionalRegistryFactory<K, V> implements RegistryFactory<K, V> {

private final AtomicReference<RegistryEntryProvider<K, V>> provider = new AtomicReference<>();
private final BiFunction<RegistryEntryProvider<K, V>, Runnable, Registry<K, V>> factory;
private final AtomicReference<Map.Entry<K, V>> entry = new AtomicReference<>();
private final BiFunction<Map.Entry<K, V>, Runnable, Registry<K, V>> factory;

public FunctionalRegistryFactory(BiFunction<RegistryEntryProvider<K, V>, Runnable, Registry<K, V>> factory) {
public FunctionalRegistryFactory(BiFunction<Map.Entry<K, V>, Runnable, Registry<K, V>> factory) {
this.factory = factory;
}

@Override
public Registry<K, V> createRegistry(RegistryEntryProvider<K, V> provider) {
public Registry<K, V> createRegistry(Map.Entry<K, V> entry) {
// Ensure only one registry is created at a time
if (!this.provider.compareAndSet(null, provider)) {
if (!this.entry.compareAndSet(null, entry)) {
throw new IllegalStateException();
}
return this.factory.apply(provider, () -> this.provider.set(null));
return this.factory.apply(entry, () -> this.entry.set(null));
}
}
Expand Up @@ -21,14 +21,12 @@
*/
package org.wildfly.clustering.server.registry;

import java.util.AbstractMap;
import java.util.Collections;
import java.util.Map;

import org.wildfly.clustering.group.Group;
import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.registry.Registry;
import org.wildfly.clustering.registry.RegistryEntryProvider;

/**
* Non-clustered {@link Registry} implementation.
Expand All @@ -42,10 +40,10 @@ public class LocalRegistry<K, V> implements Registry<K, V> {
private final Runnable closeTask;
private volatile Map.Entry<K, V> entry;

public LocalRegistry(Group group, RegistryEntryProvider<K, V> provider, Runnable closeTask) {
public LocalRegistry(Group group, Map.Entry<K, V> entry, Runnable closeTask) {
this.group = group;
this.closeTask = closeTask;
this.entry = new AbstractMap.SimpleImmutableEntry<>(provider.getKey(), provider.getValue());
this.entry = entry;
}

@Override
Expand Down
Expand Up @@ -69,7 +69,7 @@ public Builder<RegistryFactory<K, V>> configure(CapabilityServiceSupport support

@Override
public ServiceBuilder<RegistryFactory<K, V>> build(ServiceTarget target) {
Value<RegistryFactory<K, V>> value = () -> new FunctionalRegistryFactory<>((provider, closeTask) -> new LocalRegistry<>(this.group.getValue(), provider, closeTask));
Value<RegistryFactory<K, V>> value = () -> new FunctionalRegistryFactory<>((entry, closeTask) -> new LocalRegistry<>(this.group.getValue(), entry, closeTask));
return this.group.register(target.addService(this.name, new ValueService<>(value)).setInitialMode(ServiceController.Mode.ON_DEMAND));
}
}
Expand Up @@ -22,6 +22,7 @@

package org.wildfly.clustering.server.registry;

import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
Expand All @@ -35,7 +36,6 @@
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.wildfly.clustering.registry.Registry;
import org.wildfly.clustering.registry.RegistryEntryProvider;
import org.wildfly.clustering.registry.RegistryFactory;
import org.wildfly.clustering.service.AsynchronousServiceBuilder;
import org.wildfly.clustering.service.Builder;
Expand All @@ -57,7 +57,7 @@ public class RegistryBuilder<K, V> implements CapabilityServiceBuilder<Registry<
@SuppressWarnings("rawtypes")
private volatile ValueDependency<RegistryFactory> factory;
@SuppressWarnings("rawtypes")
private volatile ValueDependency<RegistryEntryProvider> provider;
private volatile ValueDependency<Map.Entry> entry;

public RegistryBuilder(ServiceName name, String containerName, String cacheName) {
this.name = name;
Expand All @@ -73,16 +73,16 @@ public ServiceName getServiceName() {
@Override
public Builder<Registry<K, V>> configure(CapabilityServiceSupport support) {
this.factory = new InjectedValueDependency<>(ClusteringCacheRequirement.REGISTRY_FACTORY.getServiceName(support, this.containerName, this.cacheName), RegistryFactory.class);
this.provider = new InjectedValueDependency<>(ClusteringCacheRequirement.REGISTRY_ENTRY.getServiceName(support, this.containerName, this.cacheName), RegistryEntryProvider.class);
this.entry = new InjectedValueDependency<>(ClusteringCacheRequirement.REGISTRY_ENTRY.getServiceName(support, this.containerName, this.cacheName), Map.Entry.class);
return this;
}

@Override
public ServiceBuilder<Registry<K, V>> build(ServiceTarget target) {
Supplier<Registry<K, V>> supplier = () -> this.factory.getValue().createRegistry(this.provider.getValue());
Supplier<Registry<K, V>> supplier = () -> this.factory.getValue().createRegistry(this.entry.getValue());
Service<Registry<K, V>> service = new SuppliedValueService<>(Function.identity(), supplier, Consumers.close());
ServiceBuilder<Registry<K, V>> builder = new AsynchronousServiceBuilder<>(this.name, service).build(target).setInitialMode(ServiceController.Mode.ON_DEMAND);
Stream.of(this.factory, this.provider).forEach(dependency -> dependency.register(builder));
Stream.of(this.factory, this.entry).forEach(dependency -> dependency.register(builder));
return builder;
}
}

0 comments on commit a83abbd

Please sign in to comment.