public Writer(SocketChannel sockChannel, int slowConsumerThroughput, int slowConsumerLatency, int slowConsumerRetries, IWriteInterestManager writeInterestManager) { _sockChannel = sockChannel; _slowConsumerThroughput = slowConsumerThroughput; _slowConsumerLatency = slowConsumerLatency; _slowConsumerRetries = slowConsumerRetries; _slowConsumer = _slowConsumerThroughput > 0; _slowConsumerSleepTime = _slowConsumerLatency / _slowConsumerRetries + 1; _slowConsumerBytes = (_slowConsumerThroughput * _slowConsumerLatency) / 1000; _contexts = new LinkedList<Context>(); _writeInterestManager = writeInterestManager; try { _baos = new GSByteArrayOutputStream(); _baos.setSize(LENGTH_SIZE); // mark the buffer to start writing only after the length place _oos = new MarshalOutputStream(_baos, true); // add a TC_RESET using the MarshalOutputStream.writeStreamHeader() initBuffer(_baos); } catch (Exception e) { if (_logger.isLoggable(Level.SEVERE)) { _logger.log(Level.SEVERE, e.getMessage(), e); } throw new RuntimeException("Failed to initialize LRMI Writer stream: ", e); } }
public LRMIChat(RequestPacket packet) throws IOException { MarshalOutputStream mos; GSByteArrayOutputStream bos = new GSByteArrayOutputStream(); bos.setSize(4); mos = new MarshalOutputStream(bos, false); ByteBuffer buffer = wrap(bos); packet.writeExternal(mos); msg = prepareBuffer(mos, bos, buffer); mode = Mode.WRITE; headerBuffer = ByteBuffer.allocate(4); headerBuffer.order(ByteOrder.BIG_ENDIAN); }
public ByteBuffer serializePacket(T packet) throws IOException { _packetStreamSerializer.writePacketToStream(_oss, packet); _oss.flush(); _oss.reset(); byte[] actualBuffer = _gsByteOutputStream.getBuffer(); //Need to rewrap the buffer because it was changed if (actualBuffer != _buffer) { _buffer = actualBuffer; _byteBuffer = ByteBuffer.wrap(_buffer); } //Remove reset indicator _byteBuffer.limit(_gsByteOutputStream.size() - 1); _byteBuffer.position(0); _gsByteOutputStream.setSize(0); return _byteBuffer; }
bos.setSize(LENGTH_SIZE); // for the stream size mos = new MarshalOutputStream(bos, false); byteBuffer = wrap(bos);