Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

What I've done (maybe temporary) is to use main to spawn a package called LeafBridge::Client within the main thread and use that to spawn the LeafBridge::Client::Controller apartment. On spawn of this controller, I pass in the handle to $self (LB::Client). LB::C::Controller spawns all of the other apartments by calling $client->spawnApartment($controllerClient). $client being the LB::Client handle that was passed in and $controllerClient being the T::A::Client handle. That spawnApartment is called in the context of the LB::C::Controller apartment thread, not in the main thread. Since LB::Client doesn't do anything except run a loop that calls $controller->tick every second, it doesn't really do anything else but provide access to the apartment creation functions and to create the first apartment (LB::C::Controller). LB::C::Controller tracks all apartment threads and allows any apartment to talk to any other apartment by calling $controller->thread('LeafBridge::Client::XMPP')->send(@args) (the thread method passes the T::A::Client handle of the LB::C::XMPP apartment to the caller; send() is a method within the LB::C::XMPP apartment itself (it could be any arbitrary method in the requested apartment thread)). It seems to work well for now. It feels hackish, but it's the best I could do with the knowledge I have right now.


I'm a Linux user. You wouldn't know it since I mostly ask Windows questions. Whee.
If you want to do evil, science provides the most powerful weapons to do evil; but equally, if you want to do good, science puts into your hands the most powerful tools to do so.
- Richard Dawkins

In reply to Re^2: Thread::Apartment, how do I use main:: subs? by wilsond
in thread Thread::Apartment, how do I use main:: subs? by wilsond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-20 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found