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.eve.agent.MeetingAgent.java
License:Apache License
/** * Retrieve the busy intervals of a calendar agent * /*from ww w . j av a 2 s.c o m*/ * @param agent */ private void updateBusyInterval(@Name("agent") final String agent) { try { // create parameters with the boundaries of the interval to be // retrieved final ObjectNode params = JOM.createObjectNode(); final DateTime timeMin = DateTime.now(); final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS); params.put("timeMin", timeMin.toString()); params.put("timeMax", timeMax.toString()); // exclude the event managed by this agent from the busy intervals final String eventId = getAgentData(agent).eventId; if (eventId != null) { final ArrayNode excludeEventIds = JOM.createArrayNode(); excludeEventIds.add(eventId); params.put("excludeEventIds", excludeEventIds); } // get the busy intervals from the agent final ArrayNode array = send(URI.create(agent), "getBusy", params, ArrayNode.class); // convert from ArrayNode to List final List<Interval> busy = new ArrayList<Interval>(); for (int i = 0; i < array.size(); i++) { final ObjectNode obj = (ObjectNode) array.get(i); final String start = obj.has("start") ? obj.get("start").asText() : null; final String end = obj.has("end") ? obj.get("end").asText() : null; busy.add(new Interval(new DateTime(start), new DateTime(end))); } // store the interval in the state putAgentBusy(agent, busy); } catch (final JSONRPCException e) { addIssue(TYPE.warning, Issue.JSONRPCEXCEPTION, e.getMessage()); LOG.log(Level.WARNING, "", e); } catch (final Exception e) { addIssue(TYPE.warning, Issue.EXCEPTION, e.getMessage()); LOG.log(Level.WARNING, "", e); } }
From source file:com.almende.eve.agent.SchedulingAgent.java
License:Apache License
public void onReady() { DateTime now = DateTime.now(); super.onReady(); LOG.warning("OnReady called!"); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); }
From source file:com.almende.eve.agent.SchedulingAgent.java
License:Apache License
/** * Repeat test./* w w w . ja v a 2s .co m*/ */ @Access(AccessType.PUBLIC) public void repeatTest() { //schedule("test", null, DateTime.now()); test(); schedule("repeatTest", null, DateTime.now().plusMillis(1000)); }
From source file:com.almende.eve.algorithms.DAA.java
License:Apache License
/** * Sets this nodes new value./*from w w w .j ava 2 s.c o m*/ * * @param value * the new new value */ public void setNewValue(final double value) { localValue = new DAAValueBean(width, evictionFactor); localValue.generate(value).setTTL(DateTime.now().plus(100).getMillis()); if (currentEstimate == null) { currentEstimate = new DAAValueBean(width, evictionFactor); Arrays.fill(currentEstimate.valueArray, Double.MAX_VALUE); } currentEstimate.minimum(localValue); }
From source file:com.almende.eve.algorithms.DAAValueBean.java
License:Apache License
/** * Make this ValueBean represent the minimum with regard to the given other. * Returns reference to itself, for chaining. * * @param other/*from w ww. ja v a 2 s. c om*/ * the other * @return the value bean * @throws IllegalArgumentException * the illegal argument exception */ public DAAValueBean minimum(final DAAValueBean other) throws IllegalArgumentException { if (this.width != other.width) { throw new IllegalArgumentException( "ValueBeans aren't of the same length:(" + this.width + "/" + other.width + ")!"); } for (int i = 0; i < width; i++) { if (other.valueArray[i] == valueArray[i]) { ttlArray[i] = Math.max(ttlArray[i], other.ttlArray[i]); } else { ttlArray[i] = Math.min(ttlArray[i], other.ttlArray[i]); if (other.valueArray[i] < valueArray[i]) { valueArray[i] = other.valueArray[i]; ttlArray[i] = other.ttlArray[i]; } } final long now = DateTime.now().getMillis(); if (ttlArray[i] < now && other.ttlArray[i] > now) { valueArray[i] = other.valueArray[i]; ttlArray[i] = other.ttlArray[i]; } } return this; }
From source file:com.almende.eve.algorithms.EventBus.java
License:Apache License
/** * Send event./*from w ww .j a v a 2s. c om*/ * * @param message * the message * @param expiryAge * the expiry age */ public void sendEvent(JSONRequest message, long expiryAge) { if (expiryAge > 0 && expiryAge < expiryInterval) { // speed up expiry after next run. expiryInterval = expiryAge; } final Event event = new Event(DateTime.now().plus(expiryAge).getMillis(), message, caller.getSenderUrls().get(0)); synchronized (events) { events.add(event); } trickle.reset(); }
From source file:com.almende.eve.algorithms.EventBus.java
License:Apache License
/** * Schedule expiry./*from w w w. j a v a 2s .c o m*/ */ @Access(AccessType.PUBLIC) public void scheduleExpiry() { doExpiry(); scheduler.schedule(EXPIRYREQUEST.getId().asText(), EXPIRYREQUEST, DateTime.now().plus(expiryInterval)); }
From source file:com.almende.eve.algorithms.EventBus.java
License:Apache License
/** * Expire old events.//from w ww. j av a 2 s . co m */ @Access(AccessType.PUBLIC) public void doExpiry() { final List<Event> stillToTrigger = new ArrayList<Event>(); synchronized (events) { Iterator<Event> iter = events.iterator(); while (iter.hasNext()) { Event event = iter.next(); if (event.getExpiryTime() < DateTime.now().getMillis()) { if (!event.isTriggered()) { stillToTrigger.add(event); } iter.remove(); } } } for (Event event : stillToTrigger) { trigger(event); } }
From source file:com.almende.eve.algorithms.EventBus.java
License:Apache License
/** * Schedule trigger./*from ww w. j ava2s.c o m*/ */ @Access(AccessType.PUBLIC) public void scheduleTrigger() { doTriggers(); scheduler.schedule(TRIGGERREQUEST.getId().asText(), TRIGGERREQUEST, DateTime.now().plus(5000)); }
From source file:com.almende.eve.algorithms.EventBus.java
License:Apache License
/** * Receive events.//from ww w.j ava 2 s .c om * * @param events * the events */ @Access(AccessType.PUBLIC) public void receiveEvents(final @Name("events") Set<Event> events) { boolean trickleReset = false; synchronized (this.events) { if (!this.events.equals(events)) { for (Event event : events) { if (DateTime.now().isBefore(event.getExpiryTime())) { this.events.add(event); trickleReset = true; } } } } if (trickleReset) { trickle.reset(); } else { trickle.incr(); } Event[] eventArray; synchronized (this.events) { eventArray = this.events.toArray(new Event[0]); } for (Event event : eventArray) { if (!event.isTriggered()) { trigger(event); } } }