public boolean setState( SystemState state ) { Lock lock = getLock().writeLock(); lock.lock(); try { getSystemStatusInternal().setState( state ); return true; } finally { lock.unlock(); } }
/** * Returns the SystemStatus, guaranteeing it's consistent state. */ public SystemStatus getSystemStatus() { updateSystemStatusIfNeeded( false ); Lock lock = getLock().readLock(); lock.lock(); try { return getSystemStatusInternal(); } finally { lock.unlock(); } }
/** * Will check is needed a SystemStatus update (using retain time) and will perform it. * * @param forced if update is forced (performs update forcefully) */ protected void updateSystemStatusIfNeeded( boolean forced ) { long currentTime = System.currentTimeMillis(); if ( forced || ( currentTime - lastUpdate > 30000 ) ) { Lock lock = getLock().writeLock(); lock.lock(); try { // maybe someone did the job, while we were blocked if ( forced || ( currentTime - lastUpdate > 30000 ) ) { renewSystemStatus( getSystemStatusInternal() ); lastUpdate = currentTime; } } finally { lock.unlock(); } } }