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.capture.admin.api;
23  
24  import org.opencastproject.util.HashtableAdapter;
25  
26  import java.util.Properties;
27  
28  import javax.xml.bind.annotation.XmlAccessType;
29  import javax.xml.bind.annotation.XmlAccessorType;
30  import javax.xml.bind.annotation.XmlElement;
31  import javax.xml.bind.annotation.XmlRootElement;
32  import javax.xml.bind.annotation.XmlType;
33  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
34  
35  /**
36   * A representation of an agent which stores its name, state and time-since-last-update value.
37   */
38  @XmlType(name = "agent-state-update", namespace = "http://capture.admin.opencastproject.org")
39  @XmlRootElement(name = "agent-state-update", namespace = "http://capture.admin.opencastproject.org")
40  @XmlAccessorType(XmlAccessType.FIELD)
41  public class AgentStateUpdate {
42  
43    /**
44     * The agent's name.
45     */
46    @XmlElement(name = "name")
47    private String name;
48  
49    /**
50     * The state of the agent. This should be defined from the constants in
51     * {@link org.opencastproject.capture.admin.api.AgentState}.
52     *
53     * @see AgentState
54     */
55    @XmlElement(name = "state")
56    private String state;
57  
58    /**
59     * The agent's URL.
60     */
61    @XmlElement(name = "url")
62    private String url;
63  
64    /**
65     * The number of milliseconds since the last time the agent checked in. Note that this is relative (ie, it's been 3000
66     * ms) rather than absolute (milliseconds since 1970).
67     */
68    @XmlElement(name = "time-since-last-update")
69    private Long timeSinceLastUpdate;
70  
71    @XmlJavaTypeAdapter(HashtableAdapter.class)
72    private Properties capabilities;
73  
74    /**
75     * Required zero-arg. constructor. Do not use.
76     */
77    public AgentStateUpdate() {
78    }
79  
80    /**
81     * Builds an AgentStateUpdate object about the Agent a. This calculates the time delta for you.
82     *
83     * @param a
84     *          The agent you wish to know more information about.
85     */
86    public AgentStateUpdate(Agent a) {
87      name = a.getName();
88      state = a.getState();
89      url = a.getUrl();
90      capabilities = a.getCapabilities();
91      timeSinceLastUpdate = System.currentTimeMillis() - a.getLastHeardFrom();
92    }
93  
94    /**
95     * Returns the agent name.
96     *
97     * @return the name
98     */
99    public String getName() {
100     return name;
101   }
102 
103   /**
104    * Returns the agent url.
105    *
106    * @return the url
107    */
108   public String getUrl() {
109     return url;
110   }
111 
112   /**
113    * Returns the agent state.
114    *
115    * @return the state
116    */
117   public String getState() {
118     return state;
119   }
120 
121   /**
122    * Returns the agent capabilities.
123    *
124    * @return the capabilities
125    */
126   public Properties getCapabilities() {
127     return capabilities;
128   }
129 
130   /**
131    * Returns the time when the agent was last seen online.
132    *
133    * @return the time of the last update
134    */
135   public Long getTimeSinceLastUpdate() {
136     return timeSinceLastUpdate;
137   }
138 
139 }