11package org .ros .internal .node .service ;
22
3-
4- import org .ros . exception . RosRuntimeException ;
3+ import org . apache . commons . logging . Log ;
4+ import org .apache . commons . logging . LogFactory ;
55import org .ros .internal .message .MessageBufferPool ;
6- import org .ros .internal .system .Utility ;
76import org .ros .internal .transport .ClientHandshakeListener ;
87import org .ros .internal .transport .ConnectionHeader ;
98import org .ros .internal .transport .ConnectionHeaderFields ;
1413import org .ros .node .service .ServiceClient ;
1514import org .ros .node .service .ServiceResponseListener ;
1615
16+ //import rosgraph_msgs.Log;
17+
1718import java .io .IOException ;
1819import java .net .InetSocketAddress ;
19- import java .nio .ByteBuffer ;
2020import java .util .LinkedList ;
2121import java .util .Queue ;
2222import java .util .concurrent .CountDownLatch ;
2929 * @author jg
3030 */
3131public class DefaultServiceClient <T , S > implements ServiceClient <T , S > {
32-
32+ private static final boolean DEBUG = true ;
33+ private final Log log = LogFactory .getLog (this .getClass ());
3334 private final class HandshakeLatch implements ClientHandshakeListener {
3435
3536 private CountDownLatch latch ;
@@ -112,14 +113,20 @@ public void connect(InetSocketAddress inetSocketAddress) throws Exception {
112113 try {
113114 tcpClient = tcpClientManager .connect (toString (), inetSocketAddress );
114115 } catch (IOException e1 ) {
115- throw new RosRuntimeException ("TcpClient failed to connect to remote " +toString ()+" " +inetSocketAddress , e1 );
116+ log .error (this .toString ()+" failed to connect to server at:" +inetSocketAddress +
117+ " using context:" +tcpClient .getContext ()+" due to IOException:" +e1 .getMessage ());
118+ throw new Exception (this .toString ()+" failed to connect to server at address:" +inetSocketAddress , e1 );
116119 }
117120 try {
118121 if (!handshakeLatch .await (1 , TimeUnit .SECONDS )) {
119- throw new RosRuntimeException (handshakeLatch .getErrorMessage ());
122+ log .error (this .toString ()+" failed to connect to server at:" +inetSocketAddress +
123+ " using context:" +tcpClient .getContext ()+" due to IOException:" +handshakeLatch .getErrorMessage ());
124+ throw new Exception ("Handshake Latch:" +handshakeLatch .toString ()+" TIMED OUT with error message:" +handshakeLatch .getErrorMessage ());
120125 }
121126 } catch (InterruptedException e ) {
122- throw new RosRuntimeException ("Handshake timed out." );
127+ log .error (this .toString ()+" failed to connect to server at:" +inetSocketAddress +
128+ " using context:" +tcpClient .getContext ()+" due to IOException:" +handshakeLatch .getErrorMessage ());
129+ throw new Exception ("Handshake Latch:" +handshakeLatch .toString ()+" INTERRUPTED with error message:" +handshakeLatch .getErrorMessage ());
123130 }
124131 }
125132
@@ -138,7 +145,8 @@ public void call(T request, ServiceResponseListener<S> listener) {
138145 try {
139146 tcpClient .getContext ().write (request );
140147 } catch (IOException e ) {
141-
148+ log .error (this .toString ()+" failed on call to server with request:" +request +
149+ " using context:" +tcpClient .getContext ()+" due to IOException:" +e .getMessage ());
142150 e .printStackTrace ();
143151 }
144152 //messageBufferPool.release(buffer);
@@ -151,7 +159,7 @@ public GraphName getName() {
151159
152160 @ Override
153161 public String toString () {
154- return "ServiceClient <" + serviceDeclaration + ">" ;
162+ return "DefaultServiceClient <" + serviceDeclaration + ">" ;
155163 }
156164
157165 @ Override
0 commit comments