List of usage examples for org.joda.time Period Period
public Period(Object period)
From source file:PeriodTypeAdapter.java
License:Apache License
@Override public Period read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull();/* w w w . ja va 2 s. c om*/ return null; } return new Period(in.nextString()); }
From source file:cd.go.contrib.elasticagents.marathon.executors.CreateAgentRequestExecutor.java
License:Apache License
@Override public GoPluginApiResponse execute() throws Exception { /*//from w w w .j ava 2 s .c om The logic here is that the go server has a list of agents, but not a definitive view of which of those agents is actually running. This means that this plugin is sent a createAgentRequest for every matching job being scheduled. The housekeeping we do to prevent over-creating new instances is to get a list of agents from the go server, find idle ones in the list, and match to the corresponding instance running on marathon. If the instance running on marathon would satisfy the request, we do not create a new instance. In the case where we might get multiple createAgentRequests in a short period of time, we mark the instance as recently matched so it is not eligible to match for subsequent requests. This isn't perfect - we might mark one and then the job actually gets scheduled to another agent. In the long term, the go agents will use web sockets, the go server will know which ones are still running, and we can drop this logic here. */ boolean agentMatch = false; for (Agent agent : pluginRequest.listAgents().agents()) { if (!agentIdle(agent)) { continue; } MarathonInstance instance = (MarathonInstance) agentInstances.find(agent.elasticAgentId()); if (instance == null) { continue; } if (!propertiesMatch(instance.properties(), request.properties())) { continue; } // Recently matched to an outstanding task if (instance.getLastMatched().isAfter(new DateTime().minus(new Period("PT30S")))) { continue; } agentMatch = true; instance.setLastMatched(new DateTime()); break; } if (!agentMatch) { agentInstances.create(request, pluginRequest.getPluginSettings()); } return new DefaultGoPluginApiResponse(200); }
From source file:cd.go.contrib.elasticagents.marathon.MarathonAgentInstances.java
License:Apache License
@Override public void refreshAll(PluginRequest pluginRequest) throws Exception { if (refreshed) { if (refreshedTime == null) { setRefreshed(false);//from w ww . ja v a 2s . c om } else { if (refreshedTime.isBefore(new DateTime().minus(new Period("PT10M")))) { setRefreshed(false); } } } if (!refreshed) { PluginSettings settings = pluginRequest.getPluginSettings(); List<MarathonInstance> marathonInstanceList = marathon(settings).getGoAgents(settings); for (MarathonInstance instance : marathonInstanceList) { register(instance); } LOG.debug("Instances found: " + marathonInstanceList.toString()); setRefreshedTime(new DateTime()); setRefreshed(true); } }
From source file:ch.eitchnet.android.util.JodaHelper.java
License:Open Source License
public static String toHourMinute(Duration duration) { PeriodFormatterBuilder builder = new PeriodFormatterBuilder(); builder.printZeroAlways();//from ww w . ja v a 2 s . c o m if (duration.isShorterThan(Duration.ZERO)) builder.appendLiteral("-"); builder.minimumPrintedDigits(2).appendHours().appendLiteral(":").minimumPrintedDigits(2).appendMinutes(); return builder.toFormatter().print(new Period(Math.abs(duration.getMillis()))); }
From source file:ch.icclab.cyclops.health.HealthStatus.java
License:Open Source License
/** * Health status of the micro service//from ww w . j a va 2 s. co m * @return Health status */ public synchronized Health getHealth() { Period period = new Period(watch.elapsed(TimeUnit.MILLISECONDS)); return new Health(healthy, period); }
From source file:com.allogy.json.jackson.joda.ISOPeriodDeserializer.java
License:Apache License
@Override public Period deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { String textValue = jsonParser.getText(); try {//from www . ja va2 s. c o m return new Period(textValue); } catch (Throwable throwable) { throw new InvalidFormatException(throwable.getMessage(), textValue, String.class); } }
From source file:com.alta189.cyborg.rest.core.CyborgProvider.java
License:Open Source License
@GET @Produces(MediaType.APPLICATION_JSON)//from www . ja va2s .co m public CyborgInfo getCyborgInfo() { Cyborg cyborg = Cyborg.getInstance(); CyborgInfo info = new CyborgInfo(); info.setNick(cyborg.getNick()); info.setIdent(cyborg.getIndent()); info.setHostmask(cyborg.getHostmask()); Set<Channel> channels = new HashSet<Channel>(); for (org.pircbotx.Channel channel : cyborg.getChannels()) { if (!channel.getMode().contains("p") && !channel.getMode().contains("s")) { channels.add(new Channel(channel)); } } info.setChannels(channels); info.setRunningTime(cyborg.getRunningTime()); Period period = new Period(info.getRunningTime()); info.setRunningTimeFormatted(timeFormatter.print(period)); return info; }
From source file:com.anrisoftware.propertiesutils.DateContextProperties.java
License:Open Source License
/** * Returns a time period property using the format defined in * {@link ISOPeriodFormat#standard()}.// ww w.j av a2 s. co m * * @param key * the property key. * * @return the {@link Period}. */ public Period getPeriodProperty(String key) { String property = getProperty(key); return new Period(property); }
From source file:com.anrisoftware.propertiesutils.DateContextProperties.java
License:Open Source License
/** * Returns a time duration property using the format defined in * {@link ISOPeriodFormat#standard()}./*from w w w.j a v a2 s.c om*/ * * @param key * the property key. * * @return the {@link Duration}. */ public Duration getDurationProperty(String key) { String property = getProperty(key); return new Period(property).toStandardDuration(); }
From source file:com.baulsupp.kolja.log.viewer.format.PeriodFormat.java
License:Open Source License
public String format(Object value) { if (value == null) { return null; }//from www. ja v a2 s . c o m if (format == null) { format = new PeriodFormatterBuilder().printZeroRarelyLast().appendDays().appendSuffix("d").appendHours() .appendSuffix("h").appendMinutes().appendSuffix("m").appendSecondsWithOptionalMillis() .appendSuffix("s").toFormatter(); } ReadablePeriod p = null; if (value instanceof ReadableInterval) { p = ((ReadableInterval) value).toPeriod(); } else if (value instanceof ReadableDuration) { p = ((ReadableDuration) value).toPeriod(); } else if (value instanceof ReadablePeriod) { p = (ReadablePeriod) value; } else if (value instanceof Long) { p = new Period(((Long) value).longValue()); } else { return ""; } return format.print(p); }