package com.atlassian.bitbucket.internal.ssh.server;

import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.server.ServerFactoryManager;
import org.apache.sshd.server.channel.ChannelSessionFactory;

/**
 * An implementation of NamedFactory which creates {@link SelfClosingChannelSession} instances
 */
public class SelfClosingChannelSessionFactory extends ChannelSessionFactory {

    private final long idleTimeout;

    public SelfClosingChannelSessionFactory(long idleTimeout) {
        this.idleTimeout = idleTimeout;
    }

    @Override
    public Channel create() {
        SelfClosingChannelSession session = new SelfClosingChannelSession();
        PropertyResolverUtils.updateProperty(session, ServerFactoryManager.IDLE_TIMEOUT, idleTimeout);

        return session;
    }
}
