Spring Integration

org.springframework.integration.twitter
Class AbstractInboundTwitterEndpointSupport<T>

java.lang.Object
  extended by org.springframework.integration.context.IntegrationObjectSupport
      extended by org.springframework.integration.endpoint.AbstractEndpoint
          extended by org.springframework.integration.twitter.AbstractInboundTwitterEndpointSupport<T>
All Implemented Interfaces:
BeanFactoryAware, BeanNameAware, InitializingBean, Lifecycle, Phased, SmartLifecycle, NamedComponent
Direct Known Subclasses:
AbstractInboundTwitterStatusEndpointSupport, InboundDMStatusEndpoint

public abstract class AbstractInboundTwitterEndpointSupport<T>
extends AbstractEndpoint
implements Lifecycle

There are a lot of operations that are common to receiving the various types of messages when using the Twitter API, and this class abstracts most of them for you. Implementers must take note of runAsAPIRateLimitsPermit(org.springframework.integration.twitter.AbstractInboundTwitterEndpointSupport.ApiCallback) which will invoke the instance of AbstractInboundTwitterEndpointSupport.ApiCallback when the rate-limit API deems that its OK to do so. This class handles keeping tabs on that and on spacing out requests as required.

Simialarly, this class handles keeping track on the latest inbound message its received and avoiding, where possible, redelivery of common messages. This functionality is enabled using the MetadataPersister implementation

Since:
2.0
Author:
Josh Long

Nested Class Summary
static interface AbstractInboundTwitterEndpointSupport.ApiCallback<C>
          Hook for clients to run logic when the API rate limiting lets us

Simply register your callback using #runAsAPIRateLimitsPermit

 
Field Summary
protected  OAuthConfiguration configuration
           
protected  long markerId
           
protected  MessagingTemplate messagingTemplate
           
protected  twitter4j.Twitter twitter
           
 
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
logger
 
Constructor Summary
AbstractInboundTwitterEndpointSupport()
           
 
Method Summary
protected  void doStart()
          Subclasses must implement this method with the start behavior.
protected  void doStop()
          Subclasses must implement this method with the stop behavior.
protected  void forward(T status)
           
protected  void forwardAll(twitter4j.ResponseList<T> tResponses)
           
 long getMarkerId()
           
protected  boolean handleReceivingRateLimitStatus(twitter4j.RateLimitStatus rateLimitStatus)
           
protected  boolean hasMarkedStatus()
           
protected abstract  void markLastStatusId(T statusId)
           
protected  void onInit()
          Subclasses may implement this for initialization logic.
protected abstract  void refresh()
           
protected  void runAsAPIRateLimitsPermit(AbstractInboundTwitterEndpointSupport.ApiCallback cb)
           
 void setConfiguration(OAuthConfiguration configuration)
           
 void setRequestChannel(MessageChannel requestChannel)
           
protected abstract  List<T> sort(List<T> rl)
           
protected  boolean waitUntilPullAvailable()
           
 
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
getPhase, isAutoStartup, isRunning, setAutoStartup, setPhase, setTaskScheduler, start, stop, stop
 
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, getBeanFactory, getComponentName, getComponentType, getConversionService, getRequiredMetadataPersister, getTaskScheduler, setBeanFactory, setBeanName, setComponentName, setConversionService, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.context.Lifecycle
isRunning, start, stop
 

Field Detail

configuration

protected volatile OAuthConfiguration configuration

messagingTemplate

protected final MessagingTemplate messagingTemplate

markerId

protected volatile long markerId

twitter

protected twitter4j.Twitter twitter
Constructor Detail

AbstractInboundTwitterEndpointSupport

public AbstractInboundTwitterEndpointSupport()
Method Detail

setConfiguration

public void setConfiguration(OAuthConfiguration configuration)

markLastStatusId

protected abstract void markLastStatusId(T statusId)

sort

protected abstract List<T> sort(List<T> rl)

forwardAll

protected void forwardAll(twitter4j.ResponseList<T> tResponses)

getMarkerId

public long getMarkerId()

doStart

protected void doStart()
Description copied from class: AbstractEndpoint
Subclasses must implement this method with the start behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.

Specified by:
doStart in class AbstractEndpoint

forward

protected void forward(T status)

runAsAPIRateLimitsPermit

protected void runAsAPIRateLimitsPermit(AbstractInboundTwitterEndpointSupport.ApiCallback cb)
                                 throws Exception
Throws:
Exception

handleReceivingRateLimitStatus

protected boolean handleReceivingRateLimitStatus(twitter4j.RateLimitStatus rateLimitStatus)

waitUntilPullAvailable

protected boolean waitUntilPullAvailable()
                                  throws Exception
Throws:
Exception

hasMarkedStatus

protected boolean hasMarkedStatus()

refresh

protected abstract void refresh()
                         throws Exception
Throws:
Exception

onInit

protected void onInit()
               throws Exception
Description copied from class: IntegrationObjectSupport
Subclasses may implement this for initialization logic.

Overrides:
onInit in class IntegrationObjectSupport
Throws:
Exception

doStop

protected void doStop()
Description copied from class: AbstractEndpoint
Subclasses must implement this method with the stop behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.

Specified by:
doStop in class AbstractEndpoint

setRequestChannel

public void setRequestChannel(MessageChannel requestChannel)

Spring Integration

Copyright © 2010. All Rights Reserved.