Skip to content

Commit

Permalink
Make ArrayUpdater backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
gilberto-torrezan committed Jul 23, 2018
1 parent 279d174 commit 48ead47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public interface Update extends Serializable {
* @param parentKey
* Parent item key that cleared range affects
*/
void clear(int start, int length, String parentKey);
default void clear(int start, int length, String parentKey) {
clear(start, length);
}

/**
* Sets the {@code items} at the {@code start} position.
Expand All @@ -80,7 +82,9 @@ public interface Update extends Serializable {
* @param parentKey
* Parent item key where given items belongs to
*/
void set(int start, List<JsonValue> items, String parentKey);
default void set(int start, List<JsonValue> items, String parentKey) {
set(start, items);
}

/**
* Commits changes for the given {@code updateId}.
Expand All @@ -102,13 +106,16 @@ public interface Update extends Serializable {
* Total number of direct child items for the given parent
* key
*/
void commit(int updateId, String parentKey, int levelSize);
default void commit(int updateId, String parentKey, int levelSize) {
commit(updateId);
}

/**
* Commits enqueued function calls added via
* {@link #enqueue(String, Serializable...)}.
*/
void commit();
default void commit() {
}

/**
* Enqueue function call with the given arguments.
Expand All @@ -122,7 +129,8 @@ public interface Update extends Serializable {
* supported by the communication mechanism, as defined by
* {@link JsonCodec}
*/
void enqueue(String name, Serializable... arguments);
default void enqueue(String name, Serializable... arguments) {
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@

/**
* CommunicationController controls all Grid's communication to client.
* <p>
* TODO move this class to 'flow-data' module first. Then get rid of the
* {@link Update} in this class by replacing {@link Update#set(int, List)},
* {@link Update#clear(int, int)} and {@link Update#commit(int)} methods with
* {@link Update#set(int, List, String)}, {@link Update#clear(int, int, String)}
* and {@link Update#commit(int, String, int)}.
*
* @param <T>
* the target bean type
Expand Down Expand Up @@ -100,10 +94,8 @@ public class CommunicationController<T> implements Serializable {
* Function for fetching items for target parent and specified
* range
*/
public CommunicationController(String parentKey,
DataKeyMapper<T> keyMapper,
HierarchyMapper<T, ?> mapper,
DataGenerator<T> dataGenerator,
public CommunicationController(String parentKey, DataKeyMapper<T> keyMapper,
HierarchyMapper<T, ?> mapper, DataGenerator<T> dataGenerator,
SerializableFunction<Integer, Update> startUpdate,
SerializableBiFunction<String, Range, Stream<T>> fetchItems) {
this.parentKey = parentKey;
Expand Down Expand Up @@ -209,8 +201,7 @@ private void set(Range effectiveRequested, Update update) {
getJsonItems(effectiveRequested));
} else {
update.set(effectiveRequested.getStart(),
getJsonItems(effectiveRequested),
parentKey);
getJsonItems(effectiveRequested), parentKey);
}
}

Expand Down Expand Up @@ -259,7 +250,7 @@ private List<String> activate(Range range) {

// XXX Explicitly refresh anything that is updated
List<String> activeKeys = new ArrayList<>(range.length());

fetchItems.apply(parentKey, range).forEach(bean -> {
boolean mapperHasKey = keyMapper.has(bean);
String key = keyMapper.key(bean);
Expand All @@ -273,8 +264,7 @@ private List<String> activate(Range range) {
}

private void passivateInactiveKeys(Set<String> oldActive,
List<String> newActiveKeyOrder, Update update,
boolean updated) {
List<String> newActiveKeyOrder, Update update, boolean updated) {
/*
* We cannot immediately unregister keys that we have asked the client
* to remove, since the client might send a message using that key
Expand All @@ -283,8 +273,8 @@ private void passivateInactiveKeys(Set<String> oldActive,
*/
if (updated) {
int updateId = nextUpdateId++;
if(parentKey == null) {

if (parentKey == null) {
update.commit(updateId);
} else {
update.commit(updateId, parentKey, assumedSize);
Expand Down

0 comments on commit 48ead47

Please sign in to comment.