blob: 81cef49e20b9f6e4025815f7efeb3906112825c6 [file] [log] [blame]
Jonathan Hart4f60f982014-10-27 08:11:17 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Jonathan Hart4f60f982014-10-27 08:11:17 -07003 *
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 */
Thomas Vachuskac97aa612015-06-23 16:00:18 -070016package org.onosproject.store.trivial;
Jonathan Hart4f60f982014-10-27 08:11:17 -070017
alshabib42947782015-03-31 14:59:06 -070018import com.google.common.collect.Sets;
Jonathan Hart4f60f982014-10-27 08:11:17 -070019import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Service;
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.packet.OutboundPacket;
22import org.onosproject.net.packet.PacketEvent;
23import org.onosproject.net.packet.PacketEvent.Type;
alshabib42947782015-03-31 14:59:06 -070024import org.onosproject.net.packet.PacketRequest;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.net.packet.PacketStore;
26import org.onosproject.net.packet.PacketStoreDelegate;
27import org.onosproject.store.AbstractStore;
Jonathan Hart4f60f982014-10-27 08:11:17 -070028
alshabib42947782015-03-31 14:59:06 -070029
30import java.util.Collections;
31import java.util.Set;
32
Jonathan Hart4f60f982014-10-27 08:11:17 -070033/**
34 * Simple single instance implementation of the packet store.
35 */
36@Component(immediate = true)
37@Service
38public class SimplePacketStore
39 extends AbstractStore<PacketEvent, PacketStoreDelegate>
40 implements PacketStore {
41
alshabib42947782015-03-31 14:59:06 -070042 private Set<PacketRequest> requests = Sets.newConcurrentHashSet();
43
Jonathan Hart4f60f982014-10-27 08:11:17 -070044 @Override
45 public void emit(OutboundPacket packet) {
46 notifyDelegate(new PacketEvent(Type.EMIT, packet));
47 }
48
alshabib42947782015-03-31 14:59:06 -070049 @Override
50 public boolean requestPackets(PacketRequest request) {
51 return requests.add(request);
52 }
53
54 @Override
55 public Set<PacketRequest> existingRequests() {
56 return Collections.unmodifiableSet(requests);
57 }
58
Jonathan Hart4f60f982014-10-27 08:11:17 -070059}