Created
April 4, 2012 16:29
-
-
Save pbogunovich/2303571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment