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 org.opencastproject.job.api.JobProducer;
25  
26  import java.util.Date;
27  
28  /**
29   * Simple implementation of a service registration.
30   */
31  public class ServiceRegistrationInMemoryImpl implements ServiceRegistration {
32  
33    /** Service type */
34    protected String serviceType = null;
35  
36    /** Host that is running the service */
37    protected String host = null;
38  
39    /** Path to the service */
40    protected String path = null;
41  
42    /** The service instance */
43    protected JobProducer service = null;
44  
45    /** True if this service produces jobs */
46    protected boolean isJobProducer = true;
47  
48    /** True if this service is active */
49    protected boolean isActive = true;
50  
51    /** True if this service is online */
52    protected boolean isOnline = true;
53  
54    /** True if this service in in maintenance mode */
55    protected boolean isInMaintenanceMode = true;
56  
57    /** Date from the last time the service has been put online */
58    private Date onlineFrom;
59  
60    private ServiceState serviceState;
61  
62    /**
63     * Creates a new service registration. The service is initially online and not in maintenance mode.
64     *
65     * @param type
66     *          the service type
67     * @param host
68     *          the service host
69     * @param path
70     *          the path to the service
71     * @param jobProducer
72     *          <code>true</code> if the service is a job producer
73     */
74    public ServiceRegistrationInMemoryImpl(String type, String host, String path, boolean jobProducer) {
75      this.serviceType = type;
76      this.host = host;
77      this.path = path;
78      this.isJobProducer = jobProducer;
79    }
80  
81    /**
82     * Creates a new service registration. The service is initially online and not in maintenance mode.
83     *
84     * @param service
85     *          the local service instance
86     * @param host
87     *          the host that the service is running on
88     */
89    public ServiceRegistrationInMemoryImpl(JobProducer service, String host) {
90      this.service = service;
91      this.serviceType = service.getJobType();
92      this.isJobProducer = true;
93      this.host = host;
94    }
95  
96    /**
97     * {@inheritDoc}
98     *
99     * @see org.opencastproject.serviceregistry.api.ServiceRegistration#getServiceType()
100    */
101   @Override
102   public String getServiceType() {
103     return serviceType;
104   }
105 
106   /**
107    * {@inheritDoc}
108    *
109    * @see org.opencastproject.serviceregistry.api.ServiceRegistration#getHost()
110    */
111   @Override
112   public String getHost() {
113     return host;
114   }
115 
116   /**
117    * {@inheritDoc}
118    *
119    * @see org.opencastproject.serviceregistry.api.ServiceRegistration#getPath()
120    */
121   @Override
122   public String getPath() {
123     return path;
124   }
125 
126   /**
127    * {@inheritDoc}
128    *
129    * @see org.opencastproject.serviceregistry.api.ServiceRegistration#isJobProducer()
130    */
131   @Override
132   public boolean isJobProducer() {
133     return isJobProducer;
134   }
135 
136   /**
137    * {@inheritDoc}
138    *
139    * @see org.opencastproject.serviceregistry.api.ServiceRegistration#isActive()
140    */
141   @Override
142   public boolean isActive() {
143     return isActive;
144   }
145 
146   /**
147    * {@inheritDoc}
148    *
149    * @see org.opencastproject.serviceregistry.api.ServiceRegistration#isOnline()
150    */
151   @Override
152   public boolean isOnline() {
153     return isOnline;
154   }
155 
156   /**
157    * {@inheritDoc}
158    *
159    * @see org.opencastproject.serviceregistry.api.ServiceRegistration#isInMaintenanceMode()
160    */
161   @Override
162   public boolean isInMaintenanceMode() {
163     return isInMaintenanceMode;
164   }
165 
166   /**
167    * Sets the service's maintenance mode.
168    *
169    * @param maintenance
170    *          <code>true</code> if the service is in maintenance mode
171    */
172   public void setMaintenance(boolean maintenance) {
173     this.isInMaintenanceMode = maintenance;
174   }
175 
176   /**
177    * Returns the actual service instance.
178    *
179    * @return the service
180    */
181   public JobProducer getService() {
182     return service;
183   }
184 
185   /**
186    *
187    * {@inheritDoc}
188    *
189    * @see org.opencastproject.serviceregistry.api.ServiceRegistration#getOnlineFrom()
190    */
191   @Override
192   public Date getOnlineFrom() {
193     return onlineFrom;
194   }
195 
196   @Override
197   public ServiceState getServiceState() {
198     // TODO Auto-generated method stub
199     return null;
200   }
201 
202   @Override
203   public Date getStateChanged() {
204     // TODO Auto-generated method stub
205     return null;
206   }
207 
208   @Override
209   public int getErrorStateTrigger() {
210     // TODO Auto-generated method stub
211     return 0;
212   }
213 
214   @Override
215   public int getWarningStateTrigger() {
216     // TODO Auto-generated method stub
217     return 0;
218   }
219 
220   @Override
221   public String toString() {
222     return serviceType + "@" + host;
223   }
224 
225 }