List of usage examples for org.joda.time Duration getStandardMinutes
public long getStandardMinutes()
From source file:org.apache.beam.sdk.nexmark.NexmarkLauncher.java
License:Apache License
/** * Monitor the performance and progress of a running job. Return final performance if it was * measured.//from ww w.ja va2 s .c o m */ @Nullable private NexmarkPerf monitor(NexmarkQuery query) { if (!options.getMonitorJobs()) { return null; } if (configuration.debug) { NexmarkUtils.console("Waiting for main pipeline to 'finish'"); } else { NexmarkUtils.console("--debug=false, so job will not self-cancel"); } PipelineResult job = mainResult; PipelineResult publisherJob = publisherResult; List<NexmarkPerf.ProgressSnapshot> snapshots = new ArrayList<>(); long startMsSinceEpoch = System.currentTimeMillis(); long endMsSinceEpoch = -1; if (options.getRunningTimeMinutes() != null) { endMsSinceEpoch = startMsSinceEpoch + Duration.standardMinutes(options.getRunningTimeMinutes()).getMillis() - Duration.standardSeconds(configuration.preloadSeconds).getMillis(); } long lastActivityMsSinceEpoch = -1; NexmarkPerf perf = null; boolean waitingForShutdown = false; boolean cancelJob = false; boolean publisherCancelled = false; List<String> errors = new ArrayList<>(); while (true) { long now = System.currentTimeMillis(); if (endMsSinceEpoch >= 0 && now > endMsSinceEpoch && !waitingForShutdown) { NexmarkUtils.console("Reached end of test, cancelling job"); try { cancelJob = true; job.cancel(); } catch (IOException e) { throw new RuntimeException("Unable to cancel main job: ", e); } if (publisherResult != null) { try { publisherJob.cancel(); } catch (IOException e) { throw new RuntimeException("Unable to cancel publisher job: ", e); } publisherCancelled = true; } waitingForShutdown = true; } PipelineResult.State state = job.getState(); NexmarkUtils.console("%s %s%s", state, queryName, waitingForShutdown ? " (waiting for shutdown)" : ""); NexmarkPerf currPerf; if (configuration.debug) { currPerf = currentPerf(startMsSinceEpoch, now, job, snapshots, query.eventMonitor, query.resultMonitor); } else { currPerf = null; } if (perf == null || perf.anyActivity(currPerf)) { lastActivityMsSinceEpoch = now; } if (options.isStreaming() && !waitingForShutdown) { Duration quietFor = new Duration(lastActivityMsSinceEpoch, now); long fatalCount = new MetricsReader(job, query.getName()).getCounterMetric("fatal"); if (fatalCount == -1) { fatalCount = 0; } if (fatalCount > 0) { NexmarkUtils.console("ERROR: job has fatal errors, cancelling."); errors.add(String.format("Pipeline reported %s fatal errors", fatalCount)); waitingForShutdown = true; cancelJob = true; } else if (configuration.debug && configuration.numEvents > 0 && currPerf.numEvents == configuration.numEvents && currPerf.numResults >= 0 && quietFor.isLongerThan(DONE_DELAY)) { NexmarkUtils.console("streaming query appears to have finished waiting for completion."); waitingForShutdown = true; } else if (quietFor.isLongerThan(STUCK_TERMINATE_DELAY)) { NexmarkUtils.console( "ERROR: streaming query appears to have been stuck for %d minutes, cancelling job.", quietFor.getStandardMinutes()); errors.add(String.format("Cancelling streaming job since it appeared stuck for %d min.", quietFor.getStandardMinutes())); waitingForShutdown = true; cancelJob = true; } else if (quietFor.isLongerThan(STUCK_WARNING_DELAY)) { NexmarkUtils.console("WARNING: streaming query appears to have been stuck for %d min.", quietFor.getStandardMinutes()); } if (cancelJob) { try { job.cancel(); } catch (IOException e) { throw new RuntimeException("Unable to cancel main job: ", e); } } } perf = currPerf; boolean running = true; switch (state) { case UNKNOWN: case UNRECOGNIZED: case STOPPED: case RUNNING: // Keep going. break; case DONE: // All done. running = false; break; case CANCELLED: running = false; if (!cancelJob) { errors.add("Job was unexpectedly cancelled"); } break; case FAILED: case UPDATED: // Abnormal termination. running = false; errors.add("Job was unexpectedly updated"); break; } if (!running) { break; } if (lastActivityMsSinceEpoch == now) { NexmarkUtils.console("new perf %s", perf); } else { NexmarkUtils.console("no activity"); } try { Thread.sleep(PERF_DELAY.getMillis()); } catch (InterruptedException e) { Thread.interrupted(); NexmarkUtils.console("Interrupted: pipeline is still running"); } } perf.errors = errors; perf.snapshots = snapshots; if (publisherResult != null) { NexmarkUtils.console("Shutting down publisher pipeline."); try { if (!publisherCancelled) { publisherJob.cancel(); } publisherJob.waitUntilFinish(Duration.standardMinutes(5)); } catch (IOException e) { throw new RuntimeException("Unable to cancel publisher job: ", e); } } return perf; }
From source file:org.cook_e.cook_e.CookActivity.java
License:Open Source License
@Override public boolean onOptionsItemSelected(MenuItem item) { Step step;//www . j a v a 2s.com switch (item.getItemId()) { case R.id.previous: // User chose the "previous" item, step = mSchedule.getPrevStep(); if (step != null) { setCurrentStep(step, mSchedule.getCurrentStepRecipe(), false); } return true; case R.id.next: // User chose the "next" item, boolean nextIsNew = mSchedule.getCurrStepIndex() == mSchedule.getMaxVisitedStepIndex(); Step originalStep = mSchedule.getCurrStep(); Recipe originalRecipe = mSchedule.getCurrentStepRecipe(); step = mSchedule.getNextStep(); Recipe recipe = mSchedule.getCurrentStepRecipe(); if (nextIsNew) { // updates learner Instant mEndInstant = new Instant(); Duration stepDuration = new Duration(mStartInstant, mEndInstant); mStartInstant = mEndInstant; if (!originalStep.isSimultaneous()) { try { mTimeLearner.learnStep(originalRecipe, originalStep, stepDuration); } catch (SQLException e) { new Builder(this).setTitle(R.string.failed_to_learn_time) .setMessage(e.getLocalizedMessage()).show(); } } } if (step != null) { setCurrentStep(step, recipe, nextIsNew); } else if (mActiveSimultaneousSteps != 0) { // Explain to the user why they cannot advance new AlertDialog.Builder(this).setTitle(R.string.dialog_title_waiting_for_step) .setMessage(R.string.dialog_waiting_for_step).show(); } else { // The final step has been completed! Instant mLastInstant = new Instant(); Duration cookDuration = new Duration(mFirstInstant, mLastInstant); String exitMessage = "Unoptimized: " + mSchedule.mOriginalEstimatedTime + " min." + "\nOptimized: " + mSchedule.mOptimizedEstimatedTime + " min." + "\n\nActual: " + cookDuration.getStandardMinutes() + " min."; new AlertDialog.Builder(this).setTitle(R.string.meal_completed).setMessage(exitMessage) .setCancelable(false).setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }).show(); } return true; default: // If we got here, the user's action was not recognized. // Invoke the superclass to handle it. return super.onOptionsItemSelected(item); } }
From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java
License:Open Source License
/** * This function compares the validity ranges of the generators. * * @param compareGenerator/*from w w w . j a v a 2 s . c o m*/ * The compare generator. * @param generators * All generators the compare generator will be compared against. If the compare generator is contained, it * will be ignored. * @return <ul> * <li>True: The validity range of the compare generator does not overlap the validity ranges of the other * generators.</li> * <li>False: The validity range of the compare generator overlaps one validity range of the other generators. * </li> * </ul> */ private static boolean compareGeneratorValidityOverlap(final IRainfallGenerator compareGenerator, final IRainfallGenerator[] generators) { /* No generators available, to compare to. */ if (generators.length == 0) return true; /* The interval of the compare generator. */ final Interval compareInterval = new Interval(new DateTime(compareGenerator.getValidFrom()), new DateTime(compareGenerator.getValidTo())); /* Check if the interval overlaps one of the other intervals. */ for (final IRainfallGenerator generator : generators) { /* Do not compare the compare generator with itself. */ if (compareGenerator.getId().equals(generator.getId())) continue; /* The interval of the generator. */ final Interval interval = new Interval(new DateTime(generator.getValidFrom()), new DateTime(generator.getValidTo())); if (compareInterval.overlaps(interval)) { final Interval overlapInterval = compareInterval.overlap(interval); final Duration overlapDuration = overlapInterval.toDuration(); final long standardMinutes = overlapDuration.getStandardMinutes(); if (standardMinutes > 0) return false; } } return true; }
From source file:org.tanrabad.survey.utils.time.DurationTimePrinter.java
License:Apache License
public static String print(DateTime startTime, DateTime endTime) { Duration duration = new Duration(startTime, endTime); if (duration.getStandardHours() > 0) return String.format(Locale.US, "%d:%02d:%02d", duration.getStandardHours(), duration.getStandardMinutes() % 60, duration.getStandardSeconds() % 60); else// w w w . j a v a 2 s . co m return String.format(Locale.US, "%02d:%02d", duration.getStandardMinutes(), duration.getStandardSeconds() % 60); }
From source file:SkynetBot.DBAccess.java
License:Open Source License
public String getLastSeen(String user, Channel channel) { Connection con;/* ww w . ja v a 2 s . c o m*/ String last = "No records found for a resistance member named " + user + "."; DateTimeFormatter format = DateTimeFormat.forPattern("CCYY-MM-dd HH:mm:ss.S"); try { con = pool.getConnection(timeout); PreparedStatement s = con .prepareStatement("SELECT `last_seen` FROM `users` WHERE `name` = ? AND `channel` = ?"); s.setString(1, user.toLowerCase()); s.setString(2, channel.getName().toLowerCase()); s.executeQuery(); ResultSet rs = s.getResultSet(); while (rs.next()) { DateTime dateTime = format.parseDateTime(rs.getString("last_seen")); Duration duration = new Duration(dateTime, new DateTime()); if (duration.getStandardMinutes() < 120) { last = "Resistance member " + user + " was last seen " + duration.getStandardMinutes() + " minutes ago. Surveillance is ongoing."; } else if (duration.getStandardHours() < 48) { last = "Resistance member " + user + " was last seen " + duration.getStandardHours() + " hours ago. Surveillance is ongoing."; } else { last = "Resistance member " + user + " was last seen " + duration.getStandardDays() + " days ago. Surveillance is ongoing."; } } con.close(); } catch (Exception ex) { last = "ERROR! Data records corrupted! Resistance activity suspected."; Logger.getLogger(DBAccess.class.getName()).log(Level.SEVERE, null, ex); } return last; }