Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: introduce ClientConn and ServerConn interfaces #4905

Merged
merged 8 commits into from Apr 4, 2016
Merged

rpc: introduce ClientConn and ServerConn interfaces #4905

merged 8 commits into from Apr 4, 2016

Conversation

davecheney
Copy link
Contributor

This PR is in preparation for adding tests for retrying temporary RPC errors.

It introduces two new interface types, rpc.ClientConn and rpc.ServerConn whose purposes are self explanatory. Also provide constructor functions for these new interface types as NewConn has been unexported.

Remove the ability to provide a RequestNotifier when requesting a ClientConn, this was never used by any non test caller and is only part of the bidirectional code for the rpc package, which is also unused by juju.

Adjust the callers in the api and apiserver packages to these new interfaces, very few changes were needed apart from adjusting the types in various wrapper types.

The bidirection nature of the rpc package remains, but if needed the caller must assert their ServerConn value to a ClientConn, or vice versa. No code in Juju does this, but the rpc tests assert this behaviour

Finally, unexport rpc.Conn.

The underlying rpc.Conn is bidirectional, but in our use case we always
send requests from the client to the server which responds.

Hide rpc.NewConn and replace it with a pair of NewClientConn and
NewServerConn methods to deliniate the method sets of both types so they
can be mocked.
ClientConn.Start is always called on return from rpc.NewClientConn, so
just make NewClientConn call Start before returning. This simplifies the
rpc client API.
@@ -234,7 +235,7 @@ func (a *CallbackMethods) Factorial(x int64val) (int64val, error) {
return int64val{1}, nil
}
var r int64val
err := a.root.conn.Call(rpc.Request{"CallbackMethods", 0, "", "Factorial"}, int64val{x.I - 1}, &r)
err := a.root.conn.(rpc.ClientConn).Call(rpc.Request{"CallbackMethods", 0, "", "Factorial"}, int64val{x.I - 1}, &r)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please make this two lines?

client := a.root.conn.(rpc.ClientConn)
err := client.Call(...)

@howbazaar
Copy link
Contributor

The diff was much larger than necessary due to the renaming the receiver of 'conn' -> 'c'.

However, LGTM with one suggestion.

@davecheney
Copy link
Contributor Author

The diff was much larger than necessary due to the renaming the receiver of 'conn' -> 'c'.

That's because conn became a type, so it couldn't also be the name of the receiver.

@davecheney
Copy link
Contributor Author

$$merge$$

@jujubot
Copy link
Collaborator

jujubot commented Apr 3, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit da28cfa into juju:api-call-retry Apr 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants