/** * Sleep for period. */ public void sleep() { sleep(this.period); }
this.msgInterval = conf.getInt("hbase.regionserver.msginterval", 3 * 1000); this.sleeper = new Sleeper(this.msgInterval, this);
@Override public void stop(String reason) { LOG.info("Stopping due to: "+reason); this.stopped = true; sleeper.skipSleepCycle(); }
this.sleeper.getPeriod(), 1000 * 60 * 5); RetryCounter rc = rcf.create(); while (keepLooping()) { long sleepTime = rc.getBackoffTimeAndIncrementAttempts(); LOG.warn("reportForDuty failed; sleeping {} ms and then retrying.", sleepTime); this.sleeper.sleep(sleepTime); } else { handleReportForDutyResponse(w); this.sleeper.sleep();
/** * If configured to put regions on active master, * wait till a backup master becomes active. * Otherwise, loop till the server is stopped or aborted. */ @Override protected void waitForMasterActive(){ if (maintenanceMode) { return; } boolean tablesOnMaster = LoadBalancer.isTablesOnMaster(conf); while (!(tablesOnMaster && activeMaster) && !isStopped() && !isAborted()) { sleeper.sleep(); } }
@Override public void abort(String reason, Throwable error) { LOG.error(HBaseMarkers.FATAL, "Aborting on: "+reason, error); this.aborted = true; this.stopped = true; sleeper.skipSleepCycle(); }
this.sleeper = new Sleeper(1000, this);
@Override public void run() { try { initialize(); while (!stopped) { this.sleeper.sleep(); } } catch (Exception e) { abort(e.getMessage(), e); } this.rpcServer.stop(); }
/** * Stops the regionserver. * @param msg Status message * @param force True if this is a regionserver abort * @param user The user executing the stop request, or null if no user is associated */ public void stop(final String msg, final boolean force, final User user) { if (!this.stopped) { LOG.info("***** STOPPING region server '" + this + "' *****"); if (this.rsHost != null) { // when forced via abort don't allow CPs to override try { this.rsHost.preStop(msg, user); } catch (IOException ioe) { if (!force) { LOG.warn("The region server did not stop", ioe); return; } LOG.warn("Skipping coprocessor exception on preStop() due to forced shutdown", ioe); } } this.stopped = true; LOG.info("STOPPED: " + msg); // Wakes run() if it is sleeping sleeper.skipSleepCycle(); } }
/** * @param p Period at which we should run. Will be adjusted appropriately * should we find work and it takes time to complete. * @param stopper When {@link Stoppable#isStopped()} is true, this thread will * cleanup and exit cleanly. */ public Chore(String name, final int p, final Stoppable stopper) { super(name); this.sleeper = new Sleeper(p, stopper); this.stopper = stopper; }
/** * Sleep for period. */ public void sleep() { sleep(this.period); }
"Region server startup failed"); } finally { sleeper.skipSleepCycle();
@Test public void testSnooze() throws Exception { Thread t = new Thread(new Sleeper()); t.start(); t.join(); }
private void loop() { while (!this.stopped) { stopSleeper.sleep(); } }
sleeper.skipSleepCycle();
public class ProcessMain { public static void main(String[] args) { for(int i = 0 ; i<4; i++){ new Thread(new StackOverflowPinger(i)).run(); new Thread(new Sleeper(i)).run(); } } }
/** * Sleep for period. */ protected void sleep() { this.sleeper.sleep(); }
/** * If the thread is currently sleeping, trigger the core to happen immediately. * If it's in the middle of its operation, will begin another operation * immediately after finishing this one. */ public void triggerNow() { this.sleeper.skipSleepCycle(); }
this.sleeper = new Sleeper(this.msgInterval, this);
/** * Sleep for period. */ public void sleep() { sleep(System.currentTimeMillis()); }