Class StorageServiceClient

java.lang.Object
org.hobbit.storage.client.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 final long
    The default maximum amount of time in millisecond the client is waiting for a response = 60000Lms.
    private static final org.slf4j.Logger
     
    RPC client that is used for the communication.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor creating a StorageServiceClient using the given RabbitRpcClient.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    create(com.rabbitmq.client.Connection connection)
    Creates a StorageServiceClient using the given RabbitMQ Connection.
    boolean
    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
    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
    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[]
    Sends a request using rpcClient.
    org.apache.jena.query.ResultSet
    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
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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:
    • rpcClient

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

    • StorageServiceClient

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

    • 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
    • close

      public void close() throws IOException

      Closes the internal rpcClient instance.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException