Permalink
Browse files

Removed aged Executor classes

  • Loading branch information...
daitangio committed Jul 1, 2017
1 parent 356accd commit 16972a9294d239ef76a34b9503713f9eaf5b466e
View
@@ -63,10 +63,13 @@ it makes me really proud.
TODO
---------------
+ Consider incorporating fixes from https://github.com/AugeoSoftware/VJDBC
+ Consider replacing
+ Replaced
de.simplicit.vjdbc.server.concurrent
with the jdk concurrent package (probably more secure).
Anyway it seems used only on an obscure
+ Code base is old but seems well written, even with a statistical log upone disconnect.
+ Code base is old and not perfect.
The config class has an executor (a bit weird....)
A statistical log is included upone disconnect.
There was some minor bad code eclipse catches (null pointer access, but only few).
View

This file was deleted.

Oops, something went wrong.
@@ -21,114 +21,118 @@
* result when nextRowPacket is called.
*/
public class ResultSetHolder {
private static Log _logger = LogFactory.getLog(ResultSetHolder.class);
private final Object _lock = new Object();
private boolean _readerThreadIsRunning = false;
private ResultSet _resultSet;
private SerializableTransport _currentSerializedRowPacket;
private ConnectionConfiguration _connectionConfiguration;
private boolean _lastPartReached;
private SQLException _lastOccurredException = null;
ResultSetHolder(ResultSet resultSet, ConnectionConfiguration config, boolean lastPartReached) throws SQLException {
_resultSet = resultSet;
_connectionConfiguration = config;
_lastPartReached = lastPartReached;
if(!_lastPartReached) {
synchronized(_lock) {
readNextRowPacket();
}
}
}
public ResultSetMetaData getMetaData() throws SQLException {
synchronized (_lock) {
return _resultSet.getMetaData();
}
}
public void close() throws SQLException {
synchronized (_lock) {
_resultSet.close();
_resultSet = null;
}
}
public SerializableTransport nextRowPacket() throws SQLException {
synchronized (_lock) {
// If the reader thread is still running we must wait
// for the lock to be released by the reader
while(_readerThreadIsRunning) {
try {
// Wait for the reader thread to finish
_lock.wait();
} catch (InterruptedException e) {
String msg = "Reader thread interrupted unexpectedly";
// Some unexpected exception occured, we must leave the loop here as the
// termination flag might not be reset to false.
_logger.error(msg, e);
_lastOccurredException = new SQLException(msg);
break;
}
}
// If any exception occured in the worker thread it will
// be delivered to the client as a normal SQL exception
if(_lastOccurredException != null) {
throw _lastOccurredException;
}
// Remember current row packet as the result
SerializableTransport result = _currentSerializedRowPacket;
// Start next reader thread
readNextRowPacket();
// Return the result
return result;
}
}
private void readNextRowPacket() throws SQLException {
if(_resultSet != null && !_lastPartReached) {
// Start the thread
try {
_connectionConfiguration.execute(new Runnable() {
public void run() {
// Aquire lock immediately
synchronized (_lock) {
try {
// When the ResultSet is null here, the client closed the ResultSet concurrently right
// after the upper check "_resultSet != null".
if(_resultSet != null) {
RowPacket rowPacket = new RowPacket(_connectionConfiguration.getRowPacketSize(), false);
// Populate the new RowPacket using the ResultSet
_lastPartReached = rowPacket.populate(_resultSet);
_currentSerializedRowPacket = new SerializableTransport(rowPacket, _connectionConfiguration.getCompressionModeAsInt(),
_connectionConfiguration.getCompressionThreshold());
}
} catch (SQLException e) {
// Just remember the exception, it will be thrown at
// the next call to nextRowPacket
_lastOccurredException = e;
} finally {
_readerThreadIsRunning = false;
// Notify possibly waiting subsequent Readers
_lock.notify();
}
}
}
});
// Set the flag that the reader thread is considered to be running.
_readerThreadIsRunning = true;
} catch (InterruptedException e) {
String msg = "Reader thread interrupted unexpectedly";
_logger.error(msg, e);
throw new SQLException(msg);
}
} else {
_currentSerializedRowPacket = null;
}
}
private static Log _logger = LogFactory.getLog(ResultSetHolder.class);
private final Object _lock = new Object();
private boolean _readerThreadIsRunning = false;
private ResultSet _resultSet;
private SerializableTransport _currentSerializedRowPacket;
private ConnectionConfiguration _connectionConfiguration;
private boolean _lastPartReached;
private SQLException _lastOccurredException = null;
ResultSetHolder(ResultSet resultSet, ConnectionConfiguration config, boolean lastPartReached) throws SQLException {
_resultSet = resultSet;
_connectionConfiguration = config;
_lastPartReached = lastPartReached;
if(!_lastPartReached) {
synchronized(_lock) {
readNextRowPacket();
}
}
}
public ResultSetMetaData getMetaData() throws SQLException {
synchronized (_lock) {
return _resultSet.getMetaData();
}
}
public void close() throws SQLException {
synchronized (_lock) {
_resultSet.close();
_resultSet = null;
}
}
public SerializableTransport nextRowPacket() throws SQLException {
synchronized (_lock) {
// If the reader thread is still running we must wait
// for the lock to be released by the reader
while(_readerThreadIsRunning) {
try {
// Wait for the reader thread to finish
_lock.wait();
} catch (InterruptedException e) {
String msg = "Reader thread interrupted unexpectedly";
// Some unexpected exception occured, we must leave the loop here as the
// termination flag might not be reset to false.
_logger.error(msg, e);
_lastOccurredException = new SQLException(msg);
break;
}
}
// If any exception occured in the worker thread it will
// be delivered to the client as a normal SQL exception
if(_lastOccurredException != null) {
throw _lastOccurredException;
}
// Remember current row packet as the result
SerializableTransport result = _currentSerializedRowPacket;
// Start next reader thread
readNextRowPacket();
// Return the result
return result;
}
}
private void readNextRowPacket() throws SQLException {
if(_resultSet != null && !_lastPartReached) {
// Start the thread
try {
_connectionConfiguration.execute(new Runnable() {
@Override
public void run() {
// Aquire lock immediately
synchronized (_lock) {
try {
// When the ResultSet is null here, the client closed the ResultSet concurrently right
// after the upper check "_resultSet != null".
if(_resultSet != null) {
RowPacket rowPacket = new RowPacket(_connectionConfiguration.getRowPacketSize(), false);
// Populate the new RowPacket using the ResultSet
_lastPartReached = rowPacket.populate(_resultSet);
_currentSerializedRowPacket = new SerializableTransport(rowPacket, _connectionConfiguration.getCompressionModeAsInt(),
_connectionConfiguration.getCompressionThreshold());
}
} catch (SQLException e) {
// Just remember the exception, it will be thrown at
// the next call to nextRowPacket
_lastOccurredException = e;
} finally {
_readerThreadIsRunning = false;
// Notify possibly waiting subsequent Readers
_lock.notify();
}
}
}
});
// Set the flag that the reader thread is considered to be running.
_readerThreadIsRunning = true;
// _GG_ JDK Executor service never throws this
// } catch (InterruptedException e) {
// String msg = "Reader thread interrupted unexpectedly";
// _logger.error(msg, e);
// throw new SQLException(msg);
}finally {
}
} else {
_currentSerializedRowPacket = null;
}
}
}

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 16972a9

Please sign in to comment.