1package DJabberd::Cluster;
2use strict;
3use base 'DJabberd::Plugin';
4use DJabberd::Queue::ClusterOut;
5
6sub register {
7    my ($self, $vhost) = @_;
8    $self->{vhost} = $vhost;
9
10    $vhost->register_hook("ClusterDeliverMessage", sub {
11        my (undef, $cb, $barejid, $message) = @_;
12        $self->deliver_cluster_message($barejid, $message, $cb);
13    });
14}
15
16# protocol:
17#    4 bytes  -- MAGIC
18#    length, barejid
19#    length, handler func  ???
20#    length, opaque data (if a ref, we storable/thaw it)
21
22# don't subclass.
23sub deliver_star {
24    my ($self, $barejid, $endpts_list, $cb) = @_;
25    # $cb can ->done, ->error
26}
27
28# subclass if you're Spread or have a fancy message bus.
29sub deliver_message {
30    my ($self, $barejid, $message, $cb) = @_;
31    if ($self->can('find_barejid_locations')) {
32        my @endpts = $self->find_barejid_locations($barejid);
33        $self->deliver_star($barejid, \@endpts, $cb);
34    }
35    $cb->error;
36}
37
38# subclass if you're lazy and want to use a star delivery topology
39#sub find_barejid_locations {
40#}
41
421;
43