This section provides detailed information about the Java example applications provided with the 5800 system client SDK.
Included with the 5800 system SDK are several command-line example applications that demonstrate the Java API. The example applications are located in the SDK in the java/examples directory. These example applications come complete with a build script.
The Java example applications require at minimum the JDK™ 5.0 software.
For Windows 2003, add C:\Program Files\Java\jdk version\bin to the PATH environment variable.
UNIX (.sh) and Windows (.bat) scripts for running the example applications are provided in the java/scripts/ directory. These scripts must be run from the java/scripts/ directory. The scripts illustrate the CLASSPATH environment variable required. The .jar files are in the java/lib/ directory.
The usage messages printed by the applications omit the CLASSPATH environment variable for the sake of readability. If you are running the example application without using the provided scripts, then you must set the CLASSPATH environment variable manually.
To build the Java example applications, go to the java/examples/ directory and execute the master-build.sh script for Solaris and Linux environments or the master-build.bat script for Windows environments. These scripts build the examples and put them in the honeycomb-sdk.jar archive located in the java/lib directory.
Once you have built the Java example applications, go to the java/scripts directory and execute the .sh scripts for Solaris and Linux environments or .bat scripts for Windows environments:
Syntax: script_name arguments
See the scripts for details of how the applications are run.
The Java example applications are all simple applications that follow the same basic structure. First, Commandline.parse is called to parse the argument list. Next, the appropriate method in the NameValueObjectArchive class is called to communicate with the 5800 system server. Finally, output is delivered back to either standard output, a file, or both. Refer to the comments in the sample code for further details.
The following sections describe the Java example applications that are included with the 5800 system client SDK:
Stores a file and associated metadata to a 5800 system server.
java StoreFile <IP | HOST> <FILE> [OPTIONS]
Stores a file and its associated metadata record. If no -m options are specified, a metadata record without user content is generated. The OID of the metadata record is printed to stdout.
StoreFile interprets the time in metadata arguments as local time zone unless the T..Z format indicating UTC is used. For example, 1952-10-27T00:30:29.999Z.
-m <name>=<value>
Any number of -m options can be specified. Each -m option specifies a single (name,value) pair.
<name> should be specified in the format <namespace>.<attribute>. Use double quotes if <value> is a string containing spaces.
-h
Print this message.
java StoreFile 10.152.0.12 myFile java StoreFile server myFile.jpg \ -m filesystem.mimetype="image/jpeg" java StoreFile server myFile \ -m system.test.type_char="do re mi" java StoreFile server myFile \ -m system.test.type_string="fa so la" java StoreFile server myFile \ -m system.test.type_long=123 java StoreFile server myFile \ -m system.test.type_double=1.23 java StoreFile server myFile \ -m system.test.type_binary=0789abcdef java StoreFile server myFile \ -m system.test.type_date=2010-10-20 java StoreFile server myFile \ -m system.test.type_time=23:30:29 java StoreFile server myFile \ -m system.test.type_timestamp="2010-10-20 23:30:29.999" java StoreFile server myFile \ -m name1=value1 -m name2="value 2"
java/examples/StoreFile.java
Ensure an object is queryable. Checks if the metadata for an object is present in the query engine, and inserts the metadata if it is not present.
java CheckIndexed <IP | HOST> <OID> [OPTIONS]
Check with the 5800 systemserver to determine if the specified OID has become queryable. If not, attempt to make it queryable.
A short message about the supplied OID is printed to stdout:
Object OID was already queryable. Object OID not yet queryable. Object OID has now been made queryable. |
-h
Print this message.
java CheckIndexed server \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000 java CheckIndexed 10.152.0.12 \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000
java/examples/CheckIndex.java
Retrieves data from a 5800 system server.
java RetrieveData <IP | HOST> <OID> [FILE] [OPTIONS]
Retrieves data from the 5800 system. The OID specifies what data to retrieve. Data is written to FILE, if specified, otherwise to stdout.
-h
Print this message.
java RetrieveData archivehost \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000 \ /archive/log.1 java RetrieveData 10.152.0.12 \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000 \ /archive/log.2
java/examples/RetrieveData.java
Retrieves data (and metadata) from a specified 5800 system server.
RetrieveMetadata always displays the time in the time zone of the shell running the program.
java RetrieveMetadata <IP | HOST> <OID> [OPTIONS]
Retrieves a data record and metadata from the 5800 system server. The metadata record identified by the supplied OID is printed to stdout.
-h
Print this message.
java RetrieveMetadata 10.152.0.12 \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000
java/examples/RetrieveMetadata.java
Adds a metadata record to an already stored object.
java AddMetadata <IP | HOST> <OID> [OPTIONS]
Adds a new metadata record to an existing data object.
-m <name>=<value>
Any number of -m options can be specified. Each option specifies a single (name, value) pair.
<name> should be specified in the format <namespace>.<attribute>. Use double quotes if <value> is a string containing spaces.
-h
Print this message.
java AddMetadata server \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m filesystem.mimetype="image/jpeg" java AddMetadata server \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m system.test.type_char="do re mi" java AddMetadata server 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m system.test.type_string="fa so la" java AddMetadata server 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m system.test.type_long=123 java AddMetadata server 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m system.test.type_double=1.23 java AddMetadata server 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m system.test.type_date=1952-10-27 java AddMetadata server \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m system.test.type_time=23:30:29 java AddMetadata server \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m system.test.type_timestamp="1952-10-27 23:30:29.999" java AddMetadata server \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000@ \ -m name1=value1 -m name2="value 2"
java/examples/AddMetadata.java
Deletes the Sun 5800 system metadata record associated with an OID.
java DeleteRecord <IP | Host> <OID> [OPTIONS]
Deletes the record with the specified OID. If this record is the only record pointing to the data, the data will also be deleted.
-v
Print deleted OID to stdout.
-h
Print this message.
java DeleteRecord server \ 0200004f75ee01094cc13e11dbbad000e08159832d000024d40200000000
java/examples/DeleteRecord.java
Queries a 5800 system server for metadata records that match the query string passed on the command line.
Query requires the T..Z UTC format. For example, 1952-10-27T00:30:29.999Z.
java Query <IP | HOST> <QUERY> [OPTIONS]
Queries for metadata records. QUERY is of the form:
<name1>=’<value1>’ AND <name2>=’<value2>’ OR ...
See the examples below for formatting of various types of values. The OID and any specified fields of metadata records that match the query are printed to stdout.
<name> should be specified in the format <namespace>.<attribute>.
Note that names that are keywords need to be enclosed in escaped double quotes ("\"<name>\"=’<value>’"). Refer to the list of keywords in Chapter 4, Sun StorageTek 5800 System Query Language, in Sun StorageTek 5800 System Client API Reference Guide. Also note that some shells such as csh might not accept the escaped quotes because they are embedded in other quotes.
-s <FIELD>
Specifies a field to be retrieved, much like an SQL select clause. To retrieve multiple fields, repeat this option. By default, the results are returned as a list of OIDs.
-n <number of results>
The maximum number of metadata records or OIDs that will be returned. The default is 1000.
-h
Print this message.
In the following examples, “first” is a keyword.
java Query server "book.author=’King’" java Query server "\"first\"=’a’" java Query 10.152.0.12 "mp3.artist=’The Beatles’ AND mp3.album=’Abbey Road’" java Query 10.152.0.12 "mp3.artist=’The Beatles’" -s mp3.album -s mp3.title java Query 10.152.0.12 system.test.type_char="’do re mi’" java Query 10.152.0.12 system.test.type_string="’fa so la’" java Query 10.152.0.12 system.test.type_long=123 java Query 10.152.0.12 system.test.type_double=1.23 java Query 10.152.0.12 system.test.type_binary="x’0789abcdef’" java Query 10.152.0.12 system.test.type_date="’2010-10-20’" java Query 10.152.0.12 system.test.type_time="’23:30:29’" java Query 10.152.0.12 system.test.type_timestamp="{timestamp’2010-10-20T23:30:29.123Z’}"
java/examples/Query.java
Returns the schema defined on a 5800 system server to standard output.
java RetrieveSchema [OPTIONS] <IP | HOST>
Retrieves the metadata schema from a 5800 system server, printing it to stdout.
-h
Print this message.
java RetrieveSchema archivehost
java/examples/RetrieveSchema.java
Gets the date.
java GetDate <IP | HOST> [OPTIONS]
Gets the current date used to compute time setting and checking during store and delete operations.
-h
Print this message.
java GetDate server
java/examples/GetDate.java