Skip to content

Commit

Permalink
Replace Group.isLocal() with Group.isSingleton(), which has clearer s…
Browse files Browse the repository at this point in the history
…emantics.
  • Loading branch information
pferraro committed Dec 7, 2017
1 parent 6d93090 commit bc4e0fd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
Expand Up @@ -122,6 +122,15 @@ default void membershipChanged(Membership previousMembership, Membership members
/** /**
* Indicates whether this is a local group. A local group only ever contains a single member. * Indicates whether this is a local group. A local group only ever contains a single member.
* @return true, if this is a local group, false otherwise. * @return true, if this is a local group, false otherwise.
* @deprecated Replaced by {@link #isSingleton()}.
*/ */
boolean isLocal(); @Deprecated default boolean isLocal() {
return this.isSingleton();
}

/**
* Indicates whether or not this is a singleton group. The membership of a singleton group contains only the local member and never changes.
* @return true, if this is a singleton group, false otherwise.
*/
boolean isSingleton();
} }
Expand Up @@ -201,7 +201,7 @@ public Node getLocalNode() {
} }


@Override @Override
public boolean isLocal() { public boolean isSingleton() {
return false; return false;
} }


Expand Down
Expand Up @@ -107,14 +107,19 @@ public Node getLocalNode() {


@Override @Override
public Membership getMembership() { public Membership getMembership() {
Transport transport = this.cache.getCacheManager().getTransport(); if (this.isSingleton()) {
if (transport == null) {
return new SingletonMembership(this.getLocalNode()); return new SingletonMembership(this.getLocalNode());
} }
Transport transport = this.cache.getCacheManager().getTransport();
DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager(); DistributionManager dist = this.cache.getAdvancedCache().getDistributionManager();
return (dist != null) ? new CacheMembership(transport.getAddress(), dist.getConsistentHash(), this.factory) : new CacheMembership(transport, this.factory); return (dist != null) ? new CacheMembership(transport.getAddress(), dist.getConsistentHash(), this.factory) : new CacheMembership(transport, this.factory);
} }


@Override
public boolean isSingleton() {
return this.cache.getCacheManager().getTransport() == null;
}

@Merged @Merged
@ViewChanged @ViewChanged
public void viewChanged(ViewChangedEvent event) { public void viewChanged(ViewChangedEvent event) {
Expand Down Expand Up @@ -201,9 +206,4 @@ private void unregister(GroupListener listener) {
public void removeListener(Listener listener) { public void removeListener(Listener listener) {
this.unregister(listener); this.unregister(listener);
} }

@Override
public boolean isLocal() {
return this.cache.getCacheManager().getTransport() == null;
}
} }
Expand Up @@ -69,7 +69,7 @@ public Membership getMembership() {
} }


@Override @Override
public boolean isLocal() { public boolean isSingleton() {
return true; return true;
} }
} }
Expand Up @@ -445,7 +445,7 @@ ListenerHandle registerClusterTopologyListener(ClusterTopologyListener listener)
// Synchronize on the listener to ensure that the initial topology is set before processing any changes from the registry listener // Synchronize on the listener to ensure that the initial topology is set before processing any changes from the registry listener
synchronized (listener) { synchronized (listener) {
this.clusterTopologyListeners.add(listener); this.clusterTopologyListeners.add(listener);
listener.clusterTopology(!this.clientMappingRegistry.getGroup().isLocal() ? Collections.singletonList(getClusterInfo(this.clientMappingRegistry.getEntries())) : Collections.emptyList()); listener.clusterTopology(!this.clientMappingRegistry.getGroup().isSingleton() ? Collections.singletonList(getClusterInfo(this.clientMappingRegistry.getEntries())) : Collections.emptyList());
} }
return () -> this.clusterTopologyListeners.remove(listener); return () -> this.clusterTopologyListeners.remove(listener);
} }
Expand Down Expand Up @@ -575,7 +575,7 @@ private Affinity getClusterAffinity() {
Registry<String, List<ClientMapping>> registry = this.clientMappingRegistry; Registry<String, List<ClientMapping>> registry = this.clientMappingRegistry;
Group group = registry != null ? registry.getGroup() : null; Group group = registry != null ? registry.getGroup() : null;


return group != null && !group.isLocal() ? new ClusterAffinity(group.getName()) : null; return group != null && !group.isSingleton() ? new ClusterAffinity(group.getName()) : null;
} }


Executor getExecutor() { Executor getExecutor() {
Expand Down
Expand Up @@ -114,7 +114,7 @@ public void moduleUnavailable(final List<EJBModuleIdentifier> modules) {
b.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(ourNodeName)); b.addAttribute(EJBClientContext.FILTER_ATTR_NODE, AttributeValue.fromString(ourNodeName));
if (clientMappingsRegistry != null) { if (clientMappingsRegistry != null) {
Group group = clientMappingsRegistry.getGroup(); Group group = clientMappingsRegistry.getGroup();
if (!group.isLocal()) { if (!group.isSingleton()) {
b.addAttribute(EJBClientContext.FILTER_ATTR_CLUSTER, AttributeValue.fromString(group.getName())); b.addAttribute(EJBClientContext.FILTER_ATTR_CLUSTER, AttributeValue.fromString(group.getName()));
} }
} }
Expand Down

0 comments on commit bc4e0fd

Please sign in to comment.