e00515f3fe18631ff0380237f23758b07ff57e18
[vpnservice.git] / bgpmanager / bgpmanager-impl / src / main / java / org / opendaylight / bgpmanager / thrift / client / implementation / BgpSyncHandle.java
1
2 package org.opendaylight.bgpmanager.thrift.client.implementation;
3
4 import java.io.IOException;
5 import java.net.Socket;
6 import java.net.SocketException;
7
8 public class BgpSyncHandle {
9     private static BgpSyncHandle handle = null;
10     private int more;
11     private int state;
12
13     public static final int INITED = 1;
14     public static final int ITERATING = 2;
15     public static final int DONE = 3;
16     public static final int ABORTED = 4;
17     public static final int NEVER_DONE = 5;
18
19     public static final int default_tcp_sock_sz = 87380;    //default receive buffer size on linux > 2.4 (SLES 11)
20
21     private BgpSyncHandle() {
22         more = 1; 
23         state = NEVER_DONE;
24     }
25
26     public static synchronized BgpSyncHandle getInstance() {
27        if (handle == null) 
28            handle = new BgpSyncHandle();
29        return handle;
30     }
31
32     public synchronized int getState() {
33        return state;
34     }
35
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;
40         try {
41             sockBufSz = skt.getReceiveBufferSize();
42         } catch (SocketException s) {
43         }
44         try {
45             skt.close();
46         } catch (IOException e) {
47         }
48         return sockBufSz/getRouteSize();
49     }
50
51     public int getRouteSize() {
52        //size of one update structure on the wire. ideally
53        //this should be computed; or thrift sure has a nice
54        //way to tell this to the applciation, but for the
55        //moment, we just use 8 bytes more than the size of 
56        //the C struct. 
57
58        return 96;
59     }
60
61     public int setState(int state) {
62        int retval = this.state;
63        this.state = state;
64        return retval;
65     }
66
67     public int setMore(int more) {
68        int retval = this.more;
69        this.more = more;
70        return retval;
71     }
72 }
73
74         
75