[infinispan-commits] Infinispan SVN: r182 - in trunk/gui-demo/src/main: resources and 2 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Apr 27 17:27:18 EDT 2009
Author: manik.surtani at jboss.com
Date: 2009-04-27 17:27:18 -0400 (Mon, 27 Apr 2009)
New Revision: 182
Added:
trunk/gui-demo/src/main/resources/bin/
trunk/gui-demo/src/main/resources/bin/run.sh
trunk/gui-demo/src/main/resources/etc/
trunk/gui-demo/src/main/resources/etc/demo-cache-config.xml
Removed:
trunk/gui-demo/src/main/resources/demo-cache-config.xml
Modified:
trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.form
trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.java
Log:
GUI demo
Modified: trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.form
===================================================================
--- trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.form 2009-04-27 20:53:44 UTC (rev 181)
+++ trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.form 2009-04-27 21:27:18 UTC (rev 182)
@@ -10,7 +10,7 @@
<colspec value="left:4dlu:noGrow"/>
<colspec value="fill:100px:grow"/>
<constraints>
- <xy x="20" y="20" width="918" height="661"/>
+ <xy x="20" y="20" width="1011" height="661"/>
</constraints>
<properties/>
<border type="line" title="Infinipan GUI Demo Application">
@@ -56,6 +56,7 @@
<forms defaultalign-vert="false"/>
</constraints>
<properties>
+ <font style="1"/>
<text value="Command"/>
</properties>
</component>
@@ -74,18 +75,13 @@
<forms defaultalign-vert="false"/>
</constraints>
</vspacer>
- <hspacer id="bfe90">
- <constraints>
- <grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
- <forms defaultalign-horz="false"/>
- </constraints>
- </hspacer>
<component id="458fc" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
<forms defaultalign-vert="false"/>
</constraints>
<properties>
+ <font style="1"/>
<text value="Cache configuration file"/>
</properties>
</component>
@@ -112,13 +108,25 @@
<properties>
<background color="-3355444"/>
<font name="Courier New" size="10"/>
+ <text value=""/>
</properties>
</component>
</children>
</scrollpane>
+ <component id="17832" class="javax.swing.JLabel">
+ <constraints>
+ <grid row="0" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+ <forms/>
+ </constraints>
+ <properties>
+ <font size="12" style="2"/>
+ <text value="Note that you can specify a configuration file to use by passing in -Dinfinispan.demo.cfg=file:/path/to/config.xml"/>
+ </properties>
+ </component>
</children>
</grid>
- <grid id="73867" binding="dataViewTab" layout-manager="BorderLayout" hgap="0" vgap="0">
+ <grid id="73867" binding="dataViewTab" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+ <margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Data view" enabled="false">
<tooltip value="This tab contains a view of all the data in the cache."/>
@@ -130,8 +138,22 @@
</properties>
<border type="none"/>
<children>
+ <component id="c41ff" class="javax.swing.JButton" binding="refreshDataTableButton">
+ <constraints>
+ <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="1" fill="0" indent="0" use-parent-layout="false">
+ <minimum-size width="100" height="20"/>
+ <preferred-size width="100" height="20"/>
+ <maximum-size width="100" height="20"/>
+ </grid>
+ </constraints>
+ <properties>
+ <text value="Refresh"/>
+ </properties>
+ </component>
<scrollpane id="1b795">
- <constraints border-constraint="Center"/>
+ <constraints>
+ <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
+ </constraints>
<properties>
<background color="-16737895"/>
<horizontalScrollBarPolicy value="30"/>
Modified: trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.java
===================================================================
--- trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.java 2009-04-27 20:53:44 UTC (rev 181)
+++ trunk/gui-demo/src/main/java/org/infinispan/demo/InfinispanDemo.java 2009-04-27 21:27:18 UTC (rev 182)
@@ -3,31 +3,37 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.infinispan.Cache;
+import org.infinispan.container.entries.InternalCacheEntry;
import org.infinispan.lifecycle.ComponentStatus;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.notifications.Listener;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryEvicted;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryModified;
+import org.infinispan.notifications.cachelistener.annotation.CacheEntryRemoved;
+import org.infinispan.notifications.cachelistener.event.Event;
import org.infinispan.notifications.cachemanagerlistener.annotation.ViewChanged;
import org.infinispan.notifications.cachemanagerlistener.event.ViewChangedEvent;
-import org.jgroups.Address;
+import org.infinispan.remoting.transport.Address;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Manik Surtani
@@ -68,17 +74,16 @@
private String startCacheButtonLabel = "Start Cache", stopCacheButtonLabel = "Stop Cache";
private String statusStarting = "Starting Cache ... ", statusStarted = "Cache Running.", statusStopping = "Stopping Cache ...", statusStopped = "Cache Stopped.";
private ExecutorService asyncExecutor;
+ private final AtomicInteger updateCounter = new AtomicInteger(0);
private BlockingQueue<Runnable> asyncTaskQueue;
private JTable dataTable;
+ private JButton refreshDataTableButton;
private Random r = new Random();
+ private ClusterTableModel clusterTableModel;
+ private CachedDataTableModel cachedDataTableModel;
public static void main(String[] args) {
- String cfgFileName = "demo-cache-config.xml";
- if (args.length == 1 && args[0] != null && args[0].toLowerCase().endsWith(".xml")) {
- // the first arg is the name of the config file.
- cfgFileName = args[0];
- }
-
+ String cfgFileName = System.getProperty("infinispan.demo.cfg", "etc/demo-cache-config.xml");
frame = new JFrame("Infinispan GUI Demo (STOPPED)");
frame.setContentPane(new InfinispanDemo(cfgFileName).panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -95,6 +100,13 @@
cacheStatusProgressBar.setVisible(false);
cacheStatusProgressBar.setEnabled(false);
configFileName.setText(cacheConfigFile);
+
+ // data tables
+ clusterTableModel = new ClusterTableModel();
+ clusterTable.setModel(clusterTableModel);
+ cachedDataTableModel = new CachedDataTableModel();
+ dataTable.setModel(cachedDataTableModel);
+
// default state of the action button should be unstarted.
actionButton.setText(startCacheButtonLabel);
cacheStatus.setText(statusStopped);
@@ -198,6 +210,20 @@
}
});
+ refreshDataTableButton.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ processAction(refreshDataTableButton, true);
+ asyncExecutor.execute(new Runnable() {
+ public void run() {
+ InfinispanDemo.this.updateCachedDataTable();
+ processAction(refreshDataTableButton, false);
+ // now switch to the data pane
+ mainPane.setSelectedIndex(1);
+ }
+ });
+ }
+ });
+
cacheDetailsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (cache != null) debugTextArea.setText(cache.toString());
@@ -263,31 +289,31 @@
try {
if (cache == null) {
URL resource = getClass().getClassLoader().getResource(cacheConfigFile);
- String contents;
+ if (resource == null) resource = new URL(cacheConfigFile);
// update config file display
- if (resource != null) {
- configFileName.setText(resource.toString());
- } else {
- configFileName.setText(cacheConfigFile);
- }
+ configFileName.setText(resource.toString());
+
configFileName.repaint();
try {
- configFileContents.setText(readContents(resource == null ? new FileInputStream(cacheConfigFile) : resource.openStream()));
+ configFileContents.setText(readContents(resource.openStream()));
configFileContents.setEditable(false);
}
catch (Exception e) {
- log.warn("Unable to open config file for display", e);
+ log.warn("Unable to open config file [" + cacheConfigFile + "] for display", e);
}
configFileContents.repaint();
- cache = new DefaultCacheManager(cacheConfigFile).getCache();
+ cache = new DefaultCacheManager(resource.openStream()).getCache();
} else {
cache.start();
}
-// updateClusterTable(cache.getCacheManager().getMembers());
-// cache.addCacheListener(new CacheListener());
+ CacheListener cl = new CacheListener();
+ cache.addListener(cl);
+ cache.getCacheManager().addListener(cl);
+ updateClusterTable(cache.getCacheManager().getMembers());
+
moveCacheToState(ComponentStatus.RUNNING);
} catch (Exception e) {
log.error("Unable to start cache!", e);
@@ -315,100 +341,82 @@
private void updateClusterTable(List<Address> members) {
log.debug("Updating cluster table with new member list " + members);
-// clusterDataModel.setMembers(members);
+ clusterTableModel.setMembers(members);
updateTitleBar();
}
private void updateTitleBar() {
String title = "Infinispan GUI Demo";
if (cache != null && cache.getStatus() == ComponentStatus.RUNNING) {
- title += " (STARTED) " + cache.getCacheManager().getAddress() + " Cluster size: " + cache.getCacheManager().getMembers().size();
+ title += " (STARTED) " + getLocalAddress() + " Cluster size: " + getClusterSize();
} else {
title += " (STOPPED)";
}
frame.setTitle(title);
}
+ private String getLocalAddress() {
+ Address a = cache.getCacheManager().getAddress();
+ if (a == null) return "(LOCAL mode)";
+ else return a.toString();
+ }
+
+ private String getClusterSize() {
+ List<Address> members = cache.getCacheManager().getMembers();
+ return members == null || members.isEmpty() ? "N/A" : "" + members.size();
+ }
+
@Listener
public class CacheListener {
@ViewChanged
public void viewChangeEvent(ViewChangedEvent e) {
-// updateClusterTable(e.getNewView().getMembers());
+ updateClusterTable(e.getNewMemberList());
}
-// @NodeModified
-// public void nodeModified(NodeModifiedEvent e) {
-// if (!e.isPre()) {
-// // only if this is the current node selected in the tree do we bother refreshing it
-// if (nodeDataTableModel.getCurrentFqn() != null && nodeDataTableModel.getCurrentFqn().equals(e.getFqn())) {
-// nodeDataTableModel.updateCurrentNode();
-// }
-// }
-// }
-//
-// @NodeCreated
-// public void nodeCreated(NodeCreatedEvent e) {
-// if (!e.isPre()) {
-// final Fqn fqn = e.getFqn();
-// asyncExecutor.execute(new Runnable() {
-// public void run() {
-// treeRefresher.addNode(fqn);
-// // only refresh if there are no more tasks queued up
-// if (asyncTaskQueue.isEmpty()) treeRefresher.repaint();
-// }
-// });
-// }
-// }
-//
-//
-// @NodeRemoved
-// public void nodeRemoved(NodeRemovedEvent e) {
-// if (!e.isPre()) {
-// final Fqn fqn = e.getFqn();
-// asyncExecutor.execute(new Runnable() {
-// public void run() {
-// treeRefresher.removeNode(fqn);
-// // only refresh if there are no more tasks queued up
-// if (asyncTaskQueue.isEmpty()) treeRefresher.repaint();
-// }
-// });
-// }
-// }
+ @CacheEntryModified
+ @CacheEntryRemoved
+ @CacheEntryEvicted
+ public void removed(Event e) {
+ if (!e.isPre()) updateCachedDataTable();
+ }
+ }
- // dont bother with node modified events since the tree GUI widget will refresh each node when it is selected.
+ private void updateCachedDataTable() {
+ updateCounter.incrementAndGet();
+ asyncExecutor.execute(new Runnable() {
+ public void run() {
+ if (updateCounter.decrementAndGet() == 0) cachedDataTableModel.update();
+ }
+ });
}
public class ClusterTableModel extends AbstractTableModel {
- List<Address> members = new ArrayList<Address>();
+ List<String> members = new ArrayList<String>();
List<String> memberStates = new ArrayList<String>();
- public void setMembers(List<Address> members) {
- if (this.members != members) {
- this.members.clear();
- this.members.addAll(members);
- }
+ public void setMembers(List<Address> m) {
+ if (m != null && !m.isEmpty()) {
+ members = new ArrayList<String>(m.size());
+ for (Address ma : m) members.add(ma.toString());
- List<Address> buddies = Collections.emptyList();
+ memberStates = new ArrayList<String>(m.size());
+ for (Address a : m) {
+ String extraInfo = "Member";
+ // if this is the first member then this is the coordinator
+ if (memberStates.isEmpty()) extraInfo += " (coord)";
+ if (a.equals(cache.getCacheManager().getAddress()))
+ extraInfo += " (me)";
- memberStates = new ArrayList<String>(members.size());
- for (Address a : members) {
- String extraInfo = "Member";
- // if this is the first member then this is the coordinator
- if (memberStates.isEmpty()) extraInfo += " (coord)";
- if (a.equals(cache.getCacheManager().getAddress()))
- extraInfo += " (me)";
- else if (buddies.contains(a))
- extraInfo += " (buddy)";
- memberStates.add(extraInfo);
+ memberStates.add(extraInfo);
+ }
+ } else {
+ members = Collections.singletonList("me!");
+ memberStates = Collections.singletonList("(local mode)");
}
fireTableDataChanged();
}
- public void setBuddies() {
- setMembers(members);
- }
-
public int getRowCount() {
return members.size();
}
@@ -427,10 +435,94 @@
return "NULL!";
}
+ @Override
public String getColumnName(int c) {
if (c == 0) return "Member Address";
if (c == 1) return "Member Info";
return "NULL!";
}
}
+
+ public class CachedDataTableModel extends AbstractTableModel {
+
+ List<InternalCacheEntry> data = new LinkedList<InternalCacheEntry>();
+
+ public int getRowCount() {
+ return data.size();
+ }
+
+ public int getColumnCount() {
+ return 4;
+ }
+
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ if (data.size() > rowIndex) {
+ InternalCacheEntry e = data.get(rowIndex);
+ switch (columnIndex) {
+ case 0:
+ return e.getKey();
+ case 1:
+ return e.getValue();
+ case 2:
+ return e.getLifespan();
+ case 3:
+ return e.getMaxIdle();
+ }
+ }
+ return "NULL!";
+ }
+
+ @Override
+ public String getColumnName(int c) {
+ switch (c) {
+ case 0:
+ return "Key";
+ case 1:
+ return "Value";
+ case 2:
+ return "Lifespan";
+ case 3:
+ return "MaxIdle";
+ }
+ return "NULL!";
+ }
+
+ public void update() {
+ // whew - expensive stuff.
+ data.clear();
+ for (InternalCacheEntry ice : cache.getAdvancedCache().getDataContainer()) {
+ if (!ice.isExpired()) data.add(ice);
+ }
+ fireTableDataChanged();
+ }
+ }
+
+ class CachedEntry {
+ String key, value;
+ long lifespan = -1, maxIdle = -1;
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CachedEntry that = (CachedEntry) o;
+
+ if (lifespan != that.lifespan) return false;
+ if (maxIdle != that.maxIdle) return false;
+ if (key != null ? !key.equals(that.key) : that.key != null) return false;
+ if (value != null ? !value.equals(that.value) : that.value != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = key != null ? key.hashCode() : 0;
+ result = 31 * result + (value != null ? value.hashCode() : 0);
+ result = 31 * result + (int) (lifespan ^ (lifespan >>> 32));
+ result = 31 * result + (int) (maxIdle ^ (maxIdle >>> 32));
+ return result;
+ }
+ }
}
Added: trunk/gui-demo/src/main/resources/bin/run.sh
===================================================================
--- trunk/gui-demo/src/main/resources/bin/run.sh (rev 0)
+++ trunk/gui-demo/src/main/resources/bin/run.sh 2009-04-27 21:27:18 UTC (rev 182)
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo TODO
Property changes on: trunk/gui-demo/src/main/resources/bin/run.sh
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: trunk/gui-demo/src/main/resources/demo-cache-config.xml
===================================================================
--- trunk/gui-demo/src/main/resources/demo-cache-config.xml 2009-04-27 20:53:44 UTC (rev 181)
+++ trunk/gui-demo/src/main/resources/demo-cache-config.xml 2009-04-27 21:27:18 UTC (rev 182)
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">
- <default/>
-</infinispan>
Copied: trunk/gui-demo/src/main/resources/etc/demo-cache-config.xml (from rev 176, trunk/gui-demo/src/main/resources/demo-cache-config.xml)
===================================================================
--- trunk/gui-demo/src/main/resources/etc/demo-cache-config.xml (rev 0)
+++ trunk/gui-demo/src/main/resources/etc/demo-cache-config.xml 2009-04-27 21:27:18 UTC (rev 182)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">
+ <global>
+ <transport clusterName="demoCluster"/>
+ </global>
+
+ <default>
+ <clustering mode="distribution">
+ <l1 enabled="true" lifespan="10000"/>
+ <hash numOwners="2"/>
+ <sync/>
+ </clustering>
+ </default>
+</infinispan>
Property changes on: trunk/gui-demo/src/main/resources/etc/demo-cache-config.xml
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
More information about the infinispan-commits
mailing list