List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.google.android.apps.paco.NotificationCreator.java
License:Open Source License
public void createNotificationsForCustomGeneratedScript(Experiment experiment, String message, boolean makeSound, boolean makeVibrate, long timeoutMillis) { List<NotificationHolder> notifications = experimentProviderUtil.getNotificationsFor(experiment.getId()); if (activeNotificationForCustomGeneratedScript(notifications)) { return;/*from w ww .j av a2 s .c om*/ } createNewCustomNotificationForExperiment(context, DateTime.now(), experiment, timeoutMillis, message); }
From source file:com.google.api.ads.adwords.awreporting.model.entities.ReportBase.java
License:Open Source License
@Override public String setIdDates() { // Time Segments if (this.getDay() != null) { return "-" + this.getDay(); }/*from w w w.j a va 2 s . c o m*/ if (this.getDayOfWeek() != null) { return "-" + this.getDayOfWeek(); } // Week may partially overlap with Month / Quarter / Year. String id = ""; if (this.getWeek() != null) { id += "-" + this.getWeek(); } if (this.getMonthOfYear() != null) { id += "-" + this.getMonthOfYear(); } else if (this.getMonth() != null) { id += "-" + DateUtil.formatYearMonth(this.getMonthDateTime()); } else if (this.getQuarter() != null) { id += "-" + this.getQuarter(); } else if (this.getYear() != null) { id += "-" + this.getYear(); } if (!id.isEmpty()) { return id; } if (this.getDateRangeType() != null) { DateRangeHandler handler = dateRangeHandlers.get(this.getDateRangeType()); if (handler != null) { this.setMonth(handler.retrieveMonth(DateTime.now())); this.setDateStart(DateUtil.formatYearMonthDay(handler.retrieveDateStart(DateTime.now()))); this.setDateEnd(DateUtil.formatYearMonthDay(handler.retrieveDateEnd(DateTime.now()))); } } if (this.getDateStart() != null && this.getDateEnd() != null) { return "-" + this.getDateStart() + "-" + this.getDateEnd(); } return ""; }
From source file:com.google.api.ads.adwords.awreporting.processors.ReportProcessor.java
License:Open Source License
/** * Caches the accounts into a temporary file. * * @param accountIdsSet the set with all the customer accounts ids. */// w w w. j av a2s .c o m private void cacheAccounts(Set<Long> accountIdsSet) { String nowFormat = TIMESTAMPFORMAT.print(DateTime.now()); File tempFile = null; try { tempFile = File.createTempFile(nowFormat + "-accounts-ids", ".txt"); logger.info("Cache file created for accounts: " + tempFile.getAbsolutePath()); } catch (IOException e) { logger.error("Could not create temporary file with the accounts. Accounts won't be cached.", e); } try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile), StandardCharsets.UTF_8)) { for (Long accountId : accountIdsSet) { writer.write(Long.toString(accountId) + "\n"); } logger.info("All account IDs added to cache file."); } catch (IOException e) { logger.error("Failed ot cache accounts into temporary file.", e); } }
From source file:com.google.api.ads.adwords.jaxws.extensions.processors.RunnableProcessor.java
License:Open Source License
/** * Executes the API call to download the report that was given when this {@code Runnable} was * created./*from w w w . j av a 2s . c o m*/ * * The download blocks this thread until it is finished, and also does the file copying. * * There is also a retry logic implemented by this method, where the times retried depends on the * value given in the constructor. * * @see java.lang.Runnable#run() */ @Override public void run() { try { CSVReader csvReader = this.createCsvReader(file); LOGGER.debug("Starting parse of report rows..."); CsvParserIterator<R> reportRowsList = csvToBean.lazyParse(mappingStrategy, csvReader); LOGGER.debug("... success."); LOGGER.debug("Starting report persistence..."); List<R> reportBuffer = Lists.newArrayList(); while (reportRowsList.hasNext()) { R report = reportRowsList.next(); // Getting Account Id from File Name for reports that do not have Client Customer Id if (report.getAccountId() == null && file.getName().contains("-") && file.getName().split("-") != null && file.getName().split("-").length > 2 && file.getName().split("-")[2].matches("\\d*")) { report.setAccountId(Long.parseLong(file.getName().split("-")[2])); } report.setTopAccountId(Long.parseLong(this.mccAccountId.replaceAll("-", ""))); //TODO better to create a setup() method in Reporting and pass all setup data as hashmap and setup Report based on criteria ReportMode mode = ReportModeService.getReportMode(); if (mode == null || mode.equals(ReportMode.METRIC)) { report.setDateRangeType(dateRangeType.value()); report.setDateStart(dateStart); report.setDateEnd(dateEnd); report.setSnapshotDay(reportSnapshotDownloadDay); } else if (mode.equals(ReportMode.ATTRIBUTE)) { report.setLastUpdatedTimeStamp(DateTime.now().getMillis()); } report.setId(); reportBuffer.add(report); if (reportBuffer.size() >= this.reportRowsSetSize) { this.persister.persistReportEntities(reportBuffer); reportBuffer.clear(); } } if (reportBuffer.size() > 0) { this.persister.persistReportEntities(reportBuffer); } LOGGER.debug("... success."); csvReader.close(); } catch (UnsupportedEncodingException e) { LOGGER.error("Error processing file: " + file.getAbsolutePath()); e.printStackTrace(); } catch (FileNotFoundException e) { LOGGER.error("Error processing file: " + file.getAbsolutePath()); e.printStackTrace(); } catch (IOException e) { LOGGER.error("Error processing file: " + file.getAbsolutePath()); e.printStackTrace(); } finally { if (this.latch != null) { this.latch.countDown(); } } }
From source file:com.google.api.ads.adwords.jaxws.extensions.report.model.entities.ReportBase.java
License:Open Source License
@Override public String setIdDates() { ReportMode mode = ReportModeService.getReportMode(); //this is for ATTRIBUTE reports if (mode.equals(ReportMode.ATTRIBUTE) && this.getLastUpdatedTimeStamp() != null) { return "-" + this.getLastUpdatedTimeStamp().toString(); }/*from ww w .j a v a 2s. com*/ // Day or Month String reportDay = this.getDay(); if (reportDay != null) { return "-" + reportDay.replaceAll("-", "") + (this.getHourOfDay() != null ? ("-" + this.getHourOfDay()) : "") + (this.getSnapshotDay() != null ? ("-" + this.getSnapshotDay()) : ""); } if (this.getDateRangeType() != null) { DateRangeHandler handler = dateRangeHandlers.get(this.getDateRangeType()); if (handler != null) { this.setDateStart(DateUtil.formatYearMonthDay(handler.retrieveDateStart(DateTime.now()))); this.setDateEnd(DateUtil.formatYearMonthDay(handler.retrieveDateEnd(DateTime.now()))); } } if (this.getDateStart() != null && this.getDateEnd() != null) { return "-" + this.getDateStart() + "-" + this.getDateEnd() + (this.getSnapshotDay() != null ? ("-" + this.getSnapshotDay()) : ""); } return ""; }
From source file:com.google.api.ads.adwords.keywordoptimizer.AwapiRateLimiter.java
License:Open Source License
/** * Update the wait time for TOKEN scope. * * @param waitForMills the wait time in milliseconds *//*from w w w . j a v a 2 s. c om*/ private void updateTokenWaitTime(long waitForMills) { final long newTime = DateTime.now().getMillis() + waitForMills; boolean done = true; do { long oldTime = tokenWaitUntil.get(); // If the new wait until time exceeds current one, update it; otherwise just skip the loop. if (oldTime < newTime) { done = tokenWaitUntil.compareAndSet(oldTime, newTime); } else { done = true; } } while (!done); }
From source file:com.google.api.ads.adwords.keywordoptimizer.AwapiRateLimiter.java
License:Open Source License
/** * Update the wait time for ACCOUNT scope. * * @param clientCustomerId the client customer ID * @param waitForMills the wait time in milliseconds *///w w w . j av a 2 s . com private void updateAccountWaitTime(Long clientCustomerId, long waitForMills) { final long newTime = DateTime.now().getMillis() + waitForMills; boolean done = true; do { long oldTime = accountWaitUntil.get(clientCustomerId); // If the new wait until time exceeds current one, update it; otherwise // just skip the loop. if (oldTime < newTime) { done = (oldTime == accountWaitUntil.getAndAdd(clientCustomerId, newTime - oldTime)); } else { done = true; } } while (!done); }
From source file:com.google.api.ads.adwords.keywordoptimizer.AwapiRateLimiter.java
License:Open Source License
/** * Wait and update the wait until time accordingly. * * @param clientCustomerId the client customer ID for the AdWords API invocation * @param lastApiException the last {@link ApiException} for the request *//*from w w w. j av a2 s .c o m*/ private void wait(Long clientCustomerId, @Nullable ApiException lastApiException) { long nowInMillis = DateTime.now().getMillis(); long waitForMillis = 0L; waitForMillis = Math.max(waitForMillis, tokenWaitUntil.get() - nowInMillis); // clientCustomerId could be null, e.g., for ReportDefinitionService invocation. if (clientCustomerId != null) { waitForMillis = Math.max(waitForMillis, accountWaitUntil.get(clientCustomerId) - nowInMillis); } if (waitForMillis > 0) { if (timeoutOnRateExceededError > 0 && waitForMillis > MILLISECONDS.convert(timeoutOnRateExceededError, SECONDS)) { throw new RuntimeException( "Need to wait too much time (more than " + timeoutOnRateExceededError + " seconds).", lastApiException); } logger.info("Thread \"{}\" sleeping for {} millis due to rate limit on {}.", Thread.currentThread().getName(), waitForMillis, bucket); Uninterruptibles.sleepUninterruptibly(waitForMillis, MILLISECONDS); } }
From source file:com.google.cloud.tools.intellij.appengine.cloud.AppEngineRuntimeInstance.java
License:Apache License
/** * Disambiguates running deployment line items by prepending a timestamp. Also appends the * cloud project and version id's to the deployment string. *//*from w w w . j a v a 2 s .c o m*/ @NotNull @Override public String getDeploymentName(@NotNull DeploymentSource source, AppEngineDeploymentConfiguration configuration) { String deploymentName = String.format("[%s] ", DateTime.now().toString("yyyy-MM-dd HH:mm:ss")); // If its a user specified archive source then we want to label it by the name of the archive if (source instanceof UserSpecifiedPathDeploymentSource && source.getFile() != null) { deploymentName += source.getFile().getName(); } else { deploymentName += source.getPresentableName(); } if (source instanceof AppEngineDeployable) { AppEngineDeployable deployable = (AppEngineDeployable) source; if (deployable.getProjectName() != null) { deploymentName += ". Project: " + ((AppEngineDeployable) source).getProjectName(); } if (deployable.getVersion() != null) { deploymentName += ". Version: " + ((AppEngineDeployable) source).getVersion(); } } return deploymentName; }
From source file:com.google.gerrit.server.config.ScheduleConfig.java
License:Apache License
public ScheduleConfig(Config rc, String section, String subsection) { this(rc, section, subsection, DateTime.now()); }