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


Java Session.isConnected方法代碼示例

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


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

示例1: executeCommand

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * Executes a given command. It opens exec channel for the command and closes
 * the channel when it's done.
 *
 * @param session ssh connection to a remote server
 * @param command command to execute
 * @return command output string if the command succeeds, or null
 */
private static String executeCommand(Session session, String command) {
    if (session == null || !session.isConnected()) {
        return null;
    }

    log.trace("Execute command {} to {}", command, session.getHost());

    try {
        Channel channel = session.openChannel("exec");
        ((ChannelExec) channel).setCommand(command);
        channel.setInputStream(null);
        InputStream output = channel.getInputStream();

        channel.connect();
        String result = CharStreams.toString(new InputStreamReader(output));
        channel.disconnect();

        log.trace("Result of command {} on {}: {}", command, session.getHost(), result);

        return result;
    } catch (JSchException | IOException e) {
        log.error("Failed to execute command {} on {} due to {}", command, session.getHost(), e.toString());
        return null;
    }
}
 
開發者ID:opencord,項目名稱:vtn,代碼行數:34,代碼來源:RemoteIpCommandUtil.java

示例2: getServerVersion

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public String getServerVersion() {
    for (Session s : sessions.keySet()) {
        if (s.isConnected()) {
            return s.getServerVersion();
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:JSchChannelsSupport.java

示例3: isConnected

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public boolean isConnected() {
    // ConcurrentHashMap.keySet() never throws ConcurrentModificationException
    for (Session s : sessions.keySet()) {
        if (s.isConnected()) {
            return true;
        }
    }

    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:11,代碼來源:JSchChannelsSupport.java

示例4: findFreeSession

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
private Session findFreeSession() {
    for (Entry<Session, AtomicInteger> entry : sessions.entrySet()) {
        Session s = entry.getKey();
        AtomicInteger availableChannels = entry.getValue();
        if (s.isConnected() && availableChannels.get() > 0) {
            log.log(Level.FINE, "availableChannels == {0}", new Object[]{availableChannels.get()}); // NOI18N
            int remains = availableChannels.decrementAndGet();
            log.log(Level.FINE, "Reuse session [{0}]. {1} channels remain...", new Object[]{System.identityHashCode(s), remains}); // NOI18N
            return s;
        }
    }

    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:JSchChannelsSupport.java

示例5: setPortForwardingL

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public int setPortForwardingL(int lport, String host, int rport) throws JSchException {
    portForwarding.addPortForwardingInfoL(lport, host, rport);
    for (Session s : sessions.keySet()) {
        if (s.isConnected()) {
            return s.setPortForwardingL(lport, host, rport);
        }
    }
    return -1;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:JSchChannelsSupport.java

示例6: setPortForwardingR

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public void setPortForwardingR(String bind_address, int rport, String host, int lport) throws JSchException {
    portForwarding.addPortForwardingInfoR(bind_address, rport, host, lport);
    for (Session s : sessions.keySet()) {
        if (s.isConnected()) {
            s.setPortForwardingR(bind_address, rport, host, lport);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:JSchChannelsSupport.java

示例7: delPortForwardingR

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public void delPortForwardingR(int rport) throws JSchException {
    portForwarding.removePortForwardingInfoR(rport);
    for (Session s : sessions.keySet()) {
        if (s.isConnected()) {
            s.delPortForwardingR(rport);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:JSchChannelsSupport.java

示例8: delPortForwardingL

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public void delPortForwardingL(int lport) throws JSchException {
    portForwarding.removePortForwardingInfoL(lport);
    for (Session s : sessions.keySet()) {
        if (s.isConnected()) {
            s.delPortForwardingL(lport);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:JSchChannelsSupport.java

示例9: getConfig

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public String getConfig(String key) {
    for (Session s : sessions.keySet()) {
        if (s.isConnected()) {
            return s.getConfig(key);
        }
    }
    return null;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:9,代碼來源:JSchChannelsSupport.java

示例10: getSession

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
public synchronized Session getSession(Uri path) throws JSchException{
    String username="anonymous";

    String password = "";
    NetworkCredentialsDatabase database = NetworkCredentialsDatabase.getInstance();
    Credential cred = database.getCredential(path.toString());
    if(cred==null){
        cred = new Credential("anonymous","",buildKeyFromUri(path).toString(), true);

    }
    if(cred!=null){
        password= cred.getPassword();
        username = cred.getUsername();
    }

    Session session = sessions.get(cred);
    if(session!=null){
        if(!session.isConnected())
            try {
                session.connect();
            } catch (JSchException e1) {
                removeSession(path);
                return getSession(path);
            }
        return session;
    }

    JSch jsch=new JSch();
    try {
        session = jsch.getSession(username, path.getHost(), path.getPort());
        session.setPassword(password);
        java.util.Properties config = new java.util.Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();
        sessions.put(cred, session);
        return session;
    } catch (JSchException e) {
        // TODO Auto-generated catch block
        throw e;

    }
    

}
 
開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:46,代碼來源:SFTPSession.java

示例11: create

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
@Override
public Channel create(final ChannelSessionKey key) throws Exception {
    Session session;
    synchronized (sessionMap) {
        session = sessionMap.get(key);
        if (session == null || !session.isConnected()) {
            session = prepareSession(key.remoteSystemConnection);
            session.connect();
            sessionMap.put(key, session);
            LOGGER.debug("session {} created and connected!", key);
        }
    }
    return session.openChannel(key.channelType.getChannelType());
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:15,代碼來源:KeyedPooledJschChannelFactory.java

示例12: addIp

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * Adds a given IP address to a given device.
 *
 * @param session ssh connection
 * @param ip network address
 * @param device device name to assign the ip address
 * @return true if the command succeeds, or false
 */
public static boolean addIp(Session session, CidrAddr ip, String device) {
    if (session == null || !session.isConnected()) {
        return false;
    }

    executeCommand(session, String.format(IP_ADDR_ADD, ip.cidr(), device));
    Set<IpAddress> result = getCurrentIps(session, device);
    return result.contains(ip.ip());
}
 
開發者ID:opencord,項目名稱:vtn,代碼行數:18,代碼來源:RemoteIpCommandUtil.java

示例13: deleteIp

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * Removes the IP address from a given device.
 *
 * @param session ssh connection
 * @param ip ip address
 * @param device device name
 * @return true if the command succeeds, or false
 */
public static boolean deleteIp(Session session, IpAddress ip, String device) {
    if (session == null || !session.isConnected()) {
        return false;
    }

    executeCommand(session, String.format(IP_ADDR_DELETE, ip, device));
    Set<IpAddress> result = getCurrentIps(session, device);
    return !result.contains(ip);
}
 
開發者ID:opencord,項目名稱:vtn,代碼行數:18,代碼來源:RemoteIpCommandUtil.java

示例14: flushIp

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * Removes all IP address on a given device.
 *
 * @param session ssh connection
 * @param device device name
 * @return true if the command succeeds, or false
 */
public static boolean flushIp(Session session, String device) {
    if (session == null || !session.isConnected()) {
        return false;
    }

    executeCommand(session, String.format(IP_ADDR_FLUSH, device));
    return getCurrentIps(session, device).isEmpty();
}
 
開發者ID:opencord,項目名稱:vtn,代碼行數:16,代碼來源:RemoteIpCommandUtil.java

示例15: getCurrentIps

import com.jcraft.jsch.Session; //導入方法依賴的package包/類
/**
 * Returns a set of IP address that a given device has.
 *
 * @param session ssh connection
 * @param device device name
 * @return set of IP prefix or empty set
 */
public static Set<IpAddress> getCurrentIps(Session session, String device) {
    if (session == null || !session.isConnected()) {
        return Sets.newHashSet();
    }

    String output = executeCommand(session, String.format(IP_ADDR_SHOW, device));
    Set<IpAddress> result = Pattern.compile(" |/")
            .splitAsStream(output)
            .filter(s -> s.matches(IP_PATTERN))
            .map(IpAddress::valueOf)
            .collect(Collectors.toSet());

    return result;
}
 
開發者ID:opencord,項目名稱:vtn,代碼行數:22,代碼來源:RemoteIpCommandUtil.java


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