View Javadoc
1   package org.apache.commons.jcs.utils.access;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * Interface for doing a piece of work which is expected to be cached. This is
24   * meant to be used in conjunction with JCSWorker.
25   * <p>
26   * Implement doWork() to return the work being done. isFinished() should return
27   * false until setFinished(true) is called, after which time it should return
28   * true.
29   * <p>
30   * @author tsavo
31   */
32  public interface JCSWorkerHelper<V>
33  {
34      /**
35       * Tells us whether or not the work has been completed. This will be called
36       * automatically by JCSWorker. You should not call it yourself.
37       * <p>
38       * @return True if the work has already been done, otherwise false.
39       */
40      boolean isFinished();
41  
42      /**
43       * Sets whether or not the work has been done.
44       * <p>
45       * @param isFinished
46       *            True if the work has already been done, otherwise false.
47       */
48      void setFinished( boolean isFinished );
49  
50      /**
51       * The method to implement to do the work that should be cached. JCSWorker
52       * will call this itself! You should not call this directly.
53       * <p>
54       * @return The result of doing the work to be cached.
55       * @throws Exception
56       *             If anything goes wrong while doing the work, an Exception
57       *             should be thrown.
58       */
59      V doWork() throws Exception;
60  }