@Override
    @SuppressWarnings ( "resource" )
    public synchronized SmbSessionImpl getSmbSession ( CIFSContext tf, String targetHost, String targetDomain ) {
        long now;

        if ( log.isTraceEnabled() ) {
            log.trace("Currently " + this.sessions.size() + " session(s) active for " + this);
        }

        if ( targetHost != null ) {
            targetHost = targetHost.toLowerCase(Locale.ROOT);
        }

        if ( targetDomain != null ) {
            targetDomain = targetDomain.toUpperCase(Locale.ROOT);
        }

        ListIterator<SmbSessionImpl> iter = this.sessions.listIterator();
        while ( iter.hasNext() ) {
            SmbSessionImpl ssn = iter.next();
            if ( ssn.matches(tf, targetHost, targetDomain) ) {
                if ( log.isTraceEnabled() ) {
                    log.trace("Reusing existing session " + ssn);
                }
                return ssn.acquire();
            }
            else if ( log.isTraceEnabled() ) {
                log.trace("Existing session " + ssn + " does not match " + tf.getCredentials());
            }
        }

        /* logoff old sessions */
        if ( tf.getConfig().getSessionTimeout() > 0 && this.sessionExpiration < ( now = System.currentTimeMillis() ) ) {
            this.sessionExpiration = now + tf.getConfig().getSessionTimeout();
            iter = this.sessions.listIterator();
            while ( iter.hasNext() ) {
                SmbSessionImpl ssn = iter.next();
                if ( ssn.getExpiration() != null && ssn.getExpiration() < now && !ssn.isInUse() ) {
                    if ( log.isDebugEnabled() ) {
                        log.debug("Closing session after timeout " + ssn);
                    }
                    ssn.logoff(false, false);
                }
            }
        }
        SmbSessionImpl ssn = new SmbSessionImpl(tf, targetHost, targetDomain, this);
        if ( log.isDebugEnabled() ) {
            log.debug("Establishing new session " + ssn + " on " + this.name);
        }
        this.sessions.add(ssn);
        return ssn;
    }
@ Override @ SuppressWarnings ( "resource" ) public synchronized SmbSessionImpl getSmbSession ( CIFSContext tf , String targetHost , String targetDomain ) { long now ; if ( log . isTraceEnabled ( ) ) { log . trace ( "Currently " + this . sessions . size ( ) + " session(s) active for " + this ) ; } if ( targetHost != null ) { targetHost = targetHost . toLowerCase ( Locale . ROOT ) ; } if ( targetDomain != null ) { targetDomain = targetDomain . toUpperCase ( Locale . ROOT ) ; } ListIterator < SmbSessionImpl > iter = this . sessions . listIterator ( ) ; while ( iter . hasNext ( ) ) { SmbSessionImpl ssn = iter . next ( ) ; if ( ssn . matches ( tf , targetHost , targetDomain ) ) { if ( log . isTraceEnabled ( ) ) { log . trace ( "Reusing existing session " + ssn ) ; } return ssn . acquire ( ) ; } else if ( log . isTraceEnabled ( ) ) { log . trace ( "Existing session " + ssn + " does not match " + tf . getCredentials ( ) ) ; } } if ( tf . getConfig ( ) . getSessionTimeout ( ) > 0 && this . sessionExpiration < ( now = System . currentTimeMillis ( ) ) ) { this . sessionExpiration = now + tf . getConfig ( ) . getSessionTimeout ( ) ; iter = this . sessions . listIterator ( ) ; while ( iter . hasNext ( ) ) { SmbSessionImpl ssn = iter . next ( ) ; if ( ssn . getExpiration ( ) != null && ssn . getExpiration ( ) < now && ! ssn . isInUse ( ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Closing session after timeout " + ssn ) ; } ssn . logoff ( false , false ) ; } } } SmbSessionImpl ssn = new SmbSessionImpl ( tf , targetHost , targetDomain , this ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Establishing new session " + ssn + " on " + this . name ) ; } this . sessions . add ( ssn ) ; return ssn ; }
@param tf
context to use
@return a session for the context