use of org.jgroups.Address in project wildfly by wildfly.
the class AddressableNodeExternalizer method read.
private static AddressableNode read(DataInput input) throws IOException {
try {
Address jgroupsAddress = org.jgroups.util.Util.readAddress(input);
String name = input.readUTF();
byte[] address = new byte[input.readInt()];
input.readFully(address);
int port = input.readInt();
return new AddressableNode(jgroupsAddress, name, new InetSocketAddress(InetAddress.getByAddress(address), port));
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.jgroups.Address in project wildfly by wildfly.
the class ChannelCommandDispatcher method createRequestOptions.
private RequestOptions createRequestOptions(Node... excludedNodes) {
RequestOptions options = this.createRequestOptions();
if ((excludedNodes != null) && (excludedNodes.length > 0)) {
Address[] addresses = new Address[excludedNodes.length];
for (int i = 0; i < excludedNodes.length; ++i) {
addresses[i] = getAddress(excludedNodes[i]);
}
options.setExclusionList(addresses);
}
return options;
}
use of org.jgroups.Address in project wildfly by wildfly.
the class ChannelCommandDispatcher method submitOnCluster.
@Override
public <R> Map<Node, Future<R>> submitOnCluster(Command<R, ? super C> command, Node... excludedNodes) throws CommandDispatcherException {
Map<Node, Future<R>> results = new ConcurrentHashMap<>();
FutureListener<RspList<R>> listener = future -> {
try {
future.get().keySet().stream().map(address -> this.factory.createNode(address)).forEach(node -> results.remove(node));
} catch (CancellationException e) {
} catch (ExecutionException e) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
};
Message message = this.createMessage(command);
RequestOptions options = this.createRequestOptions(excludedNodes);
try {
Future<? extends Map<Address, Rsp<R>>> futureResponses = this.dispatcher.castMessageWithFuture(null, message, options, listener);
Set<Node> excluded = (excludedNodes != null) ? new HashSet<>(Arrays.asList(excludedNodes)) : Collections.<Node>emptySet();
for (Address address : this.dispatcher.getChannel().getView().getMembers()) {
Node node = this.factory.createNode(address);
if (!excluded.contains(node)) {
Future<R> future = new Future<R>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return futureResponses.cancel(mayInterruptIfRunning);
}
@Override
public R get() throws InterruptedException, ExecutionException {
Map<Address, Rsp<R>> responses = futureResponses.get();
Rsp<R> response = responses.get(address);
if (response == null) {
throw new CancellationException();
}
return createCommandResponse(response).get();
}
@Override
public R get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
Map<Address, Rsp<R>> responses = futureResponses.get(timeout, unit);
Rsp<R> response = responses.get(address);
if (response == null) {
throw new CancellationException();
}
return createCommandResponse(response).get();
}
@Override
public boolean isCancelled() {
return futureResponses.isCancelled();
}
@Override
public boolean isDone() {
return futureResponses.isDone();
}
};
results.put(node, future);
}
}
return results;
} catch (Exception e) {
throw new CommandDispatcherException(e);
}
}
use of org.jgroups.Address in project wildfly by wildfly.
the class ChannelCommandDispatcherFactory method viewAccepted.
@Override
public void viewAccepted(View view) {
View oldView = this.view.getAndSet(view);
if (oldView != null) {
List<Node> oldNodes = this.getNodes(oldView);
List<Node> newNodes = this.getNodes(view);
List<Address> leftMembers = View.leftMembers(oldView, view);
if (leftMembers != null) {
this.nodeFactory.invalidate(leftMembers);
}
for (Map.Entry<Listener, ExecutorService> entry : this.listeners.entrySet()) {
try {
Listener listener = entry.getKey();
ExecutorService executor = entry.getValue();
executor.submit(() -> {
try {
listener.membershipChanged(oldNodes, newNodes, view instanceof MergeView);
} catch (Throwable e) {
ClusteringLogger.ROOT_LOGGER.warn(e.getLocalizedMessage(), e);
}
});
} catch (RejectedExecutionException e) {
// Executor was shutdown
}
}
}
}
Aggregations