Package org.hobbit.storage.client
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 longDEFAULT_MAX_WAITING_TIMEThe default maximum amount of time in millisecond the client is waiting for a response = 60000Lms.private static org.slf4j.LoggerLOGGERprivate RabbitRpcClientrpcClientRPC client that is used for the communication.
-
Constructor Summary
Constructors Constructor Description StorageServiceClient(RabbitRpcClient rpcClient)Constructor creating a StorageServiceClient using the givenRabbitRpcClient.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static StorageServiceClientcreate(com.rabbitmq.client.Connection connection)Creates a StorageServiceClient using the given RabbitMQConnection.booleansendAskQuery(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.ModelsendConstructQuery(String query)Sends the given CONSTRUCT query to the storage service and returns aModelvalue ornullif an error occurs, the service needs too much time to respond or the response couldn't be parsed.org.apache.jena.rdf.model.ModelsendDescribeQuery(String query)Sends the given DESCRIBE query to the storage service and returns aModelvalue ornullif an error occurs, the service needs too much time to respond or the response couldn't be parsed.booleansendInsertQuery(org.apache.jena.rdf.model.Model model, String graphURI)Inserts the given model into the storage and returnstrueif the query is successful orfalseif 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.ResultSetsendSelectQuery(String query)Sends the given SELECT query to the storage service and returns aResultSetvalue ornullif an error occurs, the service needs too much time to respond or the response couldn't be parsed.booleansendUpdateQuery(String query)Sends the given UPDATE query to the storage service and returnstrueif the query is successful orfalseif an error occurs or the service needs too much time to respond.voidsetMaxWaitingTime(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 givenRabbitRpcClient.- 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 RabbitMQConnection.- 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
falseif 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 aModelvalue ornullif 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 aModelvalue ornullif 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 aResultSetvalue ornullif 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 returnstrueif the query is successful orfalseif 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 returnstrueif the query is successful orfalseif an error occurs or the service needs too much time to respond.- Parameters:
model- RDF model containing triples that should be insertedgraphURI- 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 IOExceptionCloses the internal
rpcClientinstance.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-