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


Java Session.setTimeout方法代碼示例

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


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

示例1: openSession

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
protected Session openSession(final ProcessContext context) throws JSchException {
    final JSch jsch = new JSch();
    final String hostKeyVal = context.getProperty(HOST_KEY_FILE).getValue();
    if (hostKeyVal != null) {
        jsch.setKnownHosts(hostKeyVal);
    }

    final Session session = jsch.getSession(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue(),
            context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue(),
            context.getProperty(PORT).evaluateAttributeExpressions().asInteger().intValue());

    final Properties properties = new Properties();
    properties.setProperty("StrictHostKeyChecking", context.getProperty(STRICT_HOST_KEY_CHECKING).asBoolean() ? "yes" : "no");
    properties.setProperty("PreferredAuthentications", "publickey,password,keyboard-interactive");

    final PropertyValue compressionValue = context.getProperty(USE_COMPRESSION);
    if (compressionValue != null && "true".equalsIgnoreCase(compressionValue.getValue())) {
        properties.setProperty("compression.s2c", "[email protected],zlib,none");
        properties.setProperty("compression.c2s", "[email protected],zlib,none");
    } else {
        properties.setProperty("compression.s2c", "none");
        properties.setProperty("compression.c2s", "none");
    }

    session.setConfig(properties);

    final String privateKeyFile = context.getProperty(PRIVATE_KEY_PATH).evaluateAttributeExpressions().getValue();
    if (privateKeyFile != null) {
        jsch.addIdentity(privateKeyFile, context.getProperty(PRIVATE_KEY_PASSPHRASE).evaluateAttributeExpressions().getValue());
    }

    final String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue();
    if (password != null) {
        session.setPassword(password);
    }

    session.setTimeout(context.getProperty(CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue());
    session.connect();
    return session;
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:41,代碼來源:AbstractScpProcessor.java

示例2: create

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
@Override
public Session create(ServerDetails serverDetails) throws Exception {
	Session session = null;
	try {
		JSch jsch = new JSch();
		if (serverDetails.getPrivateKeyLocation() != null) {
			jsch.addIdentity(serverDetails.getPrivateKeyLocation());
		}
		session = jsch.getSession(serverDetails.getUser(), serverDetails.getHost(), serverDetails.getPort());
		session.setConfig("StrictHostKeyChecking", "no"); //
		UserInfo userInfo = new JschUserInfo(serverDetails.getUser(), serverDetails.getPassword());
		session.setUserInfo(userInfo);
		session.setTimeout(60000);
		session.setPassword(serverDetails.getPassword());
		session.connect();
	} catch (Exception e) {
		throw new RuntimeException(
				"ERROR: Unrecoverable error when trying to connect to serverDetails :  "
						+ serverDetails, e);
	}
	return session;
}
 
開發者ID:danielemaddaluno,項目名稱:command4j,代碼行數:23,代碼來源:SessionFactory.java

示例3: connect

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * 連接到服務器
 */
private static Session connect(String host,String user,String pass) throws JSchException{
	JSch sch = new JSch();
	Session session = sch.getSession(user, host, 22);
	session.setPassword(pass);
	Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.setTimeout(60000);
    session.connect();
    return session;
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:15,代碼來源:ScpClient.java

示例4: connect

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * 連接到服務器
 */
private Session connect() throws JSchException{
	JSch sch = new JSch();
	Session session = sch.getSession(user, this.hosts, 22);
	session.setPassword(password);
	Properties config = new Properties();
    config.put("StrictHostKeyChecking", "no");
    session.setConfig(config);
    session.setTimeout(60000);
    session.connect();
    return session;
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:15,代碼來源:ShellClient.java

示例5: openExecChannel

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
protected Channel openExecChannel(final ProcessContext context, final Session session, final String command) throws JSchException {
    ChannelExec channel = (ChannelExec) session.openChannel("exec");
    channel.setCommand(command);

    session.setTimeout(context.getProperty(DATA_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue());
    if (!context.getProperty(USE_KEEPALIVE_ON_TIMEOUT).asBoolean()) {
        session.setServerAliveCountMax(0); // do not send keepalive message on SocketTimeoutException
    }

    return channel;
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:12,代碼來源:AbstractScpProcessor.java

示例6: 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

示例7: connect

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public int connect(String sshTunnelHost, String host, int port, int localPort) {
	Assert.notNull(sshTunnelHost, "sshTunnelHost must not be null");
	Assert.notNull(host, "host must not be null");
	Assert.isTrue(port > 0, "illegal port: " + port);
	Assert.isTrue(localPort >= 0, "illegal local port: " + localPort);

	log.debug("tunneling to {}:{} via {}", host, port, sshTunnelHost);

	try {
		sshConfiguration.addIdentity(sshTunnelHost);

		SshProxyConfig proxyConfig = sshConfiguration.getProxyConfiguration(sshTunnelHost);
		if (proxyConfig == null) {
			return directConnect(sshTunnelHost, host, port, localPort);
		}

		int jumpPort = connect(proxyConfig);

		String hostUser = sshConfiguration.getHostUser(sshTunnelHost);
		String jumpHost = proxyConfig.getJumpHost();
		Session jumpHostSession = sshConfiguration.openSession(hostUser, jumpHost, jumpPort);
		String hostname = sshConfiguration.getHostName(sshTunnelHost);
		jumpHostSession.setHostKeyAlias(hostname);
		sshSessions.push(jumpHostSession);
		jumpHostSession.setTimeout(timeoutMillis);
		jumpHostSession.connect(timeoutMillis);

		log.debug("[{}] connected via {}@localhost:{}", sshTunnelHost, hostUser, jumpPort);

		return addLocalPortForwarding(sshTunnelHost, jumpHostSession, host, port, localPort);
	} catch (Exception e) {
		throw new SshProxyRuntimeException("Failed to create SSH tunnel to " + host + " via " + sshTunnelHost, e);
	}
}
 
開發者ID:cronn-de,項目名稱:ssh-proxy,代碼行數:35,代碼來源:SshProxy.java

示例8: directConnect

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
private int directConnect(String jumpHost, String targetHost, int targetPort, int localPort) throws JSchException {
	Session jumpHostSession = sshConfiguration.openSession(jumpHost);
	sshSessions.add(jumpHostSession);
	jumpHostSession.setTimeout(timeoutMillis);
	try {
		jumpHostSession.connect(timeoutMillis);
	} catch (JSchException e) {
		log.debug("Failed to connect to {} via {}", targetHost, jumpHost, e);
		throw new SshProxyRuntimeException("Failed to connect to " + targetHost + " via " + jumpHost);
	}

	log.debug("[{}] connected", jumpHost);

	return addLocalPortForwarding(jumpHost, jumpHostSession, targetHost, targetPort, localPort);
}
 
開發者ID:cronn-de,項目名稱:ssh-proxy,代碼行數:16,代碼來源:SshProxy.java

示例9: create

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * Connect to remote SSH endpoint specified by {@code url}.
 *
 * @throws JSchException if we fail to open the connection.
 */
JSchSshSession create(JSch jsch, URI uri) throws JSchException {
  RdeUploadUrl url = RdeUploadUrl.create(uri);
  logger.info("Connecting to SSH endpoint: " + url);
  Session session = jsch.getSession(
      url.getUser().orElse("domain-registry"),
      url.getHost(),
      url.getPort());
  if (url.getPass().isPresent()) {
    session.setPassword(url.getPass().get());
  }
  session.setTimeout((int) sshTimeout.getMillis());
  session.connect((int) sshTimeout.getMillis());
  return new JSchSshSession(session, url, (int) sshTimeout.getMillis());
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:20,代碼來源:JSchSshSession.java


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