KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > response > AbstractResponseRouter


1 /*
2  * $Id: AbstractResponseRouter.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.routing.response;
12
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15 import org.mule.config.MuleConfiguration;
16 import org.mule.config.MuleProperties;
17 import org.mule.util.properties.PropertyExtractor;
18 import org.mule.management.stats.RouterStatistics;
19 import org.mule.routing.CorrelationPropertiesExtractor;
20 import org.mule.umo.UMOMessage;
21 import org.mule.umo.routing.UMOResponseRouter;
22 import org.mule.util.ClassUtils;
23
24 /**
25  * <code>AbstractResponseRouter</code> is a base class for all Response Routers
26  */

27
28 public abstract class AbstractResponseRouter implements UMOResponseRouter
29 {
30     protected transient final Log logger = LogFactory.getLog(getClass());
31
32     private RouterStatistics routerStatistics;
33
34     private int timeout = MuleConfiguration.DEFAULT_TIMEOUT;
35
36     protected PropertyExtractor correlationExtractor = new CorrelationPropertiesExtractor();
37
38     public RouterStatistics getRouterStatistics()
39     {
40         return routerStatistics;
41     }
42
43     public void setRouterStatistics(RouterStatistics routerStatistics)
44     {
45         this.routerStatistics = routerStatistics;
46     }
47
48     public PropertyExtractor getCorrelationExtractor()
49     {
50         return correlationExtractor;
51     }
52
53     public void setCorrelationExtractor(PropertyExtractor correlationExtractor)
54     {
55         this.correlationExtractor = correlationExtractor;
56     }
57
58     /**
59      * A digester callback to configure a custom correlation extractor.
60      *
61      * @param className correlation extractor fully qualified class name
62      */

63     public void setPropertyExtractorAsString(String JavaDoc className)
64     {
65         try
66         {
67             this.correlationExtractor = (PropertyExtractor)ClassUtils.instanciateClass(className, null,
68                 getClass());
69         }
70         catch (Exception JavaDoc ex)
71         {
72             throw new IllegalArgumentException JavaDoc("Couldn't instanciate property extractor class " + className);
73         }
74     }
75
76     public int getTimeout()
77     {
78         return timeout;
79     }
80
81     public void setTimeout(int timeout)
82     {
83         this.timeout = timeout;
84     }
85
86     /**
87      * Extracts a 'Correlation Id' from a reply message. The correlation Id does not
88      * have to be the Message Correlation Id. It can be extracted from the message
89      * payload if desired.
90      *
91      * @param message a received reply message
92      * @return the correlation Id for this message
93      */

94     protected Object JavaDoc getReplyAggregateIdentifier(UMOMessage message)
95     {
96         return correlationExtractor.getProperty(MuleProperties.MULE_CORRELATION_ID_PROPERTY, message);
97     }
98
99     /**
100      * Extracts a Group identifier from the current event. When an event is received
101      * with a group identifier not registered with this router, a new group is
102      * created. The id returned here can be a correlationId or some custom
103      * aggregation Id. This implementation uses the Unique Message Id of the
104      * UMOMessage being returned a
105      *
106      * @param message A response messages received on the response router endpoint
107      * @return an aggregation Id for this event
108      */

109     protected Object JavaDoc getCallResponseAggregateIdentifier(UMOMessage message)
110     {
111         return correlationExtractor.getProperty(MuleProperties.MULE_MESSAGE_ID_PROPERTY, message);
112     }
113
114 }
115
Popular Tags