Skip to content

Make IOS.setTaskScheduler() as public #2725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -28,8 +28,6 @@
import java.util.concurrent.locks.Lock;

import org.aopalliance.aop.Advice;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanFactory;
Expand Down Expand Up @@ -57,7 +55,6 @@
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

Expand Down Expand Up @@ -96,8 +93,6 @@
public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageProducingHandler
implements DiscardingMessageHandler, DisposableBean, ApplicationEventPublisherAware, Lifecycle {

protected final Log logger = LogFactory.getLog(getClass());

private final Comparator<Message<?>> sequenceNumberComparator = new MessageSequenceComparator();

private final Map<UUID, ScheduledFuture<?>> expireGroupScheduledFutures = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -286,11 +281,6 @@ public void setPopSequence(boolean popSequence) {
this.popSequence = popSequence;
}

@Override
public void setTaskScheduler(TaskScheduler taskScheduler) {
super.setTaskScheduler(taskScheduler);
}

protected boolean isReleaseLockBeforeSend() {
return this.releaseLockBeforeSend;
}
Expand Down Expand Up @@ -444,7 +434,7 @@ protected EvaluationContext getEvaluationContext() {
}

@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
protected void handleMessageInternal(Message<?> message) throws InterruptedException {
Object correlationKey = this.correlationStrategy.getCorrelationKey(message);
Assert.state(correlationKey != null,
"Null correlation not allowed. Maybe the CorrelationStrategy is failing?");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 the original author or authors.
* Copyright 2013-2019 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.
Expand Down Expand Up @@ -30,7 +30,6 @@
import org.springframework.integration.support.channel.HeaderChannelRegistry;
import org.springframework.lang.Nullable;
import org.springframework.messaging.MessageChannel;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;

/**
Expand All @@ -53,11 +52,11 @@ public class DefaultHeaderChannelRegistry extends IntegrationObjectSupport

private static final int DEFAULT_REAPER_DELAY = 60000;

protected static final AtomicLong id = new AtomicLong();
protected static final AtomicLong id = new AtomicLong(); // NOSONAR

protected final Map<String, MessageChannelWrapper> channels = new ConcurrentHashMap<>();
protected final Map<String, MessageChannelWrapper> channels = new ConcurrentHashMap<>(); // NOSONAR

protected final String uuid = UUID.randomUUID().toString() + ":";
protected final String uuid = UUID.randomUUID().toString() + ":"; // NOSONAR

private boolean removeOnGet;

Expand Down Expand Up @@ -108,11 +107,6 @@ public void setRemoveOnGet(boolean removeOnGet) {
this.removeOnGet = removeOnGet;
}

@Override
public void setTaskScheduler(TaskScheduler taskScheduler) {
super.setTaskScheduler(taskScheduler);
}

@Override
public final int size() {
return this.channels.size();
Expand Down Expand Up @@ -157,16 +151,18 @@ public boolean isRunning() {
}

@Override
@Nullable
public Object channelToChannelName(@Nullable Object channel) {
return channelToChannelName(channel, this.reaperDelay);
}

@Override
@Nullable
public Object channelToChannelName(@Nullable Object channel, long timeToLive) {
if (!this.running && !this.explicitlyStopped && this.getTaskScheduler() != null) {
start();
}
if (channel != null && channel instanceof MessageChannel) {
if (channel instanceof MessageChannel) {
String name = this.uuid + id.incrementAndGet();
this.channels.put(name, new MessageChannelWrapper((MessageChannel) channel,
System.currentTimeMillis() + timeToLive));
Expand All @@ -181,6 +177,7 @@ public Object channelToChannelName(@Nullable Object channel, long timeToLive) {
}

@Override
@Nullable
public MessageChannel channelNameToChannel(@Nullable String name) {
if (name != null) {
MessageChannelWrapper messageChannelWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ protected BeanFactory getBeanFactory() {
return this.beanFactory;
}

/**
* Configure a {@link TaskScheduler} for those components which logic relies
* on the scheduled tasks.
* If not provided, falls back to the global {@code taskScheduler} bean
* in the application context, provided by the Spring Integration infrastructure.
* @param taskScheduler the {@link TaskScheduler} to use.
* @since 5.1.3
* @see #getTaskScheduler()
*/
public void setTaskScheduler(TaskScheduler taskScheduler) {
Assert.notNull(taskScheduler, "taskScheduler must not be null");
this.taskScheduler = taskScheduler;
}

protected TaskScheduler getTaskScheduler() {
if (this.taskScheduler == null && this.beanFactory != null) {
this.taskScheduler = IntegrationContextUtils.getTaskScheduler(this.beanFactory);
Expand All @@ -219,11 +233,6 @@ protected DestinationResolver<MessageChannel> getChannelResolver() {
return this.channelResolver;
}

protected void setTaskScheduler(TaskScheduler taskScheduler) {
Assert.notNull(taskScheduler, "taskScheduler must not be null");
this.taskScheduler = taskScheduler;
}

public ConversionService getConversionService() {
if (this.conversionService == null && this.beanFactory != null) {
this.conversionService = IntegrationUtils.getConversionService(this.beanFactory);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand All @@ -26,7 +26,6 @@
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.context.IntegrationProperties;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.PatternMatchUtils;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -56,9 +55,9 @@ public abstract class AbstractEndpoint extends IntegrationObjectSupport

private volatile boolean running;

protected final ReentrantLock lifecycleLock = new ReentrantLock();
protected final ReentrantLock lifecycleLock = new ReentrantLock(); // NOSONAR

protected final Condition lifecycleCondition = this.lifecycleLock.newCondition();
protected final Condition lifecycleCondition = this.lifecycleLock.newCondition(); // NOSONAR

private String role;

Expand Down Expand Up @@ -89,11 +88,6 @@ public String getRole() {
return this.role;
}

@Override
public void setTaskScheduler(TaskScheduler taskScheduler) {
super.setTaskScheduler(taskScheduler);
}

@Override
protected void onInit() {
super.onInit();
Expand Down Expand Up @@ -125,7 +119,7 @@ protected void onInit() {
}

@Override
public void destroy() throws Exception {
public void destroy() throws Exception { // NOSONAR TODO: remove throws in 5.2
if (this.roleController != null) {
this.roleController.removeLifecycle(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.core.DestinationResolver;
import org.springframework.messaging.support.ErrorMessage;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert;
Expand Down Expand Up @@ -142,7 +143,7 @@ public DelayHandler(String messageGroupId) {
*/
public DelayHandler(String messageGroupId, TaskScheduler taskScheduler) {
this(messageGroupId);
this.setTaskScheduler(taskScheduler);
setTaskScheduler(taskScheduler);
}

/**
Expand Down Expand Up @@ -272,11 +273,9 @@ private MessageChannel getErrorChannel() {
if (this.delayedMessageErrorChannel != null) {
return this.delayedMessageErrorChannel;
}
if (this.delayedMessageErrorChannelName != null) {
if (getChannelResolver() != null) {
this.delayedMessageErrorChannel = getChannelResolver()
.resolveDestination(this.delayedMessageErrorChannelName);
}
DestinationResolver<MessageChannel> channelResolver = getChannelResolver();
if (this.delayedMessageErrorChannelName != null && channelResolver != null) {
this.delayedMessageErrorChannel = channelResolver.resolveDestination(this.delayedMessageErrorChannelName);
}
return this.delayedMessageErrorChannel;
}
Expand Down Expand Up @@ -516,11 +515,9 @@ private void doReleaseMessage(Message<?> message) {
}
handleMessageInternal(message);
}
else {
if (logger.isDebugEnabled()) {
logger.debug("No message in the Message Store to release: " + message +
". Likely another instance has already released it.");
}
else if (logger.isDebugEnabled()) {
logger.debug("No message in the Message Store to release: " + message +
". Likely another instance has already released it.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,6 @@ public void setFlushWhenIdle(boolean flushWhenIdle) {
this.flushWhenIdle = flushWhenIdle;
}

/**
* Configure a {@link TaskScheduler} for flush operations.
* @param taskScheduler the {@link TaskScheduler} to use.
*/
@Override
public void setTaskScheduler(TaskScheduler taskScheduler) { // NOSONAR
super.setTaskScheduler(taskScheduler);
}

/**
* Set a {@link MessageFlushPredicate} to use when flushing files when
* {@link FileExistsMode#APPEND_NO_FLUSH} is being used.
Expand Down
Loading