1
2
3
4
5
6
7 package org.mule.tck;
8
9 import org.mule.api.MuleEvent;
10 import org.mule.api.MuleException;
11 import org.mule.api.processor.MessageProcessor;
12 import org.mule.api.source.MessageSource;
13 import org.mule.util.ObjectUtils;
14 import org.mule.util.concurrent.Latch;
15
16 public class SensingNullMessageProcessor implements MessageProcessor
17 {
18 public MuleEvent event;
19 protected InternalMessageSource source = new InternalMessageSource();
20 private long waitTime = 0;
21 public Latch latch = new Latch();
22
23 public MuleEvent process(MuleEvent event) throws MuleException
24 {
25 if (waitTime > 0)
26 {
27 try
28 {
29 Thread.sleep(waitTime);
30 }
31 catch (InterruptedException e)
32 {
33 throw new RuntimeException(e);
34 }
35 }
36 this.event = event;
37 latch.countDown();
38 if (source.listener != null)
39 {
40 return source.listener.process(event);
41 }
42 else
43 {
44 if (event.getEndpoint().getExchangePattern().hasResponse())
45 {
46 return event;
47 }
48 else
49 {
50 return null;
51 }
52 }
53 }
54
55 public void clear()
56 {
57 event = null;
58 }
59
60 public MessageSource getMessageSource()
61 {
62 return source;
63 }
64
65 public void setWaitTime(long waitTime)
66 {
67 this.waitTime = waitTime;
68 }
69
70 class InternalMessageSource implements MessageSource
71 {
72 MessageProcessor listener;
73
74 public void setListener(MessageProcessor listener)
75 {
76 this.listener = listener;
77
78 }
79
80 @Override
81 public String toString()
82 {
83 return ObjectUtils.toString(this);
84 }
85 }
86 }