Interface ServerConnection

All Superinterfaces:
AutoCloseable

public interface ServerConnection extends AutoCloseable
Encapsulates a connection to an RDFox server. All instances of this class are single-threaded — that is, methods should not be called simultaneously on distinct threads, and an JRDFoxException will be thrown if this requirement is violated. However, there is no thread affinity — that is, methods on one connection can be called from different threads as long as the calls are serialized externally. The interrupt(), duplicate(), and newDataStoreConnection(String dataStoreName) methods are exceptions: they can be invoked in parallel with any other method apart from close(). Calling close() in parallel with any other method is considered a serious bug in the client code; however, to safeguard against JVM crashes and aid debugging, RDFox will throw an IllegalStateException. Multiple connections should be used to access a server concurrently, in which case all access to the server is serialized. A connection must be closed after use to release the resources associated with it.
  • Field Details

    • ACCESS_TYPE_NONE

      static final byte ACCESS_TYPE_NONE
      A flag specifying no access to a resource.
      See Also:
    • ACCESS_TYPE_READ

      static final byte ACCESS_TYPE_READ
      A flag specifying read access to a resource.
      See Also:
    • ACCESS_TYPE_WRITE

      static final byte ACCESS_TYPE_WRITE
      A flag specifying write access to a resource.
      See Also:
    • ACCESS_TYPE_GRANT

      static final byte ACCESS_TYPE_GRANT
      A flag specifying grant access to a resource.
      See Also:
    • ACCESS_TYPE_STAR

      static final byte ACCESS_TYPE_STAR
      A flag specifying all access types to a resource.
      See Also:
  • Method Details

    • close

      void close()
      Closes the data store connection by freeing all resources associated with it. Once a connection is closed, it cannot be used any further. Calling this method in parallel with any other method runs a very high risk of crashing the JVM.
      Specified by:
      close in interface AutoCloseable
    • interrupt

      void interrupt() throws JRDFoxException
      Tries to interrupt an operation that is running in parallel on this connection. RDFox will make a best effort to interrupt an operation, but there are no guarantees that the operation will indeed be interrupted. An operation will throw an OperationInterruptedException exception. This method can be called concurrently with any other method apart from close().
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getAgentName

      String getAgentName() throws JRDFoxException
      Returns the name of the agent currently associated with this connection.
      Returns:
      the name of the agent currently associated with this connection
      Throws:
      JRDFoxException - thrown if there is an error
    • duplicate

      ServerConnection duplicate() throws JRDFoxException
      Creates a new connection to the same data store. The new connection inherits the role name from this one. The main use of this method is to avoid having to specify the role credentials again.
      Returns:
      a new connection to the same server
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getParameters

      Map<String,String> getParameters() throws JRDFoxException
      Returns the parameters that the server was created with.
      Returns:
      the parameters of the server
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getRDFoxVersion

      String getRDFoxVersion() throws JRDFoxException
      Returns the version string of the RDFox instance.
      Returns:
      the version string of the RDFox instance
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getRDFoxGitSHA

      String getRDFoxGitSHA() throws JRDFoxException
      Returns the string containing the Git SHA identifying the precise version of the RDFox instance code.
      Returns:
      the Git SHA string of the RDFox instance
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getLicenseMessage

      String getLicenseMessage() throws JRDFoxException
      Returns the license message of the RDFox instance.
      Returns:
      the license message of the RDFox instance
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getMemoryUse

      long[] getMemoryUse() throws JRDFoxException
      Returns the current memory use of RDFox.
      Returns:
      an array of length two where the element with index 0 contains the maximum allowed memory use, and the element with index 1 contains the currently available memory in bytes
      Throws:
      JRDFoxException - thrown if an error is encountered
    • setMaxMemoryUse

      void setMaxMemoryUse(long maxUsedBytes) throws JRDFoxException
      Sets the maximum amount of memory that RDFox is allowed to use.
      Parameters:
      maxUsedBytes - the maximum amount of memory in bytes that RDFox is allowed to use
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getNumberOfThreads

      int getNumberOfThreads() throws JRDFoxException
      Returns the number of threads that the server uses for various tasks such as reasoning and data importation.
      Returns:
      the number of threads used by the server
      Throws:
      JRDFoxException - thrown if an error is encountered
    • setNumberOfThreads

      void setNumberOfThreads(int numberOfThreads) throws JRDFoxException
      Sets the number of threads that the server should use for various tasks such as reasoning and data importation. This operation can be invoked only if no transaction is active.
      Parameters:
      numberOfThreads - the number of threads that the server should use
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getServerVersion

      int getServerVersion() throws JRDFoxException
      Returns the current server version.
      Returns:
      the current server version
      Throws:
      JRDFoxException - thrown if an error is encountered
    • checkIntegrity

      boolean checkIntegrity(int maxErrorsOfSameType, OutputStream outputStream) throws JRDFoxException
      Checks the integrity of this server and reports any problems that might have occurred. No problems should be reported under normal operation; hence, if this operation reports a problem, please contact OST customer support immediately.
      Parameters:
      maxErrorsOfSameType - the maximum number of errors of one type that should be printed
      outputStream - the stream for receiving information about any problems
      Returns:
      true if any errors were detected during the check
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getComponentInfo

      ComponentInfo getComponentInfo(boolean extended) throws JRDFoxException
      Returns diagnostic information about the server as a tree of objects each providing detailed information about the server. Note: This information should be used for diagnostics purposes only. The content of ComponentInfo is subject to change in future version. Callers should not rely on named property or a specific subcomponent being present.
      Parameters:
      extended - if true, the information about all data stores will be returned as well
      Returns:
      information about the server
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getAPILoggingEnabled

      boolean getAPILoggingEnabled() throws JRDFoxException
      Returns whether the API logging is enabled on the server.
      Returns:
      true if the API logging is enabled on the server, and false otherwise.
      Throws:
      JRDFoxException - thrown if an error is encountered
    • setAPILoggingEnabled

      void setAPILoggingEnabled(boolean enabled) throws JRDFoxException
      Enables or disables the API logging on the server.
      Parameters:
      enabled - if true, the API logging will be enabled on the server, and if false, it will be disabled.
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getAPILoggingDirectory

      String getAPILoggingDirectory() throws JRDFoxException
      Returns the directory where the API logging files are stored on the server.
      Returns:
      the directory where the API logging files are stored on the server.
      Throws:
      JRDFoxException - thrown if an error is encountered
    • setAPILoggingDirectory

      void setAPILoggingDirectory(String directory) throws JRDFoxException
      Sets the directory where the API logging files are stored on the server.
      Parameters:
      directory - the directory where the API logging files are to be stored on the server.
      Throws:
      JRDFoxException - thrown if an error is encountered
    • getAPILoggingInputRecordingLimit

      long getAPILoggingInputRecordingLimit() throws JRDFoxException
      Returns the limit on the size of input recording for API logging in bytes. If the limit is exceeded, the input recording will be truncated.
      Returns:
      the limit on the size of input recording for API logging in bytes
      Throws:
      JRDFoxException - thrown if an error is encountered
    • setAPILoggingInputRecordingLimit

      void setAPILoggingInputRecordingLimit(long inputRecordingLimit) throws JRDFoxException
      Sets the limit on the size of input recording for API logging in bytes. If the limit is exceeded, the input recording will be truncated.
      Parameters:
      inputRecordingLimit - the limit on the size of input recording for API logging in bytes
      Throws:
      JRDFoxException - thrown if an error is encountered
    • listDataStores

      Map<String, Optional<DataStoreInfo>> listDataStores() throws JRDFoxException
      Returns the list of data stores available at the connected server. The result is a map from data store names to optional objects containing data store information. If the user has sufficient privileges to access a particular data store, the optional will contain the information about the data store; otherwise, the optional will be empty.
      Returns:
      the list data stores available at the server
      Throws:
      JRDFoxException - thrown if an error is encountered
    • containsDataStore

      boolean containsDataStore(String dataStoreName) throws JRDFoxException
      Returns true if the connected server contains a data store with the given name.
      Parameters:
      dataStoreName - the name of a data store
      Returns:
      true if the server contains a data store with the name dataStoreName
      Throws:
      JRDFoxException - thrown if an error is encountered
    • describeDataStore

      DataStoreInfo describeDataStore(String dataStoreName) throws JRDFoxException
      Returns information about the data store with the given name.
      Parameters:
      dataStoreName - the name of the data store whose information is to be returned
      Returns:
      information about the data store
      Throws:
      JRDFoxException - thrown if an error is encountered
    • createDataStore

      void createDataStore(String dataStoreName, Map<String,String> dataStoreParameters) throws JRDFoxException
      Creates a data store with the given name. The remaining parameters specify the data store type, as well as various data store parameters. The server should not contain a data store with the specified name.
      Parameters:
      dataStoreName - the name of the newly created data store
      dataStoreParameters - the key-value pairs determining various data store parameters (see Data Store Parameters)
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server already contains a data store with the given name, or if some of the parameters are incorrect)
    • loadDataStoreFromBinaryFormat

      void loadDataStoreFromBinaryFormat(String dataStoreName, InputStream inputStream, String decryptionAlgorithm, String decryptionKey, Map<String,String> dataStoreParameters) throws JRDFoxException
      Loads a data store with the given name from an input stream containing the store saved in the standard or raw format. If dataStoreParameters is not null, the loaded data store will be initialised using the specified parameters, which are the same as in the createDataStore(String, Map) method. Please note that, if the * input contains a data store in the raw format, the parameters must be exactly the same as in the input. In contrast, if the input contains a data store in the standard format, most parameters (apart from the equality mode) can be overridden; hence, this method can be used to transfer the data from one data store to another. If decryptionKey is not null, its content will be interpreted as a base64-encoded key that is to be used to decrypt the input data. The server should not contain a data store with the specified name. If the decryption key is specified but a decryption algorithm is not, then AES-256-CBC is used.
      Parameters:
      dataStoreName - the name of the newly created data store
      inputStream - contains the data store encoded using the standard or the raw format
      decryptionAlgorithm - null, or the name of the algorithm used to decrypt the input data
      decryptionKey - null, or a base64-encoded key that is to be used to decrypt the input data
      dataStoreParameters - null, or the key-value pairs determining various data store parameters (see Data Store Parameters)
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server already contains a data store with the given name, or if the file format is incorrect)
    • loadDataStoreFromBinaryFormat

      void loadDataStoreFromBinaryFormat(String dataStoreName, File file, String decryptionAlgorithm, String decryptionKey, Map<String,String> dataStoreParameters) throws JRDFoxException
      Loads a data store with the given name from a file containing the store saved in the standard or raw format. If dataStoreParameters is not null, the loaded data store will be initialised using the specified parameters, which are the same as in the createDataStore(String, Map) method. Please note that, if the * input contains a data store in the raw format, the parameters must be exactly the same as in the input. In contrast, if the input contains a data store in the standard format, most parameters (apart from the equality mode) can be overridden; hence, this method can be used to transfer the data from one data store to another. If decryptionKey is not null, its content will be interpreted as a base64-encoded key that is to be used to decrypt the input data. The server should not contain a data store with the specified name. If the decryption key is specified but a decryption algorithm is not, then AES-256-CBC is used.
      Parameters:
      dataStoreName - the name of the newly created data store
      file - contains the data store encoded using the standard or the raw format
      decryptionAlgorithm - null, or the name of the algorithm used to decrypt the input data
      decryptionKey - null, or a base64-encoded key that is to be used to decrypt the input data
      dataStoreParameters - null, or the key-value pairs determining various data store parameters (see Data Store Parameters)
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server already contains a data store with the given name, or if the file format is incorrect)
    • saveDataStoreToBinaryFormat

      void saveDataStoreToBinaryFormat(String dataStoreName, OutputStream outputStream, String encryptionAlgorithm, String encryptionKey, BinaryDataStoreFormat format) throws JRDFoxException
      Saves a data store into the specified binary format. This operation can be invoked only if no transaction is active. If the encryption key is specified but an encryption algorithm is not, then AES-256-CBC is used.
      Parameters:
      dataStoreName - the name of the data store to save
      outputStream - receives the binary content of the data store
      encryptionAlgorithm - null, or the name of an encryption algorithm to use
      encryptionKey - null, or a base64-encoded key that is to be used to encrypt the input data
      format - specifies the format in which the store is saved
      Throws:
      JRDFoxException - thrown if an error is encountered
    • saveDataStoreToBinaryFormat

      void saveDataStoreToBinaryFormat(String dataStoreName, OutputStream outputStream, String encryptionAlgorithm, String encryptionKey, BinaryDataStoreFormat format, DataStoreOperationStartMonitor dataStoreOperationStartMonitor) throws JRDFoxException
      Saves a data store into the specified binary format if the validation of the operation passes. This operation can be invoked only if no transaction is active. If the encryption key is specified but an encryption algorithm is not, then AES-256-CBC is used.
      Parameters:
      dataStoreName - the name of the data store to save
      outputStream - receives the binary content of the data store
      encryptionAlgorithm - null, or the name of an encryption algorithm to use
      encryptionKey - null, or a base64-encoded key that is to be used to encrypt the input data
      format - specifies the format in which the store is saved
      dataStoreOperationStartMonitor - null, or a pointer to a callback interface that will validate the save operation
      Throws:
      JRDFoxException - thrown if an error is encountered
    • saveDataStoreToBinaryFormat

      void saveDataStoreToBinaryFormat(String dataStoreName, File file, String encryptionAlgorithm, String encryptionKey, BinaryDataStoreFormat format) throws JRDFoxException
      Saves a data store into the specified binary format. This operation can be invoked only if no transaction is active. If the encryption key is specified but an encryption algorithm is not, then AES-256-CBC is used.
      Parameters:
      dataStoreName - the name of the data store to save
      file - receives the binary content of the data store
      encryptionAlgorithm - null, or the name of an encryption algorithm to use
      encryptionKey - null, or a base64-encoded key that is to be used to encrypt the input data
      format - specifies the format in which the store is saved
      Throws:
      JRDFoxException - thrown if an error is encountered
    • saveDataStoreToBinaryFormat

      void saveDataStoreToBinaryFormat(String dataStoreName, File file, String encryptionAlgorithm, String encryptionKey, BinaryDataStoreFormat format, DataStoreOperationStartMonitor dataStoreOperationStartMonitor) throws JRDFoxException
      Saves a data store into the specified binary format if the validation of the operation passes. This operation can be invoked only if no transaction is active. If the encryption key is specified but an encryption algorithm is not, then AES-256-CBC is used.
      Parameters:
      dataStoreName - the name of the data store to save
      file - receives the binary content of the data store
      encryptionAlgorithm - null, or the name of an encryption algorithm to use
      encryptionKey - null, or a base64-encoded key that is to be used to encrypt the input data
      format - specifies the format in which the store is saved
      dataStoreOperationStartMonitor - null, or a pointer to a callback interface that will validate the save operation
      Throws:
      JRDFoxException - thrown if an error is encountered
    • deleteDataStore

      void deleteDataStore(String dataStoreName) throws JRDFoxException
      Deletes a data store with the given name from the server. A data store can be deleted only if no connections are open to it.
      Parameters:
      dataStoreName - the name of the data store to delete
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server does not contain a data store with the given name)
    • deleteDataStore

      void deleteDataStore(String dataStoreName, DataStoreOperationStartMonitor dataStoreOperationStartMonitor) throws JRDFoxException
      Deletes a data store with the given name from the server if the validation of the operation passes. A data store can be deleted only if no connections are open to it.
      Parameters:
      dataStoreName - the name of the data store to delete
      dataStoreOperationStartMonitor - null, or a pointer to a callback interface that will validate the deletion operation
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server does not contain a data store with the given name)
    • isDataStoreOnline

      boolean isDataStoreOnline(String dataStoreName) throws JRDFoxException
      Checks whether the data store with the given name is online
      Parameters:
      dataStoreName - the name of the data store to check
      Returns:
      true if the data store with the given name is online
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server does not contain a data store with the given name)
    • bringDataStoreOnline

      boolean bringDataStoreOnline(String dataStoreName) throws JRDFoxException
      Makes sure that the data store with the given name is online. If the data store is already online, this is a no-op.
      Parameters:
      dataStoreName - the name of the data store to bring online
      Returns:
      true if the data store was offline
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server does not contain a data store with the given name)
    • bringDataStoreOffline

      OfflineRequestResult bringDataStoreOffline(String dataStoreName) throws JRDFoxException
      Makes sure that the data store with the given name is offline. If the data store is already offline, this is a no-op.
      Parameters:
      dataStoreName - the name of the data store to bring offline
      Returns:
      describes the result of the request
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server does not contain a data store with the given name)
    • newDataStoreConnection

      DataStoreConnection newDataStoreConnection(String dataStoreName) throws JRDFoxException
      Creates a connection to the data store of this server with the given name. The new data store connection uses the same credentials as this server connection.
      Parameters:
      dataStoreName - the name of the data store to connect to
      Returns:
      a connection to the specified data store
      Throws:
      JRDFoxException - thrown if an error is encountered (e.g., if the server does not contain a data store with the given name)
    • listRoles

      List<String> listRoles() throws JRDFoxException
      Returns the list of all roles available at the server.
      Returns:
      the list of all roles available at the server.
      Throws:
      JRDFoxException - thrown if there is an error
    • createRole

      void createRole(String roleName, String password) throws JRDFoxException
      Creates a new role with the given name and password.
      Parameters:
      roleName - the new role name
      password - the password of the new role
      Throws:
      JRDFoxException - thrown if there is an error
    • createRole

      void createRole(String roleName, PasswordSpecificationType passwordSpecificationType, String password) throws JRDFoxException
      Creates a new role with the given name and password.
      Parameters:
      roleName - the new role name
      passwordSpecificationType - the specification type of the password parameter
      password - the password, password hash, or empty string as determined by passwordSpecificationType
      Throws:
      JRDFoxException - thrown if there is an error
    • deleteRole

      void deleteRole(String roleName) throws JRDFoxException
      Deletes a role with the given name.
      Parameters:
      roleName - the name of the role to delete
      Throws:
      JRDFoxException - thrown if there is an error
    • changeRolePassword

      void changeRolePassword(String currentPassword, String newPassword) throws JRDFoxException
      Creates the password of the role that is associated with this connection. The change is performed only if the current password matches.
      Parameters:
      currentPassword - the current password of the role associated with this connection
      newPassword - the new password for the role associated with this connection
      Throws:
      JRDFoxException - thrown if there is an error
    • getRolePasswordHash

      String getRolePasswordHash(String roleName) throws JRDFoxException
      Returns the password hash for the given role name.
      Parameters:
      roleName - the name of the role for which the password hash should be returned
      Returns:
      the password hash
      Throws:
      JRDFoxException - thrown if there is an error
    • listRoleMemberships

      List<String> listRoleMemberships(String roleName) throws JRDFoxException
      Lists the roles that the given role is a member of.
      Parameters:
      roleName - the name of the role for which the memberships should be returned
      Returns:
      the list of roles that the given role is a member of
      Throws:
      JRDFoxException - thrown if there is an error
    • listRoleMembers

      List<String> listRoleMembers(String roleName) throws JRDFoxException
      Lists the roles that are members of the given role.
      Parameters:
      roleName - the name of the role for which the members should be returned
      Returns:
      the list of roles that are members of the given role
      Throws:
      JRDFoxException - thrown if there is an error
    • isMemberOf

      boolean isMemberOf(String roleName, String superRoleName) throws JRDFoxException
      Checks whether the given role is a member of another super-role.
      Parameters:
      roleName - the name of the role for which the check is performed
      superRoleName - the name of the potential super-role for which the check is performed
      Returns:
      true if the given role is a member of another super-role.
      Throws:
      JRDFoxException - thrown if there is an error
    • grantRole

      boolean grantRole(String roleName, String superRoleName) throws JRDFoxException
      Grants the membership of a role in another role.
      Parameters:
      roleName - the name of the role that is to be made member of superRoleName
      superRoleName - the name of the role that should get roleName as member
      Returns:
      true if the role was granted, false if it was already held
      Throws:
      JRDFoxException - thrown if there is an error
    • revokeRole

      boolean revokeRole(String roleName, String superRoleName) throws JRDFoxException
      Revokes the membership of a role in another role.
      Parameters:
      roleName - the name of the role that should stop being member of superRoleName
      superRoleName - the name of the role that for which roleName should stop being a member
      Returns:
      true if the role was revoked, false if it was not held in the first place
      Throws:
      JRDFoxException - thrown if there is an error
    • listPrivileges

      Map<String,Byte> listPrivileges(String roleName) throws JRDFoxException
      Lists the privileges of a given role. The result is a map of resource specifiers to the access types that the role currently has.
      Parameters:
      roleName - the name of the role whose privileges are being listed
      Returns:
      the map of resource specifiers to the access types (specified as a bit-mask of ACCESS_TYPE_* values)
      Throws:
      JRDFoxException - thrown if there is an error
    • grantPrivileges

      boolean grantPrivileges(String roleName, String resourceSpecifier, byte accessTypesToGrant) throws JRDFoxException
      Grants privileges over a resource specifier to a role.
      Parameters:
      roleName - the name of the role to which the privileges are being granted
      resourceSpecifier - identifies a resource to which the privileges are being granted
      accessTypesToGrant - the access types (specified as a bit-mask of ACCESS_TYPE_* values) that are to be granted
      Returns:
      true if the privileges were granted, false if they were already held
      Throws:
      JRDFoxException - thrown if there is an error
    • revokePrivileges

      boolean revokePrivileges(String roleName, String resourceSpecifier, byte accessTypesToRevoke) throws JRDFoxException
      Revokes privileges over a resource specifier from a role.
      Parameters:
      roleName - the name of the role to which the privileges are being granted
      resourceSpecifier - identifies a resource to which the privileges are being granted
      accessTypesToRevoke - the access types (specified as a bit-mask of ACCESS_TYPE_* values) that are to be revoked
      Returns:
      true if the privileges were revoked, false if they weren't held in the first place
      Throws:
      JRDFoxException - thrown if there is an error