View Javadoc
1   /**
2    * Copyright (C) 2010-14 pvmanager developers. See COPYRIGHT.TXT
3    * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4    */
5   package org.epics.pvmanager.sample;
6   
7   import gov.aps.jca.Context;
8   import gov.aps.jca.Monitor;
9   import java.util.concurrent.Executor;
10  import org.epics.pvmanager.CompositeDataSource;
11  import static org.epics.pvmanager.ExpressionLanguage.*;
12  import org.epics.pvmanager.PVManager;
13  import org.epics.pvmanager.PVReader;
14  import org.epics.pvmanager.jca.JCADataSource;
15  import org.epics.pvmanager.jca.JCADataSourceBuilder;
16  import org.epics.pvmanager.sim.SimulationDataSource;
17  import static org.epics.pvmanager.util.Executors.*;
18  import static org.epics.util.time.TimeDuration.*;
19  
20  /**
21   * Examples for basic configuration of pvmanager
22   *
23   * @author carcassi
24   */
25  public class ConfigurationExamples {
26  
27      public void e1_pvManagerInCSS() {
28          // In CSS, data sources are configured by adding the appropriate plug-ins,
29          // so you **must not change the default configuration**.
30          // If you are developing user interfaces in SWT, you will want to route the notifications on the SWT thread.
31  
32          // Import from here
33          // import static org.csstudio.utility.pvmanager.ui.SWTUtil.*;
34   
35          // When creating a pv, remember to ask for notification on the SWT thread
36          PVReader<?> pvReader = PVManager.read(channel("test")).notifyOn(swtThread()).maxRate(ofMillis(100));
37      }
38  
39      public void e2_pvManagerInSwing() {
40          // You will first need to configure the data sources yourself (see other examples).
41          // You will want to route notification directly on the Event Dispatch Thread.
42          // You can do this on a PV by PV basis, or you can change the default. 
43          
44          // Import from here
45          // import static org.epics.pvmanager.util.Executors.*;
46   
47          // Route notification for this pv on the Swing EDT
48          PVReader<?> pvReader = PVManager.read(channel("test")).notifyOn(swingEDT()).maxRate(ofMillis(100));
49  
50          // Or you can change the default
51          PVManager.setDefaultNotificationExecutor(swingEDT());
52      }
53  
54      public void e3_configuringJcaAsDefaultDataSource() {
55          // Sets CAJ (pure java implementation) as the default data source,
56          // monitoring both value and alarm changes
57          PVManager.setDefaultDataSource(new JCADataSource());
58  
59          // For ultimate control, you can modify all the parameters, 
60          // and even create the JCA context yourself
61          Context jcaContext = null;
62          PVManager.setDefaultDataSource(new JCADataSourceBuilder()
63                  .monitorMask(Monitor.VALUE | Monitor.ALARM)
64                  .jcaContext(jcaContext)
65                  .build());
66          
67          // For more options, check JCADataSource and JCADataSourceBuilder.
68      }
69  
70      public void e4_configuringMultipleDataSources() {
71          // Create a multiple data source, and add different data sources
72          CompositeDataSource composite = new CompositeDataSource();
73          composite.putDataSource("ca", new JCADataSource());
74          composite.putDataSource("sim", new SimulationDataSource());
75  
76          // If no prefix is given to a channel, use JCA as default
77          composite.setDefaultDataSource("ca");
78  
79          // Set the composite as the default
80          PVManager.setDefaultDataSource(composite);
81          
82          // For more options, check CompositeDataSource.
83      }
84      
85      
86      
87      
88      
89      
90      
91      
92      
93      
94      
95      
96      
97      
98      
99      
100     
101     
102     
103     
104     
105     
106     public static Executor swtThread() {
107         // Mock method to make the examples compile
108         // This method will be in CSS
109         return null;
110     }
111 }