Search in sources :

Example 11 with Pipe

use of zmq.pipe.Pipe in project jeromq by zeromq.

the class MTrieTest method testAddRemoveMultiNodesAboveLevelWithFunctionCall.

@Test
public void testAddRemoveMultiNodesAboveLevelWithFunctionCall() {
    Mtrie mtrie = new Mtrie();
    Pipe other = createPipe();
    Pipe third = createPipe();
    boolean rc = mtrie.add(prefix, pipe);
    assertThat(rc, is(true));
    byte[] abv = Arrays.copyOf(prefix.data(), prefix.size());
    abv[1] = 3;
    Msg above = new Msg(abv);
    rc = mtrie.add(above, other);
    assertThat(rc, is(true));
    abv[1] = 33;
    above = new Msg(abv);
    rc = mtrie.add(above, third);
    assertThat(rc, is(true));
    rc = mtrie.rm(pipe, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(1));
    abv[1] = 3;
    above = new Msg(abv);
    rc = mtrie.rm(other, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(2));
    abv[1] = 33;
    above = new Msg(abv);
    rc = mtrie.rm(third, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(3));
}
Also used : Msg(zmq.Msg) Pipe(zmq.pipe.Pipe) Test(org.junit.Test)

Example 12 with Pipe

use of zmq.pipe.Pipe in project jeromq by zeromq.

the class MTrieTest method testAddRemoveMultiNodesBelowLevelWithFunctionCall.

@Test
public void testAddRemoveMultiNodesBelowLevelWithFunctionCall() {
    Mtrie mtrie = new Mtrie();
    Pipe other = createPipe();
    Pipe third = createPipe();
    boolean rc = mtrie.add(prefix, pipe);
    assertThat(rc, is(true));
    byte[] abv = Arrays.copyOf(prefix.data(), prefix.size());
    abv[1] = 0;
    Msg above = new Msg(abv);
    rc = mtrie.add(above, other);
    assertThat(rc, is(true));
    abv[1] = -1;
    above = new Msg(abv);
    rc = mtrie.add(above, third);
    assertThat(rc, is(true));
    rc = mtrie.rm(pipe, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(1));
    abv[1] = 0;
    above = new Msg(abv);
    rc = mtrie.rm(other, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(2));
    abv[1] = -1;
    above = new Msg(abv);
    rc = mtrie.rm(third, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(3));
}
Also used : Msg(zmq.Msg) Pipe(zmq.pipe.Pipe) Test(org.junit.Test)

Example 13 with Pipe

use of zmq.pipe.Pipe in project jeromq by zeromq.

the class MTrieTest method createPipe.

private Pipe createPipe() {
    ZObject object = new ZObject(null, 0) {
    };
    Pipe[] pair = Pipe.pair(new ZObject[] { object, object }, new int[2], new boolean[2]);
    return pair[0];
}
Also used : Pipe(zmq.pipe.Pipe) ZObject(zmq.ZObject)

Example 14 with Pipe

use of zmq.pipe.Pipe in project jeromq by zeromq.

the class MTrieTest method testAddRemoveMultiNodesBelowLevel.

@Test
public void testAddRemoveMultiNodesBelowLevel() {
    Mtrie mtrie = new Mtrie();
    Pipe other = createPipe();
    Pipe third = createPipe();
    boolean rc = mtrie.add(prefix, pipe);
    assertThat(rc, is(true));
    byte[] abv = Arrays.copyOf(prefix.data(), prefix.size());
    abv[1] = 0;
    Msg above = new Msg(abv);
    rc = mtrie.add(above, other);
    assertThat(rc, is(true));
    abv[1] = -1;
    above = new Msg(abv);
    rc = mtrie.add(above, third);
    assertThat(rc, is(true));
    rc = mtrie.rm(prefix, pipe);
    assertThat(rc, is(true));
    abv[1] = 0;
    above = new Msg(abv);
    rc = mtrie.rm(above, other);
    assertThat(rc, is(true));
    abv[1] = -1;
    above = new Msg(abv);
    rc = mtrie.rm(above, third);
    assertThat(rc, is(true));
}
Also used : Msg(zmq.Msg) Pipe(zmq.pipe.Pipe) Test(org.junit.Test)

Example 15 with Pipe

use of zmq.pipe.Pipe in project jeromq by zeromq.

the class Mtrie method match.

// Signal all the matching pipes.
public void match(ByteBuffer data, int size, IMtrieHandler func, XPub pub) {
    assert (data != null);
    assert (func != null);
    assert (pub != null);
    Mtrie current = this;
    int idx = 0;
    while (true) {
        // Signal the pipes attached to this node.
        if (current.pipes != null) {
            for (Pipe it : current.pipes) {
                func.invoke(it, null, 0, pub);
            }
        }
        // If we are at the end of the message, there's nothing more to match.
        if (size == 0) {
            break;
        }
        // If there are no subnodes in the trie, return.
        if (current.count == 0) {
            break;
        }
        byte c = data.get(idx);
        // If there's one subnode (optimisation).
        if (current.count == 1) {
            if (c != current.min) {
                break;
            }
            current = current.next[0];
            idx++;
            size--;
            continue;
        }
        // If there are multiple subnodes.
        if (c < current.min || c >= current.min + current.count) {
            break;
        }
        if (current.next[c - current.min] == null) {
            break;
        }
        current = current.next[c - current.min];
        idx++;
        size--;
    }
}
Also used : Pipe(zmq.pipe.Pipe)

Aggregations

Pipe (zmq.pipe.Pipe)20 Msg (zmq.Msg)13 Test (org.junit.Test)6 ValueReference (zmq.util.ValueReference)6 Blob (zmq.util.Blob)4 InetSocketAddress (java.net.InetSocketAddress)2 ZObject (zmq.ZObject)2 Metadata (zmq.io.Metadata)2 IZAddress (zmq.io.net.Address.IZAddress)2 NetProtocol (zmq.io.net.NetProtocol)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Ctx (zmq.Ctx)1 IOThread (zmq.io.IOThread)1 SessionBase (zmq.io.SessionBase)1 Address (zmq.io.net.Address)1