View Javadoc

1   /*
2    * $Id: PollingMessageSourceFactoryBean.java 20395 2010-11-30 10:48:13Z dfeist $
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      public Object doGetObject() throws Exception
28      {
29          uriBuilder = new URIBuilder("polling://" + hashCode(), muleContext);
30          properties.put(MessageProcessorPollingMessageReceiver.SOURCE_MESSAGE_PROCESSOR_PROPERTY_NAME, messageProcessor);
31          properties.put(AbstractConnector.PROPERTY_POLLING_FREQUENCY, frequency);
32          EndpointFactory ef = muleContext.getRegistry().lookupEndpointFactory();
33          if (ef != null)
34          {
35              return ef.getInboundEndpoint(this);
36          }
37          else
38          {
39              throw new ConfigurationException(
40                  MessageFactory.createStaticMessage("EndpointFactory not found in Registry"));
41          }
42      }
43  
44      public void setMessageProcessor(MessageProcessor messageProcessor)
45      {
46          this.messageProcessor = messageProcessor;
47      }
48  
49      public void setFrequency(Long frequency)
50      {
51          this.frequency = frequency;
52      }
53  
54  }