use of org.jgroups.util.Buffer in project JGroups by belaban.
the class GroupRequestTest method _testMessageReceptionWithViewChangeMemberLeft.
private void _testMessageReceptionWithViewChangeMemberLeft(boolean async) throws Exception {
List<Address> new_dests = new ArrayList<>();
new_dests.add(b);
Object[] responses = { new Message(null, (long) 1).src(b), new View(Util.createRandomAddress(), 322649, new_dests) };
MyCorrelator corr = new MyCorrelator(async, responses, 0);
GroupRequest<Object> req = new GroupRequest<>(corr, dests, new RequestOptions(ResponseMode.GET_ALL, 0));
corr.setGroupRequest(req);
System.out.println("group request before execution: " + req);
RspList<Object> results = req.execute(new Buffer(buf, 0, buf.length), true);
System.out.println("group request after execution: " + req);
assert req.isDone();
Assert.assertEquals(2, results.size());
}
use of org.jgroups.util.Buffer in project JGroups by belaban.
the class GroupRequestTest method _testMessageTimeout.
/**
* test group timeout. demonstrates that the timeout mechanism times out too
* quickly as multiple responses are received by the GroupRequest.
* Demonstrates by group request receiving multiple messages in a timeframe
* less than the total timeout. the request will fail, as after each
* received message, the request alters the total timeout.
*
* @throws Exception
*/
private void _testMessageTimeout(boolean async) throws Exception {
// need multiple destinations to replicate error
int destCount = 10;
// total timeout to hear from all members
final long timeout = destCount * 1000;
// how long each destination should delay
final long delay = 75L;
Object[] responses = new Message[destCount];
dests = new ArrayList<>();
for (int i = 0; i < destCount; i++) {
Address addr = Util.createRandomAddress();
dests.add(addr);
// how long does this simulated destination take to execute? the sum is just less than the total timeout
responses[i] = new Message(null, (long) i).src(addr);
}
MyCorrelator corr = new MyCorrelator(async, responses, delay);
// instantiate request with dummy correlator
GroupRequest<Long> req = new GroupRequest<>(corr, dests, new RequestOptions(ResponseMode.GET_ALL, timeout));
corr.setGroupRequest(req);
RspList<Long> results = req.execute(new Buffer(buf, 0, buf.length), true);
System.out.println("group request is " + req);
assert req.isDone();
Assert.assertEquals(dests.size(), results.size());
}
use of org.jgroups.util.Buffer in project wildfly by wildfly.
the class ChannelCommandDispatcher method executeOnGroup.
@Override
public <R> Map<Node, CompletionStage<R>> executeOnGroup(Command<R, ? super CC> command, Node... excludedMembers) throws CommandDispatcherException {
Set<Node> excluded = (excludedMembers != null) ? new HashSet<>(Arrays.asList(excludedMembers)) : Collections.emptySet();
Map<Node, CompletionStage<R>> results = new ConcurrentHashMap<>();
Buffer buffer = this.createBuffer(command);
for (Node member : this.group.getMembership().getMembers()) {
if (!excluded.contains(member)) {
Address address = this.group.getAddress(member);
if (this.localAddress.equals(address)) {
results.put(member, this.localDispatcher.executeOnMember(command, member));
} else {
try {
ServiceRequest<R, MC> request = new ServiceRequest<>(this.dispatcher.getCorrelator(), this.group.getAddress(member), this.options, this.context);
CompletionStage<R> future = request.send(buffer);
results.put(member, future);
future.whenComplete(new PruneCancellationTask<>(results, member));
} catch (CommandDispatcherException e) {
// Cancel previously dispatched messages
for (CompletionStage<R> result : results.values()) {
result.toCompletableFuture().cancel(true);
}
throw e;
}
}
}
}
return results;
}
use of org.jgroups.util.Buffer in project wildfly by wildfly.
the class ChannelCommandDispatcher method executeOnMember.
@Override
public <R> CompletionStage<R> executeOnMember(Command<R, ? super CC> command, Node member) throws CommandDispatcherException {
// Bypass MessageDispatcher if target node is local
Address address = this.group.getAddress(member);
if (this.localAddress.equals(address)) {
return this.localDispatcher.executeOnMember(command, member);
}
Buffer buffer = this.createBuffer(command);
ServiceRequest<R, MC> request = new ServiceRequest<>(this.dispatcher.getCorrelator(), this.group.getAddress(member), this.options, this.context);
return request.send(buffer);
}
Aggregations