[hydra-commits] beagles: branch ice/preserve-graphs r632 - in /ice/branches/preserve-graphs/j...

SVN commits to the Hydra project hydra-commits at lists.digium.com
Mon May 24 08:52:13 CDT 2010


Author: beagles
Date: Mon May 24 08:52:12 2010
New Revision: 632

URL: https://origsvn.digium.com/svn-view/hydra?view=rev&rev=632
Log:
Java sliced graphs of objects preservation support

Added:
    ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java   (with props)
    ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java   (with props)
Modified:
    ice/branches/preserve-graphs/java/build.xml
    ice/branches/preserve-graphs/java/src/IceInternal/BasicStream.java
    ice/branches/preserve-graphs/java/test/Ice/slicing/objects/ClientPrivate.ice

Modified: ice/branches/preserve-graphs/java/build.xml
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/java/build.xml?view=diff&rev=632&r1=631&r2=632
==============================================================================
--- ice/branches/preserve-graphs/java/build.xml (original)
+++ ice/branches/preserve-graphs/java/build.xml Mon May 24 08:52:12 2010
@@ -69,6 +69,7 @@
                 <include name="ObjectAdapter.ice" />
                 <include name="ObjectFactory.ice" />
                 <include name="Plugin.ice" />
+		<include name="Preserve.ice" />
                 <include name="Process.ice" />
                 <include name="Properties.ice" />
                 <include name="Router.ice" />

Added: ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java?view=auto&rev=632
==============================================================================
--- ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java (added)
+++ ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java Mon May 24 08:52:12 2010
@@ -1,0 +1,17 @@
+package Ice;
+
+public class ObjectPatcher implements IceInternal.Patcher
+{
+    public Ice.Object obj;
+
+    public void 
+    patch(Ice.Object v)
+    {
+	obj = v;
+    }
+
+    public String type()
+    {
+	return obj.ice_id();
+    }
+}

Propchange: ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: ice/branches/preserve-graphs/java/src/Ice/ObjectPatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java?view=auto&rev=632
==============================================================================
--- ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java (added)
+++ ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java Mon May 24 08:52:12 2010
@@ -1,0 +1,14 @@
+package Ice;
+
+public class SkippedSlice
+{
+    public java.lang.String typeId;
+    public byte[] slice;
+
+    public static void updateObjectId(byte[] blob, int offset, int id)
+    {
+	java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(blob);
+	buf.position(offset);
+	buf.putInt(id);
+    }
+}

Propchange: ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: ice/branches/preserve-graphs/java/src/Ice/SkippedSlice.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ice/branches/preserve-graphs/java/src/IceInternal/BasicStream.java
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/java/src/IceInternal/BasicStream.java?view=diff&rev=632&r1=631&r2=632
==============================================================================
--- ice/branches/preserve-graphs/java/src/IceInternal/BasicStream.java (original)
+++ ice/branches/preserve-graphs/java/src/IceInternal/BasicStream.java Mon May 24 08:52:12 2010
@@ -407,6 +407,16 @@
         _buf.b.putInt(_writeSlice - 4, sz);
     }
 
+    public int
+    getWriteSliceOffset()
+    {
+	if(_buf.size() < _writeSlice)
+	{
+	    throw new Ice.MarshalException("slice offsets are only valid within slices");
+	}
+	return _buf.size() - _writeSlice + 4;
+    }
+
     public void startReadSlice()
     {
         int sz = readInt();
@@ -438,192 +448,21 @@
         }
     }
 
-    public int
-    readAndCheckSeqSize(int minSize)
-    {
-        int sz = readSize();
-        
-        if(sz == 0)
-        {
-            return 0;
-        }
-        
-        //
-        // The _startSeq variable points to the start of the sequence for which
-        // we expect to read at least _minSeqSize bytes from the stream.
-        //
-        // If not initialized or if we already read more data than _minSeqSize, 
-        // we reset _startSeq and _minSeqSize for this sequence (possibly a 
-        // top-level sequence or enclosed sequence it doesn't really matter).
-        //
-        // Otherwise, we are reading an enclosed sequence and we have to bump
-        // _minSeqSize by the minimum size that this sequence will  require on
-        // the stream.
-        //
-        // The goal of this check is to ensure that when we start un-marshalling
-        // a new sequence, we check the minimal size of this new sequence against
-        // the estimated remaining buffer size. This estimatation is based on 
-        // the minimum size of the enclosing sequences, it's _minSeqSize.
-        //
-        if(_startSeq == -1 || _buf.b.position() > (_startSeq + _minSeqSize))
-        {
-            _startSeq = _buf.b.position();
-            _minSeqSize = sz * minSize;
-        }
-        else
-        {
-            _minSeqSize += sz * minSize;
-        }
-        
-        //
-        // If there isn't enough data to read on the stream for the sequence (and
-        // possibly enclosed sequences), something is wrong with the marshalled 
-        // data: it's claiming having more data that what is possible to read.
-        //
-        if(_startSeq + _minSeqSize > _buf.size())
-        {
-            throw new Ice.UnmarshalOutOfBoundsException();
-        }
-        
-        return sz;
-    }
-
-    public void
-    writeSize(int v)
-    {
-        if(v > 254)
-        {
-            expand(5);
-            _buf.b.put((byte)-1);
-            _buf.b.putInt(v);
-        }
-        else
-        {
-            expand(1);
-            _buf.b.put((byte)v);
-        }
-    }
-
-    public int
-    readSize()
-    {
-        try
-        {
-            byte b = _buf.b.get();
-            if(b == -1)
-            {
-                int v = _buf.b.getInt();
-                if(v < 0)
-                {
-                    throw new Ice.UnmarshalOutOfBoundsException();
-                }
-                return v;
-            }
-            else
-            {
-                return (int)(b < 0 ? b + 256 : b);
-            }
-        }
-        catch(java.nio.BufferUnderflowException ex)
-        {
-            throw new Ice.UnmarshalOutOfBoundsException();
-        }
-    }
-
-    public void
-    writeTypeId(String id)
-    {
-        if(_writeEncapsStack == null || _writeEncapsStack.typeIdMap == null)
-        {
-            //
-            // writeObject() must be called first.
-            //
-            throw new Ice.MarshalException("type ids require an encapsulation");
-        }
-
-        Integer index = _writeEncapsStack.typeIdMap.get(id);
-        if(index != null)
-        {
-            writeBool(true);
-            writeSize(index.intValue());
-        }
-        else
-        {
-            index = Integer.valueOf(++_writeEncapsStack.typeIdIndex);
-            _writeEncapsStack.typeIdMap.put(id, index);
-            writeBool(false);
-            writeString(id);
-        }
-    }
-
-    public String
-    readTypeId()
-    {
-        if(_readEncapsStack == null || _readEncapsStack.typeIdMap == null)
-        {
-            //
-            // readObject() must be called first.
-            //
-            throw new Ice.MarshalException("type ids require an encapsulation");
-        }
-
-        String id;
-        Integer index;
-        final boolean isIndex = readBool();
-        if(isIndex)
-        {
-            index = Integer.valueOf(readSize());
-            id = _readEncapsStack.typeIdMap.get(index);
-            if(id == null)
-            {
-                throw new Ice.UnmarshalOutOfBoundsException();
-            }
-        }
-        else
-        {
-            id = readString();
-            index = Integer.valueOf(++_readEncapsStack.typeIdIndex);
-            _readEncapsStack.typeIdMap.put(index, id);
-        }
-        return id;
-    }
-
-    public void
-    writeBlob(byte[] v)
-    {
-        if(v == null)
-        {
-            return;
-        }
-        expand(v.length);
-        _buf.b.put(v);
-    }
-
-    public void
-    writeBlob(byte[] v, int off, int len)
-    {
-        if(v == null)
-        {
-            return;
-        }
-        expand(len);
-        _buf.b.put(v, off, len);
-    }
-
-    public byte[]
-    getSkippedSlices()
-    {
-	if(_currentObjectStart < _currentSliceStart)
+    public void skipSlice(String typeId)
+    {
+	Ice.SkippedSlice newSlice = new Ice.SkippedSlice();
+	newSlice.typeId = typeId;
+	skipSlice();
+	if(_currentObjectStart < _buf.b.position())
 	{
 	    int returnTo = _buf.b.position();
 	    try
 	    {
 		try
 		{
-		    byte[] result = new byte[_currentSliceStart - _currentObjectStart];
+		    newSlice.slice = new byte[returnTo - _currentObjectStart];
 		    _buf.b.position(_currentObjectStart);
-		    _buf.b.get(result);
-		    return result;
+		    _buf.b.get(newSlice.slice);
 		}
 		catch(Exception ex)
 		{
@@ -635,7 +474,189 @@
 		_buf.b.position(returnTo);
 	    }
 	}
-	return null;
+	if(_skippedSlices == null)
+	{
+	    _skippedSlices = new java.util.ArrayList<Ice.SkippedSlice>();
+	}
+	_skippedSlices.add(newSlice);
+    }
+
+    public int
+    readAndCheckSeqSize(int minSize)
+    {
+        int sz = readSize();
+        
+        if(sz == 0)
+        {
+            return 0;
+        }
+        
+        //
+        // The _startSeq variable points to the start of the sequence for which
+        // we expect to read at least _minSeqSize bytes from the stream.
+        //
+        // If not initialized or if we already read more data than _minSeqSize, 
+        // we reset _startSeq and _minSeqSize for this sequence (possibly a 
+        // top-level sequence or enclosed sequence it doesn't really matter).
+        //
+        // Otherwise, we are reading an enclosed sequence and we have to bump
+        // _minSeqSize by the minimum size that this sequence will  require on
+        // the stream.
+        //
+        // The goal of this check is to ensure that when we start un-marshalling
+        // a new sequence, we check the minimal size of this new sequence against
+        // the estimated remaining buffer size. This estimatation is based on 
+        // the minimum size of the enclosing sequences, it's _minSeqSize.
+        //
+        if(_startSeq == -1 || _buf.b.position() > (_startSeq + _minSeqSize))
+        {
+            _startSeq = _buf.b.position();
+            _minSeqSize = sz * minSize;
+        }
+        else
+        {
+            _minSeqSize += sz * minSize;
+        }
+        
+        //
+        // If there isn't enough data to read on the stream for the sequence (and
+        // possibly enclosed sequences), something is wrong with the marshalled 
+        // data: it's claiming having more data that what is possible to read.
+        //
+        if(_startSeq + _minSeqSize > _buf.size())
+        {
+            throw new Ice.UnmarshalOutOfBoundsException();
+        }
+        
+        return sz;
+    }
+
+    public void
+    writeSize(int v)
+    {
+        if(v > 254)
+        {
+            expand(5);
+            _buf.b.put((byte)-1);
+            _buf.b.putInt(v);
+        }
+        else
+        {
+            expand(1);
+            _buf.b.put((byte)v);
+        }
+    }
+
+    public int
+    readSize()
+    {
+        try
+        {
+            byte b = _buf.b.get();
+            if(b == -1)
+            {
+                int v = _buf.b.getInt();
+                if(v < 0)
+                {
+                    throw new Ice.UnmarshalOutOfBoundsException();
+                }
+                return v;
+            }
+            else
+            {
+                return (int)(b < 0 ? b + 256 : b);
+            }
+        }
+        catch(java.nio.BufferUnderflowException ex)
+        {
+            throw new Ice.UnmarshalOutOfBoundsException();
+        }
+    }
+
+    public void
+    writeTypeId(String id)
+    {
+        if(_writeEncapsStack == null || _writeEncapsStack.typeIdMap == null)
+        {
+            //
+            // writeObject() must be called first.
+            //
+            throw new Ice.MarshalException("type ids require an encapsulation");
+        }
+
+        Integer index = _writeEncapsStack.typeIdMap.get(id);
+        if(index != null)
+        {
+            writeBool(true);
+            writeSize(index.intValue());
+        }
+        else
+        {
+            index = Integer.valueOf(++_writeEncapsStack.typeIdIndex);
+            _writeEncapsStack.typeIdMap.put(id, index);
+            writeBool(false);
+            writeString(id);
+        }
+    }
+
+    public String
+    readTypeId()
+    {
+        if(_readEncapsStack == null || _readEncapsStack.typeIdMap == null)
+        {
+            //
+            // readObject() must be called first.
+            //
+            throw new Ice.MarshalException("type ids require an encapsulation");
+        }
+
+        String id;
+        Integer index;
+        final boolean isIndex = readBool();
+        if(isIndex)
+        {
+            index = Integer.valueOf(readSize());
+            id = _readEncapsStack.typeIdMap.get(index);
+            if(id == null)
+            {
+                throw new Ice.UnmarshalOutOfBoundsException();
+            }
+        }
+        else
+        {
+            id = readString();
+            index = Integer.valueOf(++_readEncapsStack.typeIdIndex);
+            _readEncapsStack.typeIdMap.put(index, id);
+        }
+        return id;
+    }
+
+    public void
+    writeBlob(byte[] v)
+    {
+        if(v == null)
+        {
+            return;
+        }
+        expand(v.length);
+        _buf.b.put(v);
+    }
+
+    public void
+    writeBlob(byte[] v, int off, int len)
+    {
+        if(v == null)
+        {
+            return;
+        }
+        expand(len);
+        _buf.b.put(v, off, len);
+    }
+
+    public java.util.ArrayList<Ice.SkippedSlice>
+    getSkippedSlices()
+    {
+	return _skippedSlices;
     }
 
     public byte[]
@@ -1335,7 +1356,7 @@
         return _instance.proxyFactory().streamToProxy(this);
     }
 
-    public void
+    public int
     writeObject(Ice.Object v)
     {
         if(_writeEncapsStack == null) // Lazy initialization
@@ -1382,11 +1403,13 @@
                 p = q;
             }
             writeInt(-p.intValue());
+	    return p.intValue();
         }
         else
         {
             writeInt(0); // Write null reference
         }
+	return 0;
     }
 
     public void
@@ -1452,8 +1475,9 @@
             throw new Ice.MarshalException("Invalid class instance index");
         }
 
-	_currentObjectStart = _currentSliceStart = _buf.b.position();
         String mostDerivedId = readTypeId();
+	_currentObjectStart = _buf.b.position();
+	_skippedSlices.clear();
         String id = mostDerivedId;
 
         while(true)
@@ -1520,9 +1544,9 @@
                     {
                         TraceUtil.traceSlicing("class", id, _slicingCat, _instance.initializationData().logger);
                     }
-                    skipSlice(); // Slice off this derived part -- we don't understand it.
-		    _currentSliceStart = _buf.b.position();
+                    skipSlice(id); // Slice off this derived part -- we don't understand it.
                     id = readTypeId(); // Read next id for next iteration.
+		    _currentObjectStart = _buf.b.position();
                     continue;
                 }
                 else
@@ -1569,9 +1593,10 @@
         throws Ice.UserException
     {
         boolean usesClasses = readBool();
-
-	_currentObjectStart = _currentSliceStart = _buf.b.position();
+	_skippedSlices.clear();
+
         String id = readString();
+	_currentObjectStart = _buf.b.position();
         final String origId = id;
 
         for(;;)
@@ -1618,12 +1643,12 @@
                     TraceUtil.traceSlicing("exception", id, _slicingCat, _instance.initializationData().logger);
                 }
 
-                skipSlice(); // Slice off what we don't understand.
-		_currentSliceStart = _buf.b.position();
+                skipSlice(id); // Slice off what we don't understand.
 
                 try
                 {
                     id = readString(); // Read type id for next slice.
+		    _currentObjectStart = _buf.b.position();
                 }
                 catch(Ice.UnmarshalOutOfBoundsException ex)
                 {
@@ -1736,6 +1761,105 @@
     sliceObjects(boolean b)
     {
         _sliceObjects = b;
+    }
+
+    public void
+    addPreservedPatcher(Patcher patcher, int index)
+    {
+        if(_readEncapsStack == null) // Lazy initialization
+        {
+            _readEncapsStack = _readEncapsCache;
+            if(_readEncapsStack != null)
+            {
+                _readEncapsCache = _readEncapsCache.next;
+            }
+            else
+            {
+                _readEncapsStack = new ReadEncaps();
+            }
+        }
+
+        if(_readEncapsStack.patchMap == null) // Lazy initialization
+        {
+            _readEncapsStack.patchMap = new java.util.TreeMap<Integer, java.util.LinkedList<Patcher> >();
+            _readEncapsStack.unmarshaledMap = new java.util.TreeMap<Integer, Ice.Object>();
+            _readEncapsStack.typeIdMap = new java.util.TreeMap<Integer, String>();
+        }
+
+	if(index == 0)
+	{
+	    patcher.patch(null);
+	    return;
+	}
+
+	java.util.LinkedList<Patcher> patchlist = _readEncapsStack.patchMap.get(index);
+	if(patchlist == null)
+	{
+	    //
+	    // We have no outstanding instances to be patched for
+	    // this index, so make a new entry in the patch map.
+	    //
+	    patchlist = new java.util.LinkedList<Patcher>();
+	    _readEncapsStack.patchMap.put(index, patchlist);
+	}
+	//
+	// Append a patcher for this instance and see if we can
+	// patch the instance. (The instance may have been
+	// unmarshaled previously.)
+	//
+	patchlist.add(patcher);
+	patchReferences(null, index);
+	return;
+    }
+
+    public int addPendingObject(Ice.Object v)
+    {
+        if(_writeEncapsStack == null) // Lazy initialization
+        {
+            _writeEncapsStack = _writeEncapsCache;
+            if(_writeEncapsStack != null)
+            {
+                _writeEncapsCache = _writeEncapsCache.next;
+            }
+            else
+            {
+                _writeEncapsStack = new WriteEncaps();
+            }
+        }
+
+        if(_writeEncapsStack.toBeMarshaledMap == null)  // Lazy initialization
+        {
+            _writeEncapsStack.toBeMarshaledMap = new java.util.IdentityHashMap<Ice.Object, Integer>();
+            _writeEncapsStack.marshaledMap = new java.util.IdentityHashMap<Ice.Object, Integer>();
+            _writeEncapsStack.typeIdMap = new java.util.TreeMap<String, Integer>();
+        }
+        if(v != null)
+        {
+            //
+            // Look for this instance in the to-be-marshaled map.
+            //
+            Integer p = _writeEncapsStack.toBeMarshaledMap.get(v);
+            if(p == null)
+            {
+                //
+                // Didn't find it, try the marshaled map next.
+                //
+                Integer q = _writeEncapsStack.marshaledMap.get(v);
+                if(q == null)
+                {
+                    //
+                    // We haven't seen this instance previously,
+                    // create a new index, and insert it into the
+                    // to-be-marshaled map.
+                    //
+                    q = Integer.valueOf(++_writeEncapsStack.writeIndex);
+                    _writeEncapsStack.toBeMarshaledMap.put(v, q);
+                }
+                p = q;
+            }
+            writeInt(p.intValue());
+        }
+	return 0;
     }
 
     void
@@ -2441,7 +2565,6 @@
     private int _writeSlice;
 
     private int _currentObjectStart;
-    private int _currentSliceStart;
 
     private int _traceSlicing;
     private String _slicingCat;
@@ -2454,6 +2577,7 @@
     private int _startSeq;
     private int _minSeqSize;
 
+    private java.util.ArrayList<Ice.SkippedSlice> _skippedSlices = new java.util.ArrayList<Ice.SkippedSlice>();
     private java.util.ArrayList<Ice.Object> _objectList;
 
     private static java.util.HashMap<String, UserExceptionFactory> _exceptionFactories =

Modified: ice/branches/preserve-graphs/java/test/Ice/slicing/objects/ClientPrivate.ice
URL: https://origsvn.digium.com/svn-view/hydra/ice/branches/preserve-graphs/java/test/Ice/slicing/objects/ClientPrivate.ice?view=diff&rev=632&r1=631&r2=632
==============================================================================
--- ice/branches/preserve-graphs/java/test/Ice/slicing/objects/ClientPrivate.ice (original)
+++ ice/branches/preserve-graphs/java/test/Ice/slicing/objects/ClientPrivate.ice Mon May 24 08:52:12 2010
@@ -32,6 +32,7 @@
     B pb;
 };
 
+["preserve"]
 class BU extends B
 {
 };





More information about the asterisk-scf-commits mailing list