Remove unused parameters
[netvirt.git] / bgpmanager / impl / src / main / java / org / opendaylight / netvirt / bgpmanager / thrift / client / BgpSyncHandle.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.netvirt.bgpmanager.thrift.client;
10
11 import java.io.IOException;
12 import java.net.Socket;
13 import java.net.SocketException;
14 import java.util.concurrent.atomic.AtomicInteger;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 public class BgpSyncHandle {
19     private static final Logger LOG = LoggerFactory.getLogger(BgpSyncHandle.class);
20
21     public static final int INITED = 1;
22     public static final int ITERATING = 2;
23     public static final int DONE = 3;
24     public static final int ABORTED = 4;
25     public static final int NEVER_DONE = 5;
26
27     public static final int DEFAULT_TCP_SOCK_SZ = 87380;    //default receive buffer size on linux > 2.4
28
29     private final AtomicInteger state = new AtomicInteger(NEVER_DONE);
30
31     public int getState() {
32         return state.get();
33     }
34
35     public int getMaxCount() {
36         //compute the max count of routes we would like to send
37         Socket skt = new Socket();
38         int sockBufSz = DEFAULT_TCP_SOCK_SZ;
39         try {
40             sockBufSz = skt.getReceiveBufferSize();
41         } catch (SocketException s) {
42             LOG.warn("Socket Exception while retrieving default socket buffer size");
43         }
44         try {
45             skt.close();
46         } catch (IOException e) {
47             LOG.warn("IO Exception while closing socket for retrieving default socket buffer size");
48         }
49         return sockBufSz / getRouteSize();
50     }
51
52     public int getRouteSize() {
53         //size of one update structure on the wire. ideally
54         //this should be computed; or thrift sure has a nice
55         //way to tell this to the applciation, but for the
56         //moment, we just use 8 bytes more than the size of
57         //the C struct.
58
59         return 96;
60     }
61
62     public int setState(int newState) {
63         return this.state.getAndSet(newState);
64     }
65 }