Skip to content

Commit 78629b8

Browse files
v1.6.0 Release
パーサークラス生成のカスタムコマンドを追加 Parallelクラス(SocketManager、RuntimeManager、SimpleSocket)生成のカスタムコマンドを追加
1 parent 1bbac67 commit 78629b8

12 files changed

Lines changed: 374 additions & 68 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'name' => 'parallel-runtime-manager',
5+
'description' => 'パラレルクラス(RuntimeManager用)の生成',
6+
'template' => 'template.php.tpl',
7+
'output' => 'app/ParallelClass/<%= name %>.php',
8+
];
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* ランタイムマネージャーのパラレルクラスのファイル
4+
*
5+
* REST-APIサーバーのメイン処理クラスへ渡すためのクラスファイル
6+
*/
7+
8+
namespace App\ParallelClass;
9+
10+
use SocketManager\Library\RuntimeManager;
11+
12+
13+
/**
14+
* ランタイムマネージャーのパラレルクラス
15+
*
16+
* REST-APIサーバーのメイン処理クラスへ渡すためのクラス
17+
*/
18+
class <%= name %> implements IParallelClass
19+
{
20+
/**
21+
* @var RuntimeManager ランタイムマネージャーのインスタンス
22+
*/
23+
private RuntimeManager $manager;
24+
25+
/**
26+
* コンストラクタ
27+
*
28+
* @param ?array $p_conf_param REST-APIの基本パラメータ
29+
* @param ParameterForRestApi $p_context REST-APIのコンテキストクラスのインスタンス
30+
*/
31+
public function __construct(?array $p_conf_param, $p_context)
32+
{
33+
}
34+
35+
/**
36+
* メイン処理の初期化処理
37+
*
38+
* 初期化処理の依存性注入
39+
*
40+
* @return bool true(成功) or false(失敗)
41+
*/
42+
public function initMain(): bool
43+
{
44+
// ランタイムマネージャーのインスタンス設定
45+
$this->manager = new RuntimeManager();
46+
47+
/***********************************************************************
48+
* ランタイムマネージャーの初期設定
49+
*
50+
* ランタイムUNITクラス等のインスタンスをここで設定します
51+
**********************************************************************/
52+
53+
/**
54+
* 初期化クラスの設定
55+
*
56+
* $this->manager->setInitRuntimeManager()メソッドで初期化クラスを設定します
57+
*/
58+
59+
/**
60+
* ランタイムUNITの設定
61+
*
62+
* $this->manager->setRuntimeUnits()メソッドでランタイムUNITクラスを設定します
63+
*/
64+
65+
return true;
66+
}
67+
68+
/**
69+
* 周期ドリブン処理
70+
*
71+
* イベントループへの依存性注入
72+
*
73+
* @param int $p_cycle_interval REST-APIの周期インターバルタイム(マイクロ秒)
74+
* @param int $p_alive_interval REST-APIのアライブチェックインターバルタイム(秒)
75+
* @return bool true(成功) or false(失敗)
76+
*/
77+
public function cycleDriven(int $p_cycle_interval, int $p_alive_interval): bool
78+
{
79+
// 周期ドリブン
80+
$ret = $this->manager->cycleDriven($p_cycle_interval);
81+
if($ret === false)
82+
{
83+
return false;
84+
}
85+
86+
return true;
87+
}
88+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'name' => 'parallel-simple-socket',
5+
'description' => 'パラレルクラス(SimpleSocket用)の生成',
6+
'template' => 'template.php.tpl',
7+
'output' => 'app/ParallelClass/<%= name %>.php',
8+
];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
return [
4+
'SimpleSocketTypeEnum' => 'SimpleSocketTypeEnum::UDP',
5+
'ISimpleSocket' => 'ISimpleSocketUdp'
6+
];
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* シンプルソケットのパラレルクラスのファイル
4+
*
5+
* REST-APIサーバーのメイン処理クラスへ渡すためのクラスファイル
6+
*/
7+
8+
namespace App\ParallelClass;
9+
10+
use SocketManager\Library\SimpleSocketGenerator;
11+
use SocketManager\Library\SimpleSocketTypeEnum;
12+
use SocketManager\Library\<%= ISimpleSocket %>;
13+
14+
use App\UnitParameter\ParameterForRestApi;
15+
16+
17+
/**
18+
* シンプルソケットのパラレルクラス
19+
*
20+
* REST-APIサーバーのメイン処理クラスへ渡すためのクラス
21+
*/
22+
class <%= name %> implements IParallelClass
23+
{
24+
private ParameterForRestApi $context;
25+
private SimpleSocketGenerator $generator;
26+
27+
/**
28+
* コンストラクタ
29+
*
30+
* @param ?array $p_conf_param REST-APIの基本パラメータ
31+
* @param ParameterForRestApi $p_context REST-APIのコンテキストクラスのインスタンス
32+
*/
33+
public function __construct(?array $p_conf_param, $p_context)
34+
{
35+
$this->context = $p_context;
36+
}
37+
38+
/**
39+
* メイン処理の初期化処理
40+
*
41+
* 初期化処理の依存性注入
42+
*
43+
* @return bool true(成功) or false(失敗)
44+
*/
45+
public function initMain(): bool
46+
{
47+
$this->generator = new SimpleSocketGenerator(<%= SimpleSocketTypeEnum %>, null, null, 1000);
48+
$this->generator->setUnitParameter($this->context); // REST-APIのコンテキストクラスと連携
49+
$this->generator->setKeepRunning(function(?<%= ISimpleSocket %> $p_simple_socket, $p_context)
50+
{
51+
// ここにイベントループで処理する内容を書く
52+
}, $this->context);
53+
54+
$w_ret = $this->generator->generate();
55+
if($w_ret === null)
56+
{
57+
return false;
58+
}
59+
60+
return true;
61+
}
62+
63+
/**
64+
* 周期ドリブン処理
65+
*
66+
* イベントループへの依存性注入
67+
*
68+
* @param int $p_cycle_interval REST-APIの周期インターバルタイム(マイクロ秒)
69+
* @param int $p_alive_interval REST-APIのアライブチェックインターバルタイム(秒)
70+
* @return bool true(成功) or false(失敗)
71+
*/
72+
public function cycleDriven(int $p_cycle_interval, int $p_alive_interval): bool
73+
{
74+
// 周期ドリブン
75+
$ret = $this->generator->cycleDriven($p_cycle_interval);
76+
if($ret === false)
77+
{
78+
$this->generator->shutdownAll();
79+
return false;
80+
}
81+
82+
return true;
83+
}
84+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'name' => 'parallel-socket-manager',
5+
'description' => 'パラレルクラス(SocketManager用)の生成',
6+
'template' => 'template.php.tpl',
7+
'output' => 'app/ParallelClass/<%= name %>.php',
8+
];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'port' => '20000'
5+
];
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* ソケットマネージャーのパラレルクラスのファイル
4+
*
5+
* REST-APIサーバーのメイン処理クラスへ渡すためのクラスファイル
6+
*/
7+
8+
namespace App\ParallelClass;
9+
10+
use SocketManager\Library\SocketManager;
11+
12+
13+
/**
14+
* ソケットマネージャーのパラレルクラス
15+
*
16+
* REST-APIサーバーのメイン処理クラスへ渡すためのクラス
17+
*/
18+
class <%= name %> implements IParallelClass
19+
{
20+
/**
21+
* @var SocketManager ソケットマネージャーのインスタンス
22+
*/
23+
private SocketManager $manager;
24+
25+
/**
26+
* @var ?array 基本パラメータ
27+
*/
28+
private ?array $conf_param = null;
29+
30+
/**
31+
* コンストラクタ
32+
*
33+
* @param ?array $p_conf_param REST-APIの基本パラメータ
34+
* @param ContextForSample $p_context REST-APIのコンテキストクラスのインスタンス
35+
*/
36+
public function __construct(?array $p_conf_param, $p_context)
37+
{
38+
$this->conf_param = $p_conf_param;
39+
if($p_conf_param === null)
40+
{
41+
$this->conf_param['host'] = null;
42+
}
43+
}
44+
45+
/**
46+
* メイン処理の初期化処理
47+
*
48+
* 初期化処理の依存性注入
49+
*
50+
* @return bool true(成功) or false(失敗)
51+
*/
52+
public function initMain(): bool
53+
{
54+
// ソケットマネージャーのインスタンス設定
55+
$this->manager = new SocketManager($this->conf_param['host'], <%= port %>);
56+
57+
/***********************************************************************
58+
* ソケットマネージャーの初期設定
59+
*
60+
* プロトコル/コマンド部等で実装したクラスのインスタンスをここで設定します
61+
**********************************************************************/
62+
63+
/**
64+
* 初期化クラスの設定
65+
*
66+
* $this->manager->setInitSocketManager()メソッドで初期化クラスを設定します
67+
*/
68+
69+
/**
70+
* プロトコルUNITの設定
71+
*
72+
* $this->manager->setProtocolUnits()メソッドでプロトコルUNITクラスを設定します
73+
*/
74+
75+
/**
76+
* コマンドUNITの設定
77+
*
78+
* $this->manager->setCommandUnits()メソッドでコマンドUNITクラスを設定します
79+
*/
80+
81+
/***********************************************************************
82+
* ソケットマネージャーの実行
83+
*
84+
* ポートの待ち受け処理や周期ドリブン処理を実行します
85+
**********************************************************************/
86+
87+
// リッスンポートで待ち受ける
88+
$ret = $this->manager->listen();
89+
if($ret === false)
90+
{
91+
return false; // リッスン失敗
92+
}
93+
94+
return true;
95+
}
96+
97+
/**
98+
* 周期ドリブン処理
99+
*
100+
* イベントループへの依存性注入
101+
*
102+
* @param int $p_cycle_interval REST-APIの周期インターバルタイム(マイクロ秒)
103+
* @param int $p_alive_interval REST-APIのアライブチェックインターバルタイム(秒)
104+
* @return bool true(成功) or false(失敗)
105+
*/
106+
public function cycleDriven(int $p_cycle_interval, int $p_alive_interval): bool
107+
{
108+
// 周期ドリブン
109+
$ret = $this->manager->cycleDriven($p_cycle_interval, $p_alive_interval);
110+
if($ret === false)
111+
{
112+
$this->manager->shutdownAll();
113+
return false;
114+
}
115+
116+
return true;
117+
}
118+
}

commands/parallel/command.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)