Skip to content

Commit

Permalink
Use abstract class instead of interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed May 15, 2016
1 parent c6861dd commit 2c15910
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
10 changes: 5 additions & 5 deletions core/server/src/main/java/alluxio/worker/SessionCleaner.java
Expand Up @@ -28,7 +28,7 @@
public final class SessionCleaner implements Runnable { public final class SessionCleaner implements Runnable {
private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE); private static final Logger LOG = LoggerFactory.getLogger(Constants.LOGGER_TYPE);
/** The object which supports cleaning up sessions. */ /** The object which supports cleaning up sessions. */
private final SessionCleanable mSessionCleanable; private final SessionCleanupCallback mSessionCleanupCallback;
/** Milliseconds between each check. */ /** Milliseconds between each check. */
private final int mCheckIntervalMs; private final int mCheckIntervalMs;


Expand All @@ -38,10 +38,10 @@ public final class SessionCleaner implements Runnable {
/** /**
* Creates a new instance of {@link SessionCleaner}. * Creates a new instance of {@link SessionCleaner}.
* *
* @param sessionCleanable the session tracker to periodically clean * @param sessionCleanupCallback the session clean up callback which will periodically be invoked
*/ */
public SessionCleaner(SessionCleanable sessionCleanable) { public SessionCleaner(SessionCleanupCallback sessionCleanupCallback) {
mSessionCleanable = sessionCleanable; mSessionCleanupCallback = sessionCleanupCallback;
mCheckIntervalMs = mCheckIntervalMs =
WorkerContext.getConf().getInt(Constants.WORKER_BLOCK_HEARTBEAT_INTERVAL_MS); WorkerContext.getConf().getInt(Constants.WORKER_BLOCK_HEARTBEAT_INTERVAL_MS);


Expand All @@ -66,7 +66,7 @@ public void run() {


// Check if any sessions have become zombies, if so clean them up // Check if any sessions have become zombies, if so clean them up
lastCheckMs = System.currentTimeMillis(); lastCheckMs = System.currentTimeMillis();
mSessionCleanable.cleanupSessions(); mSessionCleanupCallback.cleanupSessions();
} }
} }


Expand Down
Expand Up @@ -14,9 +14,9 @@
/** /**
* Interface for classes which track sessions and provide a method to clean any expired sessions. * Interface for classes which track sessions and provide a method to clean any expired sessions.
*/ */
public interface SessionCleanable { public abstract class SessionCleanupCallback {
/** /**
* Runs a session inspection and cleans up sessions which have expired. * Runs a session inspection and cleans up sessions which have expired.
*/ */
void cleanupSessions(); public abstract void cleanupSessions();
} }
Expand Up @@ -31,7 +31,7 @@
import alluxio.wire.WorkerNetAddress; import alluxio.wire.WorkerNetAddress;
import alluxio.worker.AbstractWorker; import alluxio.worker.AbstractWorker;
import alluxio.worker.SessionCleaner; import alluxio.worker.SessionCleaner;
import alluxio.worker.SessionCleanable; import alluxio.worker.SessionCleanupCallback;
import alluxio.worker.WorkerContext; import alluxio.worker.WorkerContext;
import alluxio.worker.WorkerIdRegistry; import alluxio.worker.WorkerIdRegistry;
import alluxio.worker.block.io.BlockReader; import alluxio.worker.block.io.BlockReader;
Expand Down Expand Up @@ -594,7 +594,7 @@ public void sessionHeartbeat(long sessionId, List<Long> metrics) {
* Sets up the session cleaner thread. This logic is isolated for testing the session cleaner. * Sets up the session cleaner thread. This logic is isolated for testing the session cleaner.
*/ */
private void setupSessionCleaner() { private void setupSessionCleaner() {
mSessionCleaner = new SessionCleaner(new SessionCleanable() { mSessionCleaner = new SessionCleaner(new SessionCleanupCallback() {
/** /**
* Cleans up after sessions, to prevent zombie sessions holding local resources. * Cleans up after sessions, to prevent zombie sessions holding local resources.
*/ */
Expand Down
Expand Up @@ -25,7 +25,7 @@
import alluxio.util.network.NetworkAddressUtils.ServiceType; import alluxio.util.network.NetworkAddressUtils.ServiceType;
import alluxio.worker.AbstractWorker; import alluxio.worker.AbstractWorker;
import alluxio.worker.SessionCleaner; import alluxio.worker.SessionCleaner;
import alluxio.worker.SessionCleanable; import alluxio.worker.SessionCleanupCallback;
import alluxio.worker.WorkerContext; import alluxio.worker.WorkerContext;
import alluxio.worker.block.BlockWorker; import alluxio.worker.block.BlockWorker;


Expand Down Expand Up @@ -88,7 +88,7 @@ public FileSystemWorker(BlockWorker blockWorker) throws IOException {
NetworkAddressUtils.getConnectAddress(ServiceType.MASTER_RPC, mConf), mConf); NetworkAddressUtils.getConnectAddress(ServiceType.MASTER_RPC, mConf), mConf);


// Setup session cleaner // Setup session cleaner
mSessionCleaner = new SessionCleaner(new SessionCleanable() { mSessionCleaner = new SessionCleaner(new SessionCleanupCallback() {
/** /**
* Cleans up after sessions, to prevent zombie sessions holding ufs resources. * Cleans up after sessions, to prevent zombie sessions holding ufs resources.
*/ */
Expand Down
Expand Up @@ -20,7 +20,7 @@
import alluxio.Sessions; import alluxio.Sessions;
import alluxio.underfs.UnderFileSystem; import alluxio.underfs.UnderFileSystem;
import alluxio.util.io.PathUtils; import alluxio.util.io.PathUtils;
import alluxio.worker.SessionCleanable; import alluxio.worker.SessionCleanupCallback;
import alluxio.worker.SessionCleaner; import alluxio.worker.SessionCleaner;
import alluxio.worker.WorkerContext; import alluxio.worker.WorkerContext;
import alluxio.worker.WorkerIdRegistry; import alluxio.worker.WorkerIdRegistry;
Expand Down Expand Up @@ -154,7 +154,8 @@ public void cleanupSessionsTest() throws Exception {
when(mSessions.getTimedOutSessions()).thenReturn(sessions); when(mSessions.getTimedOutSessions()).thenReturn(sessions);
Whitebox.invokeMethod(mBlockWorker, "setupSessionCleaner"); Whitebox.invokeMethod(mBlockWorker, "setupSessionCleaner");
SessionCleaner cleaner = Whitebox.getInternalState(mBlockWorker, "mSessionCleaner"); SessionCleaner cleaner = Whitebox.getInternalState(mBlockWorker, "mSessionCleaner");
SessionCleanable cleanable = Whitebox.getInternalState(cleaner, "mSessionCleanable"); SessionCleanupCallback cleanable =
Whitebox.getInternalState(cleaner, "mSessionCleanupCallback");
cleanable.cleanupSessions(); cleanable.cleanupSessions();
verify(mSessions).removeSession(sessionId); verify(mSessions).removeSession(sessionId);
verify(mBlockStore).cleanupSession(sessionId); verify(mBlockStore).cleanupSession(sessionId);
Expand Down

0 comments on commit 2c15910

Please sign in to comment.