Files
openvpn3/javacli/OpenVPNClientThread.java
James Yonan bc02566ed9 Split OpenVPNClientThread.connect() into two methods: (1) connect()
establishes the client connection thread, and (2) wait_thread()
waits for client connection thread completion.
2012-02-15 18:59:24 +00:00

67 lines
1.4 KiB
Java

public class OpenVPNClientThread extends OpenVPNClientBase implements Runnable {
private EventReceiver parent;
private Status connect_status;
private Thread thread;
public interface EventReceiver {
void event(Event event);
void log(LogInfo loginfo);
}
public OpenVPNClientThread() {
parent = null;
}
// start connect session in worker thread
public void connect(EventReceiver parent_arg) {
// direct client callbacks to parent
parent = parent_arg;
// clear status
connect_status = null;
// execute client in a worker thread
thread = new Thread(this, "OpenVPNClientThread");
thread.start();
}
// wait for worker thread to complete; to stop thread,
// first call super stop() method then wait_thread().
public Status wait_thread() {
boolean interrupted;
do {
interrupted = false;
try {
thread.join();
}
catch (InterruptedException e) {
interrupted = true;
super.stop(); // send thread a stop message
}
} while (interrupted);
// dissassociate client callbacks from parent
parent = null;
thread = null;
return connect_status;
}
@Override
public void event(Event event) {
if (parent != null)
parent.event(event);
}
@Override
public void log(LogInfo loginfo) {
if (parent != null)
parent.log(loginfo);
}
@Override
public void run() {
connect_status = super.connect();
}
}