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 java.io.IOException;
11 import java.net.InetSocketAddress;
13 import org.opendaylight.protocol.framework.Dispatcher;
14 import org.opendaylight.protocol.framework.ProtocolServer;
15 import org.opendaylight.protocol.pcep.PCEPConnection;
16 import org.opendaylight.protocol.pcep.PCEPConnectionFactory;
17 import org.opendaylight.protocol.pcep.PCEPDispatcher;
18 import org.opendaylight.protocol.pcep.PCEPSession;
19 import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
22 * Implementation of PCEPDispatcher.
24 public class PCEPDispatcherImpl implements PCEPDispatcher {
25 public static final int DEFAULT_MAX_UNKNOWN_MSG = 5;
27 private int maxUnknownMessages = DEFAULT_MAX_UNKNOWN_MSG;
29 private final Dispatcher dispatcher;
31 private final PCEPSessionProposalFactory proposalFactory;
34 * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
36 * @throws IOException if some error occurred during opening the selector
38 public PCEPDispatcherImpl(final Dispatcher dispatcher, final PCEPSessionProposalFactory proposalFactory) {
39 this.dispatcher = dispatcher;
40 this.proposalFactory = proposalFactory;
44 public ProtocolServer createServer(final InetSocketAddress address, final PCEPConnectionFactory connectionFactory) throws IOException {
45 connectionFactory.setProposal(this.proposalFactory, address, 0);
46 return this.dispatcher.createServer(address, connectionFactory, new PCEPSessionFactoryImpl(this.maxUnknownMessages));
50 * Create client is used for mock purposes only.
53 public PCEPSession createClient(final PCEPConnection connection) throws IOException {
54 return (PCEPSession) this.dispatcher.createClient(connection, new PCEPSessionFactoryImpl(this.maxUnknownMessages));
58 public void setMaxUnknownMessages(final int limit) {
59 this.maxUnknownMessages = limit;
62 public int getMaxUnknownMessages() {
63 return this.maxUnknownMessages;
66 public Dispatcher getDispatcher() {
67 return this.dispatcher;