Servlet Objects
self._batch = None self._total = None self._count = 0
self._job = netsvc.Job(self.generateContent) def destroyServlet(self):
FormServlet.destroyServlet(self) self._job.cancel()
self._job = None
def handleRequest(self):
if not self.containsField("batch") or \ not self.containsField("total"):
self.sendError(400)
else:
try:
self._batch = int(self.field("batch")) self._total = int(self.field("total"))
except:
self.sendError(400)
else:
self.sendResponse(200)
def generateContent(self): content = []
for i in range(0,self._batch): self._count = self._count + 1 content.append(string.zfill(self._count,60))
content.append("")
self.sendContent(string.join(content,"\n")) self._total = self._total - 1
if self._total <= 0: self.ignoreCongestion() self.endContent()
else:
self.flushContent()
self._job.schedule(netsvc.IDLE_JOB) def clientCongestion(self,status,pending):
if status == netsvc.CONNECTION_CLEARED: self._job.reset() self._job.schedule(netsvc.IDLE_JOB)
elif status == netsvc.CONNECTION_BLOCKED: self._job.cancel()
When a HTTP servlet no longer wishes to monitor the status of the socket connection the member func- tion "ignoreCongestion()" can be called. Although not absolutely necessary, it is good practice to always call this just prior to calling the member function "endContent()" to close off the re- sponse.