Search in sources :

Example 6 with Pipe

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

the class SocketBase method processTerm.

@Override
protected final void processTerm(int linger) {
    // Unregister all inproc endpoints associated with this socket.
    // Doing this we make sure that no new pipes from other sockets (inproc)
    // will be initiated.
    unregisterEndpoints(this);
    // Ask all attached pipes to terminate.
    for (Pipe pipe : pipes) {
        pipe.sendDisconnectMsg();
        pipe.terminate(false);
    }
    registerTermAcks(pipes.size());
    // Continue the termination process immediately.
    super.processTerm(linger);
}
Also used : Pipe(zmq.pipe.Pipe)

Example 7 with Pipe

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

the class SessionBase method zapConnect.

public int zapConnect() {
    assert (zapPipe == null);
    Ctx.Endpoint peer = findEndpoint("inproc://zeromq.zap.01");
    if (peer.socket == null) {
        errno.set(ZError.ECONNREFUSED);
        return ZError.ECONNREFUSED;
    }
    if (peer.options.type != ZMQ.ZMQ_REP && peer.options.type != ZMQ.ZMQ_ROUTER && peer.options.type != ZMQ.ZMQ_SERVER) {
        errno.set(ZError.ECONNREFUSED);
        return ZError.ECONNREFUSED;
    }
    // Create a bi-directional pipe that will connect
    // session with zap socket.
    ZObject[] parents = { this, peer.socket };
    int[] hwms = { 0, 0 };
    boolean[] conflates = { false, false };
    Pipe[] pipes = Pipe.pair(parents, hwms, conflates);
    // Attach local end of the pipe to this socket object.
    zapPipe = pipes[0];
    zapPipe.setNoDelay();
    zapPipe.setEventSink(this);
    sendBind(peer.socket, pipes[1], false);
    // Send empty identity if required by the peer.
    if (peer.options.recvIdentity) {
        Msg id = new Msg();
        id.setFlags(Msg.IDENTITY);
        zapPipe.write(id);
        zapPipe.flush();
    }
    return 0;
}
Also used : Msg(zmq.Msg) Ctx(zmq.Ctx) Pipe(zmq.pipe.Pipe) ZObject(zmq.ZObject)

Example 8 with Pipe

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

the class MTrieTest method testAddRemoveMultiNodesSameLevel.

@Test
public void testAddRemoveMultiNodesSameLevel() {
    Mtrie mtrie = new Mtrie();
    Pipe other = createPipe();
    boolean rc = mtrie.add(prefix, pipe);
    assertThat(rc, is(true));
    rc = mtrie.add(prefix, other);
    assertThat(rc, is(false));
    rc = mtrie.rm(prefix, pipe);
    assertThat(rc, is(false));
    rc = mtrie.rm(prefix, other);
    assertThat(rc, is(true));
}
Also used : Pipe(zmq.pipe.Pipe) Test(org.junit.Test)

Example 9 with Pipe

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

the class MTrieTest method testAddRemoveMultiNodesAboveLevel.

@Test
public void testAddRemoveMultiNodesAboveLevel() {
    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] = 33;
    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] = 33;
    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 10 with Pipe

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

the class MTrieTest method testAddRemoveMultiNodesSameLevelWithFunctionCall.

@Test
public void testAddRemoveMultiNodesSameLevelWithFunctionCall() {
    Mtrie mtrie = new Mtrie();
    Pipe other = createPipe();
    boolean rc = mtrie.add(prefix, pipe);
    assertThat(rc, is(true));
    rc = mtrie.add(prefix, other);
    assertThat(rc, is(false));
    rc = mtrie.rm(pipe, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(0));
    rc = mtrie.rm(other, handler, null);
    assertThat(rc, is(true));
    assertThat(handler.counter.get(), is(1));
}
Also used : Pipe(zmq.pipe.Pipe) Test(org.junit.Test)

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