Support for add_pool_from_ring() #1 self->{pool}Support for add_pool_from_ring() #1 #4

Merged
merged 1 commit into from Feb 8, 2012
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 );