You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by sf...@apache.org on 2006/08/31 15:31:08 UTC
svn commit: r438912 - in /incubator/felix/trunk: mosgi.doc/
mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/
mosgi.jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/
mosgi.managedelements.memoryprobe....
Author: sfrenot
Date: Thu Aug 31 06:31:05 2006
New Revision: 438912
URL: http://svn.apache.org/viewvc?rev=438912&view=rev
Log:
FELIX-134
An implementation of this feature. The mbean brings memory datum to
the agent and it is provided in the JMX console as a graphical tab.
To test :
cd mosgi.doc
open 2 terminal
run ./core.sh in one,
run ./jmxconsole.sh in the other one.
Added:
incubator/felix/trunk/mosgi.managedelements.memoryprobe/ (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/ (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AbstractGraphPanel.java (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AttributeGraphPanel.java (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicJSlider.java (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicTimeJSlider.java (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryProbeTabUI.java
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryUsageLineChartComponent.java (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/NumericAttributeGraph.java (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/images/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/images/GraphSettings.gif (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jcommon-1.0.4.jar (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jfreechart-1.0.1.jar (with props)
incubator/felix/trunk/mosgi.managedelements.memoryprobe/pom.xml
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbe.java
incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbeMBean.java
Modified:
incubator/felix/trunk/mosgi.doc/config.properties.core
incubator/felix/trunk/mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java
incubator/felix/trunk/mosgi.jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java
Modified: incubator/felix/trunk/mosgi.doc/config.properties.core
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.doc/config.properties.core?rev=438912&r1=438911&r2=438912&view=diff
==============================================================================
--- incubator/felix/trunk/mosgi.doc/config.properties.core (original)
+++ incubator/felix/trunk/mosgi.doc/config.properties.core Thu Aug 31 06:31:05 2006
@@ -23,8 +23,10 @@
file:../mosgi.console.ifc/target/org.apache.felix.mosgi.console.ifc-0.8.0-SNAPSHOT.jar \
file:../mosgi.managedelements.osgiprobes/target/org.apache.felix.mosgi.managedelements.osgiprobes-0.8.0-SNAPSHOT.jar \
file:../mosgi.managedelements.bundlesprobes/target/org.apache.felix.mosgi.managedelements.bundlesprobes-0.8.0-SNAPSHOT.jar \
- file:../mosgi.managedelements.obrprobe/target/org.apache.felix.mosgi.managedelements.obrprobe-0.8.0-SNAPSHOT.jar
+ file:../mosgi.managedelements.memoryprobe/target/org.apache.felix.mosgi.managedelements.memoryprobe-0.8.0-SNAPSHOT.jar
+# file:../mosgi.managedelements.obrprobe/target/org.apache.felix.mosgi.managedelements.obrprobe-0.8.0-SNAPSHOT.jar \
+
# if we need the http jmx connector
# file:../mosgi.jmx.httpconnector/target/org.apache.felix.mosgi.jmx.httpconnector-0.8.0-SNAPSHOT.jar
@@ -32,6 +34,7 @@
insa.jmxconsole.tab.url.osgiprobestab=file:../mosgi.managedelements.osgiprobes.tab/target/org.apache.felix.mosgi.managedelements.osgiprobes.tab-0.8.0-SNAPSHOT.jar
insa.jmxconsole.tab.url.bundlesprobestab=file:../mosgi.managedelements.bundlesprobes.tab/target/org.apache.felix.mosgi.managedelements.bundlesprobes.tab-0.8.0-SNAPSHOT.jar
insa.jmxconsole.tab.url.obrprobetab=file:../mosgi.managedelements.obrprobe.tab/target/org.apache.felix.mosgi.managedelements.obrprobe.tab-0.8.0-SNAPSHOT.jar
+insa.jmxconsole.tab.url.memoryprobetab=file:../mosgi.managedelements.memoryprobe.tab/target/org.apache.felix.mosgi.managedelements.memoryprobe.tab-0.8.0-SNAPSHOT.jar
#insa.jmxconsole.rmiport.t1=1100
Modified: incubator/felix/trunk/mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java?rev=438912&r1=438911&r2=438912&view=diff
==============================================================================
--- incubator/felix/trunk/mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java (original)
+++ incubator/felix/trunk/mosgi.jmx.httpconnector/src/main/java/org/apache/felix/mosgi/jmx/httpconnector/HttpConnectorActivator.java Thu Aug 31 06:31:05 2006
@@ -47,7 +47,7 @@
HttpConnectorActivator.log(LogService.LOG_INFO, "Starting JMX Http Connector "+version,null);
MBeanServer server= (MBeanServer)bc.getService(sr);
- String httpPort = bc.getProperty("insa.jmx.httpconnector.port");
+ String httpPort = bc.getProperty("org.osgi.service.http.port");
if (httpPort==null){
httpPort="8080";
}
Modified: incubator/felix/trunk/mosgi.jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java?rev=438912&r1=438911&r2=438912&view=diff
==============================================================================
--- incubator/felix/trunk/mosgi.jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java (original)
+++ incubator/felix/trunk/mosgi.jmx.rmiconnector/src/main/java/org/apache/felix/mosgi/jmx/rmiconnector/RmiConnectorActivator.java Thu Aug 31 06:31:05 2006
@@ -131,7 +131,7 @@
rmiPort="1099";
}
String url="service:jmx:rmi:///jndi/rmi://"+ InetAddress.getLocalHost().getHostAddress()+":"+rmiPort+"/"+profile;
- RmiConnectorActivator.log(LogService.LOG_INFO, "insa.jmx.rmiconnector.url ==> "+url, null);
+ RmiConnectorActivator.log(LogService.LOG_INFO, "jmx connexion string ==> "+url, null);
RmiConnectorActivator.log(LogService.LOG_INFO, "Starting JMX Rmi Connector "+version,null);
this.mbs=(MBeanServer)bc.getService(this.mBeanServerSR);
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 31 06:31:05 2006
@@ -0,0 +1,17 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
+
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Aug 31 06:31:05 2006
@@ -0,0 +1,17 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
+
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AbstractGraphPanel.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AbstractGraphPanel.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AbstractGraphPanel.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AbstractGraphPanel.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,521 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe.tab;
+
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.DateAxis;
+import org.jfree.chart.axis.LogarithmicAxis;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.plot.XYPlot;
+import org.jfree.chart.renderer.xy.DefaultXYItemRenderer;
+import org.jfree.chart.title.TextTitle;
+import org.jfree.data.time.Millisecond;
+import org.jfree.data.time.TimeSeries;
+import org.jfree.data.time.TimeSeriesCollection;
+
+//import org.openide.windows.TopComponent;
+
+//import org.mc4j.console.dashboard.components.RefreshControlComponent;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.ButtonGroup;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButton;
+import javax.swing.SwingUtilities;
+import javax.swing.border.LineBorder;
+
+public abstract class AbstractGraphPanel extends JComponent {
+
+
+ protected TimeSeriesCollection dataset = new TimeSeriesCollection();
+
+
+ protected JFreeChart chart;
+ protected Timer dataGeneratorTimer;
+ protected TimerTask dataGeneratorTimerTask;
+
+ protected Map timeSeriesMap = new HashMap();
+ protected XYPlot xyplot;
+
+
+ private JCheckBox controlsButton;
+ private JPanel controlsPanel;
+
+ private ButtonGroup buttonGroupScale;
+ private ButtonGroup buttonGroupTimeRange;
+ private JRadioButton jRadioButtonScaleLinear;
+ private JRadioButton jRadioButtonScaleLogarithmic;
+ private JRadioButton jRadioTimeHours;
+ private JRadioButton jRadioTimeMinutes;
+ private JRadioButton jRadioTimeSeconds;
+ protected LogarithmicTimeJSlider sleepSlider;
+ protected JLabel sleepDelay;
+
+
+ private boolean removed = false;
+
+ protected int failures = 0;
+ protected static final int MAX_FAILURES = 10;
+
+
+ public AbstractGraphPanel() {
+ setDoubleBuffered(false);
+ initGraphPanel();
+ }
+
+ public void setChartTitle(final String name) {
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ setName(name);
+ }
+ });
+
+ chart.setTitle(
+ new TextTitle(name,
+ new Font("SansSerif",Font.BOLD, 12)));
+
+ }
+
+ protected void initGraphPanel() {
+
+ setPreferredSize(new Dimension(500,450));
+
+ DateAxis domain = new DateAxis("Time");
+ NumberAxis range = new NumberAxis("");
+
+ this.xyplot = new XYPlot(dataset, domain, range, new DefaultXYItemRenderer());
+
+ domain.setAutoRange(true);
+ domain.setLowerMargin(0.0);
+ domain.setUpperMargin(0.0);
+ domain.setTickLabelsVisible(true);
+
+ range.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
+
+ this.chart =
+ new JFreeChart(
+ "",
+ JFreeChart.DEFAULT_TITLE_FONT,
+ xyplot,
+ true);
+
+ chart.setTitle(
+ new TextTitle("Graph ???",
+ new Font("SansSerif",Font.BOLD, 12)));
+
+ ChartPanel chartPanel = new ChartPanel(chart,false,true,true,false,false);
+ chartPanel.setOpaque(true);
+ chartPanel.setDoubleBuffered(false);
+ chart.setBackgroundPaint(this.getBackground());
+ chartPanel.setBackground(this.getBackground());
+ chartPanel.setBorder(new LineBorder(Color.BLACK,1));
+
+ setLayout(new BorderLayout());
+ setOpaque(false);
+ add(chartPanel,BorderLayout.CENTER);
+
+ buildGraphControls();
+
+ this.controlsButton = new ControlsPopupButton();
+ JPanel northPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+ northPanel.add(this.controlsButton);
+ northPanel.setOpaque(false);
+ add(northPanel,BorderLayout.NORTH);
+ this.controlsPanel.setLocation(5,5);
+
+ doLayout();
+ repaint();
+ }
+
+
+ public class ControlsPopupButton extends JCheckBox {
+
+ private JPopupMenu popup;
+ private Icon descendingIcon = new ImageIcon(java.awt.Toolkit.getDefaultToolkit().getImage(MemoryProbeTabUI.bc.getBundle().getResource("images/GraphSettings.gif")));
+
+
+ public ControlsPopupButton() {
+ setIcon(descendingIcon);
+ setOpaque(false);
+ init();
+ }
+
+ public void showPopup() {
+ if (popup == null) {
+ popup = new JPopupMenu();
+ popup.add(controlsPanel);
+ }
+ popup.show(controlsButton, 0, controlsButton.getHeight());
+ }
+
+ private void init() {
+ addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ showPopup();
+ }
+ });
+ }
+ }
+
+
+
+ public long getUpdateDelay() {
+ if (sleepSlider != null)
+ return sleepSlider.getValue();
+ else
+ return 1000L;
+ }
+
+ /**
+ * Cancels any existing scheduled task and reschedules for the
+ * current status of the delay control.
+ */
+ public void reschedule() {
+ if (this.dataGeneratorTimer == null) {
+ this.dataGeneratorTimer = new Timer();
+ }
+
+ if (this.dataGeneratorTimerTask != null) {
+ try {
+ this.dataGeneratorTimerTask.cancel();
+ } catch(Exception e) { e.printStackTrace();}
+ }
+
+ this.dataGeneratorTimer.schedule(
+ this.dataGeneratorTimerTask = getDataGeneratorTask(),
+ getUpdateDelay(),
+ getUpdateDelay());
+
+ }
+
+ /**
+ * Stops taking measurements for the graph.
+ */
+ public void pauseSchedule() {
+ if (this.dataGeneratorTimer !=null){
+ this.dataGeneratorTimerTask.cancel();
+ }
+ this.dataGeneratorTimerTask = null;
+ }
+
+
+ protected TimerTask getDataGeneratorTask() {
+ return new DataGenerator();
+ }
+
+
+ public void addNotify() {
+ super.addNotify();
+ if (removed) {
+ reschedule();
+ this.removed = false;
+ }
+ }
+
+
+ public void removeNotify() {
+ super.removeNotify();
+ if (this.dataGeneratorTimer != null)
+ this.dataGeneratorTimer.cancel();
+ this.dataGeneratorTimer = null;
+ this.removed = true;
+ }
+
+
+
+ /**
+ * Define this graph as logarithmic or not
+ * @param logarithmic if true, graph will be logarithmic,
+ * otherwise it will be linear
+ */
+ public void setLogarithmic(boolean logarithmic) {
+ if (logarithmic) {
+ try {
+ this.xyplot.setRangeAxis(new LogarithmicAxis(""));
+ } catch(Exception e) {
+ // In case we try to use a logarithmic axis when the values go below 1
+ this.xyplot.setRangeAxis(new NumberAxis(""));
+ }
+ } else {
+ this.xyplot.setRangeAxis(new NumberAxis(""));
+ }
+ }
+
+ public void setBackground(Color bg) {
+ super.setBackground(bg);
+ //this.sleepSlider.setBackground(bg);
+ }
+
+ public void updateRange() {
+ DateAxis dateAxis = (DateAxis) this.xyplot.getDomainAxis();
+
+ Calendar start = new GregorianCalendar();
+
+ start.setTime(new Date());
+
+ if (this.jRadioTimeSeconds.isSelected()) {
+ start.add(Calendar.SECOND, -60);
+ } else if (this.jRadioTimeMinutes.isSelected()) {
+ //this.sleepSlider.setEnabled(false);
+ start.add(Calendar.MINUTE, -60);
+ } else if (this.jRadioTimeHours.isSelected()) {
+ start.add(Calendar.HOUR, -48);
+ }
+
+ // this is a hack to slow down the data gathering for the longer periods...
+ // TODO GH: Build a TimeSeries that modulates the time periods automatically
+ // i.e.
+ // | Seconds | Minutes | Hours |
+ // ***************** * * * * * * * * * * * * *
+ if (this.jRadioTimeMinutes.isSelected()) {
+ sleepSlider.setValue(10000);
+ } else if (this.jRadioTimeHours.isSelected()) {
+ sleepSlider.setValue(100000);
+ }
+
+
+ dateAxis.setRange(start.getTime(),new Date());
+ }
+
+
+ protected JPanel buildGraphControls() {
+
+ this.controlsPanel = new JPanel();
+ //this.controlsPanel.setBorder(BorderFactory.createLineBorder(Color.black));
+ this.controlsPanel.setLayout(new BoxLayout(this.controlsPanel,BoxLayout.X_AXIS));
+
+ // Seconds, Minutes, Hours
+ JPanel timeDurationPanel = new JPanel();
+ timeDurationPanel.setLayout(new BoxLayout(timeDurationPanel, BoxLayout.Y_AXIS));
+ timeDurationPanel.setBorder(BorderFactory.createTitledBorder("Time Range"));
+
+ buttonGroupTimeRange = new javax.swing.ButtonGroup();
+
+ jRadioTimeSeconds = new javax.swing.JRadioButton("seconds", true);
+ jRadioTimeSeconds.setToolTipText("Track the graph for 60 seconds");
+ jRadioTimeSeconds.setOpaque(false);
+
+ jRadioTimeMinutes = new javax.swing.JRadioButton("minutes", false);
+ jRadioTimeMinutes.setToolTipText("Track this graph for 60 minutes.");
+ jRadioTimeMinutes.setOpaque(false);
+
+ jRadioTimeHours = new javax.swing.JRadioButton("hours", false);
+ jRadioTimeHours.setToolTipText("Track this graph for 48 hours.");
+ jRadioTimeHours.setOpaque(false);
+
+ buttonGroupTimeRange.add(jRadioTimeSeconds);
+ buttonGroupTimeRange.add(jRadioTimeMinutes);
+ buttonGroupTimeRange.add(jRadioTimeHours);
+
+ timeDurationPanel.add(jRadioTimeSeconds);
+ timeDurationPanel.add(jRadioTimeMinutes);
+ timeDurationPanel.add(jRadioTimeHours);
+
+ // Scale (linear vs. logarithmic)
+ JPanel timeScalePanel = new JPanel();
+ timeScalePanel.setLayout(new BoxLayout(timeScalePanel, BoxLayout.Y_AXIS));
+ timeScalePanel.setBorder(BorderFactory.createTitledBorder("Time Scale"));
+
+ buttonGroupScale = new javax.swing.ButtonGroup();
+
+ jRadioButtonScaleLinear = new javax.swing.JRadioButton("Linear", true);
+ jRadioButtonScaleLinear.setOpaque(false);
+
+ jRadioButtonScaleLogarithmic = new javax.swing.JRadioButton("Logarithmic", false);
+ jRadioButtonScaleLogarithmic.setOpaque(false);
+
+ buttonGroupScale.add(jRadioButtonScaleLinear);
+ buttonGroupScale.add(jRadioButtonScaleLogarithmic);
+
+ timeScalePanel.add(jRadioButtonScaleLinear);
+ timeScalePanel.add(jRadioButtonScaleLogarithmic);
+
+ // Update speed (in milleseconds)
+ JPanel updateSpeedPanel = new JPanel();
+ updateSpeedPanel.setLayout(new BoxLayout(updateSpeedPanel, BoxLayout.Y_AXIS));
+ updateSpeedPanel.setBorder(BorderFactory.createTitledBorder("Update Speed"));
+
+ //sleepSlider = new javax.swing.JSlider(100,10000,1000);
+ //sleepSlider.setPaintLabels(true);
+ //sleepSlider.setPaintTicks(true);
+ //sleepSlider.setMinorTickSpacing(500);
+ //sleepSlider.setMajorTickSpacing(2000);
+
+ sleepSlider = new LogarithmicTimeJSlider(100, 100000, 1000);
+
+ sleepSlider.setPaintTicks(true);
+ sleepSlider.setPaintLabels(true);
+ sleepSlider.setMajorTickSpacing(10);
+ sleepSlider.setMinorTickSpacing(10);
+
+ sleepSlider.setToolTipText("Time between updates");
+ sleepSlider.setOpaque(false);
+
+ sleepDelay = new JLabel("Delay: " + sleepSlider.getTime());
+
+ sleepSlider.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ sleepSliderPropertyChange(null);
+ sleepDelay.setText("Delay: " + sleepSlider.getTime());
+ }
+ });
+
+
+ updateSpeedPanel.add(sleepSlider);
+ updateSpeedPanel.add(sleepDelay);
+
+ jRadioButtonScaleLinear.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ scaleChanged(evt);
+ }
+ });
+
+ jRadioButtonScaleLogarithmic.addChangeListener(new javax.swing.event.ChangeListener() {
+ public void stateChanged(javax.swing.event.ChangeEvent evt) {
+ scaleChanged(evt);
+ }
+ });
+
+
+ this.controlsPanel.add(timeDurationPanel);
+ this.controlsPanel.add(updateSpeedPanel);
+ this.controlsPanel.add(timeScalePanel);
+
+ return this.controlsPanel;
+ }
+
+
+ private void scaleChanged(javax.swing.event.ChangeEvent evt) {
+ setLogarithmic(jRadioButtonScaleLogarithmic.isSelected());
+ }
+
+
+ private void sleepSliderPropertyChange(java.beans.PropertyChangeEvent evt) {
+ if (!sleepSlider.getValueIsAdjusting()) {
+ reschedule();
+ }
+ }
+
+
+ /**
+ * Should be overridden by non-abstract subclasses to provide an observation
+ * of all time series datasets.
+ */
+ public abstract void addObservation() throws Exception;
+
+ private void addObservationHandler() {
+ try {
+ addObservation();
+ if (failures > 0)
+ failures--;
+ } catch (Exception e) {
+ failures++;
+// org.openide.windows.IOProvider.getDefault().getStdOut().println(e);
+ }
+ if (failures > MAX_FAILURES) {
+ pauseSchedule();
+ }
+
+ updateRange();
+
+ }
+
+ protected void createTimeSeries(String name, Object key) {
+ TimeSeries ts =
+ new TimeSeries(
+ name,
+ Millisecond.class);
+ //ts.setHistoryCount(1728000); // 48 hours at 100 seconds
+ ts.setMaximumItemCount(1728000); // 48 hours at 100 seconds
+ this.timeSeriesMap.put(key, ts);
+ dataset.addSeries(ts);
+ }
+
+ protected TimeSeries getTimeSeries(Object key) {
+ return (TimeSeries) this.timeSeriesMap.get(key);
+ }
+
+ /**
+ * The data generator.
+ */
+ protected class DataGenerator extends TimerTask {
+
+ public void run() {
+ addObservationHandler();
+ }
+ }
+
+
+
+ private static class TestGraph extends AbstractGraphPanel {
+ public static final String TEST = "test";
+ private int x = 1;
+ public TestGraph() {
+ createTimeSeries(TEST, TEST);
+ reschedule();
+ }
+ public void addObservation() throws Exception {
+ getTimeSeries(TEST).
+ add(new Millisecond(), new Integer(x++));
+ }
+ }
+
+ public static void main(String[] args) {
+ TestGraph graph = new TestGraph();
+
+ JFrame frame = new JFrame();
+ JPanel panel = new JPanel();
+ panel.setLayout(new BorderLayout());
+ frame.getContentPane().add(panel);
+ panel.add(graph, BorderLayout.CENTER);
+
+ frame.pack();
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ frame.setVisible(true);
+ }
+
+}
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AbstractGraphPanel.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AttributeGraphPanel.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AttributeGraphPanel.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AttributeGraphPanel.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AttributeGraphPanel.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe.tab;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+//import org.mc4j.console.swing.graph.AbstractGraphPanel;
+
+import org.jfree.data.time.Millisecond;
+import org.jfree.data.time.TimeSeries;
+
+public class AttributeGraphPanel extends AbstractGraphPanel {
+
+ protected ObjectName objectName;
+ protected MBeanServer server;
+
+
+ public AttributeGraphPanel() {
+
+ }
+
+ protected String createName() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(this.objectName.getDomain());
+ Hashtable props = this.objectName.getKeyPropertyList();
+ buf.append(" {");
+ for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ buf.append(" ");
+ buf.append(entry.getKey());
+ buf.append("=");
+ buf.append(entry.getValue());
+ }
+ buf.append("}");
+ return buf.toString();
+ }
+
+
+ public void addObservation() throws Exception {
+ System.out.println("AttributeGraphPanel.addObservation: I should not be there");
+ }
+
+
+}
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/AttributeGraphPanel.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicJSlider.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicJSlider.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicJSlider.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicJSlider.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,304 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe.tab;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import javax.swing.BoundedRangeModel;
+import javax.swing.BoxLayout;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JSlider;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.plaf.SliderUI;
+import javax.swing.plaf.UIResource;
+import javax.swing.plaf.basic.BasicSliderUI;
+
+public class LogarithmicJSlider extends JSlider {
+
+
+ public static class LogSliderUI extends BasicSliderUI {
+
+ public LogSliderUI(JSlider b) {
+ super(b);
+ }
+
+
+ public int xPositionForValue(int value) {
+ int min = slider.getMinimum();
+ int max = slider.getMaximum();
+ int trackLength = trackRect.width;
+ double valueRange = (double) Math.log(max) - (double) Math.log(min);
+ double pixelsPerValue = (double) trackLength / valueRange;
+ int trackLeft = trackRect.x;
+ int trackRight = trackRect.x + (trackRect.width - 1);
+ int xPosition;
+
+ if (!drawInverted()) {
+ xPosition = trackLeft;
+ xPosition += Math.round(pixelsPerValue * ((double) Math.log(value) - Math.log(min)));
+ } else {
+ xPosition = trackRight;
+ xPosition -= Math.round(pixelsPerValue * ((double) Math.log(value) - Math.log(min)));
+ }
+
+ xPosition = Math.max(trackLeft, xPosition);
+ xPosition = Math.min(trackRight, xPosition);
+
+ return xPosition;
+
+
+ }
+
+ public int yPositionForValue(int value) {
+ // TODO GH: Implement to support vertical log sliders
+ return super.yPositionForValue(value);
+ }
+
+ public int valueForYPosition(int yPos) {
+ // TODO GH: Implement to support vertical log sliders
+ return super.valueForYPosition(yPos);
+ }
+
+ public int valueForXPosition(int xPos) {
+ int value;
+ final int minValue = slider.getMinimum();
+ final int maxValue = slider.getMaximum();
+ final int trackLength = trackRect.width;
+ final int trackLeft = trackRect.x;
+ final int trackRight = trackRect.x + (trackRect.width - 1);
+
+ if (xPos <= trackLeft) {
+ value = drawInverted() ? maxValue : minValue;
+ } else if (xPos >= trackRight) {
+ value = drawInverted() ? minValue : maxValue;
+ } else {
+ int distanceFromTrackLeft = xPos - trackLeft;
+ double valueRange = (double) Math.log(maxValue) - (double) Math.log(minValue);
+ //double valuePerPixel = (double)valueRange / (double)trackLength;
+ //int valueFromTrackLeft =
+ // (int)Math.round( Math.pow(3.5,(double)distanceFromTrackLeft * (double)valuePerPixel));
+
+ int valueFromTrackLeft =
+ (int)
+ Math.round(Math.pow(Math.E, Math.log(minValue) + ((((double) distanceFromTrackLeft) * valueRange) / (double) trackLength)));
+
+ value = drawInverted() ? maxValue - valueFromTrackLeft :
+ (int) Math.log(minValue) + valueFromTrackLeft;
+ }
+
+ return value;
+
+ }
+
+ public void paintTicks(Graphics g) {
+ Rectangle tickBounds = tickRect;
+ int i;
+ int maj, min, max;
+ int w = tickBounds.width;
+ int h = tickBounds.height;
+ int centerEffect, tickHeight;
+
+ g.setColor(Color.black);
+
+ maj = slider.getMajorTickSpacing();
+ min = slider.getMinorTickSpacing();
+
+ if (slider.getOrientation() == JSlider.HORIZONTAL) {
+ g.translate(0, tickBounds.y);
+
+ int value = slider.getMinimum();
+ int xPos = 0;
+
+ if (slider.getMinorTickSpacing() > 0) {
+ int majorValue = slider.getMinimum();
+
+ while (value <= slider.getMaximum()) {
+ if (value >= majorValue) {
+ value = majorValue;
+ majorValue *= maj;
+ }
+ value += (majorValue / 10.0);
+
+ xPos = xPositionForValue(value);
+ paintMinorTickForHorizSlider(g, tickBounds, xPos);
+
+ }
+ }
+
+ if (slider.getMajorTickSpacing() > 0) {
+ value = slider.getMinimum();
+
+ while (value <= slider.getMaximum()) {
+ xPos = xPositionForValue(value);
+ paintMajorTickForHorizSlider(g, tickBounds, xPos);
+ value *= slider.getMajorTickSpacing();
+ }
+ }
+
+ g.translate(0, -tickBounds.y);
+ } else {
+
+ g.translate(tickBounds.x, 0);
+
+ int value = slider.getMinimum();
+ int yPos = 0;
+
+ if (slider.getMinorTickSpacing() > 0) {
+ int majorValue = slider.getMinimum();
+ int offset = 0;
+ if (!slider.getComponentOrientation().isLeftToRight()) {
+ offset = tickBounds.width - tickBounds.width / 2;
+ g.translate(offset, 0);
+ }
+
+ while (value <= slider.getMaximum()) {
+ if (value >= majorValue) {
+ value = majorValue;
+ majorValue *= maj;
+ }
+
+ yPos = yPositionForValue(value);
+ paintMinorTickForVertSlider(g, tickBounds, yPos);
+ value += (majorValue / 10.0);
+ }
+
+ if (!slider.getComponentOrientation().isLeftToRight()) {
+ g.translate(-offset, 0);
+ }
+ }
+
+ if (slider.getMajorTickSpacing() > 0) {
+ value = slider.getMinimum();
+ if (!slider.getComponentOrientation().isLeftToRight()) {
+ g.translate(2, 0);
+ }
+
+ while (value <= slider.getMaximum()) {
+ yPos = yPositionForValue(value);
+ paintMajorTickForVertSlider(g, tickBounds, yPos);
+ value *= slider.getMajorTickSpacing();
+ }
+
+ if (!slider.getComponentOrientation().isLeftToRight()) {
+ g.translate(-2, 0);
+ }
+ }
+ g.translate(-tickBounds.x, 0);
+ }
+ }
+
+ }
+
+ public Hashtable createStandardLabels(int increment, int start) {
+ if (start > getMaximum() || start < getMinimum()) {
+ throw new IllegalArgumentException("Slider label start point out of range.");
+ }
+
+ if (increment <= 0) {
+ throw new IllegalArgumentException("Label incremement must be > 0");
+ }
+
+ class LabelHashtable extends Hashtable implements PropertyChangeListener {
+ int increment = 0;
+ int start = 0;
+ boolean startAtMin = false;
+
+
+ public LabelHashtable(int increment, int start) {
+ super();
+ this.increment = increment;
+ this.start = start;
+ startAtMin = start == getMinimum();
+ createLabels(this, increment, start);
+ }
+
+ public void propertyChange(PropertyChangeEvent e) {
+ if (e.getPropertyName().equals("minimum") && startAtMin) {
+ start = getMinimum();
+ }
+
+ if (e.getPropertyName().equals("minimum") ||
+ e.getPropertyName().equals("maximum")) {
+
+ Enumeration keys = getLabelTable().keys();
+ Object key = null;
+ Hashtable hashtable = new Hashtable();
+
+ // Save the labels that were added by the developer
+ while (keys.hasMoreElements()) {
+ key = keys.nextElement();
+ Object value = getLabelTable().get(key);
+ if (!(value instanceof LabelUIResource)) {
+ hashtable.put(key, value);
+ }
+ }
+
+ clear();
+ createLabels(this, increment, start);
+
+ // Add the saved labels
+ keys = hashtable.keys();
+ while (keys.hasMoreElements()) {
+ key = keys.nextElement();
+ put(key, hashtable.get(key));
+ }
+ ((JSlider) e.getSource()).setLabelTable(this);
+ }
+ }
+ }
+
+ LabelHashtable table = new LabelHashtable(increment, start);
+
+ if (getLabelTable() != null && (getLabelTable() instanceof PropertyChangeListener)) {
+ removePropertyChangeListener((PropertyChangeListener) getLabelTable());
+ }
+
+ addPropertyChangeListener(table);
+
+ return table;
+ }
+
+ /**
+ * This method creates the table of labels that are used to label major ticks
+ * on the slider.
+ * @param table
+ * @param increment
+ * @param start
+ */
+ protected void createLabels(Hashtable table, int increment, int start) {
+ for (int labelIndex = start; labelIndex <= getMaximum(); labelIndex *= increment) {
+
+ table.put(new Integer(labelIndex), new LabelUIResource("" + labelIndex, JLabel.CENTER));
+ }
+ }
+
+ protected static class LabelUIResource extends JLabel implements UIResource {
+ public LabelUIResource(String text, int alignment) {
+ super(text, alignment);
+ setName("Slider.label");
+ }
+ }
+
+}
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicJSlider.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicTimeJSlider.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicTimeJSlider.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicTimeJSlider.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicTimeJSlider.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe.tab;
+
+import java.text.DecimalFormat;
+import java.util.Hashtable;
+
+import javax.swing.*;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+public class LogarithmicTimeJSlider extends LogarithmicJSlider {
+
+ protected static final DecimalFormat format = new DecimalFormat("#.#");
+
+ protected void createLabels(Hashtable table, int increment, int start) {
+ for (int labelIndex = start; labelIndex <= getMaximum(); labelIndex *= increment) {
+ String label = formatMilleseconds(labelIndex);
+ table.put(new Integer(labelIndex), new LabelUIResource(label, JLabel.CENTER));
+ }
+ }
+
+ public String getTime() {
+ return formatMilleseconds(getValue());
+ }
+
+ public String formatMilleseconds(int labelIndex) {
+ String label;
+ if (labelIndex >= (1000 * 60 * 60 * 24)) {
+ label = format.format(labelIndex / (double)(1000 * 60 * 60 * 24)) + " days";
+ } else if (labelIndex >= (1000 * 60 * 60)) {
+ label = format.format(labelIndex / (double)(1000 * 60 * 60)) + " hours";
+ } else if (labelIndex >= (double)(1000 * 60)) {
+ label = format.format(labelIndex / (double)(1000 * 60)) + " mins";
+ } else if (labelIndex >= 1000) {
+ label = format.format(labelIndex / (double)1000) + " secs";
+ } else {
+ label = labelIndex + " ms";
+ }
+ return label;
+ }
+
+}
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/LogarithmicTimeJSlider.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryProbeTabUI.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryProbeTabUI.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryProbeTabUI.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryProbeTabUI.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe.tab;
+
+import javax.swing.JPanel;
+import java.awt.BorderLayout;
+import java.awt.Component;
+
+import org.osgi.framework.BundleContext;
+
+import java.beans.PropertyChangeEvent;
+import javax.management.MBeanServerConnection;
+
+import org.apache.felix.mosgi.console.ifc.Plugin;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.BundleActivator;
+
+
+public class MemoryProbeTabUI extends JPanel implements Plugin, BundleActivator {
+ MemoryUsageLineChartComponent mulcc;
+ JPanel innerP;
+
+ static BundleContext bc;
+ static MBeanServerConnection mbs;
+ ServiceRegistration sreg;
+
+ ///////////////////////////////////////////
+ // BundleActivator //
+ ///////////////////////////////////////////
+ public void start(BundleContext context) {
+ this.bc = context;
+ this.registerServicePlugin();
+ }
+
+ public void stop(BundleContext context) { }
+
+ ///////////////////////////////////////////
+ // Plugin //
+ //////////////////////////////////////////
+ public void registerServicePlugin(){
+ sreg = bc.registerService(Plugin.class.getName(), this, null);
+ }
+
+ public void unregisterServicePlugin(){
+ sreg.unregister();
+ }
+
+ public String pluginLocation(){
+ return bc.getBundle().getLocation();
+ }
+
+ public String getName(){return "JVM Memory";}
+
+ public Component getGUI(){return this;}
+
+ public void propertyChange(PropertyChangeEvent e){
+ /*
+ * This a static tab, each new visit will provide the same
+ * information. A dynamic tab update is provided in LinuxTab
+ *
+ */
+ if (e.getPropertyName().equals(Plugin.NEW_NODE_READY)){
+ this.mbs=(MBeanServerConnection)e.getNewValue();
+ innerP=new JPanel(new BorderLayout());
+ innerP.add(this.mulcc=new MemoryUsageLineChartComponent(),BorderLayout.CENTER);
+ this.add(innerP, BorderLayout.CENTER);
+ this.updateUI();
+ }else if(e.getPropertyName().equals(Plugin.EMPTY_NODE)){
+ if (mulcc!=null){
+ this.mulcc.pauseSchedule();
+ this.innerP.remove(this.mulcc);
+ this.mulcc=null;
+ this.remove(innerP);
+ }
+ this.invalidate();
+ this.validate();
+ this.updateUI();
+ }
+ }
+
+}
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryUsageLineChartComponent.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryUsageLineChartComponent.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryUsageLineChartComponent.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryUsageLineChartComponent.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe.tab;
+
+import org.jfree.data.general.DefaultPieDataset;
+import org.jfree.data.time.Millisecond;
+import org.jfree.data.time.TimeSeries;
+
+import java.awt.BorderLayout;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryUsage;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+
+public class MemoryUsageLineChartComponent extends NumericAttributeGraph {
+
+ public static final String COMMITTED = "Committed";
+ public static final String INIT = "Initial";
+ public static final String MAX = "Maximum";
+ public static final String USED = "Used";
+
+ protected DefaultPieDataset pieDataset;
+
+ protected List beanList;
+
+
+ ObjectName permGen, tenuredGen, codeCache, edenSpace, survivorSpace = null;
+
+
+ public MemoryUsageLineChartComponent() {
+
+ this.chart.setTitle("Memory Usage");
+
+ try {
+ permGen = new ObjectName("java.lang:type=MemoryPool,name=Perm Gen");
+ tenuredGen = new ObjectName("java.lang:type=MemoryPool,name=Tenured Gen");
+ codeCache = new ObjectName("java.lang:type=MemoryPool,name=Code Cache");
+ edenSpace = new ObjectName("java.lang:type=MemoryPool,name=Eden Space");
+ survivorSpace = new ObjectName("java.lang:type=MemoryPool,name=Survivor Space");
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ createTimeSeries("Permanent Generation", permGen);
+ createTimeSeries("Tenured Generation", tenuredGen);
+ createTimeSeries("Code Cache", codeCache);
+ createTimeSeries("Eden Space", edenSpace);
+ createTimeSeries("Survivor Space", survivorSpace);
+ reschedule();
+ }
+
+ public void addObservation() throws Exception {
+ //MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ MemoryUsage usage = MemoryUsage.from((CompositeData) MemoryProbeTabUI.mbs.getAttribute(permGen, "Usage"));
+ MemoryUsage usage2 = MemoryUsage.from((CompositeData) MemoryProbeTabUI.mbs.getAttribute(tenuredGen, "Usage"));
+ MemoryUsage usage3 = MemoryUsage.from((CompositeData) MemoryProbeTabUI.mbs.getAttribute(codeCache, "Usage"));
+ MemoryUsage usage4 = MemoryUsage.from((CompositeData) MemoryProbeTabUI.mbs.getAttribute(edenSpace, "Usage"));
+ MemoryUsage usage5 = MemoryUsage.from((CompositeData) MemoryProbeTabUI.mbs.getAttribute(survivorSpace, "Usage"));
+ getTimeSeries(permGen).add( new Millisecond(), usage.getUsed() );
+ getTimeSeries(tenuredGen).add( new Millisecond(), usage2.getUsed() );
+ getTimeSeries(codeCache).add( new Millisecond(), usage3.getUsed() );
+ getTimeSeries(edenSpace).add( new Millisecond(), usage4.getUsed() );
+ getTimeSeries(survivorSpace).add( new Millisecond(), usage5.getUsed() );
+
+ }
+
+
+
+ public static void main(String[] args) {
+ MemoryUsageLineChartComponent graph = new MemoryUsageLineChartComponent();
+
+ JFrame frame = new JFrame();
+ JPanel panel = new JPanel();
+ panel.setLayout(new BorderLayout());
+ frame.getContentPane().add(panel);
+ panel.add(graph, BorderLayout.CENTER);
+
+ frame.pack();
+ frame.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ System.exit(0);
+ }
+ });
+ frame.setVisible(true);
+ }
+
+
+
+}
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/MemoryUsageLineChartComponent.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/NumericAttributeGraph.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/NumericAttributeGraph.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/NumericAttributeGraph.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/NumericAttributeGraph.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe.tab;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+public class NumericAttributeGraph extends AttributeGraphPanel {
+
+ protected Set attributeSet = new HashSet();
+
+ public int getUpdateInterval() {
+ return sleepSlider.getValue();
+ }
+
+ public void setUpdateInterval(int updateInterval) {
+ sleepSlider.setValue(updateInterval);
+ }
+
+ public java.lang.String getAttributeName() {
+ return "Multivalue attribute";
+ }
+
+ public void setAttributeName(java.lang.String attributeName) {
+ this.attributeSet.add(attributeName);
+ }
+
+}
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/tab/NumericAttributeGraph.java
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/images/GraphSettings.gif
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/images/GraphSettings.gif?rev=438912&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/images/GraphSettings.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jcommon-1.0.4.jar
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jcommon-1.0.4.jar?rev=438912&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jcommon-1.0.4.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jfreechart-1.0.1.jar
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jfreechart-1.0.1.jar?rev=438912&view=auto
==============================================================================
Binary file - no diff available.
Propchange: incubator/felix/trunk/mosgi.managedelements.memoryprobe.tab/src/main/resources/lib/jfreechart-1.0.1.jar
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe/pom.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe/pom.xml?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe/pom.xml (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe/pom.xml Thu Aug 31 06:31:05 2006
@@ -0,0 +1,69 @@
+<project>
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>0.8.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>osgi-bundle</packaging>
+ <name>MOSGi JMX MBean for obr interaction</name>
+ <artifactId>org.apache.felix.mosgi.managedelements.memoryprobe</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.mosgi.console.ifc</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.framework</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.mosgi.jmx.agent</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix.plugins</groupId>
+ <artifactId>maven-osgi-plugin</artifactId>
+ <version>${pom.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <osgiManifest>
+ <bundleName>MOSGi JMX MBean for memory supervision</bundleName>
+ <bundleDescription>MOSGi JMX MBean for memory supervision</bundleDescription>
+ <bundleActivator>auto-detect</bundleActivator>
+ <bundleDocUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/</bundleDocUrl>
+ <bundleUrl>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}.jar</bundleUrl>
+ <bundleSource>http://oscar-osgi.sf.net/obr2/${pom.artifactId}/${pom.artifactId}-${pom.version}-src.jar</bundleSource>
+ <bundleSymbolicName>${pom.artifactId}</bundleSymbolicName>
+ <importPackage>
+ org.osgi.framework;specification-version="1.0.0",
+ javax.management;specification-version="1.0.0",
+ org.apache.felix.mosgi.console.ifc;specification-version="1.0.0"
+ </importPackage>
+ </osgiManifest>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbe.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbe.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbe.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbe.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import javax.management.ObjectName;
+import javax.management.MBeanServer;
+
+public class MemoryProbe implements BundleActivator, MemoryProbeMBean {
+ private static final String tabNameString = "TabUI:name=MemoryProbe";
+ private ObjectName tabName=null;
+ private ServiceRegistration sr=null;
+ private BundleContext bc=null;
+
+ ////////////////////////////////////////////////////////
+ // TabIfc (from OsgiProbesMBean) //
+ ////////////////////////////////////////////////////////
+ public String getBundleName() {
+ return this.bc.getProperty("insa.jmxconsole.tab.url.memoryprobetab");
+ }
+
+ ////////////////////////////////////////////////////////
+ // BundleActivator //
+ ////////////////////////////////////////////////////////
+ public void start(BundleContext context) throws Exception {
+ this.bc=context;
+ this.tabName=new ObjectName(tabNameString);
+/*
+ this.server=(MBeanServer)this.bc.getService(sr);
+ this.server.registerMBean(this, tabName);
+*/
+ java.util.Properties p=new java.util.Properties();
+ p.put(org.apache.felix.mosgi.jmx.agent.Constants.OBJECTNAME, this.tabNameString);
+ sr=this.bc.registerService(MemoryProbeMBean.class.getName(), this, p);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ this.tabName=null;
+/*
+ this.server=(MBeanServer)this.bc.getService(sr);
+ this.server.registerMBean(this, tabName);
+*/
+ this.sr.unregister();
+ this.sr=null;
+ this.bc=null;
+ }
+}
Added: incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbeMBean.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbeMBean.java?rev=438912&view=auto
==============================================================================
--- incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbeMBean.java (added)
+++ incubator/felix/trunk/mosgi.managedelements.memoryprobe/src/main/java/org/apache/felix/mosgi/managedelements/memoryprobe/MemoryProbeMBean.java Thu Aug 31 06:31:05 2006
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.felix.mosgi.managedelements.memoryprobe;
+
+import org.apache.felix.mosgi.console.ifc.TabIfc;
+
+public interface MemoryProbeMBean extends TabIfc {
+}
+
+