diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcher.java b/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcher.java index 34dd68d3bc41..3bcfac2452e8 100644 --- a/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcher.java +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcher.java @@ -43,7 +43,6 @@ import org.wildfly.clustering.dispatcher.CommandDispatcherException; import org.wildfly.clustering.dispatcher.CommandResponse; import org.wildfly.clustering.group.Node; -import org.wildfly.clustering.server.Addressable; import org.wildfly.clustering.server.group.Group; /** @@ -123,7 +122,7 @@ public Map> submitOnCluster(Command command, N for (Node node : this.group.getMembership().getMembers()) { if (!excluded.contains(node)) { try { - results.put(node, this.dispatcher.sendMessageWithFuture(getAddress(node), buffer, options)); + results.put(node, this.dispatcher.sendMessageWithFuture(this.group.getAddress(node), buffer, options)); } catch (Exception e) { throw new CommandDispatcherException(e); } @@ -142,7 +141,7 @@ public CommandResponse executeOnNode(Command command, Node RequestOptions options = this.createRequestOptions(); try { // Use sendMessageWithFuture(...) instead of sendMessage(...) since we want to differentiate between sender exceptions and receiver exceptions - Future future = this.dispatcher.sendMessageWithFuture(getAddress(node), buffer, options); + Future future = this.dispatcher.sendMessageWithFuture(this.group.getAddress(node), buffer, options); return new SimpleCommandResponse<>(future.get()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); @@ -163,7 +162,7 @@ public Future submitOnNode(Command command, Node node) thro Buffer buffer = this.createBuffer(command); RequestOptions options = this.createRequestOptions(); try { - return this.dispatcher.sendMessageWithFuture(getAddress(node), buffer, options); + return this.dispatcher.sendMessageWithFuture(this.group.getAddress(node), buffer, options); } catch (Exception e) { throw new CommandDispatcherException(e); } @@ -171,7 +170,7 @@ public Future submitOnNode(Command command, Node node) thro public Future submit(Node node, Buffer buffer, RequestOptions options) throws CommandDispatcherException { try { - return this.dispatcher.sendMessageWithFuture(getAddress(node), buffer, options); + return this.dispatcher.sendMessageWithFuture(this.group.getAddress(node), buffer, options); } catch (Exception e) { throw new CommandDispatcherException(e); } @@ -186,17 +185,13 @@ private Buffer createBuffer(Command command) { } private boolean isLocal(Node node) { - return this.getLocalAddress().equals(getAddress(node)); - } - - private static Address getAddress(Node node) { - return (node instanceof Addressable) ? ((Addressable) node).getAddress() : null; + return this.getLocalAddress().equals(this.group.getAddress(node)); } private RequestOptions createRequestOptions(Node... excludedNodes) { Address[] excludedAddresses = new Address[excludedNodes.length]; for (int i = 0; i < excludedNodes.length; ++i) { - excludedAddresses[i] = getAddress(excludedNodes[i]); + excludedAddresses[i] = this.group.getAddress(excludedNodes[i]); } return this.createRequestOptions().exclusionList(excludedAddresses); } diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcherFactory.java b/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcherFactory.java index 134df1607f31..d5db799e2aae 100644 --- a/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcherFactory.java +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/dispatcher/ChannelCommandDispatcherFactory.java @@ -240,6 +240,11 @@ public Node createNode(Address address) { }); } + @Override + public Address getAddress(Node node) { + return ((AddressableNode) node).getAddress(); + } + @Override public void viewAccepted(View view) { View oldView = this.view.getAndSet(view); diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/AbstractLocalGroup.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/AbstractLocalGroup.java new file mode 100644 index 000000000000..62ae4b0ae146 --- /dev/null +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/AbstractLocalGroup.java @@ -0,0 +1,85 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2018, 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.server.group; + +import org.wildfly.clustering.Registration; +import org.wildfly.clustering.group.GroupListener; +import org.wildfly.clustering.group.Membership; +import org.wildfly.clustering.group.Node; + +/** + * Abstract non-clustered group implementation. + * Registered {@link GroupListener} are never invoked, as membership of a local group is fixed. + * @author Paul Ferraro + */ +public abstract class AbstractLocalGroup implements Group, Registration { + private static final String NAME = "local"; + + private final Membership membership; + + public AbstractLocalGroup(String nodeName) { + this.membership = new SingletonMembership(new LocalNode(nodeName)); + } + + @Override + public void close() { + // We never registered anything + } + + @Override + public Registration register(GroupListener listener) { + // Nothing to register + return this; + } + + @Deprecated + @Override + public void removeListener(org.wildfly.clustering.group.Group.Listener listener) { + // We never registered anything + } + + @Override + public String getName() { + return NAME; + } + + @Override + public Node getLocalMember() { + return this.membership.getCoordinator(); + } + + @Override + public Membership getMembership() { + return this.membership; + } + + @Override + public boolean isSingleton() { + return true; + } + + @Override + public Node createNode(A address) { + return this.getLocalMember(); + } +} diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/AbstractLocalGroupBuilder.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/AbstractLocalGroupBuilder.java new file mode 100644 index 000000000000..4dde6ca5858c --- /dev/null +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/AbstractLocalGroupBuilder.java @@ -0,0 +1,61 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2018, 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.server.group; + +import java.util.function.Function; + +import org.jboss.as.clustering.controller.CapabilityServiceBuilder; +import org.jboss.as.server.ServerEnvironment; +import org.jboss.as.server.ServerEnvironmentService; +import org.jboss.msc.service.ServiceBuilder; +import org.jboss.msc.service.ServiceController; +import org.jboss.msc.service.ServiceName; +import org.jboss.msc.service.ServiceTarget; +import org.wildfly.clustering.group.Group; +import org.wildfly.clustering.service.InjectedValueDependency; +import org.wildfly.clustering.service.MappedValueService; +import org.wildfly.clustering.service.ValueDependency; + +/** + * Builds a non-clustered {@link Group}. + * @author Paul Ferraro + */ +public abstract class AbstractLocalGroupBuilder implements CapabilityServiceBuilder, Function { + + private final ServiceName name; + private final ValueDependency environment = new InjectedValueDependency<>(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class); + + public AbstractLocalGroupBuilder(ServiceName name) { + this.name = name; + } + + @Override + public ServiceName getServiceName() { + return this.name; + } + + @Override + public ServiceBuilder build(ServiceTarget target) { + return this.environment.register(target.addService(this.name, new MappedValueService<>(this, this.environment))).setInitialMode(ServiceController.Mode.ON_DEMAND); + } +} diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/CacheGroup.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/CacheGroup.java index 0b4dea5c5183..f243ac8c875c 100644 --- a/clustering/server/src/main/java/org/wildfly/clustering/server/group/CacheGroup.java +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/CacheGroup.java @@ -44,8 +44,10 @@ import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged; import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent; import org.infinispan.remoting.transport.Address; +import org.infinispan.remoting.transport.LocalModeAddress; import org.infinispan.remoting.transport.Transport; import org.infinispan.remoting.transport.jgroups.JGroupsAddress; +import org.infinispan.remoting.transport.jgroups.JGroupsAddressCache; import org.jboss.threads.JBossThreadFactory; import org.wildfly.clustering.Registration; import org.wildfly.clustering.group.GroupListener; @@ -124,8 +126,13 @@ public Node createNode(Address address) { return this.nodeFactory.createNode(toJGroupsAddress(address)); } + @Override + public Address getAddress(Node node) { + return (node instanceof AddressableNode) ? JGroupsAddressCache.fromJGroupsAddress(((AddressableNode) node).getAddress()) : LocalModeAddress.INSTANCE; + } + private static org.jgroups.Address toJGroupsAddress(Address address) { - if (address == null) return null; + if ((address == null) || (address == LocalModeAddress.INSTANCE)) return null; if (address instanceof JGroupsAddress) { JGroupsAddress jgroupsAddress = (JGroupsAddress) address; return jgroupsAddress.getJGroupsAddress(); diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroup.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroup.java new file mode 100644 index 000000000000..1adcff53d847 --- /dev/null +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroup.java @@ -0,0 +1,43 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2018, 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.server.group; + +import org.infinispan.remoting.transport.Address; +import org.infinispan.remoting.transport.LocalModeAddress; +import org.wildfly.clustering.group.Node; + +/** + * Non-clustered cache group. + * @author Paul Ferraro + */ +public class LocalCacheGroup extends AbstractLocalGroup
{ + + public LocalCacheGroup(String nodeName) { + super(nodeName); + } + + @Override + public Address getAddress(Node node) { + return LocalModeAddress.INSTANCE; + } +} diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroupBuilder.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroupBuilder.java new file mode 100644 index 000000000000..fa87fc24e224 --- /dev/null +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroupBuilder.java @@ -0,0 +1,43 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2018, 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.server.group; + +import org.jboss.as.server.ServerEnvironment; +import org.jboss.msc.service.ServiceName; +import org.wildfly.clustering.group.Group; + +/** + * Builds a non-clustered cache {@link Group} service. + * @author Paul Ferraro + */ +public class LocalCacheGroupBuilder extends AbstractLocalGroupBuilder { + + public LocalCacheGroupBuilder(ServiceName name) { + super(name); + } + + @Override + public Group apply(ServerEnvironment environment) { + return new LocalCacheGroup(environment.getNodeName()); + } +} diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroupBuilderProvider.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroupBuilderProvider.java index b80ac633df22..ddd1297ef7e3 100644 --- a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroupBuilderProvider.java +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalCacheGroupBuilderProvider.java @@ -34,6 +34,6 @@ public class LocalCacheGroupBuilderProvider extends CacheGroupBuilderProvider implements LocalCacheBuilderProvider { public LocalCacheGroupBuilderProvider() { - super((name, containerName, cacheName) -> new LocalGroupBuilder(name)); + super((name, containerName, cacheName) -> new LocalCacheGroupBuilder(name)); } } diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroup.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroup.java index 6d84012ec4b7..c1b661cc6d18 100644 --- a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroup.java +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroup.java @@ -21,58 +21,21 @@ */ package org.wildfly.clustering.server.group; -import org.wildfly.clustering.Registration; -import org.wildfly.clustering.group.GroupListener; -import org.wildfly.clustering.group.Membership; +import org.jgroups.Address; import org.wildfly.clustering.group.Node; /** * Non-clustered {@link Group} implementation * @author Paul Ferraro */ -public class LocalGroup implements Group { - private static final String NAME = "local"; +public class LocalGroup extends AbstractLocalGroup
{ - private final Membership membership; - - public LocalGroup(Node node) { - this.membership = new SingletonMembership(node); - } - - @Override - public Registration register(GroupListener object) { - // membership of a non-clustered group will never change - return () -> {}; - } - - @Deprecated - @Override - public void removeListener(Listener listener) { - // membership of a non-clustered group will never change - } - - @Override - public String getName() { - return NAME; - } - - @Override - public Node getLocalMember() { - return this.membership.getCoordinator(); - } - - @Override - public Membership getMembership() { - return this.membership; - } - - @Override - public boolean isSingleton() { - return true; + public LocalGroup(String nodeName) { + super(nodeName); } @Override - public Node createNode(Void address) { - return this.getLocalMember(); + public Address getAddress(Node node) { + return null; } } diff --git a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroupBuilder.java b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroupBuilder.java index bf9bf3c28f93..8a991f3b45c9 100644 --- a/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroupBuilder.java +++ b/clustering/server/src/main/java/org/wildfly/clustering/server/group/LocalGroupBuilder.java @@ -21,44 +21,22 @@ */ package org.wildfly.clustering.server.group; -import org.jboss.as.clustering.controller.CapabilityServiceBuilder; import org.jboss.as.server.ServerEnvironment; -import org.jboss.as.server.ServerEnvironmentService; -import org.jboss.msc.service.ServiceBuilder; -import org.jboss.msc.service.ServiceController; import org.jboss.msc.service.ServiceName; -import org.jboss.msc.service.ServiceTarget; -import org.jboss.msc.service.ValueService; -import org.jboss.msc.value.Value; import org.wildfly.clustering.group.Group; -import org.wildfly.clustering.service.InjectedValueDependency; -import org.wildfly.clustering.service.ValueDependency; /** * Builds a non-clustered {@link Group} service. * @author Paul Ferraro */ -public class LocalGroupBuilder implements CapabilityServiceBuilder, Value { - - private final ServiceName name; - private final ValueDependency environment = new InjectedValueDependency<>(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class); +public class LocalGroupBuilder extends AbstractLocalGroupBuilder { public LocalGroupBuilder(ServiceName name) { - this.name = name; - } - - @Override - public Group getValue() { - return new LocalGroup(new LocalNode(this.environment.getValue().getNodeName())); - } - - @Override - public ServiceName getServiceName() { - return this.name; + super(name); } @Override - public ServiceBuilder build(ServiceTarget target) { - return this.environment.register(target.addService(this.name, new ValueService<>(this)).setInitialMode(ServiceController.Mode.ON_DEMAND)); + public Group apply(ServerEnvironment environment) { + return new LocalGroup(environment.getNodeName()); } } diff --git a/clustering/spi/src/main/java/org/wildfly/clustering/spi/NodeFactory.java b/clustering/spi/src/main/java/org/wildfly/clustering/spi/NodeFactory.java index f9965446a530..e50102fb8d5e 100644 --- a/clustering/spi/src/main/java/org/wildfly/clustering/spi/NodeFactory.java +++ b/clustering/spi/src/main/java/org/wildfly/clustering/spi/NodeFactory.java @@ -31,4 +31,6 @@ public interface NodeFactory extends org.wildfly.clustering.group.NodeFactory { @Override Node createNode(A address); + + A getAddress(Node node); }