Sho SHIMIZU | 5cb438e | 2015-02-04 13:46:00 -0800 | [diff] [blame^] | 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; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableList; |
| 19 | import org.onosproject.net.flow.FlowRuleBatchOperation; |
| 20 | import org.onosproject.net.intent.Intent; |
| 21 | |
| 22 | import java.util.LinkedList; |
| 23 | import java.util.List; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | class Withdrawn implements CompletedIntentUpdate { |
| 28 | |
| 29 | // TODO: define an interface and use it, instead of IntentManager |
| 30 | private final IntentManager intentManager; |
| 31 | private final Intent intent; |
| 32 | private final List<Intent> installables; |
| 33 | private final List<FlowRuleBatchOperation> batches; |
| 34 | private int currentBatch; |
| 35 | |
| 36 | Withdrawn(IntentManager intentManager, |
| 37 | Intent intent, List<Intent> installables, List<FlowRuleBatchOperation> batches) { |
| 38 | this.intentManager = checkNotNull(intentManager); |
| 39 | this.intent = checkNotNull(intent); |
| 40 | this.installables = ImmutableList.copyOf(installables); |
| 41 | this.batches = new LinkedList<>(batches); |
| 42 | this.currentBatch = 0; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public List<Intent> allInstallables() { |
| 47 | return installables; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public void batchSuccess() { |
| 52 | currentBatch++; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public FlowRuleBatchOperation currentBatch() { |
| 57 | return currentBatch < batches.size() ? batches.get(currentBatch) : null; |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void batchFailed() { |
| 62 | for (int i = batches.size() - 1; i >= currentBatch; i--) { |
| 63 | batches.remove(i); |
| 64 | } |
| 65 | batches.addAll(intentManager.uninstallIntent(intent, installables)); |
| 66 | } |
| 67 | } |