List of usage examples for java.time ZoneId systemDefault
public static ZoneId systemDefault()
From source file:Main.java
public static void main(String[] args) { // Instant is useful for generating a time stamp to represent machine time. Instant timestamp = Instant.now(); // Convert "machine time" to human units LocalDateTime humanTime = LocalDateTime.ofInstant(timestamp, ZoneId.systemDefault()); System.out.println(humanTime); }
From source file:com.hazelcast.jet.benchmark.trademonitor.FlinkTradeMonitor.java
public static void main(String[] args) throws Exception { if (args.length != 13) { System.err.println("Usage:"); System.err.println(" " + FlinkTradeMonitor.class.getSimpleName() + " <bootstrap.servers> <topic> <offset-reset> <maxLagMs> <windowSizeMs> <slideByMs> <outputPath> <checkpointInterval> <checkpointUri> <doAsyncSnapshot> <stateBackend> <kafkaParallelism> <windowParallelism>"); System.err.println("<stateBackend> - fs | rocksDb"); System.exit(1);/*from w w w . java2 s . co m*/ } String brokerUri = args[0]; String topic = args[1]; String offsetReset = args[2]; int lagMs = Integer.parseInt(args[3]); int windowSize = Integer.parseInt(args[4]); int slideBy = Integer.parseInt(args[5]); String outputPath = args[6]; int checkpointInt = Integer.parseInt(args[7]); String checkpointUri = args[8]; boolean doAsyncSnapshot = Boolean.parseBoolean(args[9]); String stateBackend = args[10]; int kafkaParallelism = Integer.parseInt(args[11]); int windowParallelism = Integer.parseInt(args[12]); System.out.println("bootstrap.servers: " + brokerUri); System.out.println("topic: " + topic); System.out.println("offset-reset: " + offsetReset); System.out.println("lag: " + lagMs); System.out.println("windowSize: " + windowSize); System.out.println("slideBy: " + slideBy); System.out.println("outputPath: " + outputPath); System.out.println("checkpointInt: " + checkpointInt); System.out.println("checkpointUri: " + checkpointUri); System.out.println("doAsyncSnapshot: " + doAsyncSnapshot); System.out.println("stateBackend: " + stateBackend); System.out.println("kafkaParallelism: " + kafkaParallelism); System.out.println("windowParallelism: " + windowParallelism); // set up the execution environment StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime); if (checkpointInt > 0) { env.enableCheckpointing(checkpointInt); env.getCheckpointConfig().setMinPauseBetweenCheckpoints(checkpointInt); } env.setRestartStrategy(RestartStrategies.fixedDelayRestart(Integer.MAX_VALUE, 5000)); if ("fs".equalsIgnoreCase(stateBackend)) { env.setStateBackend(new FsStateBackend(checkpointUri, doAsyncSnapshot)); } else if ("rocksDb".equalsIgnoreCase(stateBackend)) { env.setStateBackend(new RocksDBStateBackend(checkpointUri)); } else { System.err.println("Bad value for stateBackend: " + stateBackend); System.exit(1); } DeserializationSchema<Trade> schema = new AbstractDeserializationSchema<Trade>() { TradeDeserializer deserializer = new TradeDeserializer(); @Override public Trade deserialize(byte[] message) throws IOException { return deserializer.deserialize(null, message); } }; DataStreamSource<Trade> trades = env .addSource(new FlinkKafkaConsumer010<>(topic, schema, getKafkaProperties(brokerUri, offsetReset))) .setParallelism(kafkaParallelism); AssignerWithPeriodicWatermarks<Trade> timestampExtractor = new BoundedOutOfOrdernessTimestampExtractor<Trade>( Time.milliseconds(lagMs)) { @Override public long extractTimestamp(Trade element) { return element.getTime(); } }; WindowAssigner window = windowSize == slideBy ? TumblingEventTimeWindows.of(Time.milliseconds(windowSize)) : SlidingEventTimeWindows.of(Time.milliseconds(windowSize), Time.milliseconds(slideBy)); trades.assignTimestampsAndWatermarks(timestampExtractor).keyBy((Trade t) -> t.getTicker()).window(window) .aggregate(new AggregateFunction<Trade, MutableLong, Long>() { @Override public MutableLong createAccumulator() { return new MutableLong(); } @Override public MutableLong add(Trade value, MutableLong accumulator) { accumulator.increment(); return accumulator; } @Override public MutableLong merge(MutableLong a, MutableLong b) { a.setValue(Math.addExact(a.longValue(), b.longValue())); return a; } @Override public Long getResult(MutableLong accumulator) { return accumulator.longValue(); } }, new WindowFunction<Long, Tuple5<String, String, Long, Long, Long>, String, TimeWindow>() { @Override public void apply(String key, TimeWindow window, Iterable<Long> input, Collector<Tuple5<String, String, Long, Long, Long>> out) throws Exception { long timeMs = System.currentTimeMillis(); long count = input.iterator().next(); long latencyMs = timeMs - window.getEnd() - lagMs; out.collect( new Tuple5<>(Instant.ofEpochMilli(window.getEnd()).atZone(ZoneId.systemDefault()) .toLocalTime().toString(), key, count, timeMs, latencyMs)); } }).setParallelism(windowParallelism).writeAsCsv(outputPath, WriteMode.OVERWRITE); env.execute("Trade Monitor Example"); }
From source file:Main.java
public static java.sql.Date localTimeToDate(LocalDateTime lt) { return new java.sql.Date(lt.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); }
From source file:Main.java
public static Date fromLocalDate(LocalDate date) { Instant instant = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(); return Date.from(instant); }
From source file:Main.java
public static Timestamp toTimestamp(LocalDate localDate) { Date date = Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant()); Timestamp timeStamp = new Timestamp(date.getTime()); return timeStamp; }
From source file:Main.java
public static ZonedDateTime toZonedDateTime(Date utilDate) { if (utilDate == null) { return null; }// w w w .j av a2s . c om final ZoneId systemDefault = ZoneId.systemDefault(); return ZonedDateTime.ofInstant(utilDate.toInstant(), systemDefault); }
From source file:Main.java
public static LocalDate fromDate(Date date) { Instant instant = Instant.ofEpochMilli(date.getTime()); return LocalDateTime.ofInstant(instant, ZoneId.systemDefault()).toLocalDate(); }
From source file:Main.java
public static Date toDate(LocalTime localTime) { Instant instant = localTime.atDate(LocalDate.now()).atZone(ZoneId.systemDefault()).toInstant(); return toDate(instant); }
From source file:com.rcs.shoe.shop.fx.utils.DateUtils.java
public static Date convert(LocalDate localDate) { Instant instant = Instant.from(localDate.atStartOfDay(ZoneId.systemDefault())); return Date.from(instant); }
From source file:com.rcs.shoe.shop.fx.utils.DateUtils.java
public static LocalDate convert(Date date) { Instant instant = date.toInstant(); return instant.atZone(ZoneId.systemDefault()).toLocalDate(); }