PHP Interface Kraken\Channel\ChannelInterface

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

Public Methods

Method 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 method

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
return Kraken\Channel\Protocol\ProtocolInterface

filterConnected() public method

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

getConnected() public method

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

getInput() public method

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

getModel() public method

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

getName() public method

Return Channel name.
public getName ( ) : string
return string

getOutput() public method

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

getRouter() public method

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

isConnected() public method

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

isStarted() public method

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

isStopped() public method

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

onConnect() public method

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

onDisconnect() public method

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

onInput() public method

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

onOutput() public method

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

onStart() public method

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

onStop() public method

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

pull() public method

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 method

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
return Kraken\Channel\Record\RequestRecord | Kraken\Channel\Record\RequestRecord[] | null | null[] | boolean | bool[]

pushAsync() public method

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
return boolean | bool[]

pushRequest() public method

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
return Kraken\Channel\Record\RequestRecord | Kraken\Channel\Record\RequestRecord[] | null | null[]

receive() public method

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 method

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
return mixed | mixed[]

sendAsync() public method

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
return boolean | bool[]

sendRequest() public method

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
return boolean | bool[]

start() public method

Start channel.
public start ( )

stop() public method

Stop channel.
public stop ( )