class CounterSwitchPipe extends FixedForwardPipe {

	@Override
	public PipeRunResult doPipe(Message message, IPipeLineSession session) throws PipeRunException {
		String forward = "";
		PipeForward pipeForward = null;

		StatisticsKeeper sk = getPipeLine().getPipeStatistics(this);
		if (sk != null) {
			long count = sk.getCount();
			forward = "" + (getDivisor() - (count % getDivisor()));
		}

		log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");

		pipeForward = findForward(forward);

		if (pipeForward == null) {
			throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
		}
		log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
		return new PipeRunResult(pipeForward, message);
	}

}