3737import java .util .Map ;
3838import java .util .HashMap ;
3939import java .util .concurrent .TimeoutException ;
40- import java .util .concurrent .ScheduledExecutorService ;
41- import java .util .concurrent .Executors ;
42- import java .util .concurrent .TimeUnit ;
4340
4441import com .rabbitmq .client .AMQP ;
45- import com .rabbitmq .client .Address ;
4642import com .rabbitmq .client .AlreadyClosedException ;
4743import com .rabbitmq .client .Channel ;
4844import com .rabbitmq .client .Command ;
4945import com .rabbitmq .client .Connection ;
5046import com .rabbitmq .client .ConnectionFactory ;
5147import com .rabbitmq .client .MissedHeartbeatException ;
5248import com .rabbitmq .client .ShutdownSignalException ;
49+ import com .rabbitmq .client .impl .exceptions .PossibleAuthenticationFailureException ;
50+ import com .rabbitmq .client .impl .exceptions .ProtocolVersionMismatchException ;
5351import com .rabbitmq .utility .BlockingCell ;
5452import com .rabbitmq .utility .Utility ;
5553
@@ -228,7 +226,10 @@ public AMQConnection(ConnectionFactory factory,
228226 * Connection.Start/.StartOk, Connection.Tune/.TuneOk, and then
229227 * calls Connection.Open and waits for the OpenOk. Sets heartbeat
230228 * and frame max values after tuning has taken place.
231- * @throws java.io.IOException if an error is encountered
229+ * @throws java.io.IOException if an error is encountered; IOException
230+ * subtypes ProtocolVersionMismatchException and
231+ * PossibleAuthenticationFailureException will be thrown in the
232+ * corresponding circumstances.
232233 */
233234 public void start ()
234235 throws IOException
@@ -259,40 +260,39 @@ public void start()
259260 (AMQP .Connection .Start ) connStartBlocker .getReply ().getMethod ();
260261
261262 _serverProperties = connStart .getServerProperties ();
262-
263+
263264 Version serverVersion =
264265 new Version (connStart .getVersionMajor (),
265266 connStart .getVersionMinor ());
266-
267+
267268 if (!Version .checkVersion (clientVersion , serverVersion )) {
268269 _frameHandler .close (); //this will cause mainLoop to terminate
269- //TODO: throw a more specific exception
270- throw new IOException ("protocol version mismatch: expected " +
271- clientVersion + ", got " + serverVersion );
270+ throw new ProtocolVersionMismatchException (clientVersion ,
271+ serverVersion );
272272 }
273273 } catch (ShutdownSignalException sse ) {
274274 throw AMQChannel .wrap (sse );
275275 }
276-
276+
277277 LongString saslResponse = LongStringHelper .asLongString ("\0 " + _username +
278278 "\0 " + _password );
279279 AMQImpl .Connection .StartOk startOk =
280280 new AMQImpl .Connection .StartOk (_clientProperties , "PLAIN" ,
281281 saslResponse , "en_US" );
282-
282+
283283 AMQP .Connection .Tune connTune = null ;
284284
285285 try {
286286 connTune = (AMQP .Connection .Tune ) _channel0 .rpc (startOk ).getMethod ();
287287 } catch (ShutdownSignalException e ) {
288- throw AMQChannel . wrap ( e , "Possibly caused by authentication failure" );
288+ throw new PossibleAuthenticationFailureException ( e );
289289 }
290290
291291 int channelMax =
292292 negotiatedMaxValue (_factory .getRequestedChannelMax (),
293293 connTune .getChannelMax ());
294294 _channelManager = new ChannelManager (channelMax );
295-
295+
296296 int frameMax =
297297 negotiatedMaxValue (_factory .getRequestedFrameMax (),
298298 connTune .getFrameMax ());
@@ -302,7 +302,7 @@ public void start()
302302 negotiatedMaxValue (_factory .getRequestedHeartbeat (),
303303 connTune .getHeartbeat ());
304304 setHeartbeat (heartbeat );
305-
305+
306306 _channel0 .transmit (new AMQImpl .Connection .TuneOk (channelMax ,
307307 frameMax ,
308308 heartbeat ));
@@ -519,7 +519,7 @@ public boolean processControlCommand(Command c)
519519 return false ;
520520 } else {
521521 // Quiescing.
522- if (method instanceof AMQP .Connection .CloseOk ) {
522+ if (method instanceof AMQP .Connection .CloseOk ) {
523523 // It's our final "RPC". Time to shut down.
524524 _running = false ;
525525 // If Close was sent from within the MainLoop we
@@ -548,14 +548,14 @@ public void handleConnectionClose(Command closeCommand) {
548548 getHost () + ":" + getPort ());
549549 scw .start ();
550550 }
551-
551+
552552 private class SocketCloseWait extends Thread {
553553 private ShutdownSignalException cause ;
554-
554+
555555 public SocketCloseWait (ShutdownSignalException sse ) {
556556 cause = sse ;
557557 }
558-
558+
559559 @ Override public void run () {
560560 try {
561561 _appContinuation .uninterruptibleGet (CONNECTION_CLOSING_TIMEOUT );
@@ -574,7 +574,7 @@ public SocketCloseWait(ShutdownSignalException sse) {
574574 * Protected API - causes all attached channels to terminate with
575575 * a ShutdownSignal built from the argument, and stops this
576576 * connection from accepting further work from the application.
577- *
577+ *
578578 * @return a shutdown signal built using the given arguments
579579 */
580580 public ShutdownSignalException shutdown (Object reason ,
@@ -656,7 +656,7 @@ public void abort(int closeCode, String closeMessage, int timeout)
656656 }
657657 }
658658
659- /**
659+ /**
660660 * Protected API - Delegates to {@link
661661 * #close(int,String,boolean,Throwable,int,boolean) the
662662 * six-argument close method}, passing 0 for the timeout, and
0 commit comments