forked from axs-mvd/libcassandra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added utility function to ping a cassandra server to see if it is up.
- Loading branch information
Showing
7 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* LibCassandra | ||
* Copyright (C) 2010-2011 Padraig O'Sullivan | ||
* All rights reserved. | ||
* | ||
* Use and distribution licensed under the BSD license. See | ||
* the COPYING file in the parent directory for full text. | ||
*/ | ||
|
||
#ifndef __LIBCASSANDRA_UTIL_H | ||
#define __LIBCASSANDRA_UTIL_H | ||
|
||
#include "libcassandra/util/ping.h" | ||
|
||
#endif /* __LIBCASSANDRA_UTIL_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* LibCassandra | ||
* Copyright (C) 2010-2011 Padraig O'Sullivan | ||
* All rights reserved. | ||
* | ||
* Use and distribution licensed under the BSD license. See | ||
* the COPYING file in the parent directory for full text. | ||
*/ | ||
|
||
#include <string> | ||
#include <sstream> | ||
#include <iostream> | ||
|
||
#include <protocol/TBinaryProtocol.h> | ||
#include <transport/TSocket.h> | ||
#include <transport/TTransportUtils.h> | ||
|
||
#include "libgenthrift/Cassandra.h" | ||
|
||
#include "libcassandra/util/ping.h" | ||
|
||
using namespace std; | ||
using namespace apache::thrift; | ||
using namespace apache::thrift::protocol; | ||
using namespace apache::thrift::transport; | ||
using namespace org::apache::cassandra; | ||
using namespace boost; | ||
|
||
namespace libcassandra | ||
{ | ||
|
||
|
||
bool util::pingCassandraServer(const string& hostname, int port) | ||
{ | ||
try | ||
{ | ||
boost::shared_ptr<TTransport> socket(new TSocket(hostname, port)); | ||
boost::shared_ptr<TTransport> transport= boost::shared_ptr<TTransport>(new TFramedTransport(socket)); | ||
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport)); | ||
CassandraClient client(protocol); | ||
transport->open(); /* throws an exception */ | ||
} | ||
catch (std::exception&) | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
||
} /* end namespace libcassandra */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* LibCassandra | ||
* Copyright (C) 2010-2011 Padraig O'Sullivan | ||
* All rights reserved. | ||
* | ||
* Use and distribution licensed under the BSD license. See | ||
* the COPYING file in the parent directory for full text. | ||
*/ | ||
|
||
#ifndef __LIBCASSANDRA_UTIL_PING_H | ||
#define __LIBCASSANDRA_UTIL_PING_H | ||
|
||
namespace libcassandra | ||
{ | ||
|
||
namespace util | ||
{ | ||
|
||
bool pingCassandraServer(const std::string& hostname, | ||
int port); | ||
|
||
} /* end namespace util */ | ||
|
||
} /* end namespace libcassandra */ | ||
|
||
#endif /* __LIBCASSANDRA_UTIL_PING_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters