pbesa 2.1__py3-none-any.whl → 4.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pbesa/__init__.py +4 -3
- pbesa/cognitive.py +475 -0
- pbesa/kernel/__init__.py +4 -6
- pbesa/kernel/adapter.py +165 -0
- pbesa/kernel/agent.py +558 -0
- pbesa/kernel/io/__init__.py +2 -2
- pbesa/kernel/io/system_file.py +38 -0
- pbesa/kernel/io/tcp_server.py +23 -0
- pbesa/kernel/util.py +217 -0
- pbesa/kernel/world.py +43 -0
- pbesa/mas.py +565 -0
- pbesa/remote/__init__.py +5 -0
- pbesa/remote/adm_listener.py +44 -0
- pbesa/{middleware/remote/AdmListenerHandler.py → remote/adm_listener_handler.py} +74 -57
- pbesa/remote/exceptions.py +18 -0
- pbesa/remote/remote_adm.py +42 -0
- pbesa/{middleware/remote/RemoteAdmHandler.py → remote/remote_adm_handler.py} +109 -83
- pbesa/social/__init__.py +4 -0
- pbesa/social/collaborative_team.py +299 -0
- pbesa/social/delegator.py +81 -0
- pbesa/social/delegator_team.py +334 -0
- pbesa/social/dialog.py +153 -0
- pbesa/social/dispatcher_team.py +319 -0
- pbesa/social/templates.py +18 -0
- pbesa/social/worker.py +188 -0
- {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE +21 -21
- {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE.txt +21 -21
- pbesa-4.0.0.dist-info/METADATA +8 -0
- pbesa-4.0.0.dist-info/RECORD +32 -0
- {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/WHEEL +5 -5
- {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/top_level.txt +0 -0
- pbesa/engine/__init__.py +0 -2
- pbesa/engine/bdi/BDIAg.py +0 -42
- pbesa/engine/bdi/BDILevel.py +0 -10
- pbesa/engine/bdi/BDIMachine.py +0 -116
- pbesa/engine/bdi/Goal.py +0 -28
- pbesa/engine/bdi/GoalExe.py +0 -36
- pbesa/engine/bdi/__init__.py +0 -5
- pbesa/engine/rational/ActionExe.py +0 -35
- pbesa/engine/rational/Brain.py +0 -10
- pbesa/engine/rational/RationalAg.py +0 -43
- pbesa/engine/rational/__init__.py +0 -3
- pbesa/kernel/adapter/Adapter.py +0 -26
- pbesa/kernel/adapter/FileAdapter.py +0 -23
- pbesa/kernel/adapter/__init__.py +0 -2
- pbesa/kernel/agent/Action.py +0 -19
- pbesa/kernel/agent/Agent.py +0 -91
- pbesa/kernel/agent/BehaviorExe.py +0 -33
- pbesa/kernel/agent/Channel.py +0 -10
- pbesa/kernel/agent/World.py +0 -15
- pbesa/kernel/agent/__init__.py +0 -5
- pbesa/kernel/io/SystemFile.py +0 -13
- pbesa/kernel/io/TCPServer.py +0 -4
- pbesa/kernel/system/Adm.py +0 -189
- pbesa/kernel/system/Directory.py +0 -36
- pbesa/kernel/system/__init__.py +0 -2
- pbesa/kernel/util/HashTable.py +0 -62
- pbesa/kernel/util/Queue.py +0 -231
- pbesa/kernel/util/__init__.py +0 -2
- pbesa/middleware/__init__.py +0 -3
- pbesa/middleware/adapter/GameAdapter.py +0 -64
- pbesa/middleware/adapter/MongoAdapter.py +0 -47
- pbesa/middleware/adapter/RESTAdapter.py +0 -52
- pbesa/middleware/adapter/SubProcessAdapter.py +0 -30
- pbesa/middleware/adapter/WSSAdapter.py +0 -89
- pbesa/middleware/adapter/WSSNJAdapter.py +0 -51
- pbesa/middleware/adapter/WSSNJHandler.py +0 -23
- pbesa/middleware/adapter/__init__.py +0 -7
- pbesa/middleware/remote/AdmListener.py +0 -17
- pbesa/middleware/remote/RemoteAdm.py +0 -17
- pbesa/middleware/remote/__init__.py +0 -4
- pbesa/middleware/web/WebAgTK.py +0 -15
- pbesa/middleware/web/__init__.py +0 -0
- pbesa-2.1.dist-info/METADATA +0 -25
- pbesa-2.1.dist-info/RECORD +0 -54
@@ -1,57 +1,74 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
----------------------------------------------------------
|
4
|
+
-------------------------- PBESA -------------------------
|
5
|
+
----------------------------------------------------------
|
6
|
+
|
7
|
+
@autor AKEN
|
8
|
+
@version 4.0.0
|
9
|
+
@date 08/08/24
|
10
|
+
"""
|
11
|
+
|
12
|
+
# --------------------------------------------------------
|
13
|
+
# Define resources
|
14
|
+
# --------------------------------------------------------
|
15
|
+
|
16
|
+
import os
|
17
|
+
import sys
|
18
|
+
import json
|
19
|
+
import base64
|
20
|
+
import socketserver
|
21
|
+
from importlib.machinery import SourceFileLoader
|
22
|
+
|
23
|
+
# --------------------------------------------------------
|
24
|
+
# Define component
|
25
|
+
# --------------------------------------------------------
|
26
|
+
|
27
|
+
class AdmListenerHandler(socketserver.StreamRequestHandler):
|
28
|
+
""" ADM Listener Handler class """
|
29
|
+
|
30
|
+
def handle(self):
|
31
|
+
""" Handle """
|
32
|
+
from ..mas import Directory
|
33
|
+
self.data = self.rfile.readline().strip()
|
34
|
+
print("{} wrote:".format(self.client_address[0]))
|
35
|
+
print(self.data)
|
36
|
+
msg = str(self.data, "utf-8")
|
37
|
+
info = json.loads(msg)
|
38
|
+
if info['command'] == 'UPDATE':
|
39
|
+
agents = info['agents']
|
40
|
+
directory = Directory()
|
41
|
+
directory.set_agent_list(agents)
|
42
|
+
if info['command'] == 'MOVE':
|
43
|
+
appPath = os.path.abspath(os.path.dirname(sys.argv[0]))
|
44
|
+
appPathSplit = appPath.split(os.sep)
|
45
|
+
classPath = info['path']
|
46
|
+
classPathSplit = classPath.split('.')
|
47
|
+
path = appPathSplit[0]
|
48
|
+
findFlag = False
|
49
|
+
for x in range(1, len(appPathSplit) ):
|
50
|
+
if appPathSplit[x] == classPathSplit[0]:
|
51
|
+
path = path + os.sep + appPathSplit[x]
|
52
|
+
for y in range(1, len(classPathSplit) ):
|
53
|
+
path = path + os.sep + classPathSplit[y]
|
54
|
+
break
|
55
|
+
else:
|
56
|
+
path = path + os.sep + appPathSplit[x]
|
57
|
+
path = path + '.py'
|
58
|
+
module = SourceFileLoader(info['class'], path).load_module()
|
59
|
+
agType = getattr(module, info['class'])
|
60
|
+
ag = agType(info['id'])
|
61
|
+
ag.state = info['state']
|
62
|
+
ag.start()
|
63
|
+
if info['command'] == 'SENDEVENT':
|
64
|
+
from ..mas import Adm
|
65
|
+
data = info['data']
|
66
|
+
aux = None
|
67
|
+
if data and not data == 'None':
|
68
|
+
data = data.encode('utf-8')
|
69
|
+
data = base64.b64decode(data)
|
70
|
+
data = data.decode('utf-8')
|
71
|
+
aux = json.loads(data)
|
72
|
+
Adm().send_event(info['id'], info['event'], aux)
|
73
|
+
rsp = 'ACK'
|
74
|
+
self.wfile.write(bytes(rsp + "\n", "utf-8"))
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
------------------------------------------------------------
|
4
|
+
-------------------------- PBESA ---------------------------
|
5
|
+
------------------------------------------------------------
|
6
|
+
|
7
|
+
@autor AKEN & SIDRE
|
8
|
+
@version 3.0.1
|
9
|
+
@date 27/07/20
|
10
|
+
"""
|
11
|
+
|
12
|
+
# ----------------------------------------------------------
|
13
|
+
# Defines system component exceptions
|
14
|
+
# ----------------------------------------------------------
|
15
|
+
|
16
|
+
class RemoteException(Exception):
|
17
|
+
""" Base class for exceptions of system """
|
18
|
+
pass
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
----------------------------------------------------------
|
4
|
+
-------------------------- PBESA -------------------------
|
5
|
+
----------------------------------------------------------
|
6
|
+
|
7
|
+
@autor AKEN
|
8
|
+
@version 4.0.0
|
9
|
+
@date 09/08/24
|
10
|
+
"""
|
11
|
+
|
12
|
+
import traceback
|
13
|
+
import socketserver
|
14
|
+
from threading import Thread
|
15
|
+
from .exceptions import RemoteException
|
16
|
+
from .remote_adm_handler import RemoteAdmHandler
|
17
|
+
|
18
|
+
class RemoteAdm(Thread):
|
19
|
+
""" RemoteAdm class """
|
20
|
+
|
21
|
+
# IP
|
22
|
+
__IP = None
|
23
|
+
# PORT
|
24
|
+
__PORT = None
|
25
|
+
|
26
|
+
def __init__(self, ip:str, port:str) -> None:
|
27
|
+
""" Constructor
|
28
|
+
@param ip: IP
|
29
|
+
@param port: PORT
|
30
|
+
"""
|
31
|
+
self.__IP = ip
|
32
|
+
self.__PORT = port
|
33
|
+
super().__init__()
|
34
|
+
|
35
|
+
def run(self) -> None:
|
36
|
+
""" Run method """
|
37
|
+
try:
|
38
|
+
server = socketserver.TCPServer((self.__IP, self.__PORT), RemoteAdmHandler)
|
39
|
+
server.serve_forever()
|
40
|
+
except:
|
41
|
+
traceback.print_exc()
|
42
|
+
raise RemoteException("Could not initialize master container on %s host and %d port" % (self.__IP, self.__PORT))
|
@@ -1,83 +1,109 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
----------------------------------------------------------
|
4
|
+
-------------------------- PBESA -------------------------
|
5
|
+
----------------------------------------------------------
|
6
|
+
|
7
|
+
@autor AKEN
|
8
|
+
@version 4.0.0
|
9
|
+
@date 08/08/24
|
10
|
+
"""
|
11
|
+
|
12
|
+
# --------------------------------------------------------
|
13
|
+
# Define resources
|
14
|
+
# --------------------------------------------------------
|
15
|
+
|
16
|
+
import os
|
17
|
+
import json
|
18
|
+
import base64
|
19
|
+
import socket
|
20
|
+
import socketserver
|
21
|
+
from time import sleep
|
22
|
+
from importlib.machinery import SourceFileLoader
|
23
|
+
|
24
|
+
# --------------------------------------------------------
|
25
|
+
# Define component
|
26
|
+
# --------------------------------------------------------
|
27
|
+
|
28
|
+
class RemoteAdmHandler(socketserver.StreamRequestHandler):
|
29
|
+
""" Remote ADM Handler class """
|
30
|
+
|
31
|
+
def handle(self):
|
32
|
+
""" Handle """
|
33
|
+
from ..mas import Directory
|
34
|
+
self.data = self.rfile.readline().strip()
|
35
|
+
print("{} wrote:".format(self.client_address[0]))
|
36
|
+
print(self.data)
|
37
|
+
msg = str(self.data, "utf-8")
|
38
|
+
info = json.loads(msg)
|
39
|
+
if info['command'] == 'REGISTER':
|
40
|
+
directory = Directory()
|
41
|
+
directory.add_container({'name': info['name'], 'host': info['host'], 'port': info['port']})
|
42
|
+
data = 'ACK'
|
43
|
+
self.wfile.write(bytes(data + "\n", "utf-8"))
|
44
|
+
sleep(2) # 2 seconds.
|
45
|
+
containers = directory.get_containers()
|
46
|
+
agents = directory.get_agents()
|
47
|
+
dto = '{"command":"UPDATE", "agents" : ' + json.dumps(agents, ensure_ascii=False) + '}'
|
48
|
+
for ctn in containers:
|
49
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
50
|
+
try:
|
51
|
+
sock.connect( (ctn['host'], int(ctn['port'])) )
|
52
|
+
sock.sendall(bytes(dto + "\n", "utf-8"))
|
53
|
+
except:
|
54
|
+
pass
|
55
|
+
|
56
|
+
finally:
|
57
|
+
sock.close()
|
58
|
+
directory.check_full(info['name'])
|
59
|
+
if info['command'] == 'MOVE':
|
60
|
+
appPath = os.path.abspath(os.path.dirname(sys.argv[0]))
|
61
|
+
appPathSplit = appPath.split(os.sep)
|
62
|
+
classPath = info['path']
|
63
|
+
classPathSplit = classPath.split('.')
|
64
|
+
path = appPathSplit[0]
|
65
|
+
findFlag = False
|
66
|
+
for x in range(1, len(appPathSplit) ):
|
67
|
+
if appPathSplit[x] == classPathSplit[0]:
|
68
|
+
path = path + os.sep + appPathSplit[x]
|
69
|
+
for y in range(1, len(classPathSplit) ):
|
70
|
+
path = path + os.sep + classPathSplit[y]
|
71
|
+
break
|
72
|
+
else:
|
73
|
+
path = path + os.sep + appPathSplit[x]
|
74
|
+
path = path + '.py'
|
75
|
+
module = SourceFileLoader(info['class'], path).load_module()
|
76
|
+
agType = getattr(module, info['class'])
|
77
|
+
ag = agType(info['id'])
|
78
|
+
ag.state = info['state']
|
79
|
+
ag.start()
|
80
|
+
if info['command'] == 'ADD':
|
81
|
+
agent = info['agent']
|
82
|
+
host = agent['host']
|
83
|
+
directory = Directory()
|
84
|
+
directory.add_agent(agent)
|
85
|
+
containers = directory.get_containers()
|
86
|
+
agents = directory.get_agents()
|
87
|
+
dto = '{"command":"UPDATE", "agents" : ' + json.dumps(agents, ensure_ascii=False) + '}'
|
88
|
+
for ctn in containers:
|
89
|
+
if not ctn['host'] == host:
|
90
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
91
|
+
try:
|
92
|
+
sock.connect( (ctn['host'], int(ctn['port'])) )
|
93
|
+
sock.sendall(bytes(dto + "\n", "utf-8"))
|
94
|
+
except:
|
95
|
+
pass
|
96
|
+
finally:
|
97
|
+
sock.close()
|
98
|
+
if info['command'] == 'SENDEVENT':
|
99
|
+
from ..mas import Adm
|
100
|
+
data = info['data']
|
101
|
+
aux = None
|
102
|
+
if data and not data == 'None':
|
103
|
+
data = data.encode('utf-8')
|
104
|
+
data = base64.b64decode(data)
|
105
|
+
data = data.decode('utf-8')
|
106
|
+
aux = json.loads(data)
|
107
|
+
Adm().send_event(info['id'], info['event'], data)
|
108
|
+
rsp = 'ACK'
|
109
|
+
self.wfile.write(bytes(rsp + "\n", "utf-8"))
|
pbesa/social/__init__.py
ADDED