Class DatabaseAsyncExecutorImpl

    • Method Detail

      • setTransactionUseWAL

        public void setTransactionUseWAL​(boolean transactionUseWAL)
        Description copied from interface: DatabaseAsyncExecutor
        Changes the setting on using the WAL (Write Ahead Log - Transaction Journal) for asynchronous operations. The default setting is true = WAL enabled. Disabling the WAL is not recommended for online operations, but it can be used for the initial load/import of the database.
        Specified by:
        setTransactionUseWAL in interface DatabaseAsyncExecutor
        Parameters:
        transactionUseWAL - true to enable WAL for asynchronous operations, otherwise false
      • isTransactionUseWAL

        public boolean isTransactionUseWAL()
        Description copied from interface: DatabaseAsyncExecutor
        Returns the current settings if the WAL (Write Ahead Log - Transaction Journal) is active for asynchronous operations.
        Specified by:
        isTransactionUseWAL in interface DatabaseAsyncExecutor
        Returns:
        true if active, otherwise false
      • getCheckForStalledQueuesMaxDelay

        public long getCheckForStalledQueuesMaxDelay()
      • setCheckForStalledQueuesMaxDelay

        public void setCheckForStalledQueuesMaxDelay​(long checkForStalledQueuesMaxDelay)
      • onOk

        public void onOk​(OkCallback callback)
        Description copied from interface: DatabaseAsyncExecutor
        Defines a global callback to handle all the returns from asynchronous operations completed without errors.
        Specified by:
        onOk in interface DatabaseAsyncExecutor
        Parameters:
        callback - Callback invoked when an asynchronous operation succeeds
      • onError

        public void onError​(ErrorCallback callback)
        Description copied from interface: DatabaseAsyncExecutor
        Defines a global callback to handle all the errors from asynchronous operations.
        Specified by:
        onError in interface DatabaseAsyncExecutor
        Parameters:
        callback - Callback invoked when an asynchronous operation fails
      • waitCompletion

        public boolean waitCompletion​(long timeout)
        Description copied from interface: DatabaseAsyncExecutor
        Waits for the completion of all the pending tasks.
        Specified by:
        waitCompletion in interface DatabaseAsyncExecutor
        Parameters:
        timeout - timeout in milliseconds
        Returns:
        true if returns before the timeout expires or any interruptions, otherwise false
      • query

        public void query​(String language,
                          String query,
                          AsyncResultsetCallback callback,
                          Object... args)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the execution of a query as an idempotent (read only) command by specifying the language and an optional variable array of arguments.
        Specified by:
        query in interface DatabaseAsyncExecutor
        Parameters:
        language - The language to use between the supported ones ("sql", "gremlin", "cypher", "graphql", "mongo", etc.)
        query - The command to be interpreted in the specified language as a string
        callback - Callback to manage the query result
        args - (optional) Arguments to pass to the command as a variable length array
      • query

        public void query​(String language,
                          String query,
                          AsyncResultsetCallback callback,
                          Map<String,​Object> args)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the execution of a query as an idempotent (read only) command by specifying the language and arguments in a map.
        Specified by:
        query in interface DatabaseAsyncExecutor
        Parameters:
        language - The language to use between the supported ones ("sql", "gremlin", "cypher", "graphql", "mongo", etc.)
        query - The command to be interpreted in the specified language as a string
        callback - Callback to manage the query result
        args - Arguments to pass to the command as a map of name/values
      • command

        public void command​(String language,
                            String query,
                            AsyncResultsetCallback callback,
                            Object... args)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the execution of a command by specifying the language and an optional variable array of arguments.
        Specified by:
        command in interface DatabaseAsyncExecutor
        Parameters:
        language - The language to use between the supported ones ("sql", "gremlin", "cypher", "graphql", "mongo", etc.)
        query - The command to be interpreted in the specified language as a string
        callback - Callback to manage the command result
        args - (optional) Arguments to pass to the command as a variable length array
      • command

        public void command​(String language,
                            String query,
                            AsyncResultsetCallback callback,
                            Map<String,​Object> args)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the execution of a command by specifying the language and arguments in a map.
        Specified by:
        command in interface DatabaseAsyncExecutor
        Parameters:
        language - The language to use between the supported ones ("sql", "gremlin", "cypher", "graphql", "mongo", etc.)
        query - The command to be interpreted in the specified language as a string
        callback - Callback to manage the command result
        args - Arguments to pass to the command as a map of name/values
      • scanType

        public void scanType​(String typeName,
                             boolean polymorphic,
                             DocumentCallback callback)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the scan of the records contained in all the buckets defined by a type. This operation scans in sequence each bucket looking for documents, vertices and edges. For each record found a call to #DocumentCallback.onRecord is invoked. If the callback returns false, the scan is terminated, otherwise it continues to the next record.
        Specified by:
        scanType in interface DatabaseAsyncExecutor
        Parameters:
        typeName - The name of the type
        polymorphic - true if the records of all the subtypes must be included, otherwise only the records strictly contained in the #typeName will be scanned
        callback - Callback to handle the loaded record document. Returns false to interrupt the scan operation, otherwise true to continue till the end
      • scanType

        public void scanType​(String typeName,
                             boolean polymorphic,
                             DocumentCallback callback,
                             ErrorRecordCallback errorRecordCallback)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the scan of the records contained in all the buckets defined by a type. This operation scans in sequence each bucket looking for documents, vertices and edges. For each record found a call to #DocumentCallback.onRecord is invoked. If the callback returns false, the scan is terminated, otherwise it continues to the next record.
        Specified by:
        scanType in interface DatabaseAsyncExecutor
        Parameters:
        typeName - The name of the type
        polymorphic - true if the records of all the subtypes must be included, otherwise only the records strictly contained in the #typeName will be scanned
        callback - Callback to handle the loaded record document. Returns false to interrupt the scan operation, otherwise true to continue till the end
        errorRecordCallback - Callback used in case of error during the scan
      • transaction

        public void transaction​(BasicDatabase.TransactionScope txBlock,
                                int retries)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the request to execute a lambda in the transaction scope. In case an exception is thrown inside the lambda method, the transaction is rolled back. The difference with the method DatabaseAsyncExecutor.transaction(Database.TransactionScope) is that in case the NeedRetryException exception is thrown, the * transaction is re-executed for a number of retries.
        Specified by:
        transaction in interface DatabaseAsyncExecutor
        Parameters:
        txBlock - Transaction lambda to execute
        retries - Number of retries in case the NeedRetryException exception is thrown
      • transaction

        public void transaction​(BasicDatabase.TransactionScope txBlock,
                                int retries,
                                OkCallback ok,
                                ErrorCallback error)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the request to execute a lambda in the transaction scope. In case an exception is thrown inside the lambda method, the transaction is rolled back. The difference with the method DatabaseAsyncExecutor.transaction(Database.TransactionScope) is that in case the NeedRetryException exception is thrown, the transaction is re-executed for a number of retries.
        Specified by:
        transaction in interface DatabaseAsyncExecutor
        Parameters:
        txBlock - Transaction lambda to execute
        retries - Number of retries in case the NeedRetryException exception is thrown
        ok - Callback executed in case the transaction is committed
        error - Callback executed in case of error after the transaction is rolled back
      • transaction

        public void transaction​(BasicDatabase.TransactionScope txBlock,
                                int retries,
                                OkCallback ok,
                                ErrorCallback error,
                                int slot)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the request to execute a lambda in the transaction scope. In case an exception is thrown inside the lambda method, the transaction is rolled back. The difference with the method DatabaseAsyncExecutor.transaction(Database.TransactionScope) is that in case the NeedRetryException exception is thrown, the transaction is re-executed for a number of retries. The slot parameter is useful to avoid concurrency in particular use cases.
        Specified by:
        transaction in interface DatabaseAsyncExecutor
        Parameters:
        txBlock - Transaction lambda to execute
        retries - Number of retries in case the NeedRetryException exception is thrown
        ok - Callback executed in case the transaction is committed
        error - Callback executed in case of error after the transaction is rolled back
        slot - slot number to execute the transaction
      • createRecord

        public void createRecord​(Record record,
                                 String bucketName,
                                 NewRecordCallback newRecordCallback)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the request to create a record in a specific bucket. The bucket must be one defined in the schema to store the records of the current type. If the record is created successfully, the callback @NewRecordCallback is executed.
        Specified by:
        createRecord in interface DatabaseAsyncExecutor
        Parameters:
        record - Record to create
        newRecordCallback - Callback invoked after the record has been created
      • createRecord

        public void createRecord​(Record record,
                                 String bucketName,
                                 NewRecordCallback newRecordCallback,
                                 ErrorCallback errorCallback)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the request to create a record in a specific bucket. The bucket must be one defined in the schema to store the records of the current type. If the record is created successfully, the callback @NewRecordCallback is executed.
        Specified by:
        createRecord in interface DatabaseAsyncExecutor
        Parameters:
        record - Record to create
        newRecordCallback - Callback invoked after the record has been created
        errorCallback - Callback invoked in case of error
      • newEdge

        public void newEdge​(Vertex sourceVertex,
                            String edgeType,
                            RID destinationVertexRID,
                            boolean bidirectional,
                            boolean light,
                            NewEdgeCallback callback,
                            Object... properties)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the creation of an edge between two vertices. If the edge is created successfully, the callback @NewEdgeCallback is executed.
        Specified by:
        newEdge in interface DatabaseAsyncExecutor
        Parameters:
        sourceVertex - Source vertex instance
        edgeType - Type of the edge to create. The type must be defined in the schema beforehand
        destinationVertexRID - Destination vertex id as @RID
        bidirectional - True to create a bidirectional edge. Using bidirectional edges is always the recommended setting, unless advanced fine-tuning on performances
        light - True to create a light-weight edge. Using bidirectional edges is always the recommended setting, unless advanced fine-tuning on performances
        callback - Callback invoked when the edge is created
        properties - Initial properties to set to the new edge as a variable argument array with key/value pairs
      • newEdgeByKeys

        public void newEdgeByKeys​(String sourceVertexType,
                                  String sourceVertexKeyName,
                                  Object sourceVertexKeyValue,
                                  String destinationVertexType,
                                  String destinationVertexKeyName,
                                  Object destinationVertexKeyValue,
                                  boolean createVertexIfNotExist,
                                  String edgeType,
                                  boolean bidirectional,
                                  boolean lightWeight,
                                  NewEdgeCallback callback,
                                  Object... properties)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the request to creates a new edge between two vertices specifying the key/value pairs to lookup for both source and destination vertices. The direction of the edge is from source to destination. This API is useful for bulk import of edges.
        Specified by:
        newEdgeByKeys in interface DatabaseAsyncExecutor
        Parameters:
        sourceVertexType - Source vertex type name
        sourceVertexKeyName - Source vertex key
        sourceVertexKeyValue - Source vertex value
        destinationVertexType - Destination vertex type name
        destinationVertexKeyName - Destination vertex key
        destinationVertexKeyValue - Source vertex value
        createVertexIfNotExist - True to create vertices if the lookup did not find the vertices. This is valid for both source and destination vertices. In case the vertices are implicitly created, only the properties specified in keys and values will be set
        edgeType - Type of the edge to create. The type must be defined in the schema beforehand
        bidirectional - True to create a bidirectional edge. Using bidirectional edges is always the recommended setting, unless advanced fine-tuning on performances
        lightWeight - True to create a light-weight edge. Using bidirectional edges is always the recommended setting, unless advanced fine-tuning on performances
        callback - Callback invoked when the edge is created
        properties - Initial properties to set to the new edge as a variable argument array with key/value pairs
        See Also:
        DatabaseAsyncExecutor.newEdgeByKeys(String, String, Object, String, String, Object, boolean, String, boolean, boolean, NewEdgeCallback, Object...), DatabaseAsyncExecutor.newEdgeByKeys(String, String[], Object[], String, String[], Object[], boolean, String, boolean, boolean, NewEdgeCallback, Object...)
      • newEdgeByKeys

        public void newEdgeByKeys​(String sourceVertexType,
                                  String[] sourceVertexKeyNames,
                                  Object[] sourceVertexKeyValues,
                                  String destinationVertexType,
                                  String[] destinationVertexKeyNames,
                                  Object[] destinationVertexKeyValues,
                                  boolean createVertexIfNotExist,
                                  String edgeType,
                                  boolean bidirectional,
                                  boolean lightWeight,
                                  NewEdgeCallback callback,
                                  Object... properties)
        Description copied from interface: DatabaseAsyncExecutor
        Schedules the request to creates a new edge between two vertices specifying the key/value pairs to lookup for both source and destination vertices. The direction of the edge is from source to destination. This API is useful for bulk import of edges.
        Specified by:
        newEdgeByKeys in interface DatabaseAsyncExecutor
        Parameters:
        sourceVertexType - Source vertex type name
        sourceVertexKeyNames - Source vertex keys
        sourceVertexKeyValues - Source vertex values
        destinationVertexType - Destination vertex type name
        destinationVertexKeyNames - Destination vertex keys
        destinationVertexKeyValues - Source vertex values
        createVertexIfNotExist - True to create vertices if the lookup did not find the vertices. This is valid for both source and destination vertices. In case the vertices are implicitly created, only the properties specified in keys and values will be set
        edgeType - Type of the edge to create. The type must be defined in the schema beforehand
        bidirectional - True to create a bidirectional edge. Using bidirectional edges is always the recommended setting, unless advanced fine-tuning on performances
        lightWeight - True to create a light-weight edge. Using bidirectional edges is always the recommended setting, unless advanced fine-tuning on performances
        callback - Callback invoked when the edge is created
        properties - Initial properties to set to the new edge as a variable argument array with key/value pairs
        See Also:
        DatabaseAsyncExecutor.newEdgeByKeys(String, String, Object, String, String, Object, boolean, String, boolean, boolean, NewEdgeCallback, Object...), DatabaseAsyncExecutor.newEdgeByKeys(String, String[], Object[], String, String[], Object[], boolean, String, boolean, boolean, NewEdgeCallback, Object...)
      • close

        public void close()
      • getParallelLevel

        public int getParallelLevel()
        Description copied from interface: DatabaseAsyncExecutor
        Returns the number of executor threads for asynchronous operations.
        Specified by:
        getParallelLevel in interface DatabaseAsyncExecutor
        Returns:
        the number of executor threads for asynchronous operations
      • setParallelLevel

        public void setParallelLevel​(int parallelLevel)
        Description copied from interface: DatabaseAsyncExecutor
        Changes the number of executor threads for asynchronous operations. It is recommended to keep this number equals or lower than the actual cores available on the server.
        Specified by:
        setParallelLevel in interface DatabaseAsyncExecutor
        Parameters:
        parallelLevel - Number of executor threads
      • getBackPressure

        public int getBackPressure()
        Description copied from interface: DatabaseAsyncExecutor
        Returns the current settings for backpressure in terms of percentage from 0 (disabled) to 100 of how much the queue is full to activate backpressure. The default setting is 0 (disabled).
        Specified by:
        getBackPressure in interface DatabaseAsyncExecutor
        Returns:
        A value from 0 to 100. 0 means backpressure disabled
      • setBackPressure

        public void setBackPressure​(int percentage)
        Description copied from interface: DatabaseAsyncExecutor
        Sets when the threshold when the backpressure is used. The percentage is how much the asynchronous queue is full before the backpressure kicks in. When the backpressure is active, the request to enqueue asynchronous operations is delayed exponentially with the amount of free slots in the queue. The default setting is 0 (disabled).
        Specified by:
        setBackPressure in interface DatabaseAsyncExecutor
        Parameters:
        percentage - Value from 0 (disabled) to 100 of how much the queue is full to activate backpressure
      • scheduleTask

        public boolean scheduleTask​(int slot,
                                    DatabaseAsyncTask task,
                                    boolean waitIfQueueIsFull,
                                    int applyBackPressureOnPercentage)
        Schedule a task to be executed by parallel executors.
        Parameters:
        slot - slot id
        task - task to schedule
        waitIfQueueIsFull - true to wait in case the queue is full, otherwise false
        Returns:
        true if the task has been scheduled, otherwise false
      • getSlot

        public int getSlot​(int value)