/[svn]/jsampler/trunk/src/org/jsampler/task/EnhancedTask.java
ViewVC logotype

Annotation of /jsampler/trunk/src/org/jsampler/task/EnhancedTask.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2192 - (hide annotations) (download)
Fri Jun 24 21:34:51 2011 UTC (12 years, 10 months ago) by iliev
File size: 3885 byte(s)
* Initial implementation of Sampler Browser
  (choose Window/Sampler Browser) - another way to view/edit
  the sampler configuration (work in progress - for now only
  support for viewing/editing send effects)

1 iliev 845 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 2192 * Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 845 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.task;
24    
25 iliev 2192 import java.util.Date;
26 iliev 1867 import java.util.logging.Level;
27    
28 iliev 845 import net.sf.juife.AbstractTask;
29    
30 iliev 1867 import org.jsampler.CC;
31     import org.jsampler.HF;
32    
33 iliev 1204 import org.linuxsampler.lscp.LSException;
34 iliev 845
35 iliev 1867 import static org.jsampler.JSI18n.i18n;
36 iliev 1204
37 iliev 1867
38 iliev 845 /**
39 iliev 911 * This class extends <code>AbstractTask</code> to add new features.
40 iliev 845 * @author Grigor Iliev
41     */
42     public abstract class EnhancedTask<R> extends AbstractTask<R> {
43 iliev 1867 public static final int SOCKET_ERROR = 1;
44 iliev 845 private boolean stopped = false;
45 iliev 1786 private boolean silent = false;
46 iliev 1867 private boolean showErrorDetails;
47 iliev 2192 private boolean calculateElapsedTime = false;
48     private long elapsedTime = -1;
49 iliev 845
50 iliev 1867 public
51     EnhancedTask() { this(false); }
52    
53     public
54     EnhancedTask(boolean showErrorDetails) {
55     this.showErrorDetails = showErrorDetails;
56     }
57    
58     public void
59     run() {
60 iliev 2192 try {
61     if(getCalculateElapsedTime()) {
62     elapsedTime = new Date().getTime();
63     }
64    
65     exec();
66    
67     if(getCalculateElapsedTime()) {
68     elapsedTime = new Date().getTime() - elapsedTime;
69     }
70     if(getCalculateElapsedTime()) System.out.println("time: " + getElapsedTime());
71     } catch(java.net.SocketException x) {
72 iliev 1867 setErrorCode(SOCKET_ERROR);
73     setErrorMessage(i18n.getError("SOCKET_ERROR"));
74     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
75     } catch(Exception x) {
76     setErrorMessage(getDescription() + ": " + HF.getErrorMessage(x));
77     if(showErrorDetails) setErrorDetails(x);
78     CC.getLogger().log(Level.FINE, getErrorMessage(), x);
79     onError(x);
80     }
81     }
82    
83     public void
84     exec() throws Exception { }
85    
86     public void
87 iliev 2192 onError(Exception e) { e.printStackTrace(); }
88 iliev 1867
89 iliev 845 /**
90     * Marks that the execution of this task was interrupted.
91     */
92     public void
93     stop() { stopped = true; }
94    
95     /**
96     * Determines whether the execution of this task was interrupted.
97     * @return <code>true</code> if the execution of this task was interrupted,
98     * <code>false</code> otherwise.
99     */
100     public boolean
101     isStopped() { return stopped; }
102 iliev 1204
103     /**
104 iliev 1786 * Determines whether an error message should be shown
105     * if the execution of the task fail.
106     */
107     public boolean
108     isSilent() { return silent; }
109    
110     /**
111 iliev 2192 * Sets whether an error message should be shown
112 iliev 1786 * if the execution of the task fail.
113     */
114     public void
115     setSilent(boolean b) { silent = b; }
116    
117     /**
118 iliev 1204 * Sets the error details provided by the given exception (if the given
119     * exception is <code>LSException</code> instance and contains error details).
120     */
121     public void
122     setErrorDetails(Exception e) {
123     if(e == null) return;
124    
125     if(e instanceof LSException) {
126     LSException x = (LSException)e;
127     if(x.getDetails() != null && x.getDetails().length() > 0) {
128     setErrorDetails(x.getDetails());
129     }
130     }
131     }
132 iliev 2192
133     /** Determines whether to calculate the elapsed time for this task. */
134     public boolean
135     getCalculateElapsedTime() { return calculateElapsedTime; }
136    
137     /** Sets whether to calculate the elapsed time for this task. */
138     public void
139     setCalculateElapsedTime(boolean b) { calculateElapsedTime = b; }
140    
141     /** Gets the elapsed time for this task. */
142     public long
143     getElapsedTime() { return elapsedTime; }
144 iliev 845 }

  ViewVC Help
Powered by ViewVC