public
Created

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
class SocketThreadLocal extends ThreadLocal<ZMQ.Socket>
{
static final Logger log = Logger.getLogger(SocketThreadLocal.class);
 
private ZMQ.Context ctx;
private MQConfig config;
 
SocketThreadLocal(ZMQ.Context ctx, MQConfig config)
{
this.ctx = ctx;
this.config = config;
}
 
@Override
protected ZMQ.Socket initialValue() {
ZMQ.Socket socket = config.applyToSocket(ctx.socket(ZMQ.PUSH));
for (String host : config.hosts.split(",")) {
socket.connect(host);
}
return socket;
}
}
 
public class MQCache implements MessageCache
{
static final Logger log = Logger.getLogger(MQCache.class);
 
private SocketThreadLocal local;
private Boolean block;
 
@Inject
public MQCache(ZMQ.Context ctx, MQConfig config)
{
this.local = new SocketThreadLocal(ctx, config);
this.block = config.sendBlocking;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.