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  package org.opencastproject.scheduler.api;
22  
23  
24  /**
25   * An in-memory construct to represent the state of a recording, and when it was last heard from.
26   */
27  public class RecordingImpl implements Recording {
28  
29    /**
30     * The ID of the recording.
31     */
32    private String id;
33  
34    /**
35     * The state of the recording. This should be defined from RecordingState.
36     */
37    private String state;
38  
39    /**
40     * The time at which the recording last checked in with this service. Note that this is an absolute timestamp (ie,
41     * milliseconds since 1970) rather than a relative timestamp (ie, it's been 3000 ms since it last checked in).
42     */
43    private Long lastHeardFrom;
44  
45    /**
46     * Builds a representation of the recording.
47     *
48     * @param recordingID
49     *          The ID of the recording.
50     * @param recordingState
51     *          The state of the recording. This should be defined from RecordingState.
52     * @param lastHeard
53     *          The time at which the recording last checked in
54     */
55    public RecordingImpl(String recordingID, String recordingState, long lastHeard) {
56      id = recordingID;
57      state = recordingState;
58      lastHeardFrom = lastHeard;
59    }
60  
61    /**
62     * Builds a representation of the recording.
63     *
64     * @param recordingID
65     *          The ID of the recording.
66     * @param recordingState
67     *          The state of the recording. This should be defined from RecordingState.
68     */
69    public RecordingImpl(String recordingID, String recordingState) {
70      id = recordingID;
71      this.setState(recordingState);
72    }
73  
74    /**
75     * {@inheritDoc}
76     *
77     * @see org.opencastproject.scheduler.api.Recording#getID()
78     */
79    @Override
80    public String getID() {
81      return id;
82    }
83  
84    /**
85     * {@inheritDoc}
86     *
87     * @see org.opencastproject.scheduler.api.Recording#setState(java.lang.String)
88     */
89    @Override
90    public void setState(String newState) {
91      state = newState;
92      lastHeardFrom = System.currentTimeMillis();
93    }
94  
95    /**
96     * {@inheritDoc}
97     *
98     * @see org.opencastproject.scheduler.api.Recording#getState()
99     */
100   @Override
101   public String getState() {
102     return state;
103   }
104 
105   /**
106    * {@inheritDoc}
107    *
108    * @see org.opencastproject.scheduler.api.Recording#getLastCheckinTime()
109    */
110   @Override
111   public Long getLastCheckinTime() {
112     return lastHeardFrom;
113   }
114 }