View Javadoc

1   /***
2    * ProducerRunnable.java
3    *
4    * This file is part of the creme library.
5    * The creme library intends to ease the development effort of large
6    * applications by providing easy to use support classes.
7    *
8    * Copyright (C) 2002 Denis Bregeon
9    *
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   *
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   *
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23   *
24   * contact information: dbregeon@sourceforge.net
25   */
26  package org.jcreme.processing;
27  
28  /***
29   * This class is designed to act as a data source.
30   * 
31   * @author $Author: dbregeon $
32   * @version $Revision: 1.1 $
33   */
34  public class ProducerRunnable implements Runnable {
35  
36      /***
37       * The producer that provides items.
38       */
39      private final Producer source;
40  
41      /***
42       * Creates new ProducerRunnable
43       * 
44       * @param source
45       *            The producer that will produce the items.
46       * @throws IllegalArgumentException
47       *             if source is null.
48       */
49      public ProducerRunnable(Producer source) throws IllegalArgumentException {
50          if (source == null) {
51              throw new IllegalArgumentException("Null is not a valid Producer.");
52          }
53          this.source = source;
54      }
55  
56      /***
57       * The actual production process.
58       *  
59       */
60      public void run() {
61          while ((!Thread.interrupted()) && (this.source.produceItem())) {
62              // Nothing to do, produceItem does everything.
63          }
64      }
65  
66      /***
67       * Gives access to the underlying source.
68       * 
69       * @return the Producer that is animated by this Runnable.
70       */
71      public Producer getSource() {
72          return this.source;
73      }
74  }