1
2
3
4
5 package org.epics.pvmanager.sim;
6
7 import java.util.concurrent.Executors;
8 import java.util.concurrent.ScheduledExecutorService;
9 import java.util.logging.Logger;
10 import org.epics.pvmanager.ChannelHandler;
11 import org.epics.pvmanager.DataSource;
12 import org.epics.pvmanager.vtype.DataTypeSupport;
13 import static org.epics.pvmanager.util.Executors.*;
14
15
16
17
18
19
20
21 public final class SimulationDataSource extends DataSource {
22
23 static {
24
25 DataTypeSupport.install();
26 }
27
28 public SimulationDataSource() {
29 super(false);
30 }
31
32
33
34
35
36
37 public static DataSource simulatedData() {
38 return SimulationDataSource.instance;
39 }
40
41 private static final Logger log = Logger.getLogger(SimulationDataSource.class.getName());
42 static final SimulationDataSource instance = new SimulationDataSource();
43
44
45
46
47 private static ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor(namedPool("PVMgr Simulator "));
48
49 @Override
50 @SuppressWarnings("unchecked")
51 protected ChannelHandler createChannel(String channelName) {
52 if (channelName.startsWith("const(")) {
53 return new ConstantChannelHandler(channelName);
54 }
55 if (channelName.startsWith("delayedConnectionChannel(")) {
56 return new DelayedConnectionChannelHandler(channelName, exec);
57 }
58 if (channelName.startsWith("intermittentChannel(")) {
59 return new IntermittentChannelHandler(channelName, exec);
60 }
61
62 SimFunction<?> simFunction = (SimFunction<?>) NameParser.createFunction(channelName);
63 return new SimulationChannelHandler(channelName, simFunction, exec);
64 }
65
66 }