use of org.bimserver.shared.meta.SService in project BIMserver by opensourceBIM.
the class ProtocolBuffersConnectionHandler method run.
@Override
public void run() {
try {
running = true;
while (running) {
String serviceName = dataInputStream.readUTF();
String methodName = dataInputStream.readUTF();
String token = dataInputStream.readUTF();
ProtocolBuffersMetaData protocolBuffersMetaData = protocolBuffersServer.getProtocolBuffersMetaData();
SService sService = servicesMap.getBySimpleName(serviceName);
if (sService == null) {
throw new UserException("No service found with name " + serviceName);
}
SMethod method = sService.getSMethod(methodName);
if (method == null) {
throw new UserException("Method " + methodName + " not found on " + serviceName);
}
Class<? extends PublicInterface> clazz = sService.getInterfaceClass();
PublicInterface service = null;
if (token.equals("")) {
service = serviceFactory.get(AccessMethod.PROTOCOL_BUFFERS).get(clazz);
} else {
service = serviceFactory.get(token, AccessMethod.PROTOCOL_BUFFERS).get(clazz);
}
ReflectiveRpcChannel reflectiveRpcChannel = new ReflectiveRpcChannel(clazz, service, protocolBuffersMetaData, servicesMap);
MethodDescriptorContainer pbMethod = protocolBuffersMetaData.getMethod(serviceName, methodName);
Builder requestBuilder = DynamicMessage.getDefaultInstance(pbMethod.getInputDescriptor()).newBuilderForType();
requestBuilder.mergeDelimitedFrom(dataInputStream);
Message response = reflectiveRpcChannel.callBlockingMethod(pbMethod, requestBuilder.build());
response.writeDelimitedTo(outputStream);
outputStream.flush();
}
} catch (SocketException e) {
} catch (EOFException e) {
} catch (Exception e) {
if (running) {
LOGGER.error("", e);
}
}
protocolBuffersServer.unregister(this);
}
Aggregations