关闭SSH连接会话

@param session SSH会话
341826
public static void close(Session session) {
		if (session != null && session.isConnected()) {
			session.disconnect();
		}
		JschSessionPool.INSTANCE.remove(session);
	}
1157671
protected void reconnect(MemcachedTCPSession session) {
    if (!this.client.isShutdown()) {
      // Prevent reconnecting repeatedly
      synchronized (session) {
        if (!session.isAllowReconnect()) {
          return;
        }
        session.setAllowReconnect(false);
      }
      MemcachedSession memcachedTCPSession = session;
      InetSocketAddressWrapper inetSocketAddressWrapper =
          memcachedTCPSession.getInetSocketAddressWrapper();
      this.client.getConnector().addToWatingQueue(
          new ReconnectRequest(inetSocketAddressWrapper, 0, this.client.getHealSessionInterval()));
    }
  }
1315591
public void setSessions(java.util.Collection<Session> sessions) {
        if (sessions == null) {
            this.sessions = null;
            return;
        }

        this.sessions = new com.amazonaws.internal.SdkInternalList<Session>(sessions);
    }
472770
void registerSessionIfNeeded(HttpSession session) {
		if (session != null) {
			synchronized (session) {
				if (!SESSION_MAP_BY_ID.containsKey(session.getId())) {
					sessionCreated(new HttpSessionEvent(session));
				}
			}
		}
	}
1136874
public static Session createSession(String sshHost, int sshPort, String sshUser, String sshPass) {
		if (StrUtil.isEmpty(sshHost) || sshPort < 0 || StrUtil.isEmpty(sshUser) || StrUtil.isEmpty(sshPass)) {
			return null;
		}

		Session session;
		try {
			session = new JSch().getSession(sshUser, sshHost, sshPort);
			session.setPassword(sshPass);
			// 设置第一次登陆的时候提示，可选值：(ask | yes | no)
			session.setConfig("StrictHostKeyChecking", "no");
		} catch (JSchException e) {
			throw new JschRuntimeException(e);
		}
		return session;
	}
43441
def _initialize_session():
    # type: () -> None
    
    sys_random = random.SystemRandom()
    _thread_local_storage.secret_key = b''.join(
        int2byte(sys_random.randint(0, 255))
        for _ in range(SECRET_KEY_BITS // 8))
1146600
function (session) {
            this._session = session;
            if (this._smList) {
                var sz = this._smList.length;
                for (var i = 0; i < sz; i++) {
                    var subModule = this._smList[i];
                    if (subModule) {
                        subModule.setSession(session);
                    }
                }
            }
        }
148031
public void expireSession(PrimaryBackupSession session) {
    if (sessions.remove(session.sessionId().id()) != null) {
      session.expire();
      listeners.forEach(l -> l.onExpire(session));
    }
  }
427329
public void openSession(PrimaryBackupSession session) {
    sessions.put(session.sessionId().id(), session);
    listeners.forEach(l -> l.onOpen(session));
  }
1217169
public void closeSession(PrimaryBackupSession session) {
    if (sessions.remove(session.sessionId().id()) != null) {
      session.close();
      listeners.forEach(l -> l.onClose(session));
    }
  }
666704
private void free(IoSession session) {
        IoBuffer buf = buffersMap.remove(session);
        if (buf != null) {
            buf.free();
        }
    }
611007
protected void reconnect(Session session) {
		if (this.hsClient.isStarted()) {
			if (log.isDebugEnabled()) {
				log.debug("Add reconnectRequest to connector "
						+ session.getRemoteSocketAddress());
			}
			HandlerSocketSession hSession = (HandlerSocketSession) session;
			InetSocketAddress addr = hSession.getRemoteSocketAddress();
			this.hsClient.getConnector().addToWatingQueue(
					new ReconnectRequest(addr, 0, this.hsClient
							.getHealConnectionInterval()));
		}
	}
254906
public List<String> getHeapsForSession(IoSession session) {
        List<String> ret = new ArrayList<String>();
        try {
            subTermLock.lock();
            Multiset<String> s = heapsByClient.get(session);
            if (s != null) {
                ret.addAll(s.keySet());
            }
        } finally {
            subTermLock.unlock();
        }
        return ret;
    }
757638
protected void startSession()throws SocksException{
	   
	   System.out.println("Session: " + proxyHost + ":" + proxyPort);
       try{
         if(chainProxy == null)
            proxySocket = new Socket(proxyIP,proxyPort);
         else if(proxyIP != null)
            proxySocket = new SocksSocket(chainProxy,proxyIP,proxyPort);
         else
            proxySocket = new SocksSocket(chainProxy,proxyHost,proxyPort);

         in = proxySocket.getInputStream();
         out = proxySocket.getOutputStream();
       }catch(SocksException se){
         throw se;
       }catch(IOException io_ex){
         throw new SocksException(SOCKS_PROXY_IO_ERROR,""+io_ex);
       }
   }
391013
def process_reset_session(session, connection_initialize = false)
      # set active command sequence info
      session[:cmd_sequence] = connection_initialize ? :CMD_HELO : :CMD_RSET
      # drop any auth challenge
      session[:auth_challenge] = {}
      # test existing of :ctx hash
      session[:ctx] || session[:ctx] = {}
      # reset server values (only on connection start)
      if connection_initialize
        # create or rebuild :ctx hash
        session[:ctx].merge!(
          server: {
            local_host: '',
            local_ip: '',
            local_port: '',
            local_response: '',
            remote_host: '',
            remote_ip: '',
            remote_port: '',
            helo: '',
            helo_response: '',
            connected: '',
            exceptions: 0,
            authorization_id: '',
            authentication_id: '',
            authenticated: '',
            encrypted: ''
          }
        )
      end
      # reset envelope values
      session[:ctx].merge!(
        envelope: {
          from: '',
          to: [],
          encoding_body: '',
          encoding_utf8: ''
        }
      )
      # reset message data
      session[:ctx].merge!(
        message: {
          received: -1,
          delivered: -1,
          bytesize: -1,
          headers: '',
          crlf: "\r\n",
          data: ''
        }
      )
    end
1158451
@Given("^I open a ssh connection to '(.+?)'( in port '(.+?)')? with user '(.+?)'( and password '(.+?)')?( using pem file '(.+?)')?$")
    public void openSSHConnection(String remoteHost, String tmp, String remotePort, String user, String foo, String password, String bar, String pemFile) throws Exception {
        if ((pemFile == null) || (pemFile.equals("none"))) {
            if (password == null) {
                throw new Exception("You have to provide a password or a pem file to be used for connection");
            }
            commonspec.setRemoteSSHConnection(new RemoteSSHConnection(user, password, remoteHost, remotePort, null));
            commonspec.getLogger().debug("Opening ssh connection with password: { " + password + "}", commonspec.getRemoteSSHConnection());
        } else {
            File pem = new File(pemFile);
            if (!pem.exists()) {
                throw new Exception("Pem file: " + pemFile + " does not exist");
            }
            commonspec.setRemoteSSHConnection(new RemoteSSHConnection(user, null, remoteHost, remotePort, pemFile));
            commonspec.getLogger().debug("Opening ssh connection with pemFile: {}", commonspec.getRemoteSSHConnection());
        }
    }
118550
public void complete(Session session) {
        try {
            session.complete();
            sessionCache.put(session.getId(), session);
        } catch (Exception e) {
            log.warn("Session failed to complete", e);
        }
    }