forked from SiriDB/java-siridb-connector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
84 lines (68 loc) · 2.79 KB
/
Copy pathExample.java
File metadata and controls
84 lines (68 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package example;
import java.nio.channels.CompletionHandler;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import transceptor.technology.Connection;
public class Example {
public static void main(String[] args) throws InterruptedException {
LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<>();
Connection conn = new Connection("iris", "siri", "test", "localhost", 9000, false);
// Connect
CountDownLatch countDownLatch = new CountDownLatch(1);
conn.connect(new CompletionHandler() {
@Override
public void completed(Object result, Object attachment) {
countDownLatch.countDown();
}
@Override
public void failed(Throwable exc, Object attachment) {
System.out.println("Connection failed: " + exc.getMessage());
}
}, null);
countDownLatch.await();
// Authenticate
CountDownLatch countDownLatch2 = new CountDownLatch(1);
conn.authenticate(new CompletionHandler() {
@Override
public void completed(Object result, Object attachment) {
countDownLatch2.countDown();
}
@Override
public void failed(Throwable exc, Object attachment) {
System.out.println("Connection failed: " + exc.getMessage());
}
}, null);
countDownLatch2.await();
Random random = new Random();
Map<String, Number[][]> map = new HashMap<>();
map.put("some_measurements", new Number[][]{{System.currentTimeMillis(), ((random.nextInt(21) - 10) / 10.0)}});
conn.insert(map, new CompletionHandler() {
@Override
public void completed(Object result, Object attachment) {
((LinkedBlockingQueue) attachment).add(result);
}
@Override
public void failed(Throwable exc, Object attachment) {
System.out.println("exception: " + exc.getMessage());
}
}, queue);
Object result = queue.take();
System.out.println("Insert result: " + result);
conn.query("select * from \"some_measurements\"", new CompletionHandler() {
@Override
public void completed(Object result, Object attachment) {
((LinkedBlockingQueue) attachment).add(result);
}
@Override
public void failed(Throwable exc, Object attachment) {
System.out.println("exception: " + exc.getMessage());
}
}, queue);
result = queue.take();
System.out.println("Query result: " + result);
conn.close();
}
}