]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.history/src/org/simantics/history/History.java
Rest API for Historian data
[simantics/platform.git] / bundles / org.simantics.history / src / org / simantics / history / History.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.history;
13
14 import java.io.File;
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.io.OutputStream;
18
19 import org.simantics.databoard.binding.Binding;
20 import org.simantics.history.impl.CollectorImpl;
21 import org.simantics.history.impl.FileHistory;
22 import org.simantics.history.impl.FlushPolicy;
23 import org.simantics.history.impl.MemoryHistory;
24 import org.simantics.history.util.HistoryExportUtil;
25
26 /**
27  * Facade-class for History Services.
28  * 
29  * There are two main services HistoryManager and Collector.
30  * There are two main implementations file and memory.
31  * 
32  * @author toni.kalajainen
33  */
34 public class History {
35
36         /**
37          * Open a file based history manager.
38          * (Note, Trend does not need flush policy)
39          * 
40          * @param workarea
41          * @return history manager
42          */
43         public static HistoryManager openFileHistory(File workarea)
44         {
45                 return new FileHistory(workarea);
46         }
47         
48         /**
49          * Create a transient memory history
50          * 
51          * @return no history
52          */
53         public static HistoryManager createMemoryHistory()
54         {
55                 return new MemoryHistory();
56         }
57         
58         /**
59          * Create collector
60          * 
61          * @param historyManager
62          * @return collector
63          */
64         public static Collector createCollector(HistoryManager historyManager)
65         {
66                 CollectorImpl result = new CollectorImpl(historyManager);
67                 return result;
68         }
69         
70         /**
71          * Create collector
72          * 
73          * @param historyManager
74          * @param flushPolicy
75          * @return collector
76          */
77         public static Collector createCollector(HistoryManager historyManager, FlushPolicy flushPolicy)
78         {
79                 CollectorImpl result = new CollectorImpl(historyManager);
80                 result.setFlushPolicy(flushPolicy);
81                 return result;
82         }
83
84         /**
85          * Export whole history manager to an output stream.
86          * 
87          * @param history
88          * @param timeBinding
89          * @param from
90          * @param end
91          * @param os
92          * @throws IOException
93          * @throws HistoryException
94          */
95         public static void exportHistory( HistoryManager history, Binding timeBinding, Double from, Double end, OutputStream os )
96         throws IOException, HistoryException
97         {
98                 HistoryExportUtil eu = new HistoryExportUtil();
99                 eu.exportHistory(history, timeBinding, from, end, os);
100         }
101         
102         /**
103          * Import a history manager from an input stream 
104          * 
105          * @param history
106          * @param is
107          * @throws IOException
108          * @throws HistoryException
109          */
110         public static void importHistory( HistoryManager history, InputStream is )
111         throws IOException, HistoryException
112         {
113                 HistoryExportUtil eu = new HistoryExportUtil();
114                 eu.importHistory(history, is);
115         }
116
117 }