blob: 110f42f53151c4834c9826ff696f740d2a1b7fe7 [file] [log] [blame]
Sho SHIMIZUee2aa652015-02-25 18:56:43 -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
18import org.onosproject.net.intent.Intent;
19import org.onosproject.net.intent.IntentData;
20import org.onosproject.net.intent.impl.IntentProcessor;
21
22import java.util.List;
23import java.util.Optional;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * Represents a phase where an intent is being recompiled.
29 */
30class Recompiling implements IntentProcessPhase {
31
32 private final IntentProcessor processor;
33 private final IntentData data;
34 private final IntentData stored;
35
36 /**
37 * Creates a intent recompiling phase.
38 *
39 * @param processor intent processor that does work for recompiling
40 * @param data intent data containing an intent to be recompiled
41 * @param stored intent data stored in the store
42 */
43 Recompiling(IntentProcessor processor, IntentData data, IntentData stored) {
44 this.processor = checkNotNull(processor);
45 this.data = checkNotNull(data);
46 this.stored = checkNotNull(stored);
47 }
48
49 @Override
50 public Optional<IntentProcessPhase> execute() {
51 List<Intent> compiled = processor.compile(data.intent(), stored.installables());
52 data.setInstallables(compiled);
53 return Optional.of(new Replacing(processor, data, stored));
54 }
55}