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 io.netty.channel.ChannelFuture;
11 import io.netty.channel.socket.SocketChannel;
12 import io.netty.util.concurrent.Promise;
14 import java.io.IOException;
15 import java.net.InetSocketAddress;
17 import org.opendaylight.protocol.framework.AbstractDispatcher;
18 import org.opendaylight.protocol.framework.SessionListenerFactory;
19 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
20 import org.opendaylight.protocol.pcep.PCEPDispatcher;
21 import org.opendaylight.protocol.pcep.PCEPMessage;
22 import org.opendaylight.protocol.pcep.PCEPSessionListener;
24 import com.google.common.base.Preconditions;
27 * Implementation of PCEPDispatcher.
29 public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher {
31 private final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf;
33 private final PCEPHandlerFactory hf = new PCEPHandlerFactory();
36 * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
38 * @throws IOException if some error occurred during opening the selector
40 public PCEPDispatcherImpl(final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory) {
42 this.snf = Preconditions.checkNotNull(negotiatorFactory);
46 public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
47 return super.createServer(address, listenerFactory);
51 public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise,
52 final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
53 ch.pipeline().addLast(this.hf.getDecoders());
54 ch.pipeline().addLast("negotiator", this.snf.getSessionNegotiator(listenerFactory, ch, promise));
55 ch.pipeline().addLast(this.hf.getEncoders());