public void match(Pipe pipe)
    {
        int idx = pipes.indexOf(pipe);
        //  If pipe is already matching do nothing.
        if (idx < matching) {
            return;
        }

        //  If the pipe isn't eligible, ignore it.
        if (idx >= eligible) {
            return;
        }

        //  Mark the pipe as matching.
        Collections.swap(pipes, idx, matching);
        matching++;
    }
@Test
    public void testMatch()
    {
        dist.attach(second);
        assertThat(dist.matching(), is(0));

        // simulate HWM
        second.write(new Msg());

        // mark the pipe as not active and not eligible
        dist.sendToAll(new Msg());

        dist.match(first);
        assertThat(dist.matching(), is(1));

        dist.match(second);
        // second pipe is not a matching one
        assertThat(dist.matching(), is(1));
    }