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;
}
};
}
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);
}
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);
});
}
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);
}
}
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.");
}
}
Aggregations