Copyright update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / IdleHandler.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. 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;
10
11 import java.util.concurrent.TimeUnit;
12
13 import io.netty.channel.ChannelHandlerContext;
14 import io.netty.handler.timeout.IdleState;
15 import io.netty.handler.timeout.IdleStateEvent;
16 import io.netty.handler.timeout.IdleStateHandler;
17
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEventBuilder;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Detects idle state of switch and informs upper layers
24  * @author michal.polkorab
25  */
26 public class IdleHandler extends IdleStateHandler{
27
28     private static final Logger LOGGER = LoggerFactory.getLogger(IdleHandler.class);
29
30     /**
31      * @param readerIdleTime
32      * @param writerIdleTime
33      * @param allIdleTime
34      * @param unit
35      */
36     public IdleHandler(long readerIdleTime, long writerIdleTime,
37             long allIdleTime, TimeUnit unit) {
38         super(readerIdleTime, writerIdleTime, allIdleTime, unit);
39     }
40
41     @Override
42     protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent evt)
43             throws Exception {
44         if ((evt.state() == IdleState.READER_IDLE) && (evt.isFirst())) {
45             LOGGER.info("Switch idle");
46             SwitchIdleEventBuilder builder = new SwitchIdleEventBuilder();
47             builder.setInfo("Switch idle");
48             ctx.fireChannelRead(builder.build());
49         }
50     }
51
52 }