1 package org.opentrafficsim.road.network.lane.object.sensor;
2
3 import java.rmi.RemoteException;
4
5 import javax.naming.NamingException;
6
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.opentrafficsim.core.dsol.OTSDEVSSimulatorInterface;
9 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
10 import org.opentrafficsim.core.gtu.RelativePosition;
11 import org.opentrafficsim.core.network.NetworkException;
12 import org.opentrafficsim.road.gtu.lane.LaneBasedGTU;
13 import org.opentrafficsim.road.network.animation.SinkAnimation;
14 import org.opentrafficsim.road.network.lane.CrossSectionElement;
15 import org.opentrafficsim.road.network.lane.Lane;
16
17 import nl.tudelft.simulation.language.Throw;
18
19
20
21
22
23
24
25
26
27
28
29
30
31 public class SinkSensor extends AbstractSensor
32 {
33
34 private static final long serialVersionUID = 20150130L;
35
36
37
38
39
40
41
42 public SinkSensor(final Lane lane, final Length position, final OTSDEVSSimulatorInterface simulator) throws NetworkException
43 {
44 super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator);
45 try
46 {
47 new SinkAnimation(this, simulator);
48 }
49 catch (RemoteException | NamingException exception)
50 {
51 exception.printStackTrace();
52 }
53 }
54
55
56
57
58
59
60
61
62
63 public SinkSensor(final String dummy1, final Lane lane, final Length position, final RelativePosition.TYPE dummy2,
64 final OTSDEVSSimulatorInterface simulator) throws NetworkException
65 {
66 super("SINK@" + lane.toString(), lane, position, RelativePosition.FRONT, simulator);
67 try
68 {
69 new SinkAnimation(this, simulator);
70 }
71 catch (RemoteException | NamingException exception)
72 {
73 exception.printStackTrace();
74 }
75 }
76
77
78 @Override
79 public final void triggerResponse(final LaneBasedGTU gtu)
80 {
81 gtu.destroy();
82 }
83
84
85 @Override
86 public final String toString()
87 {
88 return "SinkSensor [Lane=" + this.getLane() + "]";
89 }
90
91
92 @Override
93 @SuppressWarnings("checkstyle:designforextension")
94 public SinkSensor clone(final CrossSectionElement newCSE, final OTSSimulatorInterface newSimulator, final boolean animation)
95 throws NetworkException
96 {
97 Throw.when(!(newCSE instanceof Lane), NetworkException.class, "sensors can only be cloned for Lanes");
98 Throw.when(!(newSimulator instanceof OTSDEVSSimulatorInterface), NetworkException.class,
99 "simulator should be a DEVSSimulator");
100 return new SinkSensor((Lane) newCSE, getLongitudinalPosition(), (OTSDEVSSimulatorInterface) newSimulator);
101 }
102
103 }