package org.fedoraproject.fedmsg;

import org.zeromq.ZMQ;

/**
 * Connect to a fedmsg bus.
 *
 * @author Ricky Elrod
 * @version 1.0.0
 */
public final class FedmsgConnection {
    private String endpoint;
    private int linger;
    private ZMQ.Socket sock;
    private ZMQ.Context context;

    public FedmsgConnection setEndpoint(String endpoint) {
        this.endpoint = endpoint;
        return this;
    }

    public FedmsgConnection setLinger(int linger) {
        this.linger = linger;
        return this;
    }

    public String getEndpoint() {
        return this.endpoint;
    }

    public int getLinger() {
        return this.linger;
    }

    public FedmsgConnection connect() {
        this.context = ZMQ.context(1);
        this.sock = context.socket(ZMQ.PUB);
        this.sock.setLinger(this.linger);
        this.sock.connect(this.endpoint);
        return this;
    }
}

@@ -52,16 +52,45 @@
 q.ZMQ;%0A%0A
+import java.io.IOException;%0A%0A
 /**%0A * C
@@ -915,11 +915,490 @@
 s;%0A    %7D
+%0A%0A    public void send(SignedFedmsgMessage msg) throws IOException %7B%0A        this.sock.send(msg.getMessage().getTopic(), ZMQ.SNDMORE %7C ZMQ.NOBLOCK);%0A        this.sock.send(%0A            msg.getMessage().toJson().toString(),%0A            ZMQ.SNDMORE %7C ZMQ.NOBLOCK);%0A    %7D%0A%0A    public void send(FedmsgMessage msg) throws IOException %7B%0A        this.sock.send(msg.getTopic(), ZMQ.SNDMORE %7C ZMQ.NOBLOCK);%0A        this.sock.send(msg.toJson().toString(), ZMQ.SNDMORE %7C ZMQ.NOBLOCK);%0A    %7D
 %0A%7D%0A

add methods to send to the bus (untested)