blob: a17f7a3fe47d40106965825affe56a1a71ca0807 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
alshabib902d41b2014-10-07 16:52:05 -070017
Brian O'Connor427a1762014-11-19 18:40:32 -080018
19import java.util.Collections;
Madan Jampani117aaae2014-10-23 10:04:05 -070020import java.util.Set;
alshabib193525b2014-10-08 18:58:03 -070021
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080022import com.google.common.base.MoreObjects;
Madan Jampani117aaae2014-10-23 10:04:05 -070023import com.google.common.collect.ImmutableSet;
alshabib193525b2014-10-08 18:58:03 -070024
Brian O'Connorfa81eae2014-10-30 13:20:05 -070025/**
26 * Representation of a completed flow rule batch operation.
27 */
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070028public class CompletedBatchOperation implements BatchOperationResult<FlowRule> {
alshabib193525b2014-10-08 18:58:03 -070029
alshabib193525b2014-10-08 18:58:03 -070030 private final boolean success;
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070031 private final Set<FlowRule> failures;
Brian O'Connor427a1762014-11-19 18:40:32 -080032 private final Set<Long> failedIds;
33
34 /**
35 * Creates a new batch completion result.
36 *
37 * @param success indicates whether the completion is successful.
38 * @param failures set of any failures encountered
39 * @param failedIds (optional) set of failed operation ids
40 */
41 public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures,
42 Set<Long> failedIds) {
43 this.success = success;
44 this.failures = ImmutableSet.copyOf(failures);
45 this.failedIds = ImmutableSet.copyOf(failedIds);
46 }
alshabib193525b2014-10-08 18:58:03 -070047
Brian O'Connorfa81eae2014-10-30 13:20:05 -070048 /**
49 * Creates a new batch completion result.
50 *
51 * @param success indicates whether the completion is successful.
52 * @param failures set of any failures encountered
53 */
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070054 public CompletedBatchOperation(boolean success, Set<? extends FlowRule> failures) {
alshabib193525b2014-10-08 18:58:03 -070055 this.success = success;
Madan Jampani117aaae2014-10-23 10:04:05 -070056 this.failures = ImmutableSet.copyOf(failures);
Brian O'Connor427a1762014-11-19 18:40:32 -080057 this.failedIds = Collections.emptySet();
alshabib193525b2014-10-08 18:58:03 -070058 }
59
Brian O'Connor427a1762014-11-19 18:40:32 -080060
61
alshabib193525b2014-10-08 18:58:03 -070062 @Override
63 public boolean isSuccess() {
64 return success;
65 }
66
67 @Override
Yuta HIGUCHI4b524442014-10-28 22:23:57 -070068 public Set<FlowRule> failedItems() {
alshabib193525b2014-10-08 18:58:03 -070069 return failures;
70 }
alshabib902d41b2014-10-07 16:52:05 -070071
Brian O'Connor427a1762014-11-19 18:40:32 -080072 public Set<Long> failedIds() {
73 return failedIds;
74 }
75
Yuta HIGUCHI82e53262014-11-27 10:28:51 -080076 @Override
77 public String toString() {
78 return MoreObjects.toStringHelper(getClass())
79 .add("success?", success)
80 .add("failedItems", failures)
81 .add("failedIds", failedIds)
82 .toString();
83 }
alshabib902d41b2014-10-07 16:52:05 -070084}