001/*******************************************************************************
002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *******************************************************************************/
016package org.nuxeo.ecm.core.work.api;
017
018import java.io.Serializable;
019
020/**
021 * Provides coherent queue metrics
022 *
023 * @since 8.3
024 *
025 */
026public class WorkQueueMetrics implements Serializable {
027
028    private static final long serialVersionUID = 1L;
029
030    public final String queueId;
031
032    public final Number scheduled;
033
034    public final Number running;
035
036    public final Number completed;
037
038    public final Number canceled;
039
040    public WorkQueueMetrics(String queueId, Number scheduled, Number running, Number completed, Number canceled) {
041        this.queueId = queueId;
042        this.scheduled = scheduled;
043        this.running = running;
044        this.completed = completed;
045        this.canceled = canceled;
046    }
047
048    @Override
049    public int hashCode() {
050        final int prime = 31;
051        int result = 1;
052        result = prime * result +  queueId.hashCode();
053        result = prime * result +  scheduled.hashCode();
054        result = prime * result +  running.hashCode();
055        result = prime * result +  completed.hashCode();
056        result = prime * result +  canceled.hashCode();
057        return result;
058    }
059
060    @Override
061    public boolean equals(Object obj) {
062        if (this == obj) {
063            return true;
064        }
065        if (obj == null) {
066            return false;
067        }
068        if (!(obj instanceof WorkQueueMetrics)) {
069            return false;
070        }
071        WorkQueueMetrics other = (WorkQueueMetrics) obj;
072        if (!queueId.equals(other.queueId)) {
073            return false;
074        }
075        if (scheduled.longValue() != other.scheduled.longValue()) {
076            return false;
077        }
078        if (running.longValue() != other.running.longValue()) {
079            return false;
080        }
081        if (completed.longValue() != other.completed.longValue()) {
082            return false;
083        }
084        if (canceled.longValue() != other.canceled.longValue()) {
085            return false;
086        }
087        return true;
088    }
089
090    @Override
091    public String toString() {
092        StringBuilder builder = new StringBuilder();
093        builder.append("[")
094                .append(queueId)
095                .append(", ")
096                .append(scheduled)
097                .append(", ")
098                .append(running)
099                .append(", ")
100                .append(completed)
101                .append(", ")
102                .append(canceled)
103                .append("]");
104        return builder.toString();
105    }
106
107    public String getQueueId() {
108        return queueId;
109    }
110
111    public Number getScheduled() {
112        return scheduled;
113    }
114
115    public Number getRunning() {
116        return running;
117    }
118
119    public Number getCompleted() {
120        return completed;
121    }
122
123    public Number getCanceled() {
124        return canceled;
125    }
126}