tachyon.client.file.FileSystemContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tachyon-client-unshaded Show documentation
Show all versions of tachyon-client-unshaded Show documentation
Implementation of Tachyon client module
The newest version!
/*
* Licensed to the University of California, Berkeley under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package tachyon.client.file;
import tachyon.client.ClientContext;
import tachyon.client.FileSystemMasterClient;
import tachyon.client.block.TachyonBlockStore;
/**
* A shared context in each client JVM for common File System client functionality such as a pool
* of master clients. This class is thread safe.
*/
public enum FileSystemContext {
INSTANCE;
private FileSystemMasterClientPool mFileSystemMasterClientPool;
private final TachyonBlockStore mTachyonBlockStore;
/**
* Creates a new file stream context.
*/
FileSystemContext() {
mFileSystemMasterClientPool =
new FileSystemMasterClientPool(ClientContext.getMasterAddress());
mTachyonBlockStore = TachyonBlockStore.get();
}
/**
* Acquires a block master client from the block master client pool.
*
* @return the acquired block master client
*/
public FileSystemMasterClient acquireMasterClient() {
return mFileSystemMasterClientPool.acquire();
}
/**
* Releases a block master client into the block master client pool.
*
* NOTE: the client pool is already thread-safe. Synchronizing on FileSystemContext will lead to
* deadlock: thread A acquired a client and awaits for FileSystemContext to release the client,
* while thread B holds the lock of FileSystemContext but waits for available clients.
*
* @param masterClient a block master client to release
*/
public void releaseMasterClient(FileSystemMasterClient masterClient) {
mFileSystemMasterClientPool.release(masterClient);
}
/**
* @return the Tachyon block store
*/
public synchronized TachyonBlockStore getTachyonBlockStore() {
return mTachyonBlockStore;
}
/**
* Re-initializes the Block Store context. This method should only be used in
* {@link ClientContext}.
*/
public synchronized void reset() {
mFileSystemMasterClientPool.close();
mFileSystemMasterClientPool =
new FileSystemMasterClientPool(ClientContext.getMasterAddress());
}
}