001/*******************************************************************************
002 * (C) Copyright 2016 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *******************************************************************************/
014package org.nuxeo.ecm.core.work.api;
015
016import java.io.Serializable;
017
018/**
019 * Provides coherent queue metrics
020 *
021 * @since 8.3
022 *
023 */
024public class WorkQueueMetrics implements Serializable {
025
026    private static final long serialVersionUID = 1L;
027
028    public final String queueId;
029
030    public final Number scheduled;
031
032    public final Number running;
033
034    public final Number completed;
035
036    public final Number canceled;
037
038    public WorkQueueMetrics(String queueId, Number scheduled, Number running, Number completed, Number canceled) {
039        this.queueId = queueId;
040        this.scheduled = scheduled;
041        this.running = running;
042        this.completed = completed;
043        this.canceled = canceled;
044    }
045
046    @Override
047    public int hashCode() {
048        final int prime = 31;
049        int result = 1;
050        result = prime * result +  queueId.hashCode();
051        result = prime * result +  scheduled.hashCode();
052        result = prime * result +  running.hashCode();
053        result = prime * result +  completed.hashCode();
054        result = prime * result +  canceled.hashCode();
055        return result;
056    }
057
058    @Override
059    public boolean equals(Object obj) {
060        if (this == obj) {
061            return true;
062        }
063        if (obj == null) {
064            return false;
065        }
066        if (!(obj instanceof WorkQueueMetrics)) {
067            return false;
068        }
069        WorkQueueMetrics other = (WorkQueueMetrics) obj;
070        if (!queueId.equals(other.queueId)) {
071            return false;
072        }
073        if (scheduled.longValue() != other.scheduled.longValue()) {
074            return false;
075        }
076        if (running.longValue() != other.running.longValue()) {
077            return false;
078        }
079        if (completed.longValue() != other.completed.longValue()) {
080            return false;
081        }
082        if (canceled.longValue() != other.canceled.longValue()) {
083            return false;
084        }
085        return true;
086    }
087
088    @Override
089    public String toString() {
090        StringBuilder builder = new StringBuilder();
091        builder.append("[")
092                .append(queueId)
093                .append(", ")
094                .append(scheduled)
095                .append(", ")
096                .append(running)
097                .append(", ")
098                .append(completed)
099                .append(", ")
100                .append(canceled)
101                .append("]");
102        return builder.toString();
103    }
104
105    public String getQueueId() {
106        return queueId;
107    }
108
109    public Number getScheduled() {
110        return scheduled;
111    }
112
113    public Number getRunning() {
114        return running;
115    }
116
117    public Number getCompleted() {
118        return completed;
119    }
120
121    public Number getCanceled() {
122        return canceled;
123    }
124}