2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.bgpmanager.thrift.client.implementation;
11 import java.io.IOException;
12 import java.net.Socket;
13 import java.net.SocketException;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
17 public class BgpSyncHandle {
18 private static BgpSyncHandle handle = null;
19 private static final Logger LOGGER = LoggerFactory.getLogger(BgpSyncHandle.class);
23 public static final int INITED = 1;
24 public static final int ITERATING = 2;
25 public static final int DONE = 3;
26 public static final int ABORTED = 4;
27 public static final int NEVER_DONE = 5;
29 public static final int DEFAULT_TCP_SOCK_SZ = 87380; //default receive buffer size on linux > 2.4
31 private BgpSyncHandle() {
36 public static synchronized BgpSyncHandle getInstance() {
38 handle = new BgpSyncHandle();
43 public synchronized int getState() {
47 public int getMaxCount() {
48 //compute the max count of routes we would like to send
49 Socket skt = new Socket();
50 int sockBufSz = DEFAULT_TCP_SOCK_SZ;
52 sockBufSz = skt.getReceiveBufferSize();
53 } catch (SocketException s) {
54 LOGGER.warn("Socket Exception while retrieving default socket buffer size");
58 } catch (IOException e) {
59 LOGGER.warn("IO Exception while closing socket for retrieving default socket buffer size");
61 return sockBufSz/getRouteSize();
64 public int getRouteSize() {
65 //size of one update structure on the wire. ideally
66 //this should be computed; or thrift sure has a nice
67 //way to tell this to the applciation, but for the
68 //moment, we just use 8 bytes more than the size of
74 public int setState(int state) {
75 int retval = this.state;
80 public int setMore(int more) {
81 int retval = this.more;