Sync git svn branch with SVN repository r33349.
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Oct 2016 11:48:00 +0000 (14:48 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Oct 2016 11:48:00 +0000 (14:48 +0300)
refs #6600
refs #6774
refs #6780

bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/BinaryFile.java
bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/Content.java [deleted file]
bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IAbstractRequestInterface.java [deleted file]
bundles/org.simantics.graph.db/src/org/simantics/graph/db/TGStatusMonitor.java
bundles/org.simantics.graph.db/src/org/simantics/graph/db/TransferableGraphs.java

index 1e9dfa3fbe71ac5ac3789e4be6f3cbf94c9a0597..e7d8d386eb14c79ec6b295b215c3e3626384d642 100644 (file)
@@ -578,7 +578,41 @@ public class BinaryFile implements RandomAccessBinary, BinaryReadable, BinaryWri
 \r
 \r
        // WRITE
-               
+\r
+       void _putLong(long value) throws IOException\r
+       {\r
+               prepareForWrite(8);\r
+               int posInBuf = (int) (pointer - buf_pos);\r
+               buf[posInBuf] = (byte) (value >>> 56);\r
+               buf[posInBuf+1] = (byte) (value >>> 48);\r
+               buf[posInBuf+2] = (byte) (value >>> 40);\r
+               buf[posInBuf+3] = (byte) (value >>> 32);\r
+               buf[posInBuf+4] = (byte) (value >>> 24);\r
+               buf[posInBuf+5] = (byte) (value >>> 16);\r
+               buf[posInBuf+6] = (byte) (value >>> 8);\r
+               buf[posInBuf+7] = (byte) value;\r
+               posInBuf += 8;\r
+               pointer += 8;\r
+               if (write_buf_count<posInBuf) write_buf_count = posInBuf;\r
+               if (readable_bytes_count<write_buf_count) readable_bytes_count=write_buf_count;\r
+               if (virtualLength<pointer) virtualLength=pointer;\r
+       }\r
+\r
+       void _putInt(int value) throws IOException\r
+       {\r
+               prepareForWrite(4);\r
+               int posInBuf = (int) (pointer - buf_pos);\r
+               buf[posInBuf] = (byte) (value >>> 24);\r
+               buf[posInBuf+1] = (byte) (value >>> 16);\r
+               buf[posInBuf+2] = (byte) (value >>> 8);\r
+               buf[posInBuf+3] = (byte) value;\r
+               posInBuf += 4;\r
+               pointer += 4;\r
+               if (write_buf_count<posInBuf) write_buf_count = posInBuf;\r
+               if (readable_bytes_count<write_buf_count) readable_bytes_count=write_buf_count;\r
+               if (virtualLength<pointer) virtualLength=pointer;\r
+       }\r
+
        void _put(int value) throws IOException
        {
                prepareForWrite(1);
@@ -666,22 +700,12 @@ public class BinaryFile implements RandomAccessBinary, BinaryReadable, BinaryWri
 
        @Override
        public void writeInt(int value) throws IOException {
-               _put(value >>> 24);
-               _put(value >>> 16);
-               _put(value >>> 8);
-               _put(value);
+               _putInt(value);
        }
 
        @Override
        public void writeLong(long value) throws IOException {
-               _put((int) (value >>> 56));
-               _put((int) (value >>> 48));
-               _put((int) (value >>> 40));
-               _put((int) (value >>> 32));
-               _put((int) (value >>> 24));
-               _put((int) (value >>> 16));
-               _put((int) (value >>> 8));
-               _put((int) (value));
+               _putLong(value);
        }
 
        @Override
diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/Content.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/Content.java
deleted file mode 100644 (file)
index eb957c8..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************\r
- * Copyright (c) 2014, 2016 Association for Decentralized \r
- * Information Management in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the THTH Simantics \r
- * Division Member Component License which accompanies this \r
- * distribution, and is available at\r
- * http://www.simantics.org/legal/sdmcl-v10.html\r
- *\r
- * Contributors:\r
- *     Semantum Oy - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.document.server.io;\r
-\r
-import java.io.InputStream;\r
-\r
-public class Content {\r
-       private InputStream input;\r
-       private String mimeType;\r
-       private long lastModified;\r
-       private int length;\r
-       \r
-       public Content(InputStream input, String mimeType, long lastModified, int length) {\r
-               this.input = input;\r
-               this.mimeType = mimeType;\r
-               this.lastModified = lastModified;\r
-               this.length = length;\r
-       }\r
-\r
-       public InputStream getInputStream() {\r
-               return input;\r
-       }\r
-\r
-       public void setInputStream(InputStream input) {\r
-               this.input = input;\r
-       }\r
-\r
-       public String getMimeType() {\r
-               return mimeType;\r
-       }\r
-\r
-       public void setMimeType(String mimeType) {\r
-               this.mimeType = mimeType;\r
-       }\r
-\r
-       public long getLastModified() {\r
-               return lastModified;\r
-       }\r
-\r
-       public void setLastModified(long lastModified) {\r
-               this.lastModified = lastModified;\r
-       }\r
-\r
-       public int getLength() {\r
-               return length;\r
-       }\r
-\r
-       public void setLength(int length) {\r
-               this.length = length;\r
-       }\r
-}\r
diff --git a/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IAbstractRequestInterface.java b/bundles/org.simantics.document.server.io/src/org/simantics/document/server/io/IAbstractRequestInterface.java
deleted file mode 100644 (file)
index 9e736c8..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-package org.simantics.document.server.io;\r
-\r
-public interface IAbstractRequestInterface {\r
-\r
-       void init();\r
-       void createSession(String sessionGUID, IConsole console);\r
-       void deleteSession(String sessionGUID);\r
-       void setInputURI(String sessionGUID, String inputURI);\r
-       void setSessionParameter(String sessionGUID, String parameterName, Object value);\r
-       public IJSONResult requestDocument(String document, int sequenceNumber, int pollingHint, String sessionGUID);\r
-       public String requestDocumentURI(String alias);\r
-       String requestCSS(String documentURI);\r
-       int[] requestLoadingIndicatorDelay(String documentURI);\r
-       Double requestPollingInterval(String documentURI);\r
-       Content requestContent(String resourceURI);\r
-       public CommandResult execute(String id, CommandContext context);\r
-       public void subscribeDocument(String document, String sessionGUID, IDocumentListener documentListener);\r
-       public IJSONResult readChanges(String uri, String sessionGUID, int sequenceNumber);\r
-       public void initializeDocument(String documentURI, String sessionGUID, CommandContext context);\r
-       public void onPoll(String sessionGUID);\r
-       public String escapeURI(String unicode);\r
-}\r
index 06e0adbedb659f31fe4e1092c28ef8d9643128b9..8f93639eac225667401e242bd1e1e0b8993cc6ff 100644 (file)
@@ -20,23 +20,28 @@ public interface TGStatusMonitor {
     public static class Updater {\r
         private final TGStatusMonitor monitor;\r
         private final int total;\r
-        private int percentage;\r
+        private int low;\r
+        private int high;\r
+        private int current;\r
         private int worked;\r
 \r
-        public Updater(TGStatusMonitor monitor, int total) {\r
+        public Updater(TGStatusMonitor monitor, int lowPercentage, int highPercentage, int totalWork) {\r
             this.monitor = monitor;\r
-            this.total = total;\r
+            this.low = lowPercentage;\r
+            this.high = highPercentage;\r
+            this.total = totalWork;\r
         }\r
 \r
         public int worked(int work) {\r
             worked += work;\r
-            return percentage = updatePercentage(monitor, percentage, worked, total);\r
+            return current = updatePercentage(monitor, low, high, current, worked, total);\r
         }\r
     }\r
 \r
-    public static int updatePercentage(TGStatusMonitor monitor, int oldPercentage, int done, int total) {\r
-        int current = (100 * done) / total;\r
-        if (current > oldPercentage) {\r
+    public static int updatePercentage(TGStatusMonitor monitor, int low, int high, int oldPercentage, int done, int total) {\r
+        int range = high - low;\r
+        int current = low + (range * done) / total;\r
+        if (current != oldPercentage) {\r
             oldPercentage = current;\r
             if (monitor != null) \r
                 monitor.status(oldPercentage);\r
index bfea63c48d5fc72742c34232463a0ba2b9d207ac..c2ca6ac7305d26e824a928ffa6b8ee9c6e53b372 100644 (file)
  *******************************************************************************/\r
 package org.simantics.graph.db;\r
 \r
-import java.io.BufferedOutputStream;\r
 import java.io.DataInput;\r
 import java.io.DataOutput;\r
-import java.io.DataOutputStream;\r
 import java.io.File;\r
-import java.io.FileOutputStream;\r
 import java.io.IOException;\r
 import java.io.InputStream;\r
 import java.util.ArrayList;\r
@@ -40,6 +37,8 @@ import org.simantics.databoard.container.DataContainers;
 import org.simantics.databoard.serialization.SerializationException;\r
 import org.simantics.databoard.serialization.Serializer;\r
 import org.simantics.databoard.type.Datatype;\r
+import org.simantics.databoard.util.binary.BinaryFile;\r
+import org.simantics.databoard.util.binary.RandomAccessBinary;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.RequestProcessor;\r
 import org.simantics.db.Resource;\r
@@ -437,7 +436,7 @@ public class TransferableGraphs {
 \r
        public static void writeTransferableGraph(RequestProcessor processor, String format, int version, TreeMap<String, Variant> metadata, TransferableGraphSource source, File target, TGStatusMonitor monitor) throws Exception {\r
                final Serializer datatypeSerializer = Bindings.getSerializerUnchecked(Datatype.class);\r
-               try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(target), 128*1024))) {\r
+               try (RandomAccessBinary out = new BinaryFile(target, 128*1024)) {\r
                        DataContainer container = new DataContainer(format, version, metadata, null);\r
                        DataContainers.writeHeader(out, container);\r
                        datatypeSerializer.serialize((DataOutput) out, Datatypes.getDatatypeUnchecked(TransferableGraph1.class));\r
@@ -475,17 +474,16 @@ public class TransferableGraphs {
 \r
        private static final int LITERAL_VALUE_IO_BUFFER_SIZE = 128 * 1024;\r
 \r
-       private static void writeTransferableGraph(RequestProcessor processor, final TransferableGraphSource source, final DataOutput out, TGStatusMonitor monitor) throws Exception {\r
+       private static void writeTransferableGraph(RequestProcessor processor, final TransferableGraphSource source, final RandomAccessBinary out, TGStatusMonitor monitor) throws Exception {\r
                long start = System.nanoTime();\r
 \r
                final Serializer datatypeSerializer = Bindings.getSerializerUnchecked(Datatype.class);\r
                final Serializer identitySerializer = Bindings.getSerializerUnchecked(Identity.class);\r
                final Serializer extensionSerializer = Bindings.getSerializerUnchecked(Extensions.class);\r
 \r
-               int totalCount = source.getIdentityCount() + source.getStatementCount()/4 + source.getValueCount();\r
-               TGStatusMonitor.Updater progress = new TGStatusMonitor.Updater(safeMonitor(monitor), totalCount);\r
-\r
-               out.writeInt(source.getResourceCount());\r
+               int resourceCount = source.getResourceCount();\r
+               //System.err.println("resourceCount: " + resourceCount);\r
+               out.writeInt(resourceCount);\r
                extensionSerializer.serialize(out, new Extensions(source.getExtensions()));\r
 \r
 //             System.err.println("resource count: " + source.getResourceCount());\r
@@ -500,31 +498,50 @@ public class TransferableGraphs {
                                        if (monitor.isCanceled())\r
                                                throw new CancelTransactionException();\r
 \r
-                                       out.writeInt(source.getIdentityCount());\r
+                                       int identityCount = source.getIdentityCount();\r
+                                       TGStatusMonitor.Updater identityProgress = new TGStatusMonitor.Updater(safeMonitor(monitor), 0, 33, identityCount);\r
+                                       out.writeInt(identityCount);\r
+                                       //System.err.println("identities: " + identityCount);\r
                                        source.forIdentities(graph, value -> {\r
                                                //System.err.println("id: " + value);\r
                                                identitySerializer.serialize(out, value);\r
-                                               progress.worked(1);\r
+                                               identityProgress.worked(1);\r
                                        });\r
 \r
                                        if (monitor.isCanceled())\r
                                                throw new CancelTransactionException();\r
 \r
-                                       out.writeInt(source.getStatementCount());\r
-                                       //System.err.println("stms: " + source.getStatementCount());\r
-                                       //int[] counter = {0};\r
+                                       long statementCountPos = out.position();\r
+                                       int originalStatementCount = source.getStatementCount();\r
+                                       TGStatusMonitor.Updater statementProgress = new TGStatusMonitor.Updater(safeMonitor(monitor), 34, 66, originalStatementCount);\r
+                                       out.writeInt(originalStatementCount);\r
+                                       //System.err.println("original statementCount: " + originalStatementCount);\r
+                                       int[] statementCounter = { 0 };\r
                                        source.forStatements(graph, r -> {\r
                                                for (int i = 0; i < 4; ++i)\r
                                                        out.writeInt(r[i]);\r
-                                               //System.err.println("stm " + (counter[0]++) + ": " + r[0] + " " + r[1] + " " + r[2] + " " + r[3]);\r
-                                               progress.worked(1);\r
+                                               statementCounter[0]++;\r
+                                               //System.err.println("stm " + (statementCounter[0]) + ": " + r[0] + " " + r[1] + " " + r[2] + " " + r[3]);\r
+                                               statementProgress.worked(1);\r
                                        });\r
+                                       //System.err.println("wrote " + statementCounter[0] + " statements, " + (statementCounter[0]*4)+ " integers");\r
+\r
+                                       // Rewrite statement count after knowing exactly how many\r
+                                       // statements were written. It is possible that some\r
+                                       // statements get filtered out at this stage and the\r
+                                       // original statement count does not reflect that.\r
+                                       long afterStatementsPos = out.position();\r
+                                       out.position(statementCountPos);\r
+                                       out.writeInt(statementCounter[0]*4);\r
+                                       out.position(afterStatementsPos);\r
 \r
                                        if (monitor.isCanceled())\r
                                                throw new CancelTransactionException();\r
 \r
-                                       out.writeInt(source.getValueCount());\r
-                                       //System.err.println("vals: " + source.getValueCount());\r
+                                       int valueCount = source.getValueCount();\r
+                                       TGStatusMonitor.Updater valueProgress = new TGStatusMonitor.Updater(safeMonitor(monitor), 67, 100, valueCount);\r
+                                       out.writeInt(valueCount);\r
+//                                     System.err.println("valueCount: " + valueCount);\r
                                        CopyingInputStream cis = new CopyingInputStream();\r
                                        cis.out = out;\r
                                        source.forValues2(graph, new TransferableGraphSourceValueProcedure() {\r
@@ -536,7 +553,7 @@ public class TransferableGraphs {
                                                        long copied = copy(buffer, input, out, length);\r
                                                        assert copied == length;\r
                                                        //System.err.println("value " + (num++) + ": raw variant, " + length + " bytes, copied " + copied + " bytes");\r
-                                                       progress.worked(1);\r
+                                                       valueProgress.worked(1);\r
                                                }\r
 \r
                                                @Override\r
@@ -549,7 +566,7 @@ public class TransferableGraphs {
                                                        cis.in = input;\r
                                                        serializer.skip(cis);\r
                                                        cis.in = null;\r
-                                                       progress.worked(1);\r
+                                                       valueProgress.worked(1);\r
                                                }\r
                                        });\r
 \r