MCPcopy
hub / github.com/statsd/statsd / doSend

Method doSend

examples/StatsdClient.java:205–233  ·  view source on GitHub ↗
(String stat)

Source from the content-addressed store, hash-verified

203 }
204
205 private synchronized boolean doSend(String stat) {
206 try {
207 final byte[] data = stat.getBytes("utf-8");
208
209 // If we're going to go past the threshold of the buffer then flush.
210 // the +1 is for the potential '\n' in multi_metrics below
211 if(sendBuffer.remaining() < (data.length + 1)) {
212 flush();
213 }
214
215 if(sendBuffer.position() > 0) { // multiple metrics are separated by '\n'
216 sendBuffer.put( (byte) '\n');
217 }
218
219 sendBuffer.put(data); // append the data
220
221 if(! multi_metrics) {
222 flush();
223 }
224
225 return true;
226
227 } catch (IOException e) {
228 log.error(
229 String.format("Could not send stat %s to host %s:%d", sendBuffer.toString(), _address.getHostName(),
230 _address.getPort()), e);
231 return false;
232 }
233 }
234
235 public synchronized boolean flush() {
236 try {

Callers 1

sendMethod · 0.95

Calls 2

flushMethod · 0.95
formatMethod · 0.80

Tested by

no test coverage detected