Java Code Examples for org.apache.flink.api.common.time.Time#toMilliseconds()
The following examples show how to use
org.apache.flink.api.common.time.Time#toMilliseconds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemResourcesCounter.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
public SystemResourcesCounter(Time probeInterval) { probeIntervalMs = probeInterval.toMilliseconds(); checkState(this.probeIntervalMs > 0); setName(SystemResourcesCounter.class.getSimpleName() + " probing thread"); cpuUsagePerProcessor = new AtomicReferenceArray<>(hardwareAbstractionLayer.getProcessor().getLogicalProcessorCount()); NetworkIF[] networkIFs = hardwareAbstractionLayer.getNetworkIFs(); bytesReceivedPerInterface = new long[networkIFs.length]; bytesSentPerInterface = new long[networkIFs.length]; receiveRatePerInterface = new AtomicLongArray(networkIFs.length); sendRatePerInterface = new AtomicLongArray(networkIFs.length); networkInterfaceNames = new String[networkIFs.length]; for (int i = 0; i < networkInterfaceNames.length; i++) { networkInterfaceNames[i] = networkIFs[i].getName(); } }
Example 2
Source File: SystemResourcesCounter.java From flink with Apache License 2.0 | 6 votes |
public SystemResourcesCounter(Time probeInterval) { probeIntervalMs = probeInterval.toMilliseconds(); checkState(this.probeIntervalMs > 0); setName(SystemResourcesCounter.class.getSimpleName() + " probing thread"); cpuUsagePerProcessor = new AtomicReferenceArray<>(hardwareAbstractionLayer.getProcessor().getLogicalProcessorCount()); NetworkIF[] networkIFs = hardwareAbstractionLayer.getNetworkIFs(); bytesReceivedPerInterface = new long[networkIFs.length]; bytesSentPerInterface = new long[networkIFs.length]; receiveRatePerInterface = new AtomicLongArray(networkIFs.length); sendRatePerInterface = new AtomicLongArray(networkIFs.length); networkInterfaceNames = new String[networkIFs.length]; for (int i = 0; i < networkInterfaceNames.length; i++) { networkInterfaceNames[i] = networkIFs[i].getName(); } }
Example 3
Source File: SystemResourcesCounter.java From flink with Apache License 2.0 | 6 votes |
public SystemResourcesCounter(Time probeInterval) { probeIntervalMs = probeInterval.toMilliseconds(); checkState(this.probeIntervalMs > 0); setName(SystemResourcesCounter.class.getSimpleName() + " probing thread"); cpuUsagePerProcessor = new AtomicReferenceArray<>(hardwareAbstractionLayer.getProcessor().getLogicalProcessorCount()); NetworkIF[] networkIFs = hardwareAbstractionLayer.getNetworkIFs(); bytesReceivedPerInterface = new long[networkIFs.length]; bytesSentPerInterface = new long[networkIFs.length]; receiveRatePerInterface = new AtomicLongArray(networkIFs.length); sendRatePerInterface = new AtomicLongArray(networkIFs.length); networkInterfaceNames = new String[networkIFs.length]; for (int i = 0; i < networkInterfaceNames.length; i++) { networkInterfaceNames[i] = networkIFs[i].getName(); } }
Example 4
Source File: PhysicalSlotRequestBulkChecker.java From flink with Apache License 2.0 | 6 votes |
/** * Check the slot request bulk and timeout its requests if it has been unfulfillable for too long. * @param slotRequestBulk bulk of slot requests * @param slotRequestTimeout indicates how long a pending request can be unfulfillable * @return result of the check, indicating the bulk is fulfilled, still pending, or timed out */ TimeoutCheckResult checkPhysicalSlotRequestBulkTimeout( final PhysicalSlotRequestBulk slotRequestBulk, final Time slotRequestTimeout) { if (slotRequestBulk.getPendingRequests().isEmpty()) { return TimeoutCheckResult.FULFILLED; } final boolean fulfillable = isSlotRequestBulkFulfillable(slotRequestBulk, slotsRetriever); if (fulfillable) { slotRequestBulk.markFulfillable(); } else { final long currentTimestamp = clock.relativeTimeMillis(); slotRequestBulk.markUnfulfillable(currentTimestamp); final long unfulfillableSince = slotRequestBulk.getUnfulfillableSince(); if (unfulfillableSince + slotRequestTimeout.toMilliseconds() <= currentTimestamp) { return TimeoutCheckResult.TIMEOUT; } } return TimeoutCheckResult.PENDING; }
Example 5
Source File: TestBaseUtils.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public static String getFromHTTP(String url, Time timeout) throws Exception { final URL u = new URL(url); LOG.info("Accessing URL " + url + " as URL: " + u); final long deadline = timeout.toMilliseconds() + System.currentTimeMillis(); while (System.currentTimeMillis() <= deadline) { HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setConnectTimeout(100000); connection.connect(); if (Objects.equals(HttpResponseStatus.SERVICE_UNAVAILABLE, HttpResponseStatus.valueOf(connection.getResponseCode()))) { // service not available --> Sleep and retry LOG.debug("Web service currently not available. Retrying the request in a bit."); Thread.sleep(100L); } else { InputStream is; if (connection.getResponseCode() >= 400) { // error! LOG.warn("HTTP Response code when connecting to {} was {}", url, connection.getResponseCode()); is = connection.getErrorStream(); } else { is = connection.getInputStream(); } return IOUtils.toString(is, ConfigConstants.DEFAULT_CHARSET); } } throw new TimeoutException("Could not get HTTP response in time since the service is still unavailable."); }
Example 6
Source File: TestBaseUtils.java From flink with Apache License 2.0 | 5 votes |
public static String getFromHTTP(String url, Time timeout) throws Exception { final URL u = new URL(url); LOG.info("Accessing URL " + url + " as URL: " + u); final long deadline = timeout.toMilliseconds() + System.currentTimeMillis(); while (System.currentTimeMillis() <= deadline) { HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setConnectTimeout(100000); connection.connect(); if (Objects.equals(HttpResponseStatus.SERVICE_UNAVAILABLE, HttpResponseStatus.valueOf(connection.getResponseCode()))) { // service not available --> Sleep and retry LOG.debug("Web service currently not available. Retrying the request in a bit."); Thread.sleep(100L); } else { InputStream is; if (connection.getResponseCode() >= 400) { // error! LOG.warn("HTTP Response code when connecting to {} was {}", url, connection.getResponseCode()); is = connection.getErrorStream(); } else { is = connection.getInputStream(); } return IOUtils.toString(is, ConfigConstants.DEFAULT_CHARSET); } } throw new TimeoutException("Could not get HTTP response in time since the service is still unavailable."); }
Example 7
Source File: TestBaseUtils.java From flink with Apache License 2.0 | 5 votes |
public static String getFromHTTP(String url, Time timeout) throws Exception { final URL u = new URL(url); LOG.info("Accessing URL " + url + " as URL: " + u); final long deadline = timeout.toMilliseconds() + System.currentTimeMillis(); while (System.currentTimeMillis() <= deadline) { HttpURLConnection connection = (HttpURLConnection) u.openConnection(); connection.setConnectTimeout(100000); connection.connect(); if (Objects.equals(HttpResponseStatus.SERVICE_UNAVAILABLE, HttpResponseStatus.valueOf(connection.getResponseCode()))) { // service not available --> Sleep and retry LOG.debug("Web service currently not available. Retrying the request in a bit."); Thread.sleep(100L); } else { InputStream is; if (connection.getResponseCode() >= 400) { // error! LOG.warn("HTTP Response code when connecting to {} was {}", url, connection.getResponseCode()); is = connection.getErrorStream(); } else { is = connection.getInputStream(); } return IOUtils.toString(is, ConfigConstants.DEFAULT_CHARSET); } } throw new TimeoutException("Could not get HTTP response in time since the service is still unavailable."); }
Example 8
Source File: KeyedScottyWindowOperator.java From scotty-window-processor with Apache License 2.0 | 4 votes |
public KeyedScottyWindowOperator allowedLateness(Time time){ this.allowedLateness = time.toMilliseconds(); return this; }
Example 9
Source File: GlobalScottyWindowOperator.java From scotty-window-processor with Apache License 2.0 | 4 votes |
public GlobalScottyWindowOperator allowedLateness(Time time){ this.allowedLateness = time.toMilliseconds(); return this; }
Example 10
Source File: StreamQueryConfig.java From Flink-CEPplus with Apache License 2.0 | 3 votes |
/** * Specifies a minimum and a maximum time interval for how long idle state, i.e., state which * was not updated, will be retained. * State will never be cleared until it was idle for less than the minimum time and will never * be kept if it was idle for more than the maximum time. * * <p>When new data arrives for previously cleaned-up state, the new data will be handled as if it * was the first data. This can result in previous results being overwritten. * * <p>Set to 0 (zero) to never clean-up the state. * * <p>NOTE: Cleaning up state requires additional bookkeeping which becomes less expensive for * larger differences of minTime and maxTime. The difference between minTime and maxTime must be * at least 5 minutes. * * @param minTime The minimum time interval for which idle state is retained. Set to 0 (zero) to * never clean-up the state. * @param maxTime The maximum time interval for which idle state is retained. Must be at least * 5 minutes greater than minTime. Set to 0 (zero) to never clean-up the state. */ public StreamQueryConfig withIdleStateRetentionTime(Time minTime, Time maxTime) { if (maxTime.toMilliseconds() - minTime.toMilliseconds() < 300000 && !(maxTime.toMilliseconds() == 0 && minTime.toMilliseconds() == 0)) { throw new IllegalArgumentException( "Difference between minTime: " + minTime.toString() + " and maxTime: " + maxTime.toString() + "shoud be at least 5 minutes."); } minIdleStateRetentionTime = minTime.toMilliseconds(); maxIdleStateRetentionTime = maxTime.toMilliseconds(); return this; }
Example 11
Source File: TableConfig.java From flink with Apache License 2.0 | 3 votes |
/** * Specifies a minimum and a maximum time interval for how long idle state, i.e., state which * was not updated, will be retained. * State will never be cleared until it was idle for less than the minimum time and will never * be kept if it was idle for more than the maximum time. * * <p>When new data arrives for previously cleaned-up state, the new data will be handled as if it * was the first data. This can result in previous results being overwritten. * * <p>Set to 0 (zero) to never clean-up the state. * * <p>NOTE: Cleaning up state requires additional bookkeeping which becomes less expensive for * larger differences of minTime and maxTime. The difference between minTime and maxTime must be * at least 5 minutes. * * @param minTime The minimum time interval for which idle state is retained. Set to 0 (zero) to * never clean-up the state. * @param maxTime The maximum time interval for which idle state is retained. Must be at least * 5 minutes greater than minTime. Set to 0 (zero) to never clean-up the state. */ public void setIdleStateRetentionTime(Time minTime, Time maxTime) { if (maxTime.toMilliseconds() - minTime.toMilliseconds() < 300000 && !(maxTime.toMilliseconds() == 0 && minTime.toMilliseconds() == 0)) { throw new IllegalArgumentException( "Difference between minTime: " + minTime.toString() + " and maxTime: " + maxTime.toString() + "shoud be at least 5 minutes."); } minIdleStateRetentionTime = minTime.toMilliseconds(); maxIdleStateRetentionTime = maxTime.toMilliseconds(); }
Example 12
Source File: StreamQueryConfig.java From flink with Apache License 2.0 | 3 votes |
/** * Specifies a minimum and a maximum time interval for how long idle state, i.e., state which * was not updated, will be retained. * State will never be cleared until it was idle for less than the minimum time and will never * be kept if it was idle for more than the maximum time. * * <p>When new data arrives for previously cleaned-up state, the new data will be handled as if it * was the first data. This can result in previous results being overwritten. * * <p>Set to 0 (zero) to never clean-up the state. * * <p>NOTE: Cleaning up state requires additional bookkeeping which becomes less expensive for * larger differences of minTime and maxTime. The difference between minTime and maxTime must be * at least 5 minutes. * * @param minTime The minimum time interval for which idle state is retained. Set to 0 (zero) to * never clean-up the state. * @param maxTime The maximum time interval for which idle state is retained. Must be at least * 5 minutes greater than minTime. Set to 0 (zero) to never clean-up the state. */ public StreamQueryConfig withIdleStateRetentionTime(Time minTime, Time maxTime) { if (maxTime.toMilliseconds() - minTime.toMilliseconds() < 300000 && !(maxTime.toMilliseconds() == 0 && minTime.toMilliseconds() == 0)) { throw new IllegalArgumentException( "Difference between minTime: " + minTime.toString() + " and maxTime: " + maxTime.toString() + "shoud be at least 5 minutes."); } minIdleStateRetentionTime = minTime.toMilliseconds(); maxIdleStateRetentionTime = maxTime.toMilliseconds(); return this; }
Example 13
Source File: TableConfig.java From flink with Apache License 2.0 | 3 votes |
/** * Specifies a minimum and a maximum time interval for how long idle state, i.e., state which * was not updated, will be retained. * State will never be cleared until it was idle for less than the minimum time and will never * be kept if it was idle for more than the maximum time. * * <p>When new data arrives for previously cleaned-up state, the new data will be handled as if it * was the first data. This can result in previous results being overwritten. * * <p>Set to 0 (zero) to never clean-up the state. * * <p>NOTE: Cleaning up state requires additional bookkeeping which becomes less expensive for * larger differences of minTime and maxTime. The difference between minTime and maxTime must be * at least 5 minutes. * * @param minTime The minimum time interval for which idle state is retained. Set to 0 (zero) to * never clean-up the state. * @param maxTime The maximum time interval for which idle state is retained. Must be at least * 5 minutes greater than minTime. Set to 0 (zero) to never clean-up the state. */ public void setIdleStateRetentionTime(Time minTime, Time maxTime) { if (maxTime.toMilliseconds() - minTime.toMilliseconds() < 300000 && !(maxTime.toMilliseconds() == 0 && minTime.toMilliseconds() == 0)) { throw new IllegalArgumentException( "Difference between minTime: " + minTime.toString() + " and maxTime: " + maxTime.toString() + "shoud be at least 5 minutes."); } minIdleStateRetentionTime = minTime.toMilliseconds(); maxIdleStateRetentionTime = maxTime.toMilliseconds(); }
Example 14
Source File: FutureUtils.java From Flink-CEPplus with Apache License 2.0 | 2 votes |
/** * Converts Flink time into a {@link FiniteDuration}. * * @param time to convert into a FiniteDuration * @return FiniteDuration with the length of the given time */ public static FiniteDuration toFiniteDuration(Time time) { return new FiniteDuration(time.toMilliseconds(), TimeUnit.MILLISECONDS); }
Example 15
Source File: FutureUtils.java From flink with Apache License 2.0 | 2 votes |
/** * Converts Flink time into a {@link FiniteDuration}. * * @param time to convert into a FiniteDuration * @return FiniteDuration with the length of the given time */ public static FiniteDuration toFiniteDuration(Time time) { return new FiniteDuration(time.toMilliseconds(), TimeUnit.MILLISECONDS); }