avoided using a synchronized(this) for the hash computation to prevent that the lock on the object is (accidently) stolen by another thread and replaced this synchronization using the protocol object. Made also the protocol object final.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7602 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 14 years ago
parent c2a968c23f
commit 61acf55da4

@ -146,7 +146,8 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
} }
// class variables // class variables
protected String protocol, host, userInfo, path, quest, ref; protected final String protocol, userInfo;
protected String host, path, quest, ref;
protected int port; protected int port;
/** /**
@ -176,24 +177,9 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
this.port = url.port; this.port = url.port;
} }
public MultiProtocolURI(final String url) throws MalformedURLException { public MultiProtocolURI(String url) throws MalformedURLException {
if (url == null) throw new MalformedURLException("url string is null"); if (url == null) throw new MalformedURLException("url string is null");
parseURLString(url);
}
public static final boolean isHTTP(String s) { return s.startsWith("http://"); }
public static final boolean isHTTPS(String s) { return s.startsWith("https://"); }
public static final boolean isFTP(String s) { return s.startsWith("ftp://"); }
public static final boolean isFile(String s) { return s.startsWith("file://"); }
public static final boolean isSMB(String s) { return s.startsWith("smb://") || s.startsWith("\\\\"); }
public final boolean isHTTP() { return this.protocol.equals("http"); }
public final boolean isHTTPS() { return this.protocol.equals("https"); }
public final boolean isFTP() { return this.protocol.equals("ftp"); }
public final boolean isFile() { return this.protocol.equals("file"); }
public final boolean isSMB() { return this.protocol.equals("smb"); }
private void parseURLString(String url) throws MalformedURLException {
// identify protocol // identify protocol
assert (url != null); assert (url != null);
url = url.trim(); url = url.trim();
@ -263,7 +249,7 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
port = -1; port = -1;
quest = null; quest = null;
ref = null; ref = null;
} if (protocol.equals("file")) { } else if (protocol.equals("file")) {
// parse file url // parse file url
String h = url.substring(p + 1); String h = url.substring(p + 1);
if (h.startsWith("//")) { if (h.startsWith("//")) {
@ -315,6 +301,18 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
} catch (final PunycodeException e) {} } catch (final PunycodeException e) {}
} }
public static final boolean isHTTP(String s) { return s.startsWith("http://"); }
public static final boolean isHTTPS(String s) { return s.startsWith("https://"); }
public static final boolean isFTP(String s) { return s.startsWith("ftp://"); }
public static final boolean isFile(String s) { return s.startsWith("file://"); }
public static final boolean isSMB(String s) { return s.startsWith("smb://") || s.startsWith("\\\\"); }
public final boolean isHTTP() { return this.protocol.equals("http"); }
public final boolean isHTTPS() { return this.protocol.equals("https"); }
public final boolean isFTP() { return this.protocol.equals("ftp"); }
public final boolean isFile() { return this.protocol.equals("file"); }
public final boolean isSMB() { return this.protocol.equals("smb"); }
public static MultiProtocolURI newURL(final String baseURL, final String relPath) throws MalformedURLException { public static MultiProtocolURI newURL(final String baseURL, final String relPath) throws MalformedURLException {
if ((baseURL == null) || if ((baseURL == null) ||
isHTTP(relPath) || isHTTP(relPath) ||
@ -399,6 +397,9 @@ public class MultiProtocolURI implements Serializable, Comparable<MultiProtocolU
this.host = host; this.host = host;
this.port = port; this.port = port;
this.path = path; this.path = path;
this.quest = "";
this.userInfo = "";
this.ref = "";
identRef(); identRef();
identQuest(); identQuest();
escape(); escape();

@ -154,7 +154,7 @@ public class DigestURI extends MultiProtocolURI implements Serializable {
// in case that the object was initialized without a known url hash, compute it now // in case that the object was initialized without a known url hash, compute it now
if (this.hash == null) { if (this.hash == null) {
// we check the this.hash value twice to avoid synchronization where possible // we check the this.hash value twice to avoid synchronization where possible
synchronized (this) { synchronized (this.protocol) {
if (this.hash == null) this.hash = urlHashComputation(); if (this.hash == null) this.hash = urlHashComputation();
} }
} }
@ -322,7 +322,7 @@ public class DigestURI extends MultiProtocolURI implements Serializable {
@Override @Override
public final boolean isLocal() { public final boolean isLocal() {
if (this.isFile()) return true; if (this.isFile()) return true;
if (this.hash == null) synchronized (this) { if (this.hash == null) synchronized (this.protocol) {
// this is synchronized because another thread may also call the same method in between // this is synchronized because another thread may also call the same method in between
// that is the reason that this.hash is checked again // that is the reason that this.hash is checked again
if (this.hash == null) this.hash = urlHashComputation(); if (this.hash == null) this.hash = urlHashComputation();

Loading…
Cancel
Save