The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Message::Passing::Role::ConnectionManager - A simple manager for inputs and outputs that need to make network connections.

DESCRIPTION

This role is for components which make network connections, and need to handle the connection not starting, timeouts, disconnects etc.

It provides a simple abstraction for multiple other classes to be able to use the same connection manager, and a notifies

REQUIRED METHODS

_build_connection

Build and return the connection we're managing, start the connection process.

Your connection should use the API as documented below to achieve notification of connect and disconnect events.

API FOR CONNECTIONS

_set_connected (1)

Notify clients that the connection is now ready for use.

_set_connected (0)

Notify clients that the connection is no longer ready for use.

Will cause the connection to be terminated and retried.

API FOR CLIENTS

To use a connection manager, you should register yourself like this:

    $manager->subscribe_to_connect($self);

The manager will call $self->connected($connection) and $self->disconnected() when appropriate.

If the manager is already connected when you subscribe, it will immediately call back into your connected method, if it is not already connected then this will happen at a later point once the connection is established.

See Message::Passing::Role::HasAConnection for a role to help with dealing with a connection manager.

ATTRIBUTES

connected

A Boolean indicating if the connection is currently considered fully connected

connection

The connection object (if we are connected, or connecting currently) - can be undefined if we are during a reconnect timeout.

METHODS

subscribe_to_connect