Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *    http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 package test.org.apache.spark;
0019 
0020 import java.util.Map;
0021 
0022 import org.apache.spark.TaskContext;
0023 import org.apache.spark.resource.ResourceInformation;
0024 import org.apache.spark.util.TaskCompletionListener;
0025 import org.apache.spark.util.TaskFailureListener;
0026 
0027 /**
0028  * Something to make sure that TaskContext can be used in Java.
0029  */
0030 public class JavaTaskContextCompileCheck {
0031 
0032   public static void test() {
0033     TaskContext tc = TaskContext.get();
0034 
0035     tc.isCompleted();
0036     tc.isInterrupted();
0037 
0038     tc.addTaskCompletionListener(new JavaTaskCompletionListenerImpl());
0039     tc.addTaskFailureListener(new JavaTaskFailureListenerImpl());
0040 
0041     tc.attemptNumber();
0042     tc.partitionId();
0043     tc.stageId();
0044     tc.stageAttemptNumber();
0045     tc.taskAttemptId();
0046     // this returns a scala Map, so make sure the JMap version give a java type back
0047     tc.resources();
0048     Map<String, ResourceInformation> resources = tc.resourcesJMap();
0049     tc.taskMetrics();
0050     tc.taskMemoryManager();
0051     tc.getLocalProperties();
0052   }
0053 
0054   /**
0055    * A simple implementation of TaskCompletionListener that makes sure TaskCompletionListener and
0056    * TaskContext is Java friendly.
0057    */
0058   static class JavaTaskCompletionListenerImpl implements TaskCompletionListener {
0059     @Override
0060     public void onTaskCompletion(TaskContext context) {
0061       context.isCompleted();
0062       context.isInterrupted();
0063       context.stageId();
0064       context.stageAttemptNumber();
0065       context.partitionId();
0066       context.addTaskCompletionListener(this);
0067     }
0068   }
0069 
0070   /**
0071    * A simple implementation of TaskCompletionListener that makes sure TaskCompletionListener and
0072    * TaskContext is Java friendly.
0073    */
0074   static class JavaTaskFailureListenerImpl implements TaskFailureListener {
0075     @Override
0076     public void onTaskFailure(TaskContext context, Throwable error) {
0077     }
0078   }
0079 
0080 }