1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.contacts.common.vcard;
17
18import java.util.concurrent.ExecutorService;
19import java.util.concurrent.Future;
20import java.util.concurrent.RunnableFuture;
21import java.util.concurrent.TimeUnit;
22
23/**
24 * A base processor class. One instance processes vCard one import/export request (imports a given
25 * vCard or exports a vCard). Expected to be used with {@link ExecutorService}.
26 *
27 * This instance starts itself with {@link #run()} method, and can be cancelled with
28 * {@link #cancel(boolean)}. Users can check the processor's status using {@link #isCancelled()}
29 * and {@link #isDone()} asynchronously.
30 *
31 * {@link #get()} and {@link #get(long, TimeUnit)}, which are form {@link Future}, aren't
32 * supported and {@link UnsupportedOperationException} will be just thrown when they are called.
33 */
34public abstract class ProcessorBase implements RunnableFuture<Object> {
35
36    /**
37     * @return the type of the processor. Must be {@link VCardService#TYPE_IMPORT} or
38     * {@link VCardService#TYPE_EXPORT}.
39     */
40    public abstract int getType();
41
42    @Override
43    public abstract void run();
44
45    /**
46     * Cancels this operation.
47     *
48     * @param mayInterruptIfRunning ignored. When this method is called, the instance
49     * stops processing and finish itself even if the thread is running.
50     *
51     * @see Future#cancel(boolean)
52     */
53    @Override
54    public abstract boolean cancel(boolean mayInterruptIfRunning);
55    @Override
56    public abstract boolean isCancelled();
57    @Override
58    public abstract boolean isDone();
59
60    /**
61     * Just throws {@link UnsupportedOperationException}.
62     */
63    @Override
64    public final Object get() {
65        throw new UnsupportedOperationException();
66    }
67
68    /**
69     * Just throws {@link UnsupportedOperationException}.
70     */
71    @Override
72    public final Object get(long timeout, TimeUnit unit) {
73        throw new UnsupportedOperationException();
74    }
75}
76