public MessageOutputStream writeMessage() throws IOException { int tries = 50; IntIndexMap<OutboundMessage> outboundMessages = this.outboundMessages; openOutboundMessage(); boolean ok = false; try { final Random random = ThreadLocalRandom.current(); while (tries > 0) { final int id = random.nextInt() & 0xfffe; if (! outboundMessages.containsKey(id)) { OutboundMessage message = new OutboundMessage((short) id, this, outboundWindow, maxOutboundMessageSize); OutboundMessage existing = outboundMessages.putIfAbsent(message); if (existing == null) { ok = true; return message; } } tries --; } throw log.channelBusy(); } finally { if (! ok) { closeOutboundMessage(); } } }
public MessageOutputStream writeMessage() throws IOException { int tries = 50; IntIndexMap<OutboundMessage> outboundMessages = this.outboundMessages; openOutboundMessage(); boolean ok = false; try { final Random random = ThreadLocalRandom.current(); while (tries > 0) { final int id = random.nextInt() & 0xfffe; if (! outboundMessages.containsKey(id)) { OutboundMessage message = new OutboundMessage((short) id, this, outboundWindow, maxOutboundMessageSize); OutboundMessage existing = outboundMessages.putIfAbsent(message); if (existing == null) { ok = true; return message; } } tries --; } throw log.channelBusy(); } finally { if (! ok) { closeOutboundMessage(); } } }
public MessageOutputStream writeMessage() throws IOException { int tries = 50; IntIndexMap<OutboundMessage> outboundMessages = this.outboundMessages; openOutboundMessage(); boolean ok = false; try { final Random random = ProtocolUtils.randomHolder.get(); while (tries > 0) { final int id = random.nextInt() & 0xfffe; if (! outboundMessages.containsKey(id)) { OutboundMessage message = new OutboundMessage((short) id, this, outboundWindow, maxOutboundMessageSize); OutboundMessage existing = outboundMessages.putIfAbsent(message); if (existing == null) { ok = true; return message; } } tries --; } throw log.channelBusy(); } finally { if (! ok) { closeOutboundMessage(); } } }