Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 Open Networking Laboratory |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 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 | */ |
Thomas Vachuska | c97aa61 | 2015-06-23 16:00:18 -0700 | [diff] [blame] | 16 | package org.onosproject.store.trivial; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 17 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 18 | import com.google.common.collect.Sets; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Component; |
| 20 | import org.apache.felix.scr.annotations.Service; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.packet.OutboundPacket; |
| 22 | import org.onosproject.net.packet.PacketEvent; |
| 23 | import org.onosproject.net.packet.PacketEvent.Type; |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 24 | import org.onosproject.net.packet.PacketRequest; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 25 | import org.onosproject.net.packet.PacketStore; |
| 26 | import org.onosproject.net.packet.PacketStoreDelegate; |
| 27 | import org.onosproject.store.AbstractStore; |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 28 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 29 | |
| 30 | import java.util.Collections; |
| 31 | import java.util.Set; |
| 32 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Simple single instance implementation of the packet store. |
| 35 | */ |
| 36 | @Component(immediate = true) |
| 37 | @Service |
| 38 | public class SimplePacketStore |
| 39 | extends AbstractStore<PacketEvent, PacketStoreDelegate> |
| 40 | implements PacketStore { |
| 41 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 42 | private Set<PacketRequest> requests = Sets.newConcurrentHashSet(); |
| 43 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 44 | @Override |
| 45 | public void emit(OutboundPacket packet) { |
| 46 | notifyDelegate(new PacketEvent(Type.EMIT, packet)); |
| 47 | } |
| 48 | |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 49 | @Override |
| 50 | public boolean requestPackets(PacketRequest request) { |
| 51 | return requests.add(request); |
| 52 | } |
| 53 | |
| 54 | @Override |
Thomas Vachuska | 27bee09 | 2015-06-23 19:03:10 -0700 | [diff] [blame] | 55 | public boolean cancelPackets(PacketRequest request) { |
| 56 | return requests.remove(request); |
| 57 | } |
| 58 | |
| 59 | @Override |
alshabib | 4294778 | 2015-03-31 14:59:06 -0700 | [diff] [blame] | 60 | public Set<PacketRequest> existingRequests() { |
| 61 | return Collections.unmodifiableSet(requests); |
| 62 | } |
| 63 | |
Jonathan Hart | 4f60f98 | 2014-10-27 08:11:17 -0700 | [diff] [blame] | 64 | } |