-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use an explicit per-View modification counter [ECR-2804] #658
Merged
dmitry-timofeev
merged 11 commits into
exonum:master
from
dmitry-timofeev:refactor-mod-counter
Jan 18, 2019
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
82dead4
Update Powermock
dmitry-timofeev 6e44a6c
Use an explicit per-View modification counter [ECR-2804]:
dmitry-timofeev bb7a4f1
Remove dependency of RustIter on View
dmitry-timofeev 4bcc1b6
Clarify documentation
dmitry-timofeev f227820
Remove initial_value
dmitry-timofeev 70f0f9f
Update exonum-java-binding-core/src/main/java/com/exonum/binding/stor…
bullet-tooth 80c7ba9
Merge branch 'refactor-mod-counter' of github.com:dmitry-timofeev/exo…
dmitry-timofeev 2cad55b
Merge remote-tracking branch 'main/master' into refactor-mod-counter
dmitry-timofeev 16b6f6d
Update changelog
dmitry-timofeev 9c96b2e
Fix checkstyle
dmitry-timofeev 206a972
Merge branch 'master' into refactor-mod-counter
dmitry-timofeev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
39 changes: 39 additions & 0 deletions
39
...-core/src/main/java/com/exonum/binding/storage/database/ImmutableModificationCounter.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,39 @@ | ||
/* | ||
* Copyright 2019 The Exonum Team | ||
* | ||
* 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 com.exonum.binding.storage.database; | ||
|
||
enum ImmutableModificationCounter implements ModificationCounter { | ||
|
||
INSTANCE; | ||
|
||
private static final int INITIAL_VALUE = 0; | ||
|
||
@Override | ||
public boolean isModifiedSince(int lastValue) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int getCurrentValue() { | ||
return INITIAL_VALUE; | ||
} | ||
|
||
@Override | ||
public void notifyModified() { | ||
throw new IllegalStateException("Immutable counter cannot be modified"); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ore/src/main/java/com/exonum/binding/storage/database/IncrementalModificationCounter.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,37 @@ | ||
/* | ||
* Copyright 2019 The Exonum Team | ||
* | ||
* 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 com.exonum.binding.storage.database; | ||
|
||
final class IncrementalModificationCounter implements ModificationCounter { | ||
|
||
private int counter = 0; | ||
|
||
@Override | ||
public boolean isModifiedSince(int lastValue) { | ||
return counter != lastValue; | ||
} | ||
|
||
@Override | ||
public int getCurrentValue() { | ||
return counter; | ||
} | ||
|
||
@Override | ||
public void notifyModified() { | ||
counter++; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...a-binding-core/src/main/java/com/exonum/binding/storage/database/ModificationCounter.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,52 @@ | ||
/* | ||
* Copyright 2019 The Exonum Team | ||
* | ||
* 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 com.exonum.binding.storage.database; | ||
|
||
/** | ||
* A counter of modification events of some objects (e.g., a collection, or a database view). | ||
* It is updated each time the object notifies of an event. The clients that need | ||
* to detect modifications must save the current value of the counter, and check if it has changed | ||
* to determine if the corresponding source object is modified. | ||
* | ||
* <p>Implementations must reliably detect up to 4 billion modifications (2^32-1). | ||
* | ||
* <p>Implementations are not required to be thread-safe. | ||
*/ | ||
public interface ModificationCounter { | ||
|
||
/** | ||
* Returns true if the counter was modified since the given value (if {@link #notifyModified()} | ||
* has been invoked); false — otherwise. | ||
* | ||
* @param lastValue the last value of the counter | ||
*/ | ||
boolean isModifiedSince(int lastValue); | ||
|
||
/** | ||
* Returns the current value of the counter. No assumptions must be made on how it changes | ||
* when a notification is received. | ||
*/ | ||
int getCurrentValue(); | ||
|
||
/** | ||
* Notifies this counter that the source object is modified, updating its current value. | ||
* | ||
* @throws IllegalStateException if this counter corresponds to a read-only (immutable) object, | ||
* i.e., must reject any modification events | ||
*/ | ||
void notifyModified(); | ||
} |
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
95 changes: 0 additions & 95 deletions
95
...nding-core/src/main/java/com/exonum/binding/storage/database/ViewModificationCounter.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if a counter shall concern itself with immutable things (on top of that, the AbstractIndexProxy does this check itself)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to be safe and throw an exception in case of an immutable counter (as it is now)