KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > util > images > ImageConversionRequest


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10 package org.mmbase.util.images;
11
12 import java.util.List JavaDoc;
13 import org.mmbase.util.logging.*;
14 import org.mmbase.module.core.MMObjectNode;
15
16 /**
17  * Defines one Image convert request.
18  *
19  * @author Rico Jansen
20  * @author Michiel Meeuwissen
21  * @version $Id: ImageConversionRequest.java,v 1.3 2005/10/03 17:33:39 michiel Exp $
22  */

23 public class ImageConversionRequest {
24
25     private static final Logger log = Logging.getLoggerInstance(ImageConversionRequest.class);
26
27     private boolean ready = false;
28     private List JavaDoc params;
29     private byte[] in;
30     private int count = 0;
31     private MMObjectNode icacheNode;
32     private String JavaDoc format;
33
34     /**
35      * @javadoc
36      */

37     public ImageConversionRequest(List JavaDoc params, byte[] in, String JavaDoc format, MMObjectNode icacheNode) {
38         this.in = in;
39         this.params = params;
40         this.icacheNode = icacheNode;
41         this.format = format;
42     }
43
44     /**
45      * The parameters describing the conversion.
46      */

47     public List JavaDoc getParams() {
48         return params;
49     }
50
51     /**
52      * The byte[] on which the conversion must happen.
53      */

54     public byte[] getInput() {
55         return in;
56     }
57
58     /**
59      * The icache node in which the conversion results must be stored.
60      */

61     public MMObjectNode getNode() {
62         return icacheNode;
63     }
64     public String JavaDoc getInputFormat() {
65         return format;
66     }
67
68
69     /**
70      * Waits until the conversion result is ready.
71      */

72     public synchronized void waitForConversion() {
73         if (! ready) { // the request is in progress, wait until it is ready.
74
log.service("Waiting for " + toString());
75             count++;
76             try {
77                 wait();
78             } catch (InterruptedException JavaDoc e) {
79             }
80             log.service("Ready " + toString());
81         }
82     }
83
84
85     public synchronized void ready() {
86         count = 0;
87         ready = true;
88         notifyAll();
89     }
90
91     /**
92      * Returns how many request are waiting for the result of this image transformation.
93      */

94     public int count() {
95         return count;
96     }
97
98     // javadoc inherited (of Object)
99
public String JavaDoc toString() {
100         return icacheNode.getStringValue("id") + " --> " + icacheNode.getNumber() + " " + params;
101     }
102 }
103
Popular Tags