summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-25 13:28:41 (EDT)
committerEike Stepper2007-08-25 13:28:41 (EDT)
commit7737da53c2e1748b3d83da74565a6a6f4124dc8a (patch)
treebdbe79d9da8ed23d5f036481ad619d7966d942fa
parent54bd3636c98820b9a1e88f00da363886667697ff (diff)
downloadcdo-7737da53c2e1748b3d83da74565a6a6f4124dc8a.zip
cdo-7737da53c2e1748b3d83da74565a6a6f4124dc8a.tar.gz
cdo-7737da53c2e1748b3d83da74565a6a6f4124dc8a.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java132
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/SortedFileMap.java38
2 files changed, 158 insertions, 12 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java
index 1eed461..7d74503 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java
@@ -18,7 +18,7 @@ import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.server.IStoreReader;
import org.eclipse.emf.cdo.server.ITypeManager;
-import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.internal.util.lifecycle.QueueWorker;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.io.CachedFileMap;
import org.eclipse.net4j.util.io.ExtendedDataInput;
@@ -35,7 +35,7 @@ import java.util.concurrent.ConcurrentMap;
/**
* @author Eike Stepper
*/
-public class TypeManager extends Lifecycle implements ITypeManager
+public class TypeManager extends QueueWorker<ObjectEntry> implements ITypeManager
{
private Repository repository;
@@ -45,10 +45,14 @@ public class TypeManager extends Lifecycle implements ITypeManager
private PackageURIMap packageURIMap;
+ private PackageIDMap packageIDMap;
+
private ObjectTypeMap objectTypeMap;
private ObjectTypeMap metaObjectTypeMap;
+ private int nextPackageID;
+
public TypeManager(Repository repository)
{
this.repository = repository;
@@ -72,22 +76,22 @@ public class TypeManager extends Lifecycle implements ITypeManager
public CDOClassRef getObjectType(IStoreReader storeReader, CDOID id)
{
CDOClassRef type = objectTypes.get(id);
- if (type == null)
+ if (type == null && persistent)
{
type = persistentLoadType(id);
- if (type == null && storeReader != null)
- {
- type = storeReader.readObjectType(id);
- }
+ }
- if (type == null)
- {
- throw new ImplementationError("type == null");
- }
+ if (type == null && storeReader != null)
+ {
+ type = storeReader.readObjectType(id);
+ }
- objectTypes.put(id, type);
+ if (type == null)
+ {
+ throw new ImplementationError("Type not found for id " + id);
}
+ objectTypes.put(id, type);
return type;
}
@@ -127,6 +131,26 @@ public class TypeManager extends Lifecycle implements ITypeManager
}
@Override
+ protected void work(WorkContext context, ObjectEntry element)
+ {
+ CDOID id = element.getID();
+ CDOClassRef type = element.getType();
+ String packageURI = type.getPackageURI();
+ int classifierID = type.getClassifierID();
+
+ Integer packageID = packageIDMap.get(packageURI);
+ if (packageID == null)
+ {
+ packageID = nextPackageID++;
+ packageIDMap.put(packageURI, packageID);
+ packageURIMap.put(packageID, packageURI);
+ }
+
+ TypeEntry entry = new TypeEntry(classifierID, packageID);
+ objectTypeMap.put(id, entry);
+ }
+
+ @Override
protected void doActivate() throws Exception
{
super.doActivate();
@@ -137,8 +161,12 @@ public class TypeManager extends Lifecycle implements ITypeManager
IOUtil.mkdirs(repositoryFolder);
packageURIMap = new PackageURIMap(new File(repositoryFolder, "package.uris"));
+ packageIDMap = new PackageIDMap(new File(repositoryFolder, "package.ids"));
objectTypeMap = new ObjectTypeMap(new File(repositoryFolder, "object.types"));
metaObjectTypeMap = new ObjectTypeMap(new File(repositoryFolder, "metaobject.types"));
+
+ Integer max = packageURIMap.getMaxKey();
+ nextPackageID = max == null ? 1 : max + 1;
}
}
@@ -147,6 +175,7 @@ public class TypeManager extends Lifecycle implements ITypeManager
{
IOUtil.close(metaObjectTypeMap);
IOUtil.close(objectTypeMap);
+ IOUtil.close(packageIDMap);
IOUtil.close(packageURIMap);
super.doDeactivate();
}
@@ -247,6 +276,59 @@ public class TypeManager extends Lifecycle implements ITypeManager
/**
* @author Eike Stepper
*/
+ private static final class PackageIDMap extends CachedFileMap<String, Integer>
+ {
+ public PackageIDMap(File file)
+ {
+ super(file, "rw");
+ }
+
+ @Override
+ public int getKeySize()
+ {
+ return 260;
+ }
+
+ @Override
+ protected String readKey(ExtendedDataInput in) throws IOException
+ {
+ return in.readString();
+ }
+
+ @Override
+ protected void writeKey(ExtendedDataOutput out, String key) throws IOException
+ {
+ byte[] bytes = key.getBytes();
+ if (bytes.length + 4 > getValueSize())
+ {
+ throw new IllegalArgumentException("Key size of " + getValueSize() + " exceeded: " + key);
+ }
+
+ ExtendedIOUtil.writeByteArray(out, bytes);
+ }
+
+ @Override
+ public int getValueSize()
+ {
+ return 4;
+ }
+
+ @Override
+ protected Integer readValue(ExtendedDataInput in) throws IOException
+ {
+ return in.readInt();
+ }
+
+ @Override
+ protected void writeValue(ExtendedDataOutput out, Integer value) throws IOException
+ {
+ out.writeInt(value);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
private static final class ObjectTypeMap extends SortedFileMap<CDOID, TypeEntry>
{
public ObjectTypeMap(File file)
@@ -291,3 +373,29 @@ public class TypeManager extends Lifecycle implements ITypeManager
}
}
}
+
+/**
+ * @author Eike Stepper
+ */
+final class ObjectEntry
+{
+ private CDOID id;
+
+ private CDOClassRef type;
+
+ public ObjectEntry(CDOID id, CDOClassRef type)
+ {
+ this.id = id;
+ this.type = type;
+ }
+
+ public CDOID getID()
+ {
+ return id;
+ }
+
+ public CDOClassRef getType()
+ {
+ return type;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/SortedFileMap.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/SortedFileMap.java
index 5aca41f..c0fee41 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/SortedFileMap.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/SortedFileMap.java
@@ -82,6 +82,44 @@ public abstract class SortedFileMap<K extends Comparable, V> implements Closeabl
return index * entrySize;
}
+ public K getMaxKey()
+ {
+ if (entryCount == 0)
+ {
+ return null;
+ }
+
+ return getKey(entryCount - 1);
+ }
+
+ public K getKey(long index)
+ {
+ try
+ {
+ long pos = getPosition(index);
+ randomAccessFile.seek(pos);
+ return readKey(input);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
+ public V getValue(long index)
+ {
+ try
+ {
+ long pos = getPosition(index) + getKeySize();
+ randomAccessFile.seek(pos);
+ return readValue(input);
+ }
+ catch (IOException ex)
+ {
+ throw new IORuntimeException(ex);
+ }
+ }
+
public V get(K key)
{
try