Tomek OsiĆski | e9ccf41 | 2018-01-13 19:44:11 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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.xmpp.core.ctl; |
| 18 | |
| 19 | |
| 20 | import io.netty.channel.ChannelInitializer; |
| 21 | import io.netty.channel.ChannelPipeline; |
| 22 | import io.netty.channel.socket.SocketChannel; |
| 23 | import org.onosproject.xmpp.core.XmppDeviceFactory; |
| 24 | import org.onosproject.xmpp.core.ctl.handlers.XmppChannelHandler; |
| 25 | import org.onosproject.xmpp.core.ctl.handlers.XmlMerger; |
| 26 | import org.onosproject.xmpp.core.ctl.handlers.XmlStreamDecoder; |
| 27 | import org.onosproject.xmpp.core.ctl.handlers.XmppDecoder; |
| 28 | import org.onosproject.xmpp.core.ctl.handlers.XmppEncoder; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | * Creates pipeline for server-side XMPP channel. |
| 33 | */ |
| 34 | public class XmppChannelInitializer extends ChannelInitializer<SocketChannel> { |
| 35 | |
| 36 | protected XmppDeviceFactory deviceFactory; |
| 37 | |
| 38 | public XmppChannelInitializer(XmppDeviceFactory deviceFactory) { |
| 39 | this.deviceFactory = deviceFactory; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Initializes pipeline for XMPP channel. |
| 44 | * @throws Exception |
| 45 | */ |
| 46 | @Override |
| 47 | protected void initChannel(SocketChannel channel) throws Exception { |
| 48 | ChannelPipeline pipeline = channel.pipeline(); |
| 49 | |
| 50 | XmppChannelHandler handler = new XmppChannelHandler(deviceFactory); |
| 51 | |
| 52 | pipeline.addLast("xmppencoder", new XmppEncoder()); |
| 53 | pipeline.addLast("xmlstreamdecoder", new XmlStreamDecoder()); |
| 54 | pipeline.addLast("xmlmerger", new XmlMerger()); |
| 55 | pipeline.addLast("xmppdecoder", new XmppDecoder()); |
| 56 | pipeline.addLast("handler", handler); |
| 57 | |
| 58 | } |
| 59 | } |