Skip to content

Commit 65b8899

Browse files
committed
Revert INT-4386: Support Instant in schedule expr.
This reverts commit f901c4e.
1 parent f901c4e commit 65b8899

File tree

3 files changed

+10
-44
lines changed

3 files changed

+10
-44
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/IntegrationEvaluationContextFactoryBean.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2019 the original author or authors.
2+
* Copyright 2013-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
import org.springframework.expression.PropertyAccessor;
2727
import org.springframework.expression.TypeLocator;
2828
import org.springframework.expression.spel.support.StandardEvaluationContext;
29-
import org.springframework.expression.spel.support.StandardTypeLocator;
3029
import org.springframework.integration.context.IntegrationContextUtils;
3130

3231
/**
@@ -66,7 +65,7 @@
6665
public class IntegrationEvaluationContextFactoryBean extends AbstractEvaluationContextFactoryBean
6766
implements FactoryBean<StandardEvaluationContext> {
6867

69-
private TypeLocator typeLocator;
68+
private volatile TypeLocator typeLocator;
7069

7170
private BeanResolver beanResolver;
7271

@@ -88,21 +87,12 @@ public void afterPropertiesSet() throws Exception {
8887
}
8988

9089
@Override
91-
public StandardEvaluationContext getObject() {
90+
public StandardEvaluationContext getObject() throws Exception {
9291
StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
9392
if (this.typeLocator != null) {
9493
evaluationContext.setTypeLocator(this.typeLocator);
9594
}
9695

97-
TypeLocator typeLocator = evaluationContext.getTypeLocator();
98-
if (typeLocator instanceof StandardTypeLocator) {
99-
/*
100-
* Register the 'java.time' package so its classes don't need a FQCN,
101-
* for example ' T(Instant).now().plusSeconds(5)'.
102-
*/
103-
((StandardTypeLocator) typeLocator).registerImport("java.time");
104-
}
105-
10696
evaluationContext.setBeanResolver(this.beanResolver);
10797
evaluationContext.setTypeConverter(getTypeConverter());
10898

spring-integration-core/src/main/java/org/springframework/integration/handler/DelayHandler.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.integration.handler;
1818

1919
import java.io.Serializable;
20-
import java.time.Instant;
2120
import java.util.Collection;
2221
import java.util.Collections;
2322
import java.util.Date;
@@ -159,9 +158,8 @@ public void setDefaultDelay(long defaultDelay) {
159158
}
160159

161160
/**
162-
* Specify the {@link Expression} that should be checked for a delay period
163-
* (in milliseconds) or a {@link Date}, or {@link Instant} to delay until.
164-
* If this property is set, the result of the
161+
* Specify the {@link Expression} that should be checked for a delay period (in
162+
* milliseconds) or a Date to delay until. If this property is set, the result of the
165163
* expression evaluation (if not null) will take precedence over this handler's
166164
* default delay.
167165
* @param delayExpression The delay expression.
@@ -171,9 +169,8 @@ public void setDelayExpression(Expression delayExpression) {
171169
}
172170

173171
/**
174-
* Specify the {@code Expression} that should be checked for a delay period
175-
* (in milliseconds) or a {@link Date}, or {@link Instant} to delay until.
176-
* If this property is set, the result of the
172+
* Specify the {@code Expression} that should be checked for a delay period (in
173+
* milliseconds) or a Date to delay until. If this property is set, the result of the
177174
* expression evaluation (if not null) will take precedence over this handler's
178175
* default delay.
179176
* @param delayExpression The delay expression.
@@ -367,12 +364,6 @@ private long determineDelayForMessage(Message<?> message) {
367364
: System.currentTimeMillis();
368365
delay = ((Date) delayValue).getTime() - current;
369366
}
370-
else if (delayValue instanceof Instant) {
371-
long current = delayedMessageWrapper != null
372-
? delayedMessageWrapper.getRequestDate()
373-
: Instant.now().toEpochMilli();
374-
delay = ((Instant) delayValue).minusMillis(current).toEpochMilli();
375-
}
376367
else if (delayValue != null) {
377368
try {
378369
delay = Long.valueOf(delayValue.toString());
@@ -400,7 +391,8 @@ else if (delayValue != null) {
400391

401392
private void releaseMessageAfterDelay(final Message<?> message, long delay) {
402393
Message<?> delayedMessage = message;
403-
DelayedMessageWrapper messageWrapper;
394+
395+
DelayedMessageWrapper messageWrapper = null;
404396
if (message.getPayload() instanceof DelayedMessageWrapper) {
405397
messageWrapper = (DelayedMessageWrapper) message.getPayload();
406398
}

spring-integration-core/src/test/java/org/springframework/integration/handler/DelayHandlerTests.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import org.springframework.integration.channel.DirectChannel;
5151
import org.springframework.integration.channel.MessagePublishingErrorHandler;
5252
import org.springframework.integration.channel.QueueChannel;
53-
import org.springframework.integration.config.IntegrationEvaluationContextFactoryBean;
5453
import org.springframework.integration.context.IntegrationContextUtils;
5554
import org.springframework.integration.store.MessageGroup;
5655
import org.springframework.integration.store.MessageGroupStore;
@@ -94,16 +93,13 @@ public class DelayHandlerTests {
9493

9594
@Before
9695
public void setup() {
97-
this.context.registerBean(IntegrationContextUtils.INTEGRATION_EVALUATION_CONTEXT_BEAN_NAME,
98-
new IntegrationEvaluationContextFactoryBean());
99-
this.context.refresh();
10096
input.setBeanName("input");
10197
output.setBeanName("output");
10298
taskScheduler = new ThreadPoolTaskScheduler();
10399
taskScheduler.afterPropertiesSet();
104100
delayHandler = new DelayHandler(DELAYER_MESSAGE_GROUP_ID, taskScheduler);
105101
delayHandler.setOutputChannel(output);
106-
delayHandler.setBeanFactory(this.context);
102+
delayHandler.setBeanFactory(mock(BeanFactory.class));
107103
input.subscribe(delayHandler);
108104
output.subscribe(resultHandler);
109105
}
@@ -236,18 +232,6 @@ public void delayHeaderIsDateInTheFutureAndDefaultDelayWouldTimeout() {
236232
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
237233
}
238234

239-
@Test
240-
public void delayHeaderIsInstantInTheFutureAndDefaultDelayWouldTimeout() {
241-
this.delayHandler.setDefaultDelay(5000);
242-
this.delayHandler.setDelayExpressionString("T(Instant).now().plusMillis(150)");
243-
startDelayerHandler();
244-
Message<?> message = new GenericMessage<>("test");
245-
this.input.send(message);
246-
waitForLatch(10000);
247-
assertSame(message.getPayload(), this.resultHandler.lastMessage.getPayload());
248-
assertNotSame(Thread.currentThread(), this.resultHandler.lastThread);
249-
}
250-
251235
@Test
252236
public void delayHeaderIsDateInThePastAndDefaultDelayWouldTimeout() {
253237
delayHandler.setDefaultDelay(5000);

0 commit comments

Comments
 (0)