Search in sources :

Example 1 with Address

use of org.jgroups.Address in project camel by apache.

the class JGroupsFilters method dropNonCoordinatorViews.

/**
     * Creates predicate rejecting messages that are instances of {@code org.jgroups.View}, but have not been received
     * by the coordinator JGroups node. This filter is useful for keeping only view messages indicating that receiving
     * endpoint is a master node.
     *
     * @return predicate filtering out non-coordinator view messages.
     */
public static Predicate dropNonCoordinatorViews() {
    return new Predicate() {

        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            LOG.debug("Filtering message {}.", body);
            if (body instanceof View) {
                View view = (View) body;
                Address coordinatorNodeAddress = view.getMembers().get(COORDINATOR_NODE_INDEX);
                Address channelAddress = exchange.getIn().getHeader(HEADER_JGROUPS_CHANNEL_ADDRESS, Address.class);
                LOG.debug("Comparing endpoint channel address {} against the coordinator node address {}.", channelAddress, coordinatorNodeAddress);
                return channelAddress.equals(coordinatorNodeAddress);
            }
            LOG.debug("Body {} is not an instance of org.jgroups.View . Skipping filter.", body);
            return false;
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Address(org.jgroups.Address) View(org.jgroups.View) Predicate(org.apache.camel.Predicate)

Example 2 with Address

use of org.jgroups.Address in project geode by apache.

the class AddressManager method up.

@SuppressWarnings("unchecked")
@Override
public Object up(Event evt) {
    switch(evt.getType()) {
        case Event.FIND_MBRS:
            List<Address> missing = (List<Address>) evt.getArg();
            Responses responses = new Responses(false);
            for (Address laddr : missing) {
                try {
                    if (laddr instanceof JGAddress) {
                        PingData pd = new PingData(laddr, true, laddr.toString(), newIpAddress(laddr));
                        responses.addResponse(pd, false);
                        updateUDPCache(pd);
                    }
                } catch (RuntimeException e) {
                    logger.warn("Unable to create PingData response", e);
                    throw e;
                }
            }
            return responses;
    }
    return up_prot.up(evt);
}
Also used : PingData(org.jgroups.protocols.PingData) Address(org.jgroups.Address) IpAddress(org.jgroups.stack.IpAddress) List(java.util.List) Responses(org.jgroups.util.Responses)

Example 3 with Address

use of org.jgroups.Address in project wildfly by wildfly.

the class ChannelNodeFactory method createNode.

@Override
public Node createNode(Address key) {
    return this.nodes.computeIfAbsent(key, (Address address) -> {
        IpAddress ipAddress = (IpAddress) this.channel.down(new Event(Event.GET_PHYSICAL_ADDRESS, address));
        // Physical address might be null if node is no longer a member of the cluster
        InetSocketAddress socketAddress = (ipAddress != null) ? new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort()) : new InetSocketAddress(0);
        String name = this.channel.getName(address);
        if (name == null) {
            // If no logical name exists, create one using physical address
            name = String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort());
        }
        return new AddressableNode(address, name, socketAddress);
    });
}
Also used : Address(org.jgroups.Address) InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) InetSocketAddress(java.net.InetSocketAddress) Event(org.jgroups.Event) IpAddress(org.jgroups.stack.IpAddress)

Example 4 with Address

use of org.jgroups.Address 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 5 with Address

use of org.jgroups.Address in project camel by apache.

the class JGroupsProducer method process.

// Processing logic
@Override
public void process(Exchange exchange) throws Exception {
    Object body = exchange.getIn().getBody();
    if (body != null) {
        Address destinationAddress = exchange.getIn().getHeader(JGroupsEndpoint.HEADER_JGROUPS_DEST, Address.class);
        Address sourceAddress = exchange.getIn().getHeader(JGroupsEndpoint.HEADER_JGROUPS_SRC, Address.class);
        log.debug("Posting: {} to cluster: {}", body, clusterName);
        if (destinationAddress != null) {
            log.debug("Posting to custom destination address: {}", destinationAddress);
        }
        if (sourceAddress != null) {
            log.debug("Posting from custom source address: {}", sourceAddress);
        }
        Message message = new Message(destinationAddress, body);
        message.setSrc(sourceAddress);
        channel.send(message);
    } else {
        log.debug("Body is null, cannot post to channel.");
    }
}
Also used : Address(org.jgroups.Address) Message(org.jgroups.Message)

Aggregations

Address (org.jgroups.Address)9 IOException (java.io.IOException)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Message (org.jgroups.Message)3 RequestOptions (org.jgroups.blocks.RequestOptions)3 Node (org.wildfly.clustering.group.Node)3 InetSocketAddress (java.net.InetSocketAddress)2 HashMap (java.util.HashMap)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 View (org.jgroups.View)2 IpAddress (org.jgroups.stack.IpAddress)2 Rsp (org.jgroups.util.Rsp)2 CommandDispatcherException (org.wildfly.clustering.dispatcher.CommandDispatcherException)2 CommandResponse (org.wildfly.clustering.dispatcher.CommandResponse)2 InetAddress (java.net.InetAddress)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1