Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2009-05-07 17:33:17 +0000
committerEike Stepper2009-05-07 17:33:17 +0000
commit00a2ce617eaae732d37fd06c4bb44090d706879a (patch)
tree84afcec6f2d8637b6780b6f22d41fcd6bdfee044
parent176aef0032ab63b9a8e69ee7e961bdb93de2c30f (diff)
downloadcdo-00a2ce617eaae732d37fd06c4bb44090d706879a.tar.gz
cdo-00a2ce617eaae732d37fd06c4bb44090d706879a.tar.xz
cdo-00a2ce617eaae732d37fd06c4bb44090d706879a.zip
[275323] EMF ClassifierIDs must not leave the JVM
https://bugs.eclipse.org/bugs/show_bug.cgi?id=275323
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOClassifierRef.java34
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/AbstractCDORevision.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java14
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/CDOClientProtocol.java8
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/StringCompressor.java111
6 files changed, 138 insertions, 86 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOClassifierRef.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOClassifierRef.java
index beb56a43d4..04659b98fe 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOClassifierRef.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/CDOClassifierRef.java
@@ -21,16 +21,16 @@ import java.io.IOException;
import java.text.MessageFormat;
/**
- * TODO Optimize transfer of EClassRef instances
- *
* @author Eike Stepper
* @since 2.0
*/
public final class CDOClassifierRef
{
+ public static final String URI_SEPARATOR = "#"; //$NON-NLS-1$
+
private String packageURI;
- private int classifierID;
+ private String classifierName;
public CDOClassifierRef()
{
@@ -38,25 +38,31 @@ public final class CDOClassifierRef
public CDOClassifierRef(EClassifier classifier)
{
- this(classifier.getEPackage().getNsURI(), classifier.getClassifierID());
+ this(classifier.getEPackage().getNsURI(), classifier.getName());
}
- public CDOClassifierRef(String packageURI, int classifierID)
+ public CDOClassifierRef(String packageURI, String classifierName)
{
this.packageURI = packageURI;
- this.classifierID = classifierID;
+ this.classifierName = classifierName;
}
public CDOClassifierRef(CDODataInput in) throws IOException
{
- packageURI = in.readCDOPackageURI();
- classifierID = in.readInt();
+ String uri = in.readCDOPackageURI();
+ int hash = uri.lastIndexOf(URI_SEPARATOR);
+ if (hash == -1)
+ {
+ throw new IOException("Invalid classifier URI: " + uri); //$NON-NLS-1$
+ }
+
+ packageURI = uri.substring(0, hash);
+ classifierName = uri.substring(hash + 1);
}
public void write(CDODataOutput out) throws IOException
{
- out.writeCDOPackageURI(packageURI);
- out.writeInt(classifierID);
+ out.writeCDOPackageURI(packageURI + URI_SEPARATOR + classifierName);
}
public String getPackageURI()
@@ -64,9 +70,9 @@ public final class CDOClassifierRef
return packageURI;
}
- public int getClassifierID()
+ public String getClassifierName()
{
- return classifierID;
+ return classifierName;
}
public EClassifier resolve(EPackage.Registry packageRegistry)
@@ -77,12 +83,12 @@ public final class CDOClassifierRef
throw new IllegalStateException(MessageFormat.format(Messages.getString("CDOClassifierRef.0"), packageURI)); //$NON-NLS-1$
}
- return EMFUtil.getClassifier(ePackage, classifierID);
+ return ePackage.getEClassifier(classifierName);
}
@Override
public String toString()
{
- return MessageFormat.format("CDOClassifierRef({0}, {1})", packageURI, classifierID); //$NON-NLS-1$
+ return MessageFormat.format("CDOClassifierRef({0}, {1})", packageURI, classifierName); //$NON-NLS-1$
}
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
index 592e2fed85..3d4ec483cf 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/model/EMFUtil.java
@@ -82,20 +82,6 @@ public final class EMFUtil
return array;
}
- public static EClassifier getClassifier(EPackage ePackage, int classifierID)
- {
- EList<EClassifier> classifiers = ePackage.getEClassifiers();
- for (EClassifier classifier : classifiers)
- {
- if (classifier.getClassifierID() == classifierID)
- {
- return classifier;
- }
- }
-
- return null;
- }
-
public static EPackage getTopLevelPackage(EPackage ePackage)
{
EPackage superPackage = ePackage.getESuperPackage();
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/AbstractCDORevision.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/AbstractCDORevision.java
index 377cc2f54a..0071370f1f 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/AbstractCDORevision.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/spi/common/revision/AbstractCDORevision.java
@@ -4,7 +4,7 @@
* 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
* Simon McDuff - http://bugs.eclipse.org/201266
@@ -37,6 +37,7 @@ import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.om.trace.PerfTracer;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -56,7 +57,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
private static final PerfTracer WRITING = new PerfTracer(OM.PERF_REVISION_WRITING, AbstractCDORevision.class);
- private CDOClassInfo classAdapter;
+ private CDOClassInfo classInfo;
private CDOID id;
@@ -84,7 +85,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
throw new IllegalArgumentException(Messages.getString("AbstractCDORevision.1")); //$NON-NLS-1$
}
- classAdapter = CDOModelUtil.getClassInfo(eClass);
+ classInfo = CDOModelUtil.getClassInfo(eClass);
this.id = id;
version = 0;
created = UNSPECIFIED_DATE;
@@ -92,12 +93,12 @@ public abstract class AbstractCDORevision implements InternalCDORevision
resourceID = CDOID.NULL;
containerID = CDOID.NULL;
containingFeatureID = 0;
- initValues(classAdapter.getAllPersistentFeatures());
+ initValues(classInfo.getAllPersistentFeatures());
}
public AbstractCDORevision(AbstractCDORevision source)
{
- classAdapter = source.classAdapter;
+ classInfo = source.classInfo;
id = source.id;
version = source.version;
created = source.created;
@@ -110,7 +111,8 @@ public abstract class AbstractCDORevision implements InternalCDORevision
public AbstractCDORevision(CDODataInput in) throws IOException
{
READING.start(this);
- classAdapter = CDOModelUtil.getClassInfo((EClass)in.readCDOClassifierRefAndResolve());
+ EClassifier classifier = in.readCDOClassifierRefAndResolve();
+ classInfo = CDOModelUtil.getClassInfo((EClass)classifier);
id = in.readCDOID();
version = in.readInt();
@@ -137,13 +139,14 @@ public abstract class AbstractCDORevision implements InternalCDORevision
public void write(CDODataOutput out, int referenceChunk) throws IOException
{
- CDOClassifierRef classRef = new CDOClassifierRef(getEClass());
+ EClass eClass = getEClass();
+ CDOClassifierRef classRef = new CDOClassifierRef(eClass);
if (TRACER.isEnabled())
{
TRACER
.format(
"Writing revision: ID={0}, className={1}, version={2}, created={3}, revised={4}, resource={5}, container={6}, featureID={7}", //$NON-NLS-1$
- id, getEClass().getName(), getVersion(), created, revised, resourceID, containerID, containingFeatureID);
+ id, eClass.getName(), getVersion(), created, revised, resourceID, containerID, containingFeatureID);
}
WRITING.start(this);
@@ -166,7 +169,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
public EClass getEClass()
{
- return classAdapter.getEClass();
+ return classInfo.getEClass();
}
public CDOID getID()
@@ -272,17 +275,17 @@ public abstract class AbstractCDORevision implements InternalCDORevision
public boolean isResourceNode()
{
- return classAdapter.isResourceNode();
+ return classInfo.isResourceNode();
}
public boolean isResourceFolder()
{
- return classAdapter.isResourceFolder();
+ return classInfo.isResourceFolder();
}
public boolean isResource()
{
- return classAdapter.isResource();
+ return classInfo.isResource();
}
public CDORevisionData data()
@@ -476,7 +479,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
resourceID = (CDOID)revisionAdjuster.adjustReference(resourceID);
containerID = revisionAdjuster.adjustReference(containerID);
- EStructuralFeature[] features = classAdapter.getAllPersistentFeatures();
+ EStructuralFeature[] features = classInfo.getAllPersistentFeatures();
for (int i = 0; i < features.length; i++)
{
EStructuralFeature feature = features[i];
@@ -537,13 +540,13 @@ public abstract class AbstractCDORevision implements InternalCDORevision
protected Object basicGet(EStructuralFeature feature)
{
- int featureIndex = classAdapter.getFeatureIndex(feature);
+ int featureIndex = classInfo.getFeatureIndex(feature);
return getValue(featureIndex);
}
protected Object basicSet(EStructuralFeature feature, Object value)
{
- int featureIndex = classAdapter.getFeatureIndex(feature);
+ int featureIndex = classInfo.getFeatureIndex(feature);
try
{
@@ -554,7 +557,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
catch (ArrayIndexOutOfBoundsException ex)
{
throw new IllegalArgumentException(MessageFormat.format(
- Messages.getString("AbstractCDORevision.20"), feature, classAdapter), ex); //$NON-NLS-1$
+ Messages.getString("AbstractCDORevision.20"), feature, classInfo), ex); //$NON-NLS-1$
}
}
@@ -565,7 +568,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
public CDOList getList(EStructuralFeature feature, int size)
{
- int featureIndex = classAdapter.getFeatureIndex(feature);
+ int featureIndex = classInfo.getFeatureIndex(feature);
CDOList list = (CDOList)getValue(featureIndex);
if (list == null && size != -1)
{
@@ -578,7 +581,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
public void setList(EStructuralFeature feature, InternalCDOList list)
{
- int featureIndex = classAdapter.getFeatureIndex(feature);
+ int featureIndex = classInfo.getFeatureIndex(feature);
setValue(featureIndex, list);
}
@@ -604,7 +607,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
private void readValues(CDODataInput in) throws IOException
{
- EStructuralFeature[] features = classAdapter.getAllPersistentFeatures();
+ EStructuralFeature[] features = classInfo.getAllPersistentFeatures();
initValues(features);
for (int i = 0; i < features.length; i++)
{
@@ -626,7 +629,7 @@ public abstract class AbstractCDORevision implements InternalCDORevision
private void writeValues(CDODataOutput out, int referenceChunk) throws IOException
{
- EStructuralFeature[] features = classAdapter.getAllPersistentFeatures();
+ EStructuralFeature[] features = classInfo.getAllPersistentFeatures();
for (int i = 0; i < features.length; i++)
{
EStructuralFeature feature = features[i];
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
index 80a77354bc..9d33a40a97 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
@@ -4,12 +4,12 @@
* 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
- * Simon McDuff - http://bugs.eclipse.org/233273
- * Simon McDuff - http://bugs.eclipse.org/230832
- * Simon McDuff - http://bugs.eclipse.org/233490
+ * Simon McDuff - http://bugs.eclipse.org/233273
+ * Simon McDuff - http://bugs.eclipse.org/230832
+ * Simon McDuff - http://bugs.eclipse.org/233490
* Simon McDuff - http://bugs.eclipse.org/213402
*/
package org.eclipse.emf.cdo.internal.server.protocol;
@@ -19,7 +19,6 @@ import org.eclipse.emf.cdo.internal.common.protocol.CDOProtocolImpl;
import org.eclipse.emf.cdo.server.IRepositoryProvider;
import org.eclipse.net4j.signal.SignalReactor;
-import org.eclipse.net4j.util.io.StringCompressor;
import org.eclipse.net4j.util.io.StringIO;
/**
@@ -29,7 +28,10 @@ public class CDOServerProtocol extends CDOProtocolImpl
{
private IRepositoryProvider repositoryProvider;
- private StringCompressor packageURICompressor = new StringCompressor(false);
+ private StringIO packageURICompressor = StringIO.DIRECT;
+
+ // XXX Enable compression again!
+ // private StringIO packageURICompressor = new StringCompressor(false);
public CDOServerProtocol(IRepositoryProvider repositoryProvider)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/CDOClientProtocol.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/CDOClientProtocol.java
index 784ba521fa..a3f636aade 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/CDOClientProtocol.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/net4j/protocol/CDOClientProtocol.java
@@ -4,7 +4,7 @@
* 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
**************************************************************************/
@@ -33,7 +33,6 @@ import org.eclipse.net4j.signal.RequestWithConfirmation;
import org.eclipse.net4j.signal.SignalReactor;
import org.eclipse.net4j.util.WrappedException;
import org.eclipse.net4j.util.concurrent.RWLockManager.LockType;
-import org.eclipse.net4j.util.io.StringCompressor;
import org.eclipse.net4j.util.io.StringIO;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.trace.PerfTracer;
@@ -61,7 +60,10 @@ public class CDOClientProtocol extends CDOProtocolImpl implements CDOSessionProt
private static final PerfTracer REVISION_LOADING = new PerfTracer(OM.PERF_REVISION_LOADING,
CDORevisionManagerImpl.class);
- private StringCompressor packageURICompressor = new StringCompressor(true);
+ private StringIO packageURICompressor = StringIO.DIRECT;
+
+ // XXX Enable compression again!
+ // private StringIO packageURICompressor = new StringCompressor(true);
public CDOClientProtocol()
{
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/StringCompressor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/StringCompressor.java
index b08b58f82d..161c8316dc 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/StringCompressor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/StringCompressor.java
@@ -4,7 +4,7 @@
* 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
*/
@@ -16,13 +16,21 @@ import java.util.HashMap;
import java.util.Map;
/**
- * TODO Detect possible race condition and let the client win.
- *
* @author Eike Stepper
* @since 2.0
*/
public class StringCompressor implements StringIO
{
+ private static final boolean DEBUG = false;
+
+ private static final byte DEBUG_STRING = 0;
+
+ private static final byte DEBUG_INT = 1;
+
+ private static final int NULL_ID = 0;
+
+ private static final int STRING_FOLLOWS = Integer.MIN_VALUE;
+
private boolean client;
private int lastID;
@@ -51,12 +59,10 @@ public class StringCompressor implements StringIO
{
if (string == null)
{
- out.writeInt(0);
+ writeInt(out, NULL_ID);
return;
}
- int idToWrite;
- String stringToWrite;
synchronized (stringToID)
{
Integer id = stringToID.get(string);
@@ -65,54 +71,101 @@ public class StringCompressor implements StringIO
lastID += client ? 1 : -1;
stringToID.put(string, lastID);
idToString.put(lastID, string);
- idToWrite = lastID;
- stringToWrite = string;
+ writeInt(out, STRING_FOLLOWS);
+ writeInt(out, lastID);
+ writeString(out, string);
}
else
{
- idToWrite = id;
- stringToWrite = null;
+ writeInt(out, id);
}
}
-
- out.writeInt(idToWrite);
- if (stringToWrite != null)
- {
- out.writeString(stringToWrite);
- }
}
public String read(ExtendedDataInput in) throws IOException
{
- int id = in.readInt();
- if (id == 0)
+ int id = readInt(in);
+ if (id == NULL_ID)
{
return null;
}
- String string;
- synchronized (stringToID)
- {
- string = idToString.get(id);
- }
-
- // TODO Check if we need a single synchronized block
- if (string == null)
+ if (id == STRING_FOLLOWS)
{
- string = in.readString();
+ id = readInt(in);
+ String string = readString(in);
synchronized (stringToID)
{
stringToID.put(string, id);
idToString.put(id, string);
}
+
+ return string;
}
+ else
+ {
+ synchronized (stringToID)
+ {
+ String string = idToString.get(id);
+ if (string == null)
+ {
+ throw new IOException("String ID unknown: " + id);
+ }
- return string;
+ return string;
+ }
+ }
}
@Override
public String toString()
{
- return MessageFormat.format("Compressor[client={0}]", client);
+ return MessageFormat.format("StringCompressor[client={0}]", client);
+ }
+
+ private void writeInt(ExtendedDataOutput out, int value) throws IOException
+ {
+ if (DEBUG)
+ {
+ out.writeByte(DEBUG_INT);
+ }
+
+ out.writeInt(value);
+ }
+
+ private void writeString(ExtendedDataOutput out, String value) throws IOException
+ {
+ if (DEBUG)
+ {
+ out.writeByte(DEBUG_STRING);
+ }
+
+ out.writeString(value);
+ }
+
+ private int readInt(ExtendedDataInput in) throws IOException
+ {
+ if (DEBUG)
+ {
+ if (DEBUG_INT != in.readByte())
+ {
+ throw new IOException("Not an integer value");
+ }
+ }
+
+ return in.readInt();
+ }
+
+ private String readString(ExtendedDataInput in) throws IOException
+ {
+ if (DEBUG)
+ {
+ if (DEBUG_STRING != in.readByte())
+ {
+ throw new IOException("Not a string value");
+ }
+ }
+
+ return in.readString();
}
}

Back to the top