List of usage examples for org.joda.time Period Period
public Period(Object period)
From source file:org.apache.hcatalog.hcatmix.publisher.HCatMixFormatter.java
License:Apache License
public String formatDuration(Double duration) { if (duration == null) { return "-"; }/*from w ww .j ava2 s . c o m*/ Period period = new Period(Math.round(duration)); return formatter.print(period); }
From source file:org.apache.nifi.controller.druid.DruidTranquilityController.java
License:Apache License
Beam<Map<String, Object>> buildBeam(String dataSource, String indexService, String discoveryPath, int clusterPartitions, int clusterReplication, String segmentGranularity, String queryGranularity, String windowPeriod, String indexRetryPeriod, List<String> dimensions, List<AggregatorFactory> aggregator, Timestamper<Map<String, Object>> timestamper, TimestampSpec timestampSpec) {/*ww w . j a v a 2s .c o m*/ return DruidBeams.builder(timestamper).curator(curator).discoveryPath(discoveryPath) .location(DruidLocation.create(DruidEnvironment.create(indexService, FIREHOSE_PATTERN), dataSource)) .timestampSpec(timestampSpec) .rollup(DruidRollup.create(DruidDimensions.specific(dimensions), aggregator, QueryGranularity.fromString(queryGranularity))) .tuning(ClusteredBeamTuning.builder().segmentGranularity(getGranularity(segmentGranularity)) .windowPeriod(new Period(windowPeriod)).partitions(clusterPartitions) .replicants(clusterReplication).build()) .druidBeamConfig(DruidBeamConfig.builder().indexRetryPeriod(new Period(indexRetryPeriod)).build()) .buildBeam(); }
From source file:org.apache.niolex.common.joda.Calculate.java
License:Apache License
public static void calcWorkTime(DateTime start, DateTime end) { long worked = new Duration(start, end).minus(FORMAL_TIME.plus(RESET_TIME).toStandardDuration()).getMillis(); StringBuffer sb = new StringBuffer(); if (worked < 0) { sb.append("Worked not enough! Still need work : "); PRINTER.printTo(sb, new Period(Math.abs(worked)), Locale.CHINESE); } else {/* w w w . j av a2 s . co m*/ sb.append("Good job! Worked : "); PRINTER.printTo(sb, new Period(Math.abs(worked)).plusHours(FORMAL_TIME.getHours()), Locale.CHINESE); } System.out.println(sb.toString()); }
From source file:org.apache.pig.builtin.AddDuration.java
License:Apache License
@Override public DateTime exec(Tuple input) throws IOException { if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) { return null; }/*from w w w .ja va2 s .com*/ return ((DateTime) input.get(0)).plus(new Period((String) input.get(1))); }
From source file:org.apache.pig.builtin.SubtractDuration.java
License:Apache License
@Override public DateTime exec(Tuple input) throws IOException { if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) { return null; }/*from w ww . j av a 2 s. c o m*/ return ((DateTime) input.get(0)).minus(new Period((String) input.get(1))); }
From source file:org.apache.storm.druid.SampleDruidBeamFactoryImpl.java
License:Apache License
@Override public Beam<Map<String, Object>> makeBeam(Map<?, ?> conf, IMetricsContext metrics) { final String indexService = "druid/overlord"; // Your overlord's druid.service final String discoveryPath = "/druid/discovery"; // Your overlord's druid.discovery.curator.path final String dataSource = "test"; final List<String> dimensions = ImmutableList.of("publisher", "advertiser"); List<AggregatorFactory> aggregator = ImmutableList .<AggregatorFactory>of(new CountAggregatorFactory("click")); // Tranquility needs to be able to extract timestamps from your object type (in this case, Map<String, Object>). final Timestamper<Map<String, Object>> timestamper = new Timestamper<Map<String, Object>>() { @Override/*from ww w.ja v a 2s .c o m*/ public DateTime timestamp(Map<String, Object> theMap) { return new DateTime(theMap.get("timestamp")); } }; // Tranquility uses ZooKeeper (through Curator) for coordination. final CuratorFramework curator = CuratorFrameworkFactory.builder() .connectString((String) conf.get("druid.tranquility.zk.connect")) // we can use Storm conf to get config values .retryPolicy(new ExponentialBackoffRetry(1000, 20, 30000)).build(); curator.start(); // The JSON serialization of your object must have a timestamp field in a format that Druid understands. By default, // Druid expects the field to be called "timestamp" and to be an ISO8601 timestamp. final TimestampSpec timestampSpec = new TimestampSpec("timestamp", "auto", null); // Tranquility needs to be able to serialize your object type to JSON for transmission to Druid. By default this is // done with Jackson. If you want to provide an alternate serializer, you can provide your own via ```.objectWriter(...)```. // In this case, we won't provide one, so we're just using Jackson. final Beam<Map<String, Object>> beam = DruidBeams.builder(timestamper).curator(curator) .discoveryPath(discoveryPath).location(DruidLocation.create(indexService, dataSource)) .timestampSpec(timestampSpec) .rollup(DruidRollup.create(DruidDimensions.specific(dimensions), aggregator, QueryGranularities.MINUTE)) .tuning(ClusteredBeamTuning.builder().segmentGranularity(Granularity.HOUR) .windowPeriod(new Period("PT10M")).partitions(1).replicants(1).build()) .druidBeamConfig(DruidBeamConfig.builder().indexRetryPeriod(new Period("PT10M")).build()) .buildBeam(); return beam; }
From source file:org.apereo.portal.events.aggr.PortalEventDimensionPopulatorImpl.java
License:Apache License
@Value("${org.apereo.portal.events.aggr.PortalEventDimensionPopulatorImpl.dimensionBuffer:P30D}") public void setDimensionBuffer(ReadablePeriod dimensionBuffer) { if (new Period(dimensionBuffer).toStandardDays().getDays() < 1) { throw new IllegalArgumentException("dimensionBuffer must be at least 1 day. Is: " + new Period(dimensionBuffer).toStandardDays().getDays()); }/* w w w .j a v a 2 s .c o m*/ this.dimensionBuffer = dimensionBuffer; }
From source file:org.cyberiantiger.minecraft.duckcrates.Main.java
@Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (args.length == 0) { args = new String[] { "inspect" }; }// w w w .ja v a 2 s. c om if ("daily".equalsIgnoreCase(args[0]) && args.length == 1) { if (!(sender instanceof Player)) { sender.sendMessage(getMessage("claim.error.not_player")); return true; } final Player player = (Player) sender; database.claimDaily(player.getUniqueId(), (ClaimDailyStatus t) -> { if (t.isSuccess()) { // FUTURE: Improve the message to describe what crates // where delivered. player.sendMessage(getMessage("claim.daily.success")); Map<String, CratesAvailable> available = getAvailable(player); deliverDaily(player, available); } else { Period period = new Period(t.getRemainingTime()); player.sendMessage(getMessage("claim.daily.wait", PeriodFormat.getDefault().print(period))); } }, (Exception t) -> { player.sendMessage(getMessage("claim.error.exception")); getLogger().log(Level.WARNING, "Exception handling command", t); }); return true; } else if ("reload".equalsIgnoreCase(args[0]) && args.length == 1) { if (!sender.hasPermission("duckcrates.reload")) { sender.sendMessage(getMessage("claim.permission", "duckcrates.reload")); return true; } loadConfig(); loadMessages(); database.close(); sender.sendMessage(getMessage("claim.reload")); return true; } else if ("reset".equalsIgnoreCase(args[0])) { if (!sender.hasPermission("duckcrates.reset")) { sender.sendMessage(getMessage("claim.permission", "duckcrates.reset")); return true; } Player target; if (args.length == 1) { if (sender instanceof Player) { target = (Player) sender; } else { sender.sendMessage(getMessage("claim.error.not_player")); return true; } } else if (args.length == 2) { target = getServer().getPlayer(args[1]); if (target == null) { sender.sendMessage(getMessage("claim.reset.unknown_target", args[1])); return true; } } else { return false; } database.resetClaims(target.getUniqueId(), (Void t) -> { sender.sendMessage(getMessage("claim.reset.success", target.getDisplayName())); }, (Exception t) -> { sender.sendMessage(getMessage("claim.error.exception")); getLogger().log(Level.WARNING, "Exception handling command", t); }); return true; } else if ("inspect".equalsIgnoreCase(args[0])) { Player target; if (args.length == 1) { if (sender instanceof Player) { target = (Player) sender; } else { sender.sendMessage(getMessage("claim.error.not_player")); return true; } } else if (args.length == 2) { target = getServer().getPlayer(args[1]); if (target == null) { sender.sendMessage(getMessage("claim.inspect.unknown_target", args[1])); return true; } } else { return false; } if (target != sender && !sender.hasPermission("duckcrates.inspect")) { sender.sendMessage(getMessage("claim.permission", "duckcrates.inspect")); return true; } final Map<String, CratesAvailable> available = getAvailable(target); database.getClaimStatus(target.getUniqueId(), (ClaimStatus t) -> { if (sender == target) { sender.sendMessage(getMessage("claim.inspect.header_self")); } else { sender.sendMessage(getMessage("claim.inspect.header_other", target.getDisplayName())); } long now = System.currentTimeMillis(); if (t.getLastDaily() + Database.ONE_DAY <= now) { sender.sendMessage(getMessage("claim.inspect.daily_available")); } else { Period period = new Period(t.getLastDaily() + Database.ONE_DAY - now); sender.sendMessage( getMessage("claim.inspect.daily_unavailable", PeriodFormat.getDefault().print(period))); } Map<String, Integer> claimed = t.getClaimed(); available.entrySet().stream().forEach((e) -> { int once = e.getValue().getOnce(); if (once > 0) { int delivered = 0; if (claimed.containsKey(e.getKey())) { delivered = claimed.get(e.getKey()); } int remaining = once - delivered; if (remaining < 0) { remaining = 0; } sender.sendMessage(getMessage("claim.inspect.once_available", e.getKey(), remaining, once)); } }); }, (Exception t) -> { target.sendMessage(getMessage("claim.error.exception")); getLogger().log(Level.WARNING, "Exception handling command", t); }); return true; } else if ("give".equalsIgnoreCase(args[0])) { if (!sender.hasPermission("duckcrates.give")) { sender.sendMessage(getMessage("claim.permission", "duckcrates.give")); return true; } if (args.length == 1) { return false; } String type = findCrateType(args[1]); int count = 1; Player target = (sender instanceof Player) ? (Player) sender : null; if (args.length >= 3) { try { count = Integer.parseInt(args[2]); } catch (NumberFormatException ex) { return false; } } if (args.length >= 4) { target = getServer().getPlayer(args[3]); } if (type == null) { sender.sendMessage(getMessage("claim.give.crate_not_found", args[1])); return true; } if (count < 1) { sender.sendMessage(getMessage("claim.give.amount_too_small", count)); return true; } if (count > 1024) { sender.sendMessage(getMessage("claim.give.amount_too_big", count)); return true; } if (target == null) { sender.sendMessage(getMessage("claim.give.target_not_found", args[3])); return true; } sender.sendMessage(getMessage("claim.give.success", target.getDisplayName(), type, count)); deliverSpecific(target, type, count); return true; } else if (args.length == 1) { if (!(sender instanceof Player)) { sender.sendMessage(getMessage("claim.error.not_player")); return true; } final Player player = (Player) sender; String type = findCrateType(args[0]); if (type == null) { sender.sendMessage(getMessage("claim.specific.unknown_type", args[0])); return true; } final Map<String, CratesAvailable> available = getAvailable(player); if (!available.containsKey(type) || available.get(type).getOnce() == 0) { sender.sendMessage(getMessage("claim.once.not_available", type)); return true; } database.claimOnce(player.getUniqueId(), type, available.get(type).getOnce(), (Integer amount) -> { if (amount > 0) { sender.sendMessage(getMessage("claim.once.success", type, amount)); deliverSpecific(player, type, amount); } else { sender.sendMessage(getMessage("claim.once.already_claimed", type)); } }, (Exception t) -> { player.sendMessage(getMessage("claim.error.exception")); getLogger().log(Level.WARNING, "Exception handling command", t); }); return true; } return false; }
From source file:org.cyberiantiger.minecraft.log.cmd.AbstractCommand.java
public static Period trimPeriod(long period) { period -= period % SECOND; // Trim milliseconds. return new Period(period); }
From source file:org.datanucleus.store.types.jodatime.converters.JodaPeriodStringConverter.java
License:Open Source License
public Period toMemberType(String str) { if (str == null) { return null; } return new Period(str); }