Class RemoteFileDescriptorBase<T>

java.lang.Object
org.newsclub.net.unix.rmi.RemoteFileDescriptorBase<T>
All Implemented Interfaces:
Closeable, Externalizable, Serializable, AutoCloseable, org.newsclub.net.unix.FileDescriptorAccess
Direct Known Subclasses:
RemoteFileDescriptor, RemoteFileInput, RemoteFileOutput

public abstract class RemoteFileDescriptorBase<T> extends Object implements Externalizable, Closeable, org.newsclub.net.unix.FileDescriptorAccess
A wrapper that allows a FileDescriptor be sent via RMI over AF_UNIX sockets.
Author:
Christian Kohlschütter
See Also:
  • Field Details

    • resource

      protected final transient AtomicReference<T> resource
      An optional, closeable resource that is related to this instance. If the reference is non-null, this will be closed upon close(). For unidirectional implementations, this could be the corresponding input/output stream. For bidirectional implementations (e.g., a Socket, Pipe, etc.), this should close both directions.
  • Method Details

    • writeExternal

      public final void writeExternal(ObjectOutput objOut) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public final void readExternal(ObjectInput objIn) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • getFileDescriptor

      public final FileDescriptor getFileDescriptor()
      Returns the file descriptor. This is either the original one that was specified in the constructor or a copy that was sent via RMI over an AF_UNIX connection as part of an ancillary message.
      Specified by:
      getFileDescriptor in interface org.newsclub.net.unix.FileDescriptorAccess
      Returns:
      The file descriptor.
    • getMagicValue

      protected final int getMagicValue()
      Returns the "magic value" for this type of file descriptor. The magic value consists of an indicator ("this is a file descriptor") as well as its capabilities (read/write). It is used to prevent, for example, converting an output stream to an input stream.
      Returns:
      The magic value.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException