blob: 9ddcf40e9727ac9b3067ffe8dd1b1458b0bfc36f [file] [log] [blame]
Sho SHIMIZU662c3db2015-02-23 16:59:01 -08001/*
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 */
16package org.onosproject.net.intent.impl.phase;
17
Sho SHIMIZU662c3db2015-02-23 16:59:01 -080018
19import java.util.Optional;
20import java.util.concurrent.Callable;
21
22import static com.google.common.base.Preconditions.checkNotNull;
Sho SHIMIZU662c3db2015-02-23 16:59:01 -080023
24/**
25 * Worker to process a submitted intent. {@link #call()} method generates
26 */
27public final class IntentWorker implements Callable<FinalIntentProcessPhase> {
28
Sho SHIMIZUce49b602015-02-23 19:15:49 -080029 private final IntentProcessPhase initial;
Sho SHIMIZU662c3db2015-02-23 16:59:01 -080030
31 /**
32 * Create an instance with the specified arguments.
33 *
Sho SHIMIZUce49b602015-02-23 19:15:49 -080034 * @param initial initial intent process phase
Sho SHIMIZU662c3db2015-02-23 16:59:01 -080035 */
Sho SHIMIZUce49b602015-02-23 19:15:49 -080036 public IntentWorker(IntentProcessPhase initial) {
37 this.initial = checkNotNull(initial);
Sho SHIMIZU662c3db2015-02-23 16:59:01 -080038 }
39
40 @Override
41 public FinalIntentProcessPhase call() throws Exception {
Sho SHIMIZUce49b602015-02-23 19:15:49 -080042 IntentProcessPhase update = initial;
Sho SHIMIZU662c3db2015-02-23 16:59:01 -080043 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 }
Sho SHIMIZU662c3db2015-02-23 16:59:01 -080052}