Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Remove IntentWorker by replacing it with lambda

Change-Id: Ic5d235f9b47711c4f87fbcb2e7af83853248ace5
/*
* Copyright 2014-2015 Open Networking Laboratory
* Copyright 2014-2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -44,7 +44,6 @@ import org.onosproject.net.intent.IntentStoreDelegate;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase;
import org.onosproject.net.intent.impl.phase.IntentProcessPhase;
import org.onosproject.net.intent.impl.phase.IntentWorker;
import org.slf4j.Logger;
import java.util.Collection;
......@@ -290,7 +289,16 @@ public class IntentManager
private Future<FinalIntentProcessPhase> submitIntentData(IntentData data) {
IntentData current = store.getIntentData(data.key());
IntentProcessPhase initial = newInitialPhase(processor, data, current);
return workerExecutor.submit(new IntentWorker(initial));
return workerExecutor.submit(() -> {
Optional<IntentProcessPhase> currentPhase = Optional.of(initial);
IntentProcessPhase previousPhase = initial;
while (currentPhase.isPresent()) {
previousPhase = currentPhase.get();
currentPhase = previousPhase.execute();
}
return (FinalIntentProcessPhase) previousPhase;
});
}
private class IntentBatchProcess implements Runnable {
......
/*
* Copyright 2015 Open Networking Laboratory
*
* 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 org.onosproject.net.intent.impl.phase;
import java.util.Optional;
import java.util.concurrent.Callable;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Worker to process a submitted intent. {@link #call()} method generates
*/
public final class IntentWorker implements Callable<FinalIntentProcessPhase> {
private final IntentProcessPhase initial;
/**
* Create an instance with the specified arguments.
*
* @param initial initial intent process phase
*/
public IntentWorker(IntentProcessPhase initial) {
this.initial = checkNotNull(initial);
}
@Override
public FinalIntentProcessPhase call() throws Exception {
IntentProcessPhase update = initial;
Optional<IntentProcessPhase> currentPhase = Optional.of(update);
IntentProcessPhase previousPhase = update;
while (currentPhase.isPresent()) {
previousPhase = currentPhase.get();
currentPhase = previousPhase.execute();
}
return (FinalIntentProcessPhase) previousPhase;
}
}