Interface Marshaller

    • Method Detail

      • initialize

        default void initialize​(ClassWhiteList classWhiteList)
        An optional method which allows an implementation to respect the ClassWhiteList associated with the context, for example the EmbeddedCacheManager or RemoteCacheManager.
      • objectToByteBuffer

        byte[] objectToByteBuffer​(Object obj,
                                  int estimatedSize)
                           throws IOException,
                                  InterruptedException
        Marshalls an object to a byte array. The estimatedSize parameter is a hint that can be passed in to allow for efficient sizing of the byte array before attempting to marshall the object. The more accurate this estimate is, the less likely byte[]s will need to be resized to hold the byte stream generated by marshalling the object.
        Parameters:
        obj - object to convert to a byte array. Must not be null.
        estimatedSize - an estimate of how large the resulting byte array may be
        Returns:
        a byte array with the marshalled form of the object
        Throws:
        IOException - if marshalling cannot complete due to some I/O error
        InterruptedException - if the marshalling was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more unmarshalling should be attempted.
      • objectToByteBuffer

        byte[] objectToByteBuffer​(Object obj)
                           throws IOException,
                                  InterruptedException
        Marshalls an object to a byte array.
        Parameters:
        obj - object to convert to a byte array. Must not be null.
        Returns:
        a byte array
        Throws:
        IOException - if marshalling cannot complete due to some I/O error
        InterruptedException - if the marshalling process was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more marshalling should be attempted.
      • objectFromByteBuffer

        Object objectFromByteBuffer​(byte[] buf)
                             throws IOException,
                                    ClassNotFoundException
        Unmarshalls an object from a byte array.
        Parameters:
        buf - byte array containing the binary representation of an object. Must not be null.
        Returns:
        an object
        Throws:
        IOException - if unmarshalling cannot complete due to some I/O error
        ClassNotFoundException - if the class of the object trying to unmarshall is unknown
      • objectFromByteBuffer

        Object objectFromByteBuffer​(byte[] buf,
                                    int offset,
                                    int length)
                             throws IOException,
                                    ClassNotFoundException
        Unmarshalls an object from a specific portion of a byte array.
        Parameters:
        buf - byte array containing the binary representation of an object. Must not be null.
        offset - point in buffer to start reading
        length - number of bytes to consider
        Returns:
        an object
        Throws:
        IOException - if unmarshalling cannot complete due to some I/O error
        ClassNotFoundException - if the class of the object trying to unmarshall is unknown
      • objectToBuffer

        ByteBuffer objectToBuffer​(Object o)
                           throws IOException,
                                  InterruptedException
        A method that returns an instance of ByteBuffer, which allows direct access to the byte array with minimal array copying
        Parameters:
        o - object to marshall
        Throws:
        IOException - if marshalling cannot complete due to some I/O error
        InterruptedException - if the marshalling process was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more marshalling should be attempted.
      • isMarshallable

        boolean isMarshallable​(Object o)
                        throws Exception
        A method that checks whether the given object is marshallable as per the rules of this marshaller.
        Parameters:
        o - object to verify whether it's marshallable or not
        Returns:
        true if the object is marshallable, otherwise false
        Throws:
        Exception - if while checking whether the object was serializable or not, an exception arose
      • getBufferSizePredictor

        BufferSizePredictor getBufferSizePredictor​(Object o)
        Returns a marshalled payload size predictor for a particular type. Accurate prediction of a type's serialized payload size helps avoid unnecessary copying and speeds up application performance.
        Parameters:
        o - Object for which serialized predictor will be returned
        Returns:
        an instance of BufferSizePredictor
        Throws:
        NullPointerException - if o is null
      • mediaType

        org.infinispan.commons.dataconversion.MediaType mediaType()
        Returns:
        the MediaType associated with the content produced by the marshaller
      • start

        default void start()
        Perform any initialization required before the marshaller is used.
      • stop

        default void stop()
        Stop the marshaller. Implementations of this method should clear up any cached data, or close any resources while marshalling/unmarshalling that have not been already closed.