Module org.newsclub.net.unix.rmi
Package org.newsclub.net.unix.rmi
Class RemoteFileDescriptorBase<T>
java.lang.Object
org.newsclub.net.unix.rmi.RemoteFileDescriptorBase<T>
- Type Parameters:
T
- The resource type.
- All Implemented Interfaces:
Closeable
,Externalizable
,Serializable
,AutoCloseable
,FileDescriptorAccess
- Direct Known Subclasses:
RemoteFileDescriptor
,RemoteFileInput
,RemoteFileOutput
public abstract class RemoteFileDescriptorBase<T>
extends Object
implements Externalizable, Closeable, FileDescriptorAccess
A wrapper that allows a
FileDescriptor
be sent via RMI over AF_UNIX sockets.- Author:
- Christian Kohlschütter
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AtomicReference
<T> An optional, closeable resource that is related to this instance. -
Constructor Summary
ConstructorDescriptionCreates an uninitialized instance; used for externalization. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
final FileDescriptor
Returns the file descriptor.protected final int
Returns the "magic value" for this type of file descriptor.final void
readExternal
(ObjectInput objIn) final void
writeExternal
(ObjectOutput objOut)
-
Field Details
-
resource
An optional, closeable resource that is related to this instance. If the reference is non-null, this will be closed uponclose()
. 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.
-
-
Constructor Details
-
RemoteFileDescriptorBase
public RemoteFileDescriptorBase()Creates an uninitialized instance; used for externalization.- See Also:
-
-
Method Details
-
writeExternal
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
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 interfaceFileDescriptorAccess
- 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
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-