# -*- coding: utf-8 -*-
# $Id: Service.py 1634 2013-04-12 15:36:36Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECSpooler.
#
import os
import random
import threading
import signal
import time
import logging
try:
import hashlib
except ImportError:
class Service:
"""
This is the abstract server class which will be used for spooler and
backend implementation.
"""
"""
Creates a new XML-RPC server instance at the given host and port.
@param: host: host name
@param: port: port number
"""
# set server identification
# set class varia
#log.info('host: %s' % host)
#log.info('port: %d' % port)
self._serverThread = None
# create a server instance, but do not run it
# use SSL
#server_class = SecureXMLRPCServer
#handler_class = SecureXMLRpcRequestHandler
# register functions (must be implemented in subclasses)
"""
Runs a XML-RPC server.
"""
"""
Runs this XML-RPC server instance, but do so in a different thread.
The main thread simply sleeps so that it can respond to signals.
"""
if self._manageBeforeStart():
try:
#signal.signal(signal.SIGHUP, self._reconfig)
except AttributeError:
try:
except AttributeError:
try:
# TODO: Green-IT: don't waste cpu cycles using while true: sleep(0.1)
#signal.pause()
while 1:
except KeyboardInterrupt:
else:
return "Couldn't start server thread! See log for more details."
"""
Shuts down this XML-RPC server instance.
@param: signal: the signal (TERM or KILL)
@param: stack:
"""
# stop server thread
# TODO: os_exit doesn't clean up used sockets properly
"""
Does nothing yet.
@param: signal: the signal (?)
@param: stack:
"""
return
"""
Register functions to self._server
"""
raise NotImplementedError("Method _registerFunctions must be "
"implemented by subclass")
"""
Do some necessary stuff before starting the server.
"""
raise NotImplementedError("Method _manageBeforeStart must be "
"implemented by subclass")
"""
Do some necessary stuff before stopping the server.
"""
raise NotImplementedError("Method _manageBeforeStop must be "
"implemented by subclass")