4
from MessageQueue import MessageQueue
6
from twisted.internet import reactor
8
class QueueMngException(Exception):
9
def __init__(self, value):
10
self.value = str(value)
13
return repr(self.value)
16
# Il broker e un componente unico
17
# Entita passiva creata nel main principale
18
# Viene chiamata in causa da IncomingSIPHandler.handleIncoming quando arriva un messaggio SIP
21
# Un QueueHandler per ogni dominio destinatario.
22
# Dizionario del tipo {"fqdn": [QueueHandler,"uriBGW","addrBGW",portBGW]}
25
# Chiede servizi di connessione MSRP al SessionMSRPHandler
35
def __init__(self, global_config):
36
self.global_config = global_config
41
def setSendMSRP(self, send):
44
def inizializeQueueByFile(self, filename):
47
f = open(filename,'r')
51
name, method, timeout, threshold = s
52
queue = MessageQueue(name, float(timeout.strip()), int(threshold.strip()), self.sendMSRP)
53
self.addQueue(method.strip(), queue)
58
def recvMessageSIP(self, msg, method, destHost, destPort):
60
print "** BROKER: non sono pronto"
61
raise QueueMngException
63
#LOG print "Broker: MESSAGGIO ricevuto e da ritrasmettere a "+str(destHost)+":"+str(destPort)
64
queue = self.scheduleQueue(method)
67
def scheduleQueue(self, method):
68
if self.queueDict == None:
69
print "** BROKER: Non ci sono code"
71
if not(self.queueDict.has_key(method)):
72
if not(self.queueDict.has_key("ALL")):
73
print "** BROKER: Metodo non servito"
78
i = self.rr[method].next()
80
self.rr[method] = iter(self.queueDict[method])
81
i = self.rr[method].next()
82
print "** BROKER: Select queue "+i.getName()+" - method "+method
85
def addQueue(self, method, queue):
86
if self.queueDict.has_key(method):
87
self.queueDict[method].append(queue)
89
self.queueDict[method] = [queue]
90
self.rr[method] = iter(self.queueDict[method])
93
def delQueue(self, method, queue):
99
class ManagerFittizio():
102
self.connected = True
104
def sendMSRP(self, msg):
105
print "INVIATO BLOCCO!"
107
def isConnected(self):
108
return self.connected
110
if __name__ == '__main__':
112
m = ManagerFittizio()
114
broker = Broker(global_config)
115
broker.setSendMSRP(m)
117
broker.inizializeQueueByFile("queueConfig.txt")
119
print broker.queueDict
122
f = open('test/resp.txt','r')
124
f = open('test/reqTo.txt','r')
129
broker.recvMessageSIP(req, "INVITE", "biloxi.it", 9999)
131
broker.recvMessageSIP(res, "INVITE", "atlanta.it", 10000)
b'\\ No newline at end of file'