Search in sources :

Example 6 with Node

use of org.wildfly.clustering.group.Node in project wildfly by wildfly.

the class ChannelCommandDispatcher method executeOnCluster.

@Override
public <R> Map<Node, CommandResponse<R>> executeOnCluster(Command<R, ? super C> command, Node... excludedNodes) throws CommandDispatcherException {
    Message message = this.createMessage(command);
    RequestOptions options = this.createRequestOptions(excludedNodes);
    try {
        Map<Address, Rsp<R>> responses = this.dispatcher.castMessage(null, message, options);
        Map<Node, CommandResponse<R>> results = new HashMap<>();
        for (Map.Entry<Address, Rsp<R>> entry : responses.entrySet()) {
            Address address = entry.getKey();
            Rsp<R> response = entry.getValue();
            if (response.wasReceived() && !response.wasSuspected()) {
                results.put(this.factory.createNode(address), createCommandResponse(response));
            }
        }
        return results;
    } catch (Exception e) {
        throw new CommandDispatcherException(e);
    }
}
Also used : Message(org.jgroups.Message) Address(org.jgroups.Address) RequestOptions(org.jgroups.blocks.RequestOptions) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Node(org.wildfly.clustering.group.Node) CommandResponse(org.wildfly.clustering.dispatcher.CommandResponse) Rsp(org.jgroups.util.Rsp) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with Node

use of org.wildfly.clustering.group.Node in project wildfly by wildfly.

the class ClusterTopologyRetrieverBean method getClusterTopology.

@Override
public ClusterTopology getClusterTopology() {
    try {
        Collection<CommandResponse<String>> responses = this.dispatcher.executeOnCluster(this.command).values();
        List<String> nodes = new ArrayList<>(responses.size());
        for (CommandResponse<String> response : responses) {
            nodes.add(response.get());
        }
        Node localNode = this.factory.getGroup().getLocalNode();
        String local = this.dispatcher.executeOnNode(this.command, localNode).get();
        responses = this.dispatcher.executeOnCluster(this.command, localNode).values();
        List<String> remote = new ArrayList<>(responses.size());
        for (CommandResponse<String> response : responses) {
            remote.add(response.get());
        }
        return new ClusterTopology(nodes, local, remote);
    } catch (Exception e) {
        throw new IllegalStateException(e.getCause());
    }
}
Also used : Node(org.wildfly.clustering.group.Node) ArrayList(java.util.ArrayList) CommandResponse(org.wildfly.clustering.dispatcher.CommandResponse)

Example 8 with Node

use of org.wildfly.clustering.group.Node in project wildfly by wildfly.

the class NodeServiceServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String serviceName = getRequiredParameter(req, SERVICE);
    String expected = req.getParameter(EXPECTED);
    this.log(String.format("Received request for %s, expecting %s", serviceName, expected));
    @SuppressWarnings("unchecked") ServiceController<Node> service = (ServiceController<Node>) CurrentServiceContainer.getServiceContainer().getService(ServiceName.parse(serviceName));
    try {
        Node node = service.awaitValue();
        if (expected != null) {
            for (int i = 0; i < RETRIES; ++i) {
                if ((node != null) && expected.equals(node.getName()))
                    break;
                Thread.yield();
                node = service.awaitValue();
            }
        }
        if (node != null) {
            resp.setHeader(NODE_HEADER, node.getName());
        }
    } catch (IllegalStateException e) {
    // Thrown when quorum was not met
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    resp.getWriter().write("Success");
}
Also used : Node(org.wildfly.clustering.group.Node) ServiceController(org.jboss.msc.service.ServiceController)

Example 9 with Node

use of org.wildfly.clustering.group.Node in project quickstart by wildfly.

the class ServiceActivator method activate.

@Override
public void activate(ServiceActivatorContext serviceActivatorContext) {
    try {
        SingletonPolicy policy = (SingletonPolicy) serviceActivatorContext.getServiceRegistry().getRequiredService(ServiceName.parse(SingletonDefaultRequirement.SINGLETON_POLICY.getName())).awaitValue();
        InjectedValue<Group> group = new InjectedValue<>();
        Service<Node> service = new SingletonService(group);
        policy.createSingletonServiceBuilder(SINGLETON_SERVICE_NAME, service).build(serviceActivatorContext.getServiceTarget()).addDependency(ServiceName.parse("org.wildfly.clustering.default-group"), Group.class, group).install();
        serviceActivatorContext.getServiceTarget().addService(QUERYING_SERVICE_NAME, new QueryingService()).setInitialMode(ServiceController.Mode.ACTIVE).install();
        LOG.info("Singleton and querying services activated.");
    } catch (InterruptedException e) {
        throw new ServiceRegistryException(e);
    }
}
Also used : Group(org.wildfly.clustering.group.Group) InjectedValue(org.jboss.msc.value.InjectedValue) SingletonPolicy(org.wildfly.clustering.singleton.SingletonPolicy) Node(org.wildfly.clustering.group.Node) ServiceRegistryException(org.jboss.msc.service.ServiceRegistryException)

Example 10 with Node

use of org.wildfly.clustering.group.Node in project wildfly by wildfly.

the class InfinispanRouteLocator method locate.

@Override
public String locate(String sessionId) {
    Map.Entry<String, Void> entry = null;
    Address location = this.locatePrimaryOwner(sessionId);
    if (location != null) {
        Node node = this.factory.createNode(location);
        entry = this.registry.getEntry(node);
    }
    return (entry != null) ? entry.getKey() : null;
}
Also used : Address(org.infinispan.remoting.transport.Address) Node(org.wildfly.clustering.group.Node) Map(java.util.Map)

Aggregations

Node (org.wildfly.clustering.group.Node)22 Map (java.util.Map)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 HashSet (java.util.HashSet)5 Set (java.util.Set)4 Test (org.junit.Test)4 AbstractMap (java.util.AbstractMap)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 Batch (org.wildfly.clustering.ee.Batch)3 Group (org.wildfly.clustering.group.Group)3 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Collections (java.util.Collections)2 List (java.util.List)2 CancellationException (java.util.concurrent.CancellationException)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2