better stream close handling in couchdb river

This commit is contained in:
kimchy 2010-12-30 12:25:50 +02:00
parent ed996c3e85
commit f4a30fdc84

View File

@ -361,6 +361,9 @@ public class CouchdbRiver extends AbstractRiverComponent implements River {
final BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
if (closed) {
return;
}
if (line.length() == 0) {
logger.trace("[couchdb] heartbeat");
continue;
@ -376,6 +379,8 @@ public class CouchdbRiver extends AbstractRiverComponent implements River {
is.close();
} catch (IOException e1) {
// ignore
} finally {
is = null;
}
}
if (connection != null) {
@ -383,6 +388,8 @@ public class CouchdbRiver extends AbstractRiverComponent implements River {
connection.disconnect();
} catch (Exception e1) {
// ignore
} finally {
connection = null;
}
}
if (closed) {
@ -396,6 +403,25 @@ public class CouchdbRiver extends AbstractRiverComponent implements River {
return;
}
}
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e1) {
// ignore
} finally {
is = null;
}
}
if (connection != null) {
try {
connection.disconnect();
} catch (Exception e1) {
// ignore
} finally {
connection = null;
}
}
}
}
}