Commit a9636aa1 authored by Marco Mariani's avatar Marco Mariani

made the script 'runnable'

parent a28bfd61
...@@ -4,12 +4,12 @@ import socket ...@@ -4,12 +4,12 @@ import socket
import time import time
import sys import sys
import thread import thread
import time
import os import os
sys.path[:] = %(syspath)s sys.path[:] = %(syspath)s
from slapos import slap as slapmodule from slapos import slap as slapmodule
import slapos
port = 50000 port = 50000
...@@ -43,7 +43,6 @@ class ResilientInstance(object): ...@@ -43,7 +43,6 @@ class ResilientInstance(object):
self.id = 0 self.id = 0
self.state = 'normal' self.state = 'normal'
self.halter = 0 self.halter = 0
self.nbComp = nbComp
self.inElection = False self.inElection = False
self.alive = True self.alive = True
self.lastPing = time.clock() self.lastPing = time.clock()
...@@ -68,6 +67,7 @@ class ResilientInstance(object): ...@@ -68,6 +67,7 @@ class ResilientInstance(object):
## Needs to be changed to use the master ## Needs to be changed to use the master
def aliveManagement(self): def aliveManagement(self):
while self.alive: while self.alive:
print 'XXX sleeping for 30 minutes'
time.sleep(30*60) time.sleep(30*60)
if self.id == 0: if self.id == 0:
continue continue
...@@ -165,9 +165,7 @@ class FilteredCanal(object): ...@@ -165,9 +165,7 @@ class FilteredCanal(object):
self.lock.acquire() self.lock.acquire()
if self.list: if self.list:
self.lock.release() self.lock.release()
val = self.list[0] return self.list.pop(0)
self.list = self.list[1:]
return val
self.lock.release() self.lock.release()
return [None, None] return [None, None]
...@@ -175,8 +173,6 @@ class FilteredCanal(object): ...@@ -175,8 +173,6 @@ class FilteredCanal(object):
class Wrapper(object): class Wrapper(object):
def __init__(self, timeout=20): def __init__(self, timeout=20):
self.read_pipes = [os.fdopen(x) for x in read_pipes]
self.write_pipes = write_pipes
self.canals = [] self.canals = []
self.ips = [] self.ips = []
self.id = 0 self.id = 0
...@@ -195,7 +191,7 @@ class Wrapper(object): ...@@ -195,7 +191,7 @@ class Wrapper(object):
self.getConnectionInfos() self.getConnectionInfos()
self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) self.socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
self.socket.bind((self.ips[self.id], port + self.id)) self.socket.bind((self.ips[self.id], port + self.id))
s.listen(5) self.socket.listen(5)
def send(self, message, number): def send(self, message, number):
self.getConnectionInfos() self.getConnectionInfos()
...@@ -214,15 +210,15 @@ class Wrapper(object): ...@@ -214,15 +210,15 @@ class Wrapper(object):
return created return created
def recv(self): def recv(self):
client, _ = s.accept() client, _ = self.socket.accept()
client_message = client.recv(1024) client_message = client.recv(1024)
if client_message: if client_message:
message, sender = client_message.split() message, sender = client_message.split()
for canal in self.canals: for canal in self.canals:
canal.append(message, sender) canal.append(message, int(sender))
wrapper = createWrapper(20) wrapper = Wrapper(20)
computer = ResilientInstance(wrapper) computer = ResilientInstance(wrapper)
...@@ -239,6 +235,7 @@ thread.start_new_thread(computer.main, ()) ...@@ -239,6 +235,7 @@ thread.start_new_thread(computer.main, ())
thread.start_new_thread(computer.aliveManagement, ()) thread.start_new_thread(computer.aliveManagement, ())
while True: while True:
# XXX tight loop
continue continue
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment