27
28
def get_listener(fsm, vm):
28
29
"""Return an instance of the status listener, or None if turned off."""
29
30
if should_start_listener():
30
aggregator = StatusAggregator()
31
return StatusListener(fsm, vm, aggregator)
31
status_frontend = StatusFrontend()
32
return StatusListener(fsm, vm, status_frontend)
36
#TODO: hookup the shutdown of the listener to the cleanup in the aggregator
35
37
class StatusListener(object):
36
38
"""SD listener for EQ events that turns them into status updates."""
38
def __init__(self, fsm, vm, aggregator):
40
def __init__(self, fsm, vm, status_frontend):
39
41
"""Initialize this instance with the FSM and VM."""
42
self.aggregator = aggregator
44
self.status_frontend = status_frontend
44
46
def handle_AQ_CHANGE_PUBLIC_ACCESS_OK(self, share_id, node_id, is_public,
46
48
"""The status of a published resource changed."""
48
self.aggregator.file_published(public_url)
50
self.aggregator.file_unpublished(public_url)
50
self.status_frontend.file_published(public_url)
52
self.status_frontend.file_unpublished(public_url)
54
def handle_SYS_QUEUE_ADDED(self, command):
55
"""A command has been added to the queue."""
56
if isinstance(command, action_queue.Download):
57
self.status_frontend.download_started(command)
58
elif isinstance(command, action_queue.Upload):
59
self.status_frontend.upload_started(command)
61
self.status_frontend.queue_added(command)
63
def handle_SYS_QUEUE_REMOVED(self, command):
64
"""A command has been removed from the queue."""
65
if isinstance(command, action_queue.Download):
66
self.status_frontend.download_finished(command)
67
elif isinstance(command, action_queue.Upload):
68
self.status_frontend.upload_finished(command)
70
self.status_frontend.queue_removed(command)
72
def handle_SYS_QUEUE_DONE(self):
73
"""The queue has finished processing everything."""
74
self.status_frontend.queue_done()
76
def handle_VM_SHARE_CREATED(self, share_id):
77
"""A new share is available for subscription."""
78
share = self.vm.get_volume(share_id)
79
self.status_frontend.new_share_available(share)
81
def handle_VM_UDF_CREATED(self, udf):
82
"""A new udf is available for subscription."""
83
self.status_frontend.new_udf_available(udf)
85
def handle_SYS_CONNECTION_LOST(self):
86
"""The client lost the connection to the server."""
87
self.status_frontend.server_connection_lost()
89
def handle_SYS_CONNECTION_MADE(self):
90
"""The client connected to the server."""
91
self.status_frontend.server_connection_made()