17903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng/* 27903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * Copyright (C) 2010 The Android Open Source Project 37903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * 47903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License"); 57903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * you may not use this file except in compliance with the License. 67903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * You may obtain a copy of the License at 77903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * 87903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * http://www.apache.org/licenses/LICENSE-2.0 97903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * 107903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * Unless required by applicable law or agreed to in writing, software 117903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS, 127903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * See the License for the specific language governing permissions and 147903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * limitations under the License. 157903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng */ 167903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Chengpackage com.android.contacts.common.vcard; 177903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng 187903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Chengimport java.util.concurrent.ExecutorService; 197903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Chengimport java.util.concurrent.Future; 207903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Chengimport java.util.concurrent.RunnableFuture; 217903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Chengimport java.util.concurrent.TimeUnit; 227903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng 237903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng/** 247903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * A base processor class. One instance processes vCard one import/export request (imports a given 257903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * vCard or exports a vCard). Expected to be used with {@link ExecutorService}. 267903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * 277903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * This instance starts itself with {@link #run()} method, and can be cancelled with 287903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * {@link #cancel(boolean)}. Users can check the processor's status using {@link #isCancelled()} 297903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * and {@link #isDone()} asynchronously. 307903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * 317903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * {@link #get()} and {@link #get(long, TimeUnit)}, which are form {@link Future}, aren't 327903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * supported and {@link UnsupportedOperationException} will be just thrown when they are called. 337903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng */ 347903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Chengpublic abstract class ProcessorBase implements RunnableFuture<Object> { 357903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng 367903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng /** 377903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * @return the type of the processor. Must be {@link VCardService#TYPE_IMPORT} or 387903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * {@link VCardService#TYPE_EXPORT}. 397903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng */ 407903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng public abstract int getType(); 417903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng 427903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng @Override 437903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng public abstract void run(); 447903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng 457903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng /** 467903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * Cancels this operation. 477903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * 487903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * @param mayInterruptIfRunning ignored. When this method is called, the instance 497903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * stops processing and finish itself even if the thread is running. 507903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * 517903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * @see Future#cancel(boolean) 527903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng */ 537903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng @Override 547903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng public abstract boolean cancel(boolean mayInterruptIfRunning); 557903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng @Override 567903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng public abstract boolean isCancelled(); 577903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng @Override 587903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng public abstract boolean isDone(); 597903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng 607903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng /** 617903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * Just throws {@link UnsupportedOperationException}. 627903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng */ 637903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng @Override 647903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng public final Object get() { 657903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng throw new UnsupportedOperationException(); 667903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng } 677903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng 687903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng /** 697903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng * Just throws {@link UnsupportedOperationException}. 707903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng */ 717903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng @Override 727903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng public final Object get(long timeout, TimeUnit unit) { 737903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng throw new UnsupportedOperationException(); 747903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng } 757903d2473e1120e32fa5380a7d7532d0a21e2180Chiao Cheng} 76