2023-02-01 19:22:26 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tamer\Interfaces;
|
|
|
|
|
2023-02-02 21:09:45 -05:00
|
|
|
use Closure;
|
2023-02-01 23:42:41 -05:00
|
|
|
use Tamer\Objects\Task;
|
|
|
|
|
2023-02-01 19:22:26 -05:00
|
|
|
interface ClientProtocolInterface
|
|
|
|
{
|
2023-02-01 23:42:41 -05:00
|
|
|
/**
|
2023-02-02 21:09:45 -05:00
|
|
|
* Public Constructor with optional username and password
|
2023-02-01 23:42:41 -05:00
|
|
|
*
|
2023-02-02 21:09:45 -05:00
|
|
|
* @param string|null $username (optional) The username to use when connecting to the server (if required)
|
|
|
|
* @param string|null $password (optional) The password to use when connecting to the server
|
2023-02-01 23:42:41 -05:00
|
|
|
*/
|
2023-02-02 21:09:45 -05:00
|
|
|
public function __construct(?string $username=null, ?string $password=null);
|
2023-02-01 23:42:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a server to the list of servers to use
|
|
|
|
*
|
|
|
|
* @param string $host The host to connect to (eg; 127.0.0.1)
|
|
|
|
* @param int $port The port to connect to (eg; 4730)
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function addServer(string $host, int $port): bool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a list of servers to the list of servers to use
|
|
|
|
*
|
|
|
|
* @param array $servers An array of servers to connect to (eg; ['host:port', 'host:port', ...])
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function addServers(array $servers): bool;
|
|
|
|
|
2023-02-02 21:09:45 -05:00
|
|
|
/**
|
|
|
|
* Adds options to the client (client specific)
|
|
|
|
*
|
|
|
|
* @param array $options
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function addOptions(array $options): bool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns True if the client is set to automatically reconnect to the server after a period of time
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isAutomaticReconnect(): bool;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enables or disables automatic reconnecting to the server after a period of time
|
|
|
|
*
|
|
|
|
* @param bool $automatic_reconnect
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setAutomaticReconnect(bool $automatic_reconnect): void;
|
|
|
|
|
2023-02-01 23:42:41 -05:00
|
|
|
/**
|
|
|
|
* Processes a task in the background (does not return a result)
|
|
|
|
*
|
|
|
|
* @param Task $task The task to process
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-02-02 21:09:45 -05:00
|
|
|
public function do(Task $task): void;
|
2023-02-01 23:42:41 -05:00
|
|
|
|
|
|
|
/**
|
2023-02-02 21:09:45 -05:00
|
|
|
* Executes a closure operation in the background (does not return a result)
|
2023-02-01 23:42:41 -05:00
|
|
|
*
|
2023-02-02 21:09:45 -05:00
|
|
|
* @param Closure $closure The closure operation to perform (remote)
|
2023-02-01 23:42:41 -05:00
|
|
|
* @return void
|
|
|
|
*/
|
2023-02-02 21:09:45 -05:00
|
|
|
public function doClosure(Closure $closure): void;
|
2023-02-01 23:42:41 -05:00
|
|
|
|
|
|
|
/**
|
2023-02-02 21:09:45 -05:00
|
|
|
* Queues a task to be processed in parallel (returns a result handled by a callback)
|
2023-02-01 23:42:41 -05:00
|
|
|
*
|
2023-02-02 21:09:45 -05:00
|
|
|
* @param Task $task
|
|
|
|
* @return void
|
2023-02-01 23:42:41 -05:00
|
|
|
*/
|
2023-02-02 21:09:45 -05:00
|
|
|
public function queue(Task $task): void;
|
2023-02-01 23:42:41 -05:00
|
|
|
|
|
|
|
/**
|
2023-02-02 21:09:45 -05:00
|
|
|
* Queues a closure to be processed in parallel (returns a result handled by a callback)
|
2023-02-01 23:42:41 -05:00
|
|
|
*
|
2023-02-02 21:09:45 -05:00
|
|
|
* @param Closure $closure The closure operation to perform (remote)
|
|
|
|
* @param Closure $callback The closure to call when the operation is complete (local)
|
|
|
|
* @return void
|
2023-02-01 23:42:41 -05:00
|
|
|
*/
|
2023-02-02 21:09:45 -05:00
|
|
|
public function queueClosure(Closure $closure, Closure $callback): void;
|
2023-02-01 19:22:26 -05:00
|
|
|
|
2023-02-01 23:42:41 -05:00
|
|
|
/**
|
2023-02-02 21:09:45 -05:00
|
|
|
* Executes all tasks in the queue and waits for them to complete
|
2023-02-01 23:42:41 -05:00
|
|
|
*
|
2023-02-02 21:09:45 -05:00
|
|
|
* @return bool
|
2023-02-01 23:42:41 -05:00
|
|
|
*/
|
2023-02-02 21:09:45 -05:00
|
|
|
public function run(): bool;
|
2023-02-01 19:22:26 -05:00
|
|
|
}
|