2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.protocol.pcep.impl;
10 import com.google.common.base.Preconditions;
11 import io.netty.channel.ChannelFuture;
12 import io.netty.channel.EventLoopGroup;
13 import io.netty.channel.socket.SocketChannel;
14 import io.netty.util.concurrent.Promise;
15 import org.opendaylight.protocol.framework.AbstractDispatcher;
16 import org.opendaylight.protocol.framework.SessionListenerFactory;
17 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
18 import org.opendaylight.protocol.pcep.PCEPDispatcher;
19 import org.opendaylight.protocol.pcep.PCEPSessionListener;
20 import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
23 import java.io.IOException;
24 import java.net.InetSocketAddress;
27 * Implementation of PCEPDispatcher.
29 public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher, AutoCloseable {
31 private final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf;
32 private final PCEPHandlerFactory hf;
35 * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
37 * @throws IOException if some error occurred during opening the selector
39 public PCEPDispatcherImpl(final MessageHandlerRegistry registry,
40 final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory,
41 EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
42 super(bossGroup, workerGroup);
43 this.snf = Preconditions.checkNotNull(negotiatorFactory);
44 this.hf = new PCEPHandlerFactory(registry);
48 public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
49 return super.createServer(address, new PipelineInitializer<PCEPSessionImpl>() {
51 public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise) {
52 ch.pipeline().addLast(PCEPDispatcherImpl.this.hf.getDecoders());
53 ch.pipeline().addLast("negotiator", PCEPDispatcherImpl.this.snf.getSessionNegotiator(listenerFactory, ch, promise));
54 ch.pipeline().addLast(PCEPDispatcherImpl.this.hf.getEncoders());