Commit 74f018df authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer/rpc: make newXWithMuxConn private

parent f06cd56e
...@@ -40,7 +40,7 @@ func (b *build) Prepare(v map[string]string) ([]string, error) { ...@@ -40,7 +40,7 @@ func (b *build) Prepare(v map[string]string) ([]string, error) {
func (b *build) Run(ui packer.Ui, cache packer.Cache) ([]packer.Artifact, error) { func (b *build) Run(ui packer.Ui, cache packer.Cache) ([]packer.Artifact, error) {
nextId := b.mux.NextId() nextId := b.mux.NextId()
server := NewServerWithMux(b.mux, nextId) server := newServerWithMux(b.mux, nextId)
server.RegisterCache(cache) server.RegisterCache(cache)
server.RegisterUi(ui) server.RegisterUi(ui)
go server.Serve() go server.Serve()
...@@ -52,7 +52,7 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) ([]packer.Artifact, error) ...@@ -52,7 +52,7 @@ func (b *build) Run(ui packer.Ui, cache packer.Cache) ([]packer.Artifact, error)
artifacts := make([]packer.Artifact, len(result)) artifacts := make([]packer.Artifact, len(result))
for i, streamId := range result { for i, streamId := range result {
client, err := NewClientWithMux(b.mux, streamId) client, err := newClientWithMux(b.mux, streamId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -96,7 +96,7 @@ func (b *BuildServer) Prepare(v map[string]string, resp *BuildPrepareResponse) e ...@@ -96,7 +96,7 @@ func (b *BuildServer) Prepare(v map[string]string, resp *BuildPrepareResponse) e
} }
func (b *BuildServer) Run(streamId uint32, reply *[]uint32) error { func (b *BuildServer) Run(streamId uint32, reply *[]uint32) error {
client, err := NewClientWithMux(b.mux, streamId) client, err := newClientWithMux(b.mux, streamId)
if err != nil { if err != nil {
return NewBasicError(err) return NewBasicError(err)
} }
...@@ -110,7 +110,7 @@ func (b *BuildServer) Run(streamId uint32, reply *[]uint32) error { ...@@ -110,7 +110,7 @@ func (b *BuildServer) Run(streamId uint32, reply *[]uint32) error {
*reply = make([]uint32, len(artifacts)) *reply = make([]uint32, len(artifacts))
for i, artifact := range artifacts { for i, artifact := range artifacts {
streamId := b.mux.NextId() streamId := b.mux.NextId()
server := NewServerWithMux(b.mux, streamId) server := newServerWithMux(b.mux, streamId)
server.RegisterArtifact(artifact) server.RegisterArtifact(artifact)
go server.Serve() go server.Serve()
......
...@@ -41,7 +41,7 @@ func (b *builder) Prepare(config ...interface{}) ([]string, error) { ...@@ -41,7 +41,7 @@ func (b *builder) Prepare(config ...interface{}) ([]string, error) {
func (b *builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
nextId := b.mux.NextId() nextId := b.mux.NextId()
server := NewServerWithMux(b.mux, nextId) server := newServerWithMux(b.mux, nextId)
server.RegisterCache(cache) server.RegisterCache(cache)
server.RegisterHook(hook) server.RegisterHook(hook)
server.RegisterUi(ui) server.RegisterUi(ui)
...@@ -56,7 +56,7 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe ...@@ -56,7 +56,7 @@ func (b *builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, nil return nil, nil
} }
client, err := NewClientWithMux(b.mux, responseId) client, err := newClientWithMux(b.mux, responseId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -84,7 +84,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *BuilderPrepareR ...@@ -84,7 +84,7 @@ func (b *BuilderServer) Prepare(args *BuilderPrepareArgs, reply *BuilderPrepareR
} }
func (b *BuilderServer) Run(streamId uint32, reply *uint32) error { func (b *BuilderServer) Run(streamId uint32, reply *uint32) error {
client, err := NewClientWithMux(b.mux, streamId) client, err := newClientWithMux(b.mux, streamId)
if err != nil { if err != nil {
return NewBasicError(err) return NewBasicError(err)
} }
...@@ -98,7 +98,7 @@ func (b *BuilderServer) Run(streamId uint32, reply *uint32) error { ...@@ -98,7 +98,7 @@ func (b *BuilderServer) Run(streamId uint32, reply *uint32) error {
*reply = 0 *reply = 0
if artifact != nil { if artifact != nil {
streamId = b.mux.NextId() streamId = b.mux.NextId()
server := NewServerWithMux(b.mux, streamId) server := newServerWithMux(b.mux, streamId)
server.RegisterArtifact(artifact) server.RegisterArtifact(artifact)
go server.Serve() go server.Serve()
*reply = streamId *reply = streamId
......
...@@ -17,7 +17,7 @@ type Client struct { ...@@ -17,7 +17,7 @@ type Client struct {
} }
func NewClient(rwc io.ReadWriteCloser) (*Client, error) { func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
result, err := NewClientWithMux(NewMuxConn(rwc, 0), 0) result, err := newClientWithMux(NewMuxConn(rwc, 0), 0)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -26,7 +26,7 @@ func NewClient(rwc io.ReadWriteCloser) (*Client, error) { ...@@ -26,7 +26,7 @@ func NewClient(rwc io.ReadWriteCloser) (*Client, error) {
return result, err return result, err
} }
func NewClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) { func newClientWithMux(mux *MuxConn, streamId uint32) (*Client, error) {
clientConn, err := mux.Dial(streamId) clientConn, err := mux.Dial(streamId)
if err != nil { if err != nil {
return nil, err return nil, err
......
...@@ -37,7 +37,7 @@ func (c *command) Help() (result string) { ...@@ -37,7 +37,7 @@ func (c *command) Help() (result string) {
func (c *command) Run(env packer.Environment, args []string) (result int) { func (c *command) Run(env packer.Environment, args []string) (result int) {
nextId := c.mux.NextId() nextId := c.mux.NextId()
server := NewServerWithMux(c.mux, nextId) server := newServerWithMux(c.mux, nextId)
server.RegisterEnvironment(env) server.RegisterEnvironment(env)
go server.Serve() go server.Serve()
...@@ -68,7 +68,7 @@ func (c *CommandServer) Help(args *interface{}, reply *string) error { ...@@ -68,7 +68,7 @@ func (c *CommandServer) Help(args *interface{}, reply *string) error {
} }
func (c *CommandServer) Run(args *CommandRunArgs, reply *int) error { func (c *CommandServer) Run(args *CommandRunArgs, reply *int) error {
client, err := NewClientWithMux(c.mux, args.StreamId) client, err := newClientWithMux(c.mux, args.StreamId)
if err != nil { if err != nil {
return NewBasicError(err) return NewBasicError(err)
} }
......
...@@ -31,7 +31,7 @@ func (e *Environment) Builder(name string) (b packer.Builder, err error) { ...@@ -31,7 +31,7 @@ func (e *Environment) Builder(name string) (b packer.Builder, err error) {
return return
} }
client, err := NewClientWithMux(e.mux, streamId) client, err := newClientWithMux(e.mux, streamId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -45,7 +45,7 @@ func (e *Environment) Cache() packer.Cache { ...@@ -45,7 +45,7 @@ func (e *Environment) Cache() packer.Cache {
panic(err) panic(err)
} }
client, err := NewClientWithMux(e.mux, streamId) client, err := newClientWithMux(e.mux, streamId)
if err != nil { if err != nil {
log.Printf("[ERR] Error getting cache client: %s", err) log.Printf("[ERR] Error getting cache client: %s", err)
return nil return nil
...@@ -66,7 +66,7 @@ func (e *Environment) Hook(name string) (h packer.Hook, err error) { ...@@ -66,7 +66,7 @@ func (e *Environment) Hook(name string) (h packer.Hook, err error) {
return return
} }
client, err := NewClientWithMux(e.mux, streamId) client, err := newClientWithMux(e.mux, streamId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -80,7 +80,7 @@ func (e *Environment) PostProcessor(name string) (p packer.PostProcessor, err er ...@@ -80,7 +80,7 @@ func (e *Environment) PostProcessor(name string) (p packer.PostProcessor, err er
return return
} }
client, err := NewClientWithMux(e.mux, streamId) client, err := newClientWithMux(e.mux, streamId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -95,7 +95,7 @@ func (e *Environment) Provisioner(name string) (p packer.Provisioner, err error) ...@@ -95,7 +95,7 @@ func (e *Environment) Provisioner(name string) (p packer.Provisioner, err error)
return return
} }
client, err := NewClientWithMux(e.mux, streamId) client, err := newClientWithMux(e.mux, streamId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -107,7 +107,7 @@ func (e *Environment) Ui() packer.Ui { ...@@ -107,7 +107,7 @@ func (e *Environment) Ui() packer.Ui {
var streamId uint32 var streamId uint32
e.client.Call("Environment.Ui", new(interface{}), &streamId) e.client.Call("Environment.Ui", new(interface{}), &streamId)
client, err := NewClientWithMux(e.mux, streamId) client, err := newClientWithMux(e.mux, streamId)
if err != nil { if err != nil {
log.Printf("[ERR] Error connecting to Ui: %s", err) log.Printf("[ERR] Error connecting to Ui: %s", err)
return nil return nil
...@@ -122,7 +122,7 @@ func (e *EnvironmentServer) Builder(name string, reply *uint32) error { ...@@ -122,7 +122,7 @@ func (e *EnvironmentServer) Builder(name string, reply *uint32) error {
} }
*reply = e.mux.NextId() *reply = e.mux.NextId()
server := NewServerWithMux(e.mux, *reply) server := newServerWithMux(e.mux, *reply)
server.RegisterBuilder(builder) server.RegisterBuilder(builder)
go server.Serve() go server.Serve()
return nil return nil
...@@ -132,7 +132,7 @@ func (e *EnvironmentServer) Cache(args *interface{}, reply *uint32) error { ...@@ -132,7 +132,7 @@ func (e *EnvironmentServer) Cache(args *interface{}, reply *uint32) error {
cache := e.env.Cache() cache := e.env.Cache()
*reply = e.mux.NextId() *reply = e.mux.NextId()
server := NewServerWithMux(e.mux, *reply) server := newServerWithMux(e.mux, *reply)
server.RegisterCache(cache) server.RegisterCache(cache)
go server.Serve() go server.Serve()
return nil return nil
...@@ -150,7 +150,7 @@ func (e *EnvironmentServer) Hook(name string, reply *uint32) error { ...@@ -150,7 +150,7 @@ func (e *EnvironmentServer) Hook(name string, reply *uint32) error {
} }
*reply = e.mux.NextId() *reply = e.mux.NextId()
server := NewServerWithMux(e.mux, *reply) server := newServerWithMux(e.mux, *reply)
server.RegisterHook(hook) server.RegisterHook(hook)
go server.Serve() go server.Serve()
return nil return nil
...@@ -163,7 +163,7 @@ func (e *EnvironmentServer) PostProcessor(name string, reply *uint32) error { ...@@ -163,7 +163,7 @@ func (e *EnvironmentServer) PostProcessor(name string, reply *uint32) error {
} }
*reply = e.mux.NextId() *reply = e.mux.NextId()
server := NewServerWithMux(e.mux, *reply) server := newServerWithMux(e.mux, *reply)
server.RegisterPostProcessor(pp) server.RegisterPostProcessor(pp)
go server.Serve() go server.Serve()
return nil return nil
...@@ -176,7 +176,7 @@ func (e *EnvironmentServer) Provisioner(name string, reply *uint32) error { ...@@ -176,7 +176,7 @@ func (e *EnvironmentServer) Provisioner(name string, reply *uint32) error {
} }
*reply = e.mux.NextId() *reply = e.mux.NextId()
server := NewServerWithMux(e.mux, *reply) server := newServerWithMux(e.mux, *reply)
server.RegisterProvisioner(prov) server.RegisterProvisioner(prov)
go server.Serve() go server.Serve()
return nil return nil
...@@ -186,7 +186,7 @@ func (e *EnvironmentServer) Ui(args *interface{}, reply *uint32) error { ...@@ -186,7 +186,7 @@ func (e *EnvironmentServer) Ui(args *interface{}, reply *uint32) error {
ui := e.env.Ui() ui := e.env.Ui()
*reply = e.mux.NextId() *reply = e.mux.NextId()
server := NewServerWithMux(e.mux, *reply) server := newServerWithMux(e.mux, *reply)
server.RegisterUi(ui) server.RegisterUi(ui)
go server.Serve() go server.Serve()
return nil return nil
......
...@@ -28,7 +28,7 @@ type HookRunArgs struct { ...@@ -28,7 +28,7 @@ type HookRunArgs struct {
func (h *hook) Run(name string, ui packer.Ui, comm packer.Communicator, data interface{}) error { func (h *hook) Run(name string, ui packer.Ui, comm packer.Communicator, data interface{}) error {
nextId := h.mux.NextId() nextId := h.mux.NextId()
server := NewServerWithMux(h.mux, nextId) server := newServerWithMux(h.mux, nextId)
server.RegisterCommunicator(comm) server.RegisterCommunicator(comm)
server.RegisterUi(ui) server.RegisterUi(ui)
go server.Serve() go server.Serve()
...@@ -50,7 +50,7 @@ func (h *hook) Cancel() { ...@@ -50,7 +50,7 @@ func (h *hook) Cancel() {
} }
func (h *HookServer) Run(args *HookRunArgs, reply *interface{}) error { func (h *HookServer) Run(args *HookRunArgs, reply *interface{}) error {
client, err := NewClientWithMux(h.mux, args.StreamId) client, err := newClientWithMux(h.mux, args.StreamId)
if err != nil { if err != nil {
return NewBasicError(err) return NewBasicError(err)
} }
......
...@@ -41,7 +41,7 @@ func (p *postProcessor) Configure(raw ...interface{}) (err error) { ...@@ -41,7 +41,7 @@ func (p *postProcessor) Configure(raw ...interface{}) (err error) {
func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, bool, error) { func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, bool, error) {
nextId := p.mux.NextId() nextId := p.mux.NextId()
server := NewServerWithMux(p.mux, nextId) server := newServerWithMux(p.mux, nextId)
server.RegisterArtifact(a) server.RegisterArtifact(a)
server.RegisterUi(ui) server.RegisterUi(ui)
go server.Serve() go server.Serve()
...@@ -59,7 +59,7 @@ func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Art ...@@ -59,7 +59,7 @@ func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Art
return nil, false, nil return nil, false, nil
} }
client, err := NewClientWithMux(p.mux, response.StreamId) client, err := newClientWithMux(p.mux, response.StreamId)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
} }
...@@ -77,7 +77,7 @@ func (p *PostProcessorServer) Configure(args *PostProcessorConfigureArgs, reply ...@@ -77,7 +77,7 @@ func (p *PostProcessorServer) Configure(args *PostProcessorConfigureArgs, reply
} }
func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorProcessResponse) error { func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorProcessResponse) error {
client, err := NewClientWithMux(p.mux, streamId) client, err := newClientWithMux(p.mux, streamId)
if err != nil { if err != nil {
return NewBasicError(err) return NewBasicError(err)
} }
...@@ -87,7 +87,7 @@ func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorP ...@@ -87,7 +87,7 @@ func (p *PostProcessorServer) PostProcess(streamId uint32, reply *PostProcessorP
artifactResult, keep, err := p.p.PostProcess(client.Ui(), client.Artifact()) artifactResult, keep, err := p.p.PostProcess(client.Ui(), client.Artifact())
if err == nil && artifactResult != nil { if err == nil && artifactResult != nil {
streamId = p.mux.NextId() streamId = p.mux.NextId()
server := NewServerWithMux(p.mux, streamId) server := newServerWithMux(p.mux, streamId)
server.RegisterArtifact(artifactResult) server.RegisterArtifact(artifactResult)
go server.Serve() go server.Serve()
} }
......
...@@ -35,7 +35,7 @@ func (p *provisioner) Prepare(configs ...interface{}) (err error) { ...@@ -35,7 +35,7 @@ func (p *provisioner) Prepare(configs ...interface{}) (err error) {
func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { func (p *provisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
nextId := p.mux.NextId() nextId := p.mux.NextId()
server := NewServerWithMux(p.mux, nextId) server := newServerWithMux(p.mux, nextId)
server.RegisterCommunicator(comm) server.RegisterCommunicator(comm)
server.RegisterUi(ui) server.RegisterUi(ui)
go server.Serve() go server.Serve()
...@@ -60,7 +60,7 @@ func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *error) ...@@ -60,7 +60,7 @@ func (p *ProvisionerServer) Prepare(args *ProvisionerPrepareArgs, reply *error)
} }
func (p *ProvisionerServer) Provision(streamId uint32, reply *interface{}) error { func (p *ProvisionerServer) Provision(streamId uint32, reply *interface{}) error {
client, err := NewClientWithMux(p.mux, streamId) client, err := newClientWithMux(p.mux, streamId)
if err != nil { if err != nil {
return NewBasicError(err) return NewBasicError(err)
} }
......
...@@ -36,12 +36,12 @@ type Server struct { ...@@ -36,12 +36,12 @@ type Server struct {
// NewServer returns a new Packer RPC server. // NewServer returns a new Packer RPC server.
func NewServer(conn io.ReadWriteCloser) *Server { func NewServer(conn io.ReadWriteCloser) *Server {
result := NewServerWithMux(NewMuxConn(conn, 1), 0) result := newServerWithMux(NewMuxConn(conn, 1), 0)
result.closeMux = true result.closeMux = true
return result return result
} }
func NewServerWithMux(mux *MuxConn, streamId uint32) *Server { func newServerWithMux(mux *MuxConn, streamId uint32) *Server {
return &Server{ return &Server{
mux: mux, mux: mux,
streamId: streamId, streamId: streamId,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment