Package org.jdesktop.wonderland.sessionid.client

Source Code of org.jdesktop.wonderland.sessionid.client.ClientMain

/**
* Project Wonderland
*
* Copyright (c) 2004-2009, Sun Microsystems, Inc., All Rights Reserved
*
* Redistributions in source code form must reproduce the above
* copyright and this condition.
*
* The contents of this file are subject to the GNU General Public
* License, Version 2 (the "License"); you may not use this file
* except in compliance with the License. A copy of the License is
* available at http://www.opensource.org/licenses/gpl-license.php.
*
* Sun designates this particular file as subject to the "Classpath"
* exception as provided by Sun in the License file that accompanied
* this code.
*/
package org.jdesktop.wonderland.sessionid.client;

import java.math.BigInteger;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;
import org.jdesktop.wonderland.client.comms.BaseConnection;
import org.jdesktop.wonderland.client.comms.LoginParameters;
import org.jdesktop.wonderland.client.comms.WonderlandServerInfo;
import org.jdesktop.wonderland.client.comms.WonderlandSession;
import org.jdesktop.wonderland.client.comms.WonderlandSessionImpl;

/**
* Simple client
* @author jkaplan
*/
public class ClientMain {
    public static final int CLIENT_COUNT = 10;
   
    /** logger */
    private static final Logger logger =
            Logger.getLogger(ClientMain.class.getName());
   
    // the server info
    private WonderlandServerInfo serverInfo;
   
    // whether we are done
    boolean finished = false;

    /**
     * Create a new client
     * @param serverInfo the information about the server
     */
    public ClientMain(WonderlandServerInfo serverInfo) {
        this.serverInfo = serverInfo;
    }

    /**
     * Run the test
     */
    public void runTest() throws Exception {
        // read the username and properties from files
        String username = System.getProperty("sgs.user", "sample");
        String password = System.getProperty("sgs.password", "sample");

        Set<BigInteger> ids = new HashSet<BigInteger>();
       
        for (int i = 0; i < CLIENT_COUNT; i++) {
            // create the first session & login
            WonderlandSession session = new WonderlandSessionImpl(serverInfo);
            session.login(new LoginParameters(username, password.toCharArray()));
       
            logger.info("Login with id " + session.getID());
           
            assert session.getID() != null : "Session ID is null";
            assert !ids.contains(session.getID()) : "Duplicate id " + session.getID();
           
            ids.add(session.getID());
        }
      
        // test is finished
    }
   
    public static void main(String[] args) {
        // read server and port from properties
        String server = System.getProperty("sgs.server", "locahost");
        int port = Integer.parseInt(System.getProperty("sgs.port", "1139"));

        // create a login information object
        WonderlandServerInfo serverInfo = new WonderlandServerInfo(server, port);

        // the main client
        ClientMain cm = new ClientMain(serverInfo);

        try {
            cm.runTest();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
TOP

Related Classes of org.jdesktop.wonderland.sessionid.client.ClientMain

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.