Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PollingReceiverWorker |
|
| 1.6;1.6 |
1 | /* | |
2 | * $Id: PollingReceiverWorker.java 10489 2008-01-23 17:53:38Z dfeist $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.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; | |
12 | ||
13 | import javax.resource.spi.work.Work; | |
14 | ||
15 | public class PollingReceiverWorker implements Work | |
16 | { | |
17 | protected final AbstractPollingMessageReceiver receiver; | |
18 | 0 | protected volatile boolean running = false; |
19 | ||
20 | public PollingReceiverWorker(AbstractPollingMessageReceiver pollingMessageReceiver) | |
21 | { | |
22 | 0 | super(); |
23 | 0 | receiver = pollingMessageReceiver; |
24 | 0 | } |
25 | ||
26 | public AbstractPollingMessageReceiver getReceiver() | |
27 | { | |
28 | 0 | return receiver; |
29 | } | |
30 | ||
31 | public boolean isRunning() | |
32 | { | |
33 | 0 | return running; |
34 | } | |
35 | ||
36 | // the run() method will exit after each poll() since it will be invoked again | |
37 | // by the scheduler | |
38 | public void run() | |
39 | { | |
40 | 0 | if (!receiver.stopped.get()) |
41 | { | |
42 | try | |
43 | { | |
44 | 0 | running = true; |
45 | // make sure we are connected, wait if necessary | |
46 | 0 | receiver.connected.whenTrue(null); |
47 | 0 | receiver.poll(); |
48 | } | |
49 | 0 | catch (InterruptedException e) |
50 | { | |
51 | // stop polling | |
52 | 0 | receiver.stop(); |
53 | } | |
54 | 0 | catch (Exception e) |
55 | { | |
56 | 0 | receiver.handleException(e); |
57 | } | |
58 | finally | |
59 | { | |
60 | 0 | running = false; |
61 | 0 | } |
62 | } | |
63 | 0 | } |
64 | ||
65 | public void release() | |
66 | { | |
67 | // nop | |
68 | 0 | } |
69 | ||
70 | } |