Class GridTaskSessionImpl

    • Constructor Detail

      • GridTaskSessionImpl

        public GridTaskSessionImpl​(UUID taskNodeId,
                                   String taskName,
                                   @Nullable
                                   @Nullable GridDeployment dep,
                                   String taskClsName,
                                   IgniteUuid sesId,
                                   @Nullable
                                   @Nullable Collection<UUID> top,
                                   @Nullable
                                   @Nullable IgnitePredicate<ClusterNode> topPred,
                                   long startTime,
                                   long endTime,
                                   Collection<ComputeJobSibling> siblings,
                                   @Nullable
                                   @Nullable Map<Object,​Object> attrs,
                                   GridKernalContext ctx,
                                   boolean fullSup,
                                   boolean internal,
                                   @Nullable
                                   @Nullable String execName,
                                   @Nullable
                                   @Nullable SecurityContext secCtx)
        Constructor.
        Parameters:
        taskNodeId - Task node ID.
        taskName - Task name.
        dep - Deployment.
        taskClsName - Task class name.
        sesId - Task session ID.
        top - Topology.
        topPred - Topology predicate.
        startTime - Task execution start time.
        endTime - Task execution end time.
        siblings - Collection of siblings.
        attrs - Session attributes.
        ctx - Grid Kernal Context.
        fullSup - Session full support enabled flag.
        internal - Internal task flag.
        execName - Custom executor name.
        secCtx - Security context of the user who created the session, null if security is not enabled.
    • Method Detail

      • acquire

        public boolean acquire()
        Returns:
        True if session was acquired.
      • release

        public boolean release()
        Returns:
        True if session cannot be acquired any more.
      • getStartTime

        public long getStartTime()
        Gets start of computation time for the task.
        Specified by:
        getStartTime in interface ComputeTaskSession
        Returns:
        Start of computation time for the task.
      • waitForAttribute

        public <K,​V> V waitForAttribute​(K key,
                                              long timeout)
                                       throws InterruptedException
        Waits for the specified attribute to be set. If this attribute is already in session this method will return immediately.
        Specified by:
        waitForAttribute in interface ComputeTaskSession
        Type Parameters:
        K - Attribute key type.
        V - Attribute value type.
        Parameters:
        key - Attribute key to wait for.
        timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.
        Returns:
        Value of newly set attribute.
        Throws:
        InterruptedException - Thrown if wait was interrupted.
      • waitForAttribute

        public boolean waitForAttribute​(Object key,
                                        Object val,
                                        long timeout)
                                 throws InterruptedException
        Waits for the specified attribute to be set or updated with given value. Note that this method will block even if attribute is set for as long as its value is not equal to the specified.
        Specified by:
        waitForAttribute in interface ComputeTaskSession
        Parameters:
        key - Attribute key to wait for.
        val - Attribute value to wait for. Can be null.
        timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.
        Returns:
        Whether or not specified key/value pair has been set.
        Throws:
        InterruptedException - Thrown if wait was interrupted.
      • waitForAttributes

        public Map<?,​?> waitForAttributes​(Collection<?> keys,
                                                long timeout)
                                         throws InterruptedException
        Waits for the specified attributes to be set. If these attributes are already in session this method will return immediately.
        Specified by:
        waitForAttributes in interface ComputeTaskSession
        Parameters:
        keys - Attribute keys to wait for.
        timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.
        Returns:
        Attribute values mapped by their keys.
        Throws:
        InterruptedException - Thrown if wait was interrupted.
      • waitForAttributes

        public boolean waitForAttributes​(Map<?,​?> attrs,
                                         long timeout)
                                  throws InterruptedException
        Waits for the specified attributes to be set or updated with given values. Note that this method will block even if attributes are set for as long as their values are not equal to the specified.
        Specified by:
        waitForAttributes in interface ComputeTaskSession
        Parameters:
        attrs - Key/value pairs to wait for.
        timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.
        Returns:
        Whether or not key/value pair has been set.
        Throws:
        InterruptedException - Thrown if wait was interrupted.
      • getTaskName

        public String getTaskName()
        Gets task name of the task this session belongs to.
        Specified by:
        getTaskName in interface ComputeTaskSession
        Returns:
        Task name of the task this session belongs to.
      • getTaskClassName

        public String getTaskClassName()
        Returns task class name.
        Returns:
        Task class name.
      • getId

        public IgniteUuid getId()
        Gets session ID of the task being executed.
        Specified by:
        getId in interface ComputeTaskSession
        Returns:
        Session ID of the task being executed.
      • getEndTime

        public long getEndTime()
        Gets end of computation time for the task. No job within the task will be allowed to execute passed this time.
        Specified by:
        getEndTime in interface ComputeTaskSession
        Returns:
        End of computation time for the task.
      • getUserVersion

        public String getUserVersion()
        Returns:
        Task version.
      • setClassLoader

        public void setClassLoader​(ClassLoader clsLdr)
        Parameters:
        clsLdr - Class loader.
      • refreshJobSiblings

        public Collection<ComputeJobSibling> refreshJobSiblings()
        Refreshes collection of job siblings. This method has no effect when invoked on originating node, as the list of siblings is always most recent. However, when using continuous mapping (see ComputeTaskContinuousMapper), list of siblings on remote node may not be fresh. In that case, this method will re-request list of siblings from originating node.
        Specified by:
        refreshJobSiblings in interface ComputeTaskSession
        Returns:
        Refreshed collection of job siblings.
      • getJobSiblings

        public Collection<ComputeJobSibling> getJobSiblings()
        Gets a collection of all grid job siblings. Job siblings are grid jobs that are executing within the same task.

        If task uses continuous mapper (i.e. it injected into task class) then job siblings will be requested from task node for each apply.

        Specified by:
        getJobSiblings in interface ComputeTaskSession
        Returns:
        Collection of grid job siblings executing within this task.
      • getJobSibling

        public ComputeJobSibling getJobSibling​(IgniteUuid jobId)
        Gets job sibling for a given ID.

        If task uses continuous mapper (i.e. it injected into task class) then job sibling will be requested from task node for each apply.

        Specified by:
        getJobSibling in interface ComputeTaskSession
        Parameters:
        jobId - Job ID to get the sibling for.
        Returns:
        Grid job sibling for a given ID.
      • setAttribute

        public void setAttribute​(Object key,
                                 Object val)
        Sets session attributed. Note that task session is distributed and this attribute will be propagated to all other jobs within this task and task itself - i.e., to all accessors of this session. Other jobs then will be notified by ComputeTaskSessionAttributeListener callback than an attribute has changed.

        This method is no-op if the session has finished.

        Specified by:
        setAttribute in interface ComputeTaskSession
        Parameters:
        key - Attribute key.
        val - Attribute value. Can be null.
      • setAttributes

        public void setAttributes​(Map<?,​?> attrs)
        Sets task attributes. This method exists so one distributed replication operation will take place for the whole group of attributes passed in. Use it for performance reasons, rather than ComputeTaskSession.setAttribute(Object, Object) method, whenever you need to set multiple attributes.

        This method is no-op if the session has finished.

        Specified by:
        setAttributes in interface ComputeTaskSession
        Parameters:
        attrs - Attributes to set.
      • setInternal

        public void setInternal​(Map<?,​?> attrs)
        Parameters:
        attrs - Attributes to set.
      • addAttributeListener

        public void addAttributeListener​(ComputeTaskSessionAttributeListener lsnr,
                                         boolean rewind)
        Add listener for the session attributes.
        Specified by:
        addAttributeListener in interface ComputeTaskSession
        Parameters:
        lsnr - Listener to add.
        rewind - true value will result in calling given listener for all already received attributes, while false value will result only in new attribute notification. Settings rewind to true allows for a simple mechanism that prevents the loss of notifications for the attributes that were previously received or received while this method was executing.
      • removeCheckpoint

        public boolean removeCheckpoint​(String key)
        Removes previously saved job's state for a given key from an underlying storage. The storage implementation is defined by CheckpointSpi implementation used.

        Long running jobs may decide to store intermediate state to protect themselves from failures. This way whenever a job starts, it can load its previously saved state and continue with execution.

        Specified by:
        removeCheckpoint in interface ComputeTaskSession
        Parameters:
        key - Key for intermediate job state to load.
        Returns:
        true if job state was removed, false if state was not found.
        See Also:
        ComputeTaskSession.loadCheckpoint(String), CheckpointSpi
      • getTopologyPredicate

        @Nullable
        public @Nullable IgnitePredicate<ClusterNode> getTopologyPredicate()
        Returns:
        Topology predicate.
      • setCheckpointSpi

        public void setCheckpointSpi​(String cpSpi)
        Parameters:
        cpSpi - Checkpoint SPI name.
      • getFailoverSpi

        public String getFailoverSpi()
        Returns:
        Failover SPI name.
      • setFailoverSpi

        public void setFailoverSpi​(String failSpi)
        Parameters:
        failSpi - Failover SPI name.
      • getLoadBalancingSpi

        public String getLoadBalancingSpi()
        Returns:
        Load balancing SPI name.
      • setLoadBalancingSpi

        public void setLoadBalancingSpi​(String loadSpi)
        Parameters:
        loadSpi - Load balancing SPI name.
      • getSequenceNumber

        public long getSequenceNumber()
        Returns:
        Task internal version.
      • deployment

        public GridDeployment deployment()
        Returns:
        Deployment.
      • onMapped

        public void onMapped()
        Task map callback.
      • onDone

        public void onDone()
        Finish task callback.
      • isInternal

        public boolean isInternal()
        Returns:
        True if task is internal.
      • executorName

        @Nullable
        public @Nullable String executorName()
        Returns:
        Custom executor name.
      • jobNodes

        public void jobNodes​(Collection<UUID> jobNodes)
        Sets nodes on which the jobs of the task will be executed.
        Parameters:
        jobNodes - Nodes on which the jobs of the task will be executed.
      • jobNodesSafeCopy

        public List<UUID> jobNodesSafeCopy()
        Returns:
        Nodes on which the jobs of the task will be executed.
      • attributesSafeCopy

        public Map<Object,​Object> attributesSafeCopy()
        Returns:
        All session attributes, without checks.
      • initiatorSecurityContext

        public SecurityContext initiatorSecurityContext()
        Returns:
        Security context of the task initiator, null if security is not enabled.
      • login

        public Object login()
        Returns:
        User who created the session, null if security is not enabled.