PHP Class DataSift_StreamConsumer

Author: Stuart Dallas ([email protected])
Afficher le fichier Open project: datasift/datasift-php Class Usage Examples

Protected Properties

Свойство 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

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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 méthode

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
Résultat void

factory() public static méthode

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.
Résultat DataSift_StreamConsumer The consumer object

onConnect() protected méthode

This is called when the underlying stream is connected.
protected onConnect ( ) : void
Résultat void

onData() protected méthode

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

onDeleted() protected méthode

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.
Résultat void

onDisconnect() protected méthode

This is called when the underlying stream is disconnected.
protected onDisconnect ( ) : void
Résultat void

onError() protected méthode

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

onInteraction() protected méthode

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
Résultat void

onStart() abstract protected méthode

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

onStatus() protected méthode

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.
Résultat void

onStop() protected méthode

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
Résultat void

onStopped() protected méthode

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

onWarning() protected méthode

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

stop() public méthode

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
Résultat 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