package examples.workspace;

import java.net.*;
import java.util.*;
import java.sql.*;
import weblogic.common.*;
import weblogic. workspace.common.*;


/**
 * This short example demonstrates how to extend the workspace life
 * of a T3Client so that the client can disconnect, then reconnect to
 * continue work inside the same workspace. In this example, the
 * system assigns a workspace ID, which the T3Client retrieves for
 * future use.
 * <p>
 *
 *<h3>To set up this example:</h3>
 *<ol>
 *<li>Set up your development shell as described in <a
 *href=../../techstart/environment.html>Setting up your environment</a>.
 *<p>
 *<li>Compile this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ javac -d %CLIENT_CLASSES% t3clientcache1.java</b></font>
 *
 *
 *<p>	
 *<li>Start WebLogic Server in a separate shell.
 *
 *<p>
 *<li>Run this example by executing the following command in your development shell:
 *
 *<p>
 *
 *<font face="Courier New"><b>$ java examples.workspace.t3clientcache1  t3://<i>hostname:port</i></b></font>
 *<p>Where <i>hostname:port</i> is the host name and port number of your WebLogic Server.  
 *</ol>
 * 
 * @author                    Copyright (c) 1996-2000 by BEA Systems, Inc.
 *                            All Rights Reserved.
 */
public class t3clientcache1 {

  /**
  * Runs this example from the command line.
  */
  public static void main(String argv[]) throws Exception  {

    if (argv.length != 1) {
      System.out.println("Usage:   java examples.workspace.datacache WebLogicURL");
      System.out.println("Example: java examples.workspace datacache t3://localhost:7001");
      return;
    }

    String weblogicURL = argv[0];
    
    // Create T3Client, and let the system assign a workspace ID
    T3Client t3 = new T3Client(weblogicURL);
    
    // Connect and set the timeout to be NEVER
    t3.connect()
      .setSoftDisconnectTimeoutMins(T3Client.DISCONNECT_TIMEOUT_NEVER);
    
    // Obtain a WorkspaceDef object to access the default workspace. 

    WorkspaceDef defaultWS = t3.services.workspace().getWorkspace();
    String wsid = defaultWS.getID();

    System.out.println("This client's wsid = " + wsid);
    
    // Disconnect the client. Since the soft disconnect timeout is NEVER,
    // the server will preserve the session.
    t3.disconnect();
    System.out.println("Temporarily disconnecting from workspace " + wsid);
    t3 = null;
    
    // Reconnect using the workspace ID assigned by the system
    t3 = new T3Client(weblogicURL, wsid);
    t3.connect();
    System.out.println("Reconnected client to workspace " + t3.services.workspace().getID());
    
    // Set the timeout internal to 0 to force an immediate disconnect
    // on the server.
    t3.setSoftDisconnectTimeoutMins(0)
      .disconnect();
    System.out.println("Disconnected client " + wsid);
  }
}

