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