BUG-58: refactor to take advantage of netty
[bgpcep.git] / pcep / impl / src / main / java / org / opendaylight / protocol / pcep / impl / PCEPDispatcherImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.pcep.impl;
9
10 import io.netty.channel.ChannelFuture;
11 import io.netty.util.concurrent.Future;
12
13 import java.io.IOException;
14 import java.net.InetSocketAddress;
15 import java.util.concurrent.ExecutionException;
16
17 import org.opendaylight.protocol.framework.Dispatcher;
18 import org.opendaylight.protocol.framework.ReconnectStrategy;
19 import org.opendaylight.protocol.framework.SessionListenerFactory;
20 import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
21 import org.opendaylight.protocol.pcep.PCEPDispatcher;
22 import org.opendaylight.protocol.pcep.PCEPMessage;
23 import org.opendaylight.protocol.pcep.PCEPSession;
24 import org.opendaylight.protocol.pcep.PCEPSessionListener;
25
26 /**
27  * Implementation of PCEPDispatcher.
28  */
29 public class PCEPDispatcherImpl implements PCEPDispatcher {
30         private static final PCEPMessageFactory msgFactory = new PCEPMessageFactory();
31         private final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf;
32         private final Dispatcher dispatcher;
33
34         /**
35          * Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
36          * 
37          * @throws IOException if some error occurred during opening the selector
38          */
39         public PCEPDispatcherImpl(final Dispatcher dispatcher, final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf) {
40                 this.dispatcher = dispatcher;
41                 this.snf = snf;
42         }
43
44         @Override
45         public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
46                 return this.dispatcher.createServer(address, listenerFactory, snf, msgFactory);
47         }
48
49         /**
50          * Create client is used for mock purposes only.
51          * 
52          * @throws ExecutionException
53          * @throws InterruptedException
54          */
55         @Override
56         public Future<? extends PCEPSession> createClient(final InetSocketAddress address, final PCEPSessionListener listener, final ReconnectStrategy strategy) {
57                 return this.dispatcher.createClient(address, listener, snf, msgFactory, strategy);
58         }
59 }