Package core :: Module handlers

[hide private]
[frames] | no frames]

# Source Code for Module core.handlers

      1  # Copyright 2011 the original author or authors.
      2  #
      3  # Licensed under the Apache License, Version 2.0 (the "License");
      4  # you may not use this file except in compliance with the License.
      5  # You may obtain a copy of the License at
      6  #
      7  #      http://www.apache.org/licenses/LICENSE-2.0
      8  #
      9  # Unless required by applicable law or agreed to in writing, software
     10  # distributed under the License is distributed on an "AS IS" BASIS,
     11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12  # See the License for the specific language governing permissions and
     13  # limitations under the License.
     14
     15  import org.vertx.java.core.Handler
     16
     17  from core.buffer import Buffer
     18
     19  __author__ = "Scott Horn"
     20  __email__ = "scott@hornmicro.com"
     21  __credits__ = "Based entirely on work by Tim Fox http://tfox.org"
     22
     23 -class DoneHandler(org.vertx.java.core.Handler):
     24      """ Done handler """
     25 -    def __init__(self, handler):
     26          self.handler = handler
     27
     28 -    def handle(self, arg=None):
     29          """ Call the handler when done """
     30          if self.handler != None:
     31              if arg != None:
     32                  self.handler(arg)
     33              else:
     34                  self.handler()
     35
     36 -class ContinueHandler(org.vertx.java.core.Handler):
     37      """ Continue handler """
     38 -    def __init__(self, handler):
     39          self.handler = handler
     40
     41 -    def handle(self, nothing=None):
     42          """ Call the handler to continue """
     43          self.handler()
     44
     45 -class BufferHandler(org.vertx.java.core.Handler):
     46 -    def __init__(self, handler):
     47          self.handler = handler
     48
     49 -    def handle(self, buffer):
     50          self.handler(Buffer(buffer))
     51
     52 -class ClosedHandler(org.vertx.java.core.Handler):
     53      """ Closed connection handler """
     54 -    def __init__(self, handler):
     55          self.handler = handler
     56
     57 -    def handle(self, nothing=None):
     58          """ Call the handler when a connection is closed """
     59          self.handler()
     60
     61 -class CloseHandler(org.vertx.java.core.Handler):
     62      """ Close connection handler """
     63 -    def __init__(self, handler):
     64          self.handler = handler
     65
     66 -    def handle(self, nothing=None):
     67          """ Call the handler when a connection is closed """
     68          if self.handler != None:
     69              self.handler()
     70
     71 -class ExceptionHandler(org.vertx.java.core.Handler):
     72      """ Exception handler """
     73 -    def __init__(self, handler):
     74          self.handler = handler
     75
     76 -    def handle(self, exception):
     77          """ Call the handler when there is an exception """
     78          self.handler(exception)
     79
     80 -class DrainHandler(org.vertx.java.core.Handler):
     81      """ Drain handler """
     82 -    def __init__(self, handler):
     83          self.handler = handler
     84
     85 -    def handle(self, nothing=None):
     86          """ Call the handler after stream has been drained"""
     87          self.handler()
     88
     89 -class StreamEndHandler(org.vertx.java.core.Handler):
     90      """ Stream End handler """
     91 -    def __init__(self, handler):
     92          self.handler = handler
     93
     94 -    def handle(self, stream):
     95          """ Call the handler after stream has been ended"""
     96          self.handler(stream)
     97
     98 -class TimerHandler(org.vertx.java.core.Handler):
     99      """ Timer handler """
    100 -    def __init__(self, handler):
    101          self.handler = handler
    102
    103 -    def handle(self, timer_id):
    104          """ Call the handler """
    105          if self.handler != None:
    106              self.handler(timer_id)
    107