Added graphing support. Complete (?) but disabled and replaced by mocked data.
This commit is contained in:
@ -39,6 +39,8 @@
|
||||
<classpath>
|
||||
<pathelement location="${lib}/commons-logging-1.1.1.jar" />
|
||||
<pathelement location="${lib}/json-smart-1.0.6.4.jar" />
|
||||
<pathelement location="${lib}/jchart2d-3.2.1.jar" />
|
||||
<pathelement location="${lib}/xmlgraphics-commons-1.3.1.jar" />
|
||||
</classpath>
|
||||
</javac>
|
||||
<copy todir="${build}/${resources}">
|
||||
@ -57,7 +59,7 @@
|
||||
<jar basedir="${build}" destfile="${dist}/${jar}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="net.i2p.itoopie.Main"/>
|
||||
<attribute name="Class-Path" value="${lib}/commons-logging-1.1.1.jar ${lib}/json-smart-1.0.6.4.jar" />
|
||||
<attribute name="Class-Path" value="${lib}/commons-logging-1.1.1.jar ${lib}/json-smart-1.0.6.4.jar ${lib}/jchart2d-3.2.1.jar ${lib}/xmlgraphics-commons-1.3.1.jar" />
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
@ -1,6 +1,10 @@
|
||||
package net.i2p.itoopie.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.security.cert.X509Certificate;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
@ -17,6 +21,10 @@ public class CertificateGUI {
|
||||
|
||||
public static boolean saveNewCert(String hostname, X509Certificate cert){
|
||||
JFrame frame = new JFrame();
|
||||
frame.setLayout(new BorderLayout());
|
||||
JButton bt = new JButton();
|
||||
bt.setText("text");
|
||||
frame.add(bt, BorderLayout.NORTH);
|
||||
|
||||
String title = Transl._("New remote host detected");
|
||||
String hostString = Transl._("Would you like permanently trust the certificate from the remote host " + hostname + "?");
|
||||
|
36
src/net/i2p/itoopie/gui/ConfigurationPanel.java
Normal file
36
src/net/i2p/itoopie/gui/ConfigurationPanel.java
Normal file
@ -0,0 +1,36 @@
|
||||
package net.i2p.itoopie.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import net.i2p.itoopie.gui.component.LogoPanel;
|
||||
import net.i2p.itoopie.i18n.Transl;
|
||||
|
||||
public class ConfigurationPanel extends LogoPanel {
|
||||
|
||||
private static final long serialVersionUID = 328657255717753899L;
|
||||
|
||||
|
||||
public ConfigurationPanel(String imageName) {
|
||||
super(imageName);
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
JPanel buttonArea = new JPanel();
|
||||
buttonArea.setLayout(new BorderLayout());
|
||||
add(buttonArea, BorderLayout.NORTH);
|
||||
|
||||
JPanel configArea = new JPanel();
|
||||
add(configArea, BorderLayout.CENTER);
|
||||
|
||||
JPanel positionedButtonArea = new JPanel();
|
||||
positionedButtonArea.setLayout(new BorderLayout());
|
||||
buttonArea.add(positionedButtonArea, BorderLayout.NORTH);
|
||||
|
||||
JButton btnApply = new JButton();
|
||||
btnApply.setText(Transl._("Apply"));
|
||||
positionedButtonArea.add(btnApply, BorderLayout.EAST);
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,17 @@
|
||||
package net.i2p.itoopie.gui;
|
||||
|
||||
import info.monitorenter.gui.chart.Chart2D;
|
||||
import info.monitorenter.gui.chart.views.ChartPanel;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JTabbedPane;
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JLabel;
|
||||
@ -13,9 +19,13 @@ import javax.swing.JButton;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import net.i2p.itoopie.gui.component.BandwidthChart;
|
||||
import net.i2p.itoopie.gui.component.LogoPanel;
|
||||
import net.i2p.itoopie.gui.component.ParticipatingTunnelsChart;
|
||||
import net.i2p.itoopie.util.IconLoader;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@ -60,19 +70,70 @@ public class Main {
|
||||
|
||||
|
||||
frame = new RegisteredFrame();
|
||||
frame.setBounds(100, 100, 450, 300);
|
||||
frame.setBounds(100, 100, 550, 400);
|
||||
frame.setResizable(false);
|
||||
|
||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
|
||||
JPanel overviewPanel = new LogoPanel("itoopie-opaque12");
|
||||
tabbedPane.addTab("Overview", null, overviewPanel, null);
|
||||
overviewPanel.setLayout(new BorderLayout(0, 0));
|
||||
overviewPanel.setLayout(null);
|
||||
|
||||
Chart2D bwChart = BandwidthChart.getChart();
|
||||
Chart2D partTunnelChart = ParticipatingTunnelsChart.getChart();
|
||||
//bwChart.setPreferredSize(new Dimension(30,100));
|
||||
ChartPanel pt = new ChartPanel(partTunnelChart);
|
||||
pt.setSize(300, 135);
|
||||
pt.setLocation(15, 15);;
|
||||
pt.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
|
||||
ChartPanel cp = new ChartPanel(bwChart);
|
||||
cp.setSize(300,135);
|
||||
cp.setLocation(15, 165);
|
||||
cp.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
|
||||
|
||||
JPanel configPanel = new LogoPanel("itoopie-opaque12");
|
||||
overviewPanel.add(pt);
|
||||
overviewPanel.add(cp);
|
||||
|
||||
|
||||
JPanel configPanel = new ConfigurationPanel("itoopie-opaque12");
|
||||
tabbedPane.addTab("Configuration", null, configPanel, null);
|
||||
configPanel.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
JPanel configArea = new JPanel();
|
||||
configArea.setOpaque(false);
|
||||
//configArea.setLayout(new Grid());
|
||||
configPanel.add(configArea, BorderLayout.CENTER);
|
||||
|
||||
|
||||
|
||||
JPanel buttonArea = new JPanel();
|
||||
buttonArea.setOpaque(false);
|
||||
buttonArea.setLayout(new BorderLayout(0, 0));
|
||||
configPanel.add(buttonArea, BorderLayout.SOUTH);
|
||||
|
||||
JPanel buttonAreaEast = new JPanel();
|
||||
buttonAreaEast.setLayout(new BorderLayout(0, 0));
|
||||
buttonAreaEast.setOpaque(false);
|
||||
buttonArea.add(buttonAreaEast, BorderLayout.EAST);
|
||||
|
||||
JPanel applyBtnWrapper = new JPanel();
|
||||
applyBtnWrapper.setOpaque(false);
|
||||
FlowLayout flowApplyBtnWrapper = new FlowLayout();
|
||||
flowApplyBtnWrapper.setVgap(0);
|
||||
flowApplyBtnWrapper.setHgap(3);
|
||||
applyBtnWrapper.setLayout(flowApplyBtnWrapper);
|
||||
buttonAreaEast.add(applyBtnWrapper);
|
||||
|
||||
|
||||
FlowLayout flowLayout = (FlowLayout) applyBtnWrapper.getLayout();
|
||||
flowLayout.setHgap(10);
|
||||
flowLayout.setVgap(3);
|
||||
|
||||
JButton btnApply = new JButton("Apply");
|
||||
btnApply.setOpaque(true);
|
||||
applyBtnWrapper.add(btnApply, BorderLayout.EAST);
|
||||
|
||||
JPanel logPanel = new LogoPanel("itoopie-opaque12");
|
||||
tabbedPane.addTab("Logs", null, logPanel, null);
|
||||
logPanel.setLayout(new BorderLayout(0, 0));
|
||||
@ -87,7 +148,7 @@ public class Main {
|
||||
statusPanel.add(statusLbl, BorderLayout.CENTER);
|
||||
|
||||
JPanel buttonWrapper = new JPanel();
|
||||
FlowLayout flowLayout = (FlowLayout) buttonWrapper.getLayout();
|
||||
flowLayout = (FlowLayout) buttonWrapper.getLayout();
|
||||
flowLayout.setHgap(10);
|
||||
flowLayout.setVgap(3);
|
||||
statusPanel.add(buttonWrapper, BorderLayout.EAST);
|
||||
|
@ -1,14 +1,9 @@
|
||||
package net.i2p.itoopie.gui;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.BorderLayout;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.SwingConstants;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.net.InetAddress;
|
||||
@ -16,20 +11,13 @@ import java.net.UnknownHostException;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JPasswordField;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.gui.component.ProgressiveDisclosurePanel;
|
||||
import net.i2p.itoopie.i18n.Transl;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
||||
import net.i2p.itoopie.i2pcontrol.JSONRPC2Interface;
|
||||
@ -94,7 +82,7 @@ public class Settings extends RegisteredFrame{
|
||||
GUIHelper.setDefaultStyle();
|
||||
|
||||
setTitle("itoopie Settings");
|
||||
setBounds(100, 100, 450, 300);
|
||||
setBounds(100, 100, 450, 150);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
|
||||
|
||||
|
93
src/net/i2p/itoopie/gui/component/BandwidthChart.java
Normal file
93
src/net/i2p/itoopie/gui/component/BandwidthChart.java
Normal file
@ -0,0 +1,93 @@
|
||||
package net.i2p.itoopie.gui.component;
|
||||
|
||||
import info.monitorenter.gui.chart.Chart2D;
|
||||
import info.monitorenter.gui.chart.IAxis.AxisTitle;
|
||||
import info.monitorenter.gui.chart.ITrace2D;
|
||||
import info.monitorenter.gui.chart.ITracePainter;
|
||||
import info.monitorenter.gui.chart.labelformatters.LabelFormatterDate;
|
||||
import info.monitorenter.gui.chart.labelformatters.LabelFormatterNumber;
|
||||
import info.monitorenter.gui.chart.rangepolicies.RangePolicyMinimumViewport;
|
||||
import info.monitorenter.gui.chart.traces.Trace2DLtd;
|
||||
import info.monitorenter.gui.chart.traces.painters.TracePainterPolyline;
|
||||
import info.monitorenter.gui.chart.views.ChartPanel;
|
||||
import info.monitorenter.util.Range;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.gui.component.chart.DummyDataCollector;
|
||||
import net.i2p.itoopie.gui.component.chart.RateStatTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.ObjRecorder2Trace2DAdapter;
|
||||
import net.i2p.itoopie.i18n.Transl;
|
||||
|
||||
|
||||
public class BandwidthChart {
|
||||
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
|
||||
private final static int DEFAULT_UPDATE_INTERVAL =1000; // Update every 1000th ms
|
||||
private final static int DEFAULT_GRAPH_INTERVAL = 2*3600; // The graph will cover a maximum of 2hrs
|
||||
private final static String DATE_FORMAT = "HH:mm:ss";
|
||||
|
||||
public static Chart2D getChart(){
|
||||
int updateInterval = _conf.getConf("graph.updateinterval", DEFAULT_UPDATE_INTERVAL);
|
||||
int graphInterval = _conf.getConf("graph.graphinterval", DEFAULT_GRAPH_INTERVAL);
|
||||
|
||||
Chart2D chart = new Chart2D();
|
||||
chart.setUseAntialiasing(true);
|
||||
chart.setMinPaintLatency(20);
|
||||
ITrace2D dataBWIn = new Trace2DLtd( updateInterval*graphInterval );
|
||||
dataBWIn.setStroke(new BasicStroke(1));
|
||||
dataBWIn.setColor(new Color(255, 0, 0, 255));
|
||||
dataBWIn.setName(Transl._("Bandwidth In [KB/s]"));
|
||||
|
||||
ITracePainter<?> dotPainter = new TracePainterPolyline();
|
||||
dataBWIn.setTracePainter(dotPainter);
|
||||
chart.addTrace(dataBWIn);
|
||||
|
||||
ITrace2D dataBWOut = new Trace2DLtd( updateInterval*graphInterval );
|
||||
dataBWOut.setStroke(new BasicStroke(1));
|
||||
dataBWOut.setColor(new Color(0, 0, 255, 255));
|
||||
dataBWOut.setName(Transl._("Bandwidth Out [KB/s]"));
|
||||
|
||||
dataBWOut.setTracePainter(dotPainter);
|
||||
chart.addTrace(dataBWOut);
|
||||
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
|
||||
|
||||
chart.getAxisX().setFormatter(new LabelFormatterDate(sdf));
|
||||
chart.getAxisX().setPaintGrid(true);
|
||||
chart.getAxisX().setAxisTitle(new AxisTitle(Transl._("Time")));
|
||||
|
||||
DecimalFormat df = new DecimalFormat("0 ; 0");
|
||||
chart.getAxisY().setFormatter(new LabelFormatterNumber(df));
|
||||
chart.getAxisY().setPaintGrid(true);
|
||||
chart.getAxisY().setAxisTitle(new AxisTitle(""));
|
||||
|
||||
// force ranges:
|
||||
chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 20)));
|
||||
|
||||
//new ObjRecorder2Trace2DAdapter(dataBWIn, new RateStatTracker("bw.sendRate", 3600000L), "m_value", updateInterval);
|
||||
new ObjRecorder2Trace2DAdapter(dataBWIn, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
|
||||
//new ObjRecorder2Trace2DAdapter(dataBWOut, new RateStatTracker("bw.recvRate", 3600000L), "m_value", updateInterval);
|
||||
new ObjRecorder2Trace2DAdapter(dataBWOut, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
|
||||
return chart;
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
Container contentPane = frame.getContentPane();
|
||||
contentPane.setLayout(new BorderLayout());
|
||||
contentPane.add(new ChartPanel(getChart()), BorderLayout.CENTER);
|
||||
//frame.add(new ChartPanel(getChart()));
|
||||
frame.setLocation(200, 300);
|
||||
frame.setSize(700, 210);
|
||||
frame.setResizable(true);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
package net.i2p.itoopie.gui.component;
|
||||
|
||||
import info.monitorenter.gui.chart.Chart2D;
|
||||
import info.monitorenter.gui.chart.ITrace2D;
|
||||
import info.monitorenter.gui.chart.ITracePainter;
|
||||
import info.monitorenter.gui.chart.rangepolicies.RangePolicyMinimumViewport;
|
||||
import info.monitorenter.gui.chart.traces.Trace2DLtd;
|
||||
import info.monitorenter.gui.chart.traces.painters.TracePainterPolyline;
|
||||
import info.monitorenter.gui.chart.views.ChartPanel;
|
||||
import info.monitorenter.reflection.ObjRecorder2Trace2DAdapter;
|
||||
import info.monitorenter.util.Range;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
* A test for the <code>Chart2D</code> that constantly adds new tracepoints to a
|
||||
* <code> Trace2DLtd</code>. Mainly the runtime- scaling is interesting.
|
||||
* <p>
|
||||
* Furthermore this is an example on how to connect other components to the
|
||||
* <code>Chart2D</code> using an adaptor- class. If interested have a look on
|
||||
* {@link info.monitorenter.reflection.ObjRecorder2Trace2DAdapter}.
|
||||
* <p>
|
||||
*
|
||||
* @author <a href='mailto:Achim.Westermann@gmx.de'> Achim Westermann </a>
|
||||
* @version $Revision: 1.5 $
|
||||
*/
|
||||
public class Chart extends JFrame {
|
||||
/**
|
||||
* Helper class that holds an internal number that is randomly modified by a
|
||||
* Thread.
|
||||
* <p>
|
||||
*
|
||||
* @author <a href="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
|
||||
* @version $Revision: 1.5 $
|
||||
*/
|
||||
static class RandomBumper extends Thread {
|
||||
/** Streches or compresses the grade of jumping of the internal number. */
|
||||
protected double m_factor;
|
||||
|
||||
/** The bumping number. */
|
||||
protected double m_number = 0;
|
||||
|
||||
/** The propability of an increase versus a decrease of the bumped number. */
|
||||
protected double m_plusminus = 0.5;
|
||||
|
||||
/** Needed for randomization of bumping the number. */
|
||||
protected java.util.Random m_randomizer = new java.util.Random();
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
* <p>
|
||||
*
|
||||
* @param plusminus
|
||||
* probability to increase or decrease the number each step.
|
||||
* @param factor
|
||||
* affects the amplitude of the number (severity of jumps).
|
||||
*/
|
||||
public RandomBumper(final double plusminus, final int factor) {
|
||||
|
||||
if (plusminus < 0 || plusminus > 1) {
|
||||
System.out.println(this.getClass().getName()
|
||||
+ " ignores constructor-passed value. Must be between 0.0 and 1.0!");
|
||||
} else {
|
||||
this.m_plusminus = plusminus;
|
||||
}
|
||||
this.m_factor = factor;
|
||||
this.setDaemon(true);
|
||||
this.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
double rand = this.m_randomizer.nextDouble();
|
||||
if (rand < this.m_plusminus) {
|
||||
this.m_number += this.m_randomizer.nextDouble() * this.m_factor;
|
||||
} else {
|
||||
this.m_number -= this.m_randomizer.nextDouble() * this.m_factor;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
// nop
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated for <code>serialVersionUID</code>.
|
||||
*/
|
||||
private static final long serialVersionUID = 3545231432038627123L;
|
||||
|
||||
/**
|
||||
* Main entry.
|
||||
* <p>
|
||||
*
|
||||
* @param args
|
||||
* ignored.
|
||||
*/
|
||||
public static void main(final String[] args) {
|
||||
|
||||
Chart2D chart = new Chart2D();
|
||||
chart.setUseAntialiasing(true);
|
||||
chart.setMinPaintLatency(20);
|
||||
ITrace2D data = new Trace2DLtd(300);
|
||||
data.setStroke(new BasicStroke(3));
|
||||
data.setColor(new Color(255, 0, 0, 255));
|
||||
data.setName("random");
|
||||
data.setPhysicalUnits("hertz", "ms");
|
||||
|
||||
ITracePainter<?> dotPainter = new TracePainterPolyline();
|
||||
data.setTracePainter(dotPainter);
|
||||
chart.addTrace(data);
|
||||
|
||||
Chart wnd = new Chart(chart, "AntialiasingChart");
|
||||
chart.getAxisX().setPaintGrid(true);
|
||||
chart.getAxisX().setStartMajorTick(false);
|
||||
chart.getAxisY().setPaintGrid(true);
|
||||
|
||||
chart.getAxisX().setPaintScale(true);
|
||||
chart.getAxisX().setPaintScale(true);
|
||||
|
||||
// force ranges:
|
||||
chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 20)));
|
||||
// chart.setFont(new Font(null,0,12));
|
||||
wnd.setLocation(200, 300);
|
||||
wnd.setSize(700, 210);
|
||||
wnd.setResizable(true);
|
||||
wnd.setVisible(true);
|
||||
new ObjRecorder2Trace2DAdapter(data, new RandomBumper(0.5, 1000), "m_number", 1000);
|
||||
}
|
||||
|
||||
/** The chart to use. */
|
||||
protected Chart2D m_chart = null;
|
||||
|
||||
/**
|
||||
* Creates an instance that will dynamically paint on the chart to a trace
|
||||
* with the given label.
|
||||
* <p>
|
||||
*
|
||||
* @param chart
|
||||
* the chart to use.
|
||||
* @param label
|
||||
* the name of the trace too display.
|
||||
*/
|
||||
public Chart(final Chart2D chart, final String label) {
|
||||
|
||||
super(label);
|
||||
this.m_chart = chart;
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
/**
|
||||
* @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent)
|
||||
*/
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent e) {
|
||||
|
||||
Chart.this.setVisible(false);
|
||||
Chart.this.dispose();
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
});
|
||||
Container contentPane = this.getContentPane();
|
||||
contentPane.setLayout(new BorderLayout());
|
||||
contentPane.add(new ChartPanel(this.m_chart), BorderLayout.CENTER);
|
||||
}
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package net.i2p.itoopie.gui.component;
|
||||
|
||||
import info.monitorenter.gui.chart.Chart2D;
|
||||
import info.monitorenter.gui.chart.IAxis.AxisTitle;
|
||||
import info.monitorenter.gui.chart.ITrace2D;
|
||||
import info.monitorenter.gui.chart.ITracePainter;
|
||||
import info.monitorenter.gui.chart.labelformatters.LabelFormatterDate;
|
||||
import info.monitorenter.gui.chart.labelformatters.LabelFormatterNumber;
|
||||
import info.monitorenter.gui.chart.rangepolicies.RangePolicyMinimumViewport;
|
||||
import info.monitorenter.gui.chart.traces.Trace2DLtd;
|
||||
import info.monitorenter.gui.chart.traces.painters.TracePainterPolyline;
|
||||
import info.monitorenter.gui.chart.views.ChartPanel;
|
||||
import info.monitorenter.util.Range;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.gui.component.chart.DummyDataCollector;
|
||||
import net.i2p.itoopie.gui.component.chart.RateStatTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.ObjRecorder2Trace2DAdapter;
|
||||
import net.i2p.itoopie.i18n.Transl;
|
||||
|
||||
|
||||
public class ParticipatingTunnelsChart {
|
||||
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
|
||||
private final static int DEFAULT_UPDATE_INTERVAL = 1000; // Update every 1000th ms
|
||||
private final static int DEFAULT_GRAPH_INTERVAL = 2*3600; // The graph will cover a maximum of 2hrs
|
||||
private final static String DATE_FORMAT = "HH:mm:ss";
|
||||
|
||||
public static Chart2D getChart(){
|
||||
int updateInterval = _conf.getConf("graph.updateinterval", DEFAULT_UPDATE_INTERVAL);
|
||||
int graphInterval = _conf.getConf("graph.graphinterval", DEFAULT_GRAPH_INTERVAL);
|
||||
|
||||
Chart2D chart = new Chart2D();
|
||||
chart.setUseAntialiasing(true);
|
||||
chart.setMinPaintLatency(20);
|
||||
ITrace2D dataPartTunnels = new Trace2DLtd( updateInterval*graphInterval );
|
||||
dataPartTunnels.setStroke(new BasicStroke(1));
|
||||
dataPartTunnels.setColor(new Color(255, 0, 0, 255));
|
||||
dataPartTunnels.setName(Transl._("Number of tunnels we are participating in."));
|
||||
|
||||
ITracePainter<?> dotPainter = new TracePainterPolyline();
|
||||
dataPartTunnels.setTracePainter(dotPainter);
|
||||
chart.addTrace(dataPartTunnels);
|
||||
|
||||
final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
|
||||
|
||||
chart.getAxisX().setFormatter(new LabelFormatterDate(sdf));
|
||||
chart.getAxisX().setPaintGrid(true);
|
||||
chart.getAxisX().setAxisTitle(new AxisTitle(Transl._("Time")));
|
||||
|
||||
DecimalFormat df = new DecimalFormat("0 ; 0");
|
||||
chart.getAxisY().setFormatter(new LabelFormatterNumber(df));
|
||||
chart.getAxisY().setPaintGrid(true);
|
||||
chart.getAxisY().setAxisTitle(new AxisTitle(""));
|
||||
|
||||
// force ranges:
|
||||
chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 20)));
|
||||
|
||||
//new ObjRecorder2Trace2DAdapter(dataPartTunnels, new RateStatTracker("tunnel.participatingTunnels", 3600000L), "m_value", updateInterval);
|
||||
new ObjRecorder2Trace2DAdapter(dataPartTunnels, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
|
||||
return chart;
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
Container contentPane = frame.getContentPane();
|
||||
contentPane.setLayout(new BorderLayout());
|
||||
contentPane.add(new ChartPanel(getChart()), BorderLayout.CENTER);
|
||||
//frame.add(new ChartPanel(getChart()));
|
||||
frame.setLocation(200, 300);
|
||||
frame.setSize(700, 210);
|
||||
frame.setResizable(true);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
@ -1,260 +0,0 @@
|
||||
package net.i2p.itoopie.gui.component;
|
||||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.RootPaneContainer;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public final class ProgressiveDisclosurePanel extends JOptionPane {
|
||||
/** Label. */
|
||||
private final JLabel label;
|
||||
|
||||
/** Wrapped container. */
|
||||
private final Container container;
|
||||
|
||||
/** True if this disclosure triangle container is collapsed. */
|
||||
private boolean collapsed;
|
||||
|
||||
/** Collapse icon. */
|
||||
private Icon collapseIcon;
|
||||
|
||||
/** Expand icon. */
|
||||
private Icon expandIcon;
|
||||
|
||||
/** Default label text, <code>"Details"</code>. */
|
||||
public static final String DEFAULT_LABEL_TEXT = "Details";
|
||||
|
||||
/**
|
||||
* Create a new disclosure triangle container wrapping the specified
|
||||
* container.
|
||||
*
|
||||
* <p>
|
||||
* By default this disclosure triangle container will be collapsed, its label
|
||||
* text will be <code>"Details"</code>, its collapse icon will be the icon
|
||||
* resource returned by <code>UIManager.getIcon("Tree.expandedIcon")</code>,
|
||||
* and its expand icon will be the icon resource returned by
|
||||
* <code>UIManager.getIcon("Tree.collapsedIcon")</code>.
|
||||
* </p>
|
||||
*
|
||||
* @see #DEFAULT_LABEL_TEXT
|
||||
* @see javax.swing.UIManager#getIcon
|
||||
* @param container
|
||||
* container to wrap, must not be null
|
||||
*/
|
||||
public ProgressiveDisclosurePanel(final Container container) {
|
||||
super ();
|
||||
if (container == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"container must not be null");
|
||||
}
|
||||
this .container = container;
|
||||
|
||||
collapsed = true;
|
||||
collapseIcon = UIManager.getIcon("Tree.expandedIcon");
|
||||
expandIcon = UIManager.getIcon("Tree.collapsedIcon");
|
||||
label = new JLabel(DEFAULT_LABEL_TEXT, expandIcon,
|
||||
JLabel.LEADING);
|
||||
|
||||
label.addMouseListener(new MouseAdapter() {
|
||||
/** {@inheritDoc} */
|
||||
public void mouseClicked(final MouseEvent event) {
|
||||
if (collapsed) {
|
||||
expand();
|
||||
} else {
|
||||
collapse();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add("North", label);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expand this disclosure triangle container.
|
||||
*/
|
||||
public void expand() {
|
||||
setCollapsed(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually perform the expand operation.
|
||||
*/
|
||||
private void doExpand() {
|
||||
add("Center", container);
|
||||
label.setIcon(collapseIcon);
|
||||
Container rootPaneContainer = getParentRootPaneContainer();
|
||||
if (rootPaneContainer != null) {
|
||||
Dimension dim0 = rootPaneContainer.getSize();
|
||||
Dimension dim1 = container.getSize();
|
||||
Dimension dim2 = container.getPreferredSize();
|
||||
rootPaneContainer.setSize(dim0.width, dim0.height + Math.max(dim1.height, dim2.height));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse this disclosure triangle container.
|
||||
*/
|
||||
public void collapse() {
|
||||
setCollapsed(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually perform the collapse operation.
|
||||
*/
|
||||
private void doCollapse() {
|
||||
remove(container);
|
||||
label.setIcon(expandIcon);
|
||||
Container rootPaneContainer = getParentRootPaneContainer();
|
||||
if (rootPaneContainer != null) {
|
||||
Dimension d0 = rootPaneContainer.getSize();
|
||||
Dimension d1 = container.getSize();
|
||||
Dimension d2 = container.getPreferredSize();
|
||||
rootPaneContainer.setSize(d0.width, d0.height
|
||||
- Math.max(d1.height, d2.height));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this disclosure triangle container is collapsed.
|
||||
*
|
||||
* @return true if this disclosure triangle container is collapsed
|
||||
*/
|
||||
public boolean isCollapsed() {
|
||||
return collapsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to true to collapse this disclosure triangle container. Alternatively,
|
||||
* call <code>collapse()</code> or <code>expand()</code> as appropriate.
|
||||
*
|
||||
* <p>
|
||||
* This is a bound property.
|
||||
* </p>
|
||||
*
|
||||
* @param collapsed true to collapse this disclosure triangle container
|
||||
*/
|
||||
public void setCollapsed(final boolean collapsed) {
|
||||
boolean oldCollapsed = this .collapsed;
|
||||
if (collapsed && !oldCollapsed) {
|
||||
doCollapse();
|
||||
}
|
||||
if (!collapsed && oldCollapsed) {
|
||||
doExpand();
|
||||
}
|
||||
this .collapsed = collapsed;
|
||||
firePropertyChange("collapsed", oldCollapsed, this .collapsed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parent root pane container for this disclosure triangle
|
||||
* container or null if one does not exist.
|
||||
*
|
||||
* @return the parent root pane container for this disclosure triangle
|
||||
* container or null if one does not exist
|
||||
*/
|
||||
private Container getParentRootPaneContainer() {
|
||||
Container c = this ;
|
||||
while (!(c instanceof RootPaneContainer)) {
|
||||
if (c.getParent() == null) {
|
||||
return null;
|
||||
}
|
||||
c = c.getParent();
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the label text for this disclosure triangle container.
|
||||
*
|
||||
* @return the label text for this disclosure triangle container
|
||||
*/
|
||||
public String getLabelText() {
|
||||
return label.getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the label text for this disclosure triangle container to
|
||||
* <code>labelText</code>.
|
||||
*
|
||||
* <p>
|
||||
* This is a bound property.
|
||||
* </p>
|
||||
*
|
||||
* @param labelText label text for this disclosure triangle container
|
||||
*/
|
||||
public void setLabelText(final String labelText) {
|
||||
String oldLabelText = label.getText();
|
||||
label.setText(labelText);
|
||||
firePropertyChange("labelText", oldLabelText, label.getText());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the collapse icon for this disclosure triangle container.
|
||||
*
|
||||
* @return the collapse icon for this disclosure triangle container
|
||||
*/
|
||||
public Icon getCollapseIcon() {
|
||||
return collapseIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the collapse icon for this disclosure triangle container to
|
||||
* <code>collapseIcon</code>.
|
||||
*
|
||||
* <p>
|
||||
* This is a bound property.
|
||||
* </p>
|
||||
*
|
||||
* @param collapseIcon
|
||||
* collapse icon for this disclosure triangle container
|
||||
*/
|
||||
public void setCollapseIcon(final Icon collapseIcon) {
|
||||
Icon oldCollapseIcon = this .collapseIcon;
|
||||
this .collapseIcon = collapseIcon;
|
||||
firePropertyChange("collapseIcon", oldCollapseIcon,
|
||||
this .collapseIcon);
|
||||
if (!collapsed) {
|
||||
label.setIcon(this .collapseIcon);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the expand icon for this disclosure triangle container.
|
||||
*
|
||||
* @return the expand icon for this disclosure triangle container
|
||||
*/
|
||||
public Icon getExpandIcon() {
|
||||
return expandIcon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the expand icon for this disclosure triangle container to
|
||||
* <code>expandIcon</code>.
|
||||
*
|
||||
* <p>
|
||||
* This is a bound property.
|
||||
* </p>
|
||||
*
|
||||
* @param expandIcon expand icon for this disclosure triangle container
|
||||
*/
|
||||
public void setExpandIcon(final Icon expandIcon) {
|
||||
Icon oldExpandIcon = this .expandIcon;
|
||||
this.expandIcon = expandIcon;
|
||||
firePropertyChange("expandIcon", oldExpandIcon, this.expandIcon);
|
||||
if (collapsed) {
|
||||
label.setIcon(this.expandIcon);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package net.i2p.itoopie.gui.component.chart;
|
||||
|
||||
public class DummyDataCollector extends Thread {
|
||||
/** Streches or compresses the grade of jumping of the internal number. */
|
||||
protected double m_factor;
|
||||
|
||||
/** The bumping number. */
|
||||
protected double m_number = 0;
|
||||
|
||||
/** The propability of an increase versus a decrease of the bumped number. */
|
||||
protected double m_plusminus = 0.5;
|
||||
|
||||
/** Needed for randomization of bumping the number. */
|
||||
protected java.util.Random m_randomizer = new java.util.Random();
|
||||
|
||||
/**
|
||||
* Creates an instance.
|
||||
* <p>
|
||||
*
|
||||
* @param plusminus
|
||||
* probability to increase or decrease the number each step.
|
||||
* @param factor
|
||||
* affects the amplitude of the number (severity of jumps).
|
||||
*/
|
||||
public DummyDataCollector(final double plusminus, final int factor) {
|
||||
|
||||
if (plusminus < 0 || plusminus > 1) {
|
||||
System.out
|
||||
.println(this.getClass().getName()
|
||||
+ " ignores constructor-passed value. Must be between 0.0 and 1.0!");
|
||||
} else {
|
||||
this.m_plusminus = plusminus;
|
||||
}
|
||||
this.m_factor = factor;
|
||||
this.setDaemon(true);
|
||||
this.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
double rand = this.m_randomizer.nextDouble();
|
||||
if (rand < this.m_plusminus) {
|
||||
this.m_number += this.m_randomizer.nextDouble() * this.m_factor;
|
||||
} else {
|
||||
this.m_number -= this.m_randomizer.nextDouble() * this.m_factor;
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(20);
|
||||
} catch (InterruptedException e) {
|
||||
// nop
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
/*
|
||||
* ObjectRecorder2Trace2DAdpater, an adapter which enables drawing timestamped
|
||||
* values inspected by the ObjectRecorder on a Chart2D.
|
||||
* Copyright (c) 2004 - 2011 Achim Westermann, Achim.Westermann@gmx.de
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* If you modify or optimize the code in a useful way please let me know.
|
||||
* Achim.Westermann@gmx.de
|
||||
*/
|
||||
|
||||
package net.i2p.itoopie.gui.component.chart;
|
||||
|
||||
import info.monitorenter.gui.chart.ITrace2D;
|
||||
import info.monitorenter.reflection.ObjectRecorder;
|
||||
import info.monitorenter.util.TimeStampedValue;
|
||||
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
/**
|
||||
* A simple adapter that allows displaying of timestamped values from an
|
||||
* inspection of the
|
||||
* <code>{@link info.monitorenter.reflection.ObjectRecorder}</code> on a
|
||||
* Chart2D.
|
||||
* <p>
|
||||
*
|
||||
* @author <a href='mailto:Achim.Westermann@gmx.de'>Achim Westermann </a>
|
||||
*
|
||||
* @version $Revision: 1.7 $
|
||||
*/
|
||||
public class ObjRecorder2Trace2DAdapter implements ChangeListener {
|
||||
|
||||
/** The field name to inspect. */
|
||||
private final String m_fieldname;
|
||||
|
||||
/** The source inspector to connect to the trace. */
|
||||
private final ObjectRecorder m_inspector;
|
||||
|
||||
/** The target trace to use. */
|
||||
private final ITrace2D m_view;
|
||||
|
||||
/**
|
||||
* Creates a bridge from the given field of the given instance to inspect to
|
||||
* the trace.
|
||||
* <p>
|
||||
*
|
||||
* @param view
|
||||
* the target trace that will show the inspected value.
|
||||
*
|
||||
* @param toinspect
|
||||
* the instance to inpsect.
|
||||
*
|
||||
* @param fieldname
|
||||
* the field on the instance to inspect.
|
||||
*
|
||||
* @param interval
|
||||
* the interval of inspections in ms.
|
||||
*/
|
||||
public ObjRecorder2Trace2DAdapter(final ITrace2D view, final Object toinspect,
|
||||
final String fieldname, final long interval) {
|
||||
this.m_view = view;
|
||||
this.m_fieldname = fieldname;
|
||||
this.m_inspector = new ObjectRecorder(toinspect, interval);
|
||||
this.m_inspector.addChangeListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final ObjRecorder2Trace2DAdapter other = (ObjRecorder2Trace2DAdapter) obj;
|
||||
if (this.m_fieldname == null) {
|
||||
if (other.m_fieldname != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.m_fieldname.equals(other.m_fieldname)) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_inspector == null) {
|
||||
if (other.m_inspector != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.m_inspector.equals(other.m_inspector)) {
|
||||
return false;
|
||||
}
|
||||
if (this.m_view == null) {
|
||||
if (other.m_view != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!this.m_view.equals(other.m_view)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((this.m_fieldname == null) ? 0 : this.m_fieldname.hashCode());
|
||||
result = prime * result + ((this.m_inspector == null) ? 0 : this.m_inspector.hashCode());
|
||||
result = prime * result + ((this.m_view == null) ? 0 : this.m_view.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the interval for inspections in ms.
|
||||
* <p>
|
||||
*
|
||||
* @param interval
|
||||
* the interval for inspections in ms.
|
||||
*/
|
||||
public void setInterval(final long interval) {
|
||||
this.m_inspector.setInterval(interval);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
|
||||
*/
|
||||
public void stateChanged(final ChangeEvent e) {
|
||||
TimeStampedValue last;
|
||||
try {
|
||||
last = this.m_inspector.getLastValue(this.m_fieldname);
|
||||
} catch (final Exception f) {
|
||||
f.printStackTrace();
|
||||
return;
|
||||
}
|
||||
if (last != null) {
|
||||
double tmpx;
|
||||
double tmpy;
|
||||
tmpx = last.getTime();
|
||||
tmpy = Double.parseDouble(last.getValue().toString());
|
||||
this.m_view.addPoint(tmpx, tmpy);
|
||||
}
|
||||
}
|
||||
}
|
59
src/net/i2p/itoopie/gui/component/chart/RateStatTracker.java
Normal file
59
src/net/i2p/itoopie/gui/component/chart/RateStatTracker.java
Normal file
@ -0,0 +1,59 @@
|
||||
package net.i2p.itoopie.gui.component.chart;
|
||||
|
||||
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.GetRateStat;
|
||||
|
||||
public class RateStatTracker extends Thread {
|
||||
|
||||
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
|
||||
/** Last read bw */
|
||||
private double m_value = 0;
|
||||
|
||||
/** Poll router for current ratestat every updateInterval seconds */
|
||||
private final static int DEFAULT_UPDATE_INTERVAL = 100; // Update every 100th ms
|
||||
|
||||
private int updateInterval = _conf.getConf("graph.updateinterval", DEFAULT_UPDATE_INTERVAL);
|
||||
|
||||
/** Which RateStat to measure from the router */
|
||||
private String rateStat;
|
||||
|
||||
/** Which period of a stat to measure */
|
||||
private long period;
|
||||
|
||||
/**
|
||||
* Start daemon that checks to current inbound bandwidth of the router.
|
||||
*/
|
||||
public RateStatTracker(String rateStat, long period) {
|
||||
this.rateStat = rateStat;
|
||||
this.period = period;
|
||||
this.setDaemon(true);
|
||||
this.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
m_value = GetRateStat.execute(rateStat, period);
|
||||
} catch (InvalidPasswordException e1) {
|
||||
} catch (JSONRPC2SessionException e1) {
|
||||
} catch (InvalidParametersException e1) {
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(updateInterval);
|
||||
} catch (InterruptedException e) {
|
||||
// nop
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -23,7 +23,6 @@ import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
||||
public class JSONRPC2Interface {
|
||||
private static Log _log;
|
||||
private static ConfigurationManager _conf;
|
||||
private static String DEFAULT_PASSWORD = "itoopie";
|
||||
private static int nonce;
|
||||
private static final int MAX_NBR_RETRIES = 2;
|
||||
private static JSONRPC2Session session;
|
||||
|
Reference in New Issue
Block a user