[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Wed Sep 6 11:30:56 EDT 2006
User: msurtani
Date: 06/09/06 11:30:56
Modified: src/org/jboss/cache CacheSPI.java ConsoleListener.java
TreeCache.java TreeCacheProxyImpl.java
TreeCacheView2.java
Log:
Removed TreeCache dependency on ServiceMBeanSupport
Revision Changes Path
1.13 +0 -6 JBossCache/src/org/jboss/cache/CacheSPI.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheSPI.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheSPI.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- CacheSPI.java 29 Aug 2006 11:54:10 -0000 1.12
+++ CacheSPI.java 6 Sep 2006 15:30:55 -0000 1.13
@@ -16,7 +16,6 @@
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jgroups.Address;
-import javax.management.ObjectName;
import javax.transaction.TransactionManager;
import java.util.List;
import java.util.Map;
@@ -94,11 +93,6 @@
// that is used by either an interceptor, or eviction policy
// should be added to this interface, provided they are public.
- /**
- * Gets the service name if this is registered in the MBean server.
- */
- ObjectName getServiceName();
-
TransactionManager getTransactionManager();
ReplicationQueue getReplQueue();
1.9 +343 -333 JBossCache/src/org/jboss/cache/ConsoleListener.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ConsoleListener.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/ConsoleListener.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- ConsoleListener.java 16 Aug 2006 10:52:51 -0000 1.8
+++ ConsoleListener.java 6 Sep 2006 15:30:55 -0000 1.9
@@ -10,10 +10,10 @@
/**
* This class provides a non-graphical view of <em>JBossCache</em> replication
* events for a replicated cache.
- * <p>
+ * <p/>
* It can be utilized as a standalone application or as a component in other
* applications.
- * <p>
+ * <p/>
* <strong>WARNING</strong>: take care when using this class in conjunction with
* transactionally replicated cache's as it can cause deadlock situations due to
* the reading of values for nodes in the cache.
@@ -27,7 +27,7 @@
/**
* Constructor.
- * <p>
+ * <p/>
* When using this constructor, this class with attempt to start and stop
* the specified cache.
*
@@ -43,10 +43,8 @@
* Constructor.
*
* @param cache the cache to monitor for replication events.
- *
* @param startCache indicates whether or not the cache should be started by
* this class.
- *
* @param stopCache indicates whether or not the cache should be stopped by
* this class.
*/
@@ -65,7 +63,7 @@
/**
* Instructs this class to listen for cache replication events.
- * <p>
+ * <p/>
* This method waits indefinately. Use the notify method of this class
* (using traditional Java thread notification semantics) to cause this
* method to return.
@@ -80,7 +78,7 @@
* Instructs this class to listen for cache replication events.
*
* @param wait whether or not this method should wait indefinately.
- * <p>
+ * <p/>
* If this parameter is set to <code>true</code>, using the
* notify method of this class (using traditional Java thread
* notification semantics) will cause this method to return.
@@ -92,12 +90,12 @@
if (_startCache)
{
- _cache.startService();
+ _cache.start();
}
if (wait)
{
- synchronized(this)
+ synchronized (this)
{
wait();
}
@@ -130,7 +128,7 @@
public void nodeModified(Fqn fqn, boolean pre, boolean isLocal, Map data)
{
- if(pre)
+ if (pre)
printEvent("DataNode about to be modified: " + fqn);
else
printEvent("DataNode modified: " + fqn);
@@ -138,9 +136,12 @@
public void nodeRemoved(Fqn fqn, boolean pre, boolean isLocal, Map data)
{
- if (pre) {
+ if (pre)
+ {
printEvent("DataNode about to be removed: " + fqn);
- } else {
+ }
+ else
+ {
printEvent("DataNode removed: " + fqn);
}
@@ -158,27 +159,36 @@
public void nodeEvicted(Fqn fqn, boolean pre, boolean isLocal)
{
- if (pre) {
+ if (pre)
+ {
printEvent("DataNode about to be evicted: " + fqn);
- } else {
+ }
+ else
+ {
printEvent("DataNode evicted: " + fqn);
}
}
public void nodeActivated(Fqn fqn, boolean pre)
{
- if (pre) {
+ if (pre)
+ {
printEvent("DataNode about to be activated: " + fqn);
- } else {
+ }
+ else
+ {
printEvent("DataNode activated: " + fqn);
}
}
public void nodePassivated(Fqn fqn, boolean pre)
{
- if (pre) {
+ if (pre)
+ {
printEvent("DataNode about to be evicted: " + fqn);
- } else {
+ }
+ else
+ {
printEvent("DataNode evicted: " + fqn);
}
}
@@ -200,7 +210,6 @@
* Prints the contents of the specified node.
*
* @param fqn the fully qualified name of the node to print.
- *
* @param eventDetail a description of why the node is being printed.
*/
private void printNode(Fqn fqn, String eventDetail)
@@ -277,7 +286,6 @@
* Pads standard output for printing of the specified key.
*
* @param key the to be printed in a padded fashion.
- *
* @param maxKeyLength the maximum length of the keys printed using this
* method. All keys whose length is less than this
* value will be printed in padded fashion.
@@ -318,7 +326,7 @@
public void run()
{
- _cache.stopService();
+ _cache.stop();
}
}
@@ -326,16 +334,16 @@
* The main method.
*
* @param args command line arguments dictated by convention.
- * <p>
+ * <p/>
* The first command line argument is the name of the
* <code>JBossCache</code> configuration file to be utilized
* for configuration of the cache. Only the name of the
* configuration file is necessary as it is read off of the
* classpath.
- * <p>
+ * <p/>
* If a configuration file is not specified on the command line,
* <code>jboss-cache.xml</code> will be the assumed file name.
- * <p>
+ * <p/>
* All command line arguments after the first are ignored.
*/
public static void main(String[] args)
@@ -351,7 +359,9 @@
if (args.length >= 1)
{
configFileName = args[0];
- } else {
+ }
+ else
+ {
System.out.print("No xml config file argument is supplied. Will use jboss-cache.xml from classpath");
}
1.239 +16 -32 JBossCache/src/org/jboss/cache/TreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
retrieving revision 1.238
retrieving revision 1.239
diff -u -b -r1.238 -r1.239
--- TreeCache.java 6 Sep 2006 14:45:41 -0000 1.238
+++ TreeCache.java 6 Sep 2006 15:30:55 -0000 1.239
@@ -41,7 +41,6 @@
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jboss.cache.util.MBeanConfigurator;
import org.jboss.invocation.MarshalledValueOutputStream;
-import org.jboss.system.ServiceMBeanSupport;
import org.jgroups.Address;
import org.jgroups.Channel;
import org.jgroups.ChannelClosedException;
@@ -95,11 +94,11 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: TreeCache.java,v 1.238 2006/09/06 14:45:41 msurtani Exp $
+ * @version $Id: TreeCache.java,v 1.239 2006/09/06 15:30:55 msurtani Exp $
* <p/>
* @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
*/
-public class TreeCache extends ServiceMBeanSupport implements Cloneable, MembershipListener//, TreeCacheMBean
+public class TreeCache implements Cloneable, MembershipListener
{
private static final String CREATE_MUX_CHANNEL = "createMultiplexerChannel";
private static final String[] MUX_TYPES = {"java.lang.String", "java.lang.String"};
@@ -238,7 +237,7 @@
protected boolean nodeLockingOptimistic = false;
/**
- * _createService was called.
+ * create was called.
*/
protected boolean useCreateService = false;
@@ -577,19 +576,12 @@
}
}
- /* --------------------------- MBeanSupport ------------------------- */
-
/**
- * Lifecycle method. This is like initialize. Same thing as calling <code>create</code>
+ * Lifecycle method. This is like initialize.
*
* @throws Exception
*/
- public void createService() throws Exception
- {
- _createService();
- }
-
- protected void _createService() throws Exception
+ public void create() throws Exception
{
stateFetchTimeout = configuration.getLockAcquisitionTimeout() + 5000;
if (configuration.isNodeLockingOptimistic())
@@ -636,7 +628,6 @@
// build interceptor chain
interceptor_chain = new InterceptorChainFactory().buildInterceptorChain(this);
// register interceptor mbeans
- isStandalone = (this.getServiceName() == null);
if (configuration.isUseInterceptorMbeans())
{
MBeanServer mbserver = getMBeanServer();
@@ -715,19 +706,18 @@
return !configuration.isInactiveOnStartup() && buddyManager == null && (configuration.isFetchInMemoryState() || (cacheLoaderManager != null && cacheLoaderManager.isFetchPersistentState()));
}
-
/**
- * Lifecyle method. This is the same thing as calling <code>start</code>
+ * Lifecyle method.
*
* @throws Exception
*/
- public void startService() throws Exception
+ public void start() throws Exception
{
- // Get around the problem of standalone user forgets to call createService.
+ // Get around the problem of standalone user forgets to call create.
if (!useCreateService)
{
- _createService();
+ create();
}
// cache loaders should be initialised *before* any state transfers take place to prevent
@@ -785,7 +775,7 @@
/**
* Unregisters the interceptor MBeans.
*/
- public void destroyService()
+ public void destroy()
{
// unregister interceptor mbeans
if (configuration.isUseInterceptorMbeans())
@@ -807,19 +797,19 @@
/**
- * Lifecycle method. Same thing as calling <code>stop</code>.
+ * Lifecycle method.
*/
- public void stopService()
+ public void stop()
{
if (channel != null)
{
- log.info("stopService(): closing the channel");
+ log.info("stop(): closing the channel");
channel.close();
channel = null;
}
if (disp != null)
{
- log.info("stopService(): stopping the dispatcher");
+ log.info("stop(): stopping the dispatcher");
disp.stop();
disp = null;
}
@@ -989,7 +979,7 @@
}
// Use the getter method here, as it will create the marshaller
- // if this method is called before we do it in _createService()
+ // if this method is called before we do it in create()
getMarshaller().registerClassLoader(fqn, cl);
}
@@ -1008,7 +998,7 @@
}
// Use the getter method here, as it will create the marshaller
- // if this method is called before we do it in _createService()
+ // if this method is called before we do it in create()
getMarshaller().unregisterClassLoader(fqn);
}
@@ -4421,12 +4411,6 @@
private MBeanServer getMBeanServer()
{
- // return local server from ServiceMBeanSupport if available
- if (server != null)
- {
- return server;
- }
-
ArrayList servers = MBeanServerFactory.findMBeanServer(null);
if (servers == null || servers.size() == 0)
{
1.27 +4 -10 JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheProxyImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- TreeCacheProxyImpl.java 6 Sep 2006 14:45:44 -0000 1.26
+++ TreeCacheProxyImpl.java 6 Sep 2006 15:30:55 -0000 1.27
@@ -20,7 +20,6 @@
import org.jboss.cache.statetransfer.StateTransferManager;
import org.jgroups.Address;
-import javax.management.ObjectName;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import java.util.Collection;
@@ -109,11 +108,6 @@
return treeCache.getVersion();
}
- public ObjectName getServiceName()
- {
- return treeCache.getServiceName();
- }
-
public TransactionManager getTransactionManager()
{
return treeCache.getTransactionManager();
@@ -248,22 +242,22 @@
public void create() throws Exception
{
- treeCache.createService();
+ treeCache.create();
}
public void start() throws Exception
{
- treeCache.startService();
+ treeCache.start();
}
public void stop()
{
- treeCache.stopService();
+ treeCache.stop();
}
public void destroy()
{
- treeCache.destroyService();
+ treeCache.destroy();
}
public Node getParent()
1.14 +728 -548 JBossCache/src/org/jboss/cache/TreeCacheView2.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheView2.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheView2.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- TreeCacheView2.java 16 Aug 2006 10:52:51 -0000 1.13
+++ TreeCacheView2.java 6 Sep 2006 15:30:55 -0000 1.14
@@ -12,9 +12,8 @@
import bsh.util.JConsole;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.log4j.PropertyConfigurator;
-import org.jgroups.View;
import org.jboss.cache.factories.XmlConfigurationParser;
+import org.jgroups.View;
import javax.swing.*;
import javax.swing.event.TableModelEvent;
@@ -54,74 +53,91 @@
* 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.13 $
+ * @version $Revision: 1.14 $
*/
-public class TreeCacheView2 {
- static TreeCacheGui2 gui_=null;
+public class TreeCacheView2
+{
+ static TreeCacheGui2 gui_ = null;
static boolean useConsole = false;
- TreeCache cache_=null;
- static Log log_=LogFactory.getLog(TreeCacheView2.class.getName());
+ TreeCache cache_ = null;
+ static Log log_ = LogFactory.getLog(TreeCacheView2.class.getName());
- public TreeCacheView2(TreeCache cache) throws Exception {
- this.cache_=cache;
+ public TreeCacheView2(TreeCache cache) throws Exception
+ {
+ this.cache_ = cache;
}
public static void setCache(TreeCache cache)
{
gui_.setCache(cache);
}
- public void start() throws Exception {
- if(gui_ == null) {
+
+ public void start() throws Exception
+ {
+ if (gui_ == null)
+ {
log_.info("start(): creating the GUI");
- gui_=new TreeCacheGui2(cache_);
+ gui_ = new TreeCacheGui2(cache_);
}
}
- public void stop() {
- if(gui_ != null) {
+ public void stop()
+ {
+ if (gui_ != null)
+ {
log_.info("stop(): disposing the GUI");
gui_.stopGui();
- gui_=null;
+ gui_ = null;
}
}
- void populateTree(String dir) throws Exception {
- File file=new File(dir);
+ void populateTree(String dir) throws Exception
+ {
+ File file = new File(dir);
- if(!file.exists()) return;
+ if (!file.exists()) return;
put(dir, null);
- if(file.isDirectory()) {
- String[] children=file.list();
- if(children != null && children.length > 0) {
- for(int i=0; i < children.length; i++)
+ if (file.isDirectory())
+ {
+ String[] children = file.list();
+ if (children != null && children.length > 0)
+ {
+ for (int i = 0; i < children.length; i++)
populateTree(dir + "/" + children[i]);
}
}
}
- void put(String fqn, Map m) {
- try {
+ void put(String fqn, Map m)
+ {
+ try
+ {
cache_.put(fqn, m);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log_.error("TreeCacheView2.put(): " + t);
}
}
- public static void main(String args[]) {
+ public static void main(String args[])
+ {
TreeCache tree = null;
TreeCacheView2 demo;
String start_directory = null;
String resource = "META-INF/replSync-service.xml";
- for (int i = 0; i < args.length; i++) {
- if (args[i].equals("-console")) {
+ for (int i = 0; i < args.length; i++)
+ {
+ if (args[i].equals("-console"))
+ {
useConsole = true;
continue;
}
- if (args[i].equals("-config")) {
+ if (args[i].equals("-config"))
+ {
resource = args[++i];
continue;
}
@@ -129,11 +145,15 @@
return;
}
- try {
- if (useConsole) {
+ try
+ {
+ if (useConsole)
+ {
demo = new TreeCacheView2(null);
demo.start();
- } else {
+ }
+ else
+ {
tree = new TreeCache();
tree.setConfiguration(new XmlConfigurationParser().parseFile(resource));
@@ -141,15 +161,20 @@
tree.start();
demo = new TreeCacheView2(tree);
demo.start();
- if (start_directory != null && start_directory.length() > 0) {
+ if (start_directory != null && start_directory.length() > 0)
+ {
demo.populateTree(start_directory);
}
}
- } catch (Exception ex) {
+ }
+ catch (Exception ex)
+ {
ex.printStackTrace();
}
}
- static void help() {
+
+ static void help()
+ {
System.out.println("TreeCacheView [-help] " +
"[-mbean_name <name of TreeCache MBean>] " +
"[-start_directory <dirname>] [-props <props>] " +
@@ -159,48 +184,53 @@
}
-class ShutdownThread extends Thread {
- TreeCache tree=null;
+class ShutdownThread extends Thread
+{
+ TreeCache tree = null;
- ShutdownThread(TreeCache tree) {
- this.tree=tree;
+ ShutdownThread(TreeCache tree)
+ {
+ this.tree = tree;
}
- public void run() {
- tree.stopService();
- }
+ public void run()
+ {
+ tree.stop();
}
+}
class TreeCacheGui2 extends JFrame implements WindowListener, CacheListener,
- TreeSelectionListener, TableModelListener {
+ TreeSelectionListener, TableModelListener
+{
private static final long serialVersionUID = -1242167331988194987L;
TreeCache 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 props=null;
- String selected_node=null;
- JPanel tablePanel=null;
- JMenu operationsMenu=null;
- JPopupMenu operationsPopup=null;
- JMenuBar menubar=null;
- boolean use_system_exit=false;
- static String SEP=Fqn.SEPARATOR;
- private static final int KEY_COL_WIDTH=20;
- private static final int VAL_COL_WIDTH=300;
- final String STRING=String.class.getName();
- final String MAP=Map.class.getName();
- final String OBJECT=Object.class.getName();
- TransactionManager tx_mgr=null;
- Transaction tx=null;
+ 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 props = null;
+ String selected_node = null;
+ JPanel tablePanel = null;
+ JMenu operationsMenu = null;
+ JPopupMenu operationsPopup = null;
+ JMenuBar menubar = null;
+ boolean use_system_exit = false;
+ static String SEP = Fqn.SEPARATOR;
+ private static final int KEY_COL_WIDTH = 20;
+ private static final int VAL_COL_WIDTH = 300;
+ final String STRING = String.class.getName();
+ final String MAP = Map.class.getName();
+ final String OBJECT = Object.class.getName();
+ TransactionManager tx_mgr = null;
+ Transaction tx = null;
JPanel mainPanel;
- public TreeCacheGui2(TreeCache cache) throws Exception {
+ public TreeCacheGui2(TreeCache cache) throws Exception
+ {
addNotify();
tree_model = new DefaultTreeModel(root);
@@ -216,7 +246,7 @@
addWindowListener(this);
- table_model.setColumnIdentifiers(new String[] { "Name", "Value" });
+ table_model.setColumnIdentifiers(new String[]{"Name", "Value"});
table_model.addTableModelListener(this);
setTableColumnWidths();
@@ -227,8 +257,9 @@
tablePanel.add(table, BorderLayout.CENTER);
mainPanel.add(tablePanel, BorderLayout.SOUTH);
- JSplitPane contentPanel=null;
- if (TreeCacheView2.useConsole) {
+ JSplitPane contentPanel = null;
+ if (TreeCacheView2.useConsole)
+ {
JConsole bshConsole = new JConsole();
Interpreter interpreter = new Interpreter(bshConsole);
interpreter.getNameSpace().importCommands("org.jboss.cache.util");
@@ -239,22 +270,28 @@
Thread t = new Thread(interpreter);
t.start();
- contentPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT,mainPanel, bshConsole);
+ contentPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPanel, bshConsole);
getContentPane().add(contentPanel);
- } else {
+ }
+ else
+ {
getContentPane().add(mainPanel);
}
jtree.addTreeSelectionListener(this);// REVISIT
- MouseListener ml = new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
+ MouseListener ml = new MouseAdapter()
+ {
+ public void mouseClicked(MouseEvent e)
+ {
int selRow = jtree.getRowForLocation(e.getX(), e.getY());
TreePath selPath = jtree.getPathForLocation(e.getX(), e.getY());
- if (selRow != -1) {
+ if (selRow != -1)
+ {
selected_node = makeFQN(selPath.getPath());
jtree.setSelectionPath(selPath);
- if (e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK) {
+ if (e.getModifiers() == java.awt.event.InputEvent.BUTTON3_MASK)
+ {
operationsPopup.show(e.getComponent(), e.getX(), e
.getY());
}
@@ -273,7 +310,7 @@
setCache(cache);
setVisible(true);
- if(TreeCacheView2.useConsole)
+ if (TreeCacheView2.useConsole)
{
//has to be called after setVisible() otherwise no effect
contentPanel.setDividerLocation(0.65);
@@ -283,84 +320,100 @@
public void setCache(TreeCache tree)
{
cache_ = tree;
- if(cache_!= null)
+ if (cache_ != null)
{
Runtime.getRuntime().addShutdownHook(new ShutdownThread(tree));
cache_.getNotifier().addCacheListener(this);
setTitle("TreeCacheGui2: mbr=" + getLocalAddress());
- tx_mgr=cache_.getTransactionManager();
+ tx_mgr = cache_.getTransactionManager();
populateTree();
}
else
{
setTitle("Cache undefined");
- if(tree_model!=null)
+ if (tree_model != null)
{
root = new MyNode(SEP);
tree_model.setRoot(root);
tree_model.reload();
}
- if(table_model!=null)
+ if (table_model != null)
{
clearTable();
}
}
}
- void setSystemExit(boolean flag) {
- use_system_exit=flag;
+ void setSystemExit(boolean flag)
+ {
+ use_system_exit = flag;
}
- public void windowClosed(WindowEvent event) {
+ public void windowClosed(WindowEvent event)
+ {
}
- public void windowDeiconified(WindowEvent event) {
+ public void windowDeiconified(WindowEvent event)
+ {
}
- public void windowIconified(WindowEvent event) {
+ public void windowIconified(WindowEvent event)
+ {
}
- public void windowActivated(WindowEvent event) {
+ public void windowActivated(WindowEvent event)
+ {
}
- public void windowDeactivated(WindowEvent event) {
+ public void windowDeactivated(WindowEvent event)
+ {
}
- public void windowOpened(WindowEvent event) {
+ public void windowOpened(WindowEvent event)
+ {
}
- public void windowClosing(WindowEvent event) {
+ public void windowClosing(WindowEvent event)
+ {
stopGui();
}
- public void tableChanged(TableModelEvent evt) {
+ public void tableChanged(TableModelEvent evt)
+ {
int row, col;
String key, val;
- if(evt.getType() == TableModelEvent.UPDATE) {
- row=evt.getFirstRow();
- col=evt.getColumn();
- if(col == 0) { // set()
- key=(String)table_model.getValueAt(row, col);
- val=(String)table_model.getValueAt(row, col + 1);
- if(key != null && val != null) {
+ if (evt.getType() == TableModelEvent.UPDATE)
+ {
+ row = evt.getFirstRow();
+ col = evt.getColumn();
+ if (col == 0)
+ { // set()
+ key = (String) table_model.getValueAt(row, col);
+ val = (String) table_model.getValueAt(row, col + 1);
+ if (key != null && val != null)
+ {
// tree.put(selected_node, key, val);
- try {
+ try
+ {
cache_.put(selected_node, key, val);
}
- catch(Exception e) {
+ catch (Exception e)
+ {
e.printStackTrace();
}
}
}
- else { // add()
- key=(String)table_model.getValueAt(row, col - 1);
- val=(String)table.getValueAt(row, col);
- if(key != null && val != null) {
+ else
+ { // add()
+ key = (String) table_model.getValueAt(row, col - 1);
+ val = (String) table.getValueAt(row, col);
+ if (key != null && val != null)
+ {
put(selected_node, key, val);
}
}
@@ -368,49 +421,54 @@
}
- public void valueChanged(TreeSelectionEvent evt) {
- TreePath path=evt.getPath();
- String fqn=SEP;
+ public void valueChanged(TreeSelectionEvent evt)
+ {
+ TreePath path = evt.getPath();
+ String fqn = SEP;
String component_name;
- Map data=null;
+ Map data = null;
- for(int i=0; i < path.getPathCount(); i++) {
- component_name=((MyNode)path.getPathComponent(i)).name;
- if(component_name.equals(SEP))
+ for (int i = 0; i < path.getPathCount(); i++)
+ {
+ component_name = ((MyNode) path.getPathComponent(i)).name;
+ if (component_name.equals(SEP))
continue;
- if(fqn.equals(SEP))
- fqn+=component_name;
+ if (fqn.equals(SEP))
+ fqn += component_name;
else
- fqn=fqn + SEP + component_name;
+ fqn = fqn + SEP + component_name;
}
- data=getData(fqn);
- if(data != null) {
+ data = getData(fqn);
+ if (data != null)
+ {
mainPanel.add(tablePanel, BorderLayout.SOUTH);
populateTable(data);
validate();
}
- else {
+ else
+ {
clearTable();
mainPanel.remove(tablePanel);
validate();
}
}
-
-
/* ------------------ ReplicatedTree.ReplicatedTreeListener interface ------------ */
public void nodeCreated(Fqn fqn, boolean pre, boolean isLocal)
{
- if (!pre) {
+ if (!pre)
+ {
MyNode n, p;
- n=root.add(fqn.toString());
- if(n != null) {
- p=(MyNode)n.getParent();
+ n = root.add(fqn.toString());
+ if (n != null)
+ {
+ p = (MyNode) n.getParent();
tree_model.reload(p);
jtree.scrollPathToVisible(new TreePath(n.getPath()));
- } }
+ }
+ }
}
@@ -431,10 +489,11 @@
MyNode n;
TreeNode par;
- n=root.findNode(fqn.toString());
- if(n != null) {
+ n = root.findNode(fqn.toString());
+ if (n != null)
+ {
n.removeAllChildren();
- par=n.getParent();
+ par = n.getParent();
n.removeFromParent();
tree_model.reload(par);
}
@@ -472,11 +531,15 @@
{
}
- public void viewChange(final View new_view) {
- new Thread() {
- public void run() {
+ public void viewChange(final View new_view)
+ {
+ new Thread()
+ {
+ public void run()
+ {
Vector mbrship;
- if(new_view != null && (mbrship=new_view.getMembers()) != null) {
+ if (new_view != null && (mbrship = new_view.getMembers()) != null)
+ {
_put(SEP, "members", mbrship);
_put(SEP, "coordinator", mbrship.firstElement());
}
@@ -484,30 +547,28 @@
}.start();
}
-
-
-
/* ---------------- End of ReplicatedTree.ReplicatedTreeListener interface -------- */
/*----------------- Runnable implementation to make View change calles in AWT Thread ---*/
- public void run() {
+ public void run()
+ {
}
-
-
/* ----------------------------- Private Methods ---------------------------------- */
/**
* Fetches all data from underlying tree model and display it graphically
*/
- void init() {
- Vector mbrship=null;
+ void init()
+ {
+ Vector mbrship = null;
// addGuiNode(SEP);
- mbrship=getMembers() != null ? (Vector)getMembers().clone() : null;
- if(mbrship != null && mbrship.size() > 0) {
+ mbrship = getMembers() != null ? (Vector) getMembers().clone() : null;
+ if (mbrship != null && mbrship.size() > 0)
+ {
_put(SEP, "members", mbrship);
_put(SEP, "coordinator", mbrship.firstElement());
}
@@ -517,7 +578,8 @@
/**
* Fetches all data from underlying tree model and display it graphically
*/
- private void populateTree() {
+ private void populateTree()
+ {
addGuiNode(SEP);
}
@@ -525,50 +587,57 @@
/**
* Recursively adds GUI nodes starting from fqn
*/
- void addGuiNode(String fqn) {
+ void addGuiNode(String fqn)
+ {
Set children;
String child_name;
- if(fqn == null) return;
+ if (fqn == null) return;
// 1 . Add myself
root.add(fqn);
// 2. Then add my children
- children=getChildrenNames(fqn);
- if(children != null) {
- for(Iterator it=children.iterator(); it.hasNext();) {
- child_name=it.next().toString();
+ children = getChildrenNames(fqn);
+ if (children != null)
+ {
+ for (Iterator it = children.iterator(); it.hasNext();)
+ {
+ child_name = it.next().toString();
addGuiNode(fqn + SEP + child_name);
}
}
}
- String makeFQN(Object[] path) {
- StringBuffer sb=new StringBuffer("");
+ String makeFQN(Object[] path)
+ {
+ StringBuffer sb = new StringBuffer("");
String tmp_name;
- if(path == null) return null;
- for(int i=0; i < path.length; i++) {
- tmp_name=((MyNode)path[i]).name;
- if(tmp_name.equals(SEP))
+ if (path == null) return null;
+ for (int i = 0; i < path.length; i++)
+ {
+ tmp_name = ((MyNode) path[i]).name;
+ if (tmp_name.equals(SEP))
continue;
else
sb.append(SEP + tmp_name);
}
- tmp_name=sb.toString();
- if(tmp_name.length() == 0)
+ tmp_name = sb.toString();
+ if (tmp_name.length() == 0)
return SEP;
else
return tmp_name;
}
- void clearTable() {
- int num_rows=table.getRowCount();
+ void clearTable()
+ {
+ int num_rows = table.getRowCount();
- if(num_rows > 0) {
- for(int i=0; i < num_rows; i++)
+ if (num_rows > 0)
+ {
+ for (int i = 0; i < num_rows; i++)
table_model.removeRow(0);
table_model.fireTableRowsDeleted(0, num_rows - 1);
repaint();
@@ -576,22 +645,25 @@
}
- void populateTable(Map data) {
- String key, strval="<null>";
+ void populateTable(Map data)
+ {
+ String key, strval = "<null>";
Object val;
- int num_rows=0;
+ int num_rows = 0;
Map.Entry entry;
- if(data == null) return;
- num_rows=data.size();
+ if (data == null) return;
+ num_rows = data.size();
clearTable();
- if(num_rows > 0) {
- for(Iterator it=data.entrySet().iterator(); it.hasNext();) {
- entry=(Map.Entry)it.next();
- key=(String)entry.getKey();
- val=entry.getValue();
- if(val != null) strval=val.toString();
+ if (num_rows > 0)
+ {
+ for (Iterator it = data.entrySet().iterator(); it.hasNext();)
+ {
+ entry = (Map.Entry) it.next();
+ key = (String) entry.getKey();
+ val = entry.getValue();
+ if (val != null) strval = val.toString();
table_model.addRow(new Object[]{key, strval});
}
table_model.fireTableRowsInserted(0, num_rows - 1);
@@ -599,40 +671,42 @@
}
}
- private void setTableColumnWidths() {
+ private void setTableColumnWidths()
+ {
table.sizeColumnsToFit(JTable.AUTO_RESIZE_NEXT_COLUMN);
- TableColumn column=null;
- column=table.getColumnModel().getColumn(0);
+ TableColumn column = null;
+ column = table.getColumnModel().getColumn(0);
column.setMinWidth(KEY_COL_WIDTH);
column.setPreferredWidth(KEY_COL_WIDTH);
- column=table.getColumnModel().getColumn(1);
+ column = table.getColumnModel().getColumn(1);
column.setPreferredWidth(VAL_COL_WIDTH);
}
- private void createMenus() {
- menubar=new JMenuBar();
- operationsMenu=new JMenu("Operations");
- AddNodeAction addNode=new AddNodeAction();
+ private void createMenus()
+ {
+ menubar = new JMenuBar();
+ operationsMenu = new JMenu("Operations");
+ AddNodeAction addNode = new AddNodeAction();
addNode.putValue(AbstractAction.NAME, "Add to this node");
- LoadAction load_action=new LoadAction();
+ LoadAction load_action = new LoadAction();
load_action.putValue(AbstractAction.NAME, "Load from the CacheLoader");
- RemoveNodeAction removeNode=new RemoveNodeAction();
+ RemoveNodeAction removeNode = new RemoveNodeAction();
removeNode.putValue(AbstractAction.NAME, "Remove this node");
- EvictAction evict_action=new EvictAction();
+ EvictAction evict_action = new EvictAction();
evict_action.putValue(AbstractAction.NAME, "Evict from the Cache");
- AddModifyDataForNodeAction addModAction=new AddModifyDataForNodeAction();
+ AddModifyDataForNodeAction addModAction = new AddModifyDataForNodeAction();
addModAction.putValue(AbstractAction.NAME, "Add/Modify data");
- PrintLockInfoAction print_locks=new PrintLockInfoAction();
+ PrintLockInfoAction print_locks = new PrintLockInfoAction();
print_locks.putValue(AbstractAction.NAME, "Print lock information (stdout)");
- ReleaseAllLocksAction release_locks=new ReleaseAllLocksAction();
+ ReleaseAllLocksAction release_locks = new ReleaseAllLocksAction();
release_locks.putValue(AbstractAction.NAME, "Release all locks");
- ExitAction exitAction=new ExitAction();
+ ExitAction exitAction = new ExitAction();
exitAction.putValue(AbstractAction.NAME, "Exit");
- StartTransaction start_tx=new StartTransaction();
+ StartTransaction start_tx = new StartTransaction();
start_tx.putValue(AbstractAction.NAME, "Start TX");
- CommitTransaction commit_tx=new CommitTransaction();
+ CommitTransaction commit_tx = new CommitTransaction();
commit_tx.putValue(AbstractAction.NAME, "Commit TX");
- RollbackTransaction rollback_tx=new RollbackTransaction();
+ RollbackTransaction rollback_tx = new RollbackTransaction();
rollback_tx.putValue(AbstractAction.NAME, "Rollback TX");
operationsMenu.add(addNode);
operationsMenu.add(load_action);
@@ -648,7 +722,7 @@
menubar.add(operationsMenu);
setJMenuBar(menubar);
- operationsPopup=new JPopupMenu();
+ operationsPopup = new JPopupMenu();
operationsPopup.add(addNode);
operationsPopup.add(load_action);
operationsPopup.add(evict_action);
@@ -656,150 +730,191 @@
operationsPopup.add(addModAction);
}
- Object getLocalAddress() {
- try {
+ Object getLocalAddress()
+ {
+ try
+ {
return cache_.getLocalAddress();
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.getLocalAddress(): " + t);
return null;
}
}
- Map getData(String fqn) {
+ Map getData(String 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)
+ 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);
}
return data;
}
- void load(String fqn) {
- try {
+ void load(String fqn)
+ {
+ try
+ {
cache_.load(fqn);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.load(): " + t);
}
}
- void evict(String fqn) {
- try {
+ void evict(String fqn)
+ {
+ try
+ {
cache_.evict(Fqn.fromString(fqn));
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.evict(): " + t);
}
}
- void put(String fqn, Map m) {
- try {
+ void put(String fqn, Map m)
+ {
+ try
+ {
cache_.put(fqn, m);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.put(): " + t);
}
}
- void _put(String fqn, Map m) {
- try {
+ void _put(String fqn, Map m)
+ {
+ try
+ {
cache_._put(null, fqn, m, false);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2._put(): " + t);
}
}
- void put(String fqn, String key, Object value) {
- try {
+ void put(String fqn, String key, Object value)
+ {
+ try
+ {
cache_.put(fqn, key, value);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.put(): " + t);
}
}
- void _put(String fqn, String key, Object value) {
- try {
+ void _put(String fqn, String key, Object value)
+ {
+ try
+ {
cache_._put(null, fqn, key, value, false);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2._put(): " + t);
}
}
- Set getKeys(String fqn) {
- try {
+ Set getKeys(String fqn)
+ {
+ try
+ {
return cache_.getKeys(fqn);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.getKeys(): " + t);
return null;
}
}
- Object get(String fqn, String key) {
- try {
+ Object get(String fqn, String key)
+ {
+ try
+ {
return cache_.get(fqn, key);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.get(): " + t);
return null;
}
}
- Set getChildrenNames(String fqn) {
- try {
+ Set getChildrenNames(String fqn)
+ {
+ try
+ {
return cache_.getChildrenNames(fqn);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui2.getChildrenNames(): " + t);
return null;
}
}
- Vector getMembers() {
- try {
+ Vector getMembers()
+ {
+ try
+ {
return cache_.getMembers();
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("TreeCacheGui.getMembers(): " + t);
return null;
}
}
-
/* -------------------------- End of Private Methods ------------------------------ */
/*----------------------- Actions ---------------------------*/
- class ExitAction extends AbstractAction {
+ class ExitAction extends AbstractAction
+ {
private static final long serialVersionUID = -5364163916172148038L;
- public void actionPerformed(ActionEvent e) {
+
+ public void actionPerformed(ActionEvent e)
+ {
stopGui();
}
}
- void stopGui() {
- if(cache_ != null) {
- try {
- cache_.stopService();
- cache_.destroyService();
- cache_=null;
+ void stopGui()
+ {
+ if (cache_ != null)
+ {
+ try
+ {
+ cache_.stop();
+ cache_.destroy();
+ cache_ = null;
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
t.printStackTrace();
}
}
@@ -807,18 +922,21 @@
System.exit(0);
}
- class AddNodeAction extends AbstractAction {
+ class AddNodeAction extends AbstractAction
+ {
private static final long serialVersionUID = 7084928639244438800L;
- public void actionPerformed(ActionEvent e) {
- JTextField fqnTextField=new JTextField();
- if(selected_node != null)
+
+ public void actionPerformed(ActionEvent e)
+ {
+ JTextField fqnTextField = new JTextField();
+ if (selected_node != null)
fqnTextField.setText(selected_node);
- Object[] information={"Enter fully qualified name",
+ Object[] information = {"Enter fully qualified name",
fqnTextField};
- final String btnString1="OK";
- final String btnString2="Cancel";
- Object[] options={btnString1, btnString2};
- int userChoice=JOptionPane.showOptionDialog(null,
+ final String btnString1 = "OK";
+ final String btnString2 = "Cancel";
+ Object[] options = {btnString1, btnString2};
+ int userChoice = JOptionPane.showOptionDialog(null,
information,
"Add DataNode",
JOptionPane.YES_NO_OPTION,
@@ -826,25 +944,29 @@
null,
options,
options[0]);
- if(userChoice == 0) {
- String userInput=fqnTextField.getText();
+ if (userChoice == 0)
+ {
+ String userInput = fqnTextField.getText();
put(userInput, null);
}
}
}
- class LoadAction extends AbstractAction {
+ class LoadAction extends AbstractAction
+ {
private static final long serialVersionUID = -6998760732995584428L;
- public void actionPerformed(ActionEvent e) {
- JTextField fqnTextField=new JTextField();
- if(selected_node != null)
+
+ public void actionPerformed(ActionEvent e)
+ {
+ JTextField fqnTextField = new JTextField();
+ if (selected_node != null)
fqnTextField.setText(selected_node);
- Object[] information={"Enter fully qualified name",
+ Object[] information = {"Enter fully qualified name",
fqnTextField};
- final String btnString1="OK";
- final String btnString2="Cancel";
- Object[] options={btnString1, btnString2};
- int userChoice=JOptionPane.showOptionDialog(null,
+ final String btnString1 = "OK";
+ final String btnString2 = "Cancel";
+ Object[] options = {btnString1, btnString2};
+ int userChoice = JOptionPane.showOptionDialog(null,
information,
"Load DataNode",
JOptionPane.YES_NO_OPTION,
@@ -852,25 +974,29 @@
null,
options,
options[0]);
- if(userChoice == 0) {
- String userInput=fqnTextField.getText();
+ if (userChoice == 0)
+ {
+ String userInput = fqnTextField.getText();
load(userInput);
}
}
}
- class EvictAction extends AbstractAction {
+ class EvictAction extends AbstractAction
+ {
private static final long serialVersionUID = 6007500908549034215L;
- public void actionPerformed(ActionEvent e) {
- JTextField fqnTextField=new JTextField();
- if(selected_node != null)
+
+ public void actionPerformed(ActionEvent e)
+ {
+ JTextField fqnTextField = new JTextField();
+ if (selected_node != null)
fqnTextField.setText(selected_node);
- Object[] information={"Enter fully qualified name",
+ Object[] information = {"Enter fully qualified name",
fqnTextField};
- final String btnString1="OK";
- final String btnString2="Cancel";
- Object[] options={btnString1, btnString2};
- int userChoice=JOptionPane.showOptionDialog(null,
+ final String btnString1 = "OK";
+ final String btnString2 = "Cancel";
+ Object[] options = {btnString1, btnString2};
+ int userChoice = JOptionPane.showOptionDialog(null,
information,
"Evict DataNode",
JOptionPane.YES_NO_OPTION,
@@ -878,108 +1004,146 @@
null,
options,
options[0]);
- if(userChoice == 0) {
- String userInput=fqnTextField.getText();
+ if (userChoice == 0)
+ {
+ String userInput = fqnTextField.getText();
evict(userInput);
}
}
}
- class StartTransaction extends AbstractAction {
+ class StartTransaction extends AbstractAction
+ {
private static final long serialVersionUID = 7059131008813144857L;
- public void actionPerformed(ActionEvent e) {
- if(tx_mgr == null) {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (tx_mgr == null)
+ {
log.error("no TransactionManager specified");
return;
}
- if(tx != null) {
+ if (tx != null)
+ {
log.error("transaction is already running: " + tx);
return;
}
- try {
+ try
+ {
tx_mgr.begin();
- tx=tx_mgr.getTransaction();
+ tx = tx_mgr.getTransaction();
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
t.printStackTrace();
}
}
}
- class CommitTransaction extends AbstractAction {
+ class CommitTransaction extends AbstractAction
+ {
private static final long serialVersionUID = 5426108920883879873L;
- public void actionPerformed(ActionEvent e) {
- if(tx == null) {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (tx == null)
+ {
log.error("transaction is not running");
return;
}
- try {
+ try
+ {
tx.commit();
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
t.printStackTrace();
}
- finally {
- tx=null;
+ finally
+ {
+ tx = null;
}
}
}
- class RollbackTransaction extends AbstractAction {
+ class RollbackTransaction extends AbstractAction
+ {
private static final long serialVersionUID = -4836748411400541430L;
- public void actionPerformed(ActionEvent e) {
- if(tx == null) {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (tx == null)
+ {
log.error("transaction is not running");
return;
}
- try {
+ try
+ {
tx.rollback();
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
t.printStackTrace();
}
- finally {
- tx=null;
+ finally
+ {
+ tx = null;
}
}
}
- class PrintLockInfoAction extends AbstractAction {
+ class PrintLockInfoAction extends AbstractAction
+ {
private static final long serialVersionUID = -2171307516592250436L;
- public void actionPerformed(ActionEvent e) {
+
+ public void actionPerformed(ActionEvent e)
+ {
System.out.println("\n*** lock information ****\n" + cache_.printLockInfo());
}
}
- class ReleaseAllLocksAction extends AbstractAction {
+ class ReleaseAllLocksAction extends AbstractAction
+ {
private static final long serialVersionUID = 6894888234400908985L;
- public void actionPerformed(ActionEvent e) {
+
+ public void actionPerformed(ActionEvent e)
+ {
cache_.releaseAllLocks("/");
}
}
- class RemoveNodeAction extends AbstractAction {
+ class RemoveNodeAction extends AbstractAction
+ {
private static final long serialVersionUID = 3746013603940497991L;
- public void actionPerformed(ActionEvent e) {
- try {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ try
+ {
cache_.remove(selected_node);
}
- catch(Throwable t) {
+ catch (Throwable t)
+ {
log.error("RemoveNodeAction.actionPerformed(): " + t);
}
}
}
- class AddModifyDataForNodeAction extends AbstractAction {
+ class AddModifyDataForNodeAction extends AbstractAction
+ {
private static final long serialVersionUID = -7656592171312920825L;
- public void actionPerformed(ActionEvent e) {
- Map data=getData(selected_node);
- if(data != null && data.size() > 0) {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ Map data = getData(selected_node);
+ if (data != null && data.size() > 0)
+ {
}
- else {
+ else
+ {
clearTable();
- data=new HashMap();
+ data = new HashMap();
data.put("Add Key", "Add Value");
}
@@ -991,13 +1155,15 @@
}
- class MyNode extends DefaultMutableTreeNode {
+ class MyNode extends DefaultMutableTreeNode
+ {
private static final long serialVersionUID = 4882445905140460053L;
- String name="<unnamed>";
+ String name = "<unnamed>";
- MyNode(String name) {
- this.name=name;
+ MyNode(String name)
+ {
+ this.name = name;
}
@@ -1005,24 +1171,27 @@
* 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) {
- MyNode curr, n, ret=null;
+ public MyNode add(String fqn)
+ {
+ MyNode curr, n, ret = null;
StringTokenizer tok;
String child_name;
- if(fqn == null) return null;
- curr=this;
- tok=new StringTokenizer(fqn, TreeCacheGui2.SEP);
-
- while(tok.hasMoreTokens()) {
- child_name=tok.nextToken();
- n=curr.findChild(child_name);
- if(n == null) {
- n=new MyNode(child_name);
- if(ret == null) ret=n;
+ if (fqn == null) return null;
+ curr = this;
+ tok = new StringTokenizer(fqn, TreeCacheGui2.SEP);
+
+ while (tok.hasMoreTokens())
+ {
+ child_name = tok.nextToken();
+ n = curr.findChild(child_name);
+ if (n == null)
+ {
+ n = new MyNode(child_name);
+ if (ret == null) ret = n;
curr.add(n);
}
- curr=n;
+ curr = n;
}
return ret;
}
@@ -1031,75 +1200,86 @@
/**
* Removes a node from the view. Child nodes will be removed as well
*/
- public void remove(String fqn) {
+ public void remove(String fqn)
+ {
removeFromParent();
}
- MyNode findNode(String fqn) {
+ MyNode findNode(String fqn)
+ {
MyNode curr, n;
StringTokenizer tok;
String child_name;
- if(fqn == null) return null;
- curr=this;
- tok=new StringTokenizer(fqn, TreeCacheGui2.SEP);
-
- while(tok.hasMoreTokens()) {
- child_name=tok.nextToken();
- n=curr.findChild(child_name);
- if(n == null)
+ if (fqn == null) return null;
+ curr = this;
+ tok = new StringTokenizer(fqn, TreeCacheGui2.SEP);
+
+ while (tok.hasMoreTokens())
+ {
+ child_name = tok.nextToken();
+ n = curr.findChild(child_name);
+ if (n == null)
return null;
- curr=n;
+ curr = n;
}
return curr;
}
- MyNode findChild(String relative_name) {
+ MyNode findChild(String relative_name)
+ {
MyNode child;
- if(relative_name == null || getChildCount() == 0)
+ if (relative_name == null || getChildCount() == 0)
return null;
- for(int i=0; i < getChildCount(); i++) {
- child=(MyNode)getChildAt(i);
- if(child.name == null) {
+ for (int i = 0; i < getChildCount(); i++)
+ {
+ child = (MyNode) getChildAt(i);
+ if (child.name == null)
+ {
continue;
}
- if(child.name.equals(relative_name))
+ if (child.name.equals(relative_name))
return child;
}
return null;
}
- String print(int indent) {
- StringBuffer sb=new StringBuffer();
+ String print(int indent)
+ {
+ StringBuffer sb = new StringBuffer();
- for(int i=0; i < indent; i++)
+ for (int i = 0; i < indent; i++)
sb.append(" ");
- if(!isRoot()) {
- if(name == null)
+ if (!isRoot())
+ {
+ if (name == null)
sb.append("/<unnamed>");
- else {
+ else
+ {
sb.append(TreeCacheGui2.SEP + name);
}
}
sb.append("\n");
- if(getChildCount() > 0) {
- if(isRoot())
- indent=0;
+ if (getChildCount() > 0)
+ {
+ if (isRoot())
+ indent = 0;
else
- indent+=4;
- for(int i=0; i < getChildCount(); i++)
- sb.append(((MyNode)getChildAt(i)).print(indent));
+ indent += 4;
+ for (int i = 0; i < getChildCount(); i++)
+ sb.append(((MyNode) getChildAt(i)).print(indent));
}
return sb.toString();
}
- public String toString() {
+ public String toString()
+ {
return name;
}
More information about the jboss-cvs-commits
mailing list