Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.exoplatform.services.jcr.ext.backup.impl;
 
 
 import java.io.File;
 import java.util.List;

Created by The eXo Platform SAS.

Author(s):
Alex Reshetnyak
Version:
$Id: PendingChangesLog.java 31768 2009-05-14 09:35:43Z pnedonosko $
 
 
 public class PendingChangesLog
 {

   
The apache logger.
 
    private static final Log LOG = ExoLogger.getLogger("exo.jcr.component.ext.PendingChangesLog");

   
The definition of ChangesLog types.
 
    public final class Type
    {
      
CHANGESLOG_WITHOUT_STREAM. The the type fore ChangesLog without streams.
 
       public static final int CHANGESLOG_WITHOUT_STREAM = 1;

      
CHANGESLOG_WITH_STREAM. The the type fore ChangesLog with streams.
 
       public static final int CHANGESLOG_WITH_STREAM = 2;

      
Empty constructor.
 
       private Type()
       {
       }
    }

   
Minimal sleep timeout.
 
    private static final int SLEEP_TIME = 5;

   
ChangesLog with data.
 
The list of input streams who are contains in ChangesLog.
 
    private List<InputStreamlistInputStream;

   
The list of RandomAccessFiles who ate contains in ChangesLog.
Type of ChangesLog (CHANGESLOG_WITHOUT_STREAM or CHANGESLOG_WITH_STREAM).
   private int containerType;

   
The list of FixupStreams who are indicate the location the input streams in ChangesLog.
   // private HashMap<FixupStream, RandomAccessFile> mapFixupStream;

   
The list of Files who are contains in ChangesLog.
   private List<SpoolFilelistFile;

   
The identification string for PendingChangesLog.
   private String identifier;

   
The FileCleaner will delete the temporary files.
   private FileCleaner fileCleaner;

   
The arrays of bytes for serialized ChangesLog without streams.
   private byte[] data;

   
Temporary directory;
   private final File tempDir;

   
PendingChangesLog constructor.

Parameters:
itemDataChangesLog ChangesLog with data
fileCleaner the FileCleaner
Throws:
java.io.IOException will be generated the IOExaption
   public PendingChangesLog(TransactionChangesLog itemDataChangesLogFileCleaner fileCleanerthrows IOException
   {
      this. = itemDataChangesLog;
       = new ArrayList<InputStream>();
       = new ArrayList<FixupStream>();
       = new ArrayList<SpoolFile>();
       = IdGenerator.generate();
      this. = fileCleaner;
      this. = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
   }

   
PendingChangesLog constructor.

Parameters:
itemDataChangesLog ChangesLog with data
identifier identifier to this PendingChangesLog.
type type of PendingChangesLog
fileCleaner the FileCleaner
Throws:
java.io.IOException will be generated the IOExaption
   public PendingChangesLog(TransactionChangesLog itemDataChangesLogString identifierint type,
      FileCleaner fileCleanerthrows IOException
   {
      this. = itemDataChangesLog;
       = new ArrayList<InputStream>();
       = new ArrayList<FixupStream>();
       = new ArrayList<SpoolFile>();
      this. = identifier;
       = type;
      this. = fileCleaner;
      this. = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
   }

   
PendingChangesLog constructor.

Parameters:
identifier identifier to this PendingChangesLog.
dataLength the length of binary data
   public PendingChangesLog(String identifierint dataLength)
   {
      this. = identifier;
       = new byte[dataLength];
      this. = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
   }

   
PendingChangesLog constructor.

Parameters:
transactionChangesLog ChangesLog with data
listFixupStreams list of FixupStreams
listFiles list of Files
fileCleaner the FileCleaner
   public PendingChangesLog(TransactionChangesLog transactionChangesLogList<FixupStreamlistFixupStreams,
      List<SpoolFilelistFilesFileCleaner fileCleaner)
   {
      this. = transactionChangesLog;
      this. = listFixupStreams;
      this. = listFiles;
      this. = fileCleaner;
      this. = new File(PrivilegedSystemHelper.getProperty("java.io.tmpdir"));
   }

   
putData.

Parameters:
offset offset in 'data'
tempData piece of binary data
   public void putData(int offsetbyte[] tempData)
   {
      for (int i = 0; i < tempData.lengthi++)
         [i + offset] = tempData[i];
   }

   
getData.

Returns:
byte[] return the binary data
   public byte[] getData()
   {
      return ;
   }

   
getItemDataChangesLog.

Returns:
TransactionChangesLog return the ChangesLog
   {
      return ;
   }

   
getInputStreams.

Returns:
List return the list of input streams
   {
      return ;
   }

   
getListRandomAccessFiles.

Returns:
List return the list of RandomAccessFiles
   {
      return ;
   }

   
getListFile.

Returns:
List return list of Files
   public List<SpoolFilegetListFile()
   {
      return ;
   }

   
getFixupStreams.

Returns:
List return list of FixupStreams
   {
      return ;
   }

   
analysisItemDataChangesLog.

Returns:
int type of ChangesLog (CHANGESLOG_WITHOUT_STREAM or CHANGESLOG_WITH_STREAM)
Throws:
java.io.IOException will be generated the IOException
   private int analysisItemDataChangesLog() throws IOException
   {
      int itemDataChangesLogType = ..;
      int i = 0;
      for (ItemState itemState : .getAllStates())
      {
         ItemData itemData = itemState.getData();
         if (itemData instanceof PersistedPropertyData)
         {
            PersistedPropertyData propertyData = (PersistedPropertyData)itemData;
            if ((propertyData.getValues() != null))
               for (int j = 0; j < propertyData.getValues().size(); j++)
                  if (!(propertyData.getValues().get(j).isByteArray()))
                  {
                     .add(new FixupStream(ij));
                     InputStream inputStream;
                     if (itemState.isDeleted())
                        inputStream = new ByteArrayInputStream("".getBytes());
                     else
                        inputStream = propertyData.getValues().get(j).getAsStream();
                     .add(inputStream);
                     itemDataChangesLogType = ..;
                  }
         }
         i++;
      }
      return itemDataChangesLogType;
   }

   
getConteinerType.

Returns:
int return the type of ChangesLog
   public int getConteinerType()
   {
      return ;
   }

   
getIdentifier.

Returns:
String return the identifier string
   public String getIdentifier()
   {
      return ;
   }

   
getAsByteArray. Make the array of bytes from ChangesLog.

Parameters:
dataChangesLog the ChangesLog with data
Returns:
byte[] return the serialized ChangesLog
Throws:
java.io.IOException will be generated the IOException
   public static byte[] getAsByteArray(TransactionChangesLog dataChangesLogthrows IOException
   {
      ObjectOutputStream oos = new ObjectOutputStream(os);
      oos.writeObject(dataChangesLog);
      byte[] bArray = os.toByteArray();
      return bArray;
   }

   
getAsItemDataChangesLog. Make the ChangesLog from array of bytes.

Parameters:
byteArray the serialized ChangesLog
Returns:
TransactionChangesLog return the deserialized ChangesLog
Throws:
java.io.IOException will be generated the IOException
java.lang.ClassNotFoundException will be generated the ClassNotFoundException
   public static TransactionChangesLog getAsItemDataChangesLog(byte[] byteArraythrows IOException,
   {
      ByteArrayInputStream is = new ByteArrayInputStream(byteArray);
      ObjectInputStream ois = new ObjectInputStream(is);
      return objRead;
   }

   
getRandomAccessFile.

Parameters:
fs the FixupStream
Returns:
RandomAccessFile return the RandomAccessFile by FixupStream
Throws:
java.io.IOException will be generated the IOException
   {
      int i = 0;
      try
      {
         for (i = 0; i < .size(); i++)
            if (this..get(i).compare(fs))
               return .get(i);
      }
      catch (IndexOutOfBoundsException e)
      {
         try
         {
            Thread.sleep();
            return .get(i);
         }
         catch (InterruptedException ie)
         {
            .error("The interrupted exceptio : "ie);
         }
         catch (IndexOutOfBoundsException ioobe)
         {
            if (.isDebugEnabled())
            {
               .info("listFixupStream.size() == " + .size());
               .info("listRandomAccessFile.size() == " + .size());
               .info(" i == " + i);
            }
            synchronized (this)
            {
               if (.size() > i)
               {
                  .remove(i);
               }
               .remove(i);
               addNewStream(fs);
               getRandomAccessFile(fs);
            }
         }
      }
      return null;
   }

   
addNewStream.

Parameters:
fs the FixupStream
Throws:
java.io.IOException will be generated the IOException
   public void addNewStream(FixupStream fsthrows IOException
   {
      this.getFixupStreams().add(fs);
      SpoolFile f = SpoolFile.createTempFile("tempFile" + IdGenerator.generate(), ".tmp");
      this.getListFile().add(f);
      this.getListRandomAccessFiles().add(PrivilegedFileHelper.randomAccessFile(f"rw"));
   }

   
Restore ChangesLog(set the InputStreams to ValueData).

Throws:
java.io.IOException will be generated the IOException
   public void restore() throws IOException
   {
      List<ItemStatelistItemState = .getAllStates();
      for (int i = 0; i < this..size(); i++)
      {
         ItemState itemState = listItemState.get(.get(i).getItemSateId());
         ItemData itemData = itemState.getData();
         PersistedPropertyData propertyData = (PersistedPropertyData)itemData;
         ValueData vd = (propertyData.getValues().get(.get(i).getValueDataId()));
         // re-init the value
         propertyData.getValues().set(.get(i).getValueDataId(),
            new StreamPersistedValueData(vd.getOrderNumber(), .get(i)));
      }
      if ( != null)
         for (int i = 0; i < .size(); i++)
            .get(i).close();
      for (int i = 0; i < .size(); i++)
         .addFile(.get(i));
   }
New to GrepCode? Check out our FAQ X