PHP Class DataSift_StreamConsumer

Author: Stuart Dallas ([email protected])
Mostrar archivo Open project: datasift/datasift-php Class Usage Examples

Protected Properties

Property Type Description
$_auto_reconnect Set to true when the client is supposed to reconnect automatically.
$_definition The DataSift stream definition object.
$_eventHandler The event handler object.
$_hashes The array of hashes to be consumed if using multi
$_is_multi True if this is consuming multiple hashes
$_state State active or stopped.
$_user DataSift object

Public Methods

Method Description
consume ( boolean $auto_reconnect = true ) : void Once an instance of a StreamConsumer is ready for use, call this to start consuming. Extending classes should implement onStart to handle actually starting.
factory ( string $user, string $type, mixed $definition, string $eventHandler ) : DataSift_StreamConsumer Factory function. Creates a StreamConsumer-derived object for the given type.
stop ( ) : void This method can be called at any time to *request* that the consumer stop consuming. This method sets the state to STATE_STOPPING and it's up to the consumer implementation to notice that this has changed, stop consuming and call the onStopped method.

Protected Methods

Method Description
__construct ( DataSift_User $user, mixed $definition, DataSift_IStreamConsumerEventHandler $eventHandler ) Constructor. Do not use this directly, use the factory method instead.
onConnect ( ) : void This is called when the underlying stream is connected.
onData ( $json ) : void This is called when a complete JSON item is received.
onDeleted ( array $interaction, string $hash = false ) : void This is called for each DELETE request received from the stream and must be implemented in extending classes.
onDisconnect ( ) : void This is called when the underlying stream is disconnected.
onError ( string $message ) : void This is called when an error notification is received on a stream connection.
onInteraction ( array $interaction, boolean $hash = false ) : void This is called for each interaction received from the stream and must be implemented in extending classes.
onStart ( ) : void Called when the consumer should start consuming the stream.
onStatus ( string $type, array $info = [] ) : void Called for each status message received from the stream.
onStop ( string $reason = '' ) : void Default implementation of onStop. It's unlikely that this method will ever be used in isolation, but rather it should be called as the final step in the extending class's implementation.
onStopped ( string $reason = '' ) : void This is called when the consumer is stopped.
onWarning ( string $message ) : void This is called when a warning notification is received on a scream connection.

Method Details

__construct() protected method

Constructor. Do not use this directly, use the factory method instead.
protected __construct ( DataSift_User $user, mixed $definition, DataSift_IStreamConsumerEventHandler $eventHandler )
$user DataSift_User The user this consumer will run as.
$definition mixed CSDL string, a Definition object, or an array of hashes.
$eventHandler DataSift_IStreamConsumerEventHandler The object that will receive events.

consume() public method

Once an instance of a StreamConsumer is ready for use, call this to start consuming. Extending classes should implement onStart to handle actually starting.
public consume ( boolean $auto_reconnect = true ) : void
$auto_reconnect boolean Whether to reconnect automatically
return void

factory() public static method

Factory function. Creates a StreamConsumer-derived object for the given type.
public static factory ( string $user, string $type, mixed $definition, string $eventHandler ) : DataSift_StreamConsumer
$user string Use DataSift_User object.
$type string Use the TYPE_ constants
$definition mixed CSDL string or a Definition object.
$eventHandler string The object that will receive events.
return DataSift_StreamConsumer The consumer object

onConnect() protected method

This is called when the underlying stream is connected.
protected onConnect ( ) : void
return void

onData() protected method

This is called when a complete JSON item is received.
protected onData ( $json ) : void
$json The JSON data.
return void

onDeleted() protected method

This is called for each DELETE request received from the stream and must be implemented in extending classes.
protected onDeleted ( array $interaction, string $hash = false ) : void
$interaction array The interaction data structure
$hash string The stream hash.
return void

onDisconnect() protected method

This is called when the underlying stream is disconnected.
protected onDisconnect ( ) : void
return void

onError() protected method

This is called when an error notification is received on a stream connection.
protected onError ( string $message ) : void
$message string The error message
return void

onInteraction() protected method

This is called for each interaction received from the stream and must be implemented in extending classes.
protected onInteraction ( array $interaction, boolean $hash = false ) : void
$interaction array The interaction data structure
$hash boolean
return void

onStart() abstract protected method

Called when the consumer should start consuming the stream.
abstract protected onStart ( ) : void
return void

onStatus() protected method

Called for each status message received from the stream.
protected onStatus ( string $type, array $info = [] ) : void
$type string The status type.
$info array The data received along with the status message.
return void

onStop() protected method

Default implementation of onStop. It's unlikely that this method will ever be used in isolation, but rather it should be called as the final step in the extending class's implementation.
protected onStop ( string $reason = '' ) : void
$reason string Reason why the stream was stopped
return void

onStopped() protected method

This is called when the consumer is stopped.
protected onStopped ( string $reason = '' ) : void
$reason string Reason to stop the stream
return void

onWarning() protected method

This is called when a warning notification is received on a scream connection.
protected onWarning ( string $message ) : void
$message string The warning message
return void

stop() public method

This method can be called at any time to *request* that the consumer stop consuming. This method sets the state to STATE_STOPPING and it's up to the consumer implementation to notice that this has changed, stop consuming and call the onStopped method.
public stop ( ) : void
return void

Property Details

$_auto_reconnect protected_oe property

Set to true when the client is supposed to reconnect automatically.
protected $_auto_reconnect

$_definition protected_oe property

The DataSift stream definition object.
protected $_definition

$_eventHandler protected_oe property

The event handler object.
protected $_eventHandler

$_hashes protected_oe property

The array of hashes to be consumed if using multi
protected $_hashes

$_is_multi protected_oe property

True if this is consuming multiple hashes
protected $_is_multi

$_state protected_oe property

State active or stopped.
protected $_state

$_user protected_oe property

DataSift object
protected $_user