]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/JschContextSession.java
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.jsch
;
19 import org
.apache
.commons
.logging
.Log
;
20 import org
.apache
.commons
.logging
.LogFactory
;
21 import org
.springframework
.beans
.factory
.DisposableBean
;
22 import org
.springframework
.beans
.factory
.InitializingBean
;
24 import com
.jcraft
.jsch
.Session
;
26 /** Caches a JSCH session in the the ssh target. */
27 public class JschContextSession
extends AbstractJschTask
implements
28 InitializingBean
, DisposableBean
{
29 private final static Log log
= LogFactory
.getLog(JschContextSession
.class);
30 private Boolean autoconnect
= false;
33 void run(Session session
) {
35 getSshTarget().setSession(session
);
36 if (log
.isDebugEnabled())
37 log
.debug("Cached SSH context session to " + getSshTarget());
40 public void afterPropertiesSet() throws Exception
{
41 // if (log.isDebugEnabled())
42 // log.debug(getClass() + ".afterPropertiesSet(), " + beanName + ", "
47 } catch (Exception e
) {
48 log
.error("Could not automatically open session", e
);
52 public void destroy() throws Exception
{
57 SshTarget sshTarget
= getSshTarget();
58 synchronized (sshTarget
) {
59 if (sshTarget
.getSession() != null) {
60 sshTarget
.getSession().disconnect();
61 sshTarget
.setSession(null);
62 if (log
.isDebugEnabled())
63 log
.debug("Cleared cached SSH context session to "
69 public void setAutoconnect(Boolean autoconnect
) {
70 this.autoconnect
= autoconnect
;