Commit af26ef94 authored by Vincent Pelletier's avatar Vincent Pelletier

Separate connection code and packet sending code from "execute" method.

Don't intercept exceptions arising from connection code.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@812 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 4b4ed209
......@@ -137,6 +137,8 @@ action_dict = {
class Application(object):
"""The storage node application."""
conn = None
def __init__(self, ip, port, handler):
self.connector_handler = getConnectorHandler(handler)
......@@ -144,6 +146,38 @@ class Application(object):
self.em = EventManager()
self.ptid = INVALID_PTID
def getConnection(self):
if self.conn is None:
handler = CommandEventHandler(self)
# connect to admin node
self.trying_admin_node = False
conn = None
while 1:
self.em.poll(1)
if conn is None:
self.trying_admin_node = True
logging.info('connecting to address %s:%d', *(self.server))
conn = ClientConnection(self.em, handler, \
addr = self.server,
connector_handler = self.connector_handler)
if self.trying_admin_node is False:
break
self.conn = conn
return self.conn
def doAction(self, packet):
conn = self.getConnection()
conn.ask(p)
self.result = ""
while 1:
self.em.poll(1)
if len(self.result):
break
def __del__(self):
self.conn.close()
def execute(self, args):
"""Execute the command given."""
# print node type : print list of node of the given type (STORAGE_NODE_TYPE, MASTER_NODE_TYPE...)
......@@ -163,32 +197,7 @@ class Application(object):
except ActionError, message:
self.result = message
else:
handler = CommandEventHandler(self)
# connect to admin node
conn = None
self.trying_admin_node = False
try:
while 1:
self.em.poll(1)
if conn is None:
self.trying_admin_node = True
logging.info('connecting to address %s:%d', *(self.server))
conn = ClientConnection(self.em, handler, \
addr = self.server,
connector_handler = self.connector_handler)
if self.trying_admin_node is False:
break
except OperationFailure, msg:
return "FAIL : %s" %(msg,)
conn.ask(p)
self.result = ""
while 1:
self.em.poll(1)
if len(self.result):
break
# close connection
conn.close()
self.doAction(p)
else:
self.result = usage('unknown command')
......
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