Class StorageServiceClient

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class StorageServiceClient
    extends Object
    implements Closeable
    Simple client of the storage service implementing a synchronized communication.
    Author:
    Michael Röder (roeder@informatik.uni-leipzig.de)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static long DEFAULT_MAX_WAITING_TIME
      The default maximum amount of time in millisecond the client is waiting for a response = 60000Lms.
      private static org.slf4j.Logger LOGGER  
      private RabbitRpcClient rpcClient
      RPC client that is used for the communication.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      static StorageServiceClient create​(com.rabbitmq.client.Connection connection)
      Creates a StorageServiceClient using the given RabbitMQ Connection.
      boolean sendAskQuery​(String query)
      Sends the given ASK query to the storage service and returns a boolean value or throws an Exception if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
      org.apache.jena.rdf.model.Model sendConstructQuery​(String query)
      Sends the given CONSTRUCT query to the storage service and returns a Model value or null if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
      org.apache.jena.rdf.model.Model sendDescribeQuery​(String query)
      Sends the given DESCRIBE query to the storage service and returns a Model value or null if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
      boolean sendInsertQuery​(org.apache.jena.rdf.model.Model model, String graphURI)
      Inserts the given model into the storage and returns true if the query is successful or false if an error occurs or the service needs too much time to respond.
      private byte[] sendRequest​(String request)
      Sends a request using rpcClient.
      org.apache.jena.query.ResultSet sendSelectQuery​(String query)
      Sends the given SELECT query to the storage service and returns a ResultSet value or null if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
      boolean sendUpdateQuery​(String query)
      Sends the given UPDATE query to the storage service and returns true if the query is successful or false if an error occurs or the service needs too much time to respond.
      void setMaxWaitingTime​(long maxWaitingTime)
      Sets the maximum amount of time the client is waiting for a response.
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • DEFAULT_MAX_WAITING_TIME

        private static final long DEFAULT_MAX_WAITING_TIME
        The default maximum amount of time in millisecond the client is waiting for a response = 60000Lms.
        See Also:
        Constant Field Values
      • rpcClient

        private RabbitRpcClient rpcClient
        RPC client that is used for the communication.
    • Constructor Detail

      • StorageServiceClient

        public StorageServiceClient​(RabbitRpcClient rpcClient)
        Constructor creating a StorageServiceClient using the given RabbitRpcClient.
        Parameters:
        rpcClient - RPC client that is used for the communication
    • Method Detail

      • create

        public static StorageServiceClient create​(com.rabbitmq.client.Connection connection)
                                           throws IOException
        Creates a StorageServiceClient using the given RabbitMQ Connection.
        Parameters:
        connection - RabbitMQ connection used for the communication
        Returns:
        a StorageServiceClient instance
        Throws:
        IOException - if a problem occurs during the creation of the queues or the consumer.
      • setMaxWaitingTime

        public void setMaxWaitingTime​(long maxWaitingTime)
        Sets the maximum amount of time the client is waiting for a response.
        Parameters:
        maxWaitingTime - the maximum waiting time in milliseconds
      • sendRequest

        private byte[] sendRequest​(String request)
        Sends a request using rpcClient. If environment vars AES_PASSWORD and AES_SALT are set, the request will be encrypted.
      • sendAskQuery

        public boolean sendAskQuery​(String query)
                             throws Exception
        Sends the given ASK query to the storage service and returns a boolean value or throws an Exception if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
        Parameters:
        query - ASK query
        Returns:
        result for the query or false if an error occurs
        Throws:
        Exception - if no response has been received or the response couldn't be parsed.
      • sendConstructQuery

        public org.apache.jena.rdf.model.Model sendConstructQuery​(String query)
        Sends the given CONSTRUCT query to the storage service and returns a Model value or null if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
        Parameters:
        query - CONSTRUCT query
        Returns:
        result for the query or null
      • sendDescribeQuery

        public org.apache.jena.rdf.model.Model sendDescribeQuery​(String query)
        Sends the given DESCRIBE query to the storage service and returns a Model value or null if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
        Parameters:
        query - DESCRIBE query
        Returns:
        result for the query or null
      • sendSelectQuery

        public org.apache.jena.query.ResultSet sendSelectQuery​(String query)
        Sends the given SELECT query to the storage service and returns a ResultSet value or null if an error occurs, the service needs too much time to respond or the response couldn't be parsed.
        Parameters:
        query - SELECT query
        Returns:
        result for the query or null
      • sendUpdateQuery

        public boolean sendUpdateQuery​(String query)
        Sends the given UPDATE query to the storage service and returns true if the query is successful or false if an error occurs or the service needs too much time to respond.
        Parameters:
        query - UPDATE query
        Returns:
        flag indicating whether the query has been executed successfully or not
      • sendInsertQuery

        public boolean sendInsertQuery​(org.apache.jena.rdf.model.Model model,
                                       String graphURI)
        Inserts the given model into the storage and returns true if the query is successful or false if an error occurs or the service needs too much time to respond.
        Parameters:
        model - RDF model containing triples that should be inserted
        graphURI - URI of the graph in which the model should be inserted
        Returns:
        flag indicating whether the query has been executed successfully or not