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.netvirt.bgpmanager.thrift.client;
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;
18 public class BgpSyncHandle {
19 private static final Logger LOG = LoggerFactory.getLogger(BgpSyncHandle.class);
22 public static final int INITED = 1;
23 public static final int ITERATING = 2;
24 public static final int DONE = 3;
25 public static final int ABORTED = 4;
26 public static final int NEVER_DONE = 5;
28 public static final int DEFAULT_TCP_SOCK_SZ = 87380; //default receive buffer size on linux > 2.4
30 private final AtomicInteger state = new AtomicInteger(NEVER_DONE);
32 public int getState() {
36 public int getMaxCount() {
37 //compute the max count of routes we would like to send
38 Socket skt = new Socket();
39 int sockBufSz = DEFAULT_TCP_SOCK_SZ;
41 sockBufSz = skt.getReceiveBufferSize();
42 } catch (SocketException s) {
43 LOG.warn("Socket Exception while retrieving default socket buffer size");
47 } catch (IOException e) {
48 LOG.warn("IO Exception while closing socket for retrieving default socket buffer size");
50 return sockBufSz / getRouteSize();
53 public int getRouteSize() {
54 //size of one update structure on the wire. ideally
55 //this should be computed; or thrift sure has a nice
56 //way to tell this to the applciation, but for the
57 //moment, we just use 8 bytes more than the size of
63 public int setState(int newState) {
64 return this.state.getAndSet(newState);
67 public int setMore(int localMore) {
68 this.more = localMore;