forked from O2-Czech-Republic/proxima-platform
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zdenek Tison
committed
May 26, 2020
1 parent
59e5c33
commit adfb35b
Showing
14 changed files
with
487 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
core/src/main/java/cz/o2/proxima/time/AbstractWatermarkEstimator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2017-2020 O2 Czech Republic, a.s. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cz.o2.proxima.time; | ||
|
||
import com.google.common.base.Preconditions; | ||
import cz.o2.proxima.storage.StreamElement; | ||
|
||
import java.util.Optional; | ||
|
||
public abstract class AbstractWatermarkEstimator implements WatermarkEstimator { | ||
private final IdlePolicy idlePolicy; | ||
private boolean isIdle = false; | ||
|
||
public AbstractWatermarkEstimator(IdlePolicy idlePolicy) { | ||
Preconditions.checkNotNull(idlePolicy, "IdlePolicy must be provided"); | ||
this.idlePolicy = idlePolicy; | ||
} | ||
|
||
protected abstract long estimateWatermark(); | ||
|
||
protected abstract void updateWatermark(StreamElement element); | ||
|
||
@Override | ||
public void onIdle() { | ||
isIdle = true; | ||
idlePolicy.onIdle(getWatermark()); | ||
} | ||
|
||
@Override | ||
public void onElement(StreamElement element) { | ||
isIdle = false; | ||
updateWatermark(element); | ||
} | ||
|
||
@Override | ||
public long getWatermark() { | ||
if (isIdle) { | ||
final Optional<Long> idleWatermark = idlePolicy.getIdleWatermark(); | ||
if (idleWatermark.isPresent()) { | ||
return Math.max(estimateWatermark(), idleWatermark.get()); | ||
} | ||
} | ||
return estimateWatermark(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright 2017-2020 O2 Czech Republic, a.s. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cz.o2.proxima.time; | ||
|
||
import java.io.Serializable; | ||
import java.util.Optional; | ||
|
||
/** Policy supplies watermark on idle source. */ | ||
public interface IdlePolicy extends Serializable { | ||
|
||
default void onIdle(long currentWatermark) {} | ||
|
||
default Optional<Long> getIdleWatermark() { | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
core/src/main/java/cz/o2/proxima/time/WatermarkEstimatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cz.o2.proxima.time; | ||
|
||
import java.util.Map; | ||
|
||
public interface WatermarkEstimatorFactory { | ||
WatermarkEstimator create(Map<String, Object> config); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright 2017-2020 O2 Czech Republic, a.s. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package cz.o2.proxima.time; | ||
|
||
public class Watermarks { | ||
public static final long MIN_WATERMARK = Long.MIN_VALUE; | ||
public static final long MAX_WATERMARK = Long.MAX_VALUE; | ||
} |
Oops, something went wrong.