1 | package com.framsticks.observers; |
---|
2 | |
---|
3 | import com.framsticks.core.Instance; |
---|
4 | import com.framsticks.core.InstanceListener; |
---|
5 | import com.framsticks.core.Path; |
---|
6 | import com.framsticks.params.annotations.FramsClassAnnotation; |
---|
7 | import com.framsticks.params.annotations.ParamAnnotation; |
---|
8 | import com.framsticks.core.ListChange; |
---|
9 | import com.framsticks.util.dispatching.Dispatcher; |
---|
10 | import org.apache.log4j.Logger; |
---|
11 | import com.framsticks.util.dispatching.RunAt; |
---|
12 | |
---|
13 | /** |
---|
14 | * @author Piotr Sniegowski |
---|
15 | */ |
---|
16 | @FramsClassAnnotation |
---|
17 | public class Endpoint implements Dispatcher<Instance>, InstanceListener { |
---|
18 | private final static Logger log = Logger.getLogger(Endpoint.class.getName()); |
---|
19 | |
---|
20 | @ParamAnnotation |
---|
21 | protected Instance instance; |
---|
22 | protected Observer observer; |
---|
23 | |
---|
24 | @ParamAnnotation |
---|
25 | protected String name; |
---|
26 | |
---|
27 | public Endpoint() { |
---|
28 | } |
---|
29 | |
---|
30 | public final void configurePublic(Observer observer, Instance instance, String name) { |
---|
31 | assert instance != null; |
---|
32 | this.name = name; |
---|
33 | this.observer = observer; |
---|
34 | this.instance = instance; |
---|
35 | instance.addListener(this); |
---|
36 | } |
---|
37 | |
---|
38 | public void start() { |
---|
39 | instance.start(); |
---|
40 | } |
---|
41 | |
---|
42 | @Override |
---|
43 | public void onListChange(Path path, ListChange change) { |
---|
44 | log.info("change " + change + " in " + path); |
---|
45 | } |
---|
46 | |
---|
47 | @Override |
---|
48 | public void onRun(Exception e) { |
---|
49 | } |
---|
50 | |
---|
51 | @Override |
---|
52 | public void onStop(Exception e) { |
---|
53 | } |
---|
54 | |
---|
55 | @Override |
---|
56 | public void onFetch(Path path) { |
---|
57 | log.trace("fetched " + path); |
---|
58 | } |
---|
59 | |
---|
60 | @Override |
---|
61 | public String toString() { |
---|
62 | return instance.toString(); |
---|
63 | } |
---|
64 | |
---|
65 | public final Instance getInstance() { |
---|
66 | return instance; |
---|
67 | } |
---|
68 | |
---|
69 | @Override |
---|
70 | public final boolean isActive() { |
---|
71 | return instance.isActive(); |
---|
72 | } |
---|
73 | |
---|
74 | @Override |
---|
75 | public final void invokeLater(RunAt<? extends Instance> runnable) { |
---|
76 | instance.invokeLater(runnable); |
---|
77 | } |
---|
78 | |
---|
79 | public Observer getObserver() { |
---|
80 | return observer; |
---|
81 | } |
---|
82 | |
---|
83 | public final String getName() { |
---|
84 | return name; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | } |
---|