当前位置: 首页>>代码示例>>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;未经允许,请勿转载。