Search in sources :

Example 16 with SService

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);
}
Also used : SocketException(java.net.SocketException) MethodDescriptorContainer(org.bimserver.shared.pb.ProtocolBuffersMetaData.MethodDescriptorContainer) DynamicMessage(com.google.protobuf.DynamicMessage) Message(com.google.protobuf.Message) Builder(com.google.protobuf.DynamicMessage.Builder) ProtocolBuffersMetaData(org.bimserver.shared.pb.ProtocolBuffersMetaData) IOException(java.io.IOException) EOFException(java.io.EOFException) SocketException(java.net.SocketException) UserException(org.bimserver.shared.exceptions.UserException) ReflectiveRpcChannel(org.bimserver.shared.pb.ReflectiveRpcChannel) PublicInterface(org.bimserver.shared.interfaces.PublicInterface) EOFException(java.io.EOFException) UserException(org.bimserver.shared.exceptions.UserException) SMethod(org.bimserver.shared.meta.SMethod) SService(org.bimserver.shared.meta.SService)

Aggregations

SService (org.bimserver.shared.meta.SService)16 SMethod (org.bimserver.shared.meta.SMethod)8 UserException (org.bimserver.shared.exceptions.UserException)7 CtClass (javassist.CtClass)5 SParameter (org.bimserver.shared.meta.SParameter)5 CtMethod (javassist.CtMethod)4 KeyValuePair (org.bimserver.shared.reflector.KeyValuePair)4 PublicInterface (org.bimserver.shared.interfaces.PublicInterface)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ServiceException (org.bimserver.shared.exceptions.ServiceException)2 ReflectorException (org.bimserver.shared.reflector.ReflectorException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 DynamicMessage (com.google.protobuf.DynamicMessage)1 Builder (com.google.protobuf.DynamicMessage.Builder)1 Message (com.google.protobuf.Message)1 EOFException (java.io.EOFException)1 File (java.io.File)1