@Override public BasicBytez newInstance(long size) { return new ByteBufferBasicBytez(ByteBuffer.allocate((int) size)); }
@Override public void copyTo(BasicBytez other, long otherByteIndex, long myByteIndex, long lenBytes) { // could be optimized depending on "other" type for ( long i = 0; i < lenBytes; i++ ) { other.put(otherByteIndex+i,get(myByteIndex+i)); } }
protected abstract void dataReceived(BinaryQueue queue);
public void tryFlush() { checkThread(); if ( canWrite() ) { qWriteTmp.position(0); qWriteTmp.limit(qWriteTmp.capacity()); tmp.setBuffer(qWriteTmp); long poll = writeQueue.poll(tmp, 0, tmp.length()); // System.out.println("try write "+poll+" avail:"+writeQueue.available()+" cap:"+writeQueue.capacity()); if (poll > 0) { qWriteTmp.limit((int) poll); IPromise queueDataAvailablePromise = directWrite(qWriteTmp); queueDataAvailablePromise.then((res, err) -> { if ( err != null ) { if (err instanceof Throwable ) { Log.Lg.error(this, (Throwable) err, "write failure"); closed((Throwable) err); } else { Log.Lg.error(this, null, "write failure:"+err); closed( new IOException(""+err)); } } else { tryFlush(); } }); } } }
@Override public void copyTo(BasicBytez other, long otherByteIndex, long myByteIndex, long lenBytes) { // could be optimized depending on "other" type for ( long i = 0; i < lenBytes; i++ ) { other.put(otherByteIndex+i,get(myByteIndex+i)); } }
@Override public BasicBytez newInstance(long size) { return new ByteBufferBasicBytez(ByteBuffer.allocate((int) size)); }
public void tryFlush() { checkThread(); if ( canWrite() ) { qWriteTmp.position(0); qWriteTmp.limit(qWriteTmp.capacity()); tmp.setBuffer(qWriteTmp); long poll = writeQueue.poll(tmp, 0, tmp.length()); // System.out.println("try write "+poll+" avail:"+writeQueue.available()+" cap:"+writeQueue.capacity()); if (poll > 0) { qWriteTmp.limit((int) poll); IPromise queueDataAvailablePromise = directWrite(qWriteTmp); queueDataAvailablePromise.then((res, err) -> { if ( err != null ) { if (err instanceof Throwable ) { Log.Lg.error(this, (Throwable) err, "write failure"); closed((Throwable) err); } else { Log.Lg.error(this, null, "write failure:"+err); closed( new IOException(""+err)); } } else { tryFlush(); } }); } } }
protected abstract void dataReceived(BinaryQueue queue);
public void write( ByteBuffer buf ) { checkThread(); checkQSize(); tmp.setBuffer(buf); writeQueue.add(tmp); }
public void write( ByteBuffer buf ) { checkThread(); checkQSize(); tmp.setBuffer(buf); writeQueue.add(tmp); }