Skip to content

Commit 6f29708

Browse files
committed
fix connectors logic for multi-working in 1 script
1 parent f889a68 commit 6f29708

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

Connectors/Http/HttpJsonRpcConnectorAbstract.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,20 @@ public function orderNodesByTimeoutMs($orderNodesByTimeoutMs)
141141
public function getCurrentUrl()
142142
{
143143
if (
144-
!isset(static::$currentNodeURL[$this->getPlatform()])
145-
|| static::$currentNodeURL[$this->getPlatform()] === null
146-
|| !in_array(static::$currentNodeURL[$this->getPlatform()], static::$nodeURL)
144+
!isset(static::$currentNodeURL[static::class])
145+
|| static::$currentNodeURL[static::class] === null
146+
|| !in_array(static::$currentNodeURL[static::class], static::$nodeURL)
147147
) {
148148
if (is_array(static::$nodeURL)) {
149149
$url = array_values(static::$nodeURL)[0];
150150
} else {
151151
$url = static::$nodeURL;
152152
}
153153

154-
static::$currentNodeURL[$this->getPlatform()] = $url;
154+
static::$currentNodeURL[static::class] = $url;
155155
}
156156

157-
return static::$currentNodeURL[$this->getPlatform()];
157+
return static::$currentNodeURL[static::class];
158158
}
159159

160160
protected function setReserveNodeUrlToCurrentUrl()
@@ -163,9 +163,9 @@ protected function setReserveNodeUrlToCurrentUrl()
163163
foreach (static::$nodeURL as $key => $node) {
164164
if ($node === $this->getCurrentUrl()) {
165165
if ($key + 1 < $totalNodes) {
166-
static::$currentNodeURL[$this->getPlatform()] = static::$nodeURL[$key + 1];
166+
static::$currentNodeURL[static::class] = static::$nodeURL[$key + 1];
167167
} else {
168-
static::$currentNodeURL[$this->getPlatform()] = static::$nodeURL[0];
168+
static::$currentNodeURL[static::class] = static::$nodeURL[0];
169169
}
170170
break;
171171
}
@@ -174,11 +174,14 @@ protected function setReserveNodeUrlToCurrentUrl()
174174

175175
public function getCurrentId()
176176
{
177-
if (self::$currentId === null) {
178-
self::$currentId = 1;
177+
if (
178+
!isset(self::$currentId[static::class])
179+
|| self::$currentId[static::class] === null
180+
) {
181+
self::$currentId[static::class] = 1;
179182
}
180183

181-
return self::$currentId;
184+
return self::$currentId[static::class];
182185
}
183186

184187
public function getPlatform()
@@ -188,7 +191,7 @@ public function getPlatform()
188191

189192
public function setCurrentId($id)
190193
{
191-
self::$currentId = $id;
194+
self::$currentId[static::class] = $id;
192195
}
193196

194197
public function getNextId()

Connectors/WebSocket/WSConnectorAbstract.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ abstract class WSConnectorAbstract implements ConnectorInterface
5353
*/
5454
protected $maxNumberOfTriesToCallApi = 3;
5555

56+
/**
57+
* list of connectors by connector name
58+
* @var Client[]
59+
*/
5660
protected static $connection;
5761
protected static $currentId;
5862

@@ -150,11 +154,14 @@ public function orderNodesByTimeout($orderNodesByTimeout)
150154
*/
151155
public function getConnection()
152156
{
153-
if (self::$connection === null) {
157+
if (
158+
!isset(self::$connection[static::class])
159+
|| self::$connection[static::class] === null
160+
) {
154161
$this->newConnection($this->getCurrentUrl());
155162
}
156163

157-
return self::$connection;
164+
return self::$connection[static::class];
158165
}
159166

160167
/**
@@ -164,17 +171,17 @@ public function getConnection()
164171
*/
165172
public function newConnection($nodeUrl)
166173
{
167-
self::$connection = new Client($nodeUrl, ['timeout' => $this->wsTimeoutSeconds]);
174+
self::$connection[static::class] = new Client($nodeUrl, ['timeout' => $this->wsTimeoutSeconds]);
168175

169-
return self::$connection;
176+
return self::$connection[static::class];
170177
}
171178

172179
public function getCurrentUrl()
173180
{
174181
if (
175-
!isset(static::$currentNodeURL[$this->getPlatform()])
176-
|| static::$currentNodeURL[$this->getPlatform()] === null
177-
|| !in_array(static::$currentNodeURL[$this->getPlatform()], static::$nodeURL)
182+
!isset(static::$currentNodeURL[static::class])
183+
|| static::$currentNodeURL[static::class] === null
184+
|| !in_array(static::$currentNodeURL[static::class], static::$nodeURL)
178185
) {
179186
if (is_array(static::$nodeURL)) {
180187
$this->reserveNodeUrlList = static::$nodeURL;
@@ -183,10 +190,10 @@ public function getCurrentUrl()
183190
$url = static::$nodeURL;
184191
}
185192

186-
static::$currentNodeURL[$this->getPlatform()] = $url;
193+
static::$currentNodeURL[static::class] = $url;
187194
}
188195

189-
return static::$currentNodeURL[$this->getPlatform()];
196+
return static::$currentNodeURL[static::class];
190197
}
191198

192199
public function isExistReserveNodeUrl()
@@ -196,7 +203,7 @@ public function isExistReserveNodeUrl()
196203

197204
protected function setReserveNodeUrlToCurrentUrl()
198205
{
199-
static::$currentNodeURL[$this->getPlatform()] = array_shift($this->reserveNodeUrlList);
206+
static::$currentNodeURL[static::class] = array_shift($this->reserveNodeUrlList);
200207
}
201208

202209
public function connectToReserveNode()
@@ -211,11 +218,14 @@ public function connectToReserveNode()
211218

212219
public function getCurrentId()
213220
{
214-
if (self::$currentId === null) {
215-
self::$currentId = 1;
221+
if (
222+
!isset(self::$currentId[static::class])
223+
|| self::$currentId[static::class] === null
224+
) {
225+
self::$currentId[static::class] = 1;
216226
}
217227

218-
return self::$currentId;
228+
return self::$currentId[static::class];
219229
}
220230

221231
public function getPlatform()
@@ -225,7 +235,7 @@ public function getPlatform()
225235

226236
public function setCurrentId($id)
227237
{
228-
self::$currentId = $id;
238+
self::$currentId[static::class] = $id;
229239
}
230240

231241
public function getNextId()

0 commit comments

Comments
 (0)