当前位置: 首页>>代码示例>>Java>>正文


Java Session.setServerAliveInterval方法代码示例

本文整理汇总了Java中com.jcraft.jsch.Session.setServerAliveInterval方法的典型用法代码示例。如果您正苦于以下问题:Java Session.setServerAliveInterval方法的具体用法?Java Session.setServerAliveInterval怎么用?Java Session.setServerAliveInterval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jcraft.jsch.Session的用法示例。


在下文中一共展示了Session.setServerAliveInterval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureSession

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private Session configureSession() {
    try {
        //configure the tunnel
        log.info("Configuring SSH tunnel");
        Session session = jsch.getSession(
                sshDetails.user,
                sshDetails.host,
                sshDetails.sshPort
        );

        jsch.addIdentity(sshDetails.keyFile.getPath(), sshDetails.passphrase);

        final Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        config.put("ConnectionAttempts", "3");
        //dont set the keep alive too low or you might suffer from a breaking connection during start up (for whatever reason)
        session.setServerAliveInterval(1000);//milliseconds
        session.setConfig(config);

        //forward the port
        final int assignedPort = session.setPortForwardingL(
                sshDetails.localPort,
                "localhost",
                sshDetails.remotePort
        );
        log.info("Setting up port forwarding: localhost:" + assignedPort + " -> " + sshDetails.host + ":" + sshDetails.remotePort);

        return session;
    } catch (final JSchException e) {
        throw new RuntimeException("Failed to configure SSH tunnel", e);
    }
}
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:33,代码来源:SshTunnel.java

示例2: startNewSession

import com.jcraft.jsch.Session; //导入方法依赖的package包/类
private Session startNewSession(boolean acquireChannel) throws JSchException, InterruptedException {
    Session newSession = null;
    final AtomicBoolean cancelled = new AtomicBoolean(false);

    ConnectingProgressHandle.startHandle(env, new Cancellable() {
        @Override
        public boolean cancel() {
            cancelled.set(true);
            return true;
        }
    });

    try {
        while (!cancelled.get()) {
            try {
                newSession = jsch.getSession(env.getUser(), env.getHostAddress(), env.getSSHPort());
                int serverAliveInterval = Integer.getInteger("jsch.server.alive.interval", 0); // NOI18N
                if (serverAliveInterval > 0) {
                    newSession.setServerAliveInterval(serverAliveInterval);
                    int serverAliveCount = Integer.getInteger("jsch.server.alive.count", 5); // NOI18N
                    newSession.setServerAliveCountMax(serverAliveCount);
                }
                newSession.setUserInfo(userInfo);

                for (Entry<String, String> entry : jschSessionConfig.entrySet()) {
                    newSession.setConfig(entry.getKey(), entry.getValue());
                }
                Authentication auth = Authentication.getFor(env);
                final String preferredAuthKey = "PreferredAuthentications"; // NOI18N
                if (!jschSessionConfig.containsKey(preferredAuthKey)) {
                    String methods = auth.getAuthenticationMethods().toJschString();
                    if (methods != null) {
                        log.finest("Setting auth method list to " + methods); //NOI18N
                        newSession.setConfig(preferredAuthKey, methods);
                    }
                }
                if (USE_JZLIB) {
                    newSession.setConfig("compression.s2c", "[email protected],zlib,none"); // NOI18N
                    newSession.setConfig("compression.c2s", "[email protected],zlib,none"); // NOI18N
                    newSession.setConfig("compression_level", "9"); // NOI18N
                }

                if (RemoteStatistics.COLLECT_STATISTICS && RemoteStatistics.COLLECT_TRAFFIC) {
                    newSession.setSocketFactory(MeasurableSocketFactory.getInstance());
                }

                newSession.connect(auth.getTimeout()*1000);
                break;
            } catch (JSchException ex) {
                if (!UNIT_TEST_MODE) {
                    String msg = ex.getMessage();
                    if (msg == null) {
                        throw ex;
                    }
                    if (msg.startsWith("Auth fail") || msg.startsWith("SSH_MSG_DISCONNECT: 2")) { // NOI18N
                        PasswordManager.getInstance().clearPassword(env);
                    }
                } else {
                    throw ex;
                }
            } catch (CancellationException cex) {
                cancelled.set(true);
            }
        }

        if (cancelled.get()) {
            throw new InterruptedException("StartNewSession was cancelled ..."); // NOI18N
        }

        // In case of any port-forwarding previously set for this env
        // init the new session appropriately
        portForwarding.initSession(newSession);

        sessions.put(newSession, new AtomicInteger(JSCH_CHANNELS_PER_SESSION - (acquireChannel ? 1 : 0)));

        log.log(Level.FINE, "New session [{0}] started.", new Object[]{System.identityHashCode(newSession)}); // NOI18N
    } finally {
        ConnectingProgressHandle.stopHandle(env);
    }
    return newSession;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:82,代码来源:JSchChannelsSupport.java


注:本文中的com.jcraft.jsch.Session.setServerAliveInterval方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。