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