Add manager context to CleanupMaid to allow management service access in cleanup() method

This commit is contained in:
Kelven Yang 2011-05-02 18:27:13 -07:00
parent f57fc2beb7
commit 824f0586f7
3 changed files with 32 additions and 29 deletions

View File

@ -164,12 +164,14 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
}
@Override
@DB
public long pushCheckPoint(CleanupMaid context) {
long seq = _maidDao.pushCleanupDelegate(_msId, 0, context.getClass().getName(), context);
return seq;
}
@Override
@DB
public void updateCheckPointState(long taskId, CleanupMaid updatedContext) {
CheckPointVO task = _maidDao.createForUpdate();
task.setDelegate(updatedContext.getClass().getName());
@ -178,6 +180,7 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
}
@Override
@DB
public void popCheckPoint(long taskId) {
_maidDao.remove(taskId);
}
@ -187,7 +190,7 @@ public class CheckPointManagerImpl implements CheckPointManager, Manager, Cluste
CleanupMaid delegate = (CleanupMaid)SerializerHelper.fromSerializedString(task.getContext());
assert delegate.getClass().getName().equals(task.getDelegate()) : "Deserializer says " + delegate.getClass().getName() + " but it's suppose to be " + task.getDelegate();
int result = delegate.cleanup();
int result = delegate.cleanup(this);
if (result <= 0) {
if (result == 0) {
s_logger.info("Successfully cleaned up " + task.getId());

View File

@ -33,7 +33,7 @@ public interface CleanupMaid {
* indicates the cleanup was unsuccessful but don't retry. Positive number
* indicates the cleanup was unsuccessful and retry in this many seconds.
*/
int cleanup();
int cleanup(CheckPointManager checkPointMgr);
/**

View File

@ -216,7 +216,7 @@ public class CheckPointManagerTest extends TestCase {
}
@Override
public int cleanup() {
public int cleanup(CheckPointManager checkPointMgr) {
s_logger.debug("Cleanup called for " + seq);
map.remove(seq);
return canBeCleanup ? 0 : -1;