|
From: <de...@us...> - 2003-08-19 07:44:25
|
Update of /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/objet
In directory sc8-pr-cvs1:/tmp/cvs-serv9684/objet
Modified Files:
CExec.java
Log Message:
Maj des import
Index: CExec.java
===================================================================
RCS file: /cvsroot/fudaa/fudaa_devel/dodico/src/org/fudaa/dodico/objet/CExec.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** CExec.java 4 Jul 2003 13:57:48 -0000 1.4
--- CExec.java 19 Aug 2003 07:44:22 -0000 1.5
***************
*** 30,35 ****
* @author Axel von Arnim
*/
! public class CExec
! {
String[] cmd_;
PrintStream out_, err_;
--- 30,34 ----
* @author Axel von Arnim
*/
! public class CExec {
String[] cmd_;
PrintStream out_, err_;
***************
*** 43,50 ****
* d'erreur.
*/
! public CExec()
! {
! cmd_ = null;
! catchE = true;
}
--- 42,48 ----
* d'erreur.
*/
! public CExec() {
! cmd_= null;
! catchE= true;
}
***************
*** 54,59 ****
* @see java.lang.Runtime#exec(String[])
*/
! public CExec(String[] _cmd)
! {
this();
setCommand(_cmd);
--- 52,56 ----
* @see java.lang.Runtime#exec(String[])
*/
! public CExec(String[] _cmd) {
this();
setCommand(_cmd);
***************
*** 63,70 ****
* Initialisation des commandes.
*/
! public void setCommand(String[] _cmd)
! {
System.out.println(_cmd.length);
! cmd_ = _cmd;
}
--- 60,66 ----
* Initialisation des commandes.
*/
! public void setCommand(String[] _cmd) {
System.out.println(_cmd.length);
! cmd_= _cmd;
}
***************
*** 72,79 ****
* Definition du flux recuperant la sortie standard.
*/
! public void setOutStream(PrintStream _out)
! {
//out.setStream(_out);
! out_ = _out;
}
--- 68,74 ----
* Definition du flux recuperant la sortie standard.
*/
! public void setOutStream(PrintStream _out) {
//out.setStream(_out);
! out_= _out;
}
***************
*** 81,88 ****
* Definition du flux recuperant la sortie d'erreur.
*/
! public void setErrStream(PrintStream _err)
! {
// err.setStream(_err);
! err_ = _err;
}
--- 76,82 ----
* Definition du flux recuperant la sortie d'erreur.
*/
! public void setErrStream(PrintStream _err) {
// err.setStream(_err);
! err_= _err;
}
***************
*** 90,95 ****
* Retourne le processus d'execution.
*/
! public Process getProcess()
! {
return p;
}
--- 84,88 ----
* Retourne le processus d'execution.
*/
! public Process getProcess() {
return p;
}
***************
*** 99,105 ****
* Si elles sont catchees une trace est laissée sur la sortie d'erreur.
*/
! public void setCatchExceptions(boolean _catchE)
! {
! catchE = _catchE;
}
--- 92,97 ----
* Si elles sont catchees une trace est laissée sur la sortie d'erreur.
*/
! public void setCatchExceptions(boolean _catchE) {
! catchE= _catchE;
}
***************
*** 111,163 ****
* eux-meme avant la fin du process.
*/
! private void closeReaderThread(MyReaderThread _th) throws SecurityException
! {
! try
! {
if (_th == null)
return;
if (!_th.isAlive())
return;
//il est encore vivant, on attend
_th.setPriority(Thread.MAX_PRIORITY - 2);
//sous windows, il arrivre que la lecture du flux soit bloquee.
! if (_th.isBlocked())
! {
! if ((DodicoLib.DEBUG) && (err_ != null))
! {
! err_.println(_th.getName() + " " + DodicoLib.geti18n("bloqué "));
! }
!
! }
! else
! {
! //le thread n'est pas termine... bizarre
! if ((DodicoLib.DEBUG) && (err_ != null))
! {
! err_.println(
! "!!" + _th.getName() + " " + DodicoLib.geti18n("non terminé."));
! }
! //on a attendu 2 s, on interrompt le thread
! try
! {
! if (_th != null)
! _th.join(2000);
! }
! catch (InterruptedException _e)
! {
}
}
//on a attendu 50ms, on interrompt le thread
! if (_th.isAlive())
! {
! _th.destroy();
! if ((DodicoLib.DEBUG) && (err_ != null))
! err_.println(
! _th.getName() + " " + DodicoLib.geti18n("interrompu") + " ok");
}
! }
! catch (SecurityException _e)
! {
System.err.println(_e.getMessage());
}
--- 103,137 ----
* eux-meme avant la fin du process.
*/
! private void closeReaderThread(MyReaderThread _th) throws SecurityException {
! try {
if (_th == null)
return;
if (!_th.isAlive())
return;
+ try {
+ _th.join(2000);
+ } catch (InterruptedException _e) {}
+ if (!_th.isAlive())
+ return;
//il est encore vivant, on attend
_th.setPriority(Thread.MAX_PRIORITY - 2);
//sous windows, il arrivre que la lecture du flux soit bloquee.
! if (_th.isBlocked()) {
! if ((DodicoLib.DEBUG) && (err_ != null)) {
! err_.println(_th.getName() + " " + DodicoLib.geti18n("bloqué "));
}
}
+ try {
+ _th.join(1000);
+ } catch (InterruptedException _e) {}
//on a attendu 50ms, on interrompt le thread
! if (_th.isAlive()) {
! _th.finish();
! try {
! _th.join(2000);
! } catch (InterruptedException _e) {}
}
! } catch (SecurityException _e) {
System.err.println(_e.getMessage());
}
***************
*** 169,185 ****
* a la fin du process.
*/
! public void exec()
! {
! if ((cmd_ == null) || (cmd_.length <= 0))
! {
if (err_ != null)
err_.println(DodicoLib.geti18n("Commande nulle"));
return;
}
! BufferedReader psIn = null;
! BufferedReader psErr = null;
! int oldpriority = Thread.currentThread().getPriority();
! try
! {
if (err_ != null)
err_.println(
--- 143,156 ----
* a la fin du process.
*/
! public void exec() {
! if ((cmd_ == null) || (cmd_.length <= 0)) {
if (err_ != null)
err_.println(DodicoLib.geti18n("Commande nulle"));
return;
}
! BufferedReader psIn= null;
! BufferedReader psErr= null;
! int oldpriority= Thread.currentThread().getPriority();
! try {
if (err_ != null)
err_.println(
***************
*** 188,199 ****
if (DodicoLib.DEBUG)
System.out.println("lancement processus");
! p = Runtime.getRuntime().exec(cmd_);
if (listener_ != null)
listener_.setProcess(p);
! psIn = new BufferedReader(new InputStreamReader(p.getInputStream()));
! psErr = new BufferedReader(new InputStreamReader(p.getErrorStream()));
! thErr_ = new MyReaderThread(err_, psErr);
thErr_.setName(DodicoLib.geti18n("Sortie d'erreur"));
! thOut_ = new MyReaderThread(out_, psIn);
thOut_.setName(DodicoLib.geti18n("Sortie standard"));
// try
--- 159,170 ----
if (DodicoLib.DEBUG)
System.out.println("lancement processus");
! p= Runtime.getRuntime().exec(cmd_);
if (listener_ != null)
listener_.setProcess(p);
! psIn= new BufferedReader(new InputStreamReader(p.getInputStream()));
! psErr= new BufferedReader(new InputStreamReader(p.getErrorStream()));
! thErr_= new MyReaderThread(err_, psErr);
thErr_.setName(DodicoLib.geti18n("Sortie d'erreur"));
! thOut_= new MyReaderThread(out_, psIn);
thOut_.setName(DodicoLib.geti18n("Sortie standard"));
// try
***************
*** 206,230 ****
thOut_.start();
thErr_.start();
! boolean interr = true;
! while (interr)
! {
! try
! {
p.waitFor();
! interr = false;
! }
! catch (InterruptedException e)
! {
! interr = true;
}
}
! if (DodicoLib.DEBUG)
! {
System.out.println("fin processus");
}
- closeReaderThread(thErr_);
- System.out.println("fin erreur");
closeReaderThread(thOut_);
! System.out.println("fin std");
if (p.exitValue() != 0)
throw new RuntimeException(cmd_[0] + ": abnormal exit");
--- 177,195 ----
thOut_.start();
thErr_.start();
! boolean interr= true;
! while (interr) {
! try {
p.waitFor();
! interr= false;
! } catch (InterruptedException e) {
! interr= true;
}
}
! if (DodicoLib.DEBUG) {
System.out.println("fin processus");
}
closeReaderThread(thOut_);
! closeReaderThread(thErr_);
!
if (p.exitValue() != 0)
throw new RuntimeException(cmd_[0] + ": abnormal exit");
***************
*** 232,253 ****
err_.println(
"***** " + cmd_[0] + " " + DodicoLib.geti18n("termine") + " *****");
! }
! catch (IOException io)
! {
if (catchE)
System.err.println(io);
else
throw new RuntimeException(io.getMessage());
! }
! catch (RuntimeException r)
! {
if (catchE)
System.err.println(r);
else
throw r;
! }
! finally
! {
! Thread.currentThread().setPriority(oldpriority);
// try
// {
--- 197,212 ----
err_.println(
"***** " + cmd_[0] + " " + DodicoLib.geti18n("termine") + " *****");
! } catch (IOException io) {
if (catchE)
System.err.println(io);
else
throw new RuntimeException(io.getMessage());
! } catch (RuntimeException r) {
if (catchE)
System.err.println(r);
else
throw r;
! } finally {
! Thread.currentThread().setPriority(oldpriority);
// try
// {
***************
*** 288,294 ****
}
! public static void main(String[] args)
! {
! CExec exe =
new CExec(
new String[] {
--- 247,252 ----
}
! public static void main(String[] args) {
! CExec exe=
new CExec(
new String[] {
***************
*** 346,351 ****
* @return
*/
! public CExecListener getListener()
! {
return listener_;
}
--- 304,308 ----
* @return
*/
! public CExecListener getListener() {
return listener_;
}
***************
*** 354,360 ****
* @param _listener
*/
! public void setListener(CExecListener _listener)
! {
! listener_ = _listener;
}
--- 311,316 ----
* @param _listener
*/
! public void setListener(CExecListener _listener) {
! listener_= _listener;
}
***************
*** 367,376 ****
* @see isBlocked();
*/
! class MyReaderThread extends Thread
! {
private PrintStream str_;
private BufferedReader br_;
private boolean blocked_;
! private boolean destroyed_;
/**
--- 323,331 ----
* @see isBlocked();
*/
! class MyReaderThread extends Thread {
private PrintStream str_;
private BufferedReader br_;
private boolean blocked_;
! private boolean finish_;
/**
***************
*** 379,388 ****
* @param _br le buffer lu ( en general un buffer de sortie de process).
*/
! public MyReaderThread(PrintStream _str, BufferedReader _br)
! {
super();
! blocked_ = true;
! str_ = _str;
! br_ = _br;
setPriority(Thread.MAX_PRIORITY - 2);
}
--- 334,342 ----
* @param _br le buffer lu ( en general un buffer de sortie de process).
*/
! public MyReaderThread(PrintStream _str, BufferedReader _br) {
super();
! blocked_= true;
! str_= _str;
! br_= _br;
setPriority(Thread.MAX_PRIORITY - 2);
}
***************
*** 393,398 ****
* il est conseille d'interrompre le thread.
*/
! public boolean isBlocked()
! {
return blocked_;
}
--- 347,351 ----
* il est conseille d'interrompre le thread.
*/
! public boolean isBlocked() {
return blocked_;
}
***************
*** 402,452 ****
* elles sont renvoyees dans le PrintStream.
*/
! public void run()
! {
! int charLu = -1;
! try
! {
! blocked_ = true;
//sous windows le thread de lecture peut bloquer.
//On attend que le buffer puisse etre lu.
! while ((!br_.ready()) && (!destroyed_))
! {
! try
! {
this.sleep(500);
! }
! catch (InterruptedException e)
! {
! }
}
! blocked_ = false;
! if (br_.ready())
! charLu = br_.read();
! else
! charLu = -1;
!
! if (str_ != null)
! {
! while ((charLu != -1) && (!destroyed_))
! {
str_.write(charLu);
! charLu = br_.read();
}
! }
! else
! {
! while ((charLu != -1) && (!destroyed_))
! {
! charLu = br_.read();
}
-
}
! }
! catch (IOException _io)
! {
System.err.println(_io.getMessage());
! }
! finally
! {
str_.flush();
}
--- 355,394 ----
* elles sont renvoyees dans le PrintStream.
*/
! public void run() {
! int charLu= -1;
! try {
! blocked_= true;
//sous windows le thread de lecture peut bloquer.
//On attend que le buffer puisse etre lu.
! while ((!br_.ready()) && (!finish_)) {
! try {
this.sleep(500);
! } catch (InterruptedException e) {}
}
! blocked_= false;
! // if (br_.ready()) {
! // charLu= br_.read();
! // if ((charLu != -1) && (str_ != null)) {
! // str_.write(charLu);
! // } else
! // charLu= -1;
! // }
! if ((finish_) && (!br_.ready())) {
! return;
! }
! charLu= br_.read();
! if (str_ != null) {
! while ((charLu != -1)) {
str_.write(charLu);
! charLu= br_.read();
}
! } else {
! while ((charLu != -1)) {
! charLu= br_.read();
}
}
! } catch (IOException _io) {
System.err.println(_io.getMessage());
! } finally {
str_.flush();
}
***************
*** 457,471 ****
* @see java.lang.Thread#interrupt()
*/
! public void interrupt()
! {
super.interrupt();
}
! /**
! * @see java.lang.Thread#destroy()
! */
! public void destroy()
! {
! destroyed_ = true;
}
--- 399,408 ----
* @see java.lang.Thread#interrupt()
*/
! public void interrupt() {
super.interrupt();
}
! public void finish() {
! finish_= true;
}
|