From c7697ea9d016b13b9cb9a326fe08a1a9dc9890ae Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 16 May 2018 07:57:50 +0200 Subject: [PATCH] Add ArrayBlockingQueueWithShutdown.tryPut(E) --- .../util/ArrayBlockingQueueWithShutdown.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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);