… | |
… | |
995 | |
995 | |
996 | If your head is spinning by now, that's fine - just keep in mind, after |
996 | If your head is spinning by now, that's fine - just keep in mind, after |
997 | creating a port, monitor "the other side" from it, and all will be cleaned |
997 | creating a port, monitor "the other side" from it, and all will be cleaned |
998 | up just fine. |
998 | up just fine. |
999 | |
999 | |
1000 | =head1 PART 4: Services |
1000 | =head2 Services |
1001 | |
1001 | |
1002 | #TODO |
1002 | Above it was mentioned that C<spawn> automatically loads modules, and this |
|
|
1003 | can be exploited in various ways. |
|
|
1004 | |
|
|
1005 | Assume for a moment you put the server into a file called |
|
|
1006 | F<mymod/chatserver.pm> reachable from the current directory. Then you |
|
|
1007 | could run a node there with: |
|
|
1008 | |
|
|
1009 | aemp run |
|
|
1010 | |
|
|
1011 | The other nodes could C<spawn> the server by using |
|
|
1012 | C<mymod::chatserver::client_connect> as init function. |
|
|
1013 | |
|
|
1014 | Likewise, when you have some service that starts automatically (similar to |
|
|
1015 | AnyEvent::MP::Global), then you can configure this service statically: |
|
|
1016 | |
|
|
1017 | aemp profile mysrvnode services mymod::service:: |
|
|
1018 | aemp run profile mysrvnode |
|
|
1019 | |
|
|
1020 | And the module will automatically be started in the node. |
|
|
1021 | |
|
|
1022 | Of course, you can also do it in the much more standard way by writing |
|
|
1023 | a module (e.g. C<BK::Backend::IRC>), installing it as part of a module |
|
|
1024 | distribution and then configure nodes, for example, if I want to run the |
|
|
1025 | Bummskraut IRC backend on a machine named "ruth", I could do this: |
|
|
1026 | |
|
|
1027 | aemp profile ruth addservice BK::Backend::IRC:: |
|
|
1028 | |
|
|
1029 | And any F<aemp run> on that host will automaticlaly have the bummskraut |
|
|
1030 | irc backend running. |
|
|
1031 | |
|
|
1032 | That's plenty of possibilities you can use - it's all up to you how you |
|
|
1033 | structure your application. |
1003 | |
1034 | |
1004 | =head1 SEE ALSO |
1035 | =head1 SEE ALSO |
1005 | |
1036 | |
1006 | L<AnyEvent::MP> |
1037 | L<AnyEvent::MP> |
1007 | |
1038 | |