1919import java .io .DataOutputStream ;
2020import java .io .IOException ;
2121import java .nio .ByteBuffer ;
22- import java .util .concurrent .CompletableFuture ;
2322import java .util .concurrent .locks .Lock ;
2423import java .util .concurrent .locks .ReentrantLock ;
2524
@@ -126,30 +125,28 @@ public boolean handleFrame(Frame f) throws IOException {
126125 * @param channel the channel on which to transmit the command
127126 * @throws IOException if an error is encountered
128127 */
129- public CompletableFuture < Void > transmit (AMQChannel channel ) throws IOException {
128+ public void transmit (AMQChannel channel ) throws IOException {
130129 int channelNumber = channel .getChannelNumber ();
131130 AMQConnection connection = channel .getConnection ();
132131
133- CompletableFuture <Void > future = null ;
134132 assemblerLock .lock ();
135133 try {
136134 Method m = this .assembler .getMethod ();
137135 if (m .hasContent ()) {
138136 ByteBuffer bbBody = this .assembler .getByteBufferBody ();
139137 if (bbBody != null ) {
140- future = transmitWithByteBuffer (m , bbBody , channelNumber , connection );
138+ transmitWithByteBuffer (m , bbBody , channelNumber , connection );
141139 } else {
142140 transmitWithByteArray (m , this .assembler .getContentBody (), channelNumber , connection );
143141 }
144142 } else {
145- connection .writeFrame (m .toFrame (channelNumber ), null );
143+ connection .writeFrame (m .toFrame (channelNumber ));
146144 }
147145 } finally {
148146 assemblerLock .unlock ();
149147 }
150148
151149 connection .flush ();
152- return future ;
153150 }
154151
155152 private void transmitWithByteArray (Method m , byte [] body , int channelNumber , AMQConnection connection ) throws IOException {
@@ -163,18 +160,18 @@ private void transmitWithByteArray(Method m, byte[] body, int channelNumber, AMQ
163160 String msg = String .format ("Content headers exceeded max frame size: %d > %d" , headerFrame .size (), frameMax );
164161 throw new IllegalArgumentException (msg );
165162 }
166- connection .writeFrame (m .toFrame (channelNumber ), null );
167- connection .writeFrame (headerFrame , null );
163+ connection .writeFrame (m .toFrame (channelNumber ));
164+ connection .writeFrame (headerFrame );
168165
169166 for (int offset = 0 ; offset < body .length ; offset += bodyPayloadMax ) {
170167 int remaining = body .length - offset ;
171168 int fragmentLength = (remaining < bodyPayloadMax ) ? remaining : bodyPayloadMax ;
172169 Frame frame = Frame .fromBodyFragment (channelNumber , body , offset , fragmentLength );
173- connection .writeFrame (frame , null );
170+ connection .writeFrame (frame );
174171 }
175172 }
176173
177- private CompletableFuture < Void > transmitWithByteBuffer (Method m , ByteBuffer body , int channelNumber , AMQConnection connection ) throws IOException {
174+ private void transmitWithByteBuffer (Method m , ByteBuffer body , int channelNumber , AMQConnection connection ) throws IOException {
178175 int bodySize = body .remaining ();
179176 Frame headerFrame = this .assembler .getContentHeader ().toFrame (channelNumber , bodySize );
180177
@@ -186,23 +183,16 @@ private CompletableFuture<Void> transmitWithByteBuffer(Method m, ByteBuffer body
186183 String msg = String .format ("Content headers exceeded max frame size: %d > %d" , headerFrame .size (), frameMax );
187184 throw new IllegalArgumentException (msg );
188185 }
189- connection .writeFrame (m .toFrame (channelNumber ), null );
190- connection .writeFrame (headerFrame , null );
186+ connection .writeFrame (m .toFrame (channelNumber ));
187+ connection .writeFrame (headerFrame );
191188
192- // TODO should complete the future in case of error
193- CompletableFuture <Void > future = new CompletableFuture <>();
194189 int bodyPosition = body .position ();
195190 for (int offset = 0 ; offset < bodySize ; offset += bodyPayloadMax ) {
196191 int remaining = bodySize - offset ;
197192 int fragmentLength = (remaining < bodyPayloadMax ) ? remaining : bodyPayloadMax ;
198193 Frame frame = Frame .fromBodyFragment (channelNumber , body , bodyPosition + offset , fragmentLength );
199- if (offset + bodyPayloadMax >= bodySize ) {
200- connection .writeFrame (frame , future );
201- } else {
202- connection .writeFrame (frame , null );
203- }
194+ connection .writeFrame (frame );
204195 }
205- return future ;
206196 }
207197
208198 @ Override public String toString () {
0 commit comments