Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

#!/usr/bin/env python 

 

""" 

@author David Stuebe 

""" 

import ion.util.ionlog 

log = ion.util.ionlog.getLogger(__name__) 

 

from twisted.internet import defer 

 

from ion.core.process.process import ProcessFactory 

from ion.core.process.service_process import ServiceProcess, ServiceClient 

 

from ion.core.object import object_utils 

 

 

from ion.util import procutils as pu 

 

 

ADDRESSLINK_TYPE = object_utils.create_type_identifier(object_id=20003, version=1) 

PERSON_TYPE = object_utils.create_type_identifier(object_id=20001, version=1) 

 

class ReceiverService(ServiceProcess): 

 

    declare = ServiceProcess.service_declare(name='receiver_service', 

                                          version='0.1.1', 

                                          dependencies=[]) 

 

 

    def __init__(self, *args, **kwargs): 

        # Service class initializer. Basic config, but no yields allowed. 

 

        ServiceProcess.__init__(self, *args, **kwargs) 

 

        self.action = defer.Deferred() 

 

    @defer.inlineCallbacks 

    def op_a(self, content, headers, msg): 

        """ 

        Dummy operation that takes 'a_time' seconds to complete 

        """ 

        log.info('Starting Op A') 

 

        context = self.context.get('progenitor_convid', 'None Set!') 

        log.info('Got Context: "%s"' % context) 

        self.action.callback(context) 

 

        log.info('Replying OK') 

        yield self.reply_ok(msg, content) 

 

        self.action = defer.Deferred() 

        log.info('Op A Complete!') 

 

 

    @defer.inlineCallbacks 

    def op_b(self, content, headers, msg): 

        """ 

        Dummy operation that takes 'b_time' seconds to complete 

        """ 

        log.info('Starting Op B') 

 

        context = self.context.get('progenitor_convid', 'None Set!') 

        log.info('Got Context: "%s"' % context) 

        self.action.callback(context) 

 

        log.info('Replying OK') 

        yield self.reply_ok(msg, content) 

 

        self.action = defer.Deferred() 

        log.info('Op B Complete!') 

 

 

 

factory = ProcessFactory(ReceiverService) 

 

 

class ReceiverServiceClient(ServiceClient): 

 

    def __init__(self, proc=None, **kwargs): 

        if not 'targetname' in kwargs: 

            kwargs['targetname'] = 'receiver_service' 

        ServiceClient.__init__(self, proc, **kwargs) 

 

 

    @defer.inlineCallbacks 

    def a(self, msg): 

        """ 

        @brief Call op_a 

        @retval ok 

        """ 

        yield self._check_init() 

 

        (ret, heads, message) = yield self.rpc_send('a', msg) 

        #defer.returnValue(ret) 

 

        defer.returnValue((ret, heads, message)) 

 

    @defer.inlineCallbacks 

    def b(self, msg): 

        """ 

        @brief Call op_a 

        @retval ok 

        """ 

        yield self._check_init() 

 

        (ret, heads, message) = yield self.rpc_send('b', msg) 

        defer.returnValue((ret, heads, message))