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 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;

}

java setsession_Java Session.setServerAliveInterval方法代码示例相关推荐

  1. java kryo_Kryo框架使用方法代码示例

    Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...

  2. java readtimeout_Java HttpURLConnection.getReadTimeout方法代码示例

    import java.net.HttpURLConnection; //导入方法依赖的package包/类 /** * 得到响应对象 * * @param urlConnection * @retu ...

  3. java invalidate_Java Component.invalidate方法代码示例

    import java.awt.Component; //导入方法依赖的package包/类 /** Installs the component we will embed to display t ...

  4. java hasmoreelements_Java IOException.hasMoreElements方法代码示例

    import java.io.IOException; //导入方法依赖的package包/类 /** * fileName���� ���� package �������� ������ ���� ...

  5. java methode_Java Method.getTypeParameters方法代码示例

    import java.lang.reflect.Method; //导入方法依赖的package包/类 private void validateRuleMethod(MethodRuleDefin ...

  6. java setmethod_Java Operation.setJavaMethod方法代码示例

    import com.sun.tools.internal.ws.processor.model.Operation; //导入方法依赖的package包/类 private void createJ ...

  7. java logout_Java Core.logout方法代码示例

    import com.mendix.core.Core; //导入方法依赖的package包/类 private void login(IMxRuntimeRequest req, IMxRuntim ...

  8. java cancel_Java RunnableFuture.cancel方法代码示例

    import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类 @Test public void testSnapshotAsyncC ...

  9. java getevent_Java ActionEvent.getWhen方法代码示例

    import java.awt.event.ActionEvent; //导入方法依赖的package包/类 @Override final public void actionPerformed(A ...

最新文章

  1. 【java】如何判断数组中的内容是否重复
  2. 摄像头视频推流python_摄像头视频推流装置及方法与流程
  3. placeholder 与variable
  4. php+错误+处理,PHP 错误处理手记!!!!!
  5. 给图片下方加水印_别再看不起美图秀秀啦,想要做长图,批量加水印,用它超级方便...
  6. 学习Node.js并开始在浏览器之外执行JavaScript
  7. Struts项目中引入了过滤器filter后出现中文乱码情况
  8. 域做文件服务器,linux 做域文件服务器
  9. html文件中用import,@import引入CSS文件
  10. css让image不改变大小_如何改变图片大小
  11. Java NumberFormat,DecimalFormat保存小数位数
  12. Source Insight 4.0.0086 Patched
  13. 鲁班图片压缩实现仿微信九宫格选择图片效果
  14. Qt VTK软件开发问题学习记录
  15. 用ghost为服务器装系统,Ghost详解:使用Ghost来安装Windows操作系统
  16. 花开花落花非花、缘起缘灭缘随缘
  17. peek和pop的区别
  18. 苹果CEO史蒂夫·乔布斯在斯坦福演讲(一)
  19. 面对元宇宙算力瓶颈,AI算力专家宁畅开出三大秘方
  20. AE学习基础入门小结

热门文章

  1. Wireshark图解教程(简介、抓包、过滤器)
  2. gcc/g++ 链接库的编译与链接
  3. UliPad 初体验----python 开发利器
  4. WIN7下搭建FTP
  5. J2ME开发环境配置(MyEclipse插件+WTK+jdk)
  6. linux superblock 时间,Linux命令(八)
  7. php haystack,haystack(示例代码)
  8. 服务器系统报错kernel-power,第十二讲、Linux服务器操作系统1.ppt
  9. github哪些协议能商用_GitHub 上有哪些一般人也可以用的项目?
  10. Ajax全接触(1)