當前位置: 首頁>>代碼示例>>Java>>正文


Java Session.setDaemonThread方法代碼示例

本文整理匯總了Java中com.jcraft.jsch.Session.setDaemonThread方法的典型用法代碼示例。如果您正苦於以下問題:Java Session.setDaemonThread方法的具體用法?Java Session.setDaemonThread怎麽用?Java Session.setDaemonThread使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.jcraft.jsch.Session的用法示例。


在下文中一共展示了Session.setDaemonThread方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
@Override
public Session create(ConnectionDetails connectionDetails) throws Exception {
    log.debug("Creating session for "+connectionDetails);
    Session session = null;
    try {
        byte[] privateKey = connectionDetails.getPrivateKey();
        if (privateKey != null) {
            jsch.addIdentity(connectionDetails.getUsername(), privateKey, null, connectionDetails.getPassword().getBytes());
        }
        session = jsch.getSession(connectionDetails.getUsername(), connectionDetails.getHost(), connectionDetails.getPort());
        session.setPassword(connectionDetails.getPassword());
        if (!hostKeyValidation) {
            session.setConfig("StrictHostKeyChecking", "no");
        }
        session.setDaemonThread(true);
        session.connect();
    } catch (Exception e) {
        log.error("Failed to connect to "+connectionDetails);
        throw e;
    }
    return session;
}
 
開發者ID:tilln,項目名稱:jmeter-sshmon,代碼行數:23,代碼來源:SSHSessionFactory.java

示例2: main

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public static void main( String[] args )
{
    String hostname = null;
    int port = 22;
    String username = null;
    String password = null;
    int timeout = 20000;

    Properties config = new java.util.Properties();
    config.put( "StrictHostKeyChecking", "no" );

    for ( int i = 0; i < args.length; i++ )
    {
        if ( args[i].equalsIgnoreCase( "-host" ) )
        {
            hostname = args[i + 1];
            i++;
        }
        else if ( args[i].equalsIgnoreCase( "-port" ) )
        {
            port = Integer.parseInt( args[i + 1] );
            i++;
        }
        else if ( args[i].equalsIgnoreCase( "-username" ) )
        {
            username = args[i + 1];
            i++;
        }
        else if ( args[i].equalsIgnoreCase( "-password" ) )
        {
            password = args[i + 1];
            i++;
        }
    }

    if ( hostname == null )
    {
        logger.error( "Hostname cannot be null." );
    }
    else if ( username == null )
    {
        logger.error( "Username cannot be null." );
    }
    else if ( password == null )
    {
        logger.error( "Password cannot be null." );
    }

    long start = System.currentTimeMillis();
    logger.info( "Start of processing." );
    JSch jsch = new JSch();
    try
    {
        Session session = jsch.getSession( username, hostname, port );
        session.setPassword( password );
        session.setDaemonThread( true );
        session.setConfig( config );
        logger.info( "Session default timeout " + session.getTimeout() );

        session.setTimeout( timeout );
        logger.info( "Session created after " + ( System.currentTimeMillis() - start ) / 1000.0 + " seconds." );
        session.connect();
        logger.info( "Connection established after " + ( System.currentTimeMillis() - start ) / 1000.0
            + " seconds." );
    }
    catch ( JSchException e )
    {
        logger.info( "Connection aborted after " + ( System.currentTimeMillis() - start ) / 1000.0 + " seconds." );
        logger.error( "Received exception.", e );
    }

}
 
開發者ID:vmware,項目名稱:OHMS,代碼行數:73,代碼來源:SshTimer.java

示例3: createJschSession

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
private Session createJschSession() throws JSchException {
	Session session;
	JSch jsch = new JSch();
	session = jsch.getSession(target.getLoginName(), target.getHost(),
			target.getPort());
	session.setConfig("StrictHostKeyChecking", "no");
	session.setPassword(target.getLoginPassword());
	session.setDaemonThread(true);
	session.connect(60000); // making a connection with 60s timeout.
	return session;
}
 
開發者ID:kira8565,項目名稱:JavaExpect,代碼行數:12,代碼來源:SshDriver.java


注:本文中的com.jcraft.jsch.Session.setDaemonThread方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。