Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/AbstractSyncRevisionsIndication.java119
-rw-r--r--plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOPluginProtocolFactory.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionCancelIndication.java66
-rw-r--r--plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionPhase1Indication.java71
-rw-r--r--plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RepositoryTimeIndication.java64
5 files changed, 344 insertions, 0 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/AbstractSyncRevisionsIndication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/AbstractSyncRevisionsIndication.java
new file mode 100644
index 0000000000..f991d97eda
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/AbstractSyncRevisionsIndication.java
@@ -0,0 +1,119 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.internal.net4j.protocol;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.io.CDODataInput;
+import org.eclipse.emf.cdo.common.io.CDODataOutput;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.internal.net4j.bundle.OM;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
+
+import org.eclipse.net4j.util.collection.Pair;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Simon McDuff
+ */
+public abstract class AbstractSyncRevisionsIndication extends CDOReadIndication
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, SyncRevisionsIndication.class);
+
+ protected List<Pair<InternalCDORevision, Long>> dirtyObjects = new ArrayList<Pair<InternalCDORevision, Long>>();
+
+ protected List<Pair<CDOID, Long>> detachedObjects = new ArrayList<Pair<CDOID, Long>>();
+
+ protected int referenceChunk = CDORevision.UNCHUNKED;
+
+ public AbstractSyncRevisionsIndication(CDOServerProtocol protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ @Override
+ protected void indicating(CDODataInput in) throws IOException
+ {
+ referenceChunk = in.readInt();
+ int size = in.readInt();
+ for (int i = 0; i < size; i++)
+ {
+ CDOID id = in.readCDOID();
+ int version = in.readInt();
+ process(id, version);
+ }
+ }
+
+ @Override
+ protected void responding(CDODataOutput out) throws IOException
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Sync found " + dirtyObjects.size() + " dirty objects"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ out.writeInt(dirtyObjects.size());
+ for (Pair<InternalCDORevision, Long> revisionAndOldRevised : dirtyObjects)
+ {
+ out.writeCDORevision(revisionAndOldRevised.getElement1(), referenceChunk);
+ out.writeLong(revisionAndOldRevised.getElement2());
+ }
+
+ out.writeInt(detachedObjects.size());
+ for (Pair<CDOID, Long> idAndRevised : detachedObjects)
+ {
+ out.writeCDOID(idAndRevised.getElement1());
+ out.writeLong(idAndRevised.getElement2());
+ }
+ }
+
+ protected abstract void process(CDOID id, int version);
+
+ protected void udpateObjectList(CDOID id, int version)
+ {
+ try
+ {
+ InternalCDORevision revision = getRepository().getRevisionManager().getRevision(id, referenceChunk);
+ if (revision == null)
+ {
+ detachedObjects.add(new Pair<CDOID, Long>(id, getTimestamp(id, version)));
+ }
+ else if (revision.getVersion() > version || version == CDORevision.UNSPECIFIED_VERSION)
+ {
+ dirtyObjects.add(new Pair<InternalCDORevision, Long>(revision, getTimestamp(id, version)));
+ }
+ else if (revision.getVersion() < version)
+ {
+ throw new IllegalStateException("The object " + revision.getID() + " have a higher version (" //$NON-NLS-1$ //$NON-NLS-2$
+ + revision.getVersion() + ") in the repository than the version (" + version + ") submitted."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ catch (IllegalArgumentException revisionIsNullException)
+ {
+ detachedObjects.add(new Pair<CDOID, Long>(id, getTimestamp(id, version)));
+ }
+ }
+
+ protected long getTimestamp(CDOID id, int version)
+ {
+ CDORevision revision = getRepository().getRevisionManager().getRevisionByVersion(id, 0, version, false);
+ if (revision != null)
+ {
+ return revision.getRevised() + 1;
+ }
+
+ return CDORevision.UNSPECIFIED_DATE;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOPluginProtocolFactory.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOPluginProtocolFactory.java
new file mode 100644
index 0000000000..065bddf441
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CDOPluginProtocolFactory.java
@@ -0,0 +1,24 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.net4j.protocol;
+
+import org.eclipse.emf.cdo.spi.server.PluginRepositoryProvider;
+
+/**
+ * @author Eike Stepper
+ */
+public final class CDOPluginProtocolFactory extends CDOServerProtocolFactory
+{
+ public CDOPluginProtocolFactory()
+ {
+ super(PluginRepositoryProvider.INSTANCE);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionCancelIndication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionCancelIndication.java
new file mode 100644
index 0000000000..35e23e442c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionCancelIndication.java
@@ -0,0 +1,66 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.server.internal.net4j.protocol;
+
+import org.eclipse.emf.cdo.common.io.CDODataInput;
+import org.eclipse.emf.cdo.common.io.CDODataOutput;
+import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
+
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+
+/**
+ * @author Simon McDuff
+ */
+public class CommitTransactionCancelIndication extends CommitTransactionIndication
+{
+ public CommitTransactionCancelIndication(CDOServerProtocol protocol)
+ {
+ super(protocol, CDOProtocolConstants.SIGNAL_COMMIT_TRANSACTION_CANCEL);
+ }
+
+ @Override
+ protected void indicating(CDODataInput in, OMMonitor monitor) throws Exception
+ {
+ indicatingTransaction(in);
+ }
+
+ @Override
+ protected void responding(CDODataOutput out, OMMonitor monitor) throws Exception
+ {
+ String exceptionMessage = null;
+ try
+ {
+ if (commitContext != null)
+ {
+ getRepository().getCommitManager().rollback(commitContext);
+ }
+ }
+ catch (Exception exception)
+ {
+ exceptionMessage = exception.getMessage();
+ }
+
+ if (commitContext != null && exceptionMessage == null)
+ {
+ exceptionMessage = commitContext.getRollbackMessage();
+ }
+
+ respondingException(out, exceptionMessage);
+ }
+
+ @Override
+ protected void indicatingTransaction(CDODataInput in) throws Exception
+ {
+ int viewID = in.readInt();
+ commitContext = getRepository().getCommitManager().get(getTransaction(viewID));
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionPhase1Indication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionPhase1Indication.java
new file mode 100644
index 0000000000..c91fc7fbad
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/CommitTransactionPhase1Indication.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Simon McDuff - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.cdo.server.internal.net4j.protocol;
+
+import org.eclipse.emf.cdo.common.io.CDODataInput;
+import org.eclipse.emf.cdo.common.io.CDODataOutput;
+import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.internal.server.XATransactionCommitContext;
+
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+
+/**
+ * @author Simon McDuff
+ */
+public class CommitTransactionPhase1Indication extends CommitTransactionIndication
+{
+ public CommitTransactionPhase1Indication(CDOServerProtocol protocol)
+ {
+ super(protocol, CDOProtocolConstants.SIGNAL_COMMIT_TRANSACTION_PHASE1);
+ }
+
+ @Override
+ protected void indicatingCommit(OMMonitor monitor)
+ {
+ // Register transactionContext
+ getRepository().getCommitManager().preCommit(commitContext, monitor);
+ }
+
+ @Override
+ protected void responding(CDODataOutput out, OMMonitor monitor) throws Exception
+ {
+ String exceptionMessage = null;
+
+ try
+ {
+ ((XATransactionCommitContext)commitContext).getState().acquire(XATransactionCommitContext.PHASEAPPLYMAPPING);
+ }
+ catch (Throwable ex)
+ {
+ exceptionMessage = ex.getMessage();
+ }
+
+ if (exceptionMessage == null)
+ {
+ exceptionMessage = commitContext.getRollbackMessage();
+ }
+
+ boolean success = respondingException(out, exceptionMessage);
+ if (success)
+ {
+ respondingTimestamp(out);
+ respondingMappingNewObjects(out);
+ }
+ }
+
+ @Override
+ protected void indicatingTransaction(CDODataInput in) throws Exception
+ {
+ int viewID = in.readInt();
+ commitContext = new XATransactionCommitContext(getTransaction(viewID));
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RepositoryTimeIndication.java b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RepositoryTimeIndication.java
new file mode 100644
index 0000000000..cad2d8187c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.net4j/src/org/eclipse/emf/cdo/server/internal/net4j/protocol/RepositoryTimeIndication.java
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.server.internal.net4j.protocol;
+
+import org.eclipse.emf.cdo.common.io.CDODataInput;
+import org.eclipse.emf.cdo.common.io.CDODataOutput;
+import org.eclipse.emf.cdo.common.protocol.CDOProtocolConstants;
+import org.eclipse.emf.cdo.server.internal.net4j.bundle.OM;
+
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class RepositoryTimeIndication extends CDOServerIndication
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, RepositoryTimeIndication.class);
+
+ private long indicated;
+
+ public RepositoryTimeIndication(CDOServerProtocol protocol)
+ {
+ super(protocol, CDOProtocolConstants.SIGNAL_REPOSITORY_TIME);
+ }
+
+ public RepositoryTimeIndication(CDOServerProtocol protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ @Override
+ protected void indicating(CDODataInput in) throws IOException
+ {
+ indicated = System.currentTimeMillis();
+ }
+
+ @Override
+ protected void responding(CDODataOutput out) throws IOException
+ {
+ long responded = System.currentTimeMillis();
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Writing indicated: {0,date} {0,time}", indicated); //$NON-NLS-1$
+ }
+
+ out.writeLong(indicated);
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Writing responded: {0,date} {0,time}", responded); //$NON-NLS-1$
+ }
+
+ out.writeLong(responded);
+ }
+}

Back to the top