예제 #1
0
    def __init__(self, comp, delay):
        # One of the rare cases where we do not call the parent class' init()
        # right off the bat.  Instead we first replicate the wrapped component's
        # inboxes and outboxes.  Private "_name" boxes are not replicated.
        self.child = comp

        for inbox in (item for item in self.child.Inboxes
                      if not item.startswith('_')):
            try:
                self.Inboxes[inbox] = self.child.Inboxes.get(inbox, "")
            except AttributeError:  # not a dict
                self.Inboxes[inbox] = ""

        for outbox in (item for item in self.child.Outboxes
                       if not item.startswith('_')):
            try:
                self.Outboxes[outbox] = self.child.Outboxes.get(outbox, "")
            except AttributeError:  # not a dict
                self.Outboxes[outbox] = ""

        super(TTL, self).__init__()

        self.timebomb = SingleTick(delay=delay, check_interval=1)

        # We can now create the mailbox linkages now that the parent class'
        # init() has been called.

        self.link((self.timebomb, 'outbox'), (self, '_trigger'))
        self.link((self, '_disarm'), (self.timebomb, 'control'))
        try:
            self.link((self, '_sigkill'), (self.child, 'control'))
            self.nochildcontrol = False
        except KeyError:
            self.nochildcontrol = True

        for inbox in (item for item in self.child.Inboxes
                      if not item.startswith('_')):
            self.link((self, inbox), (self.child, inbox), passthrough=1)

        for outbox in (item for item in self.child.Outboxes
                       if not item.startswith('_')):
            self.link((self.child, outbox), (self, outbox), passthrough=2)

        self.addChildren(self.child)
예제 #2
0
# -*- coding: utf-8 -*-
# Copyright 2010 British Broadcasting Corporation and Kamaelia Contributors(1)
#
# (1) Kamaelia Contributors are listed in the AUTHORS file and at
#     http://www.kamaelia.org/AUTHORS - please extend this file,
#     not this notice.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''
This file contains an example usage of Kamaelia.Apps.SA.Time.SingleTick
'''

from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Apps.SA.Time import SingleTick

Pipeline(
    SingleTick(0.3),
    ConsoleEchoer(use_repr=True),
).run()