1 package org.opentrafficsim.imb.observers;
2
3 import java.rmi.RemoteException;
4
5 import org.opentrafficsim.core.gtu.GTU;
6
7 import nl.tudelft.simulation.event.EventInterface;
8 import nl.tudelft.simulation.event.EventListenerInterface;
9 import nl.tudelft.simulation.language.d3.DirectedPoint;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class IMBTransmitter implements EventListenerInterface
23 {
24
25 private Observer observer = null;
26
27
28 public IMBTransmitter()
29 {
30 try
31 {
32 this.observer = new IMBObserver("localhost"
33 , 4000, "GTUObserver", 1, "OTS_RT");
34 System.out.println("Observer is " + this.observer);
35 }
36 catch (Exception exception1)
37 {
38 System.out.println("Observer creation failed; GTU movements will not be sent to observer");
39 }
40 }
41
42
43 @Override
44 public void notify(final EventInterface event) throws RemoteException
45 {
46 if (this.observer == null)
47 {
48 return;
49 }
50
51 if (event.getType().equals(GTU.MOVE_EVENT))
52 {
53 Object[] moveInfo = (Object[]) event.getContent();
54 DirectedPoint location = (DirectedPoint) moveInfo[1];
55 try
56 {
57 this.observer.postMessage("GTU", Observer.CHANGE,
58 new Object[] { moveInfo[0].toString(), location.x, location.y, location.z, location.getRotZ() });
59 }
60 catch (Exception exception)
61 {
62 exception.printStackTrace();
63 }
64 }
65 else if (event.getType().equals(GTU.DESTROY_EVENT))
66 {
67 Object[] destroyInfo = (Object[]) event.getContent();
68 DirectedPoint location = (DirectedPoint) destroyInfo[1];
69 try
70 {
71 this.observer.postMessage("GTU", Observer.DELETE,
72 new Object[] { destroyInfo[0].toString(), location.x, location.y, location.z, location.getRotZ() });
73 }
74 catch (Exception exception)
75 {
76 exception.printStackTrace();
77 }
78 }
79 }
80 }
81
82