001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jms.config; 018 019import java.util.concurrent.Executor; 020 021import org.springframework.jms.listener.DefaultMessageListenerContainer; 022import org.springframework.lang.Nullable; 023import org.springframework.transaction.PlatformTransactionManager; 024import org.springframework.util.backoff.BackOff; 025 026/** 027 * A {@link JmsListenerContainerFactory} implementation to build a regular 028 * {@link DefaultMessageListenerContainer}. 029 * 030 * <p>This should be the default for most users and a good transition paths 031 * for those that are used to build such container definition manually. 032 * 033 * @author Stephane Nicoll 034 * @since 4.1 035 */ 036public class DefaultJmsListenerContainerFactory 037 extends AbstractJmsListenerContainerFactory<DefaultMessageListenerContainer> { 038 039 @Nullable 040 private Executor taskExecutor; 041 042 @Nullable 043 private PlatformTransactionManager transactionManager; 044 045 @Nullable 046 private Integer cacheLevel; 047 048 @Nullable 049 private String cacheLevelName; 050 051 @Nullable 052 private String concurrency; 053 054 @Nullable 055 private Integer maxMessagesPerTask; 056 057 @Nullable 058 private Long receiveTimeout; 059 060 @Nullable 061 private Long recoveryInterval; 062 063 @Nullable 064 private BackOff backOff; 065 066 067 /** 068 * @see DefaultMessageListenerContainer#setTaskExecutor 069 */ 070 public void setTaskExecutor(Executor taskExecutor) { 071 this.taskExecutor = taskExecutor; 072 } 073 074 /** 075 * @see DefaultMessageListenerContainer#setTransactionManager 076 */ 077 public void setTransactionManager(PlatformTransactionManager transactionManager) { 078 this.transactionManager = transactionManager; 079 } 080 081 /** 082 * @see DefaultMessageListenerContainer#setCacheLevel 083 */ 084 public void setCacheLevel(Integer cacheLevel) { 085 this.cacheLevel = cacheLevel; 086 } 087 088 /** 089 * @see DefaultMessageListenerContainer#setCacheLevelName 090 */ 091 public void setCacheLevelName(String cacheLevelName) { 092 this.cacheLevelName = cacheLevelName; 093 } 094 095 /** 096 * @see DefaultMessageListenerContainer#setConcurrency 097 */ 098 public void setConcurrency(String concurrency) { 099 this.concurrency = concurrency; 100 } 101 102 /** 103 * @see DefaultMessageListenerContainer#setMaxMessagesPerTask 104 */ 105 public void setMaxMessagesPerTask(Integer maxMessagesPerTask) { 106 this.maxMessagesPerTask = maxMessagesPerTask; 107 } 108 109 /** 110 * @see DefaultMessageListenerContainer#setReceiveTimeout 111 */ 112 public void setReceiveTimeout(Long receiveTimeout) { 113 this.receiveTimeout = receiveTimeout; 114 } 115 116 /** 117 * @see DefaultMessageListenerContainer#setRecoveryInterval 118 */ 119 public void setRecoveryInterval(Long recoveryInterval) { 120 this.recoveryInterval = recoveryInterval; 121 } 122 123 /** 124 * @see DefaultMessageListenerContainer#setBackOff 125 */ 126 public void setBackOff(BackOff backOff) { 127 this.backOff = backOff; 128 } 129 130 131 @Override 132 protected DefaultMessageListenerContainer createContainerInstance() { 133 return new DefaultMessageListenerContainer(); 134 } 135 136 @Override 137 protected void initializeContainer(DefaultMessageListenerContainer container) { 138 if (this.taskExecutor != null) { 139 container.setTaskExecutor(this.taskExecutor); 140 } 141 if (this.transactionManager != null) { 142 container.setTransactionManager(this.transactionManager); 143 } 144 145 if (this.cacheLevel != null) { 146 container.setCacheLevel(this.cacheLevel); 147 } 148 else if (this.cacheLevelName != null) { 149 container.setCacheLevelName(this.cacheLevelName); 150 } 151 152 if (this.concurrency != null) { 153 container.setConcurrency(this.concurrency); 154 } 155 if (this.maxMessagesPerTask != null) { 156 container.setMaxMessagesPerTask(this.maxMessagesPerTask); 157 } 158 if (this.receiveTimeout != null) { 159 container.setReceiveTimeout(this.receiveTimeout); 160 } 161 162 if (this.backOff != null) { 163 container.setBackOff(this.backOff); 164 if (this.recoveryInterval != null) { 165 logger.info("Ignoring recovery interval in DefaultJmsListenerContainerFactory in favor of BackOff"); 166 } 167 } 168 else if (this.recoveryInterval != null) { 169 container.setRecoveryInterval(this.recoveryInterval); 170 } 171 } 172 173}