| 1 | package Voldemort::ProtoBuff::PutMessage; | ||
| 2 | |||
| 3 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use IO::Select; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use Scalar::Util qw(reftype); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 1 | ▶ | use Voldemort::Message; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 0 | ▶ | use Voldemort::ProtoBuff::Spec2; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use Voldemort::ProtoBuff::BaseMessage; | ||
| 11 | |||
| 12 | extends 'Voldemort::ProtoBuff::BaseMessage'; | ||
| 13 | |||
| 14 | sub write { | ||
| 15 | my $self = shift; | ||
| 16 | my $connection = shift; | ||
| 17 | my $store = shift; | ||
| 18 | my $key = shift; | ||
| 19 | my $value = shift; | ||
| 20 | my $node = shift || 0; | ||
| 21 | |||
| 22 | my $entries = $self->_get_entries($node); | ||
| 23 | |||
| 24 | my $data = Voldemort::ProtoBuff::Spec2::VoldemortRequest->encode( | ||
| 25 | { | ||
| 26 | 'type' => Voldemort::ProtoBuff::Spec2::RequestType::PUT(), | ||
| 27 | 'store' => $store, | ||
| 28 | 'put' => Voldemort::ProtoBuff::Spec2::PutRequest->new( | ||
| 29 | { | ||
| 30 | versioned => Voldemort::ProtoBuff::Spec2::Versioned->new( | ||
| 31 | { | ||
| 32 | value => $value, | ||
| 33 | version => | ||
| 34 | Voldemort::ProtoBuff::Spec2::VectorClock->new( | ||
| 35 | { | ||
| 36 | timestamp => time(), | ||
| 37 | entries => $entries | ||
| 38 | } | ||
| 39 | ) | ||
| 40 | } | ||
| 41 | ), | ||
| 42 | key => $key | ||
| 43 | } | ||
| 44 | ) | ||
| 45 | } | ||
| 46 | ); | ||
| 47 | |||
| 48 | $connection->send( pack( 'N', length($data) ) ); | ||
| 49 | $connection->send($data); | ||
| 50 | return; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub read { | ||
| 54 | my $self = shift; | ||
| 55 | my $connection = shift; | ||
| 56 | my $store = shift; | ||
| 57 | my $key = shift; | ||
| 58 | |||
| 59 | my $size = $connection->recv(4); | ||
| 60 | $size = unpack( 'N', $size ); | ||
| 61 | return if !$size; | ||
| 62 | |||
| 63 | my $data = $connection->recv($size); | ||
| 64 | $data = Voldemort::ProtoBuff::Spec2::PutResponse->decode($data) || carp($!); | ||
| 65 | return $data->{'error'}->{'error_code'}, | ||
| 66 | $data->{'error'}->{'error_message'}; | ||
| 67 | } | ||
| 68 | 1; | ||
| 69 | |||