-
Notifications
You must be signed in to change notification settings - Fork 460
/
FormerStreamsLeasesDeletionStrategy.java
104 lines (87 loc) · 3.5 KB
/
FormerStreamsLeasesDeletionStrategy.java
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
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates.
* 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 software.amazon.kinesis.processor;
import java.time.Duration;
import java.util.List;
import software.amazon.kinesis.common.StreamIdentifier;
/**
* Strategy for cleaning up the leases for former streams.
*/
public interface FormerStreamsLeasesDeletionStrategy {
/**
* StreamIdentifiers for which leases needs to be cleaned up in the lease table.
* @return
*/
List<StreamIdentifier> streamIdentifiersForLeaseCleanup();
/**
* Duration to wait before deleting the leases for this stream.
* @return
*/
Duration waitPeriodToDeleteFormerStreams();
/**
* Strategy type for deleting the leases of former active streams.
* @return
*/
StreamsLeasesDeletionType leaseDeletionType();
/**
* StreamsLeasesDeletionType identifying the different lease cleanup strategies.
*/
enum StreamsLeasesDeletionType {
NO_STREAMS_LEASES_DELETION,
FORMER_STREAMS_AUTO_DETECTION_DEFERRED_DELETION,
PROVIDED_STREAMS_DEFERRED_DELETION
}
/**
* Strategy for not cleaning up leases for former streams.
*/
final class NoLeaseDeletionStrategy implements FormerStreamsLeasesDeletionStrategy {
@Override
public final List<StreamIdentifier> streamIdentifiersForLeaseCleanup() {
throw new UnsupportedOperationException("StreamIdentifiers not required");
}
@Override
public final Duration waitPeriodToDeleteFormerStreams() {
return Duration.ZERO;
}
@Override
public final StreamsLeasesDeletionType leaseDeletionType() {
return StreamsLeasesDeletionType.NO_STREAMS_LEASES_DELETION;
}
}
/**
* Strategy for auto detection the old of former streams based on the {@link MultiStreamTracker#streamConfigList()}
* and do deferred deletion based on {@link #waitPeriodToDeleteFormerStreams()}
*/
abstract class AutoDetectionAndDeferredDeletionStrategy implements FormerStreamsLeasesDeletionStrategy {
@Override
public final List<StreamIdentifier> streamIdentifiersForLeaseCleanup() {
throw new UnsupportedOperationException("StreamIdentifiers not required");
}
@Override
public final StreamsLeasesDeletionType leaseDeletionType() {
return StreamsLeasesDeletionType.FORMER_STREAMS_AUTO_DETECTION_DEFERRED_DELETION;
}
}
/**
* Strategy to detect the streams for deletion through {@link #streamIdentifiersForLeaseCleanup()} provided by customer at runtime
* and do deferred deletion based on {@link #waitPeriodToDeleteFormerStreams()}
*/
abstract class ProvidedStreamsDeferredDeletionStrategy implements FormerStreamsLeasesDeletionStrategy {
@Override
public final StreamsLeasesDeletionType leaseDeletionType() {
return StreamsLeasesDeletionType.PROVIDED_STREAMS_DEFERRED_DELETION;
}
}
}