Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Schorn2008-02-22 09:24:02 -0500
committerMarkus Schorn2008-02-22 09:24:02 -0500
commit7a98d26913fa7506aec2a487f55d76e0cf85ada6 (patch)
tree48ac0df97e946fef7fab92daec317f0a5b69b286
parent04b400003bf0e56aa1bea2e43e253c03adc71c86 (diff)
downloadorg.eclipse.cdt-7a98d26913fa7506aec2a487f55d76e0cf85ada6.tar.gz
org.eclipse.cdt-7a98d26913fa7506aec2a487f55d76e0cf85ada6.tar.xz
org.eclipse.cdt-7a98d26913fa7506aec2a487f55d76e0cf85ada6.zip
ClosedChannelException when accessing the PDOM, bug 219834.
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java48
1 files changed, 43 insertions, 5 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
index 687b10c7235..690389dbb17 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/db/Database.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2007 QNX Software Systems and others.
+ * Copyright (c) 2005, 2008 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,9 +14,12 @@
package org.eclipse.cdt.internal.core.pdom.db;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
+import java.nio.channels.ClosedByInterruptException;
+import java.nio.channels.ClosedChannelException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Iterator;
@@ -61,7 +64,8 @@ import org.eclipse.core.runtime.Status;
public class Database {
private final File fLocation;
- private final RandomAccessFile fFile;
+ private final boolean fReadOnly;
+ private RandomAccessFile fFile;
private boolean fExclusiveLock= false; // necessary for any write operation
private boolean fLocked; // necessary for any operation.
private boolean fIsMarkedIncomplete= false;
@@ -99,8 +103,9 @@ public class Database {
public Database(File location, ChunkCache cache, int version, boolean openReadOnly) throws CoreException {
try {
fLocation = location;
- fFile = new RandomAccessFile(location, openReadOnly ? "r" : "rw"); //$NON-NLS-1$ //$NON-NLS-2$
+ fReadOnly= openReadOnly;
fCache= cache;
+ openFile();
int nChunksOnDisk = (int) (fFile.length() / CHUNK_SIZE);
fHeaderChunk= new Chunk(this, 0);
@@ -119,14 +124,47 @@ public class Database {
}
}
+ private void openFile() throws FileNotFoundException {
+ fFile = new RandomAccessFile(fLocation, fReadOnly ? "r" : "rw"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
void read(ByteBuffer buf, int i) throws IOException {
- fFile.getChannel().read(buf, i);
+ int retries= 0;
+ do {
+ try {
+ fFile.getChannel().read(buf, i);
+ return;
+ }
+ catch (ClosedChannelException e) {
+ // bug 219834 file may have be closed by interrupting a thread during an I/O operation.
+ reopen(e, ++retries);
+ }
+ } while (true);
}
void write(ByteBuffer buf, int i) throws IOException {
- fFile.getChannel().write(buf, i);
+ int retries= 0;
+ do {
+ try {
+ fFile.getChannel().write(buf, i);
+ return;
+ }
+ catch (ClosedChannelException e) {
+ // bug 219834 file may have be closed by interrupting a thread during an I/O operation.
+ reopen(e, ++retries);
+ }
+ } while(true);
}
+ private void reopen(ClosedChannelException e, int attempt) throws ClosedChannelException, FileNotFoundException {
+ // only if the current thread was not interrupted we try to reopen the file.
+ if (e instanceof ClosedByInterruptException || attempt >= 20) {
+ throw e;
+ }
+ openFile();
+ }
+
+
public void transferTo(FileChannel target) throws IOException {
assert fLocked;
final FileChannel from= fFile.getChannel();

Back to the top