All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.cloudslang.content.ssh.utils.SSHSessionResource Maven / Gradle / Ivy

There is a newer version: 0.0.44
Show newest version
/*******************************************************************************
 * (c) Copyright 2017 Hewlett-Packard Development Company, L.P.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *
 * The Apache License is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *******************************************************************************/
package io.cloudslang.content.ssh.utils;

import com.hp.oo.sdk.content.plugin.SessionResource;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.Session;
import io.cloudslang.content.ssh.entities.SSHConnection;

import java.util.Collection;
import java.util.Map;

/**
 * Wrapper class on SSH session.
 *
 * @author octavian-h
 */
public class SSHSessionResource extends SessionResource> {
    private Map sshConnectionMap;

    public SSHSessionResource(Map sshConnectionMap) {
        this.sshConnectionMap = sshConnectionMap;
    }

    @Override
    public Map get() {
        return sshConnectionMap;
    }

    @Override
    public void release() {
        final Collection sshConnections = sshConnectionMap.values();
        for (SSHConnection sshConnection : sshConnections) {
            synchronized (sshConnection) {
                Session session = sshConnection.getSession();
                session.disconnect();
                Channel channel = sshConnection.getChannel();
                if (channel != null) {
                    channel.disconnect();
                }
            }
        }
        sshConnectionMap = null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy