/** * Read the record stored at the given {@link Location}. * * @param location * @return * @throws IOException * @throws IllegalStateException */ public ByteBuffer read(Location location) throws IOException, IllegalStateException { Buffer buffer = accessor.readLocation(location); return buffer.toByteBuffer(); }
protected void flushNextWriteBuffer() { DataByteArrayOutputStream next = allocateNextWriteBuffer(); ByteBuffer bb = nextWriteBuffer.toBuffer().toByteBuffer(); writeBuffer.add(bb); writeBufferRemaining += bb.remaining(); nextWriteBuffer = next; }
public BufferState write(Object value) throws IOException { if (full()) { return BufferState.FULL; } else { boolean wasEmpty = empty(); Buffer buffer = (Buffer) value; next_write_size += buffer.length; next_write_buffers.add(buffer.toByteBuffer()); return wasEmpty ? BufferState.WAS_EMPTY : BufferState.NOT_EMPTY; } }
public BufferState write(Object value) throws IOException { if (full()) { return BufferState.FULL; } else { boolean wasEmpty = empty(); Buffer buffer = (Buffer) value; next_write_size += buffer.length; next_write_buffers.add(buffer.toByteBuffer()); return wasEmpty ? BufferState.WAS_EMPTY : BufferState.NOT_EMPTY; } }
protected void handleMessageArrived(final String topic, final Buffer payload, final Callback<Callback<Void>> ack) { final MqttMessageHandler handler; synchronized (this) { handler = subscriptions.get(topic); } if (handler != null) { try { handler.handleMessage(topic, payload.toByteBuffer()); ack.onSuccess(null); } catch (Exception e) { ack.onFailure(e); } } }
protected void handleMessageArrived(final String topic, final Buffer payload, final Callback<Callback<Void>> ack) { final MqttMessageHandler handler; synchronized (this) { handler = subscriptions.get(topic); } if (handler != null) { try { handler.handleMessage(topic, payload.toByteBuffer()); ack.onSuccess(null); } catch (Exception e) { ack.onFailure(e); } } }
private Location recoveryCheck() throws IOException { Location location = goToFirstLocation(dataFiles.firstEntry().getValue(), Location.BATCH_CONTROL_RECORD_TYPE, false); while (true) { ByteBuffer buffer = accessor.readLocation(location).toByteBuffer(); for (int i = 0; i < BATCH_CONTROL_RECORD_MAGIC.length; i++) { if (buffer.get() != BATCH_CONTROL_RECORD_MAGIC[i]) { throw new IOException("Bad control record magic for location: " + location); } } if (isChecksum()) { long expectedChecksum = buffer.getLong(); byte data[] = new byte[buffer.remaining()]; Checksum checksum = new Adler32(); buffer.get(data); checksum.update(data, 0, data.length); if (expectedChecksum != checksum.getValue()) { throw new IOException("Bad checksum for location: " + location); } } Location next = goToNextLocation(location, Location.BATCH_CONTROL_RECORD_TYPE, true); if (next != null) { location = next; } else { break; } } return location; }
@Override public void onTransportCommand(Object command) { if( state != CONNECTED ) { return; } try { Buffer buffer; if (command.getClass() == AmqpHeader.class) { buffer = ((AmqpHeader) command).getBuffer(); } else { buffer = (Buffer) command; } ByteBuffer bbuffer = buffer.toByteBuffer(); do { ByteBuffer input = protonTransport.getInputBuffer(); ByteBufferUtils.pour(bbuffer, input); protonTransport.processInput(); } while (bbuffer.remaining() > 0); process(); pumpOut(); } catch (Exception e) { onFailure(e); } }