List of usage examples for org.joda.time DateTime now
public static DateTime now()
ISOChronology
in the default time zone. From source file:com.almende.pi5.lch.DERSimAgent.java
License:Apache License
/** * Repeat user events./*from w w w. j a v a2 s . co m*/ */ @Access(AccessType.PUBLIC) public void repeatUserEvents() { if (doUserEvents) { doUserEvent(); schedule("repeatUserEvents", null, DateTime.now().plusSeconds(new Double(Math.random() * 30).intValue())); } }
From source file:com.almende.pi5.lch.DERSimAgent.java
License:Apache License
/** * Repeat random offset.//w w w . java2 s .co m */ @Access(AccessType.PUBLIC) public void repeatRandomOffset() { currentRandomOffset = (0.5 - Math.random()) * randomOffset; schedule("repeatRandomOffset", null, DateTime.now().plusSeconds(new Double(Math.random() * 60).intValue())); }
From source file:com.almende.pi5.lch.DERSimAgent.java
License:Apache License
/** * Do user event./* www . ja va 2 s . co m*/ */ @Access(AccessType.PUBLIC) public void doUserEvent() { if (Math.random() > 0.8) { final Double oldVal = trickOffset; final Double available = maxConsumption - minFlex; final Double target = maxConsumption - Math.pow(Math.random(), 2) * available; trickOffset = target - getGoalConsumption(DateTime.now()); LOG.info("New trickOffset:" + trickOffset + " from:" + oldVal); sendReport(); } }
From source file:com.almende.pi5.lch.DERSimAgent.java
License:Apache License
@Override public PowerProfile generateReport() { final PowerProfile profile = new PowerProfile(currentTimeslot); final PowerTimeLine demand = new PowerTimeLine(currentTimeslot); final PowerTimeLine max = new PowerTimeLine(currentTimeslot); final PowerTimeLine min = new PowerTimeLine(currentTimeslot); final String cat = getCategory().name(); final DateTime now = DateTime.now(); // Get current report and add the new info/ remove past int offset = -TIMESLOTLENGTH; long endOffset = new Duration(currentTimeslot, currentTimeslot.plus(forecastHorizon)).getMillis(); while (offset < endOffset) { final Double consumption = getConsumption(currentTimeslot.plus(offset)); demand.getSeries().add(new PowerTime(offset, consumption)); max.getSeries().add(new PowerTime(offset, getMaxFlexibility(consumption, getBaseConsumption(currentTimeslot.plus(offset))))); min.getSeries().add(new PowerTime(offset, getMinFlexibility(consumption, getBaseConsumption(currentTimeslot.plus(offset))))); offset += TIMESLOTLENGTH;/*from w ww . ja va2 s. c om*/ } if (currentReport != null) { demand.merge(currentReport.getCategoryProfile(cat).getDemand(), currentTimeslot.minus(TIMESLOTLENGTH), now); max.merge(currentReport.getCategoryProfile(cat).getExpectedFlexibilityMaxInWatts(), currentTimeslot.minus(TIMESLOTLENGTH), now); min.merge(currentReport.getCategoryProfile(cat).getExpectedFlexibilityMinInWatts(), currentTimeslot.minus(TIMESLOTLENGTH), now); LOG.fine("Adding historical data:" + currentTimeslot.minus(TIMESLOTLENGTH) + " -> " + now); } profile.getCategoryProfile(cat).setDemand(demand.compact()); if (this.modus.equals(ControlMode.ABSTAIN)) { // No flexibility available if not participating. profile.getCategoryProfile(cat).setExpectedFlexibilityMaxInWatts(demand.compact()); profile.getCategoryProfile(cat).setExpectedFlexibilityMinInWatts(demand.compact()); } else { profile.getCategoryProfile(cat).setExpectedFlexibilityMaxInWatts(max.compact()); profile.getCategoryProfile(cat).setExpectedFlexibilityMinInWatts(min.compact()); } return profile; }
From source file:com.almende.salig.Client.java
License:Apache License
private static Message createMessage(ObjectNode input) { final Message message = new Message(); message.setDateTime(DateTime.now().getMillis()); message.setValue(input.get("value").asBoolean()); message.setLicense("app1@kinect/" + input.get("type").asText() + "/string"); message.setSerial(input.get("type").asText() + "Detector"); return message; }
From source file:com.almende.util.tokens.TokenStore.java
License:Apache License
/** * Creates the./*from www . ja v a2s . c om*/ * * @return the token ret */ public static TokenRet create() { synchronized (tokens) { TokenRet result; if (tokens.size() == 0 || tokens.get(last.toString(), String.class) == null || last.plus(3600000).isBeforeNow()) { final DateTime now = DateTime.now(); final String token = new UUID().toString(); result = new TokenRet(token, now); tokens.put(now.toString(), token); last = now; if (tokens.size() > SIZE + 2) { DateTime oldest = last; for (final String time : tokens.keySet()) { try { if (time.equals(State.KEY_AGENT_TYPE)) { continue; } if (DateTime.parse(time).isBefore(oldest)) { oldest = DateTime.parse(time); } } catch (final Exception e) { LOG.log(Level.WARNING, "Failed in eviction of tokens:", e); } } tokens.remove(oldest.toString()); } } else { result = new TokenRet(tokens.get(last.toString(), String.class), last); } return result; } }
From source file:com.amazonaws.services.kinesis.log4j.FilePublisher.java
License:Open Source License
public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("Usage: java " + FilePublisher.class.getName() + " <file_path>"); System.err.println();//from w ww . j av a2s . co m System.err.println( "<file_path>\t-\tabsolute path for the input file, this file will be read line by line and "); System.err.println("\t\t\tpublished to Kinesis"); System.exit(1); } String fileAbsolutePath = args[0]; File logFile = new File(fileAbsolutePath); if (!logFile.exists() || !logFile.canRead()) { System.err.println("File " + args[0] + " doesn't exist or is not readable."); System.exit(2); } Logger kinesisLogger = Logger.getLogger("KinesisLogger"); int i = 0; DateTime startTime = DateTime.now(); BufferedReader reader = new BufferedReader(new FileReader(logFile)); LOGGER.info("Started reading: " + fileAbsolutePath); String line = null; while ((line = reader.readLine()) != null) { kinesisLogger.info(line); i++; if (i % 100 == 0 && LOGGER.isDebugEnabled()) { LOGGER.debug("Total " + i + " records written to logger"); } } reader.close(); long bufferedRecordsCount = getBufferedRecordsCountFromKinesisAppenders(); while (bufferedRecordsCount > 0) { LOGGER.info("Publisher threads within log4j appender are still working on sending " + bufferedRecordsCount + " buffered records to Kinesis"); try { Thread.sleep(SLEEP_INTERVAL); } catch (InterruptedException e) { // do nothing } bufferedRecordsCount = getBufferedRecordsCountFromKinesisAppenders(); } LOGGER.info("Published " + i + " records from " + fileAbsolutePath + " to the logger, took " + PeriodFormat.getDefault().print(new Period(startTime, DateTime.now()))); }
From source file:com.amazonaws.services.kinesis.log4j.helpers.AsyncBatchPutHandler.java
License:Open Source License
public AsyncBatchPutHandler(String appenderName, AmazonKinesisPutRecordsHelper amazonKinesisPutRecordsHelper) { this.appenderName = appenderName; this.startTime = DateTime.now(); this.amazonKinesisPutRecordsHelper = amazonKinesisPutRecordsHelper; }
From source file:com.amazonaws.services.kinesis.log4j.helpers.AsyncBatchPutHandler.java
License:Open Source License
/** * This method is invoked when a log record is successfully sent to Kinesis. * Though this is not too useful for production use cases, it provides a good * debugging tool while tweaking parameters for the appender. *//*from www .j a va 2s .c o m*/ @Override public void onSuccess(PutRecordsRequest request, PutRecordsResult result) { int currentSuccessfulCount = amazonKinesisPutRecordsHelper .getSuccessCountAndaddFailedRecordsBackToQueue(request, result); successfulRequestCount = successfulRequestCount + currentSuccessfulCount; if ((logger.isInfoEnabled() && (successfulRequestCount + failedRequestCount) % amazonKinesisPutRecordsHelper.getBatchSize() == 0) || logger.isDebugEnabled()) { logger.info("Appender (" + appenderName + ") made " + successfulRequestCount + " successful put requests out of total " + (successfulRequestCount + failedRequestCount) + " in " + PeriodFormat.getDefault().print(new Period(startTime, DateTime.now())) + " since start"); } }
From source file:com.amazonaws.services.kinesis.log4j.helpers.AsyncPutCallStatsReporter.java
License:Open Source License
public AsyncPutCallStatsReporter(String appenderName) { this.appenderName = appenderName; this.startTime = DateTime.now(); }