Moved two platform utility methods to Ignite.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/57184803 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/57184803 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/57184803 Branch: refs/heads/ignite-1124 Commit: 57184803fc64049e18d27d04777687e3f1f7e42d Parents: 5877b30 Author: vozerov-gridgain <[email protected]> Authored: Thu Aug 27 10:07:55 2015 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Thu Aug 27 10:07:55 2015 +0300 ---------------------------------------------------------------------- .../platform/utils/PlatformUtils.java | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/57184803/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java index f82fb0f..0777f9a 100644 --- a/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java +++ b/modules/platform/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java @@ -600,6 +600,61 @@ public class PlatformUtils { } /** + * Reallocate arbitrary memory chunk. + * + * @param memPtr Memory pointer. + * @param cap Capacity. + */ + public static void reallocate(long memPtr, int cap) { + PlatformMemoryUtils.reallocate(memPtr, cap); + } + + /** + * Get error data. + * + * @param err Error. + * @return Error data. + */ + @SuppressWarnings("UnusedDeclaration") + public static byte[] errorData(Throwable err) { + if (err instanceof PlatformExtendedException) { + PlatformContext ctx = ((PlatformExtendedException)err).context(); + + try (PlatformMemory mem = ctx.memory().allocate()) { + // Write error data. + PlatformOutputStream out = mem.output(); + + PortableRawWriterEx writer = ctx.writer(out); + + try { + PlatformUtils.writeErrorData(err, writer, ctx.kernalContext().log(PlatformContext.class)); + } + finally { + out.synchronize(); + } + + // Read error data into separate array. + PlatformInputStream in = mem.input(); + + in.synchronize(); + + int len = in.remaining(); + + assert len > 0; + + byte[] arr = in.array(); + byte[] res = new byte[len]; + + System.arraycopy(arr, 0, res, 0, len); + + return res; + } + } + else + return null; + } + + /** * Private constructor. */ private PlatformUtils() {
