Author: scabanovich
Date: 2010-10-25 05:54:30 -0400 (Mon, 25 Oct 2010)
New Revision: 26020
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/TestJarAccess.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
Log:
JBIDE-7399
https://jira.jboss.org/browse/JBIDE-7399
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java 2010-10-25
09:39:51 UTC (rev 26019)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/JarAccess.java 2010-10-25
09:54:30 UTC (rev 26020)
@@ -15,10 +15,12 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipEntry;
@@ -45,14 +47,20 @@
private long timeStamp = -1;
private long size = -1;
+ List<String> errors = new ArrayList<String>();
+
public JarAccess() {}
+ public List<String> getErrors() {
+ return errors;
+ }
+
public void setLocation(String location) {
this.location = location;
validate();
}
- public void lockJar() {
+ public synchronized void lockJar() {
jarLock++;
}
@@ -129,9 +137,9 @@
}
public void unlockJar() {
- jarLock--;
- if(jarLock > 0 || jar == null) return;
synchronized (this) {
+ jarLock--;
+ if(jarLock > 0 || jar == null) return;
if(jar != null && jarLock == 0) {
try {
jar.close();
@@ -203,6 +211,7 @@
ZipEntry entry = jar.getEntry(path);
if(entry == null) {
String error = "JarAccess: cannot obtain entry for path '" + path +
"' from jar '" + location + "'.";
//$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
+ errors.add(error);
ModelPlugin.getDefault().logError(error);
return ""; //$NON-NLS-1$
}
@@ -227,6 +236,7 @@
}
return sb.toString();
} catch (IOException e) {
+ errors.add(e.getClass().getName() + ": " + e.getMessage());
ModelPlugin.getPluginLog().logError(e);
return ""; //$NON-NLS-1$
} finally {
Added:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/TestJarAccess.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/TestJarAccess.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/TestJarAccess.java 2010-10-25
09:54:30 UTC (rev 26020)
@@ -0,0 +1,79 @@
+package org.jboss.tools.common.model.filesystems.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.common.model.XModelObjectConstants;
+
+public class TestJarAccess {
+ int threadCount = 10;
+ JarAccess acc = new JarAccess();
+
+ List<String> errors = new ArrayList<String>();
+
+ public TestJarAccess(String location) {
+ acc.setLocation(location);
+ }
+
+ public void runAll() {
+ Thread[] ts = new Thread[threadCount];
+ for (int i = 0; i < threadCount; i++) {
+ Runner r = new Runner(i);
+ Thread t = new Thread(r);
+ t.start();
+ ts[i] = t;
+ }
+ boolean b = true;
+ while(b) {
+ b = false;
+ for (int i = 0; i < threadCount; i++) {
+ if(ts[i].isAlive()) b = true;
+ }
+ if(b) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public List<String> getErrors() {
+ errors.addAll(acc.getErrors());
+ return errors;
+ }
+
+ class Runner implements Runnable {
+ int id;
+
+ public Runner(int id) {
+ this.id = id;
+ }
+ public void run() {
+ try {
+ for (int i = 0; i < 100; i++) {
+ readAllFiles("");
+ }
+ } catch (Exception e) {
+ errors.add(e.getClass().getName() + ": " + e.getMessage());
+ }
+ }
+
+ }
+
+ void readAllFiles(String path) {
+ String[] ps = acc.getChildren(path);
+ String parentPath = (path.length() == 0) ? "" : path +
XModelObjectConstants.SEPARATOR;
+ if(ps != null) for (int i = 0; i < ps.length; i++) {
+ boolean d = ps[i].endsWith(XModelObjectConstants.SEPARATOR);
+ if(d) ps[i] = ps[i].substring(0, ps[i].length() - 1);
+ if(d) {
+ readAllFiles(parentPath + ps[i]);
+ } else {
+ acc.getContent(parentPath + ps[i]);
+ }
+ }
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/filesystems/impl/TestJarAccess.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain