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.util.concurrent.Future;
12 import java.io.IOException;
13 import java.net.InetSocketAddress;
14 import java.util.concurrent.ExecutionException;
16 import org.opendaylight.protocol.framework.Dispatcher;
17 import org.opendaylight.protocol.framework.ProtocolServer;
18 import org.opendaylight.protocol.framework.ReconnectStrategy;
19 import org.opendaylight.protocol.pcep.PCEPConnection;
20 import org.opendaylight.protocol.pcep.PCEPConnectionFactory;
21 import org.opendaylight.protocol.pcep.PCEPDispatcher;
22 import org.opendaylight.protocol.pcep.PCEPSession;
23 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
26 * Implementation of PCEPDispatcher.
28 public class PCEPDispatcherImpl implements PCEPDispatcher {
30 public static final int DEFAULT_MAX_UNKNOWN_MSG = 5;
32 private int maxUnknownMessages = DEFAULT_MAX_UNKNOWN_MSG;
34 private final Dispatcher dispatcher;
36 private final PCEPSessionProposalFactory proposalFactory;
39 * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
41 * @throws IOException if some error occurred during opening the selector
43 public PCEPDispatcherImpl(final Dispatcher dispatcher, final PCEPSessionProposalFactory proposalFactory) {
44 this.dispatcher = dispatcher;
45 this.proposalFactory = proposalFactory;
49 public Future<ProtocolServer> createServer(final InetSocketAddress address, final PCEPConnectionFactory connectionFactory) throws IOException {
50 connectionFactory.setProposal(this.proposalFactory, address, 0);
51 return this.dispatcher.createServer(address, connectionFactory, new PCEPSessionFactoryImpl(this.maxUnknownMessages));
55 * Create client is used for mock purposes only.
57 * @throws ExecutionException
58 * @throws InterruptedException
61 public Future<? extends PCEPSession> createClient(final PCEPConnection connection, final ReconnectStrategy strategy) throws IOException {
62 return this.dispatcher.createClient(connection, new PCEPSessionFactoryImpl(this.maxUnknownMessages), strategy);
66 public void setMaxUnknownMessages(final int limit) {
67 this.maxUnknownMessages = limit;
70 public int getMaxUnknownMessages() {
71 return this.maxUnknownMessages;
74 public Dispatcher getDispatcher() {
75 return this.dispatcher;