GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing docs.voltdb.com — Appendix B. Using the Original VoltDB Client Interface Upgrade GuideAppendix B. Using the Original VoltDB Client InterfaceVolt Active Data has two Java client programming interfaces: Client and Client2. Client2 is a modern API using the best features and design patterns of the Java programming language. Client is the original client API. Because of the improvements made to Client2, Client2 is recommended for all new application development and is featured in the documentation. However, the original Client API is still supported and in use in a number of existing customer applications. Which is why this appendix is provided for anyone needing to support applications that use the original Client API. The following sections explain how to use the original VoltDB Java client interface for runtime access to VoltDB databases and functions. Please see the Using VoltDB guide for information on writing new applications using the Client2 API. B.1. Connecting to the VoltDB DatabaseThe first task for the calling program is to create a connection to the VoltDB database. You do this with the following steps: org.voltdb.client.Client client = null;
ClientConfig config = null;
try {
config = new ClientConfig("advent","xyzzy");
When you are done with the connection, you should make sure your application calls the B.1.1. Connecting to Multiple ServersYou can create the connection to any of the nodes in the database cluster and your stored procedure will be routed appropriately. In fact, you can create connections to multiple nodes on the server and your subsequent requests will be distributed to the various connections. For example, the following Java code creates the client object and then connects to all three nodes of the cluster. In this case, security is not enabled so no client configuration is needed: try {
client = ClientFactory.createClient();
client.createConnection("server1.xyz.net");
client.createConnection("server2.xyz.net");
client.createConnection("server3.xyz.net");
} catch (java.io.IOException e) {
e.printStackTrace();
System.exit(-1);
}Creating multiple connections has three major benefits:
B.1.2. Using the Auto-Connecting ClientAn easier way to create connections to all of the database servers is to use the "smart" or topology-aware client. By setting the Java client to be aware of the cluster topology, you only need to connect to one server and the client automatically connects to all of the servers in the cluster. An additional advantage of the smart client is that it will automatically reconnect whenever the topology changes. That is, if a server fails and then rejoins the cluster, or new nodes are added to the cluster, the client will automatically create connections to the newly available servers. You enable auto-connecting when you initialize the client object by setting the configuration option before creating the client object. For example: org.voltdb.client.Client client = null;
ClientConfig config = new ClientConfig("","");
config.setTopologyChangeAware(true);
try {
client = ClientFactory.createClient(config);
client.createConnection("server1.xyz.net");
. . .When | ||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |