Commit | Line | Data |
4536f655 |
1 | # File: Stem/Test/Echo.pm |
2 | |
3 | # This file is part of Stem. |
4 | # Copyright (C) 1999, 2000, 2001 Stem Systems, Inc. |
5 | |
6 | # Stem is free software; you can redistribute it and/or modify |
7 | # it under the terms of the GNU General Public License as published by |
8 | # the Free Software Foundation; either version 2 of the License, or |
9 | # (at your option) any later version. |
10 | |
11 | # Stem is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | # GNU General Public License for more details. |
15 | |
16 | # You should have received a copy of the GNU General Public License |
17 | # along with Stem; if not, write to the Free Software |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | |
20 | # For a license to use the Stem under conditions other than those |
21 | # described here, to purchase support for this software, or to purchase a |
22 | # commercial warranty contract, please contact Stem Systems at: |
23 | |
24 | # Stem Systems, Inc. 781-643-7504 |
25 | # 79 Everett St. info@stemsystems.com |
26 | # Arlington, MA 02474 |
27 | # USA |
28 | |
29 | |
30 | package Stem::Test::Echo ; |
31 | |
32 | use strict ; |
33 | |
34 | my $attr_spec = [ { } ]; |
35 | |
36 | sub new { |
37 | |
38 | my( $class ) = shift ; |
39 | |
40 | my $self = Stem::Class::parse_args( $attr_spec, @_ ) ; |
41 | return $self unless ref $self ; |
42 | |
43 | return $self ; |
44 | } |
45 | |
46 | # send this cell messages if you want test default delivery speed |
47 | # this will handle all messages not covered by other methods |
48 | |
49 | sub msg_in { |
50 | |
51 | my ( $self, $msg ) = @_ ; |
52 | |
53 | my $reply_msg = $msg->reply() ; |
54 | |
55 | $reply_msg->dispatch() ; |
56 | |
57 | return ; |
58 | } |
59 | |
60 | # send this cell data messages if you want to just echo the data |
61 | |
62 | sub data_in { |
63 | |
64 | my ( $self, $msg ) = @_ ; |
65 | |
66 | #print $msg->dump( 'ECHO data_in' ) ; |
67 | |
68 | my $reply_msg = $msg->reply( |
69 | type => 'data', |
70 | data => $msg->data(), |
71 | ) ; |
72 | |
73 | #print $reply_msg->dump( 'ECHO data reply' ) ; |
74 | |
75 | $reply_msg->dispatch() ; |
76 | |
77 | return ; |
78 | } |
79 | |
80 | # send this cell 'echo' type messages if you want test plain reply speed |
81 | |
82 | sub echo_in { |
83 | |
84 | my ( $self, $msg ) = @_ ; |
85 | |
86 | $msg->reply()->dispatch() ; |
87 | |
88 | return ; |
89 | } |
90 | |
91 | # send this cell 'echo_data' type messages if you want test reply with data |
92 | |
93 | sub echo_data_in { |
94 | |
95 | my ( $self, $msg ) = @_ ; |
96 | |
97 | #print $msg->dump( 'ECHO_DATA' ) ; |
98 | |
99 | my $data = $msg->data() ; |
100 | |
101 | my $reply_msg = $msg->reply( data => { echo => $data } ) ; |
102 | |
103 | $reply_msg->dispatch() ; |
104 | |
105 | return ; |
106 | } |
107 | |
108 | # send this cell 'echo' cmd messages if you want test plain command speed |
109 | |
110 | sub echo_cmd { |
111 | |
112 | my ( $self ) = @_ ; |
113 | |
114 | return '' ; |
115 | } |
116 | |
117 | # send this cell 'echo_data' cmd messages if you want test command |
118 | # speed with data. |
119 | |
120 | sub echo_data_cmd { |
121 | |
122 | my ( $self, $msg ) = @_ ; |
123 | |
124 | my $data = $msg->data() ; |
125 | |
126 | return $data ; |
127 | } |
128 | |
129 | 1 ; |
130 | |
131 | __END__ |
132 | |
133 | =pod |
134 | |
135 | =head1 NAME |
136 | |
137 | Stem::Test::Echo - This cell accepts messages and sends back reply |
138 | messages or command data. It can be used to test message receipt, |
139 | replies, and command returns and to benchmark message throughput. |
140 | |
141 | =head1 SYNOPSIS |
142 | |
143 | [ |
144 | 'class' => 'Stem::Test::Echo', |
145 | 'name' => 'test_echo', |
146 | ], |
147 | |
148 | =head1 USAGE |
149 | |
150 | This cell accepts various messages, all of which will echo some |
151 | message back to the sender. |
152 | |
153 | An echo type message will do a reply with no data. |
154 | |
155 | An echo_data type message will do a reply with the sent data. |
156 | |
157 | An echo command message will return a null string. |
158 | |
159 | An echo_data command message will return the data. |
160 | |
161 | Any other message type or command will do a plain reply like |
162 | an 'echo' type message. |
163 | |
164 | =cut |