Grupo ARCO - Universidad de Castilla-La Mancha
Grupo ARCO - Universidad de Castilla-La Mancha
Grupo ARCO - Universidad de Castilla-La Mancha
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
E. ESTUDIO IceStorm 90<br />
IceStorm y getPublisher <strong>de</strong>vuelve el publicador <strong>de</strong>l canal <strong>de</strong> <strong>de</strong>terminado tipo. Como<br />
se pue<strong>de</strong> observar en el SLICE <strong>de</strong>finido en E.1, el parámetro listener tiene que ser <strong>de</strong>l tipo<br />
ASD::Listener, <strong>de</strong> esta manera se asegura que el objeto a suscribir es <strong>de</strong>l tipo <strong>de</strong>seado.<br />
import sys, Ice, IceStorm<br />
Ice.loadSlice(’ASDF.ice’)<br />
import ASD<br />
class ASDAI(ASD.ASDA):<br />
<strong>de</strong>f __init__(self, topic_mgr):<br />
try:<br />
self.topic = topic_mgr.create("ASDATopic")<br />
print "create ASDATopic"<br />
except IceStorm.TopicExists, e:<br />
print "topic already created"<br />
self.topic = topic_mgr.retrieve("ASDATopic")<br />
<strong>de</strong>f addListener(self, listener, current=None):<br />
qos = {}<br />
self.topic.subscribe(qos, listener)<br />
<strong>de</strong>f getPublisher(self, current=None):<br />
pub = self.topic.getPublisher()<br />
return ASD.ListenerPrx.uncheckedCast(pub)<br />
class Delegate(Ice.Application):<br />
<strong>de</strong>f get_topic_manager(self):<br />
properties = self.communicator().getProperties()<br />
prop_key = "IceStormAdmin.TopicManager.Default"<br />
strproxy = properties.getProperty(prop_key)<br />
if not strproxy:<br />
print "property", prop_key, "not set"<br />
return 0<br />
print "Using IceStorm in ’ %s’"<br />
% strproxy<br />
base = self.communicator().stringToProxy(strproxy)<br />
return IceStorm.TopicManagerPrx.checkedCast(base)<br />
<strong>de</strong>f run(self, argv):<br />
servant = ASDAI(self.get_topic_manager())<br />
ic = self.communicator()<br />
adapter = ic.createObjectAdapterWithEndpoints("Adapter", "tcp −p<br />
3000")<br />
proxy = adapter.add(servant, ic.stringToI<strong>de</strong>ntity("ASDA"))<br />
print proxy<br />
adapter.activate()<br />
ic.waitForShutdown()<br />
return 0<br />
sys.exit(Delegate().main(sys.argv))<br />
Listado E.2: Canal encargado <strong>de</strong> la comunicación con los servicios IceStorm