}
}
- public void pushBack(DebuggerCommandImpl managerCommand) {
- if(myEvents.isClosed()) {
+ public boolean pushBack(DebuggerCommandImpl managerCommand) {
+ final boolean pushed = super.pushBack(managerCommand);
+ if (!pushed) {
managerCommand.notifyCancelled();
}
- else {
- super.pushBack(managerCommand);
- }
+ return pushed;
}
- public void schedule(DebuggerCommandImpl managerCommand) {
- if(myEvents.isClosed()) {
+ public boolean schedule(DebuggerCommandImpl managerCommand) {
+ final boolean scheduled = super.schedule(managerCommand);
+ if (!scheduled) {
managerCommand.notifyCancelled();
}
- else {
- super.schedule(managerCommand);
- }
+ return scheduled;
}
/**
}
}
- public void pushBack(@NotNull E event, int priority) {
+ public boolean pushBack(@NotNull E event, int priority) {
if(LOG.isDebugEnabled()) {
LOG.debug("pushBack event " + event);
}
myLock.lock();
try {
- assertOpen();
+ if (isClosed()) {
+ return false;
+ }
getEventsList(priority).addFirst(event);
myEventsAvailable.signalAll();
}
finally {
myLock.unlock();
}
+ return true;
}
- public void put(@NotNull E event, int priority) {
+ public boolean put(@NotNull E event, int priority) {
if(LOG.isDebugEnabled()) {
LOG.debug("put event " + event);
}
myLock.lock();
try {
- assertOpen();
+ if (isClosed()) {
+ return false;
+ }
getEventsList(priority).offer(event);
myEventsAvailable.signalAll();
}
finally {
myLock.unlock();
}
+ return true;
}
private LinkedList<E> getEventsList(final int priority) {
public void close(){
myLock.lock();
try {
- assertOpen();
myIsClosed = true;
myEventsAvailable.signalAll();
}
}
}
- private void assertOpen() {
- if (myIsClosed) throw new AssertionError("Already closed");
- }
-
private E getEvent() throws EventQueueClosedException {
myLock.lock();
try {
* @author lex
*/
public class EventQueueClosedException extends Exception {
+ @Override
+ public Throwable fillInStackTrace() {
+ return this;
+ }
}
* !!! Do not remove this code !!!
* Otherwise it will be impossible to override schedule method
*/
- public void schedule(E e) {
- super.schedule(e);
+ public boolean schedule(E e) {
+ return super.schedule(e);
}
- public void pushBack(E e) {
- super.pushBack(e);
+ public boolean pushBack(E e) {
+ return super.pushBack(e);
}
public void invokeAndWait(final E runnable) {
return request != null? request.getOwner() : null;
}
- public void schedule(E r) {
+ public boolean schedule(E r) {
if(LOG.isDebugEnabled()) {
LOG.debug("schedule " + r + " in " + this);
}
- myEvents.put(r, r.getPriority().ordinal());
+ return myEvents.put(r, r.getPriority().ordinal());
}
- public void pushBack(E r) {
+ public boolean pushBack(E r) {
if(LOG.isDebugEnabled()) {
LOG.debug("pushBack " + r + " in " + this);
}
- myEvents.pushBack(r, r.getPriority().ordinal());
+ return myEvents.pushBack(r, r.getPriority().ordinal());
}
protected void switchToRequest(WorkerThreadRequest newWorkerThread) {