Skip to content

Commit 5caabcb

Browse files
committed
Removed unused packstream methods
Main those that do flushing. Now it's handled by netty channels.
1 parent a9fcd17 commit 5caabcb

File tree

12 files changed

+25
-214
lines changed

12 files changed

+25
-214
lines changed

driver/src/main/java/org/neo4j/driver/internal/async/inbound/ByteBufInput.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ public void stop()
3939
buf = null;
4040
}
4141

42-
@Override
43-
public boolean hasMoreData()
44-
{
45-
return buf.isReadable();
46-
}
47-
4842
@Override
4943
public byte readByte()
5044
{

driver/src/main/java/org/neo4j/driver/internal/async/outbound/ChunkAwareByteBufOutput.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ public void stop()
6060
currentChunkSize = 0;
6161
}
6262

63-
@Override
64-
public PackOutput flush()
65-
{
66-
throw new UnsupportedOperationException( "Flush not supported, this output only writes to a buffer" );
67-
}
68-
6963
@Override
7064
public PackOutput writeByte( byte value )
7165
{

driver/src/main/java/org/neo4j/driver/internal/messaging/MessageFormat.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,11 @@ public interface MessageFormat
2828
interface Writer
2929
{
3030
Writer write( Message msg ) throws IOException;
31-
32-
Writer flush() throws IOException;
3331
}
3432

3533
interface Reader
3634
{
37-
/**
38-
* Return true is there is another message in the underlying buffer
39-
*/
40-
boolean hasNext() throws IOException;
41-
4235
void read( MessageHandler handler ) throws IOException;
43-
4436
}
4537

4638
Writer newWriter( PackOutput output, boolean byteArraySupportEnabled );

driver/src/main/java/org/neo4j/driver/internal/messaging/PackStreamMessageFormatV1.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,6 @@ private void packValue( Value value ) throws IOException
326326
}
327327
}
328328

329-
@Override
330-
public Writer flush() throws IOException
331-
{
332-
packer.flush();
333-
return this;
334-
}
335-
336329
@Override
337330
public Writer write( Message msg ) throws IOException
338331
{
@@ -376,12 +369,6 @@ public Reader( PackInput input )
376369
unpacker = new PackStream.Unpacker( input );
377370
}
378371

379-
@Override
380-
public boolean hasNext() throws IOException
381-
{
382-
return unpacker.hasNext();
383-
}
384-
385372
/**
386373
* Parse a single message into the given consumer.
387374
*/
@@ -660,14 +647,4 @@ private Map<String,Value> unpackMap() throws IOException
660647
return map;
661648
}
662649
}
663-
664-
public static class NoOpRunnable implements Runnable
665-
{
666-
@Override
667-
public void run()
668-
{
669-
// no-op
670-
}
671-
}
672-
673650
}

driver/src/main/java/org/neo4j/driver/internal/packstream/PackInput.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
*/
2727
public interface PackInput
2828
{
29-
/** True if there is at least one more consumable byte */
30-
boolean hasMoreData() throws IOException;
31-
3229
/** Consume one byte */
3330
byte readByte() throws IOException;
3431

driver/src/main/java/org/neo4j/driver/internal/packstream/PackOutput.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
*/
2626
public interface PackOutput
2727
{
28-
// todo: remove flush method
29-
/** If implementation has been buffering data, it should flush those buffers now. */
30-
PackOutput flush() throws IOException;
31-
3228
/** Produce a single byte */
3329
PackOutput writeByte( byte value ) throws IOException;
3430

driver/src/main/java/org/neo4j/driver/internal/packstream/PackStream.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,6 @@ public Packer( PackOutput out )
157157
this.out = out;
158158
}
159159

160-
public void flush() throws IOException
161-
{
162-
out.flush();
163-
}
164-
165160
public void packRaw( byte[] data ) throws IOException
166161
{
167162
out.writeBytes( data );
@@ -425,11 +420,6 @@ public Unpacker( PackInput in )
425420
this.in = in;
426421
}
427422

428-
public boolean hasNext() throws IOException
429-
{
430-
return in.hasMoreData();
431-
}
432-
433423
public long unpackStructHeader() throws IOException
434424
{
435425
final byte markerByte = in.readByte();

driver/src/test/java/org/neo4j/driver/internal/async/inbound/ByteBufInputTest.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import static org.hamcrest.Matchers.instanceOf;
2525
import static org.junit.Assert.assertEquals;
2626
import static org.junit.Assert.assertThat;
27-
import static org.junit.Assert.assertTrue;
2827
import static org.junit.Assert.fail;
2928
import static org.mockito.Matchers.anyInt;
3029
import static org.mockito.Mockito.mock;
@@ -66,17 +65,6 @@ public void shouldThrowWhenStartedTwice()
6665
}
6766
}
6867

69-
@Test
70-
public void shouldDelegateHasMoreData()
71-
{
72-
ByteBufInput input = new ByteBufInput();
73-
ByteBuf buf = mock( ByteBuf.class );
74-
when( buf.isReadable() ).thenReturn( true );
75-
input.start( buf );
76-
77-
assertTrue( input.hasMoreData() );
78-
}
79-
8068
@Test
8169
public void shouldDelegateReadByte()
8270
{

driver/src/test/java/org/neo4j/driver/internal/packstream/BufferedChannelInput.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,6 @@ public BufferedChannelInput( int bufferCapacity, ReadableByteChannel ch )
4444
this.channel = ch;
4545
}
4646

47-
@Override
48-
public boolean hasMoreData() throws IOException
49-
{
50-
return attempt( 1 );
51-
}
52-
5347
@Override
5448
public byte readByte() throws IOException
5549
{

driver/src/test/java/org/neo4j/driver/internal/packstream/BufferedChannelOutput.java renamed to driver/src/test/java/org/neo4j/driver/internal/packstream/ChannelOutput.java

Lines changed: 16 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,99 +20,68 @@
2020

2121
import java.io.IOException;
2222
import java.nio.ByteBuffer;
23-
import java.nio.ByteOrder;
2423
import java.nio.channels.WritableByteChannel;
2524

26-
public class BufferedChannelOutput implements PackOutput
25+
public class ChannelOutput implements PackOutput
2726
{
28-
private final ByteBuffer buffer;
2927
private final WritableByteChannel channel;
3028

31-
public BufferedChannelOutput( WritableByteChannel channel )
29+
public ChannelOutput( WritableByteChannel channel )
3230
{
33-
this( channel, 1024 );
34-
}
35-
36-
public BufferedChannelOutput( WritableByteChannel channel, int bufferSize )
37-
{
38-
this.buffer = ByteBuffer.allocate( bufferSize ).order( ByteOrder.BIG_ENDIAN );
3931
this.channel = channel;
4032
}
4133

42-
@Override
43-
public BufferedChannelOutput flush() throws IOException
44-
{
45-
buffer.flip();
46-
do { channel.write( buffer ); } while ( buffer.remaining() > 0 );
47-
buffer.clear();
48-
return this;
49-
}
50-
5134
@Override
5235
public PackOutput writeBytes( byte[] data ) throws IOException
5336
{
54-
int length = data.length;
55-
int index = 0;
56-
while ( index < length )
57-
{
58-
if ( buffer.remaining() == 0 )
59-
{
60-
flush();
61-
}
62-
63-
int amountToWrite = Math.min( buffer.remaining(), length - index );
64-
65-
buffer.put( data, index, amountToWrite );
66-
index += amountToWrite;
67-
}
37+
channel.write( ByteBuffer.wrap( data ) );
6838
return this;
6939
}
7040

7141
@Override
7242
public PackOutput writeByte( byte value ) throws IOException
7343
{
74-
ensure( 1 );
75-
buffer.put( value );
44+
channel.write( ByteBuffer.wrap( new byte[]{value} ) );
7645
return this;
7746
}
7847

7948
@Override
8049
public PackOutput writeShort( short value ) throws IOException
8150
{
82-
ensure( 2 );
51+
ByteBuffer buffer = ByteBuffer.allocate( Short.BYTES );
8352
buffer.putShort( value );
53+
buffer.flip();
54+
channel.write( buffer );
8455
return this;
8556
}
8657

8758
@Override
8859
public PackOutput writeInt( int value ) throws IOException
8960
{
90-
ensure( 4 );
61+
ByteBuffer buffer = ByteBuffer.allocate( Integer.BYTES );
9162
buffer.putInt( value );
63+
buffer.flip();
64+
channel.write( buffer );
9265
return this;
9366
}
9467

9568
@Override
9669
public PackOutput writeLong( long value ) throws IOException
9770
{
98-
ensure( 8 );
71+
ByteBuffer buffer = ByteBuffer.allocate( Long.BYTES );
9972
buffer.putLong( value );
73+
buffer.flip();
74+
channel.write( buffer );
10075
return this;
10176
}
10277

10378
@Override
10479
public PackOutput writeDouble( double value ) throws IOException
10580
{
106-
ensure( 8 );
81+
ByteBuffer buffer = ByteBuffer.allocate( Double.BYTES );
10782
buffer.putDouble( value );
83+
buffer.flip();
84+
channel.write( buffer );
10885
return this;
10986
}
110-
111-
private void ensure( int size ) throws IOException
112-
{
113-
if ( buffer.remaining() < size )
114-
{
115-
flush();
116-
}
117-
}
11887
}

0 commit comments

Comments
 (0)