Merge "Partial Implementation of US1574:"
[platform/upstream/iotivity.git] / csdk / android / OCLib / src / com / oc / OCObserver.java
1 //******************************************************************
2 //
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 package com.oc;
22
23 import java.util.UUID;
24
25 /**
26  * 
27  * TODO: Consider including Attachment like java.nio.CompletionHandler
28  * 
29  * @param <T>
30  */
31 public class OCObserver<T> implements Comparable<OCObserver<T>> {
32   private static UUID observerId = UUID.randomUUID();
33
34   /**
35    * 
36    * The OC service calls this at intervals n until the expired callback occurs.
37    * 
38    */
39   public void onChanged(T data) {}
40
41   /**
42    * Called if a failure occurred. No more events will occur after this is callback.
43    * 
44    * @param throwable - The error that caused this callback sequence to fail.
45    */
46   public void onFailed(Throwable throwable) {}
47
48   @Override
49   public int compareTo(OCObserver<T> another) {
50     return observerId.compareTo(another.getObserverId());
51   }
52
53   /**
54    * 
55    * @return observerId associated with this OCObserver object.
56    */
57   UUID getObserverId() {
58     return observerId;
59   }
60 }