File size: 118,539 Bytes
5a9e79d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 | diff --git a/flink-core/src/main/java/org/apache/flink/api/common/restartstrategy/RestartStrategies.java b/flink-core/src/main/java/org/apache/flink/api/common/restartstrategy/RestartStrategies.java
index 10363d77f65..86d39d32217 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/restartstrategy/RestartStrategies.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/restartstrategy/RestartStrategies.java
@@ -90,9 +90,23 @@ public class RestartStrategies {
* @param restartAttempts Number of restart attempts for the FixedDelayRestartStrategy
* @param delayInterval Delay in-between restart attempts for the FixedDelayRestartStrategy
* @return FixedDelayRestartStrategy
+ * @deprecated Use {@link #fixedDelayRestart(int, Duration)}
*/
+ @Deprecated
public static RestartStrategyConfiguration fixedDelayRestart(
int restartAttempts, Time delayInterval) {
+ return fixedDelayRestart(restartAttempts, Time.toDuration(delayInterval));
+ }
+
+ /**
+ * Generates a FixedDelayRestartStrategyConfiguration.
+ *
+ * @param restartAttempts Number of restart attempts for the FixedDelayRestartStrategy
+ * @param delayInterval Delay in-between restart attempts for the FixedDelayRestartStrategy
+ * @return FixedDelayRestartStrategy
+ */
+ public static RestartStrategyConfiguration fixedDelayRestart(
+ int restartAttempts, Duration delayInterval) {
return new FixedDelayRestartStrategyConfiguration(restartAttempts, delayInterval);
}
@@ -103,9 +117,25 @@ public class RestartStrategies {
* before failing a job
* @param failureInterval Time interval for failures
* @param delayInterval Delay in-between restart attempts
+ * @deprecated Use {@link #failureRateRestart(int, Duration, Duration)}
*/
+ @Deprecated
public static FailureRateRestartStrategyConfiguration failureRateRestart(
int failureRate, Time failureInterval, Time delayInterval) {
+ return failureRateRestart(
+ failureRate, Time.toDuration(failureInterval), Time.toDuration(delayInterval));
+ }
+
+ /**
+ * Generates a FailureRateRestartStrategyConfiguration.
+ *
+ * @param failureRate Maximum number of restarts in given interval {@code failureInterval}
+ * before failing a job
+ * @param failureInterval Time interval for failures
+ * @param delayInterval Delay in-between restart attempts
+ */
+ public static FailureRateRestartStrategyConfiguration failureRateRestart(
+ int failureRate, Duration failureInterval, Duration delayInterval) {
return new FailureRateRestartStrategyConfiguration(
failureRate, failureInterval, delayInterval);
}
@@ -118,18 +148,45 @@ public class RestartStrategies {
* @param backoffMultiplier Delay multiplier how many times is the delay longer than before
* @param resetBackoffThreshold How long the job must run smoothly to reset the time interval
* @param jitterFactor How much the delay may differ (in percentage)
+ * @deprecated Use {@link #exponentialDelayRestart(Duration, Duration, double, Duration,
+ * double)}
*/
+ @Deprecated
public static ExponentialDelayRestartStrategyConfiguration exponentialDelayRestart(
Time initialBackoff,
Time maxBackoff,
double backoffMultiplier,
Time resetBackoffThreshold,
double jitterFactor) {
+ return exponentialDelayRestart(
+ Time.toDuration(initialBackoff),
+ Time.toDuration(maxBackoff),
+ backoffMultiplier,
+ Time.toDuration(resetBackoffThreshold),
+ jitterFactor);
+ }
+
+ /**
+ * Generates a ExponentialDelayRestartStrategyConfiguration.
+ *
+ * @param initialBackoff Starting duration between restarts
+ * @param maxBackoff The highest possible duration between restarts
+ * @param backoffMultiplier Delay multiplier how many times is the delay longer than before
+ * @param resetBackoffThreshold How long the job must run smoothly to reset the time interval
+ * @param jitterFactor How much the delay may differ (in percentage)
+ */
+ public static ExponentialDelayRestartStrategyConfiguration exponentialDelayRestart(
+ Duration initialBackoff,
+ Duration maxBackoff,
+ double backoffMultiplier,
+ Duration resetBackoffThreshold,
+ double jitterFactor) {
return new ExponentialDelayRestartStrategyConfiguration(
initialBackoff, maxBackoff, backoffMultiplier, resetBackoffThreshold, jitterFactor);
}
/** Abstract configuration for restart strategies. */
+ @PublicEvolving
public abstract static class RestartStrategyConfiguration implements Serializable {
private static final long serialVersionUID = 6285853591578313960L;
@@ -149,6 +206,7 @@ public class RestartStrategies {
}
/** Configuration representing no restart strategy. */
+ @PublicEvolving
public static final class NoRestartStrategyConfiguration extends RestartStrategyConfiguration {
private static final long serialVersionUID = -5894362702943349962L;
@@ -172,15 +230,16 @@ public class RestartStrategies {
}
/** Configuration representing a fixed delay restart strategy. */
+ @PublicEvolving
public static final class FixedDelayRestartStrategyConfiguration
extends RestartStrategyConfiguration {
private static final long serialVersionUID = 4149870149673363190L;
private final int restartAttempts;
- private final Time delayBetweenAttemptsInterval;
+ private final Duration delayBetweenAttemptsInterval;
FixedDelayRestartStrategyConfiguration(
- int restartAttempts, Time delayBetweenAttemptsInterval) {
+ int restartAttempts, Duration delayBetweenAttemptsInterval) {
this.restartAttempts = restartAttempts;
this.delayBetweenAttemptsInterval = delayBetweenAttemptsInterval;
}
@@ -189,7 +248,13 @@ public class RestartStrategies {
return restartAttempts;
}
+ /** @deprecated Use {@link #getDurationBetweenAttempts()} */
+ @Deprecated
public Time getDelayBetweenAttemptsInterval() {
+ return Time.fromDuration(getDurationBetweenAttempts());
+ }
+
+ public Duration getDurationBetweenAttempts() {
return delayBetweenAttemptsInterval;
}
@@ -226,22 +291,43 @@ public class RestartStrategies {
}
/** Configuration representing an exponential delay restart strategy. */
+ @PublicEvolving
public static final class ExponentialDelayRestartStrategyConfiguration
extends RestartStrategyConfiguration {
private static final long serialVersionUID = 1467941615941965194L;
- private final Time initialBackoff;
- private final Time maxBackoff;
+ private final Duration initialBackoff;
+ private final Duration maxBackoff;
private final double backoffMultiplier;
- private final Time resetBackoffThreshold;
+ private final Duration resetBackoffThreshold;
private final double jitterFactor;
+ /**
+ * @deprecated Use {@link
+ * ExponentialDelayRestartStrategyConfiguration#ExponentialDelayRestartStrategyConfiguration(Duration,
+ * Duration, double, Duration, double)}
+ */
+ @Deprecated
public ExponentialDelayRestartStrategyConfiguration(
Time initialBackoff,
Time maxBackoff,
double backoffMultiplier,
Time resetBackoffThreshold,
double jitterFactor) {
+ this(
+ Time.toDuration(initialBackoff),
+ Time.toDuration(maxBackoff),
+ backoffMultiplier,
+ Time.toDuration(resetBackoffThreshold),
+ jitterFactor);
+ }
+
+ public ExponentialDelayRestartStrategyConfiguration(
+ Duration initialBackoff,
+ Duration maxBackoff,
+ double backoffMultiplier,
+ Duration resetBackoffThreshold,
+ double jitterFactor) {
this.initialBackoff = initialBackoff;
this.maxBackoff = maxBackoff;
this.backoffMultiplier = backoffMultiplier;
@@ -249,11 +335,23 @@ public class RestartStrategies {
this.jitterFactor = jitterFactor;
}
+ /** @deprecated Use {@link #getInitialBackoffDuration()} */
+ @Deprecated
public Time getInitialBackoff() {
+ return Time.fromDuration(getInitialBackoffDuration());
+ }
+
+ public Duration getInitialBackoffDuration() {
return initialBackoff;
}
+ /** @deprecated Use {@link #getMaxBackoffDuration()} */
+ @Deprecated
public Time getMaxBackoff() {
+ return Time.fromDuration(maxBackoff);
+ }
+
+ public Duration getMaxBackoffDuration() {
return maxBackoff;
}
@@ -261,7 +359,13 @@ public class RestartStrategies {
return backoffMultiplier;
}
+ /** @deprecated Use {@link #getResetBackoffDurationThreshold()} */
+ @Deprecated
public Time getResetBackoffThreshold() {
+ return Time.fromDuration(resetBackoffThreshold);
+ }
+
+ public Duration getResetBackoffDurationThreshold() {
return resetBackoffThreshold;
}
@@ -310,16 +414,31 @@ public class RestartStrategies {
}
/** Configuration representing a failure rate restart strategy. */
+ @PublicEvolving
public static final class FailureRateRestartStrategyConfiguration
extends RestartStrategyConfiguration {
private static final long serialVersionUID = 1195028697539661739L;
private final int maxFailureRate;
- private final Time failureInterval;
- private final Time delayBetweenAttemptsInterval;
+ private final Duration failureInterval;
+ private final Duration delayBetweenAttemptsInterval;
+ /**
+ * @deprecated Use {@link #FailureRateRestartStrategyConfiguration(int, Duration, Duration)}
+ */
+ @Deprecated
public FailureRateRestartStrategyConfiguration(
int maxFailureRate, Time failureInterval, Time delayBetweenAttemptsInterval) {
+ this(
+ maxFailureRate,
+ Time.toDuration(failureInterval),
+ Time.toDuration(delayBetweenAttemptsInterval));
+ }
+
+ public FailureRateRestartStrategyConfiguration(
+ int maxFailureRate,
+ Duration failureInterval,
+ Duration delayBetweenAttemptsInterval) {
this.maxFailureRate = maxFailureRate;
this.failureInterval = failureInterval;
this.delayBetweenAttemptsInterval = delayBetweenAttemptsInterval;
@@ -329,11 +448,23 @@ public class RestartStrategies {
return maxFailureRate;
}
+ /** @deprecated Use {@link #getFailureIntervalDuration()} */
+ @Deprecated
public Time getFailureInterval() {
+ return Time.fromDuration(getFailureIntervalDuration());
+ }
+
+ public Duration getFailureIntervalDuration() {
return failureInterval;
}
+ /** @deprecated Use {@link #getDurationBetweenAttempts()} */
+ @Deprecated
public Time getDelayBetweenAttemptsInterval() {
+ return Time.fromDuration(getDurationBetweenAttempts());
+ }
+
+ public Duration getDurationBetweenAttempts() {
return delayBetweenAttemptsInterval;
}
@@ -373,6 +504,7 @@ public class RestartStrategies {
* strategy. Useful especially when one has a custom implementation of restart strategy set via
* flink-conf.yaml.
*/
+ @PublicEvolving
public static final class FallbackRestartStrategyConfiguration
extends RestartStrategyConfiguration {
private static final long serialVersionUID = -4441787204284085544L;
@@ -448,10 +580,10 @@ public class RestartStrategies {
RestartStrategyOptions
.RESTART_STRATEGY_EXPONENTIAL_DELAY_JITTER_FACTOR);
return exponentialDelayRestart(
- Time.milliseconds(initialBackoff.toMillis()),
- Time.milliseconds(maxBackoff.toMillis()),
+ initialBackoff,
+ maxBackoff,
backoffMultiplier,
- Time.milliseconds(resetBackoffThreshold.toMillis()),
+ resetBackoffThreshold,
jitter);
case "failurerate":
case "failure-rate":
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/state/StateTtlConfig.java b/flink-core/src/main/java/org/apache/flink/api/common/state/StateTtlConfig.java
index 9e443c42453..26ef85f49e1 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/state/StateTtlConfig.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/state/StateTtlConfig.java
@@ -27,6 +27,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.Serializable;
+import java.time.Duration;
import java.util.EnumMap;
import static org.apache.flink.api.common.state.StateTtlConfig.CleanupStrategies.EMPTY_STRATEGY;
@@ -53,13 +54,14 @@ public class StateTtlConfig implements Serializable {
private static final long serialVersionUID = -7592693245044289793L;
public static final StateTtlConfig DISABLED =
- newBuilder(Time.milliseconds(Long.MAX_VALUE))
+ newBuilder(Duration.ofMillis(Long.MAX_VALUE))
.setUpdateType(UpdateType.Disabled)
.build();
/**
* This option value configures when to update last access timestamp which prolongs state TTL.
*/
+ @PublicEvolving
public enum UpdateType {
/** TTL is disabled. State does not expire. */
Disabled,
@@ -73,6 +75,7 @@ public class StateTtlConfig implements Serializable {
}
/** This option configures whether expired user value can be returned or not. */
+ @PublicEvolving
public enum StateVisibility {
/** Return expired user value if it is not cleaned up yet. */
ReturnExpiredIfNotCleanedUp,
@@ -81,6 +84,7 @@ public class StateTtlConfig implements Serializable {
}
/** This option configures time scale to use for ttl. */
+ @PublicEvolving
public enum TtlTimeCharacteristic {
/**
* Processing time, see also <code>
@@ -92,21 +96,21 @@ public class StateTtlConfig implements Serializable {
private final UpdateType updateType;
private final StateVisibility stateVisibility;
private final TtlTimeCharacteristic ttlTimeCharacteristic;
- private final Time ttl;
+ private final Duration ttl;
private final CleanupStrategies cleanupStrategies;
private StateTtlConfig(
UpdateType updateType,
StateVisibility stateVisibility,
TtlTimeCharacteristic ttlTimeCharacteristic,
- Time ttl,
+ Duration ttl,
CleanupStrategies cleanupStrategies) {
this.updateType = checkNotNull(updateType);
this.stateVisibility = checkNotNull(stateVisibility);
this.ttlTimeCharacteristic = checkNotNull(ttlTimeCharacteristic);
this.ttl = checkNotNull(ttl);
this.cleanupStrategies = cleanupStrategies;
- checkArgument(ttl.toMilliseconds() > 0, "TTL is expected to be positive.");
+ checkArgument(ttl.toMillis() > 0, "TTL is expected to be positive.");
}
@Nonnull
@@ -119,8 +123,14 @@ public class StateTtlConfig implements Serializable {
return stateVisibility;
}
+ /** @deprecated Use {@link #getTimeToLive()} */
+ @Deprecated
@Nonnull
public Time getTtl() {
+ return Time.fromDuration(getTimeToLive());
+ }
+
+ public Duration getTimeToLive() {
return ttl;
}
@@ -152,23 +162,36 @@ public class StateTtlConfig implements Serializable {
+ '}';
}
+ /** @deprecated Use {@link #newBuilder(Duration)} */
+ @Deprecated
@Nonnull
public static Builder newBuilder(@Nonnull Time ttl) {
return new Builder(ttl);
}
+ public static Builder newBuilder(Duration ttl) {
+ return new Builder(ttl);
+ }
+
/** Builder for the {@link StateTtlConfig}. */
+ @PublicEvolving
public static class Builder {
private UpdateType updateType = OnCreateAndWrite;
private StateVisibility stateVisibility = NeverReturnExpired;
private TtlTimeCharacteristic ttlTimeCharacteristic = ProcessingTime;
- private Time ttl;
+ private Duration ttl;
private boolean isCleanupInBackground = true;
private final EnumMap<CleanupStrategies.Strategies, CleanupStrategies.CleanupStrategy>
strategies = new EnumMap<>(CleanupStrategies.Strategies.class);
+ /** @deprecated Use {@link #newBuilder(Duration)} */
+ @Deprecated
public Builder(@Nonnull Time ttl) {
+ this(Time.toDuration(ttl));
+ }
+
+ private Builder(Duration ttl) {
this.ttl = ttl;
}
@@ -343,10 +366,16 @@ public class StateTtlConfig implements Serializable {
* Sets the ttl time.
*
* @param ttl The ttl time.
+ * @deprecated Use {@link #setTimeToLive(Duration)}
*/
+ @Deprecated
@Nonnull
public Builder setTtl(@Nonnull Time ttl) {
- this.ttl = ttl;
+ return setTimeToLive(Time.toDuration(ttl));
+ }
+
+ public Builder setTimeToLive(Duration ttl) {
+ this.ttl = Preconditions.checkNotNull(ttl);
return this;
}
@@ -368,6 +397,7 @@ public class StateTtlConfig implements Serializable {
* cleaned up on explicit read access if found expired. Currently cleanup of state full snapshot
* can be additionally activated.
*/
+ @PublicEvolving
public static class CleanupStrategies implements Serializable {
private static final long serialVersionUID = -1617740467277313524L;
@@ -427,6 +457,7 @@ public class StateTtlConfig implements Serializable {
}
/** Configuration of cleanup strategy while taking the full snapshot. */
+ @PublicEvolving
public static class IncrementalCleanupStrategy implements CleanupStrategies.CleanupStrategy {
private static final long serialVersionUID = 3109278696501988780L;
@@ -457,6 +488,7 @@ public class StateTtlConfig implements Serializable {
}
/** Configuration of cleanup strategy using custom compaction filter in RocksDB. */
+ @PublicEvolving
public static class RocksdbCompactFilterCleanupStrategy
implements CleanupStrategies.CleanupStrategy {
private static final long serialVersionUID = 3109278796506988980L;
diff --git a/flink-core/src/main/java/org/apache/flink/api/common/time/Time.java b/flink-core/src/main/java/org/apache/flink/api/common/time/Time.java
index 803478aec91..2018ef4ecda 100644
--- a/flink-core/src/main/java/org/apache/flink/api/common/time/Time.java
+++ b/flink-core/src/main/java/org/apache/flink/api/common/time/Time.java
@@ -20,6 +20,8 @@ package org.apache.flink.api.common.time;
import org.apache.flink.annotation.PublicEvolving;
+import javax.annotation.Nullable;
+
import java.io.Serializable;
import java.time.Duration;
import java.util.Objects;
@@ -32,12 +34,20 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
*
* <p>Note: This class will fully replace org.apache.flink.streaming.api.windowing.time.Time in
* Flink 2.0
+ *
+ * @deprecated Use {@link Duration}
*/
+@Deprecated
@PublicEvolving
public final class Time implements Serializable {
private static final long serialVersionUID = -350254188460915999L;
+ @Nullable
+ public static Duration toDuration(@Nullable Time time) {
+ return time != null ? time.toDuration() : null;
+ }
+
/** The time unit for this policy's time interval. */
private final TimeUnit unit;
@@ -72,6 +82,10 @@ public final class Time implements Serializable {
return size;
}
+ public Duration toDuration() {
+ return Duration.ofMillis(this.toMilliseconds());
+ }
+
/**
* Converts the time interval to milliseconds.
*
diff --git a/flink-core/src/main/java/org/apache/flink/util/TimeUtils.java b/flink-core/src/main/java/org/apache/flink/util/TimeUtils.java
index f4b31cff35f..80d38c78078 100644
--- a/flink-core/src/main/java/org/apache/flink/util/TimeUtils.java
+++ b/flink-core/src/main/java/org/apache/flink/util/TimeUtils.java
@@ -235,7 +235,9 @@ public class TimeUtils {
*
* @param time time to transform into duration
* @return duration equal to the given time
+ * @deprecated Use {@link Duration} APIs
*/
+ @Deprecated
public static Duration toDuration(Time time) {
return Duration.of(time.getSize(), toChronoUnit(time.getUnit()));
}
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/join/WindowJoin.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/join/WindowJoin.java
index 3b6d6c2bd89..abd44392a60 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/join/WindowJoin.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/join/WindowJoin.java
@@ -36,7 +36,6 @@ import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.DefaultRollingPolicy;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
-import org.apache.flink.streaming.api.windowing.time.Time;
import java.time.Duration;
@@ -122,7 +121,7 @@ public class WindowJoin {
return grades.join(salaries)
.where(new NameKeySelector())
.equalTo(new NameKeySelector())
- .window(TumblingEventTimeWindows.of(Time.milliseconds(windowSize)))
+ .window(TumblingEventTimeWindows.of(Duration.ofMillis(windowSize)))
.apply(
new JoinFunction<
Tuple2<String, Integer>,
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/sideoutput/SideOutputExample.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/sideoutput/SideOutputExample.java
index 13dc391e817..6e33f5d9ffc 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/sideoutput/SideOutputExample.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/sideoutput/SideOutputExample.java
@@ -39,7 +39,6 @@ import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.DefaultRollingPolicy;
import org.apache.flink.streaming.api.windowing.assigners.TumblingEventTimeWindows;
-import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.examples.wordcount.util.WordCountData;
import org.apache.flink.util.Collector;
import org.apache.flink.util.OutputTag;
@@ -107,7 +106,7 @@ public class SideOutputExample {
DataStream<Tuple2<String, Integer>> counts =
tokenized
.keyBy(value -> value.f0)
- .window(TumblingEventTimeWindows.of(Time.seconds(5)))
+ .window(TumblingEventTimeWindows.of(Duration.ofSeconds(5)))
// group by the tuple field "0" and sum up tuple field "1"
.sum(1);
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/socket/SocketWindowWordCount.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/socket/SocketWindowWordCount.java
index 76fb37f321f..584183a3ba9 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/socket/SocketWindowWordCount.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/socket/SocketWindowWordCount.java
@@ -24,7 +24,8 @@ import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.assigners.TumblingProcessingTimeWindows;
-import org.apache.flink.streaming.api.windowing.time.Time;
+
+import java.time.Duration;
/**
* Implements a streaming windowed version of the "WordCount" program.
@@ -77,7 +78,7 @@ public class SocketWindowWordCount {
},
Types.POJO(WordWithCount.class))
.keyBy(value -> value.word)
- .window(TumblingProcessingTimeWindows.of(Time.seconds(5)))
+ .window(TumblingProcessingTimeWindows.of(Duration.ofSeconds(5)))
.reduce((a, b) -> new WordWithCount(a.word, a.count + b.count))
.returns(WordWithCount.class);
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/GroupedProcessingTimeWindowExample.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/GroupedProcessingTimeWindowExample.java
index c8020b7d1c3..9db4e35a172 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/GroupedProcessingTimeWindowExample.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/GroupedProcessingTimeWindowExample.java
@@ -31,10 +31,11 @@ import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.v2.DiscardingSink;
import org.apache.flink.streaming.api.functions.windowing.WindowFunction;
import org.apache.flink.streaming.api.windowing.assigners.SlidingProcessingTimeWindows;
-import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.windows.Window;
import org.apache.flink.util.Collector;
+import java.time.Duration;
+
/** An example of grouped stream windowing into sliding time windows. */
public class GroupedProcessingTimeWindowExample {
@@ -60,7 +61,7 @@ public class GroupedProcessingTimeWindowExample {
stream.keyBy(value -> value.f0)
.window(
SlidingProcessingTimeWindows.of(
- Time.milliseconds(2500), Time.milliseconds(500)))
+ Duration.ofMillis(2500), Duration.ofMillis(500)))
.reduce(new SummingReducer())
// alternative: use a apply function which does not pre-aggregate
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java
index 34b3dd7d285..5708a7ae90e 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/SessionWindowing.java
@@ -32,7 +32,6 @@ import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.DefaultRollingPolicy;
import org.apache.flink.streaming.api.windowing.assigners.EventTimeSessionWindows;
-import org.apache.flink.streaming.api.windowing.time.Time;
import java.time.Duration;
import java.util.ArrayList;
@@ -85,7 +84,7 @@ public class SessionWindowing {
// We create sessions for each id with max timeout of 3 time units
DataStream<Tuple3<String, Long, Integer>> aggregated =
source.keyBy(value -> value.f0)
- .window(EventTimeSessionWindows.withGap(Time.milliseconds(3L)))
+ .window(EventTimeSessionWindows.withGap(Duration.ofMillis(3L)))
.sum(2);
if (fileOutput) {
diff --git a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/TopSpeedWindowing.java b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/TopSpeedWindowing.java
index 3cca4cc8f8f..3d12511ac03 100644
--- a/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/TopSpeedWindowing.java
+++ b/flink-examples/flink-examples-streaming/src/main/java/org/apache/flink/streaming/examples/windowing/TopSpeedWindowing.java
@@ -36,13 +36,11 @@ import org.apache.flink.streaming.api.functions.sink.filesystem.rollingpolicies.
import org.apache.flink.streaming.api.functions.windowing.delta.DeltaFunction;
import org.apache.flink.streaming.api.windowing.assigners.GlobalWindows;
import org.apache.flink.streaming.api.windowing.evictors.TimeEvictor;
-import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.triggers.DeltaTrigger;
import org.apache.flink.streaming.examples.windowing.util.CarGeneratorFunction;
import org.apache.flink.streaming.examples.wordcount.util.CLI;
import java.time.Duration;
-import java.util.concurrent.TimeUnit;
/**
* An example of grouped stream windowing where different eviction and trigger policies can be used.
@@ -130,7 +128,7 @@ public class TopSpeedWindowing {
.withTimestampAssigner((car, ts) -> car.f3))
.keyBy(value -> value.f0)
.window(GlobalWindows.create())
- .evictor(TimeEvictor.of(Time.of(evictionSec, TimeUnit.SECONDS)))
+ .evictor(TimeEvictor.of(Duration.ofSeconds(evictionSec)))
.trigger(
DeltaTrigger.of(
triggerMeters,
diff --git a/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala b/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala
index cbbe04d9adc..04606368a03 100644
--- a/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala
+++ b/flink-libraries/flink-cep-scala/src/main/scala/org/apache/flink/cep/scala/pattern/Pattern.scala
@@ -25,6 +25,8 @@ import org.apache.flink.cep.pattern.conditions.IterativeCondition.{Context => JC
import org.apache.flink.cep.scala.conditions.Context
import org.apache.flink.streaming.api.windowing.time.Time
+import java.time.Duration
+
/**
* Base class for a pattern definition.
*
@@ -64,8 +66,14 @@ class Pattern[T, F <: T](jPattern: JPattern[T, F]) {
def getName: String = jPattern.getName
/** @return Window length in which the pattern match has to occur */
+ @deprecated(message = "Use getWindowSize", since = "1.19.0")
def getWindowTime: Option[Time] = {
- Option(jPattern.getWindowTime)
+ getWindowSize.map(Time.of)
+ }
+
+ /** @return Window length in which the pattern match has to occur */
+ def getWindowSize: Option[Duration] = {
+ Option(jPattern.getWindowSize.orElse(null))
}
/** @return currently applied quantifier to this pattern */
@@ -253,17 +261,23 @@ class Pattern[T, F <: T](jPattern: JPattern[T, F]) {
until(condFun)
}
+ @deprecated(message = "Use within(Duration)", since = "1.19.0")
+ def within(windowTime: Time): Pattern[T, F] = {
+ jPattern.within(Time.toDuration(windowTime))
+ this
+ }
+
/**
* Defines the maximum time interval in which a matching pattern has to be completed in order to
* be considered valid. This interval corresponds to the maximum time gap between first and the
* last event.
*
* @param windowTime
- * Time of the matching window
+ * Duration of the matching window
* @return
* The same pattern operator with the new window length
*/
- def within(windowTime: Time): Pattern[T, F] = {
+ def within(windowTime: Duration): Pattern[T, F] = {
jPattern.within(windowTime)
this
}
diff --git a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/functions/TimedOutPartialMatchHandler.java b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/functions/TimedOutPartialMatchHandler.java
index ea790e9fc48..ae222d4e0e2 100644
--- a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/functions/TimedOutPartialMatchHandler.java
+++ b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/functions/TimedOutPartialMatchHandler.java
@@ -19,8 +19,8 @@
package org.apache.flink.cep.functions;
import org.apache.flink.annotation.PublicEvolving;
-import org.apache.flink.streaming.api.windowing.time.Time;
+import java.time.Duration;
import java.util.List;
import java.util.Map;
@@ -42,8 +42,8 @@ public interface TimedOutPartialMatchHandler<IN> {
/**
* Called for every timed out partial match (due to {@link
- * org.apache.flink.cep.pattern.Pattern#within(Time)}). It enables custom handling, e.g. one can
- * emit the timed out results through a side output:
+ * org.apache.flink.cep.pattern.Pattern#within(Duration)}). It enables custom handling, e.g. one
+ * can emit the timed out results through a side output:
*
* <pre>{@code
* private final OutputTag<T> timedOutPartialMatchesTag = ...
diff --git a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/compiler/NFACompiler.java b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/compiler/NFACompiler.java
index 6fd9fa9f2ce..331b2d97033 100644
--- a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/compiler/NFACompiler.java
+++ b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/nfa/compiler/NFACompiler.java
@@ -34,9 +34,9 @@ import org.apache.flink.cep.pattern.conditions.BooleanConditions;
import org.apache.flink.cep.pattern.conditions.IterativeCondition;
import org.apache.flink.cep.pattern.conditions.RichAndCondition;
import org.apache.flink.cep.pattern.conditions.RichNotCondition;
-import org.apache.flink.streaming.api.windowing.time.Time;
import java.io.Serializable;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -318,8 +318,7 @@ public class NFACompiler {
*/
private State<T> createEndingState() {
State<T> endState = createState(ENDING_STATE_NAME, State.StateType.Final);
- windowTime =
- Optional.ofNullable(currentPattern.getWindowTime()).map(Time::toMilliseconds);
+ windowTime = currentPattern.getWindowSize().map(Duration::toMillis);
return endState;
}
@@ -336,7 +335,7 @@ public class NFACompiler {
if (currentPattern.getQuantifier().getConsumingStrategy()
== Quantifier.ConsumingStrategy.NOT_FOLLOW) {
// skip notFollow patterns, they are converted into edge conditions
- if ((currentPattern.getWindowTime(WithinType.PREVIOUS_AND_CURRENT) != null
+ if ((currentPattern.getWindowSize(WithinType.PREVIOUS_AND_CURRENT).isPresent()
|| getWindowTime() > 0)
&& lastSink.isFinal()) {
final State<T> notFollow = createState(State.StateType.Pending, true);
@@ -370,12 +369,15 @@ public class NFACompiler {
followingPattern = currentPattern;
currentPattern = currentPattern.getPrevious();
- final Time currentWindowTime = currentPattern.getWindowTime();
- if (currentWindowTime != null
- && currentWindowTime.toMilliseconds() < windowTime.orElse(Long.MAX_VALUE)) {
- // the window time is the global minimum of all window times of each state
- windowTime = Optional.of(currentWindowTime.toMilliseconds());
- }
+ // the window time is the global minimum of all window times of each state
+ currentPattern
+ .getWindowSize()
+ .map(Duration::toMillis)
+ .filter(
+ windowSizeInMillis ->
+ windowSizeInMillis < windowTime.orElse(Long.MAX_VALUE))
+ .ifPresent(
+ windowSizeInMillis -> windowTime = Optional.of(windowSizeInMillis));
}
return lastSink;
}
@@ -422,13 +424,20 @@ public class NFACompiler {
State<T> state = createState(currentPattern.getName(), stateType);
if (isTake) {
Times times = currentPattern.getTimes();
- Time windowTime = currentPattern.getWindowTime(WithinType.PREVIOUS_AND_CURRENT);
- if (times == null && windowTime != null) {
- windowTimes.put(state.getName(), windowTime.toMilliseconds());
- } else if (times != null
- && times.getWindowTime() != null
- && state.getName().contains(STATE_NAME_DELIM)) {
- windowTimes.put(state.getName(), times.getWindowTime().toMilliseconds());
+ Optional<Duration> windowSize =
+ currentPattern.getWindowSize(WithinType.PREVIOUS_AND_CURRENT);
+ if (times == null) {
+ windowSize
+ .map(Duration::toMillis)
+ .ifPresent(
+ windowSizeInMillis ->
+ windowTimes.put(state.getName(), windowSizeInMillis));
+ } else if (state.getName().contains(STATE_NAME_DELIM)) {
+ times.getWindowSize()
+ .map(Duration::toMillis)
+ .ifPresent(
+ windowSizeInMillis ->
+ windowTimes.put(state.getName(), windowSizeInMillis));
}
}
return state;
diff --git a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
index e5a9a78976c..0b41224fdd2 100644
--- a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
+++ b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
@@ -34,8 +34,10 @@ import org.apache.flink.util.Preconditions;
import javax.annotation.Nullable;
+import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
/**
* Base class for a pattern definition.
@@ -64,7 +66,7 @@ public class Pattern<T, F extends T> {
private IterativeCondition<F> condition;
/** Window length in which the pattern match has to occur. */
- private final Map<WithinType, Time> windowTimes = new HashMap<>();
+ private final Map<WithinType, Duration> windowTimes = new HashMap<>();
/**
* A quantifier for the pattern. By default set to {@link Quantifier#one(ConsumingStrategy)}.
@@ -102,12 +104,26 @@ public class Pattern<T, F extends T> {
return name;
}
+ /** @deprecated Use {@link #getWindowSize()} */
+ @Deprecated
+ @Nullable
public Time getWindowTime() {
- return windowTimes.get(WithinType.FIRST_AND_LAST);
+ return getWindowSize().map(Time::of).orElse(null);
}
+ public Optional<Duration> getWindowSize() {
+ return getWindowSize(WithinType.FIRST_AND_LAST);
+ }
+
+ /** @deprecated Use {@link #getWindowSize(WithinType)}. */
+ @Deprecated
+ @Nullable
public Time getWindowTime(WithinType withinType) {
- return windowTimes.get(withinType);
+ return getWindowSize(withinType).map(Time::of).orElse(null);
+ }
+
+ public Optional<Duration> getWindowSize(WithinType withinType) {
+ return Optional.ofNullable(windowTimes.get(withinType));
}
public Quantifier getQuantifier() {
@@ -243,6 +259,20 @@ public class Pattern<T, F extends T> {
return this;
}
+ /**
+ * Defines the maximum time interval in which a matching pattern has to be completed in order to
+ * be considered valid. This interval corresponds to the maximum time gap between first and the
+ * last event.
+ *
+ * @param windowTime Time of the matching window
+ * @return The same pattern operator with the new window length
+ * @deprecated Use {@link #within(Duration)}.
+ */
+ @Deprecated
+ public Pattern<T, F> within(@Nullable Time windowTime) {
+ return within(Time.toDuration(windowTime));
+ }
+
/**
* Defines the maximum time interval in which a matching pattern has to be completed in order to
* be considered valid. This interval corresponds to the maximum time gap between first and the
@@ -251,7 +281,7 @@ public class Pattern<T, F extends T> {
* @param windowTime Time of the matching window
* @return The same pattern operator with the new window length
*/
- public Pattern<T, F> within(Time windowTime) {
+ public Pattern<T, F> within(@Nullable Duration windowTime) {
return within(windowTime, WithinType.FIRST_AND_LAST);
}
@@ -262,8 +292,22 @@ public class Pattern<T, F extends T> {
* @param withinType Type of the within interval between events
* @param windowTime Time of the matching window
* @return The same pattern operator with the new window length
+ * @deprecated Use {@link #within(Duration, WithinType)}.
*/
- public Pattern<T, F> within(Time windowTime, WithinType withinType) {
+ @Deprecated
+ public Pattern<T, F> within(@Nullable Time windowTime, WithinType withinType) {
+ return within(Time.toDuration(windowTime), withinType);
+ }
+
+ /**
+ * Defines the maximum time interval in which a matching pattern has to be completed in order to
+ * be considered valid. This interval corresponds to the maximum time gap between events.
+ *
+ * @param withinType Type of the within interval between events
+ * @param windowTime Time of the matching window
+ * @return The same pattern operator with the new window length
+ */
+ public Pattern<T, F> within(@Nullable Duration windowTime, WithinType withinType) {
if (windowTime != null) {
windowTimes.put(withinType, windowTime);
}
@@ -369,7 +413,7 @@ public class Pattern<T, F extends T> {
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
*/
public Pattern<T, F> oneOrMore() {
- return oneOrMore(null);
+ return oneOrMore((Duration) null);
}
/**
@@ -385,8 +429,28 @@ public class Pattern<T, F extends T> {
* @return The same pattern with a {@link Quantifier#looping(ConsumingStrategy)} quantifier
* applied.
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ * @deprecated Use {@link #oneOrMore(Duration)}
*/
+ @Deprecated
public Pattern<T, F> oneOrMore(@Nullable Time windowTime) {
+ return oneOrMore(Time.toDuration(windowTime));
+ }
+
+ /**
+ * Specifies that this pattern can occur {@code one or more} times and time interval corresponds
+ * to the maximum time gap between previous and current event for each times. This means at
+ * least one and at most infinite number of events can be matched to this pattern.
+ *
+ * <p>If this quantifier is enabled for a pattern {@code A.oneOrMore().followedBy(B)} and a
+ * sequence of events {@code A1 A2 B} appears, this will generate patterns: {@code A1 B} and
+ * {@code A1 A2 B}. See also {@link #allowCombinations()}.
+ *
+ * @param windowTime time of the matching window between times
+ * @return The same pattern with a {@link Quantifier#looping(ConsumingStrategy)} quantifier
+ * applied.
+ * @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ */
+ public Pattern<T, F> oneOrMore(@Nullable Duration windowTime) {
checkIfNoNotPattern();
checkIfQuantifierApplied();
this.quantifier = Quantifier.looping(quantifier.getConsumingStrategy());
@@ -416,7 +480,7 @@ public class Pattern<T, F extends T> {
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
*/
public Pattern<T, F> times(int times) {
- return times(times, null);
+ return times(times, (Duration) null);
}
/**
@@ -427,8 +491,23 @@ public class Pattern<T, F extends T> {
* @param windowTime time of the matching window between times
* @return The same pattern with number of times applied
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ * @deprecated Using {@link #times(int, Duration)}
*/
+ @Deprecated
public Pattern<T, F> times(int times, @Nullable Time windowTime) {
+ return times(times, Time.toDuration(windowTime));
+ }
+
+ /**
+ * Specifies exact number of times that this pattern should be matched and time interval
+ * corresponds to the maximum time gap between previous and current event for each times.
+ *
+ * @param times number of times matching event must appear
+ * @param windowTime time of the matching window between times
+ * @return The same pattern with number of times applied
+ * @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ */
+ public Pattern<T, F> times(int times, @Nullable Duration windowTime) {
checkIfNoNotPattern();
checkIfQuantifierApplied();
Preconditions.checkArgument(times > 0, "You should give a positive number greater than 0.");
@@ -446,7 +525,7 @@ public class Pattern<T, F extends T> {
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
*/
public Pattern<T, F> times(int from, int to) {
- return times(from, to, null);
+ return times(from, to, (Duration) null);
}
/**
@@ -458,8 +537,24 @@ public class Pattern<T, F extends T> {
* @param windowTime time of the matching window between times
* @return The same pattern with the number of times range applied
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ * @deprecated Use {@link #times(int, int, Duration)}
*/
+ @Deprecated
public Pattern<T, F> times(int from, int to, @Nullable Time windowTime) {
+ return times(from, to, Time.toDuration(windowTime));
+ }
+
+ /**
+ * Specifies that the pattern can occur between from and to times with time interval corresponds
+ * to the maximum time gap between previous and current event for each times.
+ *
+ * @param from number of times matching event must appear at least
+ * @param to number of times matching event must appear at most
+ * @param windowTime time of the matching window between times
+ * @return The same pattern with the number of times range applied
+ * @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ */
+ public Pattern<T, F> times(int from, int to, @Nullable Duration windowTime) {
checkIfNoNotPattern();
checkIfQuantifierApplied();
this.quantifier = Quantifier.times(quantifier.getConsumingStrategy());
@@ -480,7 +575,7 @@ public class Pattern<T, F extends T> {
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
*/
public Pattern<T, F> timesOrMore(int times) {
- return timesOrMore(times, null);
+ return timesOrMore(times, (Duration) null);
}
/**
@@ -494,8 +589,26 @@ public class Pattern<T, F extends T> {
* @return The same pattern with a {@link Quantifier#looping(ConsumingStrategy)} quantifier
* applied.
* @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ * @deprecated Use {@link #timesOrMore(int, Duration)}
*/
+ @Deprecated
public Pattern<T, F> timesOrMore(int times, @Nullable Time windowTime) {
+ return timesOrMore(times, Time.toDuration(windowTime));
+ }
+
+ /**
+ * Specifies that this pattern can occur the specified times at least with interval corresponds
+ * to the maximum time gap between previous and current event for each times. This means at
+ * least the specified times and at most infinite number of events can be matched to this
+ * pattern.
+ *
+ * @param times number of times at least matching event must appear
+ * @param windowTime time of the matching window between times
+ * @return The same pattern with a {@link Quantifier#looping(ConsumingStrategy)} quantifier
+ * applied.
+ * @throws MalformedPatternException if the quantifier is not applicable to this pattern.
+ */
+ public Pattern<T, F> timesOrMore(int times, @Nullable Duration windowTime) {
checkIfNoNotPattern();
checkIfQuantifierApplied();
this.quantifier = Quantifier.looping(quantifier.getConsumingStrategy());
diff --git a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Quantifier.java b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Quantifier.java
index d929368936a..2e5efd48dd5 100644
--- a/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Quantifier.java
+++ b/flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Quantifier.java
@@ -23,8 +23,10 @@ import org.apache.flink.util.Preconditions;
import javax.annotation.Nullable;
+import java.time.Duration;
import java.util.EnumSet;
import java.util.Objects;
+import java.util.Optional;
/**
* A quantifier describing the Pattern. There are three main groups of {@link Quantifier}.
@@ -190,9 +192,9 @@ public class Quantifier {
public static class Times {
private final int from;
private final int to;
- private final @Nullable Time windowTime;
+ private final @Nullable Duration windowTime;
- private Times(int from, int to, @Nullable Time windowTime) {
+ private Times(int from, int to, @Nullable Duration windowTime) {
Preconditions.checkArgument(
from > 0, "The from should be a positive number greater than 0.");
Preconditions.checkArgument(
@@ -211,15 +213,33 @@ public class Quantifier {
return to;
}
+ /** @deprecated Use {@link #getWindowSize()}. */
+ @Deprecated
public Time getWindowTime() {
- return windowTime;
+ return getWindowSize().map(Time::of).orElse(null);
}
+ public Optional<Duration> getWindowSize() {
+ return Optional.ofNullable(windowTime);
+ }
+
+ /** @deprecated Use {@link #of(int, int, Duration)} */
+ @Deprecated
public static Times of(int from, int to, @Nullable Time windowTime) {
+ return of(from, to, Time.toDuration(windowTime));
+ }
+
+ public static Times of(int from, int to, @Nullable Duration windowTime) {
return new Times(from, to, windowTime);
}
+ /** @deprecated Use {@link #of(int, Duration)} */
+ @Deprecated
public static Times of(int times, @Nullable Time windowTime) {
+ return of(times, Time.toDuration(windowTime));
+ }
+
+ public static Times of(int times, @Nullable Duration windowTime) {
return new Times(times, times, windowTime);
}
@@ -237,8 +257,7 @@ public class Quantifier {
&& ((windowTime == null && times.windowTime == null)
|| (windowTime != null
&& times.windowTime != null
- && windowTime.toMilliseconds()
- == times.windowTime.toMilliseconds()));
+ && windowTime.toMillis() == times.windowTime.toMillis()));
}
@Override
diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/RestartBackoffTimeStrategyFactoryLoader.java b/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/RestartBackoffTimeStrategyFactoryLoader.java
index 0d63962e6a9..6d38e472919 100644
--- a/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/RestartBackoffTimeStrategyFactoryLoader.java
+++ b/flink-runtime/src/main/java/org/apache/flink/runtime/executiongraph/failover/RestartBackoffTimeStrategyFactoryLoader.java
@@ -91,7 +91,7 @@ public final class RestartBackoffTimeStrategyFactoryLoader {
new FixedDelayRestartBackoffTimeStrategy
.FixedDelayRestartBackoffTimeStrategyFactory(
fixedDelayConfig.getRestartAttempts(),
- fixedDelayConfig.getDelayBetweenAttemptsInterval().toMilliseconds()));
+ fixedDelayConfig.getDurationBetweenAttempts().toMillis()));
} else if (restartStrategyConfiguration
instanceof FailureRateRestartStrategyConfiguration) {
final FailureRateRestartStrategyConfiguration failureRateConfig =
@@ -101,8 +101,8 @@ public final class RestartBackoffTimeStrategyFactoryLoader {
new FailureRateRestartBackoffTimeStrategy
.FailureRateRestartBackoffTimeStrategyFactory(
failureRateConfig.getMaxFailureRate(),
- failureRateConfig.getFailureInterval().toMilliseconds(),
- failureRateConfig.getDelayBetweenAttemptsInterval().toMilliseconds()));
+ failureRateConfig.getFailureIntervalDuration().toMillis(),
+ failureRateConfig.getDurationBetweenAttempts().toMillis()));
} else if (restartStrategyConfiguration instanceof FallbackRestartStrategyConfiguration) {
return Optional.empty();
} else if (restartStrategyConfiguration
@@ -112,10 +112,10 @@ public final class RestartBackoffTimeStrategyFactoryLoader {
return Optional.of(
new ExponentialDelayRestartBackoffTimeStrategy
.ExponentialDelayRestartBackoffTimeStrategyFactory(
- exponentialDelayConfig.getInitialBackoff().toMilliseconds(),
- exponentialDelayConfig.getMaxBackoff().toMilliseconds(),
+ exponentialDelayConfig.getInitialBackoffDuration().toMillis(),
+ exponentialDelayConfig.getMaxBackoffDuration().toMillis(),
exponentialDelayConfig.getBackoffMultiplier(),
- exponentialDelayConfig.getResetBackoffThreshold().toMilliseconds(),
+ exponentialDelayConfig.getResetBackoffDurationThreshold().toMillis(),
exponentialDelayConfig.getJitterFactor(),
RestartStrategyOptions.RESTART_STRATEGY_EXPONENTIAL_DELAY_ATTEMPTS
.defaultValue()));
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/AllWindowedStream.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/AllWindowedStream.java
index 639d2af5f64..ce475847c0d 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/AllWindowedStream.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/AllWindowedStream.java
@@ -62,6 +62,8 @@ import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
import org.apache.flink.util.OutputTag;
import org.apache.flink.util.Preconditions;
+import java.time.Duration;
+
import static org.apache.flink.util.Preconditions.checkArgument;
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -132,10 +134,25 @@ public class AllWindowedStream<T, W extends Window> {
* is {@code 0L}.
*
* <p>Setting an allowed lateness is only valid for event-time windows.
+ *
+ * @deprecated Use {@link #allowedLateness(Duration)}, instead.
*/
+ @Deprecated
@PublicEvolving
public AllWindowedStream<T, W> allowedLateness(Time lateness) {
- final long millis = lateness.toMilliseconds();
+ return allowedLateness(lateness.toDuration());
+ }
+
+ /**
+ * Sets the time by which elements are allowed to be late. Elements that arrive behind the
+ * watermark by more than the specified time will be dropped. By default, the allowed lateness
+ * is {@code 0L}.
+ *
+ * <p>Setting an allowed lateness is only valid for event-time windows.
+ */
+ @PublicEvolving
+ public AllWindowedStream<T, W> allowedLateness(Duration lateness) {
+ final long millis = lateness.toMillis();
checkArgument(millis >= 0, "The allowed lateness cannot be negative.");
this.allowedLateness = millis;
@@ -145,7 +162,7 @@ public class AllWindowedStream<T, W extends Window> {
/**
* Send late arriving data to the side output identified by the given {@link OutputTag}. Data is
* considered late after the watermark has passed the end of the window plus the allowed
- * lateness set using {@link #allowedLateness(Time)}.
+ * lateness set using {@link #allowedLateness(Duration)}.
*
* <p>You can get the stream of late data using {@link
* SingleOutputStreamOperator#getSideOutput(OutputTag)} on the {@link
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/CoGroupedStreams.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/CoGroupedStreams.java
index ce328dc26d7..b9a253d4e25 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/CoGroupedStreams.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/CoGroupedStreams.java
@@ -42,10 +42,14 @@ import org.apache.flink.streaming.api.windowing.windows.Window;
import org.apache.flink.util.Collector;
import org.apache.flink.util.Preconditions;
+import javax.annotation.Nullable;
+
import java.io.IOException;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import static java.util.Objects.requireNonNull;
@@ -68,7 +72,7 @@ import static java.util.Objects.requireNonNull;
* DataStream<T> result = one.coGroup(two)
* .where(new MyFirstKeySelector())
* .equalTo(new MyFirstKeySelector())
- * .window(TumblingEventTimeWindows.of(Time.of(5, TimeUnit.SECONDS)))
+ * .window(TumblingEventTimeWindows.of(Duration.ofSeconds(5)))
* .apply(new MyCoGroupFunction());
* }</pre>
*/
@@ -201,7 +205,7 @@ public class CoGroupedStreams<T1, T2> {
assigner,
null,
null,
- null);
+ (Duration) null);
}
}
}
@@ -233,10 +237,15 @@ public class CoGroupedStreams<T1, T2> {
private final Evictor<? super TaggedUnion<T1, T2>, ? super W> evictor;
- private final Time allowedLateness;
+ @Nullable private final Duration allowedLateness;
private WindowedStream<TaggedUnion<T1, T2>, KEY, W> windowedStream;
+ /**
+ * @deprecated Use {@link WithWindow#WithWindow(DataStream, DataStream, KeySelector,
+ * KeySelector, TypeInformation, WindowAssigner, Trigger, Evictor, Duration)}
+ */
+ @Deprecated
protected WithWindow(
DataStream<T1> input1,
DataStream<T2> input2,
@@ -246,7 +255,29 @@ public class CoGroupedStreams<T1, T2> {
WindowAssigner<? super TaggedUnion<T1, T2>, W> windowAssigner,
Trigger<? super TaggedUnion<T1, T2>, ? super W> trigger,
Evictor<? super TaggedUnion<T1, T2>, ? super W> evictor,
- Time allowedLateness) {
+ @Nullable Time allowedLateness) {
+ this(
+ input1,
+ input2,
+ keySelector1,
+ keySelector2,
+ keyType,
+ windowAssigner,
+ trigger,
+ evictor,
+ Time.toDuration(allowedLateness));
+ }
+
+ protected WithWindow(
+ DataStream<T1> input1,
+ DataStream<T2> input2,
+ KeySelector<T1, KEY> keySelector1,
+ KeySelector<T2, KEY> keySelector2,
+ TypeInformation<KEY> keyType,
+ WindowAssigner<? super TaggedUnion<T1, T2>, W> windowAssigner,
+ Trigger<? super TaggedUnion<T1, T2>, ? super W> trigger,
+ Evictor<? super TaggedUnion<T1, T2>, ? super W> evictor,
+ @Nullable Duration allowedLateness) {
this.input1 = input1;
this.input2 = input2;
@@ -303,9 +334,21 @@ public class CoGroupedStreams<T1, T2> {
* Sets the time by which elements are allowed to be late.
*
* @see WindowedStream#allowedLateness(Time)
+ * @deprecated Use {@link #allowedLateness(Duration)}
*/
+ @Deprecated
@PublicEvolving
- public WithWindow<T1, T2, KEY, W> allowedLateness(Time newLateness) {
+ public WithWindow<T1, T2, KEY, W> allowedLateness(@Nullable Time newLateness) {
+ return allowedLateness(Time.toDuration(newLateness));
+ }
+
+ /**
+ * Sets the time by which elements are allowed to be late.
+ *
+ * @see WindowedStream#allowedLateness(Duration)
+ */
+ @PublicEvolving
+ public WithWindow<T1, T2, KEY, W> allowedLateness(@Nullable Duration newLateness) {
return new WithWindow<>(
input1,
input2,
@@ -421,9 +464,17 @@ public class CoGroupedStreams<T1, T2> {
return (SingleOutputStreamOperator<T>) apply(function, resultType);
}
+ /** @deprecated Use {@link #getAllowedLatenessDuration()} */
+ @Deprecated
@VisibleForTesting
+ @Nullable
Time getAllowedLateness() {
- return allowedLateness;
+ return getAllowedLatenessDuration().map(Time::of).orElse(null);
+ }
+
+ @VisibleForTesting
+ Optional<Duration> getAllowedLatenessDuration() {
+ return Optional.ofNullable(allowedLateness);
}
@VisibleForTesting
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/JoinedStreams.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/JoinedStreams.java
index 83c7ac82c87..9e64d93596a 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/JoinedStreams.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/JoinedStreams.java
@@ -35,6 +35,11 @@ import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.windows.Window;
import org.apache.flink.util.Collector;
+import javax.annotation.Nullable;
+
+import java.time.Duration;
+import java.util.Optional;
+
import static java.util.Objects.requireNonNull;
/**
@@ -56,7 +61,7 @@ import static java.util.Objects.requireNonNull;
* DataStream<T> result = one.join(two)
* .where(new MyFirstKeySelector())
* .equalTo(new MyFirstKeySelector())
- * .window(TumblingEventTimeWindows.of(Time.of(5, TimeUnit.SECONDS)))
+ * .window(TumblingEventTimeWindows.of(Duration.ofSeconds(5)))
* .apply(new MyJoinFunction());
* }</pre>
*/
@@ -187,7 +192,7 @@ public class JoinedStreams<T1, T2> {
assigner,
null,
null,
- null);
+ (Duration) null);
}
}
}
@@ -219,10 +224,38 @@ public class JoinedStreams<T1, T2> {
private final Evictor<? super TaggedUnion<T1, T2>, ? super W> evictor;
- private final Time allowedLateness;
+ @Nullable private final Duration allowedLateness;
private CoGroupedStreams.WithWindow<T1, T2, KEY, W> coGroupedWindowedStream;
+ /**
+ * @deprecated Use {@link WithWindow#WithWindow(DataStream, DataStream, KeySelector,
+ * KeySelector, TypeInformation, WindowAssigner, Trigger, Evictor, Duration)}.
+ */
+ @Deprecated
+ @PublicEvolving
+ protected WithWindow(
+ DataStream<T1> input1,
+ DataStream<T2> input2,
+ KeySelector<T1, KEY> keySelector1,
+ KeySelector<T2, KEY> keySelector2,
+ TypeInformation<KEY> keyType,
+ WindowAssigner<? super TaggedUnion<T1, T2>, W> windowAssigner,
+ Trigger<? super TaggedUnion<T1, T2>, ? super W> trigger,
+ Evictor<? super TaggedUnion<T1, T2>, ? super W> evictor,
+ @Nullable Time allowedLateness) {
+ this(
+ input1,
+ input2,
+ keySelector1,
+ keySelector2,
+ keyType,
+ windowAssigner,
+ trigger,
+ evictor,
+ Time.toDuration(allowedLateness));
+ }
+
@PublicEvolving
protected WithWindow(
DataStream<T1> input1,
@@ -233,7 +266,7 @@ public class JoinedStreams<T1, T2> {
WindowAssigner<? super TaggedUnion<T1, T2>, W> windowAssigner,
Trigger<? super TaggedUnion<T1, T2>, ? super W> trigger,
Evictor<? super TaggedUnion<T1, T2>, ? super W> evictor,
- Time allowedLateness) {
+ @Nullable Duration allowedLateness) {
this.input1 = requireNonNull(input1);
this.input2 = requireNonNull(input2);
@@ -291,10 +324,22 @@ public class JoinedStreams<T1, T2> {
/**
* Sets the time by which elements are allowed to be late.
*
- * @see WindowedStream#allowedLateness(Time)
+ * @see WindowedStream#allowedLateness(Duration)
+ * @deprecated Use {@link #allowedLateness(Duration)}.
+ */
+ @Deprecated
+ @PublicEvolving
+ public WithWindow<T1, T2, KEY, W> allowedLateness(@Nullable Time newLateness) {
+ return allowedLateness(Time.toDuration(newLateness));
+ }
+
+ /**
+ * Sets the time by which elements are allowed to be late.
+ *
+ * @see WindowedStream#allowedLateness(Duration)
*/
@PublicEvolving
- public WithWindow<T1, T2, KEY, W> allowedLateness(Time newLateness) {
+ public WithWindow<T1, T2, KEY, W> allowedLateness(@Nullable Duration newLateness) {
return new WithWindow<>(
input1,
input2,
@@ -481,9 +526,16 @@ public class JoinedStreams<T1, T2> {
return (SingleOutputStreamOperator<T>) apply(function, resultType);
}
+ /** @deprecated Use {@link #getAllowedLatenessDuration()}} */
@VisibleForTesting
+ @Nullable
Time getAllowedLateness() {
- return allowedLateness;
+ return getAllowedLatenessDuration().map(Time::of).orElse(null);
+ }
+
+ @VisibleForTesting
+ Optional<Duration> getAllowedLatenessDuration() {
+ return Optional.ofNullable(allowedLateness);
}
@VisibleForTesting
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/KeyedStream.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/KeyedStream.java
index 6b3f2d1139c..c55c63a93a1 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/KeyedStream.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/KeyedStream.java
@@ -73,6 +73,7 @@ import org.apache.flink.util.Preconditions;
import org.apache.commons.lang3.StringUtils;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
@@ -429,7 +430,7 @@ public class KeyedStream<T, KEY> extends DataStream<T> {
/**
* Join elements of this {@link KeyedStream} with elements of another {@link KeyedStream} over a
- * time interval that can be specified with {@link IntervalJoin#between(Time, Time)}.
+ * time interval that can be specified with {@link IntervalJoin#between(Duration, Duration)}.
*
* @param otherStream The other keyed stream to join this keyed stream with
* @param <T1> Type parameter of elements in the other stream
@@ -497,9 +498,30 @@ public class KeyedStream<T, KEY> extends DataStream<T> {
*
* @param lowerBound The lower bound. Needs to be smaller than or equal to the upperBound
* @param upperBound The upper bound. Needs to be bigger than or equal to the lowerBound
+ * @deprecated Use {@link #between(Duration, Duration)}
*/
+ @Deprecated
@PublicEvolving
public IntervalJoined<T1, T2, KEY> between(Time lowerBound, Time upperBound) {
+ return between(lowerBound.toDuration(), upperBound.toDuration());
+ }
+
+ /**
+ * Specifies the time boundaries over which the join operation works, so that
+ *
+ * <pre>
+ * leftElement.timestamp + lowerBound <= rightElement.timestamp <= leftElement.timestamp + upperBound
+ * </pre>
+ *
+ * <p>By default both the lower and the upper bound are inclusive. This can be configured
+ * with {@link IntervalJoined#lowerBoundExclusive()} and {@link
+ * IntervalJoined#upperBoundExclusive()}
+ *
+ * @param lowerBound The lower bound. Needs to be smaller than or equal to the upperBound
+ * @param upperBound The upper bound. Needs to be bigger than or equal to the lowerBound
+ */
+ @PublicEvolving
+ public IntervalJoined<T1, T2, KEY> between(Duration lowerBound, Duration upperBound) {
if (timeBehaviour != TimeBehaviour.EventTime) {
throw new UnsupportedTimeCharacteristicException(
"Time-bounded stream joins are only supported in event time");
@@ -509,12 +531,7 @@ public class KeyedStream<T, KEY> extends DataStream<T> {
checkNotNull(upperBound, "An upper bound needs to be provided for a time-bounded join");
return new IntervalJoined<>(
- streamOne,
- streamTwo,
- lowerBound.toMilliseconds(),
- upperBound.toMilliseconds(),
- true,
- true);
+ streamOne, streamTwo, lowerBound.toMillis(), upperBound.toMillis(), true, true);
}
}
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/WindowedStream.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/WindowedStream.java
index 7e0b9aa48f1..47b22a6057a 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/WindowedStream.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/datastream/WindowedStream.java
@@ -43,6 +43,8 @@ import org.apache.flink.streaming.api.windowing.windows.Window;
import org.apache.flink.streaming.runtime.operators.windowing.WindowOperatorBuilder;
import org.apache.flink.util.OutputTag;
+import java.time.Duration;
+
import static org.apache.flink.util.Preconditions.checkNotNull;
/**
@@ -103,9 +105,24 @@ public class WindowedStream<T, K, W extends Window> {
* is {@code 0L}.
*
* <p>Setting an allowed lateness is only valid for event-time windows.
+ *
+ * @deprecated Use {@link #allowedLateness(Duration)}
*/
+ @Deprecated
@PublicEvolving
public WindowedStream<T, K, W> allowedLateness(Time lateness) {
+ return allowedLateness(lateness.toDuration());
+ }
+
+ /**
+ * Sets the time by which elements are allowed to be late. Elements that arrive behind the
+ * watermark by more than the specified time will be dropped. By default, the allowed lateness
+ * is {@code 0L}.
+ *
+ * <p>Setting an allowed lateness is only valid for event-time windows.
+ */
+ @PublicEvolving
+ public WindowedStream<T, K, W> allowedLateness(Duration lateness) {
builder.allowedLateness(lateness);
return this;
}
@@ -113,7 +130,7 @@ public class WindowedStream<T, K, W extends Window> {
/**
* Send late arriving data to the side output identified by the given {@link OutputTag}. Data is
* considered late after the watermark has passed the end of the window plus the allowed
- * lateness set using {@link #allowedLateness(Time)}.
+ * lateness set using {@link #allowedLateness(Duration)}.
*
* <p>You can get the stream of late data using {@link
* SingleOutputStreamOperator#getSideOutput(OutputTag)} on the {@link
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
index dff237cce20..2f92ab013d0 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/environment/StreamExecutionEnvironment.java
@@ -35,7 +35,6 @@ import org.apache.flink.api.common.operators.ResourceSpec;
import org.apache.flink.api.common.operators.SlotSharingGroup;
import org.apache.flink.api.common.operators.util.SlotSharingGroupUtils;
import org.apache.flink.api.common.restartstrategy.RestartStrategies;
-import org.apache.flink.api.common.time.Time;
import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
import org.apache.flink.api.common.typeinfo.TypeInformation;
import org.apache.flink.api.connector.source.Boundedness;
@@ -106,6 +105,7 @@ import org.apache.flink.streaming.api.graph.StreamGraphGenerator;
import org.apache.flink.streaming.api.operators.StreamSource;
import org.apache.flink.streaming.api.operators.collect.CollectResultIterator;
import org.apache.flink.streaming.api.transformations.CacheTransformation;
+import org.apache.flink.streaming.api.windowing.assigners.WindowAssigner;
import org.apache.flink.util.AbstractID;
import org.apache.flink.util.DynamicCodeLoadingException;
import org.apache.flink.util.ExceptionUtils;
@@ -124,6 +124,7 @@ import javax.annotation.Nullable;
import java.io.IOException;
import java.io.Serializable;
import java.net.URI;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -859,7 +860,8 @@ public class StreamExecutionEnvironment implements AutoCloseable {
* @param numberOfExecutionRetries The number of times the system will try to re-execute failed
* tasks.
* @deprecated This method will be replaced by {@link #setRestartStrategy}. The {@link
- * RestartStrategies#fixedDelayRestart(int, Time)} contains the number of execution retries.
+ * RestartStrategies#fixedDelayRestart(int, Duration)} contains the number of execution
+ * retries.
*/
@Deprecated
@PublicEvolving
@@ -979,10 +981,11 @@ public class StreamExecutionEnvironment implements AutoCloseable {
* event-time mode. If you need to disable watermarks, please use {@link
* ExecutionConfig#setAutoWatermarkInterval(long)}. If you are using {@link
* TimeCharacteristic#IngestionTime}, please manually set an appropriate {@link
- * WatermarkStrategy}. If you are using generic "time window" operations (for example {@link
- * org.apache.flink.streaming.api.datastream.KeyedStream#timeWindow(org.apache.flink.streaming.api.windowing.time.Time)}
- * that change behaviour based on the time characteristic, please use equivalent operations
- * that explicitly specify processing time or event time.
+ * WatermarkStrategy}. If you are using generic "time window" operations (for example
+ * through {@link
+ * org.apache.flink.streaming.api.datastream.KeyedStream#window(WindowAssigner)} that change
+ * behaviour based on the time characteristic, please use equivalent operations that
+ * explicitly specify processing time or event time.
*/
@PublicEvolving
@Deprecated
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/timestamps/BoundedOutOfOrdernessTimestampExtractor.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/timestamps/BoundedOutOfOrdernessTimestampExtractor.java
index bb78958761b..0ee8121f1c8 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/timestamps/BoundedOutOfOrdernessTimestampExtractor.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/timestamps/BoundedOutOfOrdernessTimestampExtractor.java
@@ -22,6 +22,8 @@ import org.apache.flink.streaming.api.functions.AssignerWithPeriodicWatermarks;
import org.apache.flink.streaming.api.watermark.Watermark;
import org.apache.flink.streaming.api.windowing.time.Time;
+import java.time.Duration;
+
/**
* This is a {@link AssignerWithPeriodicWatermarks} used to emit Watermarks that lag behind the
* element with the maximum timestamp (in event time) seen so far by a fixed amount of time, <code>
@@ -47,15 +49,24 @@ public abstract class BoundedOutOfOrdernessTimestampExtractor<T>
*/
private final long maxOutOfOrderness;
+ /**
+ * @deprecated Use {@link
+ * BoundedOutOfOrdernessTimestampExtractor#BoundedOutOfOrdernessTimestampExtractor(Duration)}
+ */
+ @Deprecated
public BoundedOutOfOrdernessTimestampExtractor(Time maxOutOfOrderness) {
- if (maxOutOfOrderness.toMilliseconds() < 0) {
- throw new RuntimeException(
- "Tried to set the maximum allowed "
- + "lateness to "
- + maxOutOfOrderness
- + ". This parameter cannot be negative.");
+ this(maxOutOfOrderness.toDuration());
+ }
+
+ public BoundedOutOfOrdernessTimestampExtractor(Duration maxOutOfOrderness) {
+ if (maxOutOfOrderness.isNegative()) {
+ throw new IllegalArgumentException(
+ String.format(
+ "Tried to set the maximum allowed lateness to %s. This parameter cannot be negative.",
+ maxOutOfOrderness));
}
- this.maxOutOfOrderness = maxOutOfOrderness.toMilliseconds();
+
+ this.maxOutOfOrderness = maxOutOfOrderness.toMillis();
this.currentMaxTimestamp = Long.MIN_VALUE + this.maxOutOfOrderness;
}
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/EventTimeSessionWindows.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/EventTimeSessionWindows.java
index ee3a0e0c263..4428b622dee 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/EventTimeSessionWindows.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/EventTimeSessionWindows.java
@@ -27,6 +27,7 @@ import org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
@@ -40,9 +41,10 @@ import java.util.Collections;
* DataStream<Tuple2<String, Integer>> in = ...;
* KeyedStream<String, Tuple2<String, Integer>> keyed = in.keyBy(...);
* WindowedStream<Tuple2<String, Integer>, String, TimeWindows> windowed =
- * keyed.window(EventTimeSessionWindows.withGap(Time.minutes(1)));
+ * keyed.window(EventTimeSessionWindows.withGap(Duration.ofMinutes(1)));
* }</pre>
*/
+@PublicEvolving
public class EventTimeSessionWindows extends MergingWindowAssigner<Object, TimeWindow> {
private static final long serialVersionUID = 1L;
@@ -85,9 +87,22 @@ public class EventTimeSessionWindows extends MergingWindowAssigner<Object, TimeW
*
* @param size The session timeout, i.e. the time gap between sessions
* @return The policy.
+ * @deprecated Use {@link #withGap(Duration)}
*/
+ @Deprecated
public static EventTimeSessionWindows withGap(Time size) {
- return new EventTimeSessionWindows(size.toMilliseconds());
+ return withGap(size.toDuration());
+ }
+
+ /**
+ * Creates a new {@code SessionWindows} {@link WindowAssigner} that assigns elements to sessions
+ * based on the element timestamp.
+ *
+ * @param size The session timeout, i.e. the time gap between sessions
+ * @return The policy.
+ */
+ public static EventTimeSessionWindows withGap(Duration size) {
+ return new EventTimeSessionWindows(size.toMillis());
}
/**
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/MergingWindowAssigner.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/MergingWindowAssigner.java
index 9080d1dfddd..3ee5db91e43 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/MergingWindowAssigner.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/MergingWindowAssigner.java
@@ -45,6 +45,7 @@ public abstract class MergingWindowAssigner<T, W extends Window> extends WindowA
* Callback to be used in {@link #mergeWindows(Collection, MergeCallback)} for specifying which
* windows should be merged.
*/
+ @PublicEvolving
public interface MergeCallback<W> {
/**
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/ProcessingTimeSessionWindows.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/ProcessingTimeSessionWindows.java
index c82309e7259..a65be4017e2 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/ProcessingTimeSessionWindows.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/ProcessingTimeSessionWindows.java
@@ -27,6 +27,7 @@ import org.apache.flink.streaming.api.windowing.triggers.ProcessingTimeTrigger;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
@@ -40,9 +41,10 @@ import java.util.Collections;
* DataStream<Tuple2<String, Integer>> in = ...;
* KeyedStream<String, Tuple2<String, Integer>> keyed = in.keyBy(...);
* WindowedStream<Tuple2<String, Integer>, String, TimeWindows> windowed =
- * keyed.window(ProcessingTimeSessionWindows.withGap(Time.minutes(1)));
+ * keyed.window(ProcessingTimeSessionWindows.withGap(Duration.ofMinutes(1)));
* }</pre>
*/
+@PublicEvolving
public class ProcessingTimeSessionWindows extends MergingWindowAssigner<Object, TimeWindow> {
private static final long serialVersionUID = 1L;
@@ -87,9 +89,22 @@ public class ProcessingTimeSessionWindows extends MergingWindowAssigner<Object,
*
* @param size The session timeout, i.e. the time gap between sessions
* @return The policy.
+ * @deprecated Use {@link #withGap(Duration)}
*/
+ @Deprecated
public static ProcessingTimeSessionWindows withGap(Time size) {
- return new ProcessingTimeSessionWindows(size.toMilliseconds());
+ return withGap(size.toDuration());
+ }
+
+ /**
+ * Creates a new {@code SessionWindows} {@link WindowAssigner} that assigns elements to sessions
+ * based on the element timestamp.
+ *
+ * @param size The session timeout, i.e. the time gap between sessions
+ * @return The policy.
+ */
+ public static ProcessingTimeSessionWindows withGap(Duration size) {
+ return new ProcessingTimeSessionWindows(size.toMillis());
}
/**
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingEventTimeWindows.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingEventTimeWindows.java
index 3711d67b0d2..4b9160aad2a 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingEventTimeWindows.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingEventTimeWindows.java
@@ -27,6 +27,7 @@ import org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -41,7 +42,7 @@ import java.util.List;
* DataStream<Tuple2<String, Integer>> in = ...;
* KeyedStream<Tuple2<String, Integer>, String> keyed = in.keyBy(...);
* WindowedStream<Tuple2<String, Integer>, String, TimeWindow> windowed =
- * keyed.window(SlidingEventTimeWindows.of(Time.minutes(1), Time.seconds(10)));
+ * keyed.window(SlidingEventTimeWindows.of(Duration.ofMinutes(1), Duration.ofSeconds(10)));
* }</pre>
*/
@PublicEvolving
@@ -115,9 +116,23 @@ public class SlidingEventTimeWindows extends WindowAssigner<Object, TimeWindow>
* @param size The size of the generated windows.
* @param slide The slide interval of the generated windows.
* @return The time policy.
+ * @deprecated Use {@link #of(Duration, Duration)}
*/
+ @Deprecated
public static SlidingEventTimeWindows of(Time size, Time slide) {
- return new SlidingEventTimeWindows(size.toMilliseconds(), slide.toMilliseconds(), 0);
+ return of(size.toDuration(), slide.toDuration());
+ }
+
+ /**
+ * Creates a new {@code SlidingEventTimeWindows} {@link WindowAssigner} that assigns elements to
+ * sliding time windows based on the element timestamp.
+ *
+ * @param size The size of the generated windows.
+ * @param slide The slide interval of the generated windows.
+ * @return The time policy.
+ */
+ public static SlidingEventTimeWindows of(Duration size, Duration slide) {
+ return new SlidingEventTimeWindows(size.toMillis(), slide.toMillis(), 0);
}
/**
@@ -138,10 +153,34 @@ public class SlidingEventTimeWindows extends WindowAssigner<Object, TimeWindow>
* @param slide The slide interval of the generated windows.
* @param offset The offset which window start would be shifted by.
* @return The time policy.
+ * @deprecated Use {@link #of(Duration, Duration, Duration)}
*/
+ @Deprecated
public static SlidingEventTimeWindows of(Time size, Time slide, Time offset) {
- return new SlidingEventTimeWindows(
- size.toMilliseconds(), slide.toMilliseconds(), offset.toMilliseconds());
+ return of(size.toDuration(), slide.toDuration(), offset.toDuration());
+ }
+
+ /**
+ * Creates a new {@code SlidingEventTimeWindows} {@link WindowAssigner} that assigns elements to
+ * time windows based on the element timestamp and offset.
+ *
+ * <p>For example, if you want window a stream by hour,but window begins at the 15th minutes of
+ * each hour, you can use {@code of(Duration.ofHours(1), Duration.ofMinutes(15))}, then you will
+ * get time windows start at 0:15:00,1:15:00,2:15:00,etc.
+ *
+ * <p>Rather than that,if you are living in somewhere which is not using UTC±00:00 time, such as
+ * China which is using UTC+08:00,and you want a time window with size of one day, and window
+ * begins at every 00:00:00 of local time,you may use {@code of(Duration.ofDays(1),
+ * Duration.ofHours(-8))}. The parameter of offset is {@code Duration.ofHours(-8))} since
+ * UTC+08:00 is 8 hours earlier than UTC time.
+ *
+ * @param size The size of the generated windows.
+ * @param slide The slide interval of the generated windows.
+ * @param offset The offset which window start would be shifted by.
+ * @return The time policy.
+ */
+ public static SlidingEventTimeWindows of(Duration size, Duration slide, Duration offset) {
+ return new SlidingEventTimeWindows(size.toMillis(), slide.toMillis(), offset.toMillis());
}
@Override
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingProcessingTimeWindows.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingProcessingTimeWindows.java
index 265a09286bf..be009727ca8 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingProcessingTimeWindows.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/SlidingProcessingTimeWindows.java
@@ -18,6 +18,7 @@
package org.apache.flink.streaming.api.windowing.assigners;
+import org.apache.flink.annotation.PublicEvolving;
import org.apache.flink.api.common.ExecutionConfig;
import org.apache.flink.api.common.typeutils.TypeSerializer;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
@@ -26,6 +27,7 @@ import org.apache.flink.streaming.api.windowing.triggers.ProcessingTimeTrigger;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import java.time.Duration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -43,6 +45,7 @@ import java.util.List;
* keyed.window(SlidingProcessingTimeWindows.of(Time.of(1, MINUTES), Time.of(10, SECONDS));
* }</pre>
*/
+@PublicEvolving
public class SlidingProcessingTimeWindows extends WindowAssigner<Object, TimeWindow> {
private static final long serialVersionUID = 1L;
@@ -107,9 +110,23 @@ public class SlidingProcessingTimeWindows extends WindowAssigner<Object, TimeWin
* @param size The size of the generated windows.
* @param slide The slide interval of the generated windows.
* @return The time policy.
+ * @deprecated {@link #of(Duration, Duration)}
*/
+ @Deprecated
public static SlidingProcessingTimeWindows of(Time size, Time slide) {
- return new SlidingProcessingTimeWindows(size.toMilliseconds(), slide.toMilliseconds(), 0);
+ return of(size.toDuration(), slide.toDuration());
+ }
+
+ /**
+ * Creates a new {@code SlidingProcessingTimeWindows} {@link WindowAssigner} that assigns
+ * elements to sliding time windows based on the element timestamp.
+ *
+ * @param size The size of the generated windows.
+ * @param slide The slide interval of the generated windows.
+ * @return The time policy.
+ */
+ public static SlidingProcessingTimeWindows of(Duration size, Duration slide) {
+ return new SlidingProcessingTimeWindows(size.toMillis(), slide.toMillis(), 0);
}
/**
@@ -130,10 +147,35 @@ public class SlidingProcessingTimeWindows extends WindowAssigner<Object, TimeWin
* @param slide The slide interval of the generated windows.
* @param offset The offset which window start would be shifted by.
* @return The time policy.
+ * @deprecated Use {@link #of(Duration, Duration, Duration)}
*/
+ @Deprecated
public static SlidingProcessingTimeWindows of(Time size, Time slide, Time offset) {
+ return of(size.toDuration(), slide.toDuration(), offset.toDuration());
+ }
+
+ /**
+ * Creates a new {@code SlidingProcessingTimeWindows} {@link WindowAssigner} that assigns
+ * elements to time windows based on the element timestamp and offset.
+ *
+ * <p>For example, if you want window a stream by hour,but window begins at the 15th minutes of
+ * each hour, you can use {@code of(Duration.ofHours(1), Duration.ofMinutes(15))}, then you will
+ * get time windows start at 0:15:00,1:15:00,2:15:00,etc.
+ *
+ * <p>Rather than that,if you are living in somewhere which is not using UTC±00:00 time, such as
+ * China which is using UTC+08:00,and you want a time window with size of one day, and window
+ * begins at every 00:00:00 of local time,you may use {@code of(Duration.ofDays(1),
+ * Duration.ofHours(-8))}. The parameter of offset is {@code Duration.ofHours(-8))} since
+ * UTC+08:00 is 8 hours earlier than UTC time.
+ *
+ * @param size The size of the generated windows.
+ * @param slide The slide interval of the generated windows.
+ * @param offset The offset which window start would be shifted by.
+ * @return The time policy.
+ */
+ public static SlidingProcessingTimeWindows of(Duration size, Duration slide, Duration offset) {
return new SlidingProcessingTimeWindows(
- size.toMilliseconds(), slide.toMilliseconds(), offset.toMilliseconds());
+ size.toMillis(), slide.toMillis(), offset.toMillis());
}
@Override
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingEventTimeWindows.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingEventTimeWindows.java
index 787514ca523..4fc414c66d0 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingEventTimeWindows.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingEventTimeWindows.java
@@ -27,6 +27,7 @@ import org.apache.flink.streaming.api.windowing.triggers.EventTimeTrigger;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
@@ -40,7 +41,7 @@ import java.util.Collections;
* DataStream<Tuple2<String, Integer>> in = ...;
* KeyedStream<Tuple2<String, Integer>, String> keyed = in.keyBy(...);
* WindowedStream<Tuple2<String, Integer>, String, TimeWindow> windowed =
- * keyed.window(TumblingEventTimeWindows.of(Time.minutes(1)));
+ * keyed.window(TumblingEventTimeWindows.of(Duration.ofMinutes(1)));
* }</pre>
*/
@PublicEvolving
@@ -109,9 +110,22 @@ public class TumblingEventTimeWindows extends WindowAssigner<Object, TimeWindow>
*
* @param size The size of the generated windows.
* @return The time policy.
+ * @deprecated Use {@link #of(Duration)}
*/
+ @Deprecated
public static TumblingEventTimeWindows of(Time size) {
- return new TumblingEventTimeWindows(size.toMilliseconds(), 0, WindowStagger.ALIGNED);
+ return of(size.toDuration());
+ }
+
+ /**
+ * Creates a new {@code TumblingEventTimeWindows} {@link WindowAssigner} that assigns elements
+ * to time windows based on the element timestamp.
+ *
+ * @param size The size of the generated windows.
+ * @return The time policy.
+ */
+ public static TumblingEventTimeWindows of(Duration size) {
+ return new TumblingEventTimeWindows(size.toMillis(), 0, WindowStagger.ALIGNED);
}
/**
@@ -130,10 +144,33 @@ public class TumblingEventTimeWindows extends WindowAssigner<Object, TimeWindow>
*
* @param size The size of the generated windows.
* @param offset The offset which window start would be shifted by.
+ * @deprecated Use {@link #of(Duration, Duration)}
*/
+ @Deprecated
public static TumblingEventTimeWindows of(Time size, Time offset) {
+ return of(size.toDuration(), offset.toDuration());
+ }
+
+ /**
+ * Creates a new {@code TumblingEventTimeWindows} {@link WindowAssigner} that assigns elements
+ * to time windows based on the element timestamp and offset.
+ *
+ * <p>For example, if you want window a stream by hour,but window begins at the 15th minutes of
+ * each hour, you can use {@code of(Duration.ofHours(1), Duration.ofMinutes(15))}, then you will
+ * get time windows start at 0:15:00,1:15:00,2:15:00,etc.
+ *
+ * <p>Rather than that,if you are living in somewhere which is not using UTC±00:00 time, such as
+ * China which is using UTC+08:00,and you want a time window with size of one day, and window
+ * begins at every 00:00:00 of local time,you may use {@code of(Duration.ofDays(1),
+ * Duration.ofHours(-8))}. The parameter of offset is {@code Duration.ofHours(-8))} since
+ * UTC+08:00 is 8 hours earlier than UTC time.
+ *
+ * @param size The size of the generated windows.
+ * @param offset The offset which window start would be shifted by.
+ */
+ public static TumblingEventTimeWindows of(Duration size, Duration offset) {
return new TumblingEventTimeWindows(
- size.toMilliseconds(), offset.toMilliseconds(), WindowStagger.ALIGNED);
+ size.toMillis(), offset.toMillis(), WindowStagger.ALIGNED);
}
/**
@@ -144,11 +181,27 @@ public class TumblingEventTimeWindows extends WindowAssigner<Object, TimeWindow>
* @param size The size of the generated windows.
* @param offset The globalOffset which window start would be shifted by.
* @param windowStagger The utility that produces staggering offset in runtime.
+ * @deprecated Use {@link #of(Duration, Duration, WindowStagger)}
*/
+ @Deprecated
@PublicEvolving
public static TumblingEventTimeWindows of(Time size, Time offset, WindowStagger windowStagger) {
- return new TumblingEventTimeWindows(
- size.toMilliseconds(), offset.toMilliseconds(), windowStagger);
+ return of(size.toDuration(), offset.toDuration(), windowStagger);
+ }
+
+ /**
+ * Creates a new {@code TumblingEventTimeWindows} {@link WindowAssigner} that assigns elements
+ * to time windows based on the element timestamp, offset and a staggering offset, depending on
+ * the staggering policy.
+ *
+ * @param size The size of the generated windows.
+ * @param offset The globalOffset which window start would be shifted by.
+ * @param windowStagger The utility that produces staggering offset in runtime.
+ */
+ @PublicEvolving
+ public static TumblingEventTimeWindows of(
+ Duration size, Duration offset, WindowStagger windowStagger) {
+ return new TumblingEventTimeWindows(size.toMillis(), offset.toMillis(), windowStagger);
}
@Override
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingProcessingTimeWindows.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingProcessingTimeWindows.java
index e22b63acf57..c93e281748d 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingProcessingTimeWindows.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/TumblingProcessingTimeWindows.java
@@ -27,6 +27,7 @@ import org.apache.flink.streaming.api.windowing.triggers.ProcessingTimeTrigger;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
+import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
@@ -40,9 +41,10 @@ import java.util.Collections;
* DataStream<Tuple2<String, Integer>> in = ...;
* KeyedStream<String, Tuple2<String, Integer>> keyed = in.keyBy(...);
* WindowedStream<Tuple2<String, Integer>, String, TimeWindows> windowed =
- * keyed.window(TumblingProcessingTimeWindows.of(Time.of(1, MINUTES), Time.of(10, SECONDS));
+ * keyed.window(TumblingProcessingTimeWindows.of(Duration.ofMinutes(1), Duration.ofSeconds(10));
* }</pre>
*/
+@PublicEvolving
public class TumblingProcessingTimeWindows extends WindowAssigner<Object, TimeWindow> {
private static final long serialVersionUID = 1L;
@@ -105,9 +107,22 @@ public class TumblingProcessingTimeWindows extends WindowAssigner<Object, TimeWi
*
* @param size The size of the generated windows.
* @return The time policy.
+ * @deprecated Use {@link #of(Duration)}
*/
+ @Deprecated
public static TumblingProcessingTimeWindows of(Time size) {
- return new TumblingProcessingTimeWindows(size.toMilliseconds(), 0, WindowStagger.ALIGNED);
+ return of(size.toDuration());
+ }
+
+ /**
+ * Creates a new {@code TumblingProcessingTimeWindows} {@link WindowAssigner} that assigns
+ * elements to time windows based on the element timestamp.
+ *
+ * @param size The size of the generated windows.
+ * @return The time policy.
+ */
+ public static TumblingProcessingTimeWindows of(Duration size) {
+ return new TumblingProcessingTimeWindows(size.toMillis(), 0, WindowStagger.ALIGNED);
}
/**
@@ -127,10 +142,34 @@ public class TumblingProcessingTimeWindows extends WindowAssigner<Object, TimeWi
* @param size The size of the generated windows.
* @param offset The offset which window start would be shifted by.
* @return The time policy.
+ * @deprecated Use {@link #of(Duration, Duration)}
*/
+ @Deprecated
public static TumblingProcessingTimeWindows of(Time size, Time offset) {
+ return of(size.toDuration(), offset.toDuration());
+ }
+
+ /**
+ * Creates a new {@code TumblingProcessingTimeWindows} {@link WindowAssigner} that assigns
+ * elements to time windows based on the element timestamp and offset.
+ *
+ * <p>For example, if you want window a stream by hour,but window begins at the 15th minutes of
+ * each hour, you can use {@code of(Duration.ofHours(1), Duration.ofMinutes(15))}, then you will
+ * get time windows start at 0:15:00,1:15:00,2:15:00,etc.
+ *
+ * <p>Rather than that, if you are living in somewhere which is not using UTC±00:00 time, such
+ * as China which is using UTC+08:00,and you want a time window with size of one day, and window
+ * begins at every 00:00:00 of local time, you may use {@code of(Duration.ofDays(1),
+ * Duration.ofHours(-8))}. The parameter of offset is {@code Duration.ofHours(-8))} since
+ * UTC+08:00 is 8 hours earlier than UTC time.
+ *
+ * @param size The size of the generated windows.
+ * @param offset The offset which window start would be shifted by.
+ * @return The time policy.
+ */
+ public static TumblingProcessingTimeWindows of(Duration size, Duration offset) {
return new TumblingProcessingTimeWindows(
- size.toMilliseconds(), offset.toMilliseconds(), WindowStagger.ALIGNED);
+ size.toMillis(), offset.toMillis(), WindowStagger.ALIGNED);
}
/**
@@ -142,12 +181,29 @@ public class TumblingProcessingTimeWindows extends WindowAssigner<Object, TimeWi
* @param offset The offset which window start would be shifted by.
* @param windowStagger The utility that produces staggering offset in runtime.
* @return The time policy.
+ * @deprecated Use {@link #of(Duration, Duration, WindowStagger)}
*/
+ @Deprecated
@PublicEvolving
public static TumblingProcessingTimeWindows of(
Time size, Time offset, WindowStagger windowStagger) {
- return new TumblingProcessingTimeWindows(
- size.toMilliseconds(), offset.toMilliseconds(), windowStagger);
+ return of(size.toDuration(), offset.toDuration(), windowStagger);
+ }
+
+ /**
+ * Creates a new {@code TumblingProcessingTimeWindows} {@link WindowAssigner} that assigns
+ * elements to time windows based on the element timestamp, offset and a staggering offset,
+ * depending on the staggering policy.
+ *
+ * @param size The size of the generated windows.
+ * @param offset The offset which window start would be shifted by.
+ * @param windowStagger The utility that produces staggering offset in runtime.
+ * @return The time policy.
+ */
+ @PublicEvolving
+ public static TumblingProcessingTimeWindows of(
+ Duration size, Duration offset, WindowStagger windowStagger) {
+ return new TumblingProcessingTimeWindows(size.toMillis(), offset.toMillis(), windowStagger);
}
@Override
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/WindowAssigner.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/WindowAssigner.java
index 0bc1b0a7d36..d0127c4350a 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/WindowAssigner.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/assigners/WindowAssigner.java
@@ -104,6 +104,7 @@ public abstract class WindowAssigner<T, W extends Window> implements Serializabl
* org.apache.flink.streaming.runtime.operators.windowing.WindowOperator}, which, in turn, gets
* it from the containing {@link org.apache.flink.streaming.runtime.tasks.StreamTask}.
*/
+ @PublicEvolving
public abstract static class WindowAssignerContext {
/** Returns the current processing time. */
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/evictors/TimeEvictor.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/evictors/TimeEvictor.java
index 449293ef9ca..5daa589ab01 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/evictors/TimeEvictor.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/evictors/TimeEvictor.java
@@ -24,6 +24,7 @@ import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.windows.Window;
import org.apache.flink.streaming.runtime.operators.windowing.TimestampedValue;
+import java.time.Duration;
import java.util.Iterator;
/**
@@ -124,9 +125,21 @@ public class TimeEvictor<W extends Window> implements Evictor<Object, W> {
* before the window function.
*
* @param windowSize The amount of time for which to keep elements.
+ * @deprecated Use {@link #of(Duration)}
*/
+ @Deprecated
public static <W extends Window> TimeEvictor<W> of(Time windowSize) {
- return new TimeEvictor<>(windowSize.toMilliseconds());
+ return of(windowSize.toDuration());
+ }
+
+ /**
+ * Creates a {@code TimeEvictor} that keeps the given number of elements. Eviction is done
+ * before the window function.
+ *
+ * @param windowSize The amount of time for which to keep elements.
+ */
+ public static <W extends Window> TimeEvictor<W> of(Duration windowSize) {
+ return new TimeEvictor<>(windowSize.toMillis());
}
/**
@@ -135,8 +148,21 @@ public class TimeEvictor<W extends Window> implements Evictor<Object, W> {
*
* @param windowSize The amount of time for which to keep elements.
* @param doEvictAfter Whether eviction is done after window function.
+ * @deprecated Use {@link #of(Duration, boolean)}
*/
+ @Deprecated
public static <W extends Window> TimeEvictor<W> of(Time windowSize, boolean doEvictAfter) {
- return new TimeEvictor<>(windowSize.toMilliseconds(), doEvictAfter);
+ return of(windowSize.toDuration(), doEvictAfter);
+ }
+
+ /**
+ * Creates a {@code TimeEvictor} that keeps the given number of elements. Eviction is done
+ * before/after the window function based on the value of doEvictAfter.
+ *
+ * @param windowSize The amount of time for which to keep elements.
+ * @param doEvictAfter Whether eviction is done after window function.
+ */
+ public static <W extends Window> TimeEvictor<W> of(Duration windowSize, boolean doEvictAfter) {
+ return new TimeEvictor<>(windowSize.toMillis(), doEvictAfter);
}
}
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/time/Time.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/time/Time.java
index b842a263dc3..2e8fa587030 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/time/Time.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/time/Time.java
@@ -20,6 +20,9 @@ package org.apache.flink.streaming.api.windowing.time;
import org.apache.flink.annotation.Public;
+import javax.annotation.Nullable;
+
+import java.time.Duration;
import java.util.concurrent.TimeUnit;
import static org.apache.flink.util.Preconditions.checkNotNull;
@@ -27,10 +30,23 @@ import static org.apache.flink.util.Preconditions.checkNotNull;
/**
* The definition of a time interval for windowing. The time characteristic referred to is the
* default time characteristic set on the execution environment.
+ *
+ * @deprecated Use {@link Duration}
*/
+@Deprecated
@Public
public final class Time {
+ @Nullable
+ public static Duration toDuration(@Nullable Time time) {
+ return time != null ? time.toDuration() : null;
+ }
+
+ @Nullable
+ public static Time of(@Nullable Duration duration) {
+ return duration != null ? Time.milliseconds(duration.toMillis()) : null;
+ }
+
/** The time unit for this policy's time interval. */
private final TimeUnit unit;
@@ -74,6 +90,10 @@ public final class Time {
return unit.toMillis(size);
}
+ public Duration toDuration() {
+ return Duration.ofMillis(this.toMilliseconds());
+ }
+
// ------------------------------------------------------------------------
// Factory
// ------------------------------------------------------------------------
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousEventTimeTrigger.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousEventTimeTrigger.java
index 8d0dcb87c89..19222b43b48 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousEventTimeTrigger.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousEventTimeTrigger.java
@@ -27,6 +27,8 @@ import org.apache.flink.api.common.typeutils.base.LongSerializer;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.windows.Window;
+import java.time.Duration;
+
/**
* A {@link Trigger} that continuously fires based on a given time interval. This fires based on
* {@link org.apache.flink.streaming.api.watermark.Watermark Watermarks}.
@@ -133,9 +135,21 @@ public class ContinuousEventTimeTrigger<W extends Window> extends Trigger<Object
*
* @param interval The time interval at which to fire.
* @param <W> The type of {@link Window Windows} on which this trigger can operate.
+ * @deprecated Use {@link #of(Duration)}
*/
+ @Deprecated
public static <W extends Window> ContinuousEventTimeTrigger<W> of(Time interval) {
- return new ContinuousEventTimeTrigger<>(interval.toMilliseconds());
+ return of(interval.toDuration());
+ }
+
+ /**
+ * Creates a trigger that continuously fires based on the given interval.
+ *
+ * @param interval The time interval at which to fire.
+ * @param <W> The type of {@link Window Windows} on which this trigger can operate.
+ */
+ public static <W extends Window> ContinuousEventTimeTrigger<W> of(Duration interval) {
+ return new ContinuousEventTimeTrigger<>(interval.toMillis());
}
private static class Min implements ReduceFunction<Long> {
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousProcessingTimeTrigger.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousProcessingTimeTrigger.java
index e3b1325f0f6..5dda7deca55 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousProcessingTimeTrigger.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/windowing/triggers/ContinuousProcessingTimeTrigger.java
@@ -27,6 +27,8 @@ import org.apache.flink.api.common.typeutils.base.LongSerializer;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.streaming.api.windowing.windows.Window;
+import java.time.Duration;
+
/**
* A {@link Trigger} that continuously fires based on a given time interval as measured by the clock
* of the machine on which the job is running.
@@ -122,9 +124,21 @@ public class ContinuousProcessingTimeTrigger<W extends Window> extends Trigger<O
*
* @param interval The time interval at which to fire.
* @param <W> The type of {@link Window Windows} on which this trigger can operate.
+ * @deprecated Use {@link #of(Duration)}
*/
+ @Deprecated
public static <W extends Window> ContinuousProcessingTimeTrigger<W> of(Time interval) {
- return new ContinuousProcessingTimeTrigger<>(interval.toMilliseconds());
+ return of(interval.toDuration());
+ }
+
+ /**
+ * Creates a trigger that continuously fires based on the given interval.
+ *
+ * @param interval The time interval at which to fire.
+ * @param <W> The type of {@link Window Windows} on which this trigger can operate.
+ */
+ public static <W extends Window> ContinuousProcessingTimeTrigger<W> of(Duration interval) {
+ return new ContinuousProcessingTimeTrigger<>(interval.toMillis());
}
private static class Min implements ReduceFunction<Long> {
diff --git a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorBuilder.java b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorBuilder.java
index f9db7a38f38..8e9564618d0 100644
--- a/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorBuilder.java
+++ b/flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/operators/windowing/WindowOperatorBuilder.java
@@ -57,6 +57,7 @@ import org.apache.flink.util.Preconditions;
import javax.annotation.Nullable;
import java.lang.reflect.Type;
+import java.time.Duration;
/**
* A builder for creating {@link WindowOperator WindowOperators}.
@@ -113,10 +114,16 @@ public class WindowOperatorBuilder<T, K, W extends Window> {
this.trigger = trigger;
}
+ /** @deprecated Use {@link #allowedLateness(Duration)}. */
+ @Deprecated
public void allowedLateness(Time lateness) {
+ allowedLateness(lateness.toDuration());
+ }
+
+ public void allowedLateness(Duration lateness) {
Preconditions.checkNotNull(lateness, "Allowed lateness cannot be null");
- final long millis = lateness.toMilliseconds();
+ final long millis = lateness.toMillis();
Preconditions.checkArgument(millis >= 0, "The allowed lateness cannot be negative.");
this.allowedLateness = millis;
|