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