Returns a helpful string representation of this Deferred. The string returned is built in O(N) where N is the number of callbacks currently in the chain. The string isn't built entirely atomically, so it can appear to show this Deferred in a slightly inconsistent
()
| 1392 | * especially if this is in the fast-path of your application. |
| 1393 | */ |
| 1394 | public String toString() { |
| 1395 | final int state = this.state; // volatile access before reading result. |
| 1396 | final Object result = this.result; |
| 1397 | final String str; |
| 1398 | if (result == null) { |
| 1399 | str = "null"; |
| 1400 | } else if (result instanceof Deferred) { // Nested Deferreds |
| 1401 | str = "Deferred@" + result.hashCode(); // are hard to read. |
| 1402 | } else { |
| 1403 | str = result.toString(); |
| 1404 | } |
| 1405 | |
| 1406 | // We can't easily estimate how much space we'll need for the callback |
| 1407 | // chains, so let's just make sure we have enough space for all the static |
| 1408 | // cruft and the result, and double that to avoid the first re-allocation. |
| 1409 | // If result is a very long string, we may end up wasting some space, but |
| 1410 | // it's not likely to happen and even less likely to be a problem. |
| 1411 | final StringBuilder buf = new StringBuilder((9 + 10 + 7 + 7 |
| 1412 | + str.length()) * 2); |
| 1413 | buf.append("Deferred@").append(super.hashCode()) |
| 1414 | .append("(state=").append(stateString(state)) |
| 1415 | .append(", result=").append(str) |
| 1416 | .append(", callback="); |
| 1417 | synchronized (this) { |
| 1418 | if (callbacks == null || next_callback == last_callback) { |
| 1419 | buf.append("<none>, errback=<none>"); |
| 1420 | } else { |
| 1421 | for (int i = next_callback; i < last_callback; i += 2) { |
| 1422 | buf.append(callbacks[i]).append(" -> "); |
| 1423 | } |
| 1424 | buf.setLength(buf.length() - 4); // Remove the extra " -> ". |
| 1425 | buf.append(", errback="); |
| 1426 | for (int i = next_callback + 1; i < last_callback; i += 2) { |
| 1427 | buf.append(callbacks[i]).append(" -> "); |
| 1428 | } |
| 1429 | buf.setLength(buf.length() - 4); // Remove the extra " -> ". |
| 1430 | } |
| 1431 | } |
| 1432 | buf.append(')'); |
| 1433 | return buf.toString(); |
| 1434 | } |
| 1435 | |
| 1436 | private static String stateString(final int state) { |
| 1437 | switch (state) { |
nothing calls this directly
no test coverage detected