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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2191 by iliev, Mon Mar 16 22:12:32 2009 UTC revision 2192 by iliev, Fri Jun 24 21:34:51 2011 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2011 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 22  Line 22 
22    
23  package org.jsampler.task;  package org.jsampler.task;
24    
25    import java.util.Date;
26  import java.util.logging.Level;  import java.util.logging.Level;
27    
28  import net.sf.juife.AbstractTask;  import net.sf.juife.AbstractTask;
# Line 43  public abstract class EnhancedTask<R> ex Line 44  public abstract class EnhancedTask<R> ex
44          private boolean stopped = false;          private boolean stopped = false;
45          private boolean silent = false;          private boolean silent = false;
46          private boolean showErrorDetails;          private boolean showErrorDetails;
47            private boolean calculateElapsedTime = false;
48            private long elapsedTime = -1;
49                    
50          public          public
51          EnhancedTask() { this(false); }          EnhancedTask() { this(false); }
# Line 54  public abstract class EnhancedTask<R> ex Line 57  public abstract class EnhancedTask<R> ex
57    
58          public void          public void
59          run() {          run() {
60                  try { exec(); }                  try {
61                  catch(java.net.SocketException x) {                          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                          setErrorCode(SOCKET_ERROR);                          setErrorCode(SOCKET_ERROR);
73                          setErrorMessage(i18n.getError("SOCKET_ERROR"));                          setErrorMessage(i18n.getError("SOCKET_ERROR"));
74                          CC.getLogger().log(Level.FINE, getErrorMessage(), x);                          CC.getLogger().log(Level.FINE, getErrorMessage(), x);
# Line 71  public abstract class EnhancedTask<R> ex Line 84  public abstract class EnhancedTask<R> ex
84          exec() throws Exception { }          exec() throws Exception { }
85    
86          public void          public void
87          onError(Exception e) { }          onError(Exception e) { e.printStackTrace(); }
88                    
89          /**          /**
90           * Marks that the execution of this task was interrupted.           * Marks that the execution of this task was interrupted.
# Line 95  public abstract class EnhancedTask<R> ex Line 108  public abstract class EnhancedTask<R> ex
108          isSilent() { return silent; }          isSilent() { return silent; }
109                    
110          /**          /**
111           * DSets whether an error message should be shown           * Sets whether an error message should be shown
112           * if the execution of the task fail.           * if the execution of the task fail.
113           */           */
114          public void          public void
# Line 116  public abstract class EnhancedTask<R> ex Line 129  public abstract class EnhancedTask<R> ex
129                          }                          }
130                  }                  }
131          }          }
132    
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  }  }

Legend:
Removed from v.2191  
changed lines
  Added in v.2192

  ViewVC Help
Powered by ViewVC