package org.fedoraproject.fedmsg;

import org.zeromq.ZMQ;

import java.io.IOException;

/**
 * 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;
    }

    public void send(FedmsgMessage msg) throws IOException {
        this.sock.send(msg.getTopic(), ZMQ.SNDMORE | ZMQ.NOBLOCK);
        this.sock.send(msg.toJson().toString(), ZMQ.NOBLOCK);
    }
}

@@ -211,16 +211,22 @@
 private 
+final 
 String e
@@ -246,16 +246,22 @@
 private 
+final 
 int ling
@@ -272,24 +272,30 @@
     private 
+final 
 ZMQ.Socket s
@@ -311,16 +311,22 @@
 private 
+final 
 ZMQ.Cont
@@ -370,21 +370,18 @@
 tion
- setEndpoint(
+(%0A        
 Stri
@@ -391,19 +391,17 @@
 endpoint
-) %7B
+,
 %0A       
@@ -405,113 +405,60 @@
     
-this.endpoint = endpoint;%0A        return this;
+int linger%0A    ) %7B
 %0A    
-%7D%0A%0A
     
-public FedmsgConnection setLinger(int linger) %7B
+this.endpoint = endpoint;
 %0A   
@@ -484,37 +484,16 @@
 linger;%0A
-        return this;%0A
     %7D%0A%0A 

Make FedmsgConnection immutable too