use of org.openstack4j.model.identity.v2.Endpoint in project zipkin by openzipkin.
the class ThriftEndpointCodec method write.
static void write(Endpoint value, WriteBuffer buffer) {
IPV4.write(buffer);
buffer.write(value.ipv4Bytes() != null ? value.ipv4Bytes() : INT_ZERO);
PORT.write(buffer);
int port = value.portAsInt();
// write short!
buffer.writeByte((port >>> 8L) & 0xff);
buffer.writeByte(port & 0xff);
SERVICE_NAME.write(buffer);
ThriftCodec.writeLengthPrefixed(buffer, value.serviceName() != null ? value.serviceName() : "");
byte[] ipv6 = value.ipv6Bytes();
if (ipv6 != null) {
IPV6.write(buffer);
ThriftCodec.writeInt(buffer, 16);
buffer.write(ipv6);
}
buffer.writeByte(TYPE_STOP);
}
use of org.openstack4j.model.identity.v2.Endpoint in project zipkin by openzipkin.
the class ThriftEndpointCodec method sizeInBytes.
static int sizeInBytes(Endpoint value) {
String serviceName = value.serviceName();
int sizeInBytes = 0;
// IPV4
sizeInBytes += 3 + 4;
// PORT
sizeInBytes += 3 + 2;
sizeInBytes += 3 + 4 + (serviceName != null ? utf8SizeInBytes(serviceName) : 0);
if (value.ipv6() != null)
sizeInBytes += 3 + 4 + 16;
// TYPE_STOP
sizeInBytes++;
return sizeInBytes;
}
use of org.openstack4j.model.identity.v2.Endpoint in project zipkin by openzipkin.
the class Trace method compareEndpoint.
/**
* Put spans with null endpoints first, so that their data can be attached to the first span with
* the same ID and endpoint. It is possible that a server can get the same request on a different
* port. Not addressing this.
*/
static int compareEndpoint(Endpoint left, Endpoint right) {
if (left == null) {
// nulls first
return (right == null) ? 0 : -1;
} else if (right == null) {
return 1;
}
int byService = nullSafeCompareTo(left.serviceName(), right.serviceName(), false);
if (byService != 0)
return byService;
int byIpV4 = nullSafeCompareTo(left.ipv4(), right.ipv4(), false);
if (byIpV4 != 0)
return byIpV4;
return nullSafeCompareTo(left.ipv6(), right.ipv6(), false);
}
use of org.openstack4j.model.identity.v2.Endpoint in project zipkin by openzipkin.
the class V1JsonSpanReader method readBinaryAnnotation.
void readBinaryAnnotation(JsonReader reader) throws IOException {
String key = null;
Endpoint endpoint = null;
Boolean booleanValue = null;
String stringValue = null;
reader.beginObject();
while (reader.hasNext()) {
String nextName = reader.nextName();
if (reader.peekNull()) {
reader.skipValue();
continue;
}
if (nextName.equals("key")) {
key = reader.nextString();
} else if (nextName.equals("value")) {
if (reader.peekString()) {
stringValue = reader.nextString();
} else if (reader.peekBoolean()) {
booleanValue = reader.nextBoolean();
} else {
reader.skipValue();
}
} else if (nextName.equals("endpoint")) {
endpoint = ENDPOINT_READER.fromJson(reader);
} else {
reader.skipValue();
}
}
if (key == null) {
throw new IllegalArgumentException("No key at " + reader.getPath());
}
reader.endObject();
if (stringValue != null) {
builder.addBinaryAnnotation(key, stringValue, endpoint);
} else if (booleanValue != null && booleanValue && endpoint != null) {
if (key.equals("sa") || key.equals("ca") || key.equals("ma")) {
builder.addBinaryAnnotation(key, endpoint);
}
}
}
use of org.openstack4j.model.identity.v2.Endpoint in project zipkin by openzipkin.
the class V1SpanWriter method write.
@Override
public void write(V1Span value, WriteBuffer b) {
b.writeAscii("{\"traceId\":\"");
if (value.traceIdHigh() != 0L)
b.writeLongHex(value.traceIdHigh());
b.writeLongHex(value.traceId());
b.writeByte('"');
if (value.parentId() != 0L) {
b.writeAscii(",\"parentId\":\"");
b.writeLongHex(value.parentId());
b.writeByte('"');
}
b.writeAscii(",\"id\":\"");
b.writeLongHex(value.id());
b.writeByte('"');
b.writeAscii(",\"name\":\"");
if (value.name() != null)
b.writeUtf8(jsonEscape(value.name()));
b.writeByte('"');
if (value.timestamp() != 0L) {
b.writeAscii(",\"timestamp\":");
b.writeAscii(value.timestamp());
}
if (value.duration() != 0L) {
b.writeAscii(",\"duration\":");
b.writeAscii(value.duration());
}
int annotationCount = value.annotations().size();
Endpoint lastEndpoint = null;
byte[] lastEndpointBytes = null;
if (annotationCount > 0) {
b.writeAscii(",\"annotations\":[");
for (int i = 0; i < annotationCount; ) {
V1Annotation a = value.annotations().get(i++);
Endpoint endpoint = a.endpoint();
byte[] endpointBytes;
if (endpoint == null) {
endpointBytes = null;
} else if (endpoint.equals(lastEndpoint)) {
endpointBytes = lastEndpointBytes;
} else {
lastEndpoint = endpoint;
endpointBytes = lastEndpointBytes = legacyEndpointBytes(endpoint);
}
writeAnnotation(a.timestamp(), a.value(), endpointBytes, b);
if (i < annotationCount)
b.writeByte(',');
}
b.writeByte(']');
}
int binaryAnnotationCount = value.binaryAnnotations().size();
if (binaryAnnotationCount > 0) {
b.writeAscii(",\"binaryAnnotations\":[");
for (int i = 0; i < binaryAnnotationCount; ) {
V1BinaryAnnotation a = value.binaryAnnotations().get(i++);
Endpoint endpoint = a.endpoint();
byte[] endpointBytes;
if (endpoint == null) {
endpointBytes = null;
} else if (endpoint.equals(lastEndpoint)) {
endpointBytes = lastEndpointBytes;
} else {
lastEndpoint = endpoint;
endpointBytes = lastEndpointBytes = legacyEndpointBytes(endpoint);
}
if (a.stringValue() != null) {
writeBinaryAnnotation(a.key(), a.stringValue(), endpointBytes, b);
} else {
b.writeAscii("{\"key\":\"");
b.writeAscii(a.key());
b.writeAscii("\",\"value\":true,\"endpoint\":");
b.write(endpointBytes);
b.writeByte('}');
}
if (i < binaryAnnotationCount)
b.writeByte(',');
}
b.writeByte(']');
}
if (Boolean.TRUE.equals(value.debug())) {
b.writeAscii(",\"debug\":true");
}
b.writeByte('}');
}
Aggregations