SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [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 | */ |
| 16 | |
harikrushna-Huawei | a2c7c20 | 2017-04-10 18:22:00 +0530 | [diff] [blame] | 17 | package org.onosproject.pcep.server.impl; |
SureshBR | 25058b7 | 2015-08-13 13:05:06 +0530 | [diff] [blame] | 18 | |
| 19 | import org.jboss.netty.channel.ChannelPipeline; |
| 20 | import org.jboss.netty.channel.ChannelPipelineFactory; |
| 21 | import org.jboss.netty.channel.Channels; |
| 22 | import org.jboss.netty.handler.timeout.IdleStateHandler; |
| 23 | import org.jboss.netty.handler.timeout.ReadTimeoutHandler; |
| 24 | import org.jboss.netty.util.ExternalResourceReleasable; |
| 25 | import org.jboss.netty.util.HashedWheelTimer; |
| 26 | import org.jboss.netty.util.Timer; |
| 27 | |
| 28 | /** |
| 29 | * Creates a ChannelPipeline for a server-side pcep channel. |
| 30 | */ |
| 31 | public class PcepPipelineFactory |
| 32 | implements ChannelPipelineFactory, ExternalResourceReleasable { |
| 33 | |
| 34 | protected Controller controller; |
| 35 | static final Timer TIMER = new HashedWheelTimer(); |
| 36 | protected IdleStateHandler idleHandler; |
| 37 | protected ReadTimeoutHandler readTimeoutHandler; |
| 38 | static final int DEFAULT_KEEP_ALIVE_TIME = 30; |
| 39 | static final int DEFAULT_DEAD_TIME = 120; |
| 40 | static final int DEFAULT_WAIT_TIME = 60; |
| 41 | |
| 42 | public PcepPipelineFactory(Controller controller) { |
| 43 | super(); |
| 44 | this.controller = controller; |
| 45 | this.idleHandler = new IdleStateHandler(TIMER, DEFAULT_DEAD_TIME, DEFAULT_KEEP_ALIVE_TIME, 0); |
| 46 | this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, DEFAULT_WAIT_TIME); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public ChannelPipeline getPipeline() throws Exception { |
| 51 | PcepChannelHandler handler = new PcepChannelHandler(controller); |
| 52 | |
| 53 | ChannelPipeline pipeline = Channels.pipeline(); |
| 54 | pipeline.addLast("pcepmessagedecoder", new PcepMessageDecoder()); |
| 55 | pipeline.addLast("pcepmessageencoder", new PcepMessageEncoder()); |
| 56 | pipeline.addLast("idle", idleHandler); |
| 57 | pipeline.addLast("waittimeout", readTimeoutHandler); |
| 58 | pipeline.addLast("handler", handler); |
| 59 | return pipeline; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public void releaseExternalResources() { |
| 64 | TIMER.stop(); |
| 65 | } |
| 66 | } |