blob: bc7a7f515b99dc2cd31f94865b3a96943f9e3a12 [file] [log] [blame]
Brian O'Connorcff03322015-02-03 15:28:59 -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;
17
18import com.google.common.collect.Maps;
19import org.onlab.util.AbstractAccumulator;
20import org.onosproject.net.intent.IntentData;
21
22import java.util.List;
23import java.util.Map;
24import java.util.Timer;
25
26/**
27 * An accumulator for building batches of intent operations. Only one batch should
28 * be in process per instance at a time.
29 */
30public class IntentAccumulator extends AbstractAccumulator<IntentData> {
31
32 private static final int DEFAULT_MAX_EVENTS = 1000;
33 private static final int DEFAULT_MAX_IDLE_MS = 10;
34 private static final int DEFAULT_MAX_BATCH_MS = 50;
35
36 // FIXME: Replace with a system-wide timer instance;
37 // TODO: Convert to use HashedWheelTimer or produce a variant of that; then decide which we want to adopt
38 private static final Timer TIMER = new Timer("intent-op-batching");
39
40 /**
41 * Creates an intent operation accumulator.
42 */
43 protected IntentAccumulator() {
44 super(TIMER, DEFAULT_MAX_EVENTS, DEFAULT_MAX_BATCH_MS, DEFAULT_MAX_IDLE_MS);
45 }
46
47 @Override
48 public void processEvents(List<IntentData> ops) {
49 Map<String, IntentData> opMap = reduce(ops);
50 // FIXME kick off the work
51 //for (IntentData data : opMap.values()) {}
52 }
53
54 private Map<String, IntentData> reduce(List<IntentData> ops) {
55 Map<String, IntentData> map = Maps.newHashMap();
56 for (IntentData op : ops) {
57 map.put(op.key(), op);
58 }
59 //TODO check the version... or maybe store will handle this.
60 return map;
61 }
62}