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 ***************************************************************************/
24 DbRetVal
NetworkTable::initialize()
27 //if (!Conf::config.useReplication() && !Conf::config.useCache()) return OK;
28 rv
= readNetworkConfig();
32 NetworkTable::~NetworkTable()
36 DbRetVal
NetworkTable::readNetworkConfig()
40 char hostname
[IDENTIFIER_LENGTH
];
42 //fp = fopen(Conf::config.getReplConfigFile(),"r");
44 printError(ErrSysInit
, "Invalid path/filename for NETWORK_CONFIG_FILE.\n");
52 printError(ErrNotYet
, "Only 2 hosts are allowed in this version");
55 printDebug(DM_Network
, "Count is %d\n", count
);
56 fscanf(fp
, "%d:%d:%s\n", &nwid
, &port
, hostname
);
57 printDebug(DM_Network
, "%d:%d:%s\n", nwid
, port
, hostname
);
58 NetworkClient
* nClient
;
59 //if (nwid == Conf::config.getNetworkID()) continue;
61 nClient
= NetworkFactory::createClient(TCP
);
63 //printDebug(DM_Network, "nwid %d getCacheNetworkID %d\n", nwid, Conf::config.getCacheNetworkID());
64 //if (nwid == Conf::config.getCacheNetworkID()) nClient->setCacheClient();
65 nClient
->setHost(hostname
, port
, nwid
);
74 //connect to peer hosts
75 DbRetVal
NetworkTable::connect()
77 DbRetVal rv
= nwClient
->connect();
79 printError(ErrOS
, "Unable to connect to peer %d\n", nwClient
->getNetworkID());
80 nwClient
->setConnectFlag(false);
84 DbRetVal
NetworkTable::connectIfNotConnected()
87 if (!nwClient
->isConnected()) rv
= nwClient
->connect(); else rv
=ErrAlready
;
90 //disconnect from all hosts in the table
91 DbRetVal
NetworkTable::disconnect()
93 if (nwClient
->isConnected()) {
94 nwClient
->disconnect();