@@ -56,7 +56,7 @@ static <T> void setResultHandler(ContextInternal ctx, Future<T> fut, Handler<Asy
5656 final TaskQueue internalOrderedTasks ;
5757 final WorkerPool internalWorkerPool ;
5858 final WorkerPool workerPool ;
59- final TaskQueue orderedTasks ;
59+ final WorkerTaskQueue orderedTasks ;
6060
6161 public ContextImpl (VertxInternal vertx ,
6262 int localsLength ,
@@ -65,7 +65,7 @@ public ContextImpl(VertxInternal vertx,
6565 EventExecutor executor ,
6666 WorkerPool internalWorkerPool ,
6767 WorkerPool workerPool ,
68- TaskQueue orderedTasks ,
68+ WorkerTaskQueue orderedTasks ,
6969 Deployment deployment ,
7070 CloseFuture closeFuture ,
7171 ClassLoader tccl ) {
@@ -84,6 +84,14 @@ public ContextImpl(VertxInternal vertx,
8484 this .internalOrderedTasks = new TaskQueue ();
8585 }
8686
87+ public Future <Void > close () {
88+ if (closeFuture == owner .closeFuture ()) {
89+ return Future .future (p -> orderedTasks .shutdown (eventLoop , p ));
90+ } else {
91+ return closeFuture .close ().eventually (() -> Future .<Void >future (p -> orderedTasks .shutdown (eventLoop , p )));
92+ }
93+ }
94+
8795 public Deployment getDeployment () {
8896 return deployment ;
8997 }
@@ -201,29 +209,29 @@ private static <T> Future<T> internalExecuteBlocking(ContextInternal context, Ha
201209 Object queueMetric = metrics != null ? metrics .submitted () : null ;
202210 Promise <T > promise = context .promise ();
203211 Future <T > fut = promise .future ();
204- try {
205- Runnable command = () -> {
206- Object execMetric = null ;
207- if (metrics != null ) {
208- execMetric = metrics .begin (queueMetric );
209- }
212+ WorkerTask task = new WorkerTask (metrics , queueMetric ) {
213+ @ Override
214+ protected void execute () {
210215 context .dispatch (promise , blockingCodeHandler );
216+ }
217+ @ Override
218+ void reject () {
211219 if (metrics != null ) {
212- metrics .end ( execMetric , fut . succeeded () );
220+ metrics .rejected ( queueMetric );
213221 }
214- };
222+ promise .fail (new RejectedExecutionException ());
223+ }
224+ };
225+ try {
215226 Executor exec = workerPool .executor ();
216227 if (queue != null ) {
217- queue .execute (command , exec );
228+ queue .execute (task , exec );
218229 } else {
219- exec .execute (command );
230+ exec .execute (task );
220231 }
221232 } catch (RejectedExecutionException e ) {
222233 // Pool is already shut down
223- if (metrics != null ) {
224- metrics .rejected (queueMetric );
225- }
226- throw e ;
234+ task .reject ();
227235 }
228236 return fut ;
229237 }
0 commit comments