Permalink
Browse files

Support for add_pool_from_ring() #2

  • Loading branch information...
1 parent de6f1bf commit d0175e2138898d954b3087c49a2b940c52718868 @jcbf jcbf committed Feb 7, 2012
Showing with 17 additions and 4 deletions.
  1. +17 −4 lib/Cassandra/Pool.pm
View
21 lib/Cassandra/Pool.pm
@@ -47,26 +47,39 @@ sub new {
$loadbalancer->add_pool(
ResourcePool->new( Cassandra::Pool::CassandraServerFactory->new($opt) )
);
+ $self->{pool} = $loadbalancer;
+ $self->{rcp_opts} = $opt;
+
+ $self = bless( $self, $class );
+
+ return $self;
+}
+
+sub add_pool_from_ring {
+ my $self = shift;
+ my $keyspace = $self->{rcp_opts}->{keyspace};
if ($keyspace) {
- my @nodes = @{ $loadbalancer->get()->describe_ring($keyspace) };
+ my @nodes = @{ $self->{pool}->get()->describe_ring($keyspace) };
foreach (
map {
map { split( /\//, $_ ) } @{ $_->{rpc_endpoints} }
} @nodes
)
{
- next if $opt->{server_name} eq $_;
- my %params = %$opt;
+ next if $self->{rcp_opts}->{server_name} eq $_;
+ my %params = %{$self->{rcp_opts}};
+
$params{server_name} = $_;
- $loadbalancer->add_pool(
+ $self->{pool}->add_pool(
ResourcePool->new(
Cassandra::Pool::CassandraServerFactory->new( \%params ),
PreCreate => 2
)
);
}
}
+
$self->{pool} = $loadbalancer;
$self = bless( $self, $class );

0 comments on commit d0175e2

Please sign in to comment.