Barrier turn on/off - Split ConnectionAdapter functionality
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / connection / AbstractConnectionAdapterStatistics.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.impl.core.connection;
10
11 import com.google.common.util.concurrent.ListenableFuture;
12 import io.netty.channel.Channel;
13 import java.net.InetSocketAddress;
14 import java.util.concurrent.Future;
15 import org.opendaylight.openflowjava.statistics.CounterEventTypes;
16 import org.opendaylight.openflowjava.statistics.StatisticsCounters;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
21 import org.opendaylight.yangtools.yang.binding.DataObject;
22 import org.opendaylight.yangtools.yang.binding.Notification;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24
25 /**
26  * Class is only wrapper for {@link AbstractConnectionAdapter} to provide statistics
27  * records for counting all needed RPC messages in Openflow Java.
28  */
29 abstract class AbstractConnectionAdapterStatistics extends AbstractConnectionAdapter implements MessageConsumer {
30
31     private final StatisticsCounters statisticsCounters;
32
33     AbstractConnectionAdapterStatistics(final Channel channel, final InetSocketAddress address) {
34         super(channel, address);
35         statisticsCounters = StatisticsCounters.getInstance();
36     }
37
38     @Override
39     public Future<RpcResult<Void>> flowMod(final FlowModInput input) {
40         statisticsCounters.incrementCounter(CounterEventTypes.DS_FLOW_MODS_ENTERED);
41         return super.flowMod(input);
42     }
43
44     @Override
45     protected <IN extends OfHeader, OUT extends OfHeader> ListenableFuture<RpcResult<OUT>> sendToSwitchExpectRpcResultFuture(
46             final IN input, final Class<OUT> responseClazz, final String failureInfo) {
47         statisticsCounters.incrementCounter(CounterEventTypes.DS_ENTERED_OFJAVA);
48         return super.sendToSwitchExpectRpcResultFuture(input, responseClazz, failureInfo);
49     }
50
51     @Override
52     protected ListenableFuture<RpcResult<Void>> sendToSwitchFuture(final DataObject input, final String failureInfo) {
53         statisticsCounters.incrementCounter(CounterEventTypes.DS_ENTERED_OFJAVA);
54         return super.sendToSwitchFuture(input, failureInfo);
55     }
56
57     @Override
58     public void consume(final DataObject message) {
59         if (Notification.class.isInstance(message)) {
60             if (!(DisconnectEvent.class.isInstance(message) || SwitchIdleEvent.class.isInstance(message))) {
61                 statisticsCounters.incrementCounter(CounterEventTypes.US_MESSAGE_PASS);
62             }
63         } else if (OfHeader.class.isInstance(message)) {
64             statisticsCounters.incrementCounter(CounterEventTypes.US_MESSAGE_PASS);
65         }
66         consumeDeviceMessage(message);
67     }
68
69     /**
70      * Method is equivalent to {@link MessageConsumer#consume(DataObject)} to prevent missing method
71      * in every children of {@link AbstractConnectionAdapterStatistics} class, because we overriding
72      * original method for {@link StatisticsCounters}
73      *
74      * @param message from device to processing
75      */
76     protected abstract void consumeDeviceMessage(DataObject message);
77 }
78