You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by cu...@apache.org on 2010/10/29 17:40:14 UTC
svn commit: r1028808 - in /openjpa/tools/trunk/openjpa-tools: ./
src/main/java/org/apache/openjpa/jconsole/
src/main/resources/META-INF/services/
src/main/resources/org/apache/openjpa/jconsole/
Author: curtisr7
Date: Fri Oct 29 15:40:14 2010
New Revision: 1028808
URL: http://svn.apache.org/viewvc?rev=1028808&view=rev
Log:
OPENJPA-1801: Add independent JConsole datacache plugin to tools project.
Added:
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheMBean.java (with props)
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePanel.java (with props)
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePlugin.java (with props)
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheStatistic.java (with props)
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheTable.java (with props)
openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheWorker.java (with props)
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/services/
openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin
openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/jconsole/
openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/jconsole/localizer.properties (with props)
Modified:
openjpa/tools/trunk/openjpa-tools/pom.xml
Modified: openjpa/tools/trunk/openjpa-tools/pom.xml
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/pom.xml?rev=1028808&r1=1028807&r2=1028808&view=diff
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/pom.xml (original)
+++ openjpa/tools/trunk/openjpa-tools/pom.xml Fri Oct 29 15:40:14 2010
@@ -27,6 +27,11 @@
<name>OpenJPA Tools</name>
<description>OpenJPA Tools</description>
+ <properties>
+ <!-- default location of jconsole.jar on most platforms -->
+ <jconsoleHome>${java.home}/../lib</jconsoleHome>
+ </properties>
+
<dependencies>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
@@ -49,8 +54,31 @@
<scope>test</scope>
<version>3.8.1</version>
</dependency>
+ <dependency>
+ <groupId>sun.jconsole</groupId>
+ <artifactId>jconsole</artifactId>
+ <version>1.6.0</version>
+ <scope>system</scope>
+ <systemPath>${jconsoleHome}/jconsole.jar</systemPath>
+ </dependency>
</dependencies>
+ <profiles>
+ <profile>
+ <id>macosx</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ <os>
+ <family>mac</family>
+ </os>
+ </activation>
+ <properties>
+ <!-- location of jconsole.jar on MacOSX -->
+ <jconsoleHome>${java.home}/lib</jconsoleHome>
+ </properties>
+ </profile>
+ </profiles>
+
<build>
<defaultGoal>install</defaultGoal>
<pluginManagement>
Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheMBean.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheMBean.java?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheMBean.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheMBean.java Fri Oct 29 15:40:14 2010
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.openjpa.jconsole;
+
+import java.util.Map;
+
+/**
+ * This interface is here as a convenience to use JMX.newMBeanProxy(..). This is NOT the entire
+ * org.apache.openjpa.instrumentation.jmx.DataCacheJMXInstrumentMBean interface from the OpenJPA runtime.
+ * <p>
+ * This <b>SHOULD NOT</b> to be used by any code outside the jconsole package!
+ */
+public interface DataCacheMBean {
+
+ /**
+ * This method is used to enable/disable caching for the specified className.
+ */
+ public void cache(String className, boolean enable);
+
+ /**
+ * Clears all data from the DataCache.
+ */
+ public void clear();
+
+ /**
+ *
+ * @param enable
+ * - If true, the cache will start collecting statistics. Else cache statistics will not be collected.
+ */
+ public void collectStatistics(boolean enable);
+
+ /**
+ * Returns the name of the cache
+ */
+ public String getCacheName();
+
+ /**
+ * Returns the CacheStatistics for the cache. The format for this map is: Type(String) =>
+ * Enabled(Boolean),Hit(Long),Read(Long),Write(Long)
+ */
+ public Map<String, long[]> getCacheStatistics();
+
+ /**
+ * Returns true if cache statistics are currently being calculated. False otherwise.
+ */
+ public Boolean getStatisticsEnabled();
+
+ /**
+ * Returns the names of classes that are known to the cache and whether or not they are currently being cached.
+ */
+ public Map<String, Boolean> listKnownTypes();
+
+ /**
+ * Resets cache statistics
+ */
+ public void reset();
+}
Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheMBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePanel.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePanel.java?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePanel.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePanel.java Fri Oct 29 15:40:14 2010
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.openjpa.jconsole;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.awt.ItemSelectable;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.border.LineBorder;
+import javax.swing.border.TitledBorder;
+
+/**
+ * <pre>
+ *
+ * DataCachePanel Layout:
+ * -> parentTopPanel:JPanel
+ * -> actionsPanel:JPanel
+ * -> enable checkbox
+ * -> clear cache button
+ * -> reset stats button
+ * -> types panel
+ * -> [N] types
+ * -> statisticsPanel:JScrollPane
+ *
+ * </pre>
+ */
+public class DataCachePanel extends JPanel {
+ private static final long serialVersionUID = 8273595264174478456L;
+ private static final ResourceBundle _msg = ResourceBundle.getBundle("org.apache.openjpa.jconsole.localizer");
+
+ private DataCacheMBean _mbean;
+ private DataCacheTable _model;
+ private Map<String, JCheckBox> _typesPanelMap = new ConcurrentHashMap<String, JCheckBox>();
+ private JPanel _typesPanel;
+
+ public DataCachePanel(DataCacheMBean mbean) {
+ super(new BorderLayout());
+ _model = new DataCacheTable();
+ _mbean = mbean;
+
+ // setup parent panel
+ JPanel parentTopPanel = new JPanel(new GridLayout(2, 0));
+ parentTopPanel.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), ""));
+ // Add parentTopPanel to DataCachePanel
+ add(parentTopPanel, BorderLayout.PAGE_START);
+
+ // Panel for action buttons
+ String actions = _msg.getString("datacachepanel.titles.actions");
+ JPanel actionsPanel = new JPanel(new GridLayout(1, 3));
+ actionsPanel.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), actions));
+ parentTopPanel.add(actionsPanel, -1);
+
+ // Create new panel for [N] children checkboxes
+ // Don't add anything here yet. This will happen dynamically in updateTypesCached
+ String knownTypes = _msg.getString("datacachepanel.titles.types");
+ _typesPanel = new JPanel(new GridLayout());
+ _typesPanel.setBorder(new TitledBorder(LineBorder.createGrayLineBorder(), knownTypes));
+ parentTopPanel.add(_typesPanel, -1);
+
+ // create enabled check box to parent
+ String statsEnabled = _msg.getString("datacachepanel.buttons.stats");
+ JCheckBox enableStatisticsCheckBox = new JCheckBox(statsEnabled, mbean.getStatisticsEnabled());
+ enableStatisticsCheckBox.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ boolean enable = (e.getStateChange() == ItemEvent.SELECTED);
+ _mbean.collectStatistics(enable);
+ }
+ });
+
+ // create clear cache button
+ String clearButton = _msg.getString("datacachepanel.buttons.clear");
+ JButton clear = new JButton(clearButton);
+ clear.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ _mbean.clear();
+ }
+ });
+
+ // create clear cache button
+ String resetButton = _msg.getString("datacachepanel.buttons.reset");
+ JButton reset = new JButton(resetButton);
+ reset.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ _mbean.reset();
+ }
+ });
+
+ actionsPanel.add(enableStatisticsCheckBox, -1);
+ actionsPanel.add(clear, -1);
+ actionsPanel.add(reset, -1);
+
+ // setup stats table
+ JTable table = new JTable(_model);
+ table.setPreferredScrollableViewportSize(new Dimension(500, 300));
+ table.setIntercellSpacing(new Dimension(6, 3));
+ table.setRowHeight(table.getRowHeight() + 4);
+ add(new JScrollPane(table), BorderLayout.PAGE_END);
+ }
+
+ DataCacheTable getModel() {
+ return _model;
+ }
+
+ /**
+ * This method is responsible for taking the provided DataCacheStatistic and adding any a check box for any types
+ * that we don't already know about.
+ */
+ void updateTypesCached(DataCacheStatistic stat) {
+ List<String> masterList = stat.getAllTypes();
+ List<String> enabled = stat.getEnabledTypes();
+
+ for (String s : masterList) {
+ JCheckBox box = _typesPanelMap.get(s);
+ if (box == null) {
+ // We don't know about this type, make a new check box.
+ box = new JCheckBox(s, enabled.contains(s));
+ box.setName(s);
+ box.addItemListener(new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ // When this item is selected / deselected, spin up a new thread to make MBean call
+ final ItemSelectable item = e.getItemSelectable();
+ if (item instanceof JCheckBox) {
+ try {
+ new Thread() {
+ public void run() {
+ JCheckBox jcb = (JCheckBox) item;
+ _mbean.cache(jcb.getName(), jcb.isSelected());
+ };
+ }.start();
+ } catch (Exception ex) {
+ // Unexpected
+ ex.printStackTrace();
+ }
+ }
+ }
+ });
+
+ _typesPanel.add(box);
+ _typesPanelMap.put(s, box);
+ } else {
+ box.setSelected(enabled.contains(s));
+ }
+ }
+ }
+}
Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePanel.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePlugin.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePlugin.java?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePlugin.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePlugin.java Fri Oct 29 15:40:14 2010
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.openjpa.jconsole;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.management.JMX;
+import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.swing.JPanel;
+import javax.swing.SwingWorker;
+
+import com.sun.tools.jconsole.JConsoleContext;
+import com.sun.tools.jconsole.JConsolePlugin;
+
+/**
+ * DataCachePlugin
+ */
+public class DataCachePlugin extends JConsolePlugin {
+ private static final ResourceBundle _msg = ResourceBundle.getBundle("org.apache.openjpa.jconsole.localizer");
+ private static final String DATACACHE_MBEAN_QUERY_STRING = "org.apache.openjpa:type=DataCache,*";
+
+ private Map<String, JPanel> _tabs;
+ private Map<DataCacheMBean, DataCachePanel> _mbeanPanelMap;
+
+ @Override
+ public Map<String, JPanel> getTabs() {
+ if (_tabs == null) {
+ _tabs = buildPanels(getMbeans());
+ }
+ return _tabs;
+ }
+
+ @Override
+ public SwingWorker<Map<DataCachePanel, DataCacheStatistic>, Object> newSwingWorker() {
+ return new DataCacheWorker(_mbeanPanelMap);
+ }
+
+ /**
+ * Private worker method that instantiates the CacheName -> DataCachePanel mapping.
+ */
+ private Map<String, JPanel> buildPanels(Map<String, DataCacheMBean> mbeans) {
+ _mbeanPanelMap = new HashMap<DataCacheMBean, DataCachePanel>();
+ Map<String, JPanel> res = new HashMap<String, JPanel>();
+ for (Map.Entry<String, DataCacheMBean> entry : mbeans.entrySet()) {
+ DataCacheMBean m = entry.getValue();
+ String cfgId = entry.getKey();
+ String name = m.getCacheName();
+
+ DataCachePanel panel = new DataCachePanel(m);
+ String key = "DataCache-" + cfgId + "-" + name;
+ // This "shouldn't" ever happen... but it will if we have name collisions for one reason or another.
+ while (res.containsKey(key) == true) {
+ key = key + "_dup";
+ }
+ res.put(key, panel);
+ _mbeanPanelMap.put(m, panel);
+ }
+ return res;
+ }
+
+ /**
+ * Private worker method that returns all MBeans matching the query "org.apache.openjpa:type=DataCache,*"
+ */
+ private Map<String, DataCacheMBean> getMbeans() {
+ Map<String, DataCacheMBean> mbeans = new HashMap<String, DataCacheMBean>();
+
+ JConsoleContext ctx = getContext();
+ Set<MBeanServerConnection> connections = new HashSet<MBeanServerConnection>();
+ connections.add(ctx.getMBeanServerConnection());
+ connections.addAll(MBeanServerFactory.findMBeanServer(null));
+ if (connections == null || connections.size() == 0) {
+ System.err.println(_msg.getString("datacacheplugin.zero.mbeanconnections"));
+ }
+
+ for (MBeanServerConnection server : connections) {
+ try {
+ ObjectName generic = new ObjectName(DATACACHE_MBEAN_QUERY_STRING);
+ ObjectName[] objects = server.queryNames(generic, null).toArray(new ObjectName[0]);
+ if (objects == null || objects.length == 0) {
+ String message = _msg.getString("datacacheplugin.zero.mbeans");
+ message = MessageFormat.format(message, new Object[] { DATACACHE_MBEAN_QUERY_STRING, server });
+ System.err.println(message);
+ }
+ for (ObjectName o : objects) {
+ DataCacheMBean bean = JMX.newMBeanProxy(server, o, DataCacheMBean.class);
+ String cfgId = o.getKeyProperty("cfgid");
+ // Handle config id collision
+ int i = 1;
+ String tempCfgId = cfgId;
+ while (mbeans.containsKey(tempCfgId)) {
+ tempCfgId = cfgId + "-" + i;
+ i++;
+ }
+ mbeans.put(tempCfgId, bean);
+ }
+ } catch (Exception e) {
+ // Shouldn't happen. Allow to bubble up as runtime exception
+ throw new RuntimeException(e);
+ }
+ }
+ return mbeans;
+ }
+}
Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCachePlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheStatistic.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheStatistic.java?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheStatistic.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheStatistic.java Fri Oct 29 15:40:14 2010
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.openjpa.jconsole;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+/**
+ * This class is a wrapper around the cache statistics map returned from the DataCacheMBean along with the stringified
+ * types that a given cache knows about.
+ */
+public class DataCacheStatistic {
+ // Type(String) => Hit(Long),Read(Long),Write(Long)
+ Map<String, long[]> _stats;
+ Set<String> _types;
+ List<String> _master;
+ List<String> _enabledTypes;
+ List<String> _disabledTypes;
+
+ public DataCacheStatistic(Map<String, long[]> stats, Map<String, Boolean> types) {
+ _stats = stats;
+ _types = stats.keySet();
+ _enabledTypes = new ArrayList<String>();
+ _disabledTypes = new ArrayList<String>();
+ _master = new ArrayList<String>();
+ for (Entry<String, Boolean> type : types.entrySet()) {
+ String name = type.getKey();
+ if (type.getValue().equals(Boolean.TRUE)) {
+ _enabledTypes.add(name);
+ } else {
+ _disabledTypes.add(name);
+ }
+ _master.add(name);
+ }
+ }
+
+ public long getReads(String cls) {
+ long[] res = _stats.get(cls);
+ return (res == null) ? 0 : res[1];
+ }
+
+ public long getHits(String cls) {
+ long[] res = _stats.get(cls);
+ return (res == null) ? 0 : res[0];
+ }
+
+ public long getWrites(String cls) {
+ long[] res = _stats.get(cls);
+ return (res == null) ? 0 : res[2];
+ }
+
+ public List<String> getEnabledTypes() {
+ return _enabledTypes;
+ }
+
+ public List<String> getDisabledTypes() {
+ return _disabledTypes;
+ }
+
+ public List<String> getAllTypes() {
+ return _master;
+ }
+
+ public int getNumTypes() {
+ return _disabledTypes.size() + _enabledTypes.size();
+ }
+}
Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheStatistic.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheTable.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheTable.java?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheTable.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheTable.java Fri Oct 29 15:40:14 2010
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.openjpa.jconsole;
+
+import java.util.List;
+import java.util.ResourceBundle;
+
+import javax.swing.table.AbstractTableModel;
+
+/**
+ * DataCacheTable
+ */
+public class DataCacheTable extends AbstractTableModel {
+ private static final long serialVersionUID = -117710809875227870L;
+ private static final ResourceBundle _msg = ResourceBundle.getBundle("org.apache.openjpa.jconsole.localizer");
+
+ // Column names -- key, reads, hits, writes
+ private static final String[] _cols =
+ { _msg.getString("datacachetable.column.key"), _msg.getString("datacachetable.column.reads"),
+ _msg.getString("datacachetable.column.hits"), _msg.getString("datacachetable.column.writes") };
+
+ // row, col
+ private Object[][] _tableData;
+
+ public int getColumnCount() {
+ return _cols.length;
+ }
+
+ public int getRowCount() {
+ return (_tableData == null) ? 0 : _tableData.length;
+ }
+
+ public Object getValueAt(int row, int col) {
+ return _tableData[row][col];
+ }
+
+ public String getColumnName(int col) {
+ return _cols[col];
+ }
+
+ public void setDataCacheStatistics(DataCacheStatistic s) {
+ // extract data from statistics into table format
+ _tableData = new Object[s.getNumTypes()][_cols.length];
+ List<String> types = s.getAllTypes();
+ for (int i = 0; i < types.size(); i++) {
+ String type = types.get(i);
+ // { "key", "reads", "hits", "writes" }
+ _tableData[i][0] = type;
+ _tableData[i][1] = s.getReads(type);
+ _tableData[i][2] = s.getHits(type);
+ _tableData[i][3] = s.getWrites(type);
+ }
+ }
+
+}
Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheTable.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheWorker.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheWorker.java?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheWorker.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheWorker.java Fri Oct 29 15:40:14 2010
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.openjpa.jconsole;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.swing.SwingWorker;
+
+import org.apache.openjpa.datacache.CacheStatistics;
+import org.apache.openjpa.instrumentation.jmx.DataCacheJMXInstrumentMBean;
+
+/**
+ * This worker class is driven by the JConsole. On a specified interval(default 4 sec, or -interval=n) this worker will
+ * be created and doInBackground() will be called. This method is responsible for performing any long running tasks that
+ * will collect data to be displayed by the UI.
+ *
+ * It keeps a mapping of MBean -> JConsole panel. On each run it needs to collect data which corresponds to each known
+ * panel.
+ */
+public class DataCacheWorker extends SwingWorker<Map<DataCachePanel, DataCacheStatistic>, Object> {
+ Map<DataCacheMBean, DataCachePanel> _map;
+
+ DataCacheWorker(Map<DataCacheMBean, DataCachePanel> map) {
+ _map = map;
+ }
+
+ @Override
+ public Map<DataCachePanel, DataCacheStatistic> doInBackground() {
+ Map<DataCachePanel, DataCacheStatistic> res = new HashMap<DataCachePanel, DataCacheStatistic>();
+ // Loop over each known panel and build DataCacheStatistic that will be consumed by the UI.
+ for (Entry<DataCacheMBean, DataCachePanel> entry : _map.entrySet()) {
+ DataCacheMBean mbean = entry.getKey();
+ DataCachePanel panel = entry.getValue();
+ // Make one MBean call to get all statistics
+ Map<String, long[]> stats = mbean.getCacheStatistics();
+ Map<String, Boolean> types = mbean.listKnownTypes();
+ DataCacheStatistic stat = new DataCacheStatistic(stats, types);
+
+ res.put(panel, stat);
+ }
+
+ return res;
+ }
+
+ /**
+ * This method is called by JConsole. It needs to pass data which was obtained in the background on to the UI for
+ * updating.
+ *
+ * Note : The method get() returns the values that were returned by the doInBackGround() method.
+ */
+ @Override
+ protected void done() {
+ try {
+ Map<DataCachePanel, DataCacheStatistic> res = get();
+ for (Entry<DataCachePanel, DataCacheStatistic> entry : res.entrySet()) {
+ DataCachePanel panel = entry.getKey();
+ DataCacheStatistic stat = entry.getValue();
+
+ // Give the types panel a chance to update known types.
+ panel.updateTypesCached(stat);
+
+ // Update statistics
+ DataCacheTable model = panel.getModel();
+ model.setDataCacheStatistics(stat);
+ model.fireTableDataChanged();
+ }
+ } catch (Exception e) {
+ // Unexpected
+ e.printStackTrace();
+ }
+ }
+}
Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/jconsole/DataCacheWorker.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/resources/META-INF/services/com.sun.tools.jconsole.JConsolePlugin Fri Oct 29 15:40:14 2010
@@ -0,0 +1 @@
+org.apache.openjpa.jconsole.DataCachePlugin
\ No newline at end of file
Added: openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/jconsole/localizer.properties
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/jconsole/localizer.properties?rev=1028808&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/jconsole/localizer.properties (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/jconsole/localizer.properties Fri Oct 29 15:40:14 2010
@@ -0,0 +1,31 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+datacachetable.column.key=key
+datacachetable.column.reads=reads
+datacachetable.column.hits=hits
+datacachetable.column.writes=writes
+
+datacacheplugin.zero.mbeanconnections=The DataCache JConsole plugin found zero MBeanServer connections. Please ensure \
+that the application is running and configured properly.
+datacacheplugin.zero.mbeans=The DataCache JConsole plugin found zero MBeans matching the following query string '{0}' \
+for MBeanServerConnection '{1}'. Please ensure that the application is running and configured properly.
+
+datacachepanel.titles.actions=Actions
+datacachepanel.titles.types=Currently known types
+datacachepanel.buttons.stats=Statistics enabled
+datacachepanel.buttons.clear=Clear cache
+datacachepanel.buttons.reset=Reset statistics
Propchange: openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/jconsole/localizer.properties
------------------------------------------------------------------------------
svn:eol-style = native