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 java.util.HashMap;
25  import java.util.Map;
26  
27  /**
28   * Provides statistics about host registrations
29   */
30  public class HostStatistics {
31    private final Map<Long, Long> queued = new HashMap<>();
32    private final Map<Long, Long> running = new HashMap<>();
33  
34    /**
35     * Add statistics for a registered host
36     *
37     * @param hostId Identifier of host
38     * @param queued Number of queued jobs for this host
39     */
40    public void addQueued(final long hostId, final long queued) {
41      this.queued.put(hostId, queued);
42    }
43  
44    /**
45     * Add statistics for a registered host
46     *
47     * @param hostId Identifier of host
48     * @param running Number of running jobs on this host
49     */
50    public void addRunning(final long hostId, final long running) {
51      this.running.put(hostId, running);
52    }
53  
54    /**
55     * Get number of queued jobs on a specific host.
56     *
57     * @param hostId Identifier of host
58     * @return Number of queued jobs
59     */
60    public long queuedJobs(final long hostId) {
61      return queued.getOrDefault(hostId, 0L);
62    }
63  
64    /**
65     * Get number of running jobs on a specific host.
66     *
67     * @param hostId Identifier of host
68     * @return Number of running jobs
69     */
70    public long runningJobs(final long hostId) {
71      return running.getOrDefault(hostId, 0L);
72    }
73  }