blob: 1d44e29d90710533cc9b730582068903f2963af8 [file] [log] [blame]
Tomek OsiƄskie9ccf412018-01-13 19:44:11 +01001/*
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
17package org.onosproject.xmpp.core.ctl;
18
19
20import io.netty.channel.ChannelInitializer;
21import io.netty.channel.ChannelPipeline;
22import io.netty.channel.socket.SocketChannel;
23import org.onosproject.xmpp.core.XmppDeviceFactory;
24import org.onosproject.xmpp.core.ctl.handlers.XmppChannelHandler;
25import org.onosproject.xmpp.core.ctl.handlers.XmlMerger;
26import org.onosproject.xmpp.core.ctl.handlers.XmlStreamDecoder;
27import org.onosproject.xmpp.core.ctl.handlers.XmppDecoder;
28import org.onosproject.xmpp.core.ctl.handlers.XmppEncoder;
29
30
31/**
32 * Creates pipeline for server-side XMPP channel.
33 */
34public 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}