Andrea Campanella | 378e21a | 2017-06-07 12:09:59 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present 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 | |
| 17 | package org.onosproject.drivers.bmv2; |
| 18 | |
| 19 | import io.grpc.ManagedChannel; |
| 20 | import io.grpc.stub.StreamObserver; |
| 21 | import org.onosproject.grpc.api.GrpcObserverHandler; |
| 22 | import org.slf4j.Logger; |
| 23 | |
| 24 | import java.util.Optional; |
| 25 | |
| 26 | import static org.slf4j.LoggerFactory.getLogger; |
| 27 | |
| 28 | /** |
| 29 | * Sample Implementation of a PacketInObserverHandler. |
| 30 | * TODO refactor and actually use. |
| 31 | */ |
| 32 | public class Bmv2PacketInObserverHandler implements GrpcObserverHandler { |
| 33 | |
| 34 | private final Logger log = getLogger(getClass()); |
| 35 | |
| 36 | //private final AbstractStub asyncStub; |
| 37 | |
| 38 | //FIXME put at object due to p4Runtime compilation problems to be fixed. |
| 39 | private StreamObserver<Object> requestStreamObserver; |
| 40 | |
| 41 | @Override |
| 42 | public void bindObserver(ManagedChannel channel) { |
| 43 | |
| 44 | //asyncStub = ProtoGeneratedClass.newStub(channel); |
| 45 | |
| 46 | //reqeustStreamObserver = asyncStub.MethodName(new PacketInObserver()); |
| 47 | |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Optional<StreamObserver> requestStreamObserver() { |
| 52 | return Optional.of(requestStreamObserver); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void removeObserver() { |
| 57 | //this should complete the two way streaming |
| 58 | requestStreamObserver.onCompleted(); |
| 59 | } |
| 60 | |
| 61 | private class PacketInObserver implements StreamObserver<Object> { |
| 62 | |
| 63 | @Override |
| 64 | public void onNext(Object o) { |
| 65 | log.info("onNext: {}", o.toString()); |
| 66 | |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void onError(Throwable throwable) { |
| 71 | |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void onCompleted() { |
| 76 | |
| 77 | } |
| 78 | } |
| 79 | } |