* @return $isNewPeer Whether 'sender' is a new peer to this peer
*/
public function isSenderNewPeer (DeliverablePackage $packageInstance, StoreableCriteria $dataSetInstance = NULL) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: packageInstance=' . $packageInstance . ' - CALLED!');
-
// Get a search criteria instance from package data
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: packageInstance=' . $packageInstance . ' - CALLED!');
$searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageInstance);
// Is the dataset instance set?
/**
* Registers the given peer state and An instance of a DeliverablePackage class
*
- * @param $stateInstance A PeerStateable class instance
+ * @param $stateInstance An instance of a PeerStateable class
* @param $packageInstance An instance of a DeliverablePackage class
* @return void
* @throws PeerAlreadyRegisteredException If a peer is already registered
* @throws UnexpectedValueException If $resultInstance->next() returns FALSE
*/
public function isSamePeerState (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...');
-
// Now get the search instance from given package data
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...');
$searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageInstance);
// With this search instance query the database for the peer and get a result instance
* @param $helperInstance An instance of a ConnectionHelper class
* @param $packageInstance An instance of a DeliverablePackage class
* @param $socketInstance An instance of a StorableSocket class
- * @param $errorCode The last error code
+ * @param $errorName Error code in text form
* @return $stateInstance A Stateable class instance
*/
- public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance, StorableSocket $socketInstance, $errorCode) {
+ public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance, StorableSocket $socketInstance, string $errorName) {
// Error code and helper's state name should not be the same
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: helperInstance=%s,packageInstance=%s,socketInstance=%s,errorCode=%s - CALLED!', $helperInstance->__toString(), $packageInstance->__toString(), $socketInstance->__toString(), $errorCode));
- if ($errorCode == $helperInstance->getPrintableState()) {
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: helperInstance=%s,packageInstance=%s,socketInstance=%s,errorName=%s - CALLED!', $helperInstance->__toString(), $packageInstance->__toString(), $socketInstance->__toString(), $errorName));
+ if (empty($errorName)) {
+ // Empty parameter
+ throw new InvalidArgumentException('Parameter "errorName" is empty');
+ } elseif ($errorName == $helperInstance->getPrintableState()) {
// Not valid!
- throw new InvalidArgumentException(sprintf('Current state and errorCode=%s are the same.', $errorCode));
+ throw new InvalidArgumentException(sprintf('Current state and errorName=%s are the same.', $errorName));
}
// Init state instance, this is better coding practice
// Do we have an entry?
if ($tableInstance->isSenderNewPeer($packageInstance)) {
- // Debug output
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: errorCode=' . $errorCode);
-
// Register the new peer with its session id
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: errorName=' . $errorName);
$tableInstance->registerPeerByPackageInstance($packageInstance, $socketInstance);
/*
* It is a new peer so create the state instance based on error
* code and get an instance from it.
*/
- $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
+ $stateInstance = self::createObjectByConfiguredName('peer_' . $errorName . '_state_class');
// And register it with the lookup table
$tableInstance->registerPeerState($stateInstance, $packageInstance);
} elseif ($tableInstance->isSamePeerState($helperInstance, $packageInstance)) {
- // Debug output
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Peer state unchanged, re-generating old state ...');
-
/*
* The peer's state has noot changed, still we have to return a
* state instance, so generate it here.
*/
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Peer state unchanged, re-generating old state ...');
$stateInstance = self::createPeerStateInstanceByName($helperInstance->getPrintableState(), $helperInstance);
} else {
- // Debug output
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Updating peer state ...');
-
/*
* It is an already known peer but with a changed state. So first
* get an instance of the state.
*/
- $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Updating peer state ...');
+ $stateInstance = self::createObjectByConfiguredName(sprintf('peer_%s_state_class', $errorName));
// The peer's state has changed, update database now
$tableInstance->registerPeerState($stateInstance, $packageInstance);
}
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
-
// Set the state in the helper
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: Peer state has changed from %s to %s (%s).', $helperInstance->getPrintableState(), $stateInstance->getStateName(), $stateInstance->__toString()));
$helperInstance->setStateInstance($stateInstance);
// For any purposes, return the state instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: stateInstance=%s - EXIT!', $stateInstance->__toString()));
return $stateInstance;
}
* @param $helperInstance A ConnectionHelper class instance
* @return $stateInstance A Stateable class instance
*/
- public static final function createPeerStateInstanceByName ($stateName, ConnectionHelper $helperInstance) {
- // Get a class from a configuration entry
- $stateInstance = self::createObjectByConfiguredName('peer_' . $stateName . '_state_class', array($helperInstance));
+ public static final function createPeerStateInstanceByName (string $stateName, ConnectionHelper $helperInstance) {
+ // Validate parameter
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: stateName=%s,helperInstance=%s - CALLED!', $stateName, $helperInstance->__toString()));
+ if (empty($stateName)) {
+ // Empty parameter
+ throw new InvalidArgumentException('Parameter "stateName" is empty');
+ }
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Peer state has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . ' (' . $stateInstance->__toString() . ').');
+ // Get a class from a configuration entry
+ $stateInstance = self::createObjectByConfiguredName(sprintf('peer_%s_state_class', $stateName), array($helperInstance));
// Once we have that state, set it in the peer instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: Peer state has changed from %s to %s (%s).', $helperInstance->getPrintableState(), $stateInstance->getStateName(), $stateInstance->__toString()));
$helperInstance->setStateInstance($stateInstance);
// For any purposes, return the state instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PEER-STATE-FACTORY: stateInstance=%s - EXIT!', $stateInstance->__toString()));
return $stateInstance;
}