directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10317 - in incubator/directory/rms/trunk: . jdbm je/src/java/org/apache/rms/je/permissions
Date Tue, 27 Apr 2004 17:09:12 GMT
Author: akarasulu
Date: Tue Apr 27 10:09:10 2004
New Revision: 10317

Modified:
   incubator/directory/rms/trunk/   (props changed)
   incubator/directory/rms/trunk/jdbm/   (props changed)
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/LoggingBitPermissionDAOMonitor.java
Log:
completed logging-commons based logging monitor

Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/LoggingBitPermissionDAOMonitor.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/LoggingBitPermissionDAOMonitor.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/permissions/LoggingBitPermissionDAOMonitor.java
Tue Apr 27 10:09:10 2004
@@ -18,7 +18,13 @@
 
 
 import java.util.Iterator ;
+import java.io.IOException;
+
 import org.apache.rms.BitPermission ;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import com.sleepycat.bind.EntryBinding;
+import com.sleepycat.je.DatabaseEntry;
 
 
 /**
@@ -29,6 +35,12 @@
  */
 public class LoggingBitPermissionDAOMonitor implements BitPermissionDAOMonitor
 {
+    /** the entry <-> object binding used for prefetched entry transformation */
+    private EntryBinding BINDING = new JeBitPermissionTupleBinding() ;
+    /** the log used by this logging monitor */
+    private Log log = LogFactory.getLog( "BitPermissionDAO" ) ;
+
+
     /**
      * Monitors events where the DAO fails to create a new BitPermission.
      *
@@ -40,14 +52,19 @@
     public void failedOnCreate( BitPermissionDAO dao, String appName,
                                 String name, Throwable fault )
     {
-        fault.printStackTrace() ;
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Creation of permission with name " + name
+                    + " for application " + appName + " failed using " + dao,
+                    fault ) ;
+        }
     }
 
 
     /**
      * Monitors events where the DAO fails to create a new BitPermission
-     * because the permission for the application by
-     * the name specified already exists.
+     * because the permission for the application by the name specified
+     * already exists.
      *
      * @param dao     the data access object that failed
      * @param appName the name of the application
@@ -56,6 +73,12 @@
     public void permissionExists( BitPermissionDAO dao, String appName,
                                   String name )
     {
+        if ( log.isWarnEnabled() )
+        {
+            log.warn( "Creation of permission with name " + name
+                    + " for application " + appName + " failed using " + dao
+                    + " because a permission by that name already exists" ) ;
+        }
     }
 
 
@@ -69,6 +92,12 @@
     public void permissionCreated( BitPermissionDAO dao, String appName,
                                    String name )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Creation of permission with name " + name
+                    + " for application " + appName + " succeeded using "
+                    + dao ) ;
+        }
     }
 
 
@@ -82,6 +111,12 @@
     public void permissionDeleted( BitPermissionDAO dao, String appName,
                                    String name )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Deletion of permission with name " + name
+                    + " for application " + appName + " succeeded using "
+                    + dao ) ;
+        }
     }
 
 
@@ -96,7 +131,12 @@
     public void deleteFailed( BitPermissionDAO dao, String appName,
                               String name, Throwable fault )
     {
-        fault.printStackTrace() ;
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Deletion of permission with name " + name
+                    + " for application " + appName + " failed using "
+                    + dao, fault ) ;
+        }
     }
 
 
@@ -112,6 +152,12 @@
     public void permissionDoesNotExist( BitPermissionDAO dao, String op,
                                         String appName, String name )
     {
+        if ( log.isWarnEnabled() )
+        {
+            log.warn( "Attempt to " + op + " permission with name " + name
+                    + " for application " + appName
+                    + " failed because no such permission exists." ) ;
+        }
     }
 
 
@@ -127,6 +173,12 @@
     public void permissionDoesNotExist( JeBitPermissionDAO dao, String op,
                                         String appName, int index )
     {
+        if ( log.isWarnEnabled() )
+        {
+            log.warn( "Attempt to " + op + " permission with index " + index
+                + " for application " + appName
+                + " failed because no such permission exists." ) ;
+        }
     }
 
 
@@ -142,7 +194,12 @@
     public void failedOnRename( JeBitPermissionDAO dao, String appName,
                                 String name, String newName, Throwable fault )
     {
-        fault.printStackTrace() ;
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Rename of permission originally named " + name
+                    + " to new name of " + newName + " for application "
+                    + appName + " failed using " + dao, fault ) ;
+        }
     }
 
 
@@ -157,6 +214,12 @@
     public void permissionRenamed( JeBitPermissionDAO dao, String appName,
                                    String name, String newName )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Rename of permission originally named " + name
+                    + " to new name of " + newName + " for application "
+                    + appName + " succeeded using " + dao ) ;
+        }
     }
 
 
@@ -171,6 +234,12 @@
     public void indexLookedUp( JeBitPermissionDAO dao, String appName,
                                String name, int index )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Lookup of permission named " + name
+                    + " with index " + name + " for application "
+                    + appName + " succeeded using " + dao ) ;
+        }
     }
 
 
@@ -185,7 +254,33 @@
     public void failedPermissionLookup( JeBitPermissionDAO dao, String appName,
                                         String name, Throwable fault )
     {
-        fault.printStackTrace() ;
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Lookup of permission with name " + name
+                    + " for application " + appName + " failed using " + dao,
+                    fault ) ;
+        }
+    }
+
+
+    /**
+     * Monitors events where the lookup of a permission object by index fails.
+     *
+     * @param dao     the data access object that failed
+     * @param appName the name of the application
+     * @param index   the bit index of the permission
+     * @param fault   the fault that caused the failure
+     */
+    public void failedPermissionLookup( JeBitPermissionDAO dao,
+                                        String appName, int index,
+                                        Throwable fault )
+    {
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Lookup of permission with index " + index
+                    + " for application " + appName + " failed using " + dao,
+                    fault ) ;
+        }
     }
 
 
@@ -198,6 +293,12 @@
     public void permissionLookedUp( JeBitPermissionDAO dao,
                                     BitPermission perm )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Lookup of permission named " + perm.getName()
+                    + " with index " + perm.getIndex() + " for application "
+                    + perm.getApplication() + " succeeded using " + dao ) ;
+        }
     }
 
 
@@ -212,7 +313,12 @@
     public void failedNameLookup( JeBitPermissionDAO dao, String appName,
                                   int index, Throwable fault )
     {
-        fault.printStackTrace() ;
+        if ( log.isErrorEnabled() )
+        {
+            log.error( "Lookup of a permission's name with index " + index
+                    + " for application " + appName + " failed using " + dao,
+                    fault ) ;
+        }
     }
 
 
@@ -228,22 +334,12 @@
     public void nameLookedUP( JeBitPermissionDAO dao, String appName,
                               String name, int index )
     {
-    }
-
-
-    /**
-     * Monitors events where the lookup of a permission object by index fails.
-     *
-     * @param dao     the data access object that failed
-     * @param appName the name of the application
-     * @param index   the bit index of the permission
-     * @param fault   the fault that caused the failure
-     */
-    public void failedPermissionLookup( JeBitPermissionDAO dao,
-                                        String appName, int index,
-                                        Throwable fault )
-    {
-        fault.printStackTrace() ;
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Lookup of permission name " + name + " with index "
+                    + index + " for application " + appName
+                    + " succeeded using " + dao ) ;
+        }
     }
 
 
@@ -258,7 +354,11 @@
     public void failedOnCleanupOperation( JeBitPermissionDAO dao, String op,
                                           Object resource, Throwable fault )
     {
-        fault.printStackTrace() ;
+        if ( log.isWarnEnabled() )
+        {
+            log.warn( dao + " clean up of resource failed while calling "
+                    + resource + "." + op + "()", fault ) ;
+        }
     }
 
 
@@ -271,6 +371,11 @@
      */
     public void cleanedUp( JeBitPermissionDAO dao, String op, Object resource )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( dao + " cleaned up resource by calling " + resource
+                    + "." + op + "()" ) ;
+        }
     }
 
 
@@ -287,6 +392,23 @@
     public void listingEmpty( JeBitPermissionDAO dao, Iterator listing,
                               String appName, boolean onlyNames )
     {
+        if ( log.isDebugEnabled() )
+        {
+            String itemType = null ;
+
+            if ( onlyNames )
+            {
+                itemType = "String name" ;
+            }
+            else
+            {
+                itemType = "BitPermission object" ;
+            }
+
+            log.debug( "Iterator " + listing + " was successfully created over"
+                    + " an empty set of " + itemType + "s for application "
+                    + appName ) ;
+        }
     }
 
 
@@ -301,6 +423,12 @@
     public void listingNamesOnly( JeBitPermissionDAO dao, Iterator listing,
                                   String appName )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Iterator " + listing + " was successfully created over"
+                    + " the set of BitPermission names only for application "
+                    + appName ) ;
+        }
     }
 
 
@@ -315,6 +443,12 @@
     public void listingPermissions( JeBitPermissionDAO dao, Iterator listing,
                                     String appName )
     {
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "Iterator " + listing + " was successfully created "
+                + "over the set of BitPermissions for application "
+                + appName ) ;
+        }
     }
 
 
@@ -330,7 +464,24 @@
                                String appName, boolean onlyNames,
                                Throwable fault )
     {
-        fault.printStackTrace() ;
+        String itemType = null ;
+
+        if ( log.isErrorEnabled() )
+        {
+            if ( onlyNames )
+            {
+                itemType = "String name" ;
+            }
+            else
+            {
+                itemType = "BitPermission object" ;
+            }
+
+            log.error( "Iterator " + listing + " created by " + dao
+                    + " to return items of " + itemType
+                    + " for application " + appName
+                    + " failed to initialize", fault ) ;
+        }
     }
 
 
@@ -348,6 +499,14 @@
                                    String appName, Object retVal,
                                    Object prefetched )
     {
+        if ( log.isDebugEnabled() )
+        {
+            String name = new String( ( ( DatabaseEntry ) prefetched ).getData() ) ;
+            log.debug( "Iterator " + listing + " created by " + dao
+                    + " successfully prefetch a BitPermission name of " + name
+                    + " for application " + appName
+                    + " after retrieving the value " + retVal ) ;
+        }
     }
 
 
@@ -365,6 +524,32 @@
                                    String appName, Object retVal,
                                    Object prefetched )
     {
+        BitPermission perm = null ;
+
+        if ( log.isDebugEnabled() )
+        {
+            if ( prefetched instanceof BitPermission )
+            {
+                perm = ( BitPermission ) prefetched ;
+            }
+            else if ( prefetched instanceof DatabaseEntry )
+            {
+                try
+                {
+                    perm = ( BitPermission )
+                            BINDING.entryToObject( ( DatabaseEntry ) prefetched ) ;
+                }
+                catch ( IOException e )
+                {
+                    log.error( "Failed to bind database entry to BitPermission" ) ;
+                }
+            }
+
+            log.debug( "Iterator " + listing + " created by " + dao
+                    + " successfully prefetch a BitPermission of " + perm
+                    + " for application " + appName
+                    + " after retrieving the value " + retVal ) ;
+        }
     }
 
 
@@ -385,7 +570,24 @@
                                  String appName, boolean onlyNames,
                                  Object retVal, Throwable fault )
     {
-        fault.printStackTrace() ;
+        String itemType = null ;
+
+        if ( log.isErrorEnabled() )
+        {
+            if ( onlyNames )
+            {
+                itemType = "String name" ;
+            }
+            else
+            {
+                itemType = "BitPermission object" ;
+            }
+
+            log.error( "Iterator " + listing + " created by " + dao
+                    + " failed on prefetch of " + itemType
+                    + " for application " + appName
+                    + " after retrieving the value " + retVal, fault ) ;
+        }
     }
 
 
@@ -404,5 +606,22 @@
                                    String appName, boolean onlyNames,
                                    Object lastVal )
     {
+        String itemType = null ;
+
+        if ( log.isDebugEnabled() )
+        {
+            if ( onlyNames )
+            {
+                itemType = "String names" ;
+            }
+            else
+            {
+                itemType = "BitPermission objects" ;
+            }
+
+            log.debug( "Iterator " + listing + " created by " + dao
+                    + " exhaused all " + itemType + " for application "
+                    + appName + ".  Will return final value of " + lastVal ) ;
+        }
     }
 }

Mime
View raw message