1 /********************************************************************************
2 * $Id: ThreadSafeJob.java 98 2008-02-27 06:11:26Z sjardine $
3 *
4 * Copyright 2003 Innovation Software Group, LLC - http://www.innovationsw.com
5 * Copyright 2003 Joe Phillips <jaiger@innovationsw.com>
6 * Copyright 2008 Steven Jardine, MJN Services, Inc. <steve@mjnservices.com>
7 *
8 * All rights reserved. This program and the accompanying materials are made
9 * available under the terms of the GNU Lesser Public License v2.1 which
10 * accompanies this distribution, and is available at
11 * http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
12 *
13 * For more information on the HylaFAX Fax Server please see
14 * HylaFAX - http://www.hylafax.org or
15 * Hylafax+ - http://hylafax.sourceforge.net
16 *
17 * Contributors:
18 * Joe Phillips - Initial API and implementation
19 * Steven Jardine - Code formatting, rework of license header, javadoc
20 ******************************************************************************/
21 package gnu.hylafax.job;
22
23 import gnu.hylafax.Client;
24 import gnu.inet.ftp.ServerResponseException;
25
26 import java.io.IOException;
27
28 /***
29 * This is a thread-safe implementation of the gnu.hylafax.Job interface.
30 *
31 * @see gnu.hylafax.ClientProtocol
32 * @see gnu.hylafax.Client
33 */
34 public class ThreadSafeJob extends Job {
35
36 /***
37 * Default constructor.
38 *
39 * @param c
40 * HylaFAX client to use for the job.
41 * @throws ServerResponseException
42 * @throws IOException
43 */
44 public ThreadSafeJob(Client c) throws ServerResponseException, IOException {
45 super(c);
46 }
47
48 /***
49 * Default constructor.
50 *
51 * @param c
52 * HylaFAX client to use for the job.
53 * @param id
54 * Job id
55 * @throws ServerResponseException
56 * @throws IOException
57 */
58 public ThreadSafeJob(Client c, long id) throws ServerResponseException,
59 IOException {
60 super(c, id);
61 }
62
63 /***
64 * Get the value for an arbitrary property for this job. Developers using
65 * this method should be familiar with the HylaFAX client protocol in order
66 * to provide the correct key values and how to interpret the values
67 * returned. This method is thread-safe.
68 *
69 * @exception ServerResponseException
70 * the server responded with an error. This is likely due
71 * to a protocol error.
72 * @exception IOException
73 * an i/o error occured
74 * @return a String value for the given property key
75 */
76 public String getProperty(String key) throws ServerResponseException,
77 IOException {
78 synchronized (client) {
79 long j = client.job();
80 client.job(getId());
81 String tmp = super.getProperty(key);
82 client.job(j);
83 return tmp;
84 }
85 }
86
87 /***
88 * Set any arbitrary property on this job. In order to use this method,
89 * developers should be familiar with the HylaFAX client protocol. This
90 * method is thread-safe.
91 *
92 * @exception ServerResponseException
93 * the server responded with an error code. This is
94 * likely a protocol violation.
95 * @exception IOException
96 * an i/o error occured
97 */
98 public void setProperty(String parameter, String value)
99 throws ServerResponseException, IOException {
100 synchronized (client) {
101 long j = client.job();
102 client.job(getId());
103 super.setProperty(parameter, value);
104 client.job(j);
105 }
106 }
107
108 }