Steffen Müller > ZMQ-Declare > ZMQ::Declare::Device

Download:
ZMQ-Declare-0.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.03   Source  

NAME ^

ZMQ::Declare::Device - A ZMQ::Declare Device object

SYNOPSIS ^

  use ZMQ::Declare;
  # See synopsis for ZMQ::Declare

DESCRIPTION ^

Instances of this class represent a single 0MQ device. With less 0MQ jargon, that means they represent a single component of your network of things that interact using 0MQ sockets.

You typically obtain these objects by calling the device method on a ZMQ::Declare::Application object. It is important to note that a ZMQ::Declare::Device object contains no runtime 0MQ components like sockets or 0MQ contexts and maintains no network connections. This is to say that you can create and use ZMQ::Declare::Device in an abstract, offline way.

Shit gets real once you call the run() or make_runtime methods on a ZMQ::Declare::Device: Those methods will (the former implicitly, the latter explicitly) construct a ZMQ::Declare::Device::Runtime object, create a threading context, create sockets, and make connections.

The ZMQ::Declare::Device::Runtime object will then hold the actual references to the underlying 0MQ objects.

This clear split should make it easy for users to know when they are handling live or abstract devices.

PROPERTIES ^

These are accessible with normal mutator methods.

name

The name of the device. This is required to be unique in a ZDCF context and cannot be context.

typename

The type of the device that's represented by the object. Types starting with z are reserved for core 0MQ devices.

The device type is optional as of ZDCF spec version 1.0.

Read-only.

implementation

The code-reference that is to be invoked by the run() method of the object. This needs to be set by the user before calling run(). The code-reference will be called by run() with a ZMQ::Declare::Device::Runtime object as first argument.

application

A reference to the underlying ZMQ::Declare::Application object.

Read-only.

METHODS ^

new

Constructor taking named arguments (see properties above). Typically, you should obtain your ZMQ::Declare::Device objects by calling device($devicename) on a ZMQ::Declare::Application object instead of using new().

run

Requires that an implementation has been set previously (see the implementation property above).

Accepts named arguments and currently only accepts the nforks option which, if it is larger or equal to two, will fork off nforks child processes before doing any further setup. The parent will return from run() after all children have been reaped. Each child will perform the actions described below.

Calls make_runtime to obtain a new ZMQ::Declare::Device::Runtime.

Then, it invokes the CODE reference that is stored in the implementation property and passes the ZMQ::Declare::Device::Runtime object as first argument.

make_runtime

Creates a ZMQ::Declare::Device::Runtime object to hold a 0MQ threading context and all 0MQ socket objects. It sets up the context, creates the sockets, configures the sockets, binds the sockets to bind-endpoints, then finally connects the sockets to connect-endpoints.

Returns the Runtime object. Once that object goes out of scope, all connections will be disconnected.

SEE ALSO ^

ZeroMQ

ZMQ::Declare, ZMQ::Declare::Device::Runtime, ZMQ::Declare::Application

AUTHOR ^

Steffen Mueller <smueller@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2011,2012 by Steffen Mueller

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: