This sample demonstrates how to create a queue, exposed fields, and an index. Run the sample by entering a command similar to the following:
java SysConfigSample username password <server name>:<port
number>/<router instance name> [output_filename]
Note For a detailed explanation of the command line, see the Run the sample application section of the Run the Unmodified Samples topic.
The SysConfigSample class contains two methods: the main(String args[]) method and the SysConfigSample(VWSession vwSession, Logger logger) method, which is the constructor method.
The main method uses common techniques for validating and defaulting argument values. The default value for the log output file is SysConfigSample.out. The main method constructs and passes vwSession and Loggerobjects to the sample constructor. Main() handles the login and logoff for the session with the login() and logoff() methods of the sample SessionHelper class. It provides workflow logging with an instance of the sample Logger class. The main method passes the session and the logger to the constructor method.
The constructor SysConfigSample(VWSession, Logger) performs common exception handling and demonstrates a variety of system configuration methods. It displays various SysConfig parameters, creates a test queue, adds one exposed field (integer), and adds one index. The code that performs these tasks is organized as follows:
Fetch the system configuration object, sysConfig, using the session object:
sysConfig = vwSession.fetchSystemConfiguration();
Use the system configuration object to get three of the system configuration parameters. Display them with the logger.log method:
logger.log("Logging state = " + sysConfig.getLoggingState());
logger.log("Max DB operations = " + sysConfig.getMaxDBOperations());
logger.log("Max instructions = " + sysConfig.getMaxInstructions());
Create a user-centric test queue:
// Create a test queue; add one exposed field (an integer) and one index.
queueDef = sysConfig.createQueueDefinition("test", VWQueue.QUEUE_TYPE_USER_CENTRIC);
if (queueDef != null){
Add an exposed field ("field1"):
VWExposedFieldDefinition exposedFieldDef = queueDef.createFieldDefinition("field1",
1, 0);
Create the index:
String[] fNames = {new String("field1")};
VWIndexDefinition id = queueDef.createIndexDefinition("index1", fNames);
Inform the user in the log:
logger.log("The queue 'test' was created with one exposed field
('field1') and one index ('index1').");
Commit the system configuration changes:
String[] errors = sysConfig.commit();
Finally, the following code logs what happened:
if (errors != null){
logger.log("Errors: ", errors);
} else
logger.log("All changes have been committed.");
Additional code for SysconfigSample performs common cleanup and exception handling.