removed call to class.finalize() because of deprecation in java 9

next: removal of finalize() implementation
after testing with assert false
pull/419/head
Michael Peter Christen 4 years ago
parent 9ef4503672
commit 9e13d77de4

@ -152,7 +152,6 @@ public class Handler implements IInArchive {
protected void finalize() throws Throwable {
close();
super.finalize();
}
public void close() throws IOException {

@ -58,16 +58,16 @@ public class NoticedURL {
/** links found by crawling to depth-1 */
private Balancer coreStack;
/** links found by crawling at target depth */
private Balancer limitStack;
/** links from remote crawl orders (init on demand) */
private Balancer remoteStack;
/** links that are not passed to a loader; the index will be generated from the Request entry */
private Balancer noloadStack;
private final File cachePath;
protected NoticedURL(
@ -82,7 +82,7 @@ public class NoticedURL {
this.limitStack = new HostBalancer(new File(cachePath, "CrawlerLimitStacks"), onDemandLimit, exceed134217727);
this.remoteStack = null; // init on demand (on first push)
ConcurrentLog.info("NoticedURL", "opening CrawlerNoLoadStacks..");
this.noloadStack = new HostBalancer(new File(cachePath, "CrawlerNoLoadStacks"), onDemandLimit, exceed134217727);
ConcurrentLog.info("NoticedURL", "FINISHED CREATING STACKS at " + cachePath.toString());
@ -131,9 +131,8 @@ public class NoticedURL {
protected void finalize() throws Throwable {
if ((this.coreStack != null) || (this.limitStack != null) || (this.remoteStack != null)) {
ConcurrentLog.warn("plasmaCrawlNURL", "NURL stack closed by finalizer");
close();
this.close();
}
super.finalize();
}
public int size() {
@ -147,9 +146,9 @@ public class NoticedURL {
if (!this.noloadStack.isEmpty()) return false;
return true;
}
public boolean isEmpty() {
if (!isEmptyLocal()) return false;
if (!this.isEmptyLocal()) return false;
if (this.remoteStack != null && !this.remoteStack.isEmpty()) return false;
return true;
}
@ -163,7 +162,7 @@ public class NoticedURL {
default: return true;
}
}
public int stackSize(final StackType stackType) {
switch (stackType) {
case NOLOAD: return (this.noloadStack == null) ? 0 : this.noloadStack.size();
@ -299,9 +298,9 @@ public class NoticedURL {
protected void shift(final StackType fromStack, final StackType toStack, final CrawlSwitchboard cs, final RobotsTxt robots) {
try {
final Request entry = pop(fromStack, false, cs, robots);
final Request entry = this.pop(fromStack, false, cs, robots);
if (entry != null) {
final String warning = push(toStack, entry, null, robots);
final String warning = this.push(toStack, entry, null, robots);
if (warning != null) {
ConcurrentLog.warn("NoticedURL", "shift from " + fromStack + " to " + toStack + ": " + warning);
}
@ -346,15 +345,15 @@ public class NoticedURL {
// it may be possible that another process has taken all
s = balancer.size(); // this time read the size to find errors
if (s == 0) return null; // the balancer is actually empty!
// if the balancer is not empty, try again
entry = balancer.pop(delay, cs, robots);
if (entry != null) return entry;
if (s > balancer.size()) continue; // the balancer has shrinked, thats good, it will terminate
errors++; // bad, if the size does not shrink we are in danger to not terminate
if (errors < 100) continue; // there is the possibility that it is not a bug but concurrency, so just ignore it for some time
// at this point we consider the balancer to be broken
final int aftersize = balancer.size(); // get the amount of data that we loose
balancer.clear(); // the balancer is broken and cannot shrink

@ -1,4 +1,4 @@
// CachedFileReader.java
// CachedFileReader.java
// ---------------------
// (C) 2009 by Michael Peter Christen; mc@yacy.net
// first published 09.09.2009 on http://yacy.net
@ -48,10 +48,10 @@ public final class CachedFileReader extends AbstractReader implements Reader {
}
this.cachelen = 0;
}
@Override
public final synchronized long available() throws IOException {
return this.length() - RAFile.getFilePointer();
return this.length() - this.RAFile.getFilePointer();
}
@Override
@ -61,28 +61,28 @@ public final class CachedFileReader extends AbstractReader implements Reader {
@Override
public final synchronized void readFully(final byte[] b, final int off, int len) throws IOException {
long seek = RAFile.getFilePointer();
if (cache != null && cachelen - seek >= len) {
final long seek = this.RAFile.getFilePointer();
if (this.cache != null && this.cachelen - seek >= len) {
// read from cache
System.arraycopy(cache, (int) (seek), b, off, len);
RAFile.seek(seek + len);
System.arraycopy(this.cache, (int) (seek), b, off, len);
this.RAFile.seek(seek + len);
return;
}
// cannot use the cache
RAFile.readFully(b, off, len);
this.RAFile.readFully(b, off, len);
return;
}
@Override
public final synchronized void seek(final long pos) throws IOException {
RAFile.seek(pos);
this.RAFile.seek(pos);
}
@Override
public final synchronized void close() {
if (RAFile != null) try {
try{RAFile.getChannel().close();} catch (final IOException e) {}
RAFile.close();
if (this.RAFile != null) try {
try{this.RAFile.getChannel().close();} catch (final IOException e) {}
this.RAFile.close();
} catch (final IOException e) {
ConcurrentLog.logException(e);
}
@ -92,7 +92,6 @@ public final class CachedFileReader extends AbstractReader implements Reader {
@Override
protected void finalize() throws Throwable {
this.close();
super.finalize();
}
}

@ -1,4 +1,4 @@
// CachedFileWriter.java
// CachedFileWriter.java
// ---------------------------------
// part of The Kelondro Database
// (C) by Michael Peter Christen; mc@yacy.net
@ -46,31 +46,31 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
this.cache = new byte[32768];
this.cachestart = 0;
this.cachelen = 0;
}
}
@Override
public final synchronized long length() throws IOException {
checkReopen();
this.checkReopen();
return this.RAFile.length();
}
@Override
public final synchronized void setLength(long length) throws IOException {
checkReopen();
this.checkReopen();
this.cachelen = 0;
this.RAFile.setLength(length);
}
@Override
public final synchronized long available() throws IOException {
checkReopen();
this.checkReopen();
return this.length() - this.RAFile.getFilePointer();
}
@Override
public final synchronized void readFully(final byte[] b, final int off, int len) throws IOException {
checkReopen();
long seek = this.RAFile.getFilePointer();
this.checkReopen();
final long seek = this.RAFile.getFilePointer();
if (this.cache != null && this.cachestart <= seek && this.cachelen - seek + this.cachestart >= len) {
// read from cache
//System.out.println("*** DEBUG FileRA " + this.file.getName() + ": CACHE HIT at " + seek);
@ -84,7 +84,7 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
return;
}
// we fill the cache here
long available = this.RAFile.length() - seek;
final long available = this.RAFile.length() - seek;
if (available == -seek) return; // we don't know how this happens but we just silently ignore it by now TODO:fixme
//System.out.println("*** available = " + available);
if (available < len) throw new IOException("EOF in " + this.file.getName() + ", available = " + available + ", requested = " + len + ", this.RAFile.length() = " + this.RAFile.length() + ", seek = " + seek);
@ -95,7 +95,7 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
this.cachelen += len;
} else {
// fill the cache as much as possible
int m = (int) Math.min(available, this.cache.length);
final int m = (int) Math.min(available, this.cache.length);
this.RAFile.readFully(this.cache, 0, m);
this.cachestart = seek;
this.cachelen = m;
@ -103,22 +103,22 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
//System.out.println("*** DEBUG FileRA " + this.file.getName() + ": replace fill " + len + " bytes");
System.arraycopy(this.cache, 0, b, off, len);
}
}
@Override
public final synchronized void write(final byte[] b, final int off, final int len) throws IOException {
checkReopen();
this.checkReopen();
//assert len > 0;
// write to file
if (this.cache.length > 512) {
// the large cache is only useful during an initialization phase
byte[] newcache = new byte[512];
final byte[] newcache = new byte[512];
System.arraycopy(this.cache, 0, newcache, 0, newcache.length);
this.cache = newcache;
if (this.cachelen > this.cache.length) this.cachelen = this.cache.length;
}
long seekpos = this.RAFile.getFilePointer();
final long seekpos = this.RAFile.getFilePointer();
if (this.cachelen + len <= this.cache.length && this.cachestart + this.cachelen == seekpos) {
// append to cache
System.arraycopy(b, off, this.cache, this.cachelen, len);
@ -139,7 +139,7 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
@Override
public final synchronized void seek(final long pos) throws IOException {
checkReopen();
this.checkReopen();
this.RAFile.seek(pos);
}
@ -156,7 +156,7 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
this.cache = null;
this.RAFile = null;
}
private final void checkReopen() {
if (this.RAFile != null) return;
// re-open the file
@ -173,7 +173,6 @@ public final class CachedFileWriter extends AbstractWriter implements Writer {
@Override
protected final void finalize() throws Throwable {
this.close();
super.finalize();
}
}

@ -120,22 +120,22 @@ public final class RandomAccessIO {
public final synchronized void writeSpace(long pos, int spaceCount) throws IOException {
if (spaceCount < 512) {
write(pos, space(spaceCount));
this.write(pos, space(spaceCount));
return;
}
byte[] b = space(512);
final byte[] b = space(512);
while (spaceCount > b.length) {
write(pos, b);
this.write(pos, b);
pos += b.length;
spaceCount -= b.length;
}
if (spaceCount > 0) {
write(pos, space(spaceCount));
this.write(pos, space(spaceCount));
}
}
private final static byte[] space(int count) {
byte[] s = new byte[count];
final byte[] s = new byte[count];
while (count-- > 0) s[count] = 0;
return s;
}
@ -147,7 +147,6 @@ public final class RandomAccessIO {
@Override
protected final void finalize() throws Throwable {
if (this.ra != null) this.close();
super.finalize();
}
public final void deleteOnExit() {

Loading…
Cancel
Save