.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "IKC 3" .TH IKC 3 2024-09-01 "perl v5.40.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME POE::Component::IKC \-\- POE Inter\-Kernel Communication .SH SYNOPSIS .IX Header "SYNOPSIS" .SS "IKC server" .IX Subsection "IKC server" .Vb 6 \& use POE::Component::IKC::Server; \& # create all your sessions \& POE::Component::IKC::Server\->spawn( \& port=>30, name=>\*(AqServer\*(Aq \& ); # more options are available \& $poe_kernel\->run(); .Ve .SS "IKC client" .IX Subsection "IKC client" .Vb 1 \& use POE::Component::IKC::Client; \& \& POE::Component::IKC::Client\->spawn( \& host=>name, \& port=>30, \& name=>\*(AqClient\*(Aq, \& on_connect=>\e&build); \& $poe_kernel\->run(); \& \& sub build \& { \& # create sessions that depend on the foreign kernel. \& } .Ve .SS "Post a state on a foreign kernel" .IX Subsection "Post a state on a foreign kernel" .Vb 1 \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqpost\*(Aq, "poe://Server/session/state", $ONE_arg); .Ve .SS "The IKC is peer-to-peer." .IX Subsection "The IKC is peer-to-peer." Server can post to client. .PP .Vb 1 \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqpost\*(Aq, \*(Aqpoe://Client/session/state\*(Aq, $ONE_arg); .Ve .SS "Call a state on a remote kernel" .IX Subsection "Call a state on a remote kernel" Call semantics are impossible, because they would cause POE to block. IKC call is a bit different. It is a 'post', but with an extra RSVP parameter. .PP .Vb 2 \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqcall\*(Aq, \*(Aqpoe://Server/hello/world\*(Aq, $ONE_arg, \& \*(Aqpoe:callback\*(Aq); .Ve .PP This will cause the returned value of the foreign state to be sent to state \&'callback' in the current session. You may want the callback to be in another session, but I don't think this is a good idea. .PP .Vb 2 \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqcall\*(Aq, \*(Aqpoe://Server/hello/world\*(Aq, $ONE_arg, \& \*(Aqpoe:/elsewhere/hi\*(Aq); .Ve .PP Note : if you use \->call('IKC'), it will return the number of foreign kernels the state was sent to. This is a handy way to find out if you are still connected to a foreign kernel. .SS "A little magic" .IX Subsection "A little magic" If a state is posted by a foreign kernel, \f(CW$_\fR[SENDER] is only valid during that state. However, you will be able to post back to it. .PP .Vb 1 \& $kernel\->post($_[SENDER], \*(Aqsomething\*(Aq, \*(Aqthe answer is foo\*(Aq); .Ve .PP The remote caller MUST have published states for them to be callable, eh? .SS "Publish / Subscribe" .IX Subsection "Publish / Subscribe" You must publish a session's interface for it to be available to remote kernels. .PP If you subscribe to a remote session, you may access it as if it was a local session. .PP First, a session publishes its interfaces: .PP .Vb 2 \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqpublish\*(Aq, \*(Aqsession_alias\*(Aq, \& [qw(state1 state2 state3 state4)], ); .Ve .PP Then a foreign kernel subscribes to it: .PP .Vb 6 \& # Look for a session on all known foreign kernels \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqsubscribe\*(Aq, [qw(poe://*/session_alias/)]); \& # Look for a session on a specific foreign kernel \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqsubscribe\*(Aq, [qw(poe://Pulse/timeserver)]); \& # Make sure the session has a given state \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqsubscribe\*(Aq, [qw(poe://*/timeserver/connect)]); .Ve .PP After subscription, a proxy session is created that can be accessed like any old session, though \->\fBcall()\fR acts the same as \->\fBpost()\fR for obvious reasons: .PP .Vb 1 \& $kernel\->post(\*(Aqpoe:/Pulse/timeserver\*(Aq, \*(Aqstate\*(Aq, $arg1, $arg2...); .Ve .PP Currently, the session alias used by post to the proxy session must be the same one as used when subscribing. Because kernels have multiple names, if you are using '*' as the kernel name when subscribing, the session alias might not be what you think it is. See "Monitor" for details. .PP Of course, attempting to post to a proxy session before it is created will be problematic. To be alerted when the proxy session is created, a callback state may be specified, .PP .Vb 2 \& $kernel\->post(\*(AqIKC\*(Aq, \*(Aqsubscribe\*(Aq, [qw(poe://*/timeserver)], \& \*(Aqtimeserver_subscribed\*(Aq); .Ve .PP The callback will be called with a list of all the sessions that it managed to subscribe to. You should check this list before continuing. Better yet, you could use the IKC monitor (see below). .PP One can also let POE::Component::IKC::Client\->spawn deal with all the details. .PP .Vb 5 \& POE::Component::IKC::Client\->spawn( \& port=>31337, name=>$name, \& subscribe=>[qw(poe://*/timeserver)], \& on_connect=>\e&create_me, \& ); .Ve .PP \&'on_connect' is only called when all the subscriptions have either been accepted. If a subscription was refused, create_ikc_client will give up. If multiple foreign kernels where quieried for a session (as is the case above), subscription is deemed to succeed if at least one foreign kernel accepts the subscription. .PP To undo things : .PP .Vb 1 \& $kernel\->post(IKC=>\*(Aqretract\*(Aq, \*(Aqsession_alias\*(Aq=>[qw(states)]); \& \& $kernel\->post(IKC=>\*(Aqunsubscribe\*(Aq, [qw(poe://Pulse/timeserver)]); .Ve .SS Monitor .IX Subsection "Monitor" Say you wanted to monitor all remote kernels that connect to you: .PP .Vb 1 \& $kernel\->post(IKC=>\*(Aqmonitor\*(Aq, \*(Aq*\*(Aq=>{register=>\*(Aqsome_event\*(Aq}); \& \& sub some_event \& { \& my($name, $real)=@_[ARG1, ARG2]; \& print "\- Remote kernel ", ($real ? \*(Aq\*(Aq : "alias "), "$name connected\en"; \& } .Ve .PP Later, you want to know when a given remote session disconnects: .PP .Vb 1 \& $kernel\->post(IKC=>\*(Aqmonitor\*(Aq, some_kernel=>{unregister=>\*(Aqbye_bye\*(Aq}); .Ve .PP Or maybe you think a session should clean up and leave whenever IKC does. .PP .Vb 1 \& $kernel\->post(IKC=>\*(Aqmonitor\*(Aq, \*(Aq*\*(Aq=>{shutdown=>\*(Aqother_event\*(Aq}); \& \& sub other_event \& { \& # kill wheels, alarms, selects and aliases here \& } .Ve .PP See "monitor" in POE::Component::IKC::Responder for more details. .SS Shutdown .IX Subsection "Shutdown" When you feel the time is right and you want to get rid of all IKC-related sessions, just do the following: .PP .Vb 1 \& $kernel\->post(IKC=>\*(Aqshutdown\*(Aq); .Ve .PP And they should all disapear. At worst, some will still have registered alises, but this won't prevent the kernel from exiting. .SS "The local kernel" .IX Subsection "The local kernel" You can post to the local kernel as if it was remote: .PP .Vb 2 \& $kernel\->post(IKC=>\*(Aqpost\*(Aq, \& "poe://$kernel\->ID/session/state\*(Aq=>$ONE_arg); .Ve .PP However, you can't currently subscribe to local sessions. I don't know how I'm going to resolve this. .SH DESCRIPTION .IX Header "DESCRIPTION" This is Inter-Kernel Communication for POE. It is used to get events from one POE kernel to another .SH "SEE ALSO" .IX Header "SEE ALSO" POE::Component::IKC::Responder \-\- Heart of the system .PP POE::Component::IKC::Server \-\- Create a process that listens for other kernels. .PP POE::Component::IKC::Client \-\- Create a process that connects to other kernels. .PP POE::Component::IKC::ClientLite \-\- Light weight IKC implementation for places you can't use POE, such as mod_perl. .PP POE::Component::IKC::Channel \-\- Handle communcation with other kernels. .PP POE::Component::IKC::Proxy \-\- Proxy session that is created when you subscribe to a remote session. .PP POE::Component::IKC::Freezer \-\- Pure-Perl serialization method. .PP POE::Component::IKC::Specifier \-\- Helper routines for parsing IKC specifiers. .SH AUTHOR .IX Header "AUTHOR" Philip Gwyn .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 1999\-2014 by Philip Gwyn. All rights reserved. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See