Integration Toolbox
for IBM® TIVOLI® Storage Manager

package connect_disconnect; import hu.user.toolbox.tsm.ConnectionOptions; import hu.user.toolbox.tsm.ITSMSession; import hu.user.toolbox.tsm.Toolbox; import hu.user.toolbox.tsm.exception.TSMException; import hu.user.toolbox.tsm.exception.ToolboxException; import hu.user.toolbox.tsm.internal.structures.TsmReturnCodes; /** * <b>Function:</b><br> * Demonstrates how to connect and start a session with the TSM server and how * to disconnect and clean up the resources with the <i>PASSWORDACCESS</i> option set to <i>GENERATE</i>. * <p> * The following operations are performed: * <ol> * <li>Initializing a single-threaded TSM API environment.</li> * <li>Creating a new TSMSession instance. Setting custom connection options. * Connecting to the server without node name and password.</li> * <li>Disconnecting from the server and cleaning up the resources.</li> * </ol> * <p> * <b>Compile:</b> * <pre> * javac -d bin -cp ../lib/toolboxfortsm.jar * connect_disconnect/ConnectDisconnectWithPasswordAccessGenerate.java * </pre> * <p> * <b>Execute:</b><br> * You should first set the environment variables to point to the correct * files/directories. * <pre> * set DSMI_CONFIG={Full path of your dsm.opt} * set DSMI_DIR={Tivoli Storage Manager API installation directory} * set DSMI_LOG={Any arbitrary directory} * </pre> * Then use the java command to execute the program: * <p> * <pre> * java -cp bin:../lib/toolboxfortsm.jar:../lib/ext/log4j-1.2.17.jar:../config * -Djava.library.path=../lib connect_disconnect.ConnectDisconnectWithPasswordAccessGenerate * </pre> */ public class ConnectDisconnectWithPasswordAccessGenerate { private static final String CONFIG_FILE = "inputs/dsm_pwaccess_generate.opt"; private static final String PASSWORD = "password"; public static void main(final String args[]) throws ToolboxException { ITSMSession session = null; try { // Initializing a single-threaded environment Toolbox.initSingleThreading(); // Connecting to the server with custom connection options ConnectionOptions connectionOptions = new ConnectionOptions(); connectionOptions.setConfigFile(CONFIG_FILE); session = Toolbox.createSession(connectionOptions); System.out.println("Connecting successful."); } catch (ToolboxException e) { Throwable cause = e.getCause(); if (cause instanceof TSMException && ((TSMException) cause).getReturnCode() == TsmReturnCodes.DSM_RC_NO_PASS_FILE) { System.out.println("No password file, generating one."); ConnectionOptions connectionOptions = new ConnectionOptions(); connectionOptions.setConfigFile(CONFIG_FILE); connectionOptions.setPassword(PASSWORD); session = Toolbox.createSession(connectionOptions); } else { e.printStackTrace(); } } finally { // Disconnecting session.disconnect(); System.out.println("Disconnecting successful."); // Cleaning up the environment Toolbox.cleanUp(); } } }