Minor refactoring
This commit is contained in:
parent
ac9e738018
commit
5993b8b963
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.common.msg.queue;
|
package org.thingsboard.server.common.msg.queue;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.EntityId;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -34,7 +35,7 @@ public interface TbCallback {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
default UUID getId(){
|
default UUID getId() {
|
||||||
return EntityId.NULL_UUID;
|
return EntityId.NULL_UUID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,4 +43,18 @@ public interface TbCallback {
|
|||||||
|
|
||||||
void onFailure(Throwable t);
|
void onFailure(Throwable t);
|
||||||
|
|
||||||
|
static <V> TbCallback wrap(SettableFuture<V> future) {
|
||||||
|
return new TbCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess() {
|
||||||
|
future.set(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable t) {
|
||||||
|
future.setException(t);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -183,6 +183,15 @@ public abstract class TaskProcessor<T extends Task<R>, R extends TaskResult> {
|
|||||||
discardedJobs.add(jobId);
|
discardedJobs.add(jobId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected <V> V wait(Future<V> future) throws Exception {
|
||||||
|
try {
|
||||||
|
return future.get(); // will be interrupted after task processing timeout
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
future.cancel(true); // interrupting the underlying task
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
taskConsumer.stop();
|
taskConsumer.stop();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user