Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-05-13 15:11:01 +0000
committerEike Stepper2010-05-13 15:11:01 +0000
commit94635de2df59ed7f7b14aee8d7cffd0241fcee24 (patch)
treeeb5546ce6fa6e070bda00057635a777a463fdcac /plugins/org.eclipse.emf.cdo.examples.server
parentf6dbb81f4ff5e49fc774cd96430df9f1bc6e8457 (diff)
downloadcdo-94635de2df59ed7f7b14aee8d7cffd0241fcee24.tar.gz
cdo-94635de2df59ed7f7b14aee8d7cffd0241fcee24.tar.xz
cdo-94635de2df59ed7f7b14aee8d7cffd0241fcee24.zip
vserver
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.examples.server')
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/ConfigOverview.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/RequestForm.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/ConfigOverviewServlet.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoConfiguration.java27
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoServer.java63
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.server/templates/configOverview.htmljet14
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.server/templates/requestForm.htmljet5
7 files changed, 123 insertions, 35 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/ConfigOverview.java b/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/ConfigOverview.java
index 1d32933a95..ad7f9190ea 100644
--- a/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/ConfigOverview.java
+++ b/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/ConfigOverview.java
@@ -16,43 +16,52 @@ public class ConfigOverview
public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
protected final String TEXT_1 = "";
- protected final String TEXT_2 = NL + NL + "<html>" + NL + " <header>" + NL + "\t <title>" + NL + "\t\t\t";
- protected final String TEXT_3 = NL + "\t </title>" + NL + "\t\t<link media=\"screen\" href=\"gastro.css\" type=\"text/css\" rel=\"stylesheet\">" + NL + "\t<header>" + NL + "<body>" + NL + "" + NL + "<h1>";
- protected final String TEXT_4 = "</h1>" + NL + "" + NL + "<table border=\"0\" width=\"400\">" + NL + "\t<tr><td>Mode:</td><td>";
- protected final String TEXT_5 = "</td></tr>" + NL + "\t<tr><td>User IDs:</td><td>" + NL + "\t";
- protected final String TEXT_6 = NL + "\t\t\t";
- protected final String TEXT_7 = ": ";
- protected final String TEXT_8 = "<br>";
- protected final String TEXT_9 = NL + "\t\t</td></tr>" + NL + "</table>" + NL + "" + NL + "</body>" + NL + "</html>";
- protected final String TEXT_10 = NL;
+ protected final String TEXT_2 = NL + NL + "<html>" + NL + " <header>" + NL + "\t <title>" + NL + "\t\t\tDemo Configuration ";
+ protected final String TEXT_3 = NL + "\t </title>" + NL + "\t\t<link media=\"screen\" href=\"demo-server.css\" type=\"text/css\" rel=\"stylesheet\">" + NL + "\t<header>" + NL + "<body>" + NL + "" + NL + "<h1>Demo Configuration</h1>" + NL + "<hr>" + NL + "" + NL + "<table border=\"0\" width=\"400\">" + NL + "\t<tr><td>Server:</td><td><b>tcp://cdo.eclipse.org:";
+ protected final String TEXT_4 = "</b></td></tr>" + NL + "\t<tr><td>Repository:</td><td><b>";
+ protected final String TEXT_5 = "</b></td></tr>" + NL + "\t<tr><td>Mode:</td><td>";
+ protected final String TEXT_6 = "</td></tr>" + NL + "\t<tr><td>User IDs:</td><td>" + NL + "\t";
+ protected final String TEXT_7 = NL + "\t\t\t";
+ protected final String TEXT_8 = ": ";
+ protected final String TEXT_9 = "<br>";
+ protected final String TEXT_10 = NL + "\t\t</td></tr>" + NL + "\t</td></tr>" + NL + "\t<tr><td>Idle Time:</td><td>";
+ protected final String TEXT_11 = "</td></tr>" + NL + "\t<tr><td>&nbsp;</td><td><a href=\"?name=";
+ protected final String TEXT_12 = "\">Refresh Page</a></td></tr>" + NL + "</table>" + NL + "" + NL + "</body>" + NL + "</html>";
+ protected final String TEXT_13 = NL;
public String generate(Object argument)
{
final StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(TEXT_1);
DemoConfiguration config = (DemoConfiguration)argument;
- String title = "Demo Configuration " + AbstractTemplateServlet.html(config.getName());
+ String name = config.getName();
stringBuffer.append(TEXT_2);
- stringBuffer.append(title);
+ stringBuffer.append(name);
stringBuffer.append(TEXT_3);
- stringBuffer.append(title);
+ stringBuffer.append(DemoServer.PORT);
stringBuffer.append(TEXT_4);
- stringBuffer.append(AbstractTemplateServlet.html(config.getMode().toString()));
+ stringBuffer.append(name);
stringBuffer.append(TEXT_5);
+ stringBuffer.append(AbstractTemplateServlet.html(config.getMode().toString()));
+ stringBuffer.append(TEXT_6);
Map<String, char[]> users = config.getUsers();
List<String> userIDs = new ArrayList<String>(users.keySet());
Collections.sort(userIDs);
for (String userID : userIDs)
{
- stringBuffer.append(TEXT_6);
- stringBuffer.append(userID);
stringBuffer.append(TEXT_7);
- stringBuffer.append(users.get(userID));
+ stringBuffer.append(userID);
stringBuffer.append(TEXT_8);
- }
+ stringBuffer.append(users.get(userID));
stringBuffer.append(TEXT_9);
+ }
stringBuffer.append(TEXT_10);
+ stringBuffer.append(AbstractTemplateServlet.html(config.formatIdleTime()));
+ stringBuffer.append(TEXT_11);
+ stringBuffer.append(name);
+ stringBuffer.append(TEXT_12);
+ stringBuffer.append(TEXT_13);
return stringBuffer.toString();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/RequestForm.java b/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/RequestForm.java
index 814a8026d4..555b2f31e1 100644
--- a/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/RequestForm.java
+++ b/plugins/org.eclipse.emf.cdo.examples.server/src-gen/templates/RequestForm.java
@@ -12,7 +12,7 @@ public class RequestForm
}
public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
- protected final String TEXT_1 = NL + "<html>" + NL + " <header>" + NL + "\t <title>" + NL + "\t\t\tDemo Request Form" + NL + "\t </title>" + NL + "\t\t<link media=\"screen\" href=\"demo-server.css\" type=\"text/css\" rel=\"stylesheet\">" + NL + "\t<header>" + NL + "<body>" + NL + "" + NL + "<h1>Demo Request Form</h1>" + NL + "" + NL + "<form method=\"post\" action=\"configOverview.html\">" + NL + "\t<table border=\"0\">" + NL + "\t\t<tr><td>Mode:</td><td><select name=\"mode\"><option>NORMAL</option><option>AUDITING</option><option>BRANCHING</option></select></td></tr>" + NL + "\t\t<tr><td>User IDs:</td><td><input name=\"userIDs\" type=\"input\"></input></td></tr>" + NL + "\t\t<tr><td>&nbsp;</td><td><input name=\"submit\" type=\"submit\">Submit Request</input></td></tr>" + NL + "\t</table>" + NL + "</form>" + NL + "" + NL + "</body>" + NL + "</html>";
+ protected final String TEXT_1 = NL + "<html>" + NL + " <header>" + NL + "\t <title>" + NL + "\t\t\tDemo Request Form" + NL + "\t </title>" + NL + "\t\t<link media=\"screen\" href=\"demo-server.css\" type=\"text/css\" rel=\"stylesheet\">" + NL + "\t<header>" + NL + "<body>" + NL + "" + NL + "<h1>Demo Request Form</h1>" + NL + "<hr>" + NL + "" + NL + "<form method=\"post\" action=\"configOverview.html\">" + NL + "\t<table border=\"0\">" + NL + "\t\t<tr><td>Mode:</td><td><select name=\"mode\"><option>NORMAL</option><option>AUDITING</option><option>BRANCHING</option></select></td></tr>" + NL + "\t\t<!--<tr><td>User IDs:</td><td><input name=\"userIDs\" type=\"input\"/></td></tr>-->" + NL + "\t\t<tr><td>&nbsp;</td><td><input name=\"submit\" type=\"submit\"/></td></tr>" + NL + "\t</table>" + NL + "</form>" + NL + "" + NL + "</body>" + NL + "</html>";
protected final String TEXT_2 = NL;
public String generate(Object argument)
diff --git a/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/ConfigOverviewServlet.java b/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/ConfigOverviewServlet.java
index 3e0de625c5..b16daa5a0e 100644
--- a/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/ConfigOverviewServlet.java
+++ b/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/ConfigOverviewServlet.java
@@ -56,13 +56,13 @@ public class ConfigOverviewServlet extends AbstractTemplateServlet<DemoConfigura
}
config.activate();
- DemoServer.INSTANCE.getConfigs().put(config.getName(), config);
+ DemoServer.INSTANCE.addConfig(config);
return config;
}
protected DemoConfiguration getDemoConfiguration(String name)
{
- DemoConfiguration config = DemoServer.INSTANCE.getConfigs().get(name);
+ DemoConfiguration config = DemoServer.INSTANCE.getConfig(name);
if (config == null)
{
throw new IllegalStateException("No demo configuration available for " + name);
diff --git a/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoConfiguration.java b/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoConfiguration.java
index f7361334e2..e58b7208cf 100644
--- a/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoConfiguration.java
+++ b/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoConfiguration.java
@@ -29,6 +29,7 @@ import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.Lifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.security.IUserManager;
@@ -38,6 +39,8 @@ import org.h2.jdbcx.JdbcDataSource;
import javax.sql.DataSource;
+import java.io.File;
+import java.text.MessageFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -48,7 +51,7 @@ import java.util.Random;
*/
public class DemoConfiguration extends Lifecycle
{
- private static final int NAME_LENGTH = 8;
+ private static final int NAME_LENGTH = 10;
private static final String NAME_ALPHABET = "abcdefghijklmnopqrstuvwxyz";
@@ -62,7 +65,7 @@ public class DemoConfiguration extends Lifecycle
private DemoUserManager userManager;
- private transient long lastAccess;
+ private transient long lastAccess = System.currentTimeMillis();
public DemoConfiguration()
{
@@ -121,9 +124,14 @@ public class DemoConfiguration extends Lifecycle
return userManager.getUsers();
}
- public long getLastAccess()
+ public synchronized long getIdleTime()
{
- return lastAccess;
+ return System.currentTimeMillis() - lastAccess;
+ }
+
+ public String formatIdleTime()
+ {
+ return MessageFormat.format("{0,time,mm:ss}", getIdleTime());
}
@Override
@@ -156,15 +164,19 @@ public class DemoConfiguration extends Lifecycle
{
if (repository != null)
{
+ File folder = new File(new File("databases"), repository.getName());
+
LifecycleUtil.deactivate(repository);
repository = null;
+
+ IOUtil.delete(folder);
}
}
protected String createRandomName()
{
Random random = new Random(System.currentTimeMillis());
- StringBuilder builder = new StringBuilder("repo_");
+ StringBuilder builder = new StringBuilder();
for (int i = 0; i < NAME_LENGTH; i++)
{
int pos = random.nextInt(NAME_ALPHABET.length());
@@ -221,7 +233,10 @@ public class DemoConfiguration extends Lifecycle
{
public void notifyEvent(IEvent event)
{
- lastAccess = System.currentTimeMillis();
+ synchronized (DemoConfiguration.this)
+ {
+ lastAccess = System.currentTimeMillis();
+ }
}
});
}
diff --git a/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoServer.java b/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoServer.java
index 404dfcdf94..7c4f0d604b 100644
--- a/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoServer.java
+++ b/plugins/org.eclipse.emf.cdo.examples.server/src/org/eclipse/emf/cdo/examples/server/DemoServer.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.examples.server;
import org.eclipse.net4j.acceptor.IAcceptor;
import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.concurrent.Worker;
import org.eclipse.net4j.util.container.IPluginContainer;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMPlatform;
@@ -32,12 +33,16 @@ public class DemoServer extends OSGiApplication
public static final int PORT = 3003;
+ public static final long MAX_IDLE_TIME = 2 * 60 * 1000;
+
public static DemoServer INSTANCE;
private IAcceptor acceptor;
private Map<String, DemoConfiguration> configs = new HashMap<String, DemoConfiguration>();
+ private Cleaner cleaner = new Cleaner();
+
public DemoServer()
{
super(ID);
@@ -49,9 +54,20 @@ public class DemoServer extends OSGiApplication
return acceptor;
}
- public Map<String, DemoConfiguration> getConfigs()
+ public DemoConfiguration getConfig(String name)
+ {
+ synchronized (configs)
+ {
+ return configs.get(name);
+ }
+ }
+
+ public void addConfig(DemoConfiguration config)
{
- return configs;
+ synchronized (configs)
+ {
+ configs.put(config.getName(), config);
+ }
}
@Override
@@ -70,6 +86,7 @@ public class DemoServer extends OSGiApplication
container.getElement("org.eclipse.emf.cdo.server.db.browsers", "default", port); //$NON-NLS-1$ //$NON-NLS-2$
}
+ cleaner.activate();
OM.LOG.info("Demo server started");
}
@@ -77,7 +94,9 @@ public class DemoServer extends OSGiApplication
protected void doStop() throws Exception
{
OM.LOG.info("Demo server stopping");
- for (DemoConfiguration config : configs.values().toArray(new DemoConfiguration[configs.size()]))
+ cleaner.deactivate();
+
+ for (DemoConfiguration config : getConfigs())
{
config.deactivate();
}
@@ -93,4 +112,42 @@ public class DemoServer extends OSGiApplication
OM.LOG.info("Demo server stopped");
super.doStop();
}
+
+ protected DemoConfiguration[] getConfigs()
+ {
+ synchronized (configs)
+ {
+ return configs.values().toArray(new DemoConfiguration[configs.size()]);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class Cleaner extends Worker
+ {
+ @Override
+ protected void work(WorkContext context) throws Exception
+ {
+ for (DemoConfiguration config : getConfigs())
+ {
+ cleanIfNeeded(config);
+ }
+
+ context.nextWork(2000L);
+ }
+
+ protected void cleanIfNeeded(DemoConfiguration config)
+ {
+ if (config.getIdleTime() > MAX_IDLE_TIME)
+ {
+ synchronized (configs)
+ {
+ configs.remove(config.getName());
+ }
+
+ config.deactivate();
+ }
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.examples.server/templates/configOverview.htmljet b/plugins/org.eclipse.emf.cdo.examples.server/templates/configOverview.htmljet
index e14b9639bc..ee89f0a882 100644
--- a/plugins/org.eclipse.emf.cdo.examples.server/templates/configOverview.htmljet
+++ b/plugins/org.eclipse.emf.cdo.examples.server/templates/configOverview.htmljet
@@ -4,20 +4,23 @@
imports="java.util.* org.eclipse.emf.cdo.examples.server.*" %>
<% DemoConfiguration config = (DemoConfiguration)argument; %>
-<% String title = "Demo Configuration " + AbstractTemplateServlet.html(config.getName()); %>
+<% String name = config.getName(); %>
<html>
<header>
<title>
- <%=title%>
+ Demo Configuration <%=name%>
</title>
- <link media="screen" href="gastro.css" type="text/css" rel="stylesheet">
+ <link media="screen" href="demo-server.css" type="text/css" rel="stylesheet">
<header>
<body>
-<h1><%=title%></h1>
+<h1>Demo Configuration</h1>
+<hr>
<table border="0" width="400">
+ <tr><td>Server:</td><td><b>tcp://cdo.eclipse.org:<%=DemoServer.PORT%></b></td></tr>
+ <tr><td>Repository:</td><td><b><%=name%></b></td></tr>
<tr><td>Mode:</td><td><%=AbstractTemplateServlet.html(config.getMode().toString())%></td></tr>
<tr><td>User IDs:</td><td>
<%
@@ -29,6 +32,9 @@
<%=userID%>: <%=users.get(userID)%><br>
<% } %>
</td></tr>
+ </td></tr>
+ <tr><td>Idle Time:</td><td><%=AbstractTemplateServlet.html(config.formatIdleTime())%></td></tr>
+ <tr><td>&nbsp;</td><td><a href="?name=<%=name%>">Refresh Page</a></td></tr>
</table>
</body>
diff --git a/plugins/org.eclipse.emf.cdo.examples.server/templates/requestForm.htmljet b/plugins/org.eclipse.emf.cdo.examples.server/templates/requestForm.htmljet
index 583558eac9..f773f1469b 100644
--- a/plugins/org.eclipse.emf.cdo.examples.server/templates/requestForm.htmljet
+++ b/plugins/org.eclipse.emf.cdo.examples.server/templates/requestForm.htmljet
@@ -12,12 +12,13 @@
<body>
<h1>Demo Request Form</h1>
+<hr>
<form method="post" action="configOverview.html">
<table border="0">
<tr><td>Mode:</td><td><select name="mode"><option>NORMAL</option><option>AUDITING</option><option>BRANCHING</option></select></td></tr>
- <tr><td>User IDs:</td><td><input name="userIDs" type="input"></input></td></tr>
- <tr><td>&nbsp;</td><td><input name="submit" type="submit">Submit Request</input></td></tr>
+ <!--<tr><td>User IDs:</td><td><input name="userIDs" type="input"/></td></tr>-->
+ <tr><td>&nbsp;</td><td><input name="submit" type="submit"/></td></tr>
</table>
</form>

Back to the top