Skip to content

Commit

Permalink
PLANNER-491 Remove PartitionChangedEventId
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Nov 17, 2016
1 parent 7c57b1f commit 0943348
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 80 deletions.
Expand Up @@ -25,42 +25,42 @@
*/
public final class PartitionChangedEvent<Solution_> implements Serializable {

private final PartitionEventId id;
private final int partIndex;
private final long eventIndex;
private final PartitionChangedEventType type;
private final PartitionChangeMove<Solution_> move;
private final Throwable throwable;

public PartitionChangedEvent(PartitionEventId id, PartitionChangedEventType type) {
this.id = id;
public PartitionChangedEvent(int partIndex, long eventIndex, PartitionChangedEventType type) {
this.partIndex = partIndex;
this.eventIndex = eventIndex;
this.type = type;
move = null;
throwable = null;
}

public PartitionChangedEvent(PartitionEventId id, PartitionChangeMove<Solution_> move) {
this.id = id;
public PartitionChangedEvent(int partIndex, long eventIndex, PartitionChangeMove<Solution_> move) {
this.partIndex = partIndex;
this.eventIndex = eventIndex;
type = PartitionChangedEventType.MOVE;
this.move = move;
throwable = null;
}

public PartitionChangedEvent(PartitionEventId id, Throwable throwable) {
this.id = id;
public PartitionChangedEvent(int partIndex, long eventIndex, Throwable throwable) {
this.partIndex = partIndex;
this.eventIndex = eventIndex;
type = PartitionChangedEventType.EXCEPTION_THROWN;
move = null;
this.throwable = throwable;
}

public PartitionEventId getId() {
return id;
}

public int getPartIndex() {
return id.getPartIndex();
return partIndex;
}

public Long getEventIndex() {
return id.getEventIndex();
return eventIndex;
}

public PartitionChangedEventType getType() {
Expand Down

This file was deleted.

Expand Up @@ -69,8 +69,9 @@ public PartitionQueue(int partCount) {
* @param move never null
*/
public void addMove(int partIndex, PartitionChangeMove<Solution_> move) {
long eventIndex = nextEventIndexMap.get(partIndex).getAndIncrement();
PartitionChangedEvent<Solution_> event = new PartitionChangedEvent<>(
buildPartitionEventId(partIndex), move);
partIndex, eventIndex, move);
moveEventMap.put(event.getPartIndex(), event);
queue.add(event);
}
Expand All @@ -81,8 +82,9 @@ public void addMove(int partIndex, PartitionChangeMove<Solution_> move) {
* @param partIndex {@code 0 <= partIndex < partCount}
*/
public void addFinish(int partIndex) {
long eventIndex = nextEventIndexMap.get(partIndex).getAndIncrement();
PartitionChangedEvent<Solution_> event = new PartitionChangedEvent<>(
buildPartitionEventId(partIndex), PartitionChangedEvent.PartitionChangedEventType.FINISHED);
partIndex, eventIndex, PartitionChangedEvent.PartitionChangedEventType.FINISHED);
queue.add(event);
}

Expand All @@ -94,16 +96,12 @@ public void addFinish(int partIndex) {
* @param throwable never null
*/
public void addExceptionThrown(int partIndex, Throwable throwable) {
long eventIndex = nextEventIndexMap.get(partIndex).getAndIncrement();
PartitionChangedEvent<Solution_> event = new PartitionChangedEvent<>(
buildPartitionEventId(partIndex), throwable);
partIndex, eventIndex, throwable);
queue.add(event);
}

protected PartitionEventId buildPartitionEventId(int partIndex) {
long eventIndex = nextEventIndexMap.get(partIndex).getAndIncrement();
return new PartitionEventId(partIndex, eventIndex);
}

@Override
public Iterator<PartitionChangeMove> iterator() {
// Currently doesn't be support to be called twice on the same instance
Expand Down

0 comments on commit 0943348

Please sign in to comment.