Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-08-18 02:24:31 +0000
committerCaspar De Groot2011-08-18 02:24:31 +0000
commitb7e84a0e190445f303dc8fa918cd5a7c6c0670f6 (patch)
tree776782d6099f9228e8764ce57b692914e9b80812 /plugins/org.eclipse.emf.cdo.examples/src
parent8c9b3bb2192a53b7ee1eff6035462f04c20ba842 (diff)
downloadcdo-b7e84a0e190445f303dc8fa918cd5a7c6c0670f6.tar.gz
cdo-b7e84a0e190445f303dc8fa918cd5a7c6c0670f6.tar.xz
cdo-b7e84a0e190445f303dc8fa918cd5a7c6c0670f6.zip
[353691] Add lock notifications and lock caching
https://bugs.eclipse.org/bugs/show_bug.cgi?id=353691
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.examples/src')
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/AbstractOfflineExampleServer.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleClient.java77
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleMaster.java8
3 files changed, 87 insertions, 14 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/AbstractOfflineExampleServer.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/AbstractOfflineExampleServer.java
index ac775d09de..c7f3f649dd 100644
--- a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/AbstractOfflineExampleServer.java
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/AbstractOfflineExampleServer.java
@@ -124,10 +124,10 @@ public abstract class AbstractOfflineExampleServer
{
for (;;)
{
- // System.out.println();
- // System.out.println("Enter a command:");
- // showMenu();
- // System.out.println();
+ System.out.println();
+ System.out.println("Enter a command:");
+ showMenu();
+ System.out.println();
String command = new BufferedReader(new InputStreamReader(System.in)).readLine();
if (handleCommand(command))
@@ -144,6 +144,14 @@ public abstract class AbstractOfflineExampleServer
container.deactivate();
}
+ protected void showMenu()
+ {
+ System.out.println("0 - exit");
+ System.out.println("1 - connect repository to network");
+ System.out.println("2 - disconnect repository from network");
+ System.out.println("3 - dump repository infos");
+ }
+
protected boolean handleCommand(String command)
{
if ("1".equals(command))
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleClient.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleClient.java
index a8a448486d..52d10208c5 100644
--- a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleClient.java
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleClient.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.emf.cdo.examples.server.offline;
+import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.common.CDOCommonRepository;
import org.eclipse.emf.cdo.common.CDOCommonRepository.State;
import org.eclipse.emf.cdo.common.branch.CDOBranch;
@@ -21,6 +22,7 @@ import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration;
import org.eclipse.emf.cdo.net4j.CDONet4jUtil;
import org.eclipse.emf.cdo.session.CDORepositoryInfo;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
+import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.cdo.util.CommitException;
import org.eclipse.net4j.Net4jUtil;
@@ -28,7 +30,10 @@ import org.eclipse.net4j.connector.IConnector;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.event.IEvent;
import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.spi.cdo.DefaultCDOMerger;
import java.io.BufferedReader;
@@ -67,6 +72,42 @@ public class OfflineExampleClient
}
}
+ private static void lockObject(CDOTransaction tx)
+ {
+ EList<EObject> contents = tx.getOrCreateResource("/r1").getContents();
+ int size = contents.size();
+ if (size < 1)
+ {
+ System.out.println("There are no objects; can't lock anything.");
+ }
+
+ System.out.println("Locking last object");
+ CDOObject firstObject = CDOUtil.getCDOObject(contents.get(size - 1));
+ firstObject.cdoWriteLock().lock();
+ System.out.println("Locked last object");
+ }
+
+ private static void unlockObject(CDOTransaction tx)
+ {
+ EList<EObject> contents = tx.getOrCreateResource("/r1").getContents();
+ int size = contents.size();
+ if (size < 1)
+ {
+ System.out.println("There are no objects; can't lock anything.");
+ }
+
+ System.out.println("Unlocking last object");
+ CDOObject firstObject = CDOUtil.getCDOObject(contents.get(size - 1));
+ firstObject.cdoWriteLock().unlock();
+ System.out.println("Unlocked last object");
+ }
+
+ private static void createBranch(CDOTransaction tx)
+ {
+ CDOBranch subBranch = tx.getBranch().createBranch("sub.1");
+ tx.setBranch(subBranch);
+ }
+
private static boolean isAutoMerge(String[] args)
{
for (int i = 0; i < args.length; i++)
@@ -150,12 +191,44 @@ public class OfflineExampleClient
System.out.println("Connected to " + repositoryInfo.getName());
tx = session.openTransaction();
+ tx.enableDurableLocking(true);
createSessionListener(session, autoMerging);
for (;;)
{
- new BufferedReader(new InputStreamReader(System.in)).readLine();
- addObject(tx);
+ System.out.println();
+ System.out.println("Enter a command:");
+ System.out.println("0 - exit");
+ System.out.println("1 - add an object to the repository");
+ System.out.println("2 - lock the last object in the repository");
+ System.out.println("3 - unlock the last object in the repository");
+ System.out.println("4 - create a branch");
+
+ String command = new BufferedReader(new InputStreamReader(System.in)).readLine();
+ if ("0".equals(command))
+ {
+ break;
+ }
+
+ if ("1".equals(command))
+ {
+ addObject(tx);
+ }
+ else if ("2".equals(command))
+ {
+ lockObject(tx);
+ }
+ else if ("3".equals(command))
+ {
+ unlockObject(tx);
+ }
+ else if ("4".equals(command))
+ {
+ createBranch(tx);
+ }
}
+
+ session.close();
+ LifecycleUtil.deactivate(container);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleMaster.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleMaster.java
index 20dcd4bba8..6147a90d7f 100644
--- a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleMaster.java
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/server/offline/OfflineExampleMaster.java
@@ -40,14 +40,6 @@ public class OfflineExampleMaster extends AbstractOfflineExampleServer
return CDOServerUtil.createRepository(name, store, props);
}
- protected void showMenu()
- {
- System.out.println("0 - exit");
- System.out.println("1 - connect repository to network");
- System.out.println("2 - disconnect repository from network");
- System.out.println("3 - dump repository infos");
- }
-
public static void main(String[] args) throws Exception
{
System.out.println("Master repository starting...");

Back to the top