# Path: gumpy/deco.py
# class _RequirementHepler(object):
# class _ConsumerHelper(object):
# class _EventHepler(object):
# class activate(Annotation):
# class deactivate(Annotation):
# class _TaskHelper(object):
#     def __init__(self, fn, args, kwargs):
#     def __get__(self, instance, owner):
#     def __init__(self, fn, resource_uri, cardinality):
#     def __get__(self, instance, owner):
#     def unbind(self, fn):
#     def __init__(self, fn):
#     def __get__(self, instance, owner):
# def configuration(**config_map):
#     def deco(func):
#         def configuration_injected_func(self, *args, **kwargs):
#     def subject(self):
#     def subject(self):
#     def __init__(self, fn):
#     def __get__(self, instance, owner):


import multiprocessing.pool
import functools
import wsgiref.simple_server, wsgiref.util, wsgiref.validate
import logging
from gumpy.deco import service, configuration, bind, event
__author__ = 'chinfeng'


logger = logging.getLogger(__name__)

class ThreadPoolWSGIServer(wsgiref.simple_server.WSGIServer):
    def __init__(self, thread_count, *args, **kwds):
        wsgiref.simple_server.WSGIServer.__init__(self, *args, **kwds)
        self._pool = multiprocessing.pool.ThreadPool(thread_count)

    def process_request_worker(self, request, client_address):
        try:
            self.finish_request(request, client_address)
            self.shutdown_request(request)
        except:
            self.handle_error(request, client_address)
            self.shutdown_request(request)

    def process_request(self, request, client_address):
        self._pool.apply_async(self.process_request_worker, args=(request, client_address))

    def serve_forever(self, *args, **kwds):
        self._pool.apply_async(wsgiref.simple_server.WSGIServer.serve_forever, args=(self, ) + args, kwds=kwds)

    def shutdown(self):
        super(self.__class__, self).shutdown()
        self._pool.terminate()

@service
class WSGIService(object):

# Path: gumpy/deco.py
# class _RequirementHepler(object):
# class _ConsumerHelper(object):
# class _EventHepler(object):
# class activate(Annotation):
# class deactivate(Annotation):
# class _TaskHelper(object):
#     def __init__(self, fn, args, kwargs):
#     def __get__(self, instance, owner):
#     def __init__(self, fn, resource_uri, cardinality):
#     def __get__(self, instance, owner):
#     def unbind(self, fn):
#     def __init__(self, fn):
#     def __get__(self, instance, owner):
# def configuration(**config_map):
#     def deco(func):
#         def configuration_injected_func(self, *args, **kwargs):
#     def subject(self):
#     def subject(self):
#     def __init__(self, fn):
#     def __get__(self, instance, owner):


# Path: huacaya/tserv.py
import multiprocessing.pool
import functools
import wsgiref.simple_server, wsgiref.util, wsgiref.validate
import logging
from gumpy.deco import service, configuration, bind, event

__author__ = 'chinfeng'


logger = logging.getLogger(__name__)

class ThreadPoolWSGIServer(wsgiref.simple_server.WSGIServer):
    def __init__(self, thread_count, *args, **kwds):
        wsgiref.simple_server.WSGIServer.__init__(self, *args, **kwds)
        self._pool = multiprocessing.pool.ThreadPool(thread_count)

    def process_request_worker(self, request, client_address):
        try:
            self.finish_request(request, client_address)
            self.shutdown_request(request)
        except:
            self.handle_error(request, client_address)
            self.shutdown_request(request)

    def process_request(self, request, client_address):
        self._pool.apply_async(self.process_request_worker, args=(request, client_address))

    def serve_forever(self, *args, **kwds):
        self._pool.apply_async(wsgiref.simple_server.WSGIServer.serve_forever, args=(self, ) + args, kwds=kwds)

    def shutdown(self):
        super(self.__class__, self).shutdown()
        self._pool.terminate()

@service
class WSGIService(object):

    @configuration(rootapp='rootapp')