https://issues.apache.org/activemq/browse/AMQ-2440 - fixing bug on marking worker as non empty

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@920827 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-03-09 12:18:47 +00:00
parent 54fa83da8b
commit 3cbe3f1f92
3 changed files with 12 additions and 14 deletions

View File

@ -99,7 +99,7 @@ public final class SelectorManager {
}
public synchronized void onWorkerNotFullEvent(SelectorWorker worker) {
freeWorkers.add(worker);
freeWorkers.addFirst(worker);
}
public Executor getChannelExecutor() {

View File

@ -53,7 +53,7 @@ public class SelectorWorker implements Runnable {
int use = retainCounter.decrementAndGet();
if (use == 0) {
manager.onWorkerEmptyEvent(this);
} else if (use < maxChannelsPerWorker) {
} else if (use == maxChannelsPerWorker - 1) {
manager.onWorkerNotFullEvent(this);
}
}
@ -68,18 +68,15 @@ public class SelectorWorker implements Runnable {
selector.wakeup();
}
private boolean processIoTasks() {
boolean rc = false;
private void processIoTasks() {
Runnable task;
while( (task= ioTasks.poll()) !=null ) {
try {
rc = true;
task.run();
} catch (Throwable e) {
e.printStackTrace();
}
}
return rc;
}
@ -91,10 +88,10 @@ public class SelectorWorker implements Runnable {
Thread.currentThread().setName("Selector Worker: " + id);
while (!isReleased()) {
if( processIoTasks() ) {
continue;
}
int count = selector.select(10);
processIoTasks();
int count = selector.select(10);
if (count == 0) {
continue;
}
@ -134,8 +131,8 @@ public class SelectorWorker implements Runnable {
}
}
} catch (Throwable e) {
e.printStackTrace();
// Notify all the selections that the error occurred.
Set keys = selector.keys();
for (Iterator i = keys.iterator(); i.hasNext();) {
@ -143,12 +140,12 @@ public class SelectorWorker implements Runnable {
SelectorSelection s = (SelectorSelection)key.attachment();
s.onError(e);
}
} finally {
try {
manager.onWorkerEmptyEvent(this);
selector.close();
} catch (IOException ignore) {
ignore.printStackTrace();
}
Thread.currentThread().setName(origName);
}

View File

@ -145,6 +145,7 @@ public class StompNIOTransport extends TcpTransport {
try {
selection.close();
} catch (Exception e) {
e.printStackTrace();
}
super.doStop(stopper);
}