diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/PoolItemNotAvailableException.java b/spring-integration-core/src/main/java/org/springframework/integration/util/PoolItemNotAvailableException.java new file mode 100644 index 0000000000..d26dfc498d --- /dev/null +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/PoolItemNotAvailableException.java @@ -0,0 +1,37 @@ +/* + * Copyright 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.integration.util; + +/** + * Thrown when a pooled item could not be obtained for some reason. + * + * @author Gary Russell + * @since 5.1 + * + */ +@SuppressWarnings("serial") +public class PoolItemNotAvailableException extends RuntimeException { + + public PoolItemNotAvailableException(String message, Throwable cause) { + super(message, cause); + } + + public PoolItemNotAvailableException(String message) { + super(message); + } + +} diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java b/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java index 741e485a29..7c31009edb 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -28,7 +28,6 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.messaging.MessagingException; import org.springframework.util.Assert; /** @@ -155,7 +154,7 @@ public class SimplePool implements Pool { /** * Obtains an item from the pool; waits up to waitTime milliseconds (default infinity). - * @throws MessagingException if no items become available in time. + * @throws PoolItemNotAvailableException if no items become available in time. */ @Override public T getItem() { @@ -166,10 +165,10 @@ public class SimplePool implements Pool { } catch (InterruptedException e) { Thread.currentThread().interrupt(); - throw new MessagingException("Interrupted awaiting a pooled resource", e); + throw new PoolItemNotAvailableException("Interrupted awaiting a pooled resource", e); } if (!permitted) { - throw new IllegalStateException("Timed out while waiting to acquire a pool entry."); + throw new PoolItemNotAvailableException("Timed out while waiting to acquire a pool entry."); } return doGetItem(); } @@ -177,10 +176,10 @@ public class SimplePool implements Pool { if (permitted) { this.permits.release(); } - if (e instanceof MessagingException) { - throw (MessagingException) e; + if (e instanceof PoolItemNotAvailableException) { + throw (PoolItemNotAvailableException) e; } - throw new MessagingException("Failed to obtain pooled item", e); + throw new PoolItemNotAvailableException("Failed to obtain pooled item", e); } } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/util/SimplePoolTests.java b/spring-integration-core/src/test/java/org/springframework/integration/util/SimplePoolTests.java index 34a22ea8d5..6ee5a10222 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/util/SimplePoolTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/util/SimplePoolTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 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. @@ -30,7 +30,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Test; import org.springframework.integration.test.util.TestUtils; -import org.springframework.messaging.MessagingException; /** * @author Gary Russell @@ -85,7 +84,7 @@ public class SimplePoolTests { pool.getItem(); fail("Expected exception"); } - catch (MessagingException e) { } + catch (PoolItemNotAvailableException e) { } // resize up pool.setPoolSize(4); @@ -154,17 +153,20 @@ public class SimplePoolTests { final AtomicBoolean stale) { SimplePool pool = new SimplePool(size, new SimplePool.PoolItemCallback() { private int i; + @Override public String createForPool() { String string = "String" + i++; strings.add(string); return string; } + @Override public boolean isStale(String item) { if (stale.get()) { strings.remove(item); } return stale.get(); } + @Override public void removedFromPool(String item) { strings.remove(item); }