diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java b/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java index d0b9ff343..3f860a16a 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/ArrayBlockingQueueWithShutdown.java @@ -1,6 +1,6 @@ /** * - * Copyright 2014 Florian Schmaus + * Copyright 2014-2018 Florian Schmaus * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -263,6 +263,25 @@ public class ArrayBlockingQueueWithShutdown extends AbstractQueue implemen } } + public boolean tryPut(E e) { + checkNotNull(e); + + boolean locked = lock.tryLock(); + if (!locked) { + return false; + } + try { + if (isShutdown || isFull()) { + return false; + } + + insert(e); + return true; + } finally { + lock.unlock(); + } + } + @Override public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException { checkNotNull(e);