private void updateStatusInternal( LogSequenceNumber received, LogSequenceNumber flushed, LogSequenceNumber applied, boolean replyRequired) throws SQLException { byte[] reply = prepareUpdateStatus(received, flushed, applied, replyRequired); copyDual.writeToCopy(reply, 0, reply.length); copyDual.flushCopy(); lastStatusUpdate = System.currentTimeMillis(); }
@Override public boolean isClosed() { return closeFlag || !copyDual.isActive(); }
public void close() throws SQLException { if (isClosed()) { return; } LOGGER.log(Level.FINEST, " FE=> StopReplication"); copyDual.endCopy(); closeFlag = true; } }
private ByteBuffer receiveNextData(boolean block) throws SQLException { try { byte[] message = copyDual.readFromCopy(block); if (message != null) { return ByteBuffer.wrap(message); } else { return null; } } catch (PSQLException e) { //todo maybe replace on thread sleep? if (e.getCause() instanceof SocketTimeoutException) { //signal for keep alive return null; } throw e; } }
@Override public ByteBuffer read() throws SQLException { checkClose(); ByteBuffer payload = null; while (payload == null && copyDual.isActive()) { payload = readInternal(true); } return payload; }
private ByteBuffer readInternal(boolean block) throws SQLException { boolean updateStatusRequired = false; while (copyDual.isActive()) { if (updateStatusRequired || isTimeUpdate()) { timeUpdateStatus(); } ByteBuffer buffer = receiveNextData(block); if (buffer == null) { return null; } int code = buffer.get(); switch (code) { case 'k': //KeepAlive message updateStatusRequired = processKeepAliveMessage(buffer); updateStatusRequired |= updateInterval == 0; break; case 'w': //XLogData return processXLogData(buffer); default: throw new PSQLException( GT.tr("Unexpected packet type during replication: {0}", Integer.toString(code)), PSQLState.PROTOCOL_VIOLATION ); } } return null; }