| 1 | package POE::Component::FunctionBus; | ||
| 2 | |||
| 3 | # Core/Internal modules and options | ||
| 4 | 1 | ▶ | use 5.0244; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | # External modules | ||
| 9 | 1 | ▶ | use POE; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | POE::Component::FunctionBus - Scalable dynamic function bus | ||
| 14 | |||
| 15 | =head1 PECULIARITIES | ||
| 16 | |||
| 17 | =head2 UNUSABLE MODULE | ||
| 18 | |||
| 19 | This module is a skeleton for a larger module and the author | ||
| 20 | is basically getting his enviroment setup, trying to remember | ||
| 21 | howto get PODs nicely formatted and other bits and bobs, that | ||
| 22 | is the only reason this module has been uploaded. | ||
| 23 | |||
| 24 | This module should not be used by anyone in its current state. | ||
| 25 | |||
| 26 | =head2 VERSIONING | ||
| 27 | |||
| 28 | The author of this module has taken a rather strange approach | ||
| 29 | to the versioning of the module, basically there the time the | ||
| 30 | source code/package was packaged 'make dist'. | ||
| 31 | |||
| 32 | =head1 VERSION | ||
| 33 | |||
| 34 | Version 1569954247 | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | 1 | our $VERSION = '1569954247'; | |
| 39 | |||
| 40 | =head1 DESCRIPTION | ||
| 41 | |||
| 42 | The entire point of this module is to make a very fast/easy interface for | ||
| 43 | attaching internal and even external functions to a common standardized | ||
| 44 | serialization bus. (The serialization used is not enforced) | ||
| 45 | |||
| 46 | This module is the forerunner for an upcoming protocol that is in RFC, as the | ||
| 47 | author of the same protocol I have decided to race ahead and make something | ||
| 48 | from its fundamental core principles to solve some issues I have in the present. | ||
| 49 | |||
| 50 | =head2 WHY | ||
| 51 | |||
| 52 | Simply put you can publish functions over a common protocol (not neccesarily | ||
| 53 | just in perl) and instead of them being controlled by any type of namespace, | ||
| 54 | they are infact simply functions on a bus so for scalability of that expensive | ||
| 55 | processing function, you can attach as many workers as like. | ||
| 56 | |||
| 57 | This does however mean that very large complex tasks should be split down into | ||
| 58 | as small of a set of work functions as possible, so that they can be more easily | ||
| 59 | distributed amongst multiple processes. | ||
| 60 | |||
| 61 | But no one writes large heavy monolthic 'evil' functions anymore, right? | ||
| 62 | |||
| 63 | =head2 CONSIDERATIONS | ||
| 64 | |||
| 65 | To be considering using this type of distributed work network you should also | ||
| 66 | remember that it is rather dependant on code enacting postback type behaviour, | ||
| 67 | rather than block-and-return. | ||
| 68 | |||
| 69 | Not that you could not use block-and-return it would just well, be rather | ||
| 70 | resource hungry and not very scalable. If you do have a_function() that takes | ||
| 71 | 8 days to run, consider wrapping it in a service that responds that it is busy | ||
| 72 | or so. That way you can have multiple nodes providing that service. | ||
| 73 | |||
| 74 | =head1 SYNOPSIS | ||
| 75 | |||
| 76 | Perhaps a little code snippet. | ||
| 77 | |||
| 78 | use POE::Component::FunctionBus; | ||
| 79 | |||
| 80 | my $options = { | ||
| 81 | } | ||
| 82 | |||
| 83 | my $node = POE::Component::FunctionBus->new($options); | ||
| 84 | |||
| 85 | $node->offer() | ||
| 86 | |||
| 87 | |||
| 88 | =head1 EXPORT | ||
| 89 | |||
| 90 | There are no exports for this module | ||
| 91 | |||
| 92 | =head1 METHODS | ||
| 93 | |||
| 94 | These are for instanciating connecting nodes | ||
| 95 | |||
| 96 | =head2 new | ||
| 97 | |||
| 98 | Create a new connection object, by default this will act as both a server and | ||
| 99 | client, it also by default binds 0.0.0.0/IPV4_ANY on port 10101(TCP) as well as | ||
| 100 | af_unix:/tmp/functionbus.PID.sock (PID here meaning the literal PID that perl | ||
| 101 | is using) | ||
| 102 | |||
| 103 | =cut | ||
| 104 | |||
| 105 | 0 | ▶ | sub new { |
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 106 | 0 | my ($class,$options) = @_; | |
| 107 | |||
| 108 | 0 | my $self = bless { | |
| 109 | alias => __PACKAGE__, | ||
| 110 | session => 0, | ||
| 111 | }, $class; | ||
| 112 | |||
| 113 | 0 | $self->{session} = POE::Session->create( | |
| 114 | package_states => [ | ||
| 115 | $self => { | ||
| 116 | _start => '_start', | ||
| 117 | _stop => '_stop', | ||
| 118 | _keep_alive => '_keep_alive', | ||
| 119 | } | ||
| 120 | ], | ||
| 121 | heap => { | ||
| 122 | parent => POE::Kernel->get_active_session()->ID | ||
| 123 | } | ||
| 124 | ); | ||
| 125 | |||
| 126 | 0 | $self->{id} = $self->{session}->ID; | |
| 127 | |||
| 128 | 0 | return $self; | |
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | |||
| 133 | =head1 OBJECT METHODS | ||
| 134 | |||
| 135 | =head2 Blocking | ||
| 136 | |||
| 137 | These are primarily functions that can be called on the resultant POE::Session | ||
| 138 | returned from an initilizer (documented above), in the spirit of non blocking | ||
| 139 | processing you should really use these as little as possible | ||
| 140 | |||
| 141 | =head3 somefunc | ||
| 142 | |||
| 143 | =cut | ||
| 144 | |||
| 145 | 0 | ▶ | sub somefunc { |
|
Subroutine
somefunc: not called CC=1 SCAR=0.0
Pod
documented
| |||
| 146 | } | ||
| 147 | |||
| 148 | =head2 NON Blocking | ||
| 149 | |||
| 150 | These are binds to anonymous POE::Kernels that post into the primary session, | ||
| 151 | as of such they do not return anything directly but some may allow callbacks. | ||
| 152 | |||
| 153 | =head3 network_id | ||
| 154 | |||
| 155 | Networks are generally dynamically created within the scope of a set of working | ||
| 156 | nodes however this in its self is given a unique id, just incase there happens | ||
| 157 | to be more than one network running. | ||
| 158 | |||
| 159 | This value can be set in the initilizer. | ||
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | =head1 AUTHOR | ||
| 164 | |||
| 165 | Paul G Webster, C<< <daemon at cpan.org> >> | ||
| 166 | |||
| 167 | =head1 BUGS | ||
| 168 | |||
| 169 | We don't have these! | ||
| 170 | |||
| 171 | Incase we are wrong though report any bugs or feature requests to | ||
| 172 | L<https://github.com/PaulGWebster/p5-POE-Component-FunctionBus/issues>. | ||
| 173 | |||
| 174 | I will be notified, and then you'll automatically be notified | ||
| 175 | of progress on your bug as I make changes. | ||
| 176 | |||
| 177 | =head1 SUPPORT | ||
| 178 | |||
| 179 | You can find documentation for this module with the perldoc | ||
| 180 | command. | ||
| 181 | |||
| 182 | perldoc POE::Component::FunctionBus | ||
| 183 | |||
| 184 | You can also look for information at: | ||
| 185 | |||
| 186 | =over 4 | ||
| 187 | |||
| 188 | =item * Github: Authors repository | ||
| 189 | |||
| 190 | L<https://github.com/PaulGWebster/p5-POE-Component-FunctionBus> | ||
| 191 | |||
| 192 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 193 | |||
| 194 | L<http://annocpan.org/dist/POE-Component-FunctionBus> | ||
| 195 | |||
| 196 | =item * CPAN Ratings | ||
| 197 | |||
| 198 | L<https://cpanratings.perl.org/d/POE-Component-FunctionBus> | ||
| 199 | |||
| 200 | =item * Search CPAN | ||
| 201 | |||
| 202 | L<https://metacpan.org/release/POE-Component-FunctionBus> | ||
| 203 | |||
| 204 | =back | ||
| 205 | |||
| 206 | |||
| 207 | =head1 ACKNOWLEDGEMENTS | ||
| 208 | |||
| 209 | =over 2 | ||
| 210 | |||
| 211 | =item Rocco Caputo | ||
| 212 | |||
| 213 | Rocco Caputo is <rcaputo@cpan.org>. POE is his brainchild. He wishes | ||
| 214 | to thank you for your interest, and he has more thanks than he can | ||
| 215 | count for all the people who have contributed. POE would not be | ||
| 216 | nearly as cool without you. | ||
| 217 | |||
| 218 | Except where otherwise noted, POE is Copyright 1998-2013 Rocco Caputo. | ||
| 219 | All rights reserved. POE is free software; you may redistribute it | ||
| 220 | and/or modify it under the same terms as Perl itself. | ||
| 221 | |||
| 222 | =back | ||
| 223 | |||
| 224 | =head1 LICENSE AND COPYRIGHT | ||
| 225 | |||
| 226 | This software is Copyright (c) 2019 by Paul G Webster. | ||
| 227 | |||
| 228 | This is free software, licensed under: | ||
| 229 | |||
| 230 | The (three-clause) BSD License | ||
| 231 | |||
| 232 | |||
| 233 | =head1 DEVELOPER SECTION | ||
| 234 | |||
| 235 | This section is because this module is under heavy development, really its just | ||
| 236 | notes to my self on what I am planning to do - examples and other bits and | ||
| 237 | peices. (or total junk) | ||
| 238 | |||
| 239 | Anything in this section should never be reffered to as once this module hits | ||
| 240 | release this section will vanish. | ||
| 241 | |||
| 242 | =head2 TODO | ||
| 243 | |||
| 244 | =head3 AF_UNIX local pools | ||
| 245 | |||
| 246 | make it so /var/functionbus.pid.sock (pid representing the master perl process) | ||
| 247 | is contactable | ||
| 248 | |||
| 249 | =head3 detailed protocol spec | ||
| 250 | |||
| 251 | Write down precisely what is required to talk on one of these networks so other | ||
| 252 | people have half a prayer of using it in other languages, maybe write a csharp | ||
| 253 | module? maybe kick python/java friends to do the same hmmm | ||
| 254 | |||
| 255 | =head2 functions | ||
| 256 | |||
| 257 | =head3 _start | ||
| 258 | |||
| 259 | Start a session and setup the initial enviroment | ||
| 260 | |||
| 261 | =cut | ||
| 262 | |||
| 263 | 0 | ▶ | sub _start { |
|
Subroutine
_start: not called CC=1 SCAR=6.9
| |||
| 264 | 0 | my ($kernel,$heap) = @_[KERNEL,HEAP]; | |
| 265 | |||
| 266 | # This is a hack because we do not trust alias. | ||
| 267 | 0 | $kernel->yield('_keep_alive'); | |
| 268 | } | ||
| 269 | |||
| 270 | =head3 _stop | ||
| 271 | |||
| 272 | Called when the main POE::Session stops ... tidying up | ||
| 273 | |||
| 274 | =cut | ||
| 275 | |||
| 276 | 0 | ▶ | sub _stop { |
|
Subroutine
_stop: not called CC=1 SCAR=6.9
| |||
| 277 | 0 | my ($kernel,$heap) = @_[KERNEL,HEAP]; | |
| 278 | |||
| 279 | |||
| 280 | } | ||
| 281 | |||
| 282 | =head3 _start | ||
| 283 | |||
| 284 | Start a session and setup the initial enviroment | ||
| 285 | |||
| 286 | =cut | ||
| 287 | |||
| 288 | 0 | ▶ | sub _keep_alive { |
|
Subroutine
_keep_alive: not called CC=1 SCAR=6.9
| |||
| 289 | 0 | my ($kernel,$heap) = @_[KERNEL,HEAP]; | |
| 290 | |||
| 291 | 0 | warn "keepalive"; | |
| 292 | 0 | $kernel->delay_add('_keep_alive' => 1); | |
| 293 | } | ||
| 294 | |||
| 295 | 1 | 1; # End of POE::Component::FunctionBus | |