import { ExternalSystem } from "../external/ExternalSystem";
import { ParallelSystemArray } from "./ParallelSystemArray";
import { IClientDriver } from "../../protocol/communicator/IClientDriver";
import { InvokeHistory } from "../slave/InvokeHistory";
import { Invoke } from "../../protocol/invoke/Invoke";
import { XML } from "sxml";
/**
* A driver for a parallel slave system.
*
* The {@link ParallelSystem} is an abstract class represents a **slave** system in *Parallel Processing System*,
* connected with this **master** system. This {@link ParallelSystem} takes full charge of network communication with
* the remote, parallel **slave** system has connected.
*
* When a *parallel process* is requested (by {@link ParallelSystemArray.sendSegmentData} or
* {@link ParallelSystemArray.sendPieceData}), the number of pieces to be allocated to a {@link ParallelSystem} is
* turn on its {@link getPerformance performance index}. Higher {@link getPerformance performance index}, then
* more pieces are requested. The {@link getPerformance performance index} is revaluated whenever a *parallel process*
* has completed, basic on the execution time and number of pieces. You can sugguest or enforce the
* {@link getPerformance performance index} with {@link setPerformance} or {@link enforcePerformance}.
*
*
*
*
*
* #### Bridge & Proxy Pattern
* This class {@link ParallelSystem} is derived from the {@link ExternalSystem} class. Thus, you can take advantage
* of the *Bridge & Proxy Pattern* in this {@link ParallelSystem} class. If a process to request is not the
* *parallel process* (to be distrubted to all slaves), but the **exclusive process** handled in a system, then it
* may better to utilizing the *Bridge & Proxy Pattern*:
*
* The {@link ExternalSystem} class can be a *bridge* for *logical proxy*. In framework within user,
* which {@link ExternalSystem external system} is connected with {@link ExternalSystemArray this system}, it's not
* important. Only interested in user's perspective is *which can be done*.
*
* By using the *logical proxy*, user dont't need to know which {@link ExternalSystemRole role} is belonged
* to which {@link ExternalSystem system}. Just access to a role directly from {@link ExternalSystemArray.getRole}.
* Sends and receives {@link Invoke} message via the {@link ExternalSystemRole role}.
*
*
* -
* {@link ExternalSystemRole} can be accessed from {@link ExternalSystemArray} directly, without inteferring
* from {@link ExternalSystem}, with {@link ExternalSystemArray.getRole}.
*
* -
* When you want to send an {@link Invoke} message to the belonged {@link ExternalSystem system}, just call
* {@link ExternalSystemRole.sendData ExternalSystemRole.sendData()}. Then, the message will be sent to the
* external system.
*
* - Those strategy is called *Bridge Pattern* and *Proxy Pattern*.
*
*
* @handbook [Templates - Parallel System](https://github.com/samchon/framework/wiki/TypeScript-Templates-Parallel_System)
* @author Jeongho Nam
*/
export declare abstract class ParallelSystem extends ExternalSystem {
/**
* @hidden
*/
private progress_list_;
/**
* @hidden
*/
private history_list_;
/**
* @hidden
*/
private exclude_;
/**
* @hidden
*/
private performance;
/**
* @hidden
*/
private enforced_;
/**
* Construct from parent {@link ParallelSystemArray}.
*
* @param systemArray The parent {@link ParallelSystemArray} object.
*/
constructor(systemArray: ParallelSystemArray);
/**
* Construct from parent {@link ParallelSystemArray} and communicator.
*
* @param systemArray The parent {@link ParallelSystemArray} object.
* @param communicator A communicator communicates with remote, the external system.
*/
constructor(systemArray: ParallelSystemArray, communicator: IClientDriver);
/**
* Default Destructor.
*
* This {@link destructor destructor()} method is called when the {@link ParallelSystem} object is destructed and
* the {@link ParallelSystem} object is destructed when connection with the remote system is closed or this
* {@link ParallelSystem} object is {@link ParallelSystemArray.erase erased} from its parent
* {@link ParallelSystemArray} object.
*
* You may think if there're some *parallel processes* have requested but not completed yet, then it would be a
* critical problem because the *parallel processes* will not complete forever. Do not worry. The critical problem
* does not happen. After the destruction, the remained *parallel processes* will be shifted to and proceeded in
* other {@link ParallelSystem} objects.
*
* Note that, don't call this {@link destructor destructor()} method by yourself. It must be called automatically
* by those *destruction* cases. Also, if your derived {@link ParallelSystem} class has something to do on the
* *destruction*, then overrides this {@link destructor destructor()} method and defines the something to do.
* Overriding this {@link destructor destructor()}, don't forget to calling ```super.destructor();``` on tail.
*
* ```typescript
* class SomeSystem extends ExternalSystem
* {
* protected destructor(): void
* {
* // DO SOMETHING
* this.do_something();
*
* // CALL SUPER.DESTRUCTOR() ON TAIL. DON'T FORGET THIS
* super.destructor();
* }
* }
* ```
*/
protected destructor(): void;
/**
* Get manager of this object.
*
* @return The parent {@link ParallelSystemArray} object.
*/
getSystemArray(): ParallelSystemArray;
/**
* Get manager of this object.
*
* @return The parent {@link ParallelSystemArray} object.
*/
getSystemArray>(): SystemArray;
/**
* Get performance index.
*
* Get *performance index* that indicates how much fast the remote system is.
*
* If this {@link ParallelSystem parallel system} does not have any {@link Invoke} message had handled, then the
* *performance index* will be ```1.0```, which means default and average value between all {@link ParallelSystem}
* instances (that are belonged to a same {@link ParallelSystemArray} object).
*
* You can specify this *performance index* by yourself but notice that, if the *performance index* is higher
* than other {@link ParallelSystem} objects, then this {@link ParallelSystem parallel system} will be ordered to
* handle more processes than other {@link ParallelSystem} objects. Otherwise, the *performance index* is lower
* than others, of course, less processes will be delivered.
*
* - {@link setPerformance setPerformance()}
* - {@link enforcePerformance enforcePerformance()}
*
* Unless {@link enforcePerformance enforcePerformance()} is called, This *performance index* is **revaluated**
* whenever user calls one of them below.
*
* - {@link ParallelSystemArray.sendSegmentData ParallelSystemArray.sendSegmentData()}
* - {@link ParallelSystemArray.sendPieceData ParallelSystemArray.sendPieceData()}
* - {@link DistributedProcess.sendData DistributedProcess.sendData()}.
*
* @return Performance index.
*/
getPerformance(): number;
/**
* Set performance index.
*
* Set *performance index* that indicates how much fast the remote system is. This *performance index* can be
* **revaulated**.
*
* Note that, initial and average *performance index* of {@link ParallelSystem} objects are ```1.0```. If the
* *performance index* is higher than other {@link ParallelSystem} objects, then this {@link ParallelSystem} will
* be ordered to handle more processes than other {@link ParallelSystem} objects. Otherwise, the
* *performance index* is lower than others, of course, less processes will be delivered.
*
* Unlike {@link enforcePerformance}, configuring *performance index* by this {@link setPerformance} allows
* **revaluation**. This **revaluation** prevents wrong valuation from user. For example, you *mis-valuated* the
* *performance index*. The remote system is much faster than any other, but you estimated it to the slowest one.
* It looks like a terrible case that causes {@link ParallelSystemArray entire parallel systems} to be slower,
* however, don't mind. The system will direct to the *propriate performance index* eventually with the
* **revaluation** by following methods.
*
* - {@link ParallelSystemArray.sendSegmentData ParallelSystemArray.sendSegmentData()}
* - {@link ParallelSystemArray.sendPieceData ParallelSystemArray.sendPieceData()}
* - {@link DistributedProcess.sendData DistributedProcess.sendData()}.
*
* @param val New performance index, but can be revaluated.
*/
setPerformance(val: number): void;
/**
* Enforce performance index.
*
* Enforce *performance index* that indicates how much fast the remote system is. The *performance index* will be
* fixed, never be **revaluated**.
*
* Note that, initial and average *performance index* of {@link ParallelSystem} objects are ```1.0```. If the
* *performance index* is higher than other {@link ParallelSystem} objects, then this {@link ParallelSystem} will
* be ordered to handle more processes than other {@link ParallelSystem} objects. Otherwise, the
* *performance index* is lower than others, of course, less processes will be delivered.
*
* The difference between {@link setPerformance} and this {@link enforcePerformance} is allowing **revaluation**
* or not. This {@link enforcePerformance} does not allow the **revaluation**. The *performance index* is clearly
* fixed and never be changed by the **revaluation**. But you've to keep in mind that, you can't avoid the
* **mis-valuation** with this {@link enforcePerformance}.
*
* For example, there's a remote system much faster than any other, but you **mis-estimated** it to the slowest.
* In that case, there's no way. The {@link ParallelSystemArray entire parallel systems} will be slower by the
* **mis-valuation**. By the reason, using {@link enforcePerformance}, it's recommended only when you can clearly
* certain the *performance index*. If you can't certain the *performance index* but want to recommend, then use
* {@link setPerformance} instead.
*
* @param val New performance index to be fixed.
*/
enforcePerformance(val: number): void;
/**
* @hidden
*/
private _Send_piece_data;
/**
* @hidden
*/
private _Reply_data;
/**
* @hidden
*/
protected _Report_history(xml: XML): void;
/**
* @hidden
*/
protected _Send_back_history(invoke: Invoke, history: InvokeHistory): void;
}