Search in sources :

Example 11 with Buffer

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());
}
Also used : Buffer(org.jgroups.util.Buffer) ArrayList(java.util.ArrayList)

Example 12 with Buffer

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());
}
Also used : Buffer(org.jgroups.util.Buffer)

Example 13 with Buffer

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;
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.jgroups.util.Buffer) Address(org.jgroups.Address) CommandDispatcherException(org.wildfly.clustering.dispatcher.CommandDispatcherException) Node(org.wildfly.clustering.group.Node) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompletionStage(java.util.concurrent.CompletionStage)

Example 14 with Buffer

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);
}
Also used : ByteBuffer(java.nio.ByteBuffer) Buffer(org.jgroups.util.Buffer) Address(org.jgroups.Address)

Aggregations

Buffer (org.jgroups.util.Buffer)14 Address (org.jgroups.Address)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Message (org.jgroups.Message)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 UnknownHostException (java.net.UnknownHostException)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Marshaller (org.jboss.marshalling.Marshaller)1 org.jgroups (org.jgroups)1 MessageDispatcher (org.jgroups.blocks.MessageDispatcher)1 RequestOptions (org.jgroups.blocks.RequestOptions)1 GMS (org.jgroups.protocols.pbcast.GMS)1 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)1 STABLE (org.jgroups.protocols.pbcast.STABLE)1