...
/**
 * Actions queue stats producer.
 */
public class ActionsQueueStatsProducer implements IStatsProducer {

	/**
	 * Stats list.
	 */
	private List<IStats> statsList;
	/**
	 * Actions queue stats instance.
	 */
	private ActionsQueueStats stats;

	/**
	 * Constructor. Producer will be registered himself in IProducerRegistry.
	 *
	 * @param name stats name.
	 * @param selectedIntervals supported intervals.
	 */
	public ActionsQueueStatsProducer(final String name,  final Interval[] selectedIntervals) {
		stats = new ActionsQueueStats(name, selectedIntervals);

		statsList = new ArrayList<IStats>();
		statsList.add(stats);

		IProducerRegistry registry = ProducerRegistryFactory.getProducerRegistryInstance();
		registry.registerProducer(this);
	}

	@Override
	public final String getCategory() {
		return "actionsQueue";
	}

	@Override
	public final String getProducerId() {
		return "CMProfileActionsQueue";
	}

	@Override
	public final List<IStats> getStats() {
		return statsList;
	}

	@Override
	public final String getSubsystem() {
		return "CheetahMailProfileSys";
	}

	/**
	 * Add requested (planned to be enqueued) action to stats.
	 *
	 * @param action requested action.
	 * @param currentQueueElements current queue elements count.
	 */
	public final void addRequestedAction(final CMProfileAction action, final long currentQueueElements) {
		stats.addRequestedAction(action, currentQueueElements);
	}

	/**
	 * Add enqueued action to stats.
	 */
	public final void addEnqueuedAction() {
		stats.addEnqueuedAction();
	}

	/**
	 * Add processed actions batch to stats.
	 *
	 * @param actions processed actions.
	 * @param processingTime processing time in mills.
	 */
	public final void addProcessedActions(final List<CMProfileAction> actions, final long processingTime) {
		stats.addProcessedBatch(actions, processingTime);
	}

	/**
	 * Add queue overflow (unrecoverable overflow) to stats.
	 */
	public final void addQueueOverflow() {
		stats.addQueueOverflow();
	}

	/**
	 * Add processing error to stats.
	 */
	public final void addProcessingError() {
		stats.addProcessingError();
	}
}
  • No labels