Hector is a high-level client
API
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how to build ...
for
Apache Cassandra
Apache Cassandra is a free and open-source software, free and open-source database management system designed to handle large volumes of data across multiple Commodity computing, commodity servers. The system prioritizes availability and scalab ...
. Named after
Hector
In Greek mythology, Hector (; , ) was a Trojan prince, a hero and the greatest warrior for Troy during the Trojan War. He is a major character in Homer's ''Iliad'', where he leads the Trojans and their allies in the defense of Troy, killing c ...
, a warrior of
Troy
Troy (/; ; ) or Ilion (; ) was an ancient city located in present-day Hisarlik, Turkey. It is best known as the setting for the Greek mythology, Greek myth of the Trojan War. The archaeological site is open to the public as a tourist destina ...
in
Greek mythology
Greek mythology is the body of myths originally told by the Ancient Greece, ancient Greeks, and a genre of ancient Greek folklore, today absorbed alongside Roman mythology into the broader designation of classical mythology. These stories conc ...
, it is a substitute for the Cassandra Java Client, or Thrift,
that is encapsulated by Hector. It also has
Maven
MAVEN is a NASA spacecraft orbiting Mars to study the loss of that planet's atmospheric gases to space, providing insight into the history of the planet's climate and water. The name is an acronym for "Mars Atmosphere and Volatile Evolution" w ...
repository access.
History
As Cassandra is shipped with the low-level
Thrift (protocol), there was a potential to develop a better protocol for application developers. Hector was developed by Ran Tavory as a high-level interface that overlays the shortcomings of Thrift. It is licensed with the MIT License that allows to use, modify, split and change the design.
Features
The high-level features of Hector are
* A high-level object oriented interface to Cassandra: It is mainly inspired by the Cassandra-java-client. The API is defined in the Keyspace interface.
* Connection pooling. As in high-scale applications, the usual pattern for
DAO
The Tao or Dao is the natural way of the universe, primarily as conceived in East Asian philosophy and religion. This seeing of life cannot be grasped as a concept. Rather, it is seen through actual living experience of one's everyday being. T ...
s is a large number of reads/writes. It is too expensive for clients to open new connections with each request. So, a client may easily run out of available sockets, if it operates fast enough. Hector provides connection pooling and a nice framework that manages the details.
* Failover support: As Cassandra is a distributed data store where hosts (
''nodes'') may go down. Hector has its own
failover policy.
*
JMX support: Hector exposes JMX for many important runtime metrics, such as number of available connections, idle connections, error statistics.
*
Load balancing: A simple load balancing exists in the newer version.
* Supports the command design pattern to allow clients to concentrate on their business logic and let Hector take care of the required plumbing.
Availability metrics
Hector exposes availability counters and statistics through
JMX.
Load balancing
Hector follows two load balancing policies with the
LoadBalancingPolicy
interface. The default is called
RoundRobinBalancingPolicy
and is a simple
round-robin distribution algorithm. The
LeastActiveBalancingPolicy
routes requests to the pools having the lowest number of active connections, ensuring a good spread of utilisation across the cluster. .
Pooling
The
ExhaustedPolicy
determines how the underlying client connection pools are controlled. Currently, three options are available:
Code examples
As an example, an implementation of a simple distributed
hashtable
In computer science, a hash table is a data structure that implements an associative array, also called a dictionary or simply map; an associative array is an abstract data type that maps keys to values. A hash table uses a hash function to ...
over Cassandra is listed.
/**
* Insert a new value keyed by key
* @param key Key for the value
* @param value the String value to insert
*/
public void insert(final String key, final String value) throws Exception
/**
* Get a string value.
* @return The string value; null if no value exists for the given key.
*/
public String get(final String key) throws Exception
/**
* Delete a key from cassandra
*/
public void delete(final String key) throws Exception
References
External links
Apache ThriftHector on githubThe Cassandra Java client
{{DEFAULTSORT:Hector (Api)
Distributed computing
Distributed data stores
Java (programming language)