Sho SHIMIZU
Committed by Gerrit Code Review

Refactor: Remove IntentWorker by replacing it with lambda

Change-Id: Ic5d235f9b47711c4f87fbcb2e7af83853248ace5
1 /* 1 /*
2 - * Copyright 2014-2015 Open Networking Laboratory 2 + * Copyright 2014-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -44,7 +44,6 @@ import org.onosproject.net.intent.IntentStoreDelegate; ...@@ -44,7 +44,6 @@ import org.onosproject.net.intent.IntentStoreDelegate;
44 import org.onosproject.net.intent.Key; 44 import org.onosproject.net.intent.Key;
45 import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase; 45 import org.onosproject.net.intent.impl.phase.FinalIntentProcessPhase;
46 import org.onosproject.net.intent.impl.phase.IntentProcessPhase; 46 import org.onosproject.net.intent.impl.phase.IntentProcessPhase;
47 -import org.onosproject.net.intent.impl.phase.IntentWorker;
48 import org.slf4j.Logger; 47 import org.slf4j.Logger;
49 48
50 import java.util.Collection; 49 import java.util.Collection;
...@@ -290,7 +289,16 @@ public class IntentManager ...@@ -290,7 +289,16 @@ public class IntentManager
290 private Future<FinalIntentProcessPhase> submitIntentData(IntentData data) { 289 private Future<FinalIntentProcessPhase> submitIntentData(IntentData data) {
291 IntentData current = store.getIntentData(data.key()); 290 IntentData current = store.getIntentData(data.key());
292 IntentProcessPhase initial = newInitialPhase(processor, data, current); 291 IntentProcessPhase initial = newInitialPhase(processor, data, current);
293 - return workerExecutor.submit(new IntentWorker(initial)); 292 + return workerExecutor.submit(() -> {
293 + Optional<IntentProcessPhase> currentPhase = Optional.of(initial);
294 + IntentProcessPhase previousPhase = initial;
295 +
296 + while (currentPhase.isPresent()) {
297 + previousPhase = currentPhase.get();
298 + currentPhase = previousPhase.execute();
299 + }
300 + return (FinalIntentProcessPhase) previousPhase;
301 + });
294 } 302 }
295 303
296 private class IntentBatchProcess implements Runnable { 304 private class IntentBatchProcess implements Runnable {
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.net.intent.impl.phase;
17 -
18 -
19 -import java.util.Optional;
20 -import java.util.concurrent.Callable;
21 -
22 -import static com.google.common.base.Preconditions.checkNotNull;
23 -
24 -/**
25 - * Worker to process a submitted intent. {@link #call()} method generates
26 - */
27 -public final class IntentWorker implements Callable<FinalIntentProcessPhase> {
28 -
29 - private final IntentProcessPhase initial;
30 -
31 - /**
32 - * Create an instance with the specified arguments.
33 - *
34 - * @param initial initial intent process phase
35 - */
36 - public IntentWorker(IntentProcessPhase initial) {
37 - this.initial = checkNotNull(initial);
38 - }
39 -
40 - @Override
41 - public FinalIntentProcessPhase call() throws Exception {
42 - IntentProcessPhase update = initial;
43 - Optional<IntentProcessPhase> currentPhase = Optional.of(update);
44 - IntentProcessPhase previousPhase = update;
45 -
46 - while (currentPhase.isPresent()) {
47 - previousPhase = currentPhase.get();
48 - currentPhase = previousPhase.execute();
49 - }
50 - return (FinalIntentProcessPhase) previousPhase;
51 - }
52 -}