OLD | NEW |
1 // Copyright 2012, 2013 Canonical Ltd. | 1 // Copyright 2012, 2013 Canonical Ltd. |
2 // Licensed under the AGPLv3, see LICENCE file for details. | 2 // Licensed under the AGPLv3, see LICENCE file for details. |
3 | 3 |
4 package rpc | 4 package rpc |
5 | 5 |
6 import ( | 6 import ( |
7 "fmt" | 7 "fmt" |
8 "io" | 8 "io" |
9 "reflect" | 9 "reflect" |
10 "sync" | 10 "sync" |
11 | 11 |
12 » "launchpad.net/juju-core/log" | 12 » "launchpad.net/loggo" |
| 13 |
13 "launchpad.net/juju-core/rpc/rpcreflect" | 14 "launchpad.net/juju-core/rpc/rpcreflect" |
14 ) | 15 ) |
15 | 16 |
| 17 var logger = loggo.GetLogger("juju.rpc") |
| 18 |
16 // A Codec implements reading and writing of messages in an RPC | 19 // A Codec implements reading and writing of messages in an RPC |
17 // session. The RPC code calls WriteMessage to write a message to the | 20 // session. The RPC code calls WriteMessage to write a message to the |
18 // connection and calls ReadHeader and ReadBody in pairs to read | 21 // connection and calls ReadHeader and ReadBody in pairs to read |
19 // messages. | 22 // messages. |
20 type Codec interface { | 23 type Codec interface { |
21 // ReadHeader reads a message header into hdr. | 24 // ReadHeader reads a message header into hdr. |
22 ReadHeader(hdr *Header) error | 25 ReadHeader(hdr *Header) error |
23 | 26 |
24 // ReadBody reads a message body into the given body value. The | 27 // ReadBody reads a message body into the given body value. The |
25 // isRequest parameter specifies whether the message being read | 28 // isRequest parameter specifies whether the message being read |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 227 } |
225 } | 228 } |
226 conn.mutex.Unlock() | 229 conn.mutex.Unlock() |
227 | 230 |
228 // Wait for any outstanding server requests to complete | 231 // Wait for any outstanding server requests to complete |
229 // and write their replies before closing the codec. | 232 // and write their replies before closing the codec. |
230 conn.srvPending.Wait() | 233 conn.srvPending.Wait() |
231 | 234 |
232 // Closing the codec should cause the input loop to terminate. | 235 // Closing the codec should cause the input loop to terminate. |
233 if err := conn.codec.Close(); err != nil { | 236 if err := conn.codec.Close(); err != nil { |
234 » » log.Infof("rpc: error closing codec: %v", err) | 237 » » logger.Infof("error closing codec: %v", err) |
235 } | 238 } |
236 <-conn.dead | 239 <-conn.dead |
237 return conn.inputLoopError | 240 return conn.inputLoopError |
238 } | 241 } |
239 | 242 |
240 // ErrorCoder represents an any error that has an associated | 243 // ErrorCoder represents an any error that has an associated |
241 // error code. An error code is a short string that represents the | 244 // error code. An error code is a short string that represents the |
242 // kind of an error. | 245 // kind of an error. |
243 type ErrorCoder interface { | 246 type ErrorCoder interface { |
244 ErrorCode() string | 247 ErrorCode() string |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 conn.sending.Lock() | 408 conn.sending.Lock() |
406 defer conn.sending.Unlock() | 409 defer conn.sending.Unlock() |
407 if rv.IsValid() { | 410 if rv.IsValid() { |
408 rvi = rv.Interface() | 411 rvi = rv.Interface() |
409 } else { | 412 } else { |
410 rvi = struct{}{} | 413 rvi = struct{}{} |
411 } | 414 } |
412 err = conn.codec.WriteMessage(hdr, rvi) | 415 err = conn.codec.WriteMessage(hdr, rvi) |
413 } | 416 } |
414 if err != nil { | 417 if err != nil { |
415 » » log.Errorf("rpc: error writing response: %v", err) | 418 » » logger.Errorf("error writing response: %v", err) |
416 } | 419 } |
417 } | 420 } |
OLD | NEW |