]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.history/src/org/simantics/history/HistorySamplerItem.java
Rest API for Historian data
[simantics/platform.git] / bundles / org.simantics.history / src / org / simantics / history / HistorySamplerItem.java
1 package org.simantics.history;
2
3 import org.simantics.databoard.accessor.StreamAccessor;
4 import org.simantics.databoard.accessor.error.AccessorException;
5 import org.simantics.history.util.StreamIterator;
6
7 public class HistorySamplerItem implements Comparable<HistorySamplerItem> {
8         
9         Collector collector;
10         HistoryManager history;         // History source for this item
11         String historyItemId;
12
13         // State data
14         StreamAccessor accessor;                        // Stream accessor
15         public StreamIterator iter;
16     public int chartDataId;
17         
18         public HistorySamplerItem(Collector collector, HistoryManager history, String historyItemId, int identityHashCode) {
19                 this.collector = collector;
20                 this.history = history;
21                 this.historyItemId = historyItemId;
22                 this.chartDataId = identityHashCode;
23         }
24         
25         public void open() throws HistoryException {
26                 accessor = history.openStream(historyItemId, "r");
27                 iter = new StreamIterator( accessor );
28         }
29         
30         public void close() {
31                 if (accessor!=null) {
32                         try {
33                                 accessor.close();
34                         } catch (AccessorException e) {
35                         }
36                 }
37                 accessor = null;
38                 iter = null;
39         }
40
41         @Override
42         public int compareTo(HistorySamplerItem o) {
43                 int i;
44                 i = historyItemId.compareTo(o.historyItemId);                   
45                 if (i!=0) return i;
46                 return 0;
47         }
48         
49         @Override
50         public int hashCode() {
51                 int code = 0x2304;
52                 code = 13*code + historyItemId.hashCode();
53                 code = 13*code + history.hashCode();                    
54                 return code;
55         }
56         
57         @Override
58         public boolean equals(Object obj) {
59                 if ( obj == null ) return false;
60                 if ( obj instanceof HistorySamplerItem == false ) return false;
61                 HistorySamplerItem other = (HistorySamplerItem) obj;                    
62                 if ( !other.history.equals(history) ) return false;
63                 if ( !other.historyItemId.equals(historyItemId) ) return false;
64                 return true;
65         }
66         
67 }