Skip to content

Commit

Permalink
refactor: use lambdas for updaters
Browse files Browse the repository at this point in the history
  • Loading branch information
ngmr committed Jan 17, 2025
1 parent 8fd34b6 commit a97a7b0
Showing 1 changed file with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,10 @@
import com.ibm.ws.sib.msgstore.persistence.dispatcher.StateUtils.StateUpdater;

final class DispatcherState {
static final StateUpdater<DispatcherState> updaterForStart = new StateUpdater<DispatcherState>() {
public DispatcherState update(DispatcherState currentState) {
return currentState.startRequested().running(true);
}
};
static final StateUpdater<DispatcherState> updaterForStopped = new StateUpdater<DispatcherState>() {
public DispatcherState update(DispatcherState currentState) {
return currentState.running(false);
}
};
static final StateUpdater<DispatcherState> updaterForErrorOccurred = new StateUpdater<DispatcherState>() {
public DispatcherState update(DispatcherState currentState) {
return currentState.addThreadWriteError();
}
};
static final StateUpdater<DispatcherState> updaterForErrorCleared = new StateUpdater<DispatcherState>() {
public DispatcherState update(DispatcherState currentState) {
return currentState.clearThreadWriteError();
}
};
static final StateUpdater<DispatcherState> updaterForStart = state -> state.startRequested().running(true);
static final StateUpdater<DispatcherState> updaterForStopped = state -> state.running(false);
static final StateUpdater<DispatcherState> updaterForErrorOccurred = DispatcherState::addThreadWriteError;
static final StateUpdater<DispatcherState> updaterForErrorCleared = DispatcherState::clearThreadWriteError;

public static final class StopRequesterInfo extends Throwable {
private static final long serialVersionUID = 1L;
Expand All @@ -52,13 +36,7 @@ public StopRequesterInfo(Throwable requester) {
}

static StateUpdater<DispatcherState> getUpdaterForStopRequested(final Throwable requester) {
return new StateUpdater<DispatcherState>() {
@Override
public DispatcherState update(DispatcherState currentState) {
if (!currentState.isRunning) return currentState;
return currentState.stopRequested(new StopRequesterInfo(requester));
}
};
return state -> state.isRunning ? state.stopRequested(new StopRequesterInfo(requester)) : state;
}

// Flag set to indicate whether dispatcher is running.
Expand Down

0 comments on commit a97a7b0

Please sign in to comment.