/[xulu]/branches/1.8-gt2-2.6/src/appl/parallel/plugin/event/SimpleCommEventMonitorEngine.java
ViewVC logotype

Annotation of /branches/1.8-gt2-2.6/src/appl/parallel/plugin/event/SimpleCommEventMonitorEngine.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Mon Aug 31 14:23:19 2009 UTC (15 years, 4 months ago) by mojays
File size: 5791 byte(s)
Branch 1.8-gt2-2.6 (from rev 45) for geotools 2.6 migration
1 mojays 2 package appl.parallel.plugin.event;
2    
3     import java.awt.event.ActionEvent;
4     import java.awt.event.ActionListener;
5     import java.util.Calendar;
6     import java.util.Comparator;
7     import java.util.GregorianCalendar;
8    
9     import javax.swing.JTable;
10     import javax.swing.table.DefaultTableModel;
11     import javax.swing.table.TableModel;
12     import javax.swing.table.TableRowSorter;
13    
14     import appl.ext.XuluConfig;
15     import appl.parallel.client.RemoteEventHandler;
16     import appl.parallel.event.TimeEvent;
17     import appl.parallel.event.TimeMonitor;
18     import appl.parallel.event.TransferEvent;
19     import appl.parallel.event.TransferMonitor;
20    
21     /**
22     * Controls the {@link SimpleCommEventMonitorPlugin}
23     *
24     * @author Dominik Appl
25     */
26     public class SimpleCommEventMonitorEngine implements TimeMonitor,
27     TransferMonitor, ActionListener {
28    
29     private XuluConfig config;
30    
31     private boolean timeMonitoring;
32    
33     private boolean transferMonitoring;
34    
35     private SimpleCommEventMonitor monitor;
36    
37     private final RemoteEventHandler eventProxy;
38    
39     private DefaultTableModel timeEventModel;
40    
41     private DefaultTableModel transferEventModel;
42    
43     public SimpleCommEventMonitorEngine(RemoteEventHandler eventProxy) {
44     this.eventProxy = eventProxy;
45     config = XuluConfig.getXuluConfig();
46    
47     }
48    
49     /**
50     * @return the GUI for the monitor
51     */
52     public SimpleCommEventMonitor getMonitor() {
53     if (monitor == null) {
54     monitor = new SimpleCommEventMonitor(this);
55     initGUI();
56     }
57     return monitor;
58     }
59    
60     /**
61     * inits the {@link SimpleCommEventMonitor}
62     */
63     public void initGUI() {
64     // get Data from XuluConfig:
65     timeMonitoring = config
66     .getBooleanProperty("SimpleCommEventMonitor.timemonitoring");
67     transferMonitoring = config
68     .getBooleanProperty("SimpleCommEventMonitor.transfermonitoring");
69     // registers itself as timeEvent receiver
70     if (timeMonitoring)
71     eventProxy.addTimeEventListener(this);
72     if (transferMonitoring)
73     eventProxy.addTransferEventListener(this);
74     initTimeEventTable();
75     initTransferEventTable();
76     monitor.timeEventEnabled.setSelected(timeMonitoring);
77     monitor.transferEventEnabled.setSelected(transferMonitoring);
78     }
79    
80     /**
81     *
82     */
83     private void initTimeEventTable() {
84     JTable table = monitor.timeEventTable;
85    
86     timeEventModel = new DefaultTableModel(
87     new Object[] { "Receive Time", "Event type", "Event Source",
88     "Event target", "Exec time (ms)" }, 0);
89     TableRowSorter sorter = new TableRowSorter<TableModel>(timeEventModel);
90     sorter.setComparator(4, LONG_COMPARATOR);
91     table.setModel(timeEventModel);
92     table.setRowSorter(sorter);
93    
94     }
95    
96     private void initTransferEventTable() {
97     JTable table = monitor.transferEventTable;
98     transferEventModel = new DefaultTableModel(new Object[] {
99     "Receive Time", "Event type", "Event Source", "Event target",
100     "Size (kb)" }, 0);
101     TableRowSorter sorter = new TableRowSorter(transferEventModel);
102     sorter.setComparator(4, LONG_COMPARATOR);
103     table.setModel(transferEventModel);
104     table.setRowSorter(sorter);
105     }
106    
107     /*
108     * (non-Javadoc)
109     *
110     * @see appl.parallel.event.TimeMonitor#receiveTimeEvent(appl.parallel.event.TimeEvent)
111     */
112     public synchronized void receiveTimeEvent(TimeEvent t) {
113     timeEventModel.addRow(new Object[] { getCurrentTimeString(),
114     t.getType(), t.getSrc(), t.getTarget(),
115     (long) (t.getTime() / 1000000) });
116     }
117    
118     /*
119     * (non-Javadoc)
120     *
121     * @see appl.parallel.event.TransferMonitor#receiveTransferEvent(appl.parallel.event.TransferEvent)
122     */
123     public void receiveTransferEvent(TransferEvent t) {
124     transferEventModel.addRow(new Object[] { getCurrentTimeString(),
125     t.getType(), t.getSrc(), t.getTarget(),
126     (long) (t.getSize() / 1024) });
127     }
128    
129     public String getCurrentTimeString() {
130     Calendar cal = new GregorianCalendar();
131     String hour = String.valueOf(cal.get(Calendar.HOUR_OF_DAY));
132     while (hour.length() < 2)
133     hour = "0" + hour;
134     String min = String.valueOf(cal.get(Calendar.MINUTE));
135     while (min.length() < 2)
136     min = "0" + min;
137     String sec = String.valueOf(cal.get(Calendar.SECOND));
138     while (sec.length() < 2)
139     sec = "0" + sec;
140     String ms = String.valueOf(cal.get(Calendar.MILLISECOND));
141     while (ms.length() < 3)
142     ms = "0" + ms;
143     String time = hour + ":" + min + ":" + sec + ":" + ms;
144     return time;
145     }
146    
147     /*
148     * (non-Javadoc)
149     *
150     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
151     */
152     public void actionPerformed(ActionEvent e) {
153     Object src = e.getSource();
154     if (src == monitor.transferEventEnabled) {
155     eventProxy.removeTransferMonitor(this);
156     if (monitor.transferEventEnabled.isSelected()) {
157     eventProxy.addTransferEventListener(this);
158     config.setBooleanProperty(
159     "SimpleCommEventMonitor.transfermonitoring", true);
160     } else
161     config.setBooleanProperty(
162     "SimpleCommEventMonitor.transfermonitoring", false);
163     }
164     if (src == monitor.timeEventEnabled) {
165     eventProxy.removeTimeMonitor(this);
166     if (monitor.timeEventEnabled.isSelected()) {
167     eventProxy.addTimeEventListener(this);
168     config.setBooleanProperty(
169     "SimpleCommEventMonitor.timemonitoring", true);
170     } else
171     config.setBooleanProperty(
172     "SimpleCommEventMonitor.timemonitoring", false);
173     }
174     if (src == monitor.clearButton) {
175     initTimeEventTable();
176     initTransferEventTable();
177     }
178     }
179    
180     /**
181     * stops the execution
182     */
183     public void stop() {
184     eventProxy.removeTimeMonitor(this);
185     eventProxy.removeTransferMonitor(this);
186     }
187    
188     /**
189     * The comparator is used for sorting the values in the {@link JTable}
190     */
191     public static final Comparator LONG_COMPARATOR = new Comparator() {
192     public int compare(Object o1, Object o2) {
193     return ((Long) o1).compareTo((Long) o2);
194     }
195     };
196    
197     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26