View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.config.spring.factories;
8   
9   import org.mule.api.config.ConfigurationException;
10  import org.mule.api.endpoint.EndpointFactory;
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.config.i18n.MessageFactory;
13  import org.mule.endpoint.URIBuilder;
14  import org.mule.transport.AbstractConnector;
15  import org.mule.transport.polling.MessageProcessorPollingMessageReceiver;
16  
17  public class PollingMessageSourceFactoryBean extends InboundEndpointFactoryBean
18  {
19  
20      protected MessageProcessor messageProcessor;
21      protected Long frequency;
22  
23      @Override
24      public Object doGetObject() throws Exception
25      {
26          uriBuilder = new URIBuilder("polling://" + hashCode(), muleContext);
27  
28          properties.put(MessageProcessorPollingMessageReceiver.SOURCE_MESSAGE_PROCESSOR_PROPERTY_NAME, messageProcessor);
29          properties.put(AbstractConnector.PROPERTY_POLLING_FREQUENCY, frequency);
30  
31          EndpointFactory ef = muleContext.getEndpointFactory();
32          if (ef != null)
33          {
34              return ef.getInboundEndpoint(this);
35          }
36          else
37          {
38              throw new ConfigurationException(
39                  MessageFactory.createStaticMessage("EndpointFactory not found in Registry"));
40          }
41      }
42  
43      public void setMessageProcessor(MessageProcessor messageProcessor)
44      {
45          this.messageProcessor = messageProcessor;
46      }
47  
48      public void setFrequency(Long frequency)
49      {
50          this.frequency = frequency;
51      }
52  
53  }