HCE Project PHP language client API bindings OOP style  1.1.1
Hierarchical Cluster Engine PHP Client Interface API OOP style
 All Classes Namespaces Files Functions Variables Pages
NodeManageRequest.inc.php
Go to the documentation of this file.
1 <?php
2 
14 namespace HCE\admin {
15 
16  require_once __DIR__ . '/../transport/Constants.inc.php';
17  require_once __DIR__ . '/../transport/Connection.inc.php';
18  require_once __DIR__ . '/../transport/Request.inc.php';
19 
20  require_once 'Constants.inc.php';
21  require_once 'Node.inc.php';
22  require_once 'NodeCommand.inc.php';
23  require_once 'NodeManageResponse.inc.php';
24 
32  protected $transportRequest = NULL;
33 
37  protected $transportConnection = NULL;
38 
42  protected $error = 0;
43 
51  public function setErrorCode($errorCode) {
52  $this->error = $errorCode;
53  }
54 
60  public function getErrorCode() {
61  return $this->error;
62  }
63 
73  public function __construct($transportConnection = null, $transportRequest = null) {
74  // Init transport connection
75  $this->transportConnection = $transportConnection;
76 
77  // Init transport request
78  $this->transportRequest = $transportRequest;
79  }
80 
84  public function __destruct() {
85  $this->transportRequest = NULL;
86  $this->transportConnection = NULL;
87  }
88 
100  public function execute($command, $node) {
101  // Make $NodeManageResponse object instance to return
102  $nodeManageResponseObject = new \HCE\admin\NodeManageResponse ();
103 
104  // Create connection with default initialization
105  $connection = new \HCE\transport\Connection ();
106  if (! $connection->error) {
107  // Set connection properties
108  $connection->host = $node->getHost ();
109  $connection->port = $node->getPort ();
110  // Create request with default initialization
111  $request = new \HCE\transport\Request ( $connection );
112  if (! $request->getErrorCode ()) {
113  // Try to open connection
114  if ($connection->open ()) {
115  // Execute request
116  $response = $request->execute ( $command->getMessageBody (), $node->getTimeout () );
117  // Check transport request state
118  if ($response->getErrorCode ()) {
119  // Error of transport request execution
120  $nodeManageResponseObject->setErrorCode ( ERROR_TRANSPORT_REQUEST );
121  }
122  // Set transport response
123  $nodeManageResponseObject->setResponse ( $response );
124  // Close connection
125  $connection->close ();
126  } else {
127  // Error open connection
128  $nodeManageResponseObject->setErrorCode ( ERROR_CONNECTION_OPEN );
129  }
130  } else {
131  // Error create request object
132  $nodeManageResponseObject->setErrorCode ( ERROR_REQUEST_CREATE );
133  }
134  } else {
135  // Error create connection object
136  $nodeManageResponseObject->setErrorCode ( ERROR_CONNECTION_CREATE );
137  }
138 
139  return $nodeManageResponseObject;
140  }
141  }
142 }
143 
144 ?>