Class PlatformUtils


  • public class PlatformUtils
    extends Object
    Platform utility methods.
    • Method Detail

      • writeNullableCollection

        public static <T> void writeNullableCollection​(BinaryRawWriterEx writer,
                                                       @Nullable
                                                       @Nullable Collection<T> col)
        Write nullable collection to the writer.
        Parameters:
        writer - Writer.
        col - Collection to write.
      • writeNullableCollection

        public static <T> void writeNullableCollection​(BinaryRawWriterEx writer,
                                                       @Nullable
                                                       @Nullable Collection<T> col,
                                                       @Nullable
                                                       @Nullable PlatformWriterClosure<T> writeClo)
        Write nullable collection to the writer.
        Parameters:
        writer - Writer.
        col - Collection to write.
        writeClo - Writer closure.
      • writeNullableCollection

        public static <T> void writeNullableCollection​(BinaryRawWriterEx writer,
                                                       @Nullable
                                                       @Nullable Collection<T> col,
                                                       @Nullable
                                                       @Nullable PlatformWriterClosure<T> writeClo,
                                                       @Nullable
                                                       @Nullable IgnitePredicate<T> filter)
        Write collection to the writer.
        Parameters:
        writer - Writer.
        col - Collection to write.
        writeClo - Optional writer closure.
        filter - Optional filter.
      • writeCollection

        public static <T> void writeCollection​(BinaryRawWriterEx writer,
                                               Collection<T> col)
        Write collection to the writer.
        Parameters:
        writer - Writer.
        col - Collection to write.
      • writeCollection

        public static <T> void writeCollection​(BinaryRawWriterEx writer,
                                               Collection<T> col,
                                               @Nullable
                                               @Nullable PlatformWriterClosure<T> writeClo)
        Write collection to the writer.
        Parameters:
        writer - Writer.
        col - Collection to write.
        writeClo - Writer closure.
      • writeCollection

        public static <T> void writeCollection​(BinaryRawWriterEx writer,
                                               Collection<T> col,
                                               @Nullable
                                               @Nullable PlatformWriterClosure<T> writeClo,
                                               @Nullable
                                               @Nullable IgnitePredicate<T> filter)
        Write collection to the writer.
        Parameters:
        writer - Writer.
        col - Collection to write.
        writeClo - Optional writer closure.
        filter - Optional filter.
      • writeNullableMap

        public static <K,​V> void writeNullableMap​(BinaryRawWriterEx writer,
                                                        @Nullable
                                                        @Nullable Map<K,​V> map)
        Write nullable map to the writer.
        Parameters:
        writer - Writer.
        map - Map to write.
      • writeMap

        public static <K,​V> void writeMap​(BinaryRawWriterEx writer,
                                                Map<K,​V> map)
        Write nullable map to the writer.
        Parameters:
        writer - Writer.
        map - Map to write.
      • writeMap

        public static <K,​V> void writeMap​(BinaryRawWriterEx writer,
                                                Map<K,​V> map,
                                                @Nullable
                                                @Nullable PlatformWriterBiClosure<K,​V> writeClo)
        Write nullable map to the writer.
        Parameters:
        writer - Writer.
        map - Map to write.
        writeClo - Writer closure.
      • readCollection

        public static <T> List<T> readCollection​(BinaryRawReaderEx reader)
        Read collection.
        Parameters:
        reader - Reader.
        Returns:
        List.
      • readCollection

        public static <T> List<T> readCollection​(BinaryRawReaderEx reader,
                                                 @Nullable
                                                 @Nullable PlatformReaderClosure<T> readClo)
        Read collection.
        Parameters:
        reader - Reader.
        readClo - Optional reader closure.
        Returns:
        List.
      • readNullableCollection

        public static <T> List<T> readNullableCollection​(BinaryRawReaderEx reader)
        Read nullable collection.
        Parameters:
        reader - Reader.
        Returns:
        List.
      • readNullableCollection

        public static <T> List<T> readNullableCollection​(BinaryRawReaderEx reader,
                                                         @Nullable
                                                         @Nullable PlatformReaderClosure<T> readClo)
        Read nullable collection.
        Parameters:
        reader - Reader.
        Returns:
        List.
      • readSet

        public static <T> Set<T> readSet​(BinaryRawReaderEx reader)
        Parameters:
        reader - Reader.
        Returns:
        Set.
      • readNullableSet

        public static <T> Set<T> readNullableSet​(BinaryRawReaderEx reader)
        Parameters:
        reader - Reader.
        Returns:
        Set.
      • readMap

        public static <K,​V> Map<K,​V> readMap​(BinaryRawReaderEx reader)
        Read map.
        Parameters:
        reader - Reader.
        Returns:
        Map.
      • readMap

        public static <K,​V> Map<K,​V> readMap​(BinaryRawReaderEx reader,
                                                         @Nullable
                                                         @Nullable PlatformReaderBiClosure<K,​V> readClo)
        Read map.
        Parameters:
        reader - Reader.
        readClo - Reader closure.
        Returns:
        Map.
      • readLinkedMap

        public static <K,​V> Map<K,​V> readLinkedMap​(BinaryRawReaderEx reader,
                                                               @Nullable
                                                               @Nullable PlatformReaderBiClosure<K,​V> readClo)
        Read linked map.
        Parameters:
        reader - Reader.
        readClo - Reader closure.
        Returns:
        Map.
      • readNullableMap

        public static <K,​V> Map<K,​V> readNullableMap​(BinaryRawReaderEx reader)
        Read nullable map.
        Parameters:
        reader - Reader.
        Returns:
        Map.
      • writeIgniteUuid

        public static void writeIgniteUuid​(BinaryRawWriterEx writer,
                                           IgniteUuid val)
        Writes IgniteUuid to a writer.
        Parameters:
        writer - Writer.
        val - Values.
      • decodeCachePeekModes

        public static CachePeekMode[] decodeCachePeekModes​(int modes)
        Convert native cache peek modes to Java cache peek modes.
        Parameters:
        modes - Encoded peek modes.
        Returns:
        Cache peek modes.
      • unwrapQueryException

        public static IgniteCheckedException unwrapQueryException​(Throwable err)
        Unwrap query exception.
        Parameters:
        err - Initial error.
        Returns:
        Unwrapped error.
      • applyContinuousQueryEvents

        public static void applyContinuousQueryEvents​(PlatformContext ctx,
                                                      long lsnrPtr,
                                                      Iterable<javax.cache.event.CacheEntryEvent> evts)
                                               throws javax.cache.event.CacheEntryListenerException
        Apply continuous query events to listener.
        Parameters:
        ctx - Context.
        lsnrPtr - Listener pointer.
        evts - Events.
        Throws:
        javax.cache.event.CacheEntryListenerException - In case of failure.
      • evaluateContinuousQueryEvent

        public static boolean evaluateContinuousQueryEvent​(PlatformContext ctx,
                                                           long filterPtr,
                                                           javax.cache.event.CacheEntryEvent evt)
                                                    throws javax.cache.event.CacheEntryListenerException
        Evaluate the filter.
        Parameters:
        ctx - Context.
        filterPtr - Native filter pointer.
        evt - Event.
        Returns:
        Result.
        Throws:
        javax.cache.event.CacheEntryListenerException - In case of failure.
      • writeError

        public static void writeError​(Throwable ex,
                                      BinaryRawWriterEx writer)
        Writes error.
        Parameters:
        ex - Error.
        writer - Writer.
      • writeErrorData

        public static void writeErrorData​(Throwable err,
                                          BinaryRawWriterEx writer)
        Writer error data.
        Parameters:
        err - Error.
        writer - Writer.
      • writeErrorData

        public static void writeErrorData​(Throwable err,
                                          BinaryRawWriterEx writer,
                                          @Nullable
                                          @Nullable IgniteLogger log)
        Write error data.
        Parameters:
        err - Error.
        writer - Writer.
        log - Optional logger.
      • platformProcessor

        public static PlatformProcessor platformProcessor​(Ignite grid)
        Get platform processor.
        Parameters:
        grid - Ignite instance.
        Returns:
        Platform processor.
      • platformContext

        public static PlatformContext platformContext​(Ignite grid)
        Gets interop context for the grid.
        Parameters:
        grid - Grid
        Returns:
        Context.
      • reallocate

        public static void reallocate​(long memPtr,
                                      int cap)
        Reallocate arbitrary memory chunk.
        Parameters:
        memPtr - Memory pointer.
        cap - Capacity.
      • errorData

        public static byte[] errorData​(Throwable err)
        Get error data.
        Parameters:
        err - Error.
        Returns:
        Error data.
      • writeInvocationResult

        public static void writeInvocationResult​(BinaryRawWriterEx writer,
                                                 Object resObj,
                                                 Throwable err)
        Writes invocation result (of a job/service/etc) using a common protocol.
        Parameters:
        writer - Writer.
        resObj - Result.
        err - Error.
      • readInvocationResult

        public static Object readInvocationResult​(PlatformContext ctx,
                                                  BinaryRawReaderEx reader,
                                                  boolean deserialize)
                                           throws IgniteCheckedException
        Reads invocation result (of a job/service/etc) using a common protocol.
        Parameters:
        ctx - Platform context.
        reader - Reader.
        deserialize - If true deserialize invocation result.
        Returns:
        Result.
        Throws:
        IgniteCheckedException - When invocation result is an error.
      • marshaller

        public static GridBinaryMarshaller marshaller()
        Create binary marshaller.
        Returns:
        Marshaller.
      • unwrapBinariesInArray

        public static Object[] unwrapBinariesInArray​(Object[] arr)
        Unwrap array of binaries if needed.
        Parameters:
        arr - Array.
        Returns:
        Result.
      • createJavaObject

        public static <T> T createJavaObject​(String clsName)
        Create Java object.
        Parameters:
        clsName - Class name.
        Returns:
        Instance.
      • initializeJavaObject

        public static void initializeJavaObject​(Object obj,
                                                String clsName,
                                                @Nullable
                                                @Nullable Map<String,​Object> props,
                                                @Nullable
                                                @Nullable GridKernalContext ctx)
        Initialize Java object or object factory.
        Parameters:
        obj - Object.
        clsName - Class name.
        props - Properties (optional).
        ctx - Kernal context (optional).
      • getFullStackTrace

        public static String getFullStackTrace​(Throwable throwable)
        Gets the entire nested stack-trace of an throwable.
        Parameters:
        throwable - The Throwable to be examined.
        Returns:
        The nested stack trace, with the root cause first.
      • getSchema

        public static int[] getSchema​(CacheObjectBinaryProcessorImpl cacheObjProc,
                                      int typeId,
                                      int schemaId)
        Gets the schema.
        Parameters:
        cacheObjProc - Cache object processor.
        typeId - Type id.
        schemaId - Schema id.
      • writeBinaryMetadata

        public static void writeBinaryMetadata​(BinaryRawWriter writer,
                                               BinaryMetadata meta,
                                               boolean includeSchemas)
        Writes the binary metadata to a writer.
        Parameters:
        writer - Writer.
        meta - Meta.
      • readBinaryMetadataCollection

        public static Collection<BinaryMetadata> readBinaryMetadataCollection​(BinaryRawReaderEx reader)
        Reads the binary metadata.
        Parameters:
        reader - Reader.
        Returns:
        Collection of metas.
      • readBinaryMetadata

        public static BinaryMetadata readBinaryMetadata​(BinaryRawReaderEx reader)
        Reads the binary metadata.
        Parameters:
        reader - Reader.
        Returns:
        Binary type metadata.
      • writeNodeAttributes

        public static void writeNodeAttributes​(BinaryRawWriterEx writer,
                                               Map<String,​Object> attrs)
        Writes node attributes.
        Parameters:
        writer - Writer.
        attrs - Attributes.
      • readNodeAttributes

        public static Map<String,​Object> readNodeAttributes​(BinaryRawReaderEx reader)
        Reads node attributes.
        Parameters:
        reader - Reader.
        Returns:
        Attributes.
      • writeNodeVersion

        public static void writeNodeVersion​(BinaryRawWriterEx out,
                                            IgniteProductVersion productVersion)
        Write binary productVersion.
        Parameters:
        out - Writer.
        productVersion - IgniteProductVersion.
      • servicePlatform

        public static String servicePlatform​(ServiceConfiguration svcCfg)
        Get service platform.
        Parameters:
        svcCfg - Service configuration.
        Returns:
        Service platform or empty string if this is a java service.
      • readCacheObject

        public static <T extends CacheObject> T readCacheObject​(BinaryReaderExImpl reader,
                                                                boolean isKey)
        Read cache object from the stream as raw bytes to avoid marshalling.
        Parameters:
        reader - Reader.
        isKey - True if object is a key.