Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CountingRedeliveryHandlerFactory |
|
| 0.0;0 |
1 | /* | |
2 | * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com | |
3 | * The software in this package is published under the terms of the CPAL v1.0 | |
4 | * license, a copy of which has been included with this distribution in the | |
5 | * LICENSE.txt file. | |
6 | */ | |
7 | package org.mule.transport.jms.redelivery; | |
8 | ||
9 | ||
10 | import java.util.concurrent.atomic.AtomicReference; | |
11 | ||
12 | /** | |
13 | * @see CountingRedeliveryHandler | |
14 | */ | |
15 | 0 | public class CountingRedeliveryHandlerFactory implements RedeliveryHandlerFactory |
16 | { | |
17 | ||
18 | 0 | protected AtomicReference<RedeliveryHandler> handler = new AtomicReference<RedeliveryHandler>(null); |
19 | ||
20 | public RedeliveryHandler create() | |
21 | { | |
22 | RedeliveryHandler result; | |
23 | ||
24 | // initialize, accounting for concurrency | |
25 | 0 | if (handler.get() == null) |
26 | { | |
27 | 0 | final CountingRedeliveryHandler newInstance = new CountingRedeliveryHandler(); |
28 | 0 | boolean ok = handler.compareAndSet(null, newInstance); |
29 | 0 | if (!ok) |
30 | { | |
31 | // someone was faster to initialize it, use this ref instead | |
32 | 0 | result = handler.get(); |
33 | } | |
34 | else | |
35 | { | |
36 | 0 | result = newInstance; |
37 | } | |
38 | 0 | } |
39 | else | |
40 | { | |
41 | // just re-use existing stateful handler | |
42 | 0 | result = handler.get(); |
43 | } | |
44 | ||
45 | 0 | return result; |
46 | } | |
47 | ||
48 | } | |
49 | ||
50 |