@Override public void onIOError(Exception exception, String message, SequentialFile file) { criticalErrorListener.onIOException(exception, message, file); }
@Override public void onIOError(Exception exception, String message, SequentialFile file) { if (critialErrorListener != null) { critialErrorListener.onIOException(exception, message, file); } else { logger.warn("Critical IO Error Called. No Critical IO Error Handler Registered::" + message + " at file " + file, exception); } }
@Override public void onIOError(Exception exception, String message, SequentialFile file) { if (critialErrorListener != null) { critialErrorListener.onIOException(exception, message, file); } else { logger.warn("Critical IO Error Called. No Critical IO Error Handler Registered::" + message + " at file " + file, exception); } }
@Override public void criticalError(Throwable error) { ioCriticalErrorListener.onIOException(error, error.getMessage(), null); }
@Override public void flush() { for (SequentialFile file : files) { try { file.sync(); } catch (Exception e) { criticalErrorListener.onIOException(e, "Error during JDBC file sync.", file); } } }
public JDBCSequentialFileFactory(final String connectionUrl, final String className, final SQLProvider sqlProvider, Executor executor, IOCriticalErrorListener criticalErrorListener) throws Exception { this.executor = executor; this.criticalErrorListener = criticalErrorListener; try { this.dbDriver = JDBCFileUtils.getDBFileDriver(className, connectionUrl, sqlProvider); } catch (SQLException e) { criticalErrorListener.onIOException(e, "Failed to start JDBC Driver", null); } }
@Override public synchronized void start() { try { if (!started) { dbDriver.start(); started = true; } } catch (Exception e) { criticalErrorListener.onIOException(e, "Unable to start database driver", null); started = false; } }
@Override public List<String> listFiles(String extension) throws Exception { try { return dbDriver.listFiles(extension); } catch (SQLException e) { criticalErrorListener.onIOException(e, "Error listing JDBC files.", null); throw e; } }
public JDBCSequentialFileFactory(final DataSource dataSource, final SQLProvider sqlProvider, Executor executor, IOCriticalErrorListener criticalErrorListener) throws Exception { this.executor = executor; this.criticalErrorListener = criticalErrorListener; try { this.dbDriver = JDBCFileUtils.getDBFileDriver(dataSource, sqlProvider); } catch (SQLException e) { criticalErrorListener.onIOException(e, "Failed to start JDBC Driver", null); } }
public JDBCSequentialFileFactory(final Connection connection, final SQLProvider sqlProvider, final Executor executor, final IOCriticalErrorListener criticalErrorListener) throws Exception { this.executor = executor; this.criticalErrorListener = criticalErrorListener; try { this.dbDriver = JDBCFileUtils.getDBFileDriver(connection, sqlProvider); } catch (SQLException e) { criticalErrorListener.onIOException(e, "Failed to start JDBC Driver", null); } }
@Override public SequentialFile createSequentialFile(String fileName) { try { fileLocks.putIfAbsent(fileName, new Object()); JDBCSequentialFile file = new JDBCSequentialFile(this, fileName, executor, dbDriver, fileLocks.get(fileName)); files.add(file); return file; } catch (Exception e) { criticalErrorListener.onIOException(e, "Error whilst creating JDBC file", null); } return null; }
private void criticalIO(Throwable e) throws Exception { if (criticalErrorListener != null) { criticalErrorListener.onIOException(e, e.getMessage(), currentFile == null ? null : currentFile.getFile()); } if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof IllegalStateException) { throw (IllegalStateException) e; } else { IOException ioex = new IOException(); ioex.initCause(e); throw ioex; } }
private void criticalIO(Throwable e) throws Exception { if (criticalErrorListener != null) { criticalErrorListener.onIOException(e, e.getMessage(), currentFile == null ? null : currentFile.getFile()); } if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof IllegalStateException) { throw (IllegalStateException) e; } else { IOException ioex = new IOException(); ioex.initCause(e); throw ioex; } }
/** public for tests only, not through API */ public void handleException(List<JDBCJournalRecord> recordRef, Throwable e) { logger.warn(e.getMessage(), e); failed.set(true); criticalIOErrorListener.onIOException(e, "Critical IO Error. Failed to process JDBC Record statements", null); if (logger.isTraceEnabled()) { logger.trace("Rolling back Transaction, just in case"); } try { connection.rollback(); } catch (Throwable rollback) { logger.warn(rollback); } try { connection.close(); } catch (Throwable rollback) { logger.warn(rollback); } if (recordRef != null) { executeCallbacks(recordRef, false); } }
@Override public void run() { final long lastRenewStart = this.lastLockRenewStart; final long renewStart = System.nanoTime(); try { if (!this.lock.renew()) { ioCriticalErrorListener.onIOException(new IllegalStateException(lockName + " lock can't be renewed"), "Critical error while on " + lockName + " renew", null); } } catch (Throwable t) { ioCriticalErrorListener.onIOException(t, "Critical error while on " + lockName + " renew", null); throw t; } //logic to detect slowness of DB and/or the scheduled executor service detectAndReportRenewSlowness(lockName, lastRenewStart, renewStart, renewPeriodMillis, lock.expirationMillis()); this.lastLockRenewStart = renewStart; }
private void renewLiveLockIfNeeded(final long acquiredOn) { final long acquiredMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - acquiredOn); if (acquiredMillis > this.scheduledLiveLock.renewPeriodMillis()) { if (!this.scheduledLiveLock.lock().renew()) { final IllegalStateException e = new IllegalStateException("live lock can't be renewed"); ioCriticalErrorListener.onIOException(e, "live lock can't be renewed", null); throw e; } } }
@Override public void write(EncodingSupport bytes, boolean sync, IOCallback callback) throws IOException { if (callback == null) { throw new NullPointerException("callback parameter need to be set"); } checkIsOpen(callback); try { this.mappedFile.write(bytes); if (factory.isDatasync() && sync) { this.mappedFile.force(); } callback.done(); } catch (IOException e) { if (this.criticalErrorListener != null) { this.criticalErrorListener.onIOException(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), e.getMessage()); throw e; } }
@Override public void write(ActiveMQBuffer bytes, boolean sync, IOCallback callback) throws IOException { if (callback == null) { throw new NullPointerException("callback parameter need to be set"); } checkIsOpen(callback); try { final ByteBuf byteBuf = bytes.byteBuf(); final int writerIndex = byteBuf.writerIndex(); final int readerIndex = byteBuf.readerIndex(); final int readableBytes = writerIndex - readerIndex; if (readableBytes > 0) { this.mappedFile.write(byteBuf, readerIndex, readableBytes); if (factory.isDatasync() && sync) { this.mappedFile.force(); } } callback.done(); } catch (IOException e) { if (this.criticalErrorListener != null) { this.criticalErrorListener.onIOException(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), e.getMessage()); throw e; } }
@Override public void pauseLiveServer() throws Exception { LOGGER.debug("ENTER pauseLiveServer"); try { if (scheduledLiveLock.isStarted()) { LOGGER.debug("scheduledLiveLock is running: set paused shared state, stop it and release live lock"); setPaused(); scheduledLiveLock.stop(); scheduledLiveLock.lock().release(); } else { LOGGER.debug("scheduledLiveLock is not running: try renew live lock"); if (scheduledLiveLock.lock().renew()) { LOGGER.debug("live lock renewed: set paused shared state and release live lock"); setPaused(); scheduledLiveLock.lock().release(); } else { final IllegalStateException e = new IllegalStateException("live lock can't be renewed"); ioCriticalErrorListener.onIOException(e, "live lock can't be renewed on pauseLiveServer", null); throw e; } } } finally { LOGGER.debug("EXIT pauseLiveServer"); } }
@Override public void write(EncodingSupport bytes, boolean sync, IOCallback callback) throws IOException { if (callback == null) { throw new NullPointerException("callback parameter need to be set"); } checkIsOpen(callback); try { this.mappedFile.write(bytes); if (factory.isDatasync() && sync) { this.mappedFile.force(); } callback.done(); } catch (IOException e) { if (this.criticalErrorListener != null) { this.criticalErrorListener.onIOException(new ActiveMQIOErrorException(e.getMessage(), e), e.getMessage(), this); } callback.onError(ActiveMQExceptionType.IO_ERROR.getCode(), e.getMessage()); throw e; } }