[jboss-cvs] JBossCache/src/org/jboss/cache ...
Elias Ross
genman at noderunner.net
Mon Dec 11 16:17:51 EST 2006
User: genman
Date: 06/12/11 16:17:51
Modified: src/org/jboss/cache TreeCacheView.java
Log:
Still doesn't work 100% but starts.
App should probably be removed or rewritten.
Revision Changes Path
1.17 +100 -144 JBossCache/src/org/jboss/cache/TreeCacheView.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheView.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- TreeCacheView.java 18 Oct 2006 11:07:54 -0000 1.16
+++ TreeCacheView.java 11 Dec 2006 21:17:51 -0000 1.17
@@ -8,15 +8,36 @@
package org.jboss.cache;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.cache.config.Configuration;
-import org.jgroups.View;
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
-import javax.swing.*;
+import javax.swing.AbstractAction;
+import javax.swing.JFrame;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.JTree;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.event.TreeSelectionEvent;
@@ -28,21 +49,11 @@
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-import java.io.File;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.Vector;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.Configuration;
+import org.jgroups.View;
/**
@@ -53,7 +64,7 @@
* The view itself caches only the nodes, but doesn't cache any of the data (HashMap) associated with it. When
* data needs to be displayed, the underlying tree will be accessed directly.
*
- * @version $Revision: 1.16 $
+ * @version $Revision: 1.17 $
* @author<a href="mailto:bela at jboss.org">Bela Ban</a> March 27 2003
*/
public class TreeCacheView implements TreeCacheViewMBean
@@ -63,7 +74,7 @@
*/
ObjectName cache_service = null;
TreeCacheGui gui = null;
- TreeCache cache;
+ CacheSPI cache;
Log log = LogFactory.getLog(TreeCacheView.class);
@@ -138,11 +149,9 @@
throw new Exception("TreeCacheView.init(): no MBeanServers found");
srv = (MBeanServer) servers.get(0);
log.info("init(): found MBeanServer " + srv);
- //cache = (TreeCacheMBean) MBeanProxyExt.create(TreeCacheMBean.class, cache_service, srv);
-
- // TODO: Sort out proper JMX lookup
- throw new RuntimeException("Sort out proper JMX lookup");
-
+ cache = (CacheSPI)srv.getAttribute(this.cache_service, "Cache");
+ System.out.println("Cache " + cache);
+ TreeCacheGui gui = new TreeCacheGui(cache);
}
@@ -152,7 +161,7 @@
if (!file.exists()) return;
- put(dir, null);
+ put(Fqn.fromString(dir), null);
if (file.isDirectory())
{
@@ -165,7 +174,7 @@
}
}
- void put(String fqn, Map m)
+ void put(Fqn fqn, Map m)
{
try
{
@@ -258,7 +267,7 @@
tree.getNotifier().addCacheListener(new MyListener());
log.info("registering the tree as " + mbean_name);
- srv.registerMBean(tree, new ObjectName(mbean_name));
+ srv.registerMBean(tree.getCacheMBeanInterface(), new ObjectName(mbean_name));
tree.start();
@@ -342,24 +351,24 @@
TreeSelectionListener, TableModelListener
{
private static final long serialVersionUID = 8576324868563647538L;
- TreeCache cache;
+ CacheSPI cache;
DefaultTreeModel tree_model = null;
Log log = LogFactory.getLog(getClass());
JTree jtree = null;
DefaultTableModel table_model = new DefaultTableModel();
JTable table = new JTable(table_model);
- MyNode root = new MyNode(SEP);
- String selected_node = null;
+ MyNode root = new MyNode(SEP.getName());
+ Fqn selected_node = null;
JPanel tablePanel = null;
JMenu operationsMenu = null;
JPopupMenu operationsPopup = null;
JMenuBar menubar = null;
- static final String SEP = Fqn.SEPARATOR;
+ static final Fqn SEP = Fqn.ROOT;
private static final int KEY_COL_WIDTH = 20;
private static final int VAL_COL_WIDTH = 300;
- public TreeCacheGui(TreeCache cache) throws Exception
+ public TreeCacheGui(CacheSPI cache) throws Exception
{
this.cache = cache;
@@ -499,7 +508,7 @@
val = (String) table.getValueAt(row, col);
if (key != null && val != null)
{
- put(selected_node, key, val);
+ cache.put(selected_node, key, val);
}
}
}
@@ -509,19 +518,16 @@
public void valueChanged(TreeSelectionEvent evt)
{
TreePath path = evt.getPath();
- String fqn = SEP;
- String component_name;
+ Fqn fqn = SEP;
+ Object component_name;
Map data = null;
for (int i = 0; i < path.getPathCount(); i++)
{
component_name = ((MyNode) path.getPathComponent(i)).name;
- if (component_name.equals(SEP))
+ if (component_name.equals("/"))
continue;
- if (fqn.equals(SEP))
- fqn += component_name;
- else
- fqn = fqn + SEP + component_name;
+ fqn = new Fqn(fqn, component_name);
}
data = getData(fqn);
if (data != null)
@@ -546,7 +552,7 @@
{
MyNode n, p;
- n = root.add(fqn.toString());
+ n = root.add(fqn);
if (n != null)
{
p = (MyNode) n.getParent();
@@ -563,7 +569,7 @@
MyNode n;
TreeNode par;
- n = root.findNode(fqn.toString());
+ n = root.findNode(fqn);
if (n != null)
{
n.removeAllChildren();
@@ -631,8 +637,8 @@
Vector mbrship;
if (new_view != null && (mbrship = new_view.getMembers()) != null)
{
- _put(SEP, "members", mbrship);
- _put(SEP, "coordinator", mbrship.firstElement());
+ put(SEP, "members", mbrship);
+ put(SEP, "coordinator", mbrship.firstElement());
}
}
}.start();
@@ -661,8 +667,8 @@
mbrship = getMembers() != null ? (Vector) getMembers().clone() : null;
if (mbrship != null && mbrship.size() > 0)
{
- _put(SEP, "members", mbrship);
- _put(SEP, "coordinator", mbrship.firstElement());
+ put(SEP, "members", mbrship);
+ put(SEP, "coordinator", mbrship.firstElement());
}
}
@@ -679,10 +685,9 @@
/**
* Recursively adds GUI nodes starting from fqn
*/
- void addGuiNode(String fqn)
+ void addGuiNode(Fqn fqn)
{
Set children;
- String child_name;
if (fqn == null) return;
@@ -691,36 +696,24 @@
// 2. Then add my children
children = getChildrenNames(fqn);
- if (children != null)
- {
- for (Iterator it = children.iterator(); it.hasNext();)
- {
- child_name = it.next().toString();
- addGuiNode(fqn + SEP + child_name);
- }
+ for (Object o : children) {
+ addGuiNode(new Fqn(fqn, o));
}
}
- String makeFQN(Object[] path)
- {
- StringBuffer sb = new StringBuffer("");
- String tmp_name;
-
- if (path == null) return null;
- for (int i = 0; i < path.length; i++)
+ Fqn makeFQN(Object[] opath)
{
- tmp_name = ((MyNode) path[i]).name;
- if (tmp_name.equals(SEP))
+ List l = new ArrayList();
+ for (Object o : opath) {
+ MyNode node = (MyNode)o;
+ Object name = node.name;
+ if (name.equals(Fqn.SEPARATOR))
continue;
- else
- sb.append(SEP + tmp_name);
+ l.add(name);
}
- tmp_name = sb.toString();
- if (tmp_name.length() == 0)
- return SEP;
- else
- return tmp_name;
+ System.out.println(" L " + l);
+ return new Fqn(l);
}
void clearTable()
@@ -818,29 +811,17 @@
}
}
- Map getData(String fqn)
+ Map getData(Fqn fqn)
{
- Map data;
- Set keys;
- String key;
- Object value;
-
- if (fqn == null) return null;
- keys = getKeys(fqn);
- if (keys == null) return null;
- data = new HashMap();
- for (Iterator it = keys.iterator(); it.hasNext();)
- {
- key = (String) it.next();
- value = get(fqn, key);
- if (value != null)
- data.put(key, value);
+ Node n = cache.getChild(fqn);
+ if (n == null) {
+ return null;
}
- return data;
+ return n.getData();
}
- void put(String fqn, Map m)
+ void put(Fqn fqn, Map m)
{
try
{
@@ -853,7 +834,7 @@
}
- void put(String fqn, String key, Object value)
+ void put(Fqn fqn, String key, Object value)
{
try
{
@@ -865,23 +846,11 @@
}
}
- void _put(String fqn, String key, Object value)
+ Set getKeys(Fqn fqn)
{
try
{
- cache._put(null, fqn, key, value, false);
- }
- catch (Throwable t)
- {
- log.error("TreeCacheGui._put(): " + t);
- }
- }
-
- Set getKeys(String fqn)
- {
- try
- {
- return cache.getKeys(fqn);
+ return cache.getChild(fqn).getKeys();
}
catch (Throwable t)
{
@@ -890,11 +859,11 @@
}
}
- Object get(String fqn, String key)
+ Object get(Fqn fqn, String key)
{
try
{
- return cache.get(fqn, key);
+ return cache.getChild(fqn).getData().get(key);
}
catch (Throwable t)
{
@@ -903,11 +872,12 @@
}
}
- Set getChildrenNames(String fqn)
+ Set getChildrenNames(Fqn fqn)
{
try
{
- return cache.getChildrenNames(fqn);
+ Node n = cache.getChild(fqn);
+ return n.getChildrenNames();
}
catch (Throwable t)
{
@@ -920,7 +890,8 @@
{
try
{
- return cache.getMembers();
+ return new Vector();
+ // return cache.getMembers();
}
catch (Throwable t)
{
@@ -951,7 +922,7 @@
{
JTextField fqnTextField = new JTextField();
if (selected_node != null)
- fqnTextField.setText(selected_node);
+ fqnTextField.setText(selected_node.toString());
Object[] information = {"Enter fully qualified name",
fqnTextField};
final String btnString1 = "OK";
@@ -968,7 +939,7 @@
if (userChoice == 0)
{
String userInput = fqnTextField.getText();
- put(userInput, null);
+ put(Fqn.fromString(userInput), null);
}
}
}
@@ -980,7 +951,7 @@
public void actionPerformed(ActionEvent e)
{
- System.out.println("\n*** lock information ****\n" + cache.printLockInfo());
+ System.out.println("\n*** lock information ****\n" + cache.getLockTable());
}
}
@@ -990,7 +961,7 @@
public void actionPerformed(ActionEvent e)
{
- cache.releaseAllLocks("/");
+ System.out.println("TODO :-)");
}
}
@@ -1000,13 +971,9 @@
public void actionPerformed(ActionEvent e)
{
- //remove(selected_node);
try
{
- //server.invoke(cache_service, "remove",
- // new Object[]{selected_node},
- // new String[]{STRING});
- cache.remove(selected_node);
+ cache.removeChild(selected_node);
}
catch (Throwable t)
{
@@ -1043,10 +1010,10 @@
class MyNode extends DefaultMutableTreeNode
{
private static final long serialVersionUID = 1578599138419577069L;
- String name = "<unnamed>";
+ Object name = "<unnamed>";
- MyNode(String name)
+ MyNode(Object name)
{
this.name = name;
}
@@ -1056,23 +1023,17 @@
* Adds a new node to the view. Intermediary nodes will be created if they don't yet exist.
* Returns the first node that was created or null if node already existed
*/
- public MyNode add(String fqn)
+ public MyNode add(Fqn fqn)
{
MyNode curr, n, ret = null;
- StringTokenizer tok;
- String child_name;
if (fqn == null) return null;
curr = this;
- tok = new StringTokenizer(fqn, TreeCacheGui.SEP);
-
- while (tok.hasMoreTokens())
- {
- child_name = tok.nextToken();
- n = curr.findChild(child_name);
+ for (Object o : fqn.peekElements()) {
+ n = curr.findChild(o);
if (n == null)
{
- n = new MyNode(child_name);
+ n = new MyNode(o.toString());
if (ret == null) ret = n;
curr.add(n);
}
@@ -1091,20 +1052,15 @@
}
- MyNode findNode(String fqn)
+ MyNode findNode(Fqn fqn)
{
MyNode curr, n;
- StringTokenizer tok;
- String child_name;
if (fqn == null) return null;
curr = this;
- tok = new StringTokenizer(fqn, TreeCacheGui.SEP);
-
- while (tok.hasMoreTokens())
+ for (Object o : fqn.peekElements())
{
- child_name = tok.nextToken();
- n = curr.findChild(child_name);
+ n = curr.findChild(o);
if (n == null)
return null;
curr = n;
@@ -1113,7 +1069,7 @@
}
- MyNode findChild(String relative_name)
+ MyNode findChild(Object relative_name)
{
MyNode child;
@@ -1146,7 +1102,7 @@
sb.append("/<unnamed>");
else
{
- sb.append(TreeCacheGui.SEP + name);
+ sb.append(TreeCacheGui.SEP.toString() + name);
}
}
sb.append("\n");
@@ -1165,7 +1121,7 @@
public String toString()
{
- return name;
+ return name.toString();
}
}
More information about the jboss-cvs-commits
mailing list