List of usage examples for org.joda.time Duration millis
public static Duration millis(long millis)
From source file:org.apache.druid.indexing.overlord.helpers.TaskLogAutoCleaner.java
License:Apache License
@Override public void schedule(ScheduledExecutorService exec) { log.info("Scheduling TaskLogAutoCleaner with config [%s].", config.toString()); ScheduledExecutors.scheduleWithFixedDelay(exec, Duration.millis(config.getInitialDelay()), Duration.millis(config.getDelay()), new Runnable() { @Override//from w w w . j a v a 2 s .c o m public void run() { try { long timestamp = System.currentTimeMillis() - config.getDurationToRetain(); taskLogKiller.killOlderThan(timestamp); taskStorage.removeTasksOlderThan(timestamp); } catch (Exception ex) { log.error(ex, "Failed to clean-up the task logs"); } } }); }
From source file:org.apache.druid.security.basic.CommonCacheNotifier.java
License:Apache License
private List<ListenableFuture<StatusResponseHolder>> sendUpdate(String updatedAuthorizerPrefix, byte[] serializedUserMap) { List<ListenableFuture<StatusResponseHolder>> futures = new ArrayList<>(); for (NodeType nodeType : NODE_TYPES) { DruidNodeDiscovery nodeDiscovery = discoveryProvider.getForNodeType(nodeType); Collection<DiscoveryDruidNode> nodes = nodeDiscovery.getAllNodes(); for (DiscoveryDruidNode node : nodes) { URL listenerURL = getListenerURL(node.getDruidNode(), baseUrl, updatedAuthorizerPrefix); // best effort, if this fails, remote node will poll and pick up the update eventually Request req = new Request(HttpMethod.POST, listenerURL); req.setContent(MediaType.APPLICATION_JSON, serializedUserMap); BasicAuthDBConfig itemConfig = itemConfigMap.get(updatedAuthorizerPrefix); ListenableFuture<StatusResponseHolder> future = httpClient.go(req, new ResponseHandler(), Duration.millis(itemConfig.getCacheNotificationTimeout())); futures.add(future);//from w ww . ja v a2 s . co m } } return futures; }
From source file:org.apache.druid.server.coordination.ChangeRequestHttpSyncer.java
License:Apache License
private void sync() { if (!startStopLock.awaitStarted(1, TimeUnit.MILLISECONDS)) { log.info("Skipping sync() call for server[%s].", logIdentity); return;//from w w w. ja v a 2s. c o m } lastSyncTime = System.currentTimeMillis(); try { final String req = getRequestString(); BytesAccumulatingResponseHandler responseHandler = new BytesAccumulatingResponseHandler(); log.debug("Sending sync request to server[%s]", logIdentity); ListenableFuture<InputStream> syncRequestFuture = httpClient.go( new Request(HttpMethod.GET, new URL(baseServerURL, req)) .addHeader(HttpHeaders.Names.ACCEPT, SmileMediaTypes.APPLICATION_JACKSON_SMILE) .addHeader(HttpHeaders.Names.CONTENT_TYPE, SmileMediaTypes.APPLICATION_JACKSON_SMILE), responseHandler, Duration.millis(serverHttpTimeout)); log.debug("Sent sync request to [%s]", logIdentity); Futures.addCallback(syncRequestFuture, new FutureCallback<InputStream>() { @Override public void onSuccess(InputStream stream) { synchronized (startStopLock) { if (!startStopLock.awaitStarted(1, TimeUnit.MILLISECONDS)) { log.info("Skipping sync() success for server[%s].", logIdentity); return; } try { if (responseHandler.getStatus() == HttpServletResponse.SC_NO_CONTENT) { log.debug("Received NO CONTENT from server[%s]", logIdentity); lastSuccessfulSyncTime = System.currentTimeMillis(); return; } else if (responseHandler.getStatus() != HttpServletResponse.SC_OK) { handleFailure(new RE("Bad Sync Response.")); return; } log.debug("Received sync response from [%s]", logIdentity); ChangeRequestsSnapshot<T> changes = smileMapper.readValue(stream, responseTypeReferences); log.debug("Finished reading sync response from [%s]", logIdentity); if (changes.isResetCounter()) { log.info("[%s] requested resetCounter for reason [%s].", logIdentity, changes.getResetCause()); counter = null; return; } if (counter == null) { listener.fullSync(changes.getRequests()); } else { listener.deltaSync(changes.getRequests()); } counter = changes.getCounter(); if (initializationLatch.getCount() > 0) { initializationLatch.countDown(); log.info("[%s] synced successfully for the first time.", logIdentity); } if (consecutiveFailedAttemptCount > 0) { consecutiveFailedAttemptCount = 0; log.info("[%s] synced successfully.", logIdentity); } lastSuccessfulSyncTime = System.currentTimeMillis(); } catch (Exception ex) { String logMsg = StringUtils.nonStrictFormat( "Error processing sync response from [%s]. Reason [%s]", logIdentity, ex.getMessage()); if (incrementFailedAttemptAndCheckUnstabilityTimeout()) { log.error(ex, logMsg); } else { log.info("Temporary Failure. %s", logMsg); log.debug(ex, logMsg); } } finally { addNextSyncToWorkQueue(); } } } @Override public void onFailure(Throwable t) { synchronized (startStopLock) { if (!startStopLock.awaitStarted(1, TimeUnit.MILLISECONDS)) { log.info("Skipping sync() failure for URL[%s].", logIdentity); return; } try { handleFailure(t); } finally { addNextSyncToWorkQueue(); } } } private void handleFailure(Throwable t) { String logMsg = StringUtils.nonStrictFormat( "failed to get sync response from [%s]. Return code [%s], Reason: [%s]", logIdentity, responseHandler.getStatus(), responseHandler.getDescription()); if (incrementFailedAttemptAndCheckUnstabilityTimeout()) { log.error(t, logMsg); } else { log.info("Temporary Failure. %s", logMsg); log.debug(t, logMsg); } } }, executor); } catch (Throwable th) { try { String logMsg = StringUtils.nonStrictFormat("Fatal error while fetching segment list from [%s].", logIdentity); if (incrementFailedAttemptAndCheckUnstabilityTimeout()) { log.makeAlert(th, logMsg).emit(); } else { log.info("Temporary Failure. %s", logMsg); log.debug(th, logMsg); } } finally { addNextSyncToWorkQueue(); } } }
From source file:org.apache.druid.server.coordinator.DruidCoordinatorConfig.java
License:Apache License
@Config("druid.coordinator.loadqueuepeon.repeatDelay") public Duration getLoadQueuePeonRepeatDelay() { return Duration.millis(50); }
From source file:org.apache.druid.server.coordinator.DruidCoordinatorConfig.java
License:Apache License
@Config("druid.coordinator.loadqueuepeon.http.repeatDelay") public Duration getHttpLoadQueuePeonRepeatDelay() { return Duration.millis(60000); }
From source file:org.apache.druid.server.coordinator.DruidCoordinatorConfig.java
License:Apache License
@Config("druid.coordinator.loadqueuepeon.http.hostTimeout") public Duration getHttpLoadQueuePeonHostTimeout() { return Duration.millis(300000); }
From source file:org.cook_e.cook_e.ui.TimerFragment.java
License:Open Source License
/** * Rounds a duration down to the nearest second * @param duration the duration to round. Must not be null. * @return a duration up to 1 second less than the provided duration, representing an * integer number of seconds//from w w w . j av a 2 s . c o m */ private static Duration roundDownToSecond(ReadableDuration duration) { final long millis = duration.getMillis(); return Duration.millis(millis - (millis % 1000)); }
From source file:org.cook_e.data.StorageParser.java
License:Open Source License
/** * Parses a serialized list of steps/* ww w.j a v a2s. c o m*/ * @param stepsString a string representing a list of steps, in the format returned by * {@link #serializeRecipeSteps(List)} * @return the steps in the provided String * @throws java.text.ParseException if the steps could not be parsed */ public List<Step> parseRecipeSteps(String stepsString) throws ParseException { try { final JSONArray json = new JSONArray(stepsString); final List<Step> steps = new ArrayList<>(json.length()); for (int i = 0; i < json.length(); i++) { final JSONObject stepJson = json.getJSONObject(i); final String description = stepJson.getString("description"); final Duration duration = Duration.millis(stepJson.getLong("duration_ms")); final boolean simultaneous = stepJson.getBoolean("simultaneous"); final JSONArray ingredientsJson = stepJson.getJSONArray("ingredients"); final List<String> ingredients = new ArrayList<>(ingredientsJson.length()); for (int j = 0; j < ingredientsJson.length(); j++) { ingredients.add(ingredientsJson.getString(j)); } steps.add(new Step(ingredients, description, duration, simultaneous, i)); } return steps; } catch (JSONException e) { final ParseException parseException = new ParseException("Invalid JSON", 0); parseException.initCause(e); throw parseException; } }
From source file:org.cook_e.data.TimeLearner.java
License:Open Source License
/** * Returns the estimated time for a step based on learning result. * If step is not learned before, returns the estimate time of that step. * * @param s the step you need to estimate the time for * @return the estimated time (in milliseconds) for that specific step *///w w w . java 2 s . c om @Override @NonNull public Duration getEstimatedTime(@NonNull Recipe r, @NonNull Step s) { Objects.requireNonNull(r, "recipe must not be null"); Objects.requireNonNull(s, "step must not be null"); LearningWeight lw = accessOrCreateLearningWeight(r, s); long time = (long) (s.getTime().getMillis() * lw.getTimeWeight()); return Duration.millis(time); }
From source file:org.esco.portlet.changeetab.service.impl.CachingEtablissementService.java
License:Apache License
/** * Setter of cachingDuration (in ms)./*from w ww .j av a 2s .c o m*/ * * @param cachingDuration the cachingDuration to set */ public void setCachingDuration(final long cachingDuration) { this.cachingDuration = Duration.millis(cachingDuration); }