From a833889c2ae657a3575e8afc6e22d770d69ffbb7 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 17 Sep 2014 21:55:46 +0200 Subject: [PATCH] Polishing --- .../config/ScheduledTaskRegistrar.java | 19 ++++++++++--------- .../HttpComponentsClientHttpRequest.java | 8 +++++--- .../HttpComponentsClientHttpResponse.java | 2 ++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java index 7682ad86f7..a7e9afd372 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTaskRegistrar.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import org.springframework.scheduling.Trigger; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; import org.springframework.scheduling.support.CronTrigger; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; /** * Helper bean for registering tasks with a {@link TaskScheduler}, typically using cron @@ -268,10 +269,10 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean * @since 3.2 */ public boolean hasTasks() { - return (this.fixedRateTasks != null && !this.fixedRateTasks.isEmpty()) || - (this.fixedDelayTasks != null && !this.fixedDelayTasks.isEmpty()) || - (this.cronTasks != null && !this.cronTasks.isEmpty()) || - (this.triggerTasks != null && !this.triggerTasks.isEmpty()); + return (!CollectionUtils.isEmpty(this.triggerTasks) || + !CollectionUtils.isEmpty(this.cronTasks) || + !CollectionUtils.isEmpty(this.fixedRateTasks) || + !CollectionUtils.isEmpty(this.fixedDelayTasks)); } @@ -295,19 +296,19 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean this.taskScheduler = new ConcurrentTaskScheduler(this.localExecutor); } if (this.triggerTasks != null) { - for (TriggerTask task : triggerTasks) { + for (TriggerTask task : this.triggerTasks) { this.scheduledFutures.add(this.taskScheduler.schedule( task.getRunnable(), task.getTrigger())); } } if (this.cronTasks != null) { - for (CronTask task : cronTasks) { + for (CronTask task : this.cronTasks) { this.scheduledFutures.add(this.taskScheduler.schedule( task.getRunnable(), task.getTrigger())); } } if (this.fixedRateTasks != null) { - for (IntervalTask task : fixedRateTasks) { + for (IntervalTask task : this.fixedRateTasks) { if (task.getInitialDelay() > 0) { Date startTime = new Date(now + task.getInitialDelay()); this.scheduledFutures.add(this.taskScheduler.scheduleAtFixedRate( @@ -320,7 +321,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean } } if (this.fixedDelayTasks != null) { - for (IntervalTask task : fixedDelayTasks) { + for (IntervalTask task : this.fixedDelayTasks) { if (task.getInitialDelay() > 0) { Date startTime = new Date(now + task.getInitialDelay()); this.scheduledFutures.add(this.taskScheduler.scheduleWithFixedDelay( diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java index 1c07868ef6..7706b365f6 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java @@ -40,6 +40,8 @@ import org.springframework.util.StringUtils; * *

Created via the {@link HttpComponentsClientHttpRequestFactory}. * + *

NOTE: Requires Apache HttpComponents 4.3 or higher, as of Spring 4.0. + * * @author Oleg Kalnichevski * @author Arjen Poutsma * @author Juergen Hoeller @@ -73,16 +75,16 @@ final class HttpComponentsClientHttpRequest extends AbstractBufferingClientHttpR } HttpContext getHttpContext() { - return httpContext; + return this.httpContext; } + @Override protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException { addHeaders(this.httpRequest, headers); if (this.httpRequest instanceof HttpEntityEnclosingRequest) { - HttpEntityEnclosingRequest entityEnclosingRequest = - (HttpEntityEnclosingRequest) this.httpRequest; + HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest; HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput); entityEnclosingRequest.setEntity(requestEntity); } diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java index 7b6ca8b894..f8fa0eb702 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java @@ -32,6 +32,8 @@ import org.springframework.http.HttpHeaders; * *

Created via the {@link HttpComponentsClientHttpRequest}. * + *

NOTE: Requires Apache HttpComponents 4.3 or higher, as of Spring 4.0. + * * @author Oleg Kalnichevski * @author Arjen Poutsma * @since 3.1