1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
23 DbRetVal
NetworkTable::initialize()
26 if (!Conf::config
.useReplication() && !Conf::config
.useCache()) return OK
;
27 rv
= readNetworkConfig();
31 NetworkTable::~NetworkTable()
35 DbRetVal
NetworkTable::readNetworkConfig()
39 char hostname
[IDENTIFIER_LENGTH
];
41 fp
= fopen(Conf::config
.getReplConfigFile(),"r");
43 printError(ErrSysInit
, "Invalid path/filename for NETWORK_CONFIG_FILE.\n");
51 printError(ErrNotYet
, "Only 2 hosts are allowed in this version");
54 printDebug(DM_Network
, "Count is %d\n", count
);
55 fscanf(fp
, "%d:%d:%s\n", &nwid
, &port
, hostname
);
56 printDebug(DM_Network
, "%d:%d:%s\n", nwid
, port
, hostname
);
57 NetworkClient
* nClient
;
58 if (nwid
== Conf::config
.getNetworkID()) continue;
60 nClient
= NetworkFactory::createClient(TCP
);
62 printDebug(DM_Network
, "nwid %d getCacheNetworkID %d\n", nwid
, Conf::config
.getCacheNetworkID());
63 if (nwid
== Conf::config
.getCacheNetworkID()) nClient
->setCacheClient();
64 nClient
->setHost(hostname
, port
, nwid
);
73 //connect to peer hosts
74 DbRetVal
NetworkTable::connect()
76 DbRetVal rv
= nwClient
->connect();
78 printError(ErrOS
, "Unable to connect to peer %d\n", nwClient
->getNetworkID());
79 nwClient
->setConnectFlag(false);
83 DbRetVal
NetworkTable::connectIfNotConnected()
86 if (!nwClient
->isConnected()) rv
= nwClient
->connect(); else rv
=ErrAlready
;
89 //disconnect from all hosts in the table
90 DbRetVal
NetworkTable::disconnect()
92 if (nwClient
->isConnected()) {
93 nwClient
->disconnect();