当前位置: 首页>>代码示例>>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;未经允许,请勿转载。