masonjm     2004/09/01 12:08:56

  Modified:    src/stores/org/apache/slide/store/txjndi
                        JNDIPrincipalStore.java
  Log:
  - No longer uses a single connection. When a hung LDAP server recovers Slide will 
now recover as well.
  
  Revision  Changes    Path
  1.7       +78 -39    
jakarta-slide/src/stores/org/apache/slide/store/txjndi/JNDIPrincipalStore.java
  
  Index: JNDIPrincipalStore.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/stores/org/apache/slide/store/txjndi/JNDIPrincipalStore.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- JNDIPrincipalStore.java   31 Aug 2004 16:02:36 -0000      1.6
  +++ JNDIPrincipalStore.java   1 Sep 2004 19:08:56 -0000       1.7
  @@ -267,7 +267,6 @@
        
        public static final String LOG_CHANNEL = JNDIPrincipalStore.class.getName();
        
  -     protected DirContext ctx;
        protected Hashtable ctxParameters;
   
        protected boolean isConnected = false;
  @@ -552,44 +551,18 @@
                if ( !refresher.isAlive() ) {
                        refresher.start();
                }
  -             getLogger().log( name + ": Connecting to LDAP server.", LOG_CHANNEL, 
Logger.DEBUG );
  -             try {
  -                     ctx = new InitialDirContext( ctxParameters );
  -                     if ( ctx != null ) {
  -                             isConnected = true;
  -                     } else {
  -                             throw new ServiceConnectionFailedException(
  -                                     this, "Invalid JNDI connection parameters." );
  -                     }
  -             } catch ( NamingException e ) {
  -                     getLogger().log( name + ": Error Connecting to LDAP Server",
  -                             e,
  -                             LOG_CHANNEL,
  -                             Logger.CRITICAL );
  -                     throw new ServiceConnectionFailedException( this, e );
  -             }
        }
   
  -     public void disconnect() throws ServiceDisconnectionFailedException {
  +    public void disconnect() throws ServiceDisconnectionFailedException {
                if ( refresher.isAlive() ) {
                        refresher.halt();
                }
  -             getLogger().log( name + ": Disconnecting from LDAP server.", 
LOG_CHANNEL, Logger.DEBUG );
  -             try {
  -                     ctx.close();
  -             } catch ( NamingException e ) {
  -                     getLogger().log( name + ": Error disconnecting from LDAP",
  -                             e, LOG_CHANNEL, Logger.WARNING );
  -                     ctx = null;
  -             } finally {
  -                     isConnected = false;
  -             }
        }
   
  -     public void reset() throws ServiceResetFailedException {}
  +    public void reset() throws ServiceResetFailedException {}
   
        public boolean isConnected() throws ServiceAccessException {
  -             return isConnected;
  +             return true;
        }
   
        public int getTransactionTimeout() throws XAException {
  @@ -705,8 +678,13 @@
                        throws ObjectNotFoundException, ServiceAccessException {
                
                long start = System.currentTimeMillis();
  -             
  -             Uri parentUri = uri.getParentUri();
  +        DirContext ctx = null;
  +        try {
  +            ctx = getContext();
  +        } catch ( ServiceConnectionFailedException e ) {
  +            throw new ServiceAccessException(this, e);
  +        }
  +        Uri parentUri = uri.getParentUri();
                String objectName = getObjectNameFromUri( uri );
                
                Vector parentBindings = new Vector();
  @@ -778,12 +756,18 @@
                                        controls );
   
                                if ( !results.hasMore() ) {
  +                    if (ctx != null) {
  +                        closeContext(ctx);
  +                    }
                                        throw new ObjectNotFoundException( uri );
                                }
                        } catch ( NamingException e ) {
                                getLogger().log(
                                        name + ": Error retrieving " + uri.toString(),
                                        e, LOG_CHANNEL, Logger.ERROR );
  +                if (ctx != null) {
  +                    closeContext(ctx);
  +                }
                                throw new ServiceAccessException( this, e );
                        }
                }
  @@ -809,7 +793,9 @@
                if ( elapsed > refreshThreshold ) {
                        addRefreshee( uri, Refreshee.REFRESH_OBJECT );
                }
  -             
  +        if (ctx != null) {
  +            closeContext(ctx);
  +        }            
                return node;
        }
   
  @@ -817,6 +803,12 @@
                        throws RevisionDescriptorNotFoundException, 
ServiceAccessException {
                
                long start = System.currentTimeMillis();
  +        DirContext ctx = null;
  +        try {
  +            ctx = getContext();
  +        } catch ( ServiceConnectionFailedException e ) {
  +            throw new ServiceAccessException(this, e);
  +        }
                
                String objectName = getObjectNameFromUri( uri );
                
  @@ -849,6 +841,9 @@
                                        controls );
   
                                if ( !results.hasMore() ) {
  +                    if (ctx != null) {
  +                        closeContext(ctx);
  +                    }
                                        throw new RevisionDescriptorNotFoundException( 
uri.toString() );
                                }
                                while ( results.hasMore() ) {
  @@ -860,6 +855,9 @@
                                                        name + ": Error getting search 
result with filter: " + localFilter +
                                                        " from container: " + 
container + ".",
                                                        LOG_CHANNEL, Logger.ERROR );
  +                        if (ctx != null) {
  +                            closeContext(ctx);
  +                        }
                                                throw new ServiceAccessException( 
this, e );
                                        }
                                        
  @@ -889,10 +887,10 @@
                                                                        if ( isMva ) {
                                                                                
valueString.append( "<mva xmlns=\"" )
                                                                                       
 .append( LDAP_NAMESPACE ).append( "\">" );
  -                                                                             
valueString.append( value.toString().toLowerCase() );
  +                                                                             
valueString.append( value.toString() );
                                                                                
valueString.append( "</mva>" );
                                                                        } else {
  -                                                                             
valueString.append( value.toString().toLowerCase() );
  +                                                                             
valueString.append( value.toString() );
                                                                        }
                                                                }
                                                        } catch ( NamingException e ) {
  @@ -961,12 +959,53 @@
                if ( elapsed > refreshThreshold ) {
                        addRefreshee( uri, Refreshee.REFRESH_DESCRIPTOR );
                }
  -             
  +        if (ctx != null) {
  +            closeContext(ctx);
  +        }
                return descriptor;
        }
        
        // --------------------------------------------------- Helper Methods 
---------------
   
  +    /**
  +     * Closes a JNDI connection.
  +     * @param ctx the Context to close
  +     */
  +    private void closeContext(DirContext ctx) {
  +        getLogger().log( name + ": Disconnecting from LDAP server.", LOG_CHANNEL, 
Logger.DEBUG );
  +        try {
  +            ctx.close();
  +        } catch ( NamingException e ) {
  +            getLogger().log( name + ": Error disconnecting from LDAP",
  +                e, LOG_CHANNEL, Logger.WARNING );
  +            ctx = null;
  +        }
  +    }
  +    
  +    /**
  +     * Gets a JNDI Context using the connection parameters specified for
  +     * this Store in the Domain.
  +     * @throws ServiceConnectionFailedException
  +     */
  +    private DirContext getContext() throws ServiceConnectionFailedException {
  +        getLogger().log( name + ": Connecting to LDAP server.", LOG_CHANNEL, 
Logger.DEBUG );
  +        try {
  +            DirContext ctx = new InitialDirContext( ctxParameters );
  +            if ( ctx != null ) {
  +                return ctx;
  +            } else {
  +                throw new ServiceConnectionFailedException(
  +                    this, "Invalid JNDI connection parameters." );
  +            }
  +        } catch ( NamingException e ) {
  +            getLogger().log( name + ": Error Connecting to LDAP Server",
  +                e,
  +                LOG_CHANNEL,
  +                Logger.CRITICAL );
  +            throw new ServiceConnectionFailedException( this, e );
  +        }
  +    }
  +    
        protected String getObjectNameFromUri( Uri uri ) {
                String objectName = uri.toString().substring(
                        uri.toString().lastIndexOf( "/" ) + 1 );
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to