14 namespace HCE\transport {
16 require_once
'zmsg.php';
17 require_once
'Constants.inc.php';
18 require_once
'IdGenerator.inc.php';
27 protected $connectionArray = array ();
36 $this->connectionArray = $connectionArray;
45 return $this->connectionArray;
56 return $this->connectionArray [$name];
70 'error' => PROTOCOL_ERROR_OK,
80 if ($connectionArray === NULL) {
82 'host' => PROTOCOL_HOST_DEFAULT,
83 'port' => PROTOCOL_PORT_ADMIN_DEFAULT,
84 'type' => PROTOCOL_CONNECTION_TYPE_ADMIN,
88 if (! isset ( $connectionArray [
'host'] ) || ! isset ( $connectionArray [
'port'] ) || ! isset ( $connectionArray [
'type'] ) || ! isset ( $connectionArray [
'identity'] )) {
89 $ret [
'error'] = PROTOCOL_ERROR_CONNECTION_PARAMS;
91 $con_ar = $connectionArray;
96 if ($ret [
'error'] == PROTOCOL_ERROR_OK) {
98 $ret [
'context'] = new \ZMQContext ();
99 if ($ret [
'context'] == NULL) {
100 $ret [
'error'] = PROTOCOL_ERROR_CONTEXT_CREATE;
103 $ret [
'socket'] = new \ZMQSocket ( $ret [
'context'], \ZMQ::SOCKET_DEALER );
104 if ($ret [
'socket'] === NULL) {
105 $ret [
'error'] = PROTOCOL_ERROR_SOCKET_CREATE;
108 $ret [
'socket']->setSockOpt ( \ZMQ::SOCKOPT_IDENTITY, $con_ar [
'identity'] );
109 if ($con_ar [
'type'] == PROTOCOL_CONNECTION_TYPE_ADMIN) {
111 $ret [
'socket']->setSockOpt ( \ZMQ::SOCKOPT_LINGER, 0 );
115 $ret [
'host'] = $con_ar [
'host'];
116 $ret [
'port'] = $con_ar [
'port'];
117 $ret [
'type'] = $con_ar [
'type'];
118 $ret [
'identity'] = $con_ar [
'identity'];
124 $this->setConnectionArray ( $ret );
134 return $this->connectionArray [
'socket']->connect ( $this->getDSN () );
143 return $this->connectionArray [
'socket']->disconnect ( $this->getDSN () );
152 $this->connectionArray [
'socket']->disconnect ( $this->getDSN () );
153 return $this->connectionArray [
'socket']->connect ();
161 public function getDSN($protocol = PROTOCOL_ADMIN_DEFAULT) {
162 return $protocol .
'://' . $this->connectionArray [
'host'] .
':' . $this->connectionArray [
'port'];
170 $this->connectionArray [
'context'] = NULL;
171 $this->connectionArray [
'socket'] = NULL;
172 $this->connectionArray [
'host'] = NULL;
173 $this->connectionArray [
'port'] = NULL;
174 $this->connectionArray [
'type'] = NULL;
175 $this->connectionArray [
'identity'] = NULL;