1 package org.opendaylight.openflowjava.protocol.impl.core;
\r
3 import io.netty.channel.Channel;
\r
4 import io.netty.channel.ChannelInitializer;
\r
5 import io.netty.channel.group.DefaultChannelGroup;
\r
6 import io.netty.channel.socket.SocketChannel;
\r
8 import java.util.Iterator;
\r
10 import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
\r
11 import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionFacade;
\r
12 import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterFactory;
\r
13 import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES;
\r
16 * @author michal.polkorab
\r
19 public class PublishingChannelInitializer extends ChannelInitializer<SocketChannel> {
\r
21 private DefaultChannelGroup allChannels;
\r
22 private SwitchConnectionHandler switchConnectionHandler;
\r
27 public PublishingChannelInitializer() {
\r
28 allChannels = new DefaultChannelGroup("netty-receiver", null);
\r
32 protected void initChannel(SocketChannel ch) throws Exception {
\r
33 // TODO - call switchConnectionHandler accept first
\r
34 allChannels.add(ch);
\r
35 ConnectionFacade connectionAdapter = null;
\r
36 if (switchConnectionHandler != null) {
\r
37 connectionAdapter = ConnectionAdapterFactory.createConnectionAdapter(ch);
\r
38 switchConnectionHandler.onSwitchConnected(connectionAdapter);
\r
40 ch.pipeline().addLast(COMPONENT_NAMES.TLS_DETECTOR.name(), new TlsDetector());
\r
41 ch.pipeline().addLast(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), new DelegatingInboundHandler(connectionAdapter));
\r
45 * @return iterator through active connections
\r
47 public Iterator<Channel> getConnectionIterator() {
\r
48 return allChannels.iterator();
\r
52 * @return amount of active channels
\r
55 return allChannels.size();
\r
59 * @param switchListener the switchListener to set
\r
61 public void setSwitchConnectionHandler(SwitchConnectionHandler switchListener) {
\r
62 this.switchConnectionHandler = switchListener;
\r