use of java.util.Timer in project hive by apache.
the class HeartbeatFactory method newInstance.
/** Creates a new {@link HeartbeatTimerTask} instance for the {@link Lock} and schedules it. */
Timer newInstance(IMetaStoreClient metaStoreClient, LockFailureListener listener, Long transactionId, Collection<Table> tableDescriptors, long lockId, int heartbeatPeriod) {
Timer heartbeatTimer = new Timer("hive-lock-heartbeat[lockId=" + lockId + ", transactionId=" + transactionId + "]", true);
HeartbeatTimerTask task = new HeartbeatTimerTask(metaStoreClient, listener, transactionId, tableDescriptors, lockId);
heartbeatTimer.schedule(task, TimeUnit.SECONDS.toMillis(heartbeatPeriod), TimeUnit.SECONDS.toMillis(heartbeatPeriod));
LOG.debug("Scheduled heartbeat timer task: {}", heartbeatTimer);
return heartbeatTimer;
}
use of java.util.Timer in project hive by apache.
the class ScriptOperator method close.
@Override
public void close(boolean abort) throws HiveException {
boolean new_abort = abort;
if (!abort) {
if (scriptError != null) {
throw new HiveException(ErrorMsg.SCRIPT_GENERIC_ERROR.getErrorCodedMsg(), scriptError);
}
// everything ok. try normal shutdown
try {
try {
if (scriptOutWriter != null) {
scriptOutWriter.close();
}
} catch (IOException e) {
if (isBrokenPipeException(e) && allowPartialConsumption()) {
LOG.warn("Got broken pipe: ignoring exception");
} else {
if (isBrokenPipeException(e)) {
displayBrokenPipeInfo();
}
throw e;
}
}
int exitVal = 0;
if (scriptPid != null) {
exitVal = scriptPid.waitFor();
}
if (exitVal != 0) {
LOG.error("Script failed with code " + exitVal);
new_abort = true;
}
} catch (IOException e) {
LOG.error("Got ioexception: " + e.getMessage());
e.printStackTrace();
new_abort = true;
} catch (InterruptedException e) {
}
} else {
// error code of the child process if possible.
try {
// Interrupt the current thread after 1 second
final Thread mythread = Thread.currentThread();
Timer timer = new Timer(true);
timer.schedule(new TimerTask() {
@Override
public void run() {
mythread.interrupt();
}
}, 1000);
// Wait for the child process to finish
int exitVal = 0;
if (scriptPid != null) {
scriptPid.waitFor();
}
// Cancel the timer
timer.cancel();
// Output the exit code
LOG.error("Script exited with code " + exitVal);
} catch (InterruptedException e) {
// Ignore
LOG.error("Script has not exited yet. It will be killed.");
}
}
// try these best effort
try {
if (outThread != null) {
outThread.join(0);
}
} catch (Exception e) {
LOG.warn("Exception in closing outThread: " + StringUtils.stringifyException(e));
}
try {
if (errThread != null) {
errThread.join(0);
}
} catch (Exception e) {
LOG.warn("Exception in closing errThread: " + StringUtils.stringifyException(e));
}
try {
if (scriptPid != null) {
scriptPid.destroy();
}
} catch (Exception e) {
LOG.warn("Exception in destroying scriptPid: " + StringUtils.stringifyException(e));
}
super.close(new_abort);
if (new_abort && !abort) {
throw new HiveException(ErrorMsg.SCRIPT_CLOSING_ERROR.getErrorCodedMsg());
}
}
use of java.util.Timer in project zeppelin by apache.
the class ZeppelinClient method addRoutines.
private void addRoutines() {
schedulerService.add(ZeppelinHeartbeat.newInstance(this), 10, 1 * MIN);
new Timer().schedule(new java.util.TimerTask() {
@Override
public void run() {
watcherSession = openWatcherSession();
}
}, 5000);
}
use of java.util.Timer in project UltimateAndroid by cymcsg.
the class CircleProgressActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.circle_progress_activity_my);
donutProgress = (DonutProgress) findViewById(R.id.donut_progress);
circleProgress = (CircleProgress) findViewById(R.id.circle_progress);
arcProgress = (ArcProgress) findViewById(R.id.arc_progress);
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
donutProgress.setProgress(donutProgress.getProgress() + 1);
circleProgress.setProgress(circleProgress.getProgress() + 1);
arcProgress.setProgress(arcProgress.getProgress() + 1);
}
});
}
}, 1000, 100);
}
use of java.util.Timer in project PlayerHater by chrisrhoden.
the class PlaylistSupportingPlayer method startWithFade.
public void startWithFade() throws IllegalStateException {
setVolume(0, 0);
start();
final Timer timer = new Timer(true);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
setVolume(mLeftVolume + 0.1f, mRightVolume + 01.f);
if (mLeftVolume >= 1.0f || mRightVolume >= 1.0f) {
timer.cancel();
timer.purge();
}
}
};
timer.schedule(timerTask, 200, 200);
}
Aggregations