protected File makeLogDirectory(long timestamp, final String pid, boolean flag) {
        // Find the most recent instance directory.
        File instanceDir = null;
        long maxTimestamp = -1;
        for (File dir : AccessHelper.listFiles(repositoryLocation, new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                return AccessHelper.isDirectory(pathname);
            }
        })) {
            long dirTimestamp = parseTimeStamp(dir.getName());
            if (maxTimestamp < dirTimestamp) {
                instanceDir = dir;
                maxTimestamp = dirTimestamp;
            }
        }

        // If the most recent instance directory was generated by the required pid, use it.
        if (maxTimestamp >= 0 && pid.equals(parseProcessID(instanceDir.getName()))) {
            return instanceDir;
        }
        // PM99024 , Code fix when .lock file removed
        if (flag == true)
        {
            if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled())
            {
                debugLogger.logp(Level.FINE, thisClass, "makingLogDirectory", "no lock files found , creating folder with XXXXXX label");
            }
            instanceDir = new File(repositoryLocation, getLogDirectoryName(timestamp, pid, "XXXXXXX"));
            AccessHelper.makeDirectories(instanceDir);

            return instanceDir;
        }

        // Find lock files
        File[] lockFiles = AccessHelper.listFiles(repositoryLocation, LOCKFILE_FILTER);

        // If there's more than one lock file or a file generated by the wrong process then parent manager didn't
        //    clean up old locks yet, need to wait.
        // If there's no lock files then either parent manager didn't create one yet or somebody already
        //    deleted it to create instance directory, need to wait and try again.
        if (lockFiles.length != 1 || !pid.equals(parseProcessID(lockFiles[0].getName()))) {
            // Use System.err to report that condition since logger is not ready yet.
            if (lockFiles.length < 1) {
                if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled())
                    debugLogger.logp(Level.FINE, thisClass, "makingLogDirectory", "no lock files found.");
            } else if (lockFiles.length > 1) {
                StringBuilder sb = new StringBuilder();
                for (File lock : lockFiles) {
                    sb.append(lock.getName()).append(" ");
                }
                if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled())
                    debugLogger.logp(Level.FINE, thisClass, "makeLogDirectory", "too many lock files found: " + sb.toString());
            } else {
                if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled())
                    debugLogger.logp(Level.FINE, thisClass, "makeLogDirectory", "found stale lock file " + lockFiles[0].getName() + " but was expecting one generated by process "
                                                                                + pid);
            }
            return null;
        }

        String lockname = lockFiles[0].getName();
        // If somebody else deleted lock file right under our nose, need to wait until that somebody
        //    creates the right directory.
        if (!AccessHelper.deleteFile(lockFiles[0])) {
            if (debugLogger.isLoggable(Level.FINE) && isDebugEnabled())
                debugLogger.logp(Level.FINE, thisClass, "makeLogDirectory", "failed to delete found lock file " + lockFiles[0].getName() + ". Assume it was deleted already");
            return null;
        }

        // The lock file was deleted - call cannot return 'null' anymore without causing hang - need to create
        //     and return the new instance directory.
        String label = parseLabel(lockname.substring(0, lockname.length() - LOCK_EXT.length()));
        instanceDir = new File(repositoryLocation, getLogDirectoryName(timestamp, pid, label));
        AccessHelper.makeDirectories(instanceDir);

        return instanceDir;
    }
protected File makeLogDirectory ( long timestamp , final String pid , boolean flag ) { File instanceDir = null ; long maxTimestamp = - 1 ; for ( File dir : AccessHelper . listFiles ( repositoryLocation , new FileFilter ( ) { @ Override public boolean accept ( File pathname ) { return AccessHelper . isDirectory ( pathname ) ; } } ) ) { long dirTimestamp = parseTimeStamp ( dir . getName ( ) ) ; if ( maxTimestamp < dirTimestamp ) { instanceDir = dir ; maxTimestamp = dirTimestamp ; } } if ( maxTimestamp >= 0 && pid . equals ( parseProcessID ( instanceDir . getName ( ) ) ) ) { return instanceDir ; } if ( flag == true ) { if ( debugLogger . isLoggable ( Level . FINE ) && isDebugEnabled ( ) ) { debugLogger . logp ( Level . FINE , thisClass , "makingLogDirectory" , "no lock files found , creating folder with XXXXXX label" ) ; } instanceDir = new File ( repositoryLocation , getLogDirectoryName ( timestamp , pid , "XXXXXXX" ) ) ; AccessHelper . makeDirectories ( instanceDir ) ; return instanceDir ; } File [ ] lockFiles = AccessHelper . listFiles ( repositoryLocation , LOCKFILE_FILTER ) ; if ( lockFiles . length != 1 || ! pid . equals ( parseProcessID ( lockFiles [ 0 ] . getName ( ) ) ) ) { if ( lockFiles . length < 1 ) { if ( debugLogger . isLoggable ( Level . FINE ) && isDebugEnabled ( ) ) debugLogger . logp ( Level . FINE , thisClass , "makingLogDirectory" , "no lock files found." ) ; } else if ( lockFiles . length > 1 ) { StringBuilder sb = new StringBuilder ( ) ; for ( File lock : lockFiles ) { sb . append ( lock . getName ( ) ) . append ( " " ) ; } if ( debugLogger . isLoggable ( Level . FINE ) && isDebugEnabled ( ) ) debugLogger . logp ( Level . FINE , thisClass , "makeLogDirectory" , "too many lock files found: " + sb . toString ( ) ) ; } else { if ( debugLogger . isLoggable ( Level . FINE ) && isDebugEnabled ( ) ) debugLogger . logp ( Level . FINE , thisClass , "makeLogDirectory" , "found stale lock file " + lockFiles [ 0 ] . getName ( ) + " but was expecting one generated by process " + pid ) ; } return null ; } String lockname = lockFiles [ 0 ] . getName ( ) ; if ( ! AccessHelper . deleteFile ( lockFiles [ 0 ] ) ) { if ( debugLogger . isLoggable ( Level . FINE ) && isDebugEnabled ( ) ) debugLogger . logp ( Level . FINE , thisClass , "makeLogDirectory" , "failed to delete found lock file " + lockFiles [ 0 ] . getName ( ) + ". Assume it was deleted already" ) ; return null ; } String label = parseLabel ( lockname . substring ( 0 , lockname . length ( ) - LOCK_EXT . length ( ) ) ) ; instanceDir = new File ( repositoryLocation , getLogDirectoryName ( timestamp , pid , label ) ) ; AccessHelper . makeDirectories ( instanceDir ) ; return instanceDir ; }
creates instance directory to use for log files. Both parent and children
need to use it when figuring out the log repository location.

@param timestamp time on the first record to be stored.
@param pid process ID of the parent
@return parent's directory (kids need to create directories under it) or
<code>null</code> if directory can't be created or found due to race
condition. In the later case user need to wait and try again.