Search in sources :

Example 1 with ReflectiveRpcChannel

use of org.bimserver.shared.pb.ReflectiveRpcChannel in project BIMserver by opensourceBIM.

the class Handler method run.

@Override
public void run() {
    running = true;
    try {
        DataInputStream dis = new DataInputStream(socket.getInputStream());
        String token = dis.readUTF();
        ReflectiveRpcChannel reflectiveRpcChannel = new ReflectiveRpcChannel(ServiceInterface.class, serviceFactory.get(token, AccessMethod.INTERNAL).get(ServiceInterface.class), protocolBuffersMetaData, servicesMap);
        while (running) {
            String serviceName = dis.readUTF();
            String methodName = dis.readUTF();
            MethodDescriptorContainer methodDescriptorContainer;
            try {
                methodDescriptorContainer = protocolBuffersMetaData.getMethod(serviceName, methodName);
                Builder newBuilder = DynamicMessage.newBuilder(methodDescriptorContainer.getInputDescriptor());
                newBuilder.mergeDelimitedFrom(dis);
                DynamicMessage request = newBuilder.build();
                Message response = reflectiveRpcChannel.callBlockingMethod(methodDescriptorContainer, request);
                response.writeDelimitedTo(socket.getOutputStream());
            } catch (ServiceNotFoundException e) {
                // TODO should return a usable pb message for the user
                LOGGER.error("", e);
            } catch (ServiceMethodNotFoundException e) {
                // TODO should return a usable pb message for the user
                LOGGER.error("", e);
            }
        }
    } catch (IOException e) {
        LOGGER.error("", e);
    } catch (UserException e) {
        LOGGER.error("", e);
    }
    socketNotificationsClient.notifyDisconnect();
}
Also used : ReflectiveRpcChannel(org.bimserver.shared.pb.ReflectiveRpcChannel) MethodDescriptorContainer(org.bimserver.shared.pb.ProtocolBuffersMetaData.MethodDescriptorContainer) DynamicMessage(com.google.protobuf.DynamicMessage) Message(com.google.protobuf.Message) ServiceNotFoundException(org.bimserver.shared.pb.ServiceNotFoundException) ServiceInterface(org.bimserver.shared.interfaces.ServiceInterface) Builder(com.google.protobuf.DynamicMessage.Builder) DynamicMessage(com.google.protobuf.DynamicMessage) IOException(java.io.IOException) UserException(org.bimserver.shared.exceptions.UserException) DataInputStream(java.io.DataInputStream) ServiceMethodNotFoundException(org.bimserver.shared.pb.ServiceMethodNotFoundException)

Example 2 with ReflectiveRpcChannel

use of org.bimserver.shared.pb.ReflectiveRpcChannel 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

DynamicMessage (com.google.protobuf.DynamicMessage)2 Builder (com.google.protobuf.DynamicMessage.Builder)2 Message (com.google.protobuf.Message)2 IOException (java.io.IOException)2 UserException (org.bimserver.shared.exceptions.UserException)2 MethodDescriptorContainer (org.bimserver.shared.pb.ProtocolBuffersMetaData.MethodDescriptorContainer)2 ReflectiveRpcChannel (org.bimserver.shared.pb.ReflectiveRpcChannel)2 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 SocketException (java.net.SocketException)1 PublicInterface (org.bimserver.shared.interfaces.PublicInterface)1 ServiceInterface (org.bimserver.shared.interfaces.ServiceInterface)1 SMethod (org.bimserver.shared.meta.SMethod)1 SService (org.bimserver.shared.meta.SService)1 ProtocolBuffersMetaData (org.bimserver.shared.pb.ProtocolBuffersMetaData)1 ServiceMethodNotFoundException (org.bimserver.shared.pb.ServiceMethodNotFoundException)1 ServiceNotFoundException (org.bimserver.shared.pb.ServiceNotFoundException)1