@ThreadSafe public final class FileSystemContext extends Object implements Closeable
FileSystem
. Usually, one user
only needs one instance of FileSystemContext
.
NOTE: The context maintains a pool of file system master clients that is already thread-safe.
Synchronizing FileSystemContext
methods could lead to deadlock: thread A attempts to
acquire a client when there are no clients left in the pool and blocks holding a lock on the
FileSystemContext
, when thread B attempts to release a client it owns it is unable to do
so, because thread A holds the lock on FileSystemContext
.
Modifier and Type | Method and Description |
---|---|
CloseableResource<BlockMasterClient> |
acquireBlockMasterClientResource()
Acquires a block master client resource from the block master client pool.
|
FileSystemMasterClient |
acquireMasterClient()
Acquires a file system master client from the file system master client pool.
|
CloseableResource<FileSystemMasterClient> |
acquireMasterClientResource()
Acquires a file system master client from the file system master client pool.
|
io.netty.channel.Channel |
acquireNettyChannel(WorkerNetAddress workerNetAddress)
Acquires a netty channel from the channel pools.
|
static void |
clearCache()
Clears the context cache.
|
void |
close()
Closes all the resources associated with the context.
|
static FileSystemContext |
create(Subject subject,
MasterInquireClient masterInquireClient)
This method is provided for testing, use the
get() methods. |
static FileSystemContext |
get() |
static FileSystemContext |
get(Subject subject) |
WorkerNetAddress |
getLocalWorker() |
InetSocketAddress |
getMasterAddress() |
MasterInquireClient |
getMasterInquireClient() |
Subject |
getParentSubject() |
boolean |
hasLocalWorker() |
void |
releaseMasterClient(FileSystemMasterClient masterClient)
Releases a file system master client into the file system master client pool.
|
void |
releaseNettyChannel(WorkerNetAddress workerNetAddress,
io.netty.channel.Channel channel)
Releases a netty channel to the channel pools.
|
void |
reset(InstancedConfiguration configuration)
Resets the context.
|
public static FileSystemContext get()
public static FileSystemContext get(Subject subject)
subject
- the subject associated with this contextpublic static FileSystemContext create(Subject subject, MasterInquireClient masterInquireClient)
get()
methods. The
returned context object will not be cached automatically.subject
- the parent subject, set to null if not presentmasterInquireClient
- the client to use for determining the master; note that if the
context is reset, this client will be replaced with a new masterInquireClient based on
global configurationpublic static void clearCache()
public void close() throws IOException
FileSystem
associated with this FileSystemContext
.close
in interface Closeable
close
in interface AutoCloseable
IOException
public void reset(InstancedConfiguration configuration) throws IOException
AbstractFileSystem
and tests to
reset the default file system context.configuration
- the instance configurationIOException
public Subject getParentSubject()
public InetSocketAddress getMasterAddress() throws UnavailableException
UnavailableException
- if the master address cannot be determinedpublic MasterInquireClient getMasterInquireClient()
public FileSystemMasterClient acquireMasterClient()
public void releaseMasterClient(FileSystemMasterClient masterClient)
masterClient
- a file system master client to releasepublic CloseableResource<FileSystemMasterClient> acquireMasterClientResource()
Closeable
.public CloseableResource<BlockMasterClient> acquireBlockMasterClientResource()
Closeable
.public io.netty.channel.Channel acquireNettyChannel(WorkerNetAddress workerNetAddress) throws IOException
workerNetAddress
- the network address of the channelIOException
public void releaseNettyChannel(WorkerNetAddress workerNetAddress, io.netty.channel.Channel channel)
workerNetAddress
- the address of the channelchannel
- the channel to releasepublic boolean hasLocalWorker() throws IOException
IOException
public WorkerNetAddress getLocalWorker() throws IOException
IOException
Copyright © 2023. All Rights Reserved.