Esempio n. 1
0
 void findNextGeneration()
 {
     base.close();
     for (int i = count - 1; i > 0; i--)
     {
         if (files[i].exists())
         {
             files[i].delete();
         }
         files[i - 1].renameTo(files[i]);
     }
     try {
         output = new MeasureOutputStream(new java.io.BufferedOutputStream(
                                              new java.io.FileOutputStream(files[0])));
     } catch (java.io.FileNotFoundException e1) {
         // logging.1A=Error happened when open log file.
         this.getErrorManager().error("Error happened when open log file.", //$NON-NLS-1$
                                      e1, ErrorManager.OPEN_FAILURE);
     }
     setOutputStream(output);
 }
Esempio n. 2
0
 private void initOutputFiles()
 {
     //throws FileNotFoundException, IOException {
     while (true) {
     // try to find a unique file which is not locked by other process
     uniqueID++;
     // FIXME: improve performance here
     for (int generation = 0; generation < count; generation++) {
         // cache all file names for rotation use
         files[generation] = new java.io.File(parseFileName(generation));
     }
     fileName = files[0].getAbsolutePath();
     lock (allLocks) {
         /*
          * if current process has held lock for this fileName continue
          * to find next file
          */
         if (null != allLocks.get(fileName)) {
             continue;
         }
         if (files[0].exists()
                 && (!append || files[0].length() >= limit)) {
             for (int i = count - 1; i > 0; i--) {
                 if (files[i].exists()) {
                     files[i].delete();
                 }
                 files[i - 1].renameTo(files[i]);
             }
         }
         java.io.FileOutputStream fileStream = new java.io.FileOutputStream(fileName
                 + LCK_EXT);
         java.nio.channels.FileChannel channel = fileStream.getChannel();
         /*
          * if lock is unsupported and IOException thrown, just let the
          * IOException throws out and exit otherwise it will go into an
          * undead cycle
          */
         lockJ = channel.tryLock();
         if (null == lockJ) {
             try {
                 fileStream.close();
             } catch (Exception e) {
                 // ignore
             }
             continue;
         }
         allLocks.put(fileName, lockJ);
         break;
     }
     }
     output = new MeasureOutputStream(new java.io.BufferedOutputStream(
         new java.io.FileOutputStream(fileName, append)), files[0].length());
     setOutputStream(output);
 }
Esempio n. 3
0
        private void initOutputFiles()//throws FileNotFoundException, IOException {
        {
            while (true)
            {
                // try to find a unique file which is not locked by other process
                uniqueID++;
                // FIXME: improve performance here
                for (int generation = 0; generation < count; generation++)
                {
                    // cache all file names for rotation use
                    files[generation] = new java.io.File(parseFileName(generation));
                }
                fileName = files[0].getAbsolutePath();
                lock (allLocks) {
                    /*
                     * if current process has held lock for this fileName continue
                     * to find next file
                     */
                    if (null != allLocks.get(fileName))
                    {
                        continue;
                    }
                    if (files[0].exists() &&
                        (!append || files[0].length() >= limit))
                    {
                        for (int i = count - 1; i > 0; i--)
                        {
                            if (files[i].exists())
                            {
                                files[i].delete();
                            }
                            files[i - 1].renameTo(files[i]);
                        }
                    }
                    java.io.FileOutputStream fileStream = new java.io.FileOutputStream(fileName
                                                                                       + LCK_EXT);
                    java.nio.channels.FileChannel channel = fileStream.getChannel();

                    /*
                     * if lock is unsupported and IOException thrown, just let the
                     * IOException throws out and exit otherwise it will go into an
                     * undead cycle
                     */
                    lockJ = channel.tryLock();
                    if (null == lockJ)
                    {
                        try {
                            fileStream.close();
                        } catch (Exception e) {
                            // ignore
                        }
                        continue;
                    }
                    allLocks.put(fileName, lockJ);
                    break;
                }
            }
            output = new MeasureOutputStream(new java.io.BufferedOutputStream(
                                                 new java.io.FileOutputStream(fileName, append)), files[0].length());
            setOutputStream(output);
        }
Esempio n. 4
0
 void findNextGeneration()
 {
     base.close();
     for (int i = count - 1; i > 0; i--) {
     if (files[i].exists()) {
         files[i].delete();
     }
     files[i - 1].renameTo(files[i]);
     }
     try {
     output = new MeasureOutputStream(new java.io.BufferedOutputStream(
             new java.io.FileOutputStream(files[0])));
     } catch (java.io.FileNotFoundException e1) {
     // logging.1A=Error happened when open log file.
     this.getErrorManager().error("Error happened when open log file.", //$NON-NLS-1$
             e1, ErrorManager.OPEN_FAILURE);
     }
     setOutputStream(output);
 }