Skip to content

Commit a4ee599

Browse files
committed
Full Service model integration.
1 parent 4c513d7 commit a4ee599

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/main/java/org/ros/internal/node/service/DefaultServiceClient.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package 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;
55
import org.ros.internal.message.MessageBufferPool;
6-
import org.ros.internal.system.Utility;
76
import org.ros.internal.transport.ClientHandshakeListener;
87
import org.ros.internal.transport.ConnectionHeader;
98
import org.ros.internal.transport.ConnectionHeaderFields;
@@ -14,9 +13,10 @@
1413
import org.ros.node.service.ServiceClient;
1514
import org.ros.node.service.ServiceResponseListener;
1615

16+
//import rosgraph_msgs.Log;
17+
1718
import java.io.IOException;
1819
import java.net.InetSocketAddress;
19-
import java.nio.ByteBuffer;
2020
import java.util.LinkedList;
2121
import java.util.Queue;
2222
import java.util.concurrent.CountDownLatch;
@@ -29,7 +29,8 @@
2929
* @author jg
3030
*/
3131
public 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

src/main/java/org/ros/internal/node/service/DefaultServiceServer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void onMasterUnregistrationFailure(ServiceServer<T, S> registrant) {
8080
});
8181
}
8282

83-
public ByteBuffer finishHandshake(ConnectionHeader incomingConnectionHeader) {
83+
public ConnectionHeader finishHandshake(ConnectionHeader incomingConnectionHeader) {
8484
if (DEBUG) {
8585
log.info("Client handshake header: " + incomingConnectionHeader);
8686
}
@@ -93,9 +93,9 @@ public ByteBuffer finishHandshake(ConnectionHeader incomingConnectionHeader) {
9393
if (DEBUG) {
9494
log.info("Server handshake header: " + connectionHeader);
9595
}
96-
ByteBuffer headbuf = MessageBuffers.dynamicBuffer();
97-
Utility.serialize(connectionHeader, headbuf);
98-
return headbuf;
96+
//ByteBuffer headbuf = MessageBuffers.dynamicBuffer();
97+
//Utility.serialize(connectionHeader, headbuf);
98+
return connectionHeader;
9999
}
100100

101101
@Override

src/main/java/org/ros/internal/transport/tcp/TcpServerHandshakeHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ private void handleServiceHandshake(ChannelHandlerContext ctx, ConnectionHeader
7676
GraphName serviceName = GraphName.of(incomingHeader.getField(ConnectionHeaderFields.SERVICE));
7777
assert(serviceManager.hasServer(serviceName));
7878
DefaultServiceServer<?, ?> serviceServer = serviceManager.getServer(serviceName);
79+
// finishHandshake previously returned ByteBuffer, now returns ConnectionHeader
7980
ctx.write(serviceServer.finishHandshake(incomingHeader));
8081
String probe = incomingHeader.getField(ConnectionHeaderFields.PROBE);
8182
if (probe != null && probe.equals("1")) {

src/main/java/org/ros/master/client/MasterStateClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ public MasterStateClient(Node caller, InetSocketAddress masterUri) throws IOExce
5959
/**
6060
* @param nodeName
6161
* the name of the {@link Node} to lookup
62-
* @return the {@link URI} of the {@link Node} with the given name
62+
* @return the {@link InetSocketAddress} of the {@link Node} with the given name
6363
*/
64-
public URI lookupNode(String nodeName) {
64+
public InetSocketAddress lookupNode(String nodeName) {
6565
Response<InetSocketAddress> response = masterClient.lookupNode(caller.getName(), nodeName);
6666
return response.getResult();
6767
}
6868

6969
/**
70-
* @return the {@link URI} of the {@link MasterServer}
70+
* @return the {@link InetSocketAddress0} of the {@link MasterServer}
7171
*/
7272
public InetSocketAddress getUri() {
7373
Response<InetSocketAddress> response = masterClient.getUri(caller.getName());
@@ -77,7 +77,7 @@ public InetSocketAddress getUri() {
7777
/**
7878
* @param serviceName
7979
* the name of the {@link ServiceServer} to look up
80-
* @return the {@link URI} of the {@link ServiceServer} with the given name
80+
* @return the {@link InetSocketAddress} of the {@link ServiceServer} with the given name
8181
*/
8282
public InetSocketAddress lookupService(String serviceName) {
8383
Response<InetSocketAddress> result = masterClient.lookupService(caller.getName(), serviceName);

0 commit comments

Comments
 (0)