PHP Interface Kraken\Channel\ChannelInterface

Inheritance: extends Kraken\Event\EventEmitterInterface, extends Kraken\Loop\LoopAwareInterface
Afficher le fichier Open project: kraken-php/framework Interface Usage Examples

Méthodes publiques

Méthode Description
createProtocol ( string | string[] | null $message = null ) : Kraken\Channel\Protocol\ProtocolInterface Put message into newly created protocol and return its wrapper.
filterConnected ( string | string[] $pattern ) : string[] Return array of all connected channels' IDs that matches pattern
getConnected ( ) : string[] Return array of all connected external channels' IDs.
getInput ( ) : Kraken\Channel\Router\RouterInterface | Kraken\Channel\Router\RouterCompositeInterface Return router used for input messages.
getModel ( ) : Kraken\Channel\ChannelModelInterface | null Return model which is being used by Channel.
getName ( ) : string Return Channel name.
getOutput ( ) : Kraken\Channel\Router\RouterInterface | Kraken\Channel\Router\RouterCompositeInterface Return router used for output messages.
getRouter ( ) : Kraken\Channel\Router\RouterCompositeInterface Return router which is being used by Channel.
isConnected ( string | string[] $name ) : boolean | bool[] Check if specific external channel is connected.
isStarted ( ) : boolean | bool[] Check if channel is started.
isStopped ( ) : boolean | bool[] Check if channel is stopped.
onConnect ( callable $handler ) : EventListener Attach connect event handler.
onDisconnect ( callable $handler ) : EventListener Attach disconnect event handler.
onInput ( callable $handler ) : EventListener Attach input event handler.
onOutput ( callable $handler ) : EventListener Attach output event handler.
onStart ( callable $handler ) : EventListener Attach start event handler.
onStop ( callable $handler ) : EventListener Attach stop event handler.
pull ( string $sender, Kraken\Channel\Protocol\ProtocolInterface $protocol ) Pull message from sender.
push ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : RequestRecord | RequestRecord[] | null | null[] | boolean | bool[] Push one or multiple messages to one or more receivers.
pushAsync ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT ) : boolean | bool[] Push one or multiple asynchronous messages to one or more receivers.
pushRequest ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : RequestRecord | RequestRecord[] | null | null[] Push one or multiple requests to one or more receivers.
receive ( string $sender, Kraken\Channel\Protocol\ProtocolInterface $protocol ) Receive message from sender.
send ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : mixed | mixed[] Send one or multiple messages to one or more receivers.
sendAsync ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT ) : boolean | bool[] Send one or multiple asynchronous messages to one or more receivers.
sendRequest ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : boolean | bool[] Send one or multiple requests to one or more receivers.
start ( ) Start channel.
stop ( ) Stop channel.

Method Details

createProtocol() public méthode

Put message into newly created protocol and return its wrapper.
public createProtocol ( string | string[] | null $message = null ) : Kraken\Channel\Protocol\ProtocolInterface
$message string | string[] | null
Résultat Kraken\Channel\Protocol\ProtocolInterface

filterConnected() public méthode

Return array of all connected channels' IDs that matches pattern
public filterConnected ( string | string[] $pattern ) : string[]
$pattern string | string[]
Résultat string[]

getConnected() public méthode

Return array of all connected external channels' IDs.
public getConnected ( ) : string[]
Résultat string[]

getInput() public méthode

Throws ResourceUndefinedException if input router is not found.
public getInput ( ) : Kraken\Channel\Router\RouterInterface | Kraken\Channel\Router\RouterCompositeInterface
Résultat Kraken\Channel\Router\RouterInterface | Kraken\Channel\Router\RouterCompositeInterface

getModel() public méthode

Return model which is being used by Channel.
public getModel ( ) : Kraken\Channel\ChannelModelInterface | null
Résultat Kraken\Channel\ChannelModelInterface | null

getName() public méthode

Return Channel name.
public getName ( ) : string
Résultat string

getOutput() public méthode

Throws ResourceUndefinedException if output router is not found.
public getOutput ( ) : Kraken\Channel\Router\RouterInterface | Kraken\Channel\Router\RouterCompositeInterface
Résultat Kraken\Channel\Router\RouterInterface | Kraken\Channel\Router\RouterCompositeInterface

getRouter() public méthode

Return router which is being used by Channel.
public getRouter ( ) : Kraken\Channel\Router\RouterCompositeInterface
Résultat Kraken\Channel\Router\RouterCompositeInterface

isConnected() public méthode

Check if specific external channel is connected.
public isConnected ( string | string[] $name ) : boolean | bool[]
$name string | string[]
Résultat boolean | bool[]

isStarted() public méthode

Check if channel is started.
public isStarted ( ) : boolean | bool[]
Résultat boolean | bool[]

isStopped() public méthode

Check if channel is stopped.
public isStopped ( ) : boolean | bool[]
Résultat boolean | bool[]

onConnect() public méthode

Attach connect event handler.
public onConnect ( callable $handler ) : EventListener
$handler callable
Résultat Kraken\Event\EventListener

onDisconnect() public méthode

Attach disconnect event handler.
public onDisconnect ( callable $handler ) : EventListener
$handler callable
Résultat Kraken\Event\EventListener

onInput() public méthode

Attach input event handler.
public onInput ( callable $handler ) : EventListener
$handler callable
Résultat Kraken\Event\EventListener

onOutput() public méthode

Attach output event handler.
public onOutput ( callable $handler ) : EventListener
$handler callable
Résultat Kraken\Event\EventListener

onStart() public méthode

Attach start event handler.
public onStart ( callable $handler ) : EventListener
$handler callable
Résultat Kraken\Event\EventListener

onStop() public méthode

Attach stop event handler.
public onStop ( callable $handler ) : EventListener
$handler callable
Résultat Kraken\Event\EventListener

pull() public méthode

This method pulls message immediataly processing it without router usage.
public pull ( string $sender, Kraken\Channel\Protocol\ProtocolInterface $protocol )
$sender string
$protocol Kraken\Channel\Protocol\ProtocolInterface

push() public méthode

In comparison to send() method skips routing mechanisms and tries to push message directly to receiver, therefore this method should be used with caution. This method will push multiple messages separately. If any of the callback handlers are set, then message(s) will be treated as Request(s) and Channel will asynchronously await response(s). On the other hand, if none are set, then message(s) will be send without creating handler making the process faster and better memory-optimized. However, in that case Channel will not be able to process any returned values. Timeout works only for requests and represents number of seconds after which handler will automatically cancel. Flags might be one of: Channel::MODE_STANDARD - sends message if both sender and receiver are online. Channel::MODE_BUFFER_OFFLINE - works in similar way as MODE_STANDARD, but also enables buffering messages in case that sender is offline. Channel::MODE_BUFFER_ONLINE - works in similar way as MODE_STANDARD, but also enables buffering messages in case that receiver is offline. Channel::MODE_BUFFER - sends message if both sender and receiver are online or buffers it if one of them is offline.
public push ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : RequestRecord | RequestRecord[] | null | null[] | boolean | bool[]
$name string | string[]
$message string | string[] | Kraken\Channel\Protocol\ProtocolInterface
$flags integer
$success callable
$failure callable
$cancel callable
$timeout float
Résultat Kraken\Channel\Record\RequestRecord | Kraken\Channel\Record\RequestRecord[] | null | null[] | boolean | bool[]

pushAsync() public méthode

This method only enables pushing asynchronous messages. For more complex options use push() method.
See also: ChannelInterface::push
public pushAsync ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT ) : boolean | bool[]
$name string | string[]
$message string | string[] | Kraken\Channel\Protocol\ProtocolInterface
$flags integer
Résultat boolean | bool[]

pushRequest() public méthode

This method only enables pushing requests. For more complex options use push() method.
See also: ChannelInterface::push
public pushRequest ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : RequestRecord | RequestRecord[] | null | null[]
$name string | string[]
$message string | string[] | Kraken\Channel\Protocol\ProtocolInterface
$flags integer
$success callable
$failure callable
$cancel callable
$timeout float
Résultat Kraken\Channel\Record\RequestRecord | Kraken\Channel\Record\RequestRecord[] | null | null[]

receive() public méthode

This method uses Channel input router to validate the message and then process or do something else with it depending on router rules.
public receive ( string $sender, Kraken\Channel\Protocol\ProtocolInterface $protocol )
$sender string
$protocol Kraken\Channel\Protocol\ProtocolInterface

send() public méthode

In comparison to push() method, this one sends messages first to output router that decides how to handle them. This method will send multiple messages separately. If any of the callback handlers are set, then message(s) will be treated as Request(s) and Channel will asynchronously await response(s). On the other hand, if none are set, then message(s) will be send without creating handler making the process faster and better memory-optimized. However, in that case Channel will not be able to process any returned values. Timeout works only for requests and represents number of seconds after which handler will automatically cancel. Flags might be one of: Channel::MODE_STANDARD - sends message if both sender and receiver are online. Channel::MODE_BUFFER_OFFLINE - works in similar way as MODE_STANDARD, but also enables buffering messages in case that sender is offline. Channel::MODE_BUFFER_ONLINE - works in similar way as MODE_STANDARD, but also enables buffering messages in case that receiver is offline. Channel::MODE_BUFFER - sends message if both sender and receiver are online or buffers it if one of them is offline.
See also: ChannelInterface::sendAsync
See also: ChannelInterface::sendRequest
public send ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : mixed | mixed[]
$name string | string[]
$message string | string[] | Kraken\Channel\Protocol\ProtocolInterface
$flags integer
$success callable
$failure callable
$cancel callable
$timeout float
Résultat mixed | mixed[]

sendAsync() public méthode

This method only enables sending asynchronous messages. For more complex options use send() method.
See also: ChannelInterface::send
public sendAsync ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT ) : boolean | bool[]
$name string | string[]
$message string | string[] | Kraken\Channel\Protocol\ProtocolInterface
$flags integer
Résultat boolean | bool[]

sendRequest() public méthode

This method only enables sending requests. For more complex options use send() method.
See also: ChannelInterface::send
public sendRequest ( string | string[] $name, string | string[] | Kraken\Channel\Protocol\ProtocolInterface $message, integer $flags = Channel::MODE_DEFAULT, callable $success = null, callable $failure = null, callable $cancel = null, float $timeout ) : boolean | bool[]
$name string | string[]
$message string | string[] | Kraken\Channel\Protocol\ProtocolInterface
$flags integer
$success callable
$failure callable
$cancel callable
$timeout float
Résultat boolean | bool[]

start() public méthode

Start channel.
public start ( )

stop() public méthode

Stop channel.
public stop ( )