команда запуска без shell канала а через exec
v++
This commit is contained in:
85
src/Common/Utils/TimerTask.java
Normal file
85
src/Common/Utils/TimerTask.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package Common.Utils;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
public abstract class TimerTask {
|
||||
int maxtime;
|
||||
int attempts;
|
||||
boolean success;
|
||||
Semaphore semaphore = null;
|
||||
Thread actionThread = null;
|
||||
//--
|
||||
public TimerTask(int maxtime_in, int attempts_in) {
|
||||
maxtime = maxtime_in;
|
||||
attempts = attempts_in;
|
||||
semaphore = new Semaphore(1);
|
||||
actionThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Action();
|
||||
} catch (Exception ex) {
|
||||
System.out.println("Thread occured exception!");
|
||||
ex.printStackTrace();
|
||||
System.out.println("-------------------------");
|
||||
} finally {
|
||||
releaseSemaphore();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//--
|
||||
public abstract void Action() throws Exception;
|
||||
public void finalizeThread() {
|
||||
}
|
||||
void acquireSemaphore() {
|
||||
try {
|
||||
semaphore.acquire();
|
||||
System.out.println("semaphore acquired");
|
||||
} catch (Exception ignore) {
|
||||
}
|
||||
}
|
||||
void releaseSemaphore() {
|
||||
semaphore.release();
|
||||
System.out.println("semaphore released");
|
||||
}
|
||||
void waitForThread() {
|
||||
int i = 0;
|
||||
success = false;
|
||||
while (true) {
|
||||
try {
|
||||
++i;
|
||||
if (semaphore.tryAcquire(1, TimeUnit.SECONDS)) {
|
||||
System.out.println("thread finished for " + i + " seconds");
|
||||
success = true;
|
||||
return;
|
||||
} else {
|
||||
System.out.println("thread active " + i + " seconds");
|
||||
if (i >= maxtime) {
|
||||
System.out.println("maxtime reached: " + i + " seconds");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out.println("waiting exception");
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean Perform(int attempts) {
|
||||
int i = 0;
|
||||
while (i < attempts) {
|
||||
acquireSemaphore();
|
||||
actionThread.start();
|
||||
waitForThread();
|
||||
finalizeThread();
|
||||
++i;
|
||||
System.out.println("task finished for " + i + " attempts");
|
||||
if (success) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
System.out.println("attempts overlimited");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class Visualiser extends Component {
|
||||
//http://www.seostella.com/ru/article/2012/02/05/formatirovanie-daty-v-java.html
|
||||
@Override
|
||||
public void GetVersionInfo() {
|
||||
version = 1126;
|
||||
version = 1127;
|
||||
String pattern = "MMM dd yyyy HH:mm:ss";
|
||||
DateFormat df = new SimpleDateFormat(pattern, Locale.ENGLISH);
|
||||
date_text = df.format(getClassBuildTime());
|
||||
|
||||
@@ -413,6 +413,7 @@ public class UserConnection {
|
||||
}
|
||||
}
|
||||
//-----
|
||||
/*
|
||||
public void ShellConnect() throws Exception {
|
||||
shellChannel = (ChannelShell) session.openChannel("shell");
|
||||
in = new PipedInputStream();
|
||||
@@ -425,10 +426,6 @@ public class UserConnection {
|
||||
shellChannel.connect();
|
||||
//-
|
||||
fromServer = new InputStreamReader(pout);
|
||||
/*
|
||||
ShellParser.setUserName(user.login);
|
||||
ShellParser.ReadInvitation(fromServer); //прочитать первое приглашение от машины.
|
||||
*/
|
||||
}
|
||||
public void ShellDisconnect() throws Exception {
|
||||
if (in != null) {
|
||||
@@ -476,6 +473,8 @@ public class UserConnection {
|
||||
shellChannel = null;
|
||||
System.gc();
|
||||
}
|
||||
*/
|
||||
|
||||
public void waitForFileCreation(RemoteFile file) throws Exception {
|
||||
while (!Exists(file)) {
|
||||
System.out.println(file.full_name + " NOT FOUND");
|
||||
@@ -507,6 +506,16 @@ public class UserConnection {
|
||||
RemoteFile outFile = new RemoteFile(directory, outFileName);
|
||||
if (Exists(outFile))
|
||||
sftpChannel.rm(outFile.full_name);
|
||||
//--
|
||||
System.out.println("nohup " + start_command + " &\r\n");
|
||||
execChannel = (ChannelExec) session.openChannel("exec");
|
||||
execChannel.setErrStream(System.err);
|
||||
execChannel.setCommand("nohup " + start_command + " &\r\n");
|
||||
execChannel.connect();
|
||||
execChannel.disconnect();
|
||||
System.out.println("done");
|
||||
//--
|
||||
/*
|
||||
System.out.println("connecting shell");
|
||||
ShellConnect();
|
||||
System.out.println("done");
|
||||
@@ -521,6 +530,7 @@ public class UserConnection {
|
||||
ShellDisconnect();
|
||||
System.out.println("done");
|
||||
// return readFromFile(outFile).replace("\n", "").replace("\r", "");
|
||||
*/
|
||||
}
|
||||
//-- проверка существования рабочего пространства.
|
||||
public void CheckUserInitialization(String email) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user