private void validateConnectionCount(
            final int count, final StubConnection conn) {
        try {
            BOSHClient session = client.get();
            int max = 2;
            if (session != null) {
                CMSessionParams params = session.getCMSessionParams();
                if (params == null) {
                    max = 1;
                } else {
                    AttrRequests requests = params.getRequests();
                    if (requests != null) {
                        max = requests.intValue();
                    }
                }
            }

            AbstractBody msg = conn.getRequest().getBody();
            int extra;
            if (msg.getAttribute(Attributes.PAUSE) != null
                    || "terminate".equals(msg.getAttribute(Attributes.TYPE))) {
                extra = 1;
            } else {
                extra = 0;
            }

            assertTrue("concurrent connections must be 0 <= x <= " + max
                    + "+" + extra + " (was: " + count + ")",
                    count >= 0 && count <= (max + extra));
        } catch (Error err) {
            toThrow.compareAndSet(null, err);
        }
    }