Building a K2 Client

RMI user connections

Java™ RMI connections to a K2 server have more capabilities than their socket-based counterparts, since they're not limited to a simple back-and-forth protocol. These connections are capable of executing multiple queries at once, and can halt execution of queries in progress.

RMI user connections implement the K2 interface RMIUserConnectionI. To get a new connection, first use the lookup method in the java.rmi.Naming class to look up the K2 server, using the RMI URL to which the server is bound (you can get this URL from the K2 server's administrator). This will return an object that implements RMIConnectionFactoryI. You can then use the getUserConnection method to get a connection object. You'll have to pass a new Login object to getUserConnection, which means you'll need a username and password. You can get these from the K2 server's administrator.

Once you have the connection object, you're ready to go. You can execute OQL queries using the executeOQLQuery method, which will return a QueryResultHolder that contains your query's result. The result will be an absynExpA, which you should cast to the type of object you expect back from the query you sent (typically either an absynCollectionA or an absynRecordA). Each object contains accessor methods to allow you to get its child objects, which together provide a means of descending the tree that represents your result.

If your client is multi-threaded you can call executeOQLQuery more than once, thereby executing multiple queries simultaneously. To halt a query in progress, call the halt method. Note that if more than one query is being processed at once, all will be halted. You can read in OQL, ODL, or K2MDL scripts using the readScript method. The getDataSources and getSourceMetaData methods can be used to get metadata for the data sources to which the server is connected. Finally, when you're done, call the close method to close the connection before exiting your program.

The other kind of RMI connection is an administrative connection.

[Tech Docs Index]