View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  
22  package org.opencastproject.serviceregistry.api;
23  
24  import javax.xml.bind.annotation.XmlAccessType;
25  import javax.xml.bind.annotation.XmlAccessorType;
26  import javax.xml.bind.annotation.XmlAttribute;
27  import javax.xml.bind.annotation.XmlElement;
28  import javax.xml.bind.annotation.XmlRootElement;
29  import javax.xml.bind.annotation.XmlType;
30  
31  /**
32   * Statistics for a service registration.
33   */
34  @XmlAccessorType(XmlAccessType.NONE)
35  @XmlType(name = "statistic", namespace = "http://serviceregistry.opencastproject.org")
36  @XmlRootElement(name = "statistic", namespace = "http://serviceregistry.opencastproject.org")
37  public class JaxbServiceStatistics implements ServiceStatistics {
38  
39    /** The service registration **/
40    @XmlElement
41    protected JaxbServiceRegistration serviceRegistration;
42  
43    /** The mean run time for jobs **/
44    @XmlAttribute(name = "meanruntime")
45    protected long meanRunTime;
46  
47    /** The mean queue time for jobs **/
48    @XmlAttribute(name = "meanqueuetime")
49    protected long meanQueueTime;
50  
51    /** The number of finished jobs **/
52    @XmlAttribute(name = "finished")
53    protected int finishedJobs;
54  
55    /** The number of currently running jobs **/
56    @XmlAttribute(name = "running")
57    protected int runningJobs;
58  
59    /** The number of currently queued jobs **/
60    @XmlAttribute(name = "queued")
61    protected int queuedJobs;
62  
63    /**
64     * No-arg constructor needed by JAXB
65     */
66    public JaxbServiceStatistics() {
67    }
68  
69    /**
70     * Constructs a new service statistics instance without statistics.
71     *
72     * @param serviceRegistration
73     *          the service registration
74     */
75    public JaxbServiceStatistics(JaxbServiceRegistration serviceRegistration) {
76      super();
77      this.serviceRegistration = serviceRegistration;
78    }
79  
80    /**
81     * Constructs a new service statistics instance without statistics.
82     *
83     * @param serviceRegistration
84     *          the service registration
85     */
86    public JaxbServiceStatistics(ServiceRegistration serviceRegistration) {
87      super();
88      this.serviceRegistration = new JaxbServiceRegistration(serviceRegistration);
89    }
90  
91    /**
92     * Constructs a new service statistics instance with statistics.
93     *
94     * @param serviceRegistration
95     *          the service registration
96     * @param meanRunTime
97     * @param meanQueueTime
98     * @param runningJobs
99     * @param queuedJobs
100    */
101   public JaxbServiceStatistics(JaxbServiceRegistration serviceRegistration, long meanRunTime, long meanQueueTime,
102           int runningJobs, int queuedJobs, int finishedJobs) {
103     this(serviceRegistration);
104     this.meanRunTime = meanRunTime;
105     this.meanQueueTime = meanQueueTime;
106     this.runningJobs = runningJobs;
107     this.finishedJobs = finishedJobs;
108     this.queuedJobs = queuedJobs;
109   }
110 
111   /**
112    * {@inheritDoc}
113    *
114    * @see org.opencastproject.serviceregistry.api.ServiceStatistics#getMeanQueueTime()
115    */
116   @Override
117   public long getMeanQueueTime() {
118     return meanQueueTime;
119   }
120 
121   /**
122    * Sets the mean queue time.
123    *
124    * @param meanQueueTime
125    *          the mean queue time
126    */
127   public void setMeanQueueTime(long meanQueueTime) {
128     this.meanQueueTime = meanQueueTime;
129   }
130 
131   /**
132    * {@inheritDoc}
133    *
134    * @see org.opencastproject.serviceregistry.api.ServiceStatistics#getMeanRunTime()
135    */
136   @Override
137   public long getMeanRunTime() {
138     return meanRunTime;
139   }
140 
141   /**
142    * Sets the mean run time.
143    *
144    * @param meanRunTime
145    *          the mean run time.
146    */
147   public void setMeanRunTime(long meanRunTime) {
148     this.meanRunTime = meanRunTime;
149   }
150 
151   /**
152    * {@inheritDoc}
153    *
154    * @see org.opencastproject.serviceregistry.api.ServiceStatistics#getFinishedJobs()
155    */
156   @Override
157   public int getFinishedJobs() {
158     return finishedJobs;
159   }
160 
161   /**
162    * Sets the number of finished jobs
163    *
164    * @param finishedJobs
165    *          the number of finished jobs
166    */
167   public void setFinishedJobs(int finishedJobs) {
168     this.finishedJobs = finishedJobs;
169   }
170 
171   /**
172    * {@inheritDoc}
173    *
174    * @see org.opencastproject.serviceregistry.api.ServiceStatistics#getQueuedJobs()
175    */
176   @Override
177   public int getQueuedJobs() {
178     return queuedJobs;
179   }
180 
181   /**
182    * Sets the number of queued jobs
183    *
184    * @param queuedJobs
185    *          the number of queued jobs
186    */
187   public void setQueuedJobs(int queuedJobs) {
188     this.queuedJobs = queuedJobs;
189   }
190 
191   /**
192    * {@inheritDoc}
193    *
194    * @see org.opencastproject.serviceregistry.api.ServiceStatistics#getRunningJobs()
195    */
196   @Override
197   public int getRunningJobs() {
198     return runningJobs;
199   }
200 
201   /**
202    * Sets the number of running jobs
203    *
204    * @param runningJobs
205    *          the number of running jobs
206    */
207   public void setRunningJobs(int runningJobs) {
208     this.runningJobs = runningJobs;
209   }
210 
211   /**
212    * {@inheritDoc}
213    *
214    * @see org.opencastproject.serviceregistry.api.ServiceStatistics#getServiceRegistration()
215    */
216   @Override
217   public ServiceRegistration getServiceRegistration() {
218     return serviceRegistration;
219   }
220 
221 }