Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.execution;
 
 
 
 
 import static com.google.common.base.MoreObjects.toStringHelper;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 public class TaskStateMachine
 {
     private static final Logger log = Logger.get(TaskStateMachine.class);
 
     private final DateTime createdTime = DateTime.now();
 
     private final TaskId taskId;
     private final StateMachine<TaskStatetaskState;
     private final LinkedBlockingQueue<ThrowablefailureCauses = new LinkedBlockingQueue<>();
 
     public TaskStateMachine(TaskId taskIdExecutor executor)
     {
         this. = checkNotNull(taskId"taskId is null");
          = new StateMachine<>("task " + taskIdexecutor.);
         {
             @Override
             public void stateChanged(TaskState newValue)
             {
                 .debug("Task %s is %s"TaskStateMachine.this.newValue);
             }
         });
     }
 
     public DateTime getCreatedTime()
     {
         return ;
     }
 
     public TaskId getTaskId()
     {
         return ;
     }
 
     public TaskState getState()
     {
         return .get();
     }
 
     public ListenableFuture<TaskStategetStateChange(TaskState currentState)
     {
         checkNotNull(currentState"currentState is null");
         checkArgument(!currentState.isDone(), "Current state is already done");
 
         ListenableFuture<TaskStatefuture = .getStateChange(currentState);
         TaskState state = .get();
         if (state.isDone()) {
             return Futures.immediateFuture(state);
         }
         return future;
     }
 
     {
         return ;
     }
 
     public void finished()
     {
     }
 
     public void cancel()
     {
     }
 
    public void abort()
    {
    }
    public void failed(Throwable cause)
    {
        .add(cause);
    }
    private void transitionToDoneState(TaskState doneState)
    {
        checkNotNull(doneState"doneState is null");
        checkArgument(doneState.isDone(), "doneState %s is not a done state"doneState);
        .setIf(doneStatecurrentState -> !currentState.isDone());
    }
    public Duration waitForStateChange(TaskState currentStateDuration maxWait)
            throws InterruptedException
    {
        return .waitForStateChange(currentStatemaxWait);
    }
    public void addStateChangeListener(StateChangeListener<TaskStatestateChangeListener)
    {
        .addStateChangeListener(stateChangeListener);
    }
    @Override
    public String toString()
    {
        return toStringHelper(this)
                .add("taskId")
                .add("taskState")
                .add("failureCauses")
                .toString();
    }
New to GrepCode? Check out our FAQ X