Skip to content
Snippets Groups Projects
Commit 04ac0755 authored by Nick Mathewson's avatar Nick Mathewson :family:
Browse files

Tweak jaa control lib interface: make launchThread unneeded, add stub...

Tweak jaa control lib interface: make launchThread unneeded, add stub implementation for EventHandler.
parent 6a0471ac
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ package net.freehaven.tor.control;
* Abstract interface whose methods are invoked when Tor sends us an event.
*
* @see TorControlConnection#setEventHandler
* @see TorControlConnection#listenForEvents
* @see TorControlConnection#setEvents
*/
public interface EventHandler {
/**
......
// $Id$
// Copyright 2005 Nick Mathewson, Roger Dingledine
// See LICENSE file for copying information
package net.freehaven.tor.control;
/**
* Implementation of EventHandler that ignores all events. Useful
* when you only want to override one method.
*/
public class NullEventHandler implements EventHandler {
public void circuitStatus(String status, String circID, String path) {}
public void streamStatus(String status, String streamID, String target) {}
public void orConnStatus(String status, String orName) {}
public void bandwidthUsed(long read, long written) {}
public void newDescriptors(java.util.List orList) {}
public void message(String severity, String msg) {}
public void unrecognized(String type, String msg) {}
}
......@@ -19,6 +19,8 @@ public abstract class TorControlConnection// implements TorControlCommands {
protected LinkedList waiters;
protected Thread thread;
static class Waiter {
Object response;
public synchronized Object getResponse() {
......@@ -78,7 +80,7 @@ public abstract class TorControlConnection// implements TorControlCommands {
/** Set the EventHandler object that will be notified of any
* events Tor delivers to this connection. To make Tor send us
* events, call listenForEvents(). */
* events, call setEvents(). */
public void setEventHandler(EventHandler handler) {
this.handler = handler;
}
......@@ -101,9 +103,15 @@ public abstract class TorControlConnection// implements TorControlCommands {
if (daemon)
th.setDaemon(true);
th.start();
this.thread = th;
return th;
}
protected final void checkThread() {
if (thread == null)
launchThread(true);
}
protected abstract void react() throws IOException;
/** Change the value of the configuration option 'key' to 'val'.
......
......@@ -133,6 +133,7 @@ public class TorControlConnection0 extends TorControlConnection
* to be received (in order) */
protected synchronized Cmd _sendAndWaitForResponse(short type, byte[] cmd)
throws IOException {
checkThread();
Waiter w = new Waiter();
synchronized (waiters) {
sendCommand(type, cmd);
......
......@@ -138,6 +138,7 @@ public class TorControlConnection1 extends TorControlConnection
protected synchronized ArrayList sendAndWaitForResponse(String s,String rest)
throws IOException {
checkThread();
Waiter w = new Waiter();
synchronized (waiters) {
output.write(s);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment