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.replication.test.concurrent;
 
 
 import java.io.File;
 
 import javax.jcr.Node;
Created by The eXo Platform SAS.

Author(s):
Alex Reshetnyak
Version:
$Id: ConcurrentModificationTestCase.java 111 2008-11-11 11:11:11Z rainf0x $
 
 
 {

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

   
ConcurrentModificationTestCase constructor.

Parameters:
repositoryService the RepositoryService.
reposytoryName the repository name
workspaceName the workspace name
userName the user name
password the password
 
    public ConcurrentModificationTestCase(RepositoryService repositoryServiceString reposytoryName,
       String workspaceNameString userNameString password)
    {
       super(repositoryServicereposytoryNameworkspaceNameuserNamepassword);
    }

   
createContent.

Parameters:
repoPath the repository path
fileName the file name
iterations how many iterations for simple content
simpleContent the simple content
Returns:
StringBuffer return the responds {'ok', 'fail'}
 
    public StringBuffer createContent(String repoPathString fileNameLong iterationsString simpleContent)
    {
       StringBuffer sb = new StringBuffer();
 
       .info("ReplicationTestService.createContent run");
       long startend;
 
       File tempFile = null;
       try
       {
          tempFile = PrivilegedFileHelper.createTempFile("tempF""_");
          FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(tempFile);
 
          for (long i = 0; i < iterationsi++)
             fos.write(simpleContent.getBytes());
          fos.close();
 
         start = System.currentTimeMillis(); // to get the time of start
         Node cool = addNodePath(repoPath).addNode(fileName"nt:file");
         Node contentNode = cool.addNode("jcr:content""nt:resource");
         contentNode.setProperty("jcr:encoding""UTF-8");
         contentNode.setProperty("jcr:data", PrivilegedFileHelper.fileInputStream(tempFile));
         contentNode.setProperty("jcr:mimeType""application/octet-stream");
         contentNode.setProperty("jcr:lastModified".getValueFactory().createValue(Calendar.getInstance()));
         .save();
         end = System.currentTimeMillis();
         .info("The time of the adding of nt:file : " + ((end - start) / .)
            + " sec");
         sb.append("ok");
      }
      catch (Exception e)
      {
         .error("Can't save nt:file : "e);
         sb.append("fail");
      }
      finally
      {
         PrivilegedFileHelper.delete(tempFile);
      }
      return sb;
   }

   
compareData.

Parameters:
srcRepoPath the source repository path
srcFileName the source file name
destRepoPath the destination repository path
destFileName the destination file name
Returns:
StringBuffer return the responds {'ok', 'fail'}
   public StringBuffer compareData(String srcRepoPathString srcFileNameString destRepoPathString destFileName)
   {
      StringBuffer sb = new StringBuffer();
      try
      {
         Node srcNode = ((Node).getItem(getNormalizePath(srcRepoPath))).getNode(srcFileName);
         Node destNode = ((Node).getItem(getNormalizePath(destRepoPath))).getNode(destFileName);
         InputStream srcStream = srcNode.getNode("jcr:content").getProperty("jcr:data").getStream();
         InputStream destStream = destNode.getNode("jcr:content").getProperty("jcr:data").getStream();
         compareStream(srcStreamdestStream);
         .info("ReplicationTestService.startThread run");
         sb.append("ok");
      }
      catch (Exception e)
      {
         .error("Can't compare the data : "e);
         sb.append("fail");
      }
      return sb;
   }

   
startThreadUpdater. *

Parameters:
srcRepoPath the source repository path
srcFileName the source file name
destRepoPath the destination repository path
destFileName the destination file name
iterations how many iterations the thread
Returns:
StringBuffer return the responds {'ok', 'fail'}
   public StringBuffer startThreadUpdater(String srcRepoPathString srcFileNameString destRepoPath,
      String destFileNameLong iterations)
   {
      StringBuffer sb = new StringBuffer();
      try
      {
         Node srcNode = ((Node).getItem(getNormalizePath(srcRepoPath))).getNode(srcFileName);
         Node destNode = ((Node).getItem(getNormalizePath(destRepoPath))).getNode(destFileName);
         DataUpdaterThread updaterThread = new DataUpdaterThread(srcNodedestNodeiterations);
         updaterThread.start();
         .info("ReplicationTestService.startThread run");
         sb.append("ok");
      }
      catch (Exception e)
      {
         .error("Can't start the thread : "e);
         sb.append("fail");
      }
      return sb;
   }

   
The DataUpdaterThread will be update the specific property.
   class DataUpdaterThread extends Thread
   {
      
The source node.
      private final Node srcNode;

      
The destination node.
      private final Node destNode;

      
How many iterations the update property.
      private final Long iterations;

      
DataUpdaterThread constructor.

Parameters:
srcNode the source node
destNode the destination node
iterations the iteration value
      public DataUpdaterThread(Node srcNodeNode destNodeLong iterations)
      {
         this. = srcNode;
         this. = destNode;
         this. = iterations;
      }

      
      @Override
      public void run()
      {
         String destPath = null;
         try
         {
            destPath = .getPath();
            for (int i = 0; i < i++)
            {
               InputStream srcStream = .getNode("jcr:content").getProperty("jcr:data").getStream();
               .getNode("jcr:content").setProperty("jcr:data"srcStream);
               .save();
               .info(Calendar.getInstance().getTime().toGMTString() + " : ");
               
                  .info(this.getName() + " : " + "has been updated the 'nt:file' " + destPath + " : iterations == " + i);
            }
         }
         catch (RepositoryException e)
         {
            .error("Can't update the 'nt:file' " + destPath + " : "e);
         }
      }
   }
New to GrepCode? Check out our FAQ X