View Javadoc

1   /*
2    * $Id: PollingMessageSourceFactoryBean.java 21610 2011-03-28 09:52:05Z dirk.olmes $
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.config.spring.factories;
12  
13  import org.mule.api.config.ConfigurationException;
14  import org.mule.api.endpoint.EndpointFactory;
15  import org.mule.api.processor.MessageProcessor;
16  import org.mule.config.i18n.MessageFactory;
17  import org.mule.endpoint.URIBuilder;
18  import org.mule.transport.AbstractConnector;
19  import org.mule.transport.polling.MessageProcessorPollingMessageReceiver;
20  
21  public class PollingMessageSourceFactoryBean extends InboundEndpointFactoryBean
22  {
23  
24      protected MessageProcessor messageProcessor;
25      protected Long frequency;
26  
27      @Override
28      public Object doGetObject() throws Exception
29      {
30          uriBuilder = new URIBuilder("polling://" + hashCode(), muleContext);
31  
32          properties.put(MessageProcessorPollingMessageReceiver.SOURCE_MESSAGE_PROCESSOR_PROPERTY_NAME, messageProcessor);
33          properties.put(AbstractConnector.PROPERTY_POLLING_FREQUENCY, frequency);
34  
35          EndpointFactory ef = muleContext.getEndpointFactory();
36          if (ef != null)
37          {
38              return ef.getInboundEndpoint(this);
39          }
40          else
41          {
42              throw new ConfigurationException(
43                  MessageFactory.createStaticMessage("EndpointFactory not found in Registry"));
44          }
45      }
46  
47      public void setMessageProcessor(MessageProcessor messageProcessor)
48      {
49          this.messageProcessor = messageProcessor;
50      }
51  
52      public void setFrequency(Long frequency)
53      {
54          this.frequency = frequency;
55      }
56  
57  }