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

NAME

Argon::Stream

SYNOPSIS

    use Coro::Handle;
    use Argon::Stream;

    # Create a stream manually
    my $stream = Argon::Stream->new(
        in_chan  => unblock(*STDIN),
        out_chan => unblock(*STDOUT),
    );

    # Create stream by directly connecting to a remote host
    my $stream = Argon::Stream->connect(host => 'someserver', port => 8888);

    # Create stream from a single existing 2-way channel (e.g. a socket)
    my $stream = Argon::Stream->create($sock);

    # Send a message and wait for a response (yields to Coro loop).
    my $reply = $stream->send($msg);

    # Send a message manually
    $stream->send_message($msg);

    # Get the reply
    my $reply = $stream->receive;

    # Disconnect
    $stream->close;

DESCRIPTION

Argon::Stream wraps an input and output handle to make sending and receiving messages easier. It also facilitates some of the monitoring between Argon::Cluster and Argon::Node objects.

METHDOS

new(in_chan => Coro::Handle, out_chan => Coro::Handle)

Creates a new Argon::Stream using two Coro::Handle objects. Note that neither handle is required, allowing unidirectional streams to be created.

create(IO::Handle)

Creates a new Argon::Stream using a single, bidirectional IO::Handle object.

connect(host => 'someserver', port => 8888)

Creates a new Argon::Stream by connecting directly to a remote host.

monitor($on_fail)

Begins monitoring the channel for connectivity. WARNING: this method assumes that the other end of the connection is controlled by an Argon::Stream as well. If connectivity breaks, subroutine $on_fail is triggered with two arguments: the stream object and the error message.

address()

Returns the address of this stream. Note that this is NOT just the URL or IP address. Since the stream is composed of (possibly) two handles, this is simply an identifier that may be used to uniquely identify the stream as well as to create a human-readable description of it.

send_message($msg)

Sends an Argon::Message. Croaks if not connected or if the output handle has not been configured.

receive()

Blocks until the next Argon::Message is available on the stream. Croaks if an input handle has not been configured.

send($msg)

Sends an Argon::Message and returns the response (another Argon::Message). Blocks until the response is available. Croaks if either the output or input handles have not been configured.

close()

Closes and disconnects the stream. The instance is not left in a useable or reconnectable state.

AUTHOR

Jeff Ober mailto:jeffober@gmail.com

LICENSE

BSD license