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
pbesa/kernel/system/Adm.py
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
import os
|
3
|
-
import sys
|
4
|
-
import json
|
5
|
-
import socket
|
6
|
-
from time import sleep
|
7
|
-
from ...kernel.util.HashTable import HashTable
|
8
|
-
from ...kernel.system.Directory import Directory
|
9
|
-
from ...kernel.adapter.FileAdapter import FileAdapter
|
10
|
-
from ...middleware.remote.RemoteAdm import RemoteAdm
|
11
|
-
from ...middleware.remote.AdmListener import AdmListener
|
12
|
-
|
13
|
-
class Adm(object):
|
14
|
-
class __Adm:
|
15
|
-
def __init__(self):
|
16
|
-
self.val = None
|
17
|
-
self.conf = None
|
18
|
-
self.adapters = HashTable()
|
19
|
-
self.agentsTable = {}
|
20
|
-
self.containerList = []
|
21
|
-
|
22
|
-
def __str__(self):
|
23
|
-
return repr(self) + self.val
|
24
|
-
|
25
|
-
def start(self):
|
26
|
-
self.startByConf('')
|
27
|
-
|
28
|
-
def startByConf(self, conf):
|
29
|
-
|
30
|
-
if conf == '':
|
31
|
-
self.conf = {
|
32
|
-
"user" : "local",
|
33
|
-
"ip" : "localhost",
|
34
|
-
"port" : 8080,
|
35
|
-
"remote" : None
|
36
|
-
}
|
37
|
-
else:
|
38
|
-
CONF_DIR = conf
|
39
|
-
fa = FileAdapter({'alias':'JsonAdapter', 'type': 'JSON', 'path': CONF_DIR})
|
40
|
-
fa.setUp()
|
41
|
-
param = fa.request()
|
42
|
-
self.conf = param['conf']
|
43
|
-
|
44
|
-
if self.conf['remote']:
|
45
|
-
remote = self.conf['remote']
|
46
|
-
if remote['mode'] == 'MASTER':
|
47
|
-
self.remoteAdm = RemoteAdm(remote['ip'], remote['port'])
|
48
|
-
self.remoteAdm.start()
|
49
|
-
else:
|
50
|
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
51
|
-
attempts = remote['attempts']
|
52
|
-
master = remote['master']
|
53
|
-
data = '{"command": "REGISTER", "alias":"' + remote['container_alias'] + '", "ip":"' + remote['ip'] + '", "port":"'+ str(remote['port']) +'"}'
|
54
|
-
for x in range(1, attempts):
|
55
|
-
try:
|
56
|
-
sock.connect((master['master_ip'], master['master_port']))
|
57
|
-
sock.sendall(bytes(data + "\n", "utf-8"))
|
58
|
-
received = str(sock.recv(1024), "utf-8")
|
59
|
-
print("Received: {}".format(received))
|
60
|
-
if received == 'ACK' + "\n":
|
61
|
-
break
|
62
|
-
except:
|
63
|
-
sleep(1) # 1 second.
|
64
|
-
finally:
|
65
|
-
sock.close()
|
66
|
-
|
67
|
-
admListener = AdmListener(remote['ip'], remote['port'])
|
68
|
-
admListener.start()
|
69
|
-
|
70
|
-
def addAgent(self, agent):
|
71
|
-
self.agentsTable[agent.id] = agent
|
72
|
-
ip = ''
|
73
|
-
port = ''
|
74
|
-
if self.conf['remote']:
|
75
|
-
remote = self.conf['remote']
|
76
|
-
ip = remote['ip']
|
77
|
-
port = remote['port']
|
78
|
-
directory = Directory()
|
79
|
-
directory.addAgent({'agent': agent.id, 'ip': ip, 'port' : port})
|
80
|
-
if self.conf['remote']:
|
81
|
-
remote = self.conf['remote']
|
82
|
-
agents = directory.getAgents()
|
83
|
-
dto = '{"command":"UPDATE", "agents" : ' + json.dumps(agents, ensure_ascii=False) + '}'
|
84
|
-
if remote['mode'] == 'MASTER':
|
85
|
-
containers = directory.getContainers()
|
86
|
-
for ctn in containers:
|
87
|
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
88
|
-
try:
|
89
|
-
sock.connect( (ctn['ip'], int(ctn['port'])) )
|
90
|
-
sock.sendall(bytes(dto + "\n", "utf-8"))
|
91
|
-
except:
|
92
|
-
pass
|
93
|
-
|
94
|
-
finally:
|
95
|
-
sock.close()
|
96
|
-
else:
|
97
|
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
98
|
-
attempts = remote['attempts']
|
99
|
-
master = remote['master']
|
100
|
-
try:
|
101
|
-
sock.connect((master['master_ip'], master['master_port']))
|
102
|
-
sock.sendall(bytes(dto + "\n", "utf-8"))
|
103
|
-
except:
|
104
|
-
sleep(1) # 1 second.
|
105
|
-
finally:
|
106
|
-
sock.close()
|
107
|
-
|
108
|
-
def sendEvent(self, agentID, event, data):
|
109
|
-
try:
|
110
|
-
ag = self.agentsTable[agentID]
|
111
|
-
if (ag):
|
112
|
-
ag.sendEvent(event, data)
|
113
|
-
return True
|
114
|
-
else:
|
115
|
-
remote = self.conf['remote']
|
116
|
-
attempts = remote['attempts']
|
117
|
-
agents = Directory().getAgents()
|
118
|
-
for agent in agents:
|
119
|
-
if agentID == agent['agent']:
|
120
|
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
121
|
-
aux = str(data)
|
122
|
-
aux = aux.replace("\'", "\"")
|
123
|
-
dto = '{"command": "SENDEVENT", "alias":"' + agentID + '", "event":"' + event + '", "data":'+ aux +'}'
|
124
|
-
print('Send::')
|
125
|
-
print(dto)
|
126
|
-
for x in range(1, attempts):
|
127
|
-
try:
|
128
|
-
sock.connect((agent['ip'], agent['port']))
|
129
|
-
sock.sendall(bytes(dto + "\n", "utf-8"))
|
130
|
-
received = str(sock.recv(1024), "utf-8")
|
131
|
-
print("Received: {}".format(received))
|
132
|
-
if received == 'ACK' + "\n":
|
133
|
-
break
|
134
|
-
except:
|
135
|
-
sleep(1) # 1 second.
|
136
|
-
finally:
|
137
|
-
sock.close()
|
138
|
-
return True
|
139
|
-
|
140
|
-
except Exception as inst:
|
141
|
-
print('Controled ecxeption in Adm: ')
|
142
|
-
print(inst)
|
143
|
-
return False
|
144
|
-
|
145
|
-
def addAdapter(self, id, adapter):
|
146
|
-
self.adapters[id] = adapter
|
147
|
-
|
148
|
-
def getAdapter(self, id):
|
149
|
-
return self.adapters[id]
|
150
|
-
|
151
|
-
def getConf(self):
|
152
|
-
return self.conf
|
153
|
-
|
154
|
-
def addContainer(self, container):
|
155
|
-
self.containerList.append(container)
|
156
|
-
|
157
|
-
def moveAgent(self, agentID, container):
|
158
|
-
ag = self.agentsTable[agentID]
|
159
|
-
ag.finalize()
|
160
|
-
dto = ag.toDTO()
|
161
|
-
print (dto)
|
162
|
-
containers = Directory().getContainers()
|
163
|
-
for ctn in containers:
|
164
|
-
if container == ctn['alias']:
|
165
|
-
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
166
|
-
try:
|
167
|
-
sock.connect( (ctn['ip'], int(ctn['port'])) )
|
168
|
-
sock.sendall(bytes(dto + "\n", "utf-8"))
|
169
|
-
except:
|
170
|
-
pass
|
171
|
-
finally:
|
172
|
-
sock.close()
|
173
|
-
break
|
174
|
-
self.agentsTable[agentID] = None
|
175
|
-
Directory().removeAgent(agentID)
|
176
|
-
|
177
|
-
def setEndPoint(self, agID, socket):
|
178
|
-
ag = self.agentsTable[agID]
|
179
|
-
ag.setSocket(socket)
|
180
|
-
|
181
|
-
instance = None
|
182
|
-
def __new__(cls):
|
183
|
-
if not Adm.instance:
|
184
|
-
Adm.instance = Adm.__Adm()
|
185
|
-
return Adm.instance
|
186
|
-
def __getattr__(self, name):
|
187
|
-
return getattr(self.instance, name)
|
188
|
-
def __setattr__(self, name):
|
189
|
-
return setattr(self.instance, name)
|
pbesa/kernel/system/Directory.py
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
class Directory(object):
|
2
|
-
class __Directory:
|
3
|
-
|
4
|
-
def __init__(self):
|
5
|
-
self.containerList = []
|
6
|
-
self.agentList = []
|
7
|
-
|
8
|
-
def addContainer(self, container):
|
9
|
-
self.containerList.append(container)
|
10
|
-
|
11
|
-
def addAgent(self, agent):
|
12
|
-
self.agentList.append(agent)
|
13
|
-
|
14
|
-
def getContainers(self):
|
15
|
-
return self.containerList
|
16
|
-
|
17
|
-
def getAgents(self):
|
18
|
-
return self.agentList
|
19
|
-
|
20
|
-
def resetAgentList(self):
|
21
|
-
self.agentList = []
|
22
|
-
|
23
|
-
def removeAgent(self, agent):
|
24
|
-
for ag in self.agentList:
|
25
|
-
if ag['agent'] == agent:
|
26
|
-
self.agentList.remove(ag)
|
27
|
-
|
28
|
-
instance = None
|
29
|
-
def __new__(cls):
|
30
|
-
if not Directory.instance:
|
31
|
-
Directory.instance = Directory.__Directory()
|
32
|
-
return Directory.instance
|
33
|
-
def __getattr__(self, name):
|
34
|
-
return getattr(self.instance, name)
|
35
|
-
def __setattr__(self, name):
|
36
|
-
return setattr(self.instance, name)
|
pbesa/kernel/system/__init__.py
DELETED
pbesa/kernel/util/HashTable.py
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
class HashTable:
|
2
|
-
def __init__(self):
|
3
|
-
self.size = 11
|
4
|
-
self.slots = [None] * self.size
|
5
|
-
self.data = [None] * self.size
|
6
|
-
|
7
|
-
def put(self,key,data):
|
8
|
-
hashvalue = self.hashfunction(key,len(self.slots))
|
9
|
-
|
10
|
-
if self.slots[hashvalue] == None:
|
11
|
-
self.slots[hashvalue] = key
|
12
|
-
self.data[hashvalue] = data
|
13
|
-
else:
|
14
|
-
if self.slots[hashvalue] == key:
|
15
|
-
self.data[hashvalue] = data #replace
|
16
|
-
else:
|
17
|
-
nextslot = self.rehash(hashvalue,len(self.slots))
|
18
|
-
while self.slots[nextslot] != None and \
|
19
|
-
self.slots[nextslot] != key:
|
20
|
-
nextslot = self.rehash(nextslot,len(self.slots))
|
21
|
-
|
22
|
-
if self.slots[nextslot] == None:
|
23
|
-
self.slots[nextslot]=key
|
24
|
-
self.data[nextslot]=data
|
25
|
-
else:
|
26
|
-
self.data[nextslot] = data #replace
|
27
|
-
|
28
|
-
def hashfunction(self,key,size):
|
29
|
-
return self.hasht(key,size)#key%size
|
30
|
-
|
31
|
-
def hasht(self,astring, tablesize):
|
32
|
-
sum = 0
|
33
|
-
for pos in range(len(astring)):
|
34
|
-
sum = sum + ord(astring[pos])
|
35
|
-
return sum%tablesize
|
36
|
-
|
37
|
-
def rehash(self,oldhash,size):
|
38
|
-
return (oldhash+1)%size
|
39
|
-
|
40
|
-
def get(self,key):
|
41
|
-
startslot = self.hashfunction(key,len(self.slots))
|
42
|
-
|
43
|
-
data = None
|
44
|
-
stop = False
|
45
|
-
found = False
|
46
|
-
position = startslot
|
47
|
-
while self.slots[position] != None and \
|
48
|
-
not found and not stop:
|
49
|
-
if self.slots[position] == key:
|
50
|
-
found = True
|
51
|
-
data = self.data[position]
|
52
|
-
else:
|
53
|
-
position=self.rehash(position,len(self.slots))
|
54
|
-
if position == startslot:
|
55
|
-
stop = True
|
56
|
-
return data
|
57
|
-
|
58
|
-
def __getitem__(self,key):
|
59
|
-
return self.get(key)
|
60
|
-
|
61
|
-
def __setitem__(self,key,data):
|
62
|
-
self.put(key,data)
|
pbesa/kernel/util/Queue.py
DELETED
@@ -1,231 +0,0 @@
|
|
1
|
-
from time import time as _time
|
2
|
-
try:
|
3
|
-
import threading as _threading
|
4
|
-
except ImportError:
|
5
|
-
import dummy_threading as _threading
|
6
|
-
from collections import deque
|
7
|
-
import heapq
|
8
|
-
|
9
|
-
__all__ = ['Empty', 'Full', 'Queue', 'PriorityQueue', 'LifoQueue']
|
10
|
-
|
11
|
-
class Empty(Exception):
|
12
|
-
"Exception raised by Queue.get(block=0)/get_nowait()."
|
13
|
-
pass
|
14
|
-
|
15
|
-
class Full(Exception):
|
16
|
-
"Exception raised by Queue.put(block=0)/put_nowait()."
|
17
|
-
pass
|
18
|
-
|
19
|
-
class Queue:
|
20
|
-
"""Create a queue object with a given maximum size.
|
21
|
-
If maxsize is <= 0, the queue size is infinite.
|
22
|
-
"""
|
23
|
-
def __init__(self, maxsize=0):
|
24
|
-
self.maxsize = maxsize
|
25
|
-
self._init(maxsize)
|
26
|
-
# mutex must be held whenever the queue is mutating. All methods
|
27
|
-
# that acquire mutex must release it before returning. mutex
|
28
|
-
# is shared between the three conditions, so acquiring and
|
29
|
-
# releasing the conditions also acquires and releases mutex.
|
30
|
-
self.mutex = _threading.Lock()
|
31
|
-
# Notify not_empty whenever an item is added to the queue; a
|
32
|
-
# thread waiting to get is notified then.
|
33
|
-
self.not_empty = _threading.Condition(self.mutex)
|
34
|
-
# Notify not_full whenever an item is removed from the queue;
|
35
|
-
# a thread waiting to put is notified then.
|
36
|
-
self.not_full = _threading.Condition(self.mutex)
|
37
|
-
# Notify all_tasks_done whenever the number of unfinished tasks
|
38
|
-
# drops to zero; thread waiting to join() is notified to resume
|
39
|
-
self.all_tasks_done = _threading.Condition(self.mutex)
|
40
|
-
self.unfinished_tasks = 0
|
41
|
-
|
42
|
-
def task_done(self):
|
43
|
-
"""Indicate that a formerly enqueued task is complete.
|
44
|
-
Used by Queue consumer threads. For each get() used to fetch a task,
|
45
|
-
a subsequent call to task_done() tells the queue that the processing
|
46
|
-
on the task is complete.
|
47
|
-
If a join() is currently blocking, it will resume when all items
|
48
|
-
have been processed (meaning that a task_done() call was received
|
49
|
-
for every item that had been put() into the queue).
|
50
|
-
Raises a ValueError if called more times than there were items
|
51
|
-
placed in the queue.
|
52
|
-
"""
|
53
|
-
self.all_tasks_done.acquire()
|
54
|
-
try:
|
55
|
-
unfinished = self.unfinished_tasks - 1
|
56
|
-
if unfinished <= 0:
|
57
|
-
if unfinished < 0:
|
58
|
-
raise ValueError('task_done() called too many times')
|
59
|
-
self.all_tasks_done.notify_all()
|
60
|
-
self.unfinished_tasks = unfinished
|
61
|
-
finally:
|
62
|
-
self.all_tasks_done.release()
|
63
|
-
|
64
|
-
def join(self):
|
65
|
-
"""Blocks until all items in the Queue have been gotten and processed.
|
66
|
-
The count of unfinished tasks goes up whenever an item is added to the
|
67
|
-
queue. The count goes down whenever a consumer thread calls task_done()
|
68
|
-
to indicate the item was retrieved and all work on it is complete.
|
69
|
-
When the count of unfinished tasks drops to zero, join() unblocks.
|
70
|
-
"""
|
71
|
-
self.all_tasks_done.acquire()
|
72
|
-
try:
|
73
|
-
while self.unfinished_tasks:
|
74
|
-
self.all_tasks_done.wait()
|
75
|
-
finally:
|
76
|
-
self.all_tasks_done.release()
|
77
|
-
|
78
|
-
def qsize(self):
|
79
|
-
"""Return the approximate size of the queue (not reliable!)."""
|
80
|
-
self.mutex.acquire()
|
81
|
-
n = self._qsize()
|
82
|
-
self.mutex.release()
|
83
|
-
return n
|
84
|
-
|
85
|
-
def empty(self):
|
86
|
-
"""Return True if the queue is empty, False otherwise (not reliable!)."""
|
87
|
-
self.mutex.acquire()
|
88
|
-
n = not self._qsize()
|
89
|
-
self.mutex.release()
|
90
|
-
return n
|
91
|
-
|
92
|
-
def full(self):
|
93
|
-
"""Return True if the queue is full, False otherwise (not reliable!)."""
|
94
|
-
self.mutex.acquire()
|
95
|
-
n = 0 < self.maxsize == self._qsize()
|
96
|
-
self.mutex.release()
|
97
|
-
return n
|
98
|
-
|
99
|
-
def put(self, item, block=True, timeout=None):
|
100
|
-
"""Put an item into the queue.
|
101
|
-
If optional args 'block' is true and 'timeout' is None (the default),
|
102
|
-
block if necessary until a free slot is available. If 'timeout' is
|
103
|
-
a non-negative number, it blocks at most 'timeout' seconds and raises
|
104
|
-
the Full exception if no free slot was available within that time.
|
105
|
-
Otherwise ('block' is false), put an item on the queue if a free slot
|
106
|
-
is immediately available, else raise the Full exception ('timeout'
|
107
|
-
is ignored in that case).
|
108
|
-
"""
|
109
|
-
self.not_full.acquire()
|
110
|
-
try:
|
111
|
-
if self.maxsize > 0:
|
112
|
-
if not block:
|
113
|
-
if self._qsize() == self.maxsize:
|
114
|
-
raise Full
|
115
|
-
elif timeout is None:
|
116
|
-
while self._qsize() == self.maxsize:
|
117
|
-
self.not_full.wait()
|
118
|
-
elif timeout < 0:
|
119
|
-
raise ValueError("'timeout' must be a non-negative number")
|
120
|
-
else:
|
121
|
-
endtime = _time() + timeout
|
122
|
-
while self._qsize() == self.maxsize:
|
123
|
-
remaining = endtime - _time()
|
124
|
-
if remaining <= 0.0:
|
125
|
-
raise Full
|
126
|
-
self.not_full.wait(remaining)
|
127
|
-
self._put(item)
|
128
|
-
self.unfinished_tasks += 1
|
129
|
-
self.not_empty.notify()
|
130
|
-
finally:
|
131
|
-
self.not_full.release()
|
132
|
-
|
133
|
-
def put_nowait(self, item):
|
134
|
-
"""Put an item into the queue without blocking.
|
135
|
-
Only enqueue the item if a free slot is immediately available.
|
136
|
-
Otherwise raise the Full exception.
|
137
|
-
"""
|
138
|
-
return self.put(item, False)
|
139
|
-
|
140
|
-
def get(self, block=True, timeout=None):
|
141
|
-
"""Remove and return an item from the queue.
|
142
|
-
If optional args 'block' is true and 'timeout' is None (the default),
|
143
|
-
block if necessary until an item is available. If 'timeout' is
|
144
|
-
a non-negative number, it blocks at most 'timeout' seconds and raises
|
145
|
-
the Empty exception if no item was available within that time.
|
146
|
-
Otherwise ('block' is false), return an item if one is immediately
|
147
|
-
available, else raise the Empty exception ('timeout' is ignored
|
148
|
-
in that case).
|
149
|
-
"""
|
150
|
-
self.not_empty.acquire()
|
151
|
-
try:
|
152
|
-
if not block:
|
153
|
-
if not self._qsize():
|
154
|
-
raise Empty
|
155
|
-
elif timeout is None:
|
156
|
-
while not self._qsize():
|
157
|
-
self.not_empty.wait()
|
158
|
-
elif timeout < 0:
|
159
|
-
raise ValueError("'timeout' must be a non-negative number")
|
160
|
-
else:
|
161
|
-
endtime = _time() + timeout
|
162
|
-
while not self._qsize():
|
163
|
-
remaining = endtime - _time()
|
164
|
-
if remaining <= 0.0:
|
165
|
-
raise Empty
|
166
|
-
self.not_empty.wait(remaining)
|
167
|
-
item = self._get()
|
168
|
-
self.not_full.notify()
|
169
|
-
return item
|
170
|
-
finally:
|
171
|
-
self.not_empty.release()
|
172
|
-
|
173
|
-
def get_nowait(self):
|
174
|
-
"""Remove and return an item from the queue without blocking.
|
175
|
-
Only get an item if one is immediately available. Otherwise
|
176
|
-
raise the Empty exception.
|
177
|
-
"""
|
178
|
-
return self.get(False)
|
179
|
-
|
180
|
-
# Override these methods to implement other queue organizations
|
181
|
-
# (e.g. stack or priority queue).
|
182
|
-
# These will only be called with appropriate locks held
|
183
|
-
|
184
|
-
# Initialize the queue representation
|
185
|
-
def _init(self, maxsize):
|
186
|
-
self.queue = deque()
|
187
|
-
|
188
|
-
def _qsize(self, len=len):
|
189
|
-
return len(self.queue)
|
190
|
-
|
191
|
-
# Put a new item in the queue
|
192
|
-
def _put(self, item):
|
193
|
-
self.queue.append(item)
|
194
|
-
|
195
|
-
# Get an item from the queue
|
196
|
-
def _get(self):
|
197
|
-
return self.queue.popleft()
|
198
|
-
|
199
|
-
|
200
|
-
class PriorityQueue(Queue):
|
201
|
-
'''Variant of Queue that retrieves open entries in priority order (lowest first).
|
202
|
-
Entries are typically tuples of the form: (priority number, data).
|
203
|
-
'''
|
204
|
-
|
205
|
-
def _init(self, maxsize):
|
206
|
-
self.queue = []
|
207
|
-
|
208
|
-
def _qsize(self, len=len):
|
209
|
-
return len(self.queue)
|
210
|
-
|
211
|
-
def _put(self, item, heappush=heapq.heappush):
|
212
|
-
heappush(self.queue, item)
|
213
|
-
|
214
|
-
def _get(self, heappop=heapq.heappop):
|
215
|
-
return heappop(self.queue)
|
216
|
-
|
217
|
-
|
218
|
-
class LifoQueue(Queue):
|
219
|
-
'''Variant of Queue that retrieves most recently added entries first.'''
|
220
|
-
|
221
|
-
def _init(self, maxsize):
|
222
|
-
self.queue = []
|
223
|
-
|
224
|
-
def _qsize(self, len=len):
|
225
|
-
return len(self.queue)
|
226
|
-
|
227
|
-
def _put(self, item):
|
228
|
-
self.queue.append(item)
|
229
|
-
|
230
|
-
def _get(self):
|
231
|
-
return self.queue.pop()
|
pbesa/kernel/util/__init__.py
DELETED
pbesa/middleware/__init__.py
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
from threading import Thread
|
2
|
-
from abc import ABC, abstractmethod
|
3
|
-
#from ...kernel.system.Adm import Adm
|
4
|
-
from ...kernel.adapter.Adapter import Adapter
|
5
|
-
|
6
|
-
import os
|
7
|
-
import random
|
8
|
-
import pygame
|
9
|
-
import math
|
10
|
-
import sys
|
11
|
-
|
12
|
-
class GameAdapter(Adapter, Thread):
|
13
|
-
|
14
|
-
adm = None
|
15
|
-
conf = None
|
16
|
-
clock = None
|
17
|
-
screen = None
|
18
|
-
agentList = None
|
19
|
-
|
20
|
-
def __init__(self, conf):
|
21
|
-
self.conf = conf
|
22
|
-
self.agentList = []
|
23
|
-
self.adm = None #Adm()
|
24
|
-
super().__init__()
|
25
|
-
|
26
|
-
def setUp(self):
|
27
|
-
os.environ["SDL_VIDEO_CENTERED"] = "1"
|
28
|
-
self.screen = pygame.display.set_mode((self.conf['width'], self.conf['height']))
|
29
|
-
pygame.display.set_caption(self.conf['title'])
|
30
|
-
self.clock = pygame.time.Clock()
|
31
|
-
pygame.init()
|
32
|
-
self.clock = pygame.time.Clock()
|
33
|
-
|
34
|
-
def response(self):
|
35
|
-
pass
|
36
|
-
|
37
|
-
def request(self):
|
38
|
-
return self.data
|
39
|
-
|
40
|
-
def finalize(self):
|
41
|
-
pass
|
42
|
-
|
43
|
-
def addAgent(self, ag):
|
44
|
-
self.agentList.append(ag)
|
45
|
-
|
46
|
-
def run(self):
|
47
|
-
running = True
|
48
|
-
while running:
|
49
|
-
for event in pygame.event.get():
|
50
|
-
if event.type == pygame.QUIT:
|
51
|
-
running = False
|
52
|
-
self.frame()
|
53
|
-
pygame.display.update()
|
54
|
-
self.clock.tick(40)
|
55
|
-
|
56
|
-
def updateWorlds(self, event, data):
|
57
|
-
for ag in self.agentList:
|
58
|
-
self.adm.sendEvent(ag.id, event, data)
|
59
|
-
|
60
|
-
def getPygame(self):
|
61
|
-
return pygame
|
62
|
-
|
63
|
-
def frame(self):
|
64
|
-
pass
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import pymongo
|
2
|
-
|
3
|
-
from pymongo import MongoClient
|
4
|
-
from ...kernel.adapter.Adapter import Adapter
|
5
|
-
|
6
|
-
class MongoAdapter(Adapter):
|
7
|
-
|
8
|
-
db = None
|
9
|
-
conf = None
|
10
|
-
client = None
|
11
|
-
|
12
|
-
def __init__(self, conf):
|
13
|
-
self.conf = conf
|
14
|
-
super().__init__()
|
15
|
-
|
16
|
-
def setUp(self):
|
17
|
-
self.client = MongoClient()
|
18
|
-
self.db = self.client[self.conf['database']]
|
19
|
-
|
20
|
-
def response(self, response):
|
21
|
-
pass
|
22
|
-
|
23
|
-
def request(self):
|
24
|
-
pass
|
25
|
-
|
26
|
-
def finalize(self):
|
27
|
-
pass
|
28
|
-
|
29
|
-
def getAll(self, collection):
|
30
|
-
coll = self.db[collection]
|
31
|
-
return coll.find()
|
32
|
-
|
33
|
-
def getObject(self, collection, query):
|
34
|
-
coll = self.db[collection]
|
35
|
-
return coll.find_one(query)
|
36
|
-
|
37
|
-
def getObjectByID(self, collection, id):
|
38
|
-
coll = self.db[collection]
|
39
|
-
return coll.find_one({"_id": id})
|
40
|
-
|
41
|
-
def insertObject(self, collection, dto):
|
42
|
-
coll = self.db[collection]
|
43
|
-
return coll.insert_one(dto).inserted_id
|
44
|
-
|
45
|
-
def updateObject(self, collection, id, dto):
|
46
|
-
coll = self.db[collection]
|
47
|
-
return coll.replace_one({"_id": id}, dto, True)
|
@@ -1,52 +0,0 @@
|
|
1
|
-
from threading import Thread
|
2
|
-
#from ...kernel.system.Adm import Adm
|
3
|
-
from ...kernel.util.Queue import Queue
|
4
|
-
from ...kernel.adapter.Adapter import Adapter
|
5
|
-
|
6
|
-
#import web
|
7
|
-
import json
|
8
|
-
|
9
|
-
class RESTAdapter(Adapter, Thread):
|
10
|
-
|
11
|
-
app = None
|
12
|
-
adm = None
|
13
|
-
conf = None
|
14
|
-
|
15
|
-
def __init__(self):
|
16
|
-
self.adm = None #Adm()
|
17
|
-
super().__init__()
|
18
|
-
|
19
|
-
def setUp(self):
|
20
|
-
urls = ('/(.*)', 'RESTAdapter')
|
21
|
-
self.app = web.application(urls, globals())
|
22
|
-
|
23
|
-
def response(self, response):
|
24
|
-
pass
|
25
|
-
|
26
|
-
def request(self):
|
27
|
-
pass
|
28
|
-
|
29
|
-
def finalize(self):
|
30
|
-
pass
|
31
|
-
|
32
|
-
def run(self):
|
33
|
-
self.app.run()
|
34
|
-
|
35
|
-
def GET(self, name):
|
36
|
-
if not name:
|
37
|
-
name = 'World'
|
38
|
-
return 'Hello, ' + name + '!'
|
39
|
-
|
40
|
-
def POST(self, rqst):
|
41
|
-
data = json.loads(web.data().decode('utf-8'))
|
42
|
-
queue = Queue(10)
|
43
|
-
dto = {'queue': queue,'url': rqst, 'data': data}
|
44
|
-
self.adm.sendEvent('front_controller', 'request', dto)
|
45
|
-
response = queue.get()
|
46
|
-
queue.task_done()
|
47
|
-
web.header('Access-Control-Allow-Origin', '*')
|
48
|
-
web.header('Access-Control-Allow-Credentials', 'true')
|
49
|
-
return str(response).replace("'", "\"")
|
50
|
-
|
51
|
-
|
52
|
-
|