OverlayApps.py :  » Network » Torrent-Swapper » swapper » Swapper » Overlay » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Torrent Swapper 
Torrent Swapper » swapper » Swapper » Overlay » OverlayApps.py
# Written by Arno Bakker
# see LICENSE.txt for license information
#
# All applications on top of the SecureOverlay should be started here.
#
import sys

from BitTornado.BT1.MessageID import HelpCoordinatorMessages,HelpHelperMessages,MetadataMessages,BuddyCastMessages,getMessageName
from Swapper.toofastbt.CoordinatorMessageHandler import CoordinatorMessageHandler
from Swapper.toofastbt.HelperMessageHandler import HelperMessageHandler
from MetadataHandler import MetadataHandler
from Swapper.BuddyCast.buddycast import BuddyCastFactory
from Swapper.BuddyCast.TorrentCollecting import TorrentCollecting

DEBUG = False

class OverlayApps:
    # Code to make this a singleton
    __single = None

    def __init__(self):
        if OverlayApps.__single:
            raise RuntimeError, "OverlayApps is Singleton"
        OverlayApps.__single = self 
        self.coord_handler = None
        self.help_handler = None
        self.metadata_handler = None
        self.buddycast = None
        self.collect = None

    def getInstance(*args, **kw):
        if OverlayApps.__single is None:
            OverlayApps(*args, **kw)
        return OverlayApps.__single
    getInstance = staticmethod(getInstance)

    def register(self, secure_overlay, launchmany, enable_recommender, 
                 enable_dlhelp, enable_collect, config_dir):
        self.config_dir = config_dir
        if enable_dlhelp:
            # Create handler for messages to dlhelp coordinator
            self.coord_handler = CoordinatorMessageHandler(launchmany)
            secure_overlay.registerHandler(HelpHelperMessages, self.coord_handler)

            # Create handler for messages to dlhelp helper
            self.help_handler = HelperMessageHandler(launchmany)
            secure_overlay.registerHandler(HelpCoordinatorMessages, self.help_handler)
        else:
            secure_overlay.registerHandler(HelpCoordinatorMessages,self)

        if enable_recommender:
            # Create handler for Buddycast messages
            self.buddycast = BuddyCastFactory.getInstance()
            self.buddycast.register(secure_overlay, launchmany.rawserver, launchmany.listen_port, launchmany.exchandler)
            secure_overlay.registerHandler(BuddyCastMessages, self.buddycast)
        else:
            secure_overlay.registerHandler(BuddyCastMessages,self)

        if enable_collect:
            self.collect = TorrentCollecting.getInstance()

        if enable_collect or enable_dlhelp:
            # Create handler for metadata messages
            self.metadata_handler = MetadataHandler.getInstance()
            self.metadata_handler.register(secure_overlay, self.help_handler, launchmany, self.config_dir)
            secure_overlay.registerHandler(MetadataMessages, self.metadata_handler)
            
            if self.help_handler is not None:
                self.help_handler.register(self.metadata_handler)

            if self.collect is not None:
                self.collect.register(secure_overlay, launchmany.rawserver, self.metadata_handler)
        else:
            secure_overlay.registerHandler(MetadataMessages,self)

    def handleMessage(self,permid,message):
        """ dummy handler for when features are disabled."""
        t = message[0]
        if DEBUG:
            print >> sys.stderr,"olapps: Got",getMessageName(t),"but the feature it belongs to is disabled."
        return True
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.