.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 turned on, 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "IKC 3pm" .TH IKC 3pm "2014-05-16" "perl v5.18.2" "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 "\s-1IKC\s0 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 "\s-1IKC\s0 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 \s-1IKC\s0 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 \s-1POE\s0 to block. \s-1IKC\s0 call is a bit different. It is a 'post', but with an extra \s-1RSVP\s0 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('\s-1IKC\s0'), 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[\s-1SENDER\s0] 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 \s-1MUST\s0 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 \->\fIcall()\fR acts the same as \->\fIpost()\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 \*(L"Monitor\*(R" 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 \s-1IKC\s0 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 \s-1IKC\s0 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 \*(L"monitor\*(R" 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 \s-1POE. \s0 It is used to get events from one \s-1POE\s0 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 \s-1IKC\s0 implementation for places you can't use \s-1POE,\s0 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 \s-1IKC\s0 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