/** * Copyright 2015-2016 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ /** * Autogenerated by Thrift Compiler (0.9.3) * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated */ package com.twitter.zipkin.thriftjava; import org.apache.thrift.scheme.IScheme; import org.apache.thrift.scheme.SchemeFactory; import org.apache.thrift.scheme.StandardScheme; import org.apache.thrift.scheme.TupleScheme; import org.apache.thrift.protocol.TTupleProtocol; import org.apache.thrift.protocol.TProtocolException; import org.apache.thrift.EncodingUtils; import org.apache.thrift.TException; import org.apache.thrift.async.AsyncMethodCallback; import org.apache.thrift.server.AbstractNonblockingServer.*; import java.util.List; import java.util.ArrayList; import java.util.Map; import java.util.HashMap; import java.util.EnumMap; import java.util.Set; import java.util.HashSet; import java.util.EnumSet; import java.util.Collections; import java.util.BitSet; import java.nio.ByteBuffer; import java.util.Arrays; import javax.annotation.Generated; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @SuppressWarnings({"cast", "rawtypes", "serial", "unchecked"}) /** * Indicates the network context of a service recording an annotation with two * exceptions. * * When a BinaryAnnotation, and key is CLIENT_ADDR or SERVER_ADDR, * the endpoint indicates the source or destination of an RPC. This exception * allows zipkin to display network context of uninstrumented services, or * clients such as web browsers. */ @Generated(value = "Autogenerated by Thrift Compiler (0.9.3)", date = "2016-10-26") public class Endpoint implements org.apache.thrift.TBase<Endpoint, Endpoint._Fields>, java.io.Serializable, Cloneable, Comparable<Endpoint> { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Endpoint"); private static final org.apache.thrift.protocol.TField IPV4_FIELD_DESC = new org.apache.thrift.protocol.TField("ipv4", org.apache.thrift.protocol.TType.I32, (short)1); private static final org.apache.thrift.protocol.TField PORT_FIELD_DESC = new org.apache.thrift.protocol.TField("port", org.apache.thrift.protocol.TType.I16, (short)2); private static final org.apache.thrift.protocol.TField SERVICE_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("service_name", org.apache.thrift.protocol.TType.STRING, (short)3); private static final org.apache.thrift.protocol.TField IPV6_FIELD_DESC = new org.apache.thrift.protocol.TField("ipv6", org.apache.thrift.protocol.TType.STRING, (short)4); private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>(); static { schemes.put(StandardScheme.class, new EndpointStandardSchemeFactory()); schemes.put(TupleScheme.class, new EndpointTupleSchemeFactory()); } /** * IPv4 host address packed into 4 bytes. * * Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 */ public int ipv4; // required /** * IPv4 port or 0, if unknown. * * Note: this is to be treated as an unsigned integer, so watch for negatives. */ public short port; // required /** * Classifier of a source or destination in lowercase, such as "zipkin-web". * * This is the primary parameter for trace lookup, so should be intuitive as * possible, for example, matching names in service discovery. * * Conventionally, when the service name isn't known, service_name = "unknown". * However, it is also permissible to set service_name = "" (empty string). * The difference in the latter usage is that the span will not be queryable * by service name unless more information is added to the span with non-empty * service name, e.g. an additional annotation from the server. * * Particularly clients may not have a reliable service name at ingest. One * approach is to set service_name to "" at ingest, and later assign a * better label based on binary annotations, such as user agent. */ public String service_name; // required /** * IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes() */ public ByteBuffer ipv6; // optional /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ public enum _Fields implements org.apache.thrift.TFieldIdEnum { /** * IPv4 host address packed into 4 bytes. * * Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 */ IPV4((short)1, "ipv4"), /** * IPv4 port or 0, if unknown. * * Note: this is to be treated as an unsigned integer, so watch for negatives. */ PORT((short)2, "port"), /** * Classifier of a source or destination in lowercase, such as "zipkin-web". * * This is the primary parameter for trace lookup, so should be intuitive as * possible, for example, matching names in service discovery. * * Conventionally, when the service name isn't known, service_name = "unknown". * However, it is also permissible to set service_name = "" (empty string). * The difference in the latter usage is that the span will not be queryable * by service name unless more information is added to the span with non-empty * service name, e.g. an additional annotation from the server. * * Particularly clients may not have a reliable service name at ingest. One * approach is to set service_name to "" at ingest, and later assign a * better label based on binary annotations, such as user agent. */ SERVICE_NAME((short)3, "service_name"), /** * IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes() */ IPV6((short)4, "ipv6"); private static final Map<String, _Fields> byName = new HashMap<String, _Fields>(); static { for (_Fields field : EnumSet.allOf(_Fields.class)) { byName.put(field.getFieldName(), field); } } /** * Find the _Fields constant that matches fieldId, or null if its not found. */ public static _Fields findByThriftId(int fieldId) { switch(fieldId) { case 1: // IPV4 return IPV4; case 2: // PORT return PORT; case 3: // SERVICE_NAME return SERVICE_NAME; case 4: // IPV6 return IPV6; default: return null; } } /** * Find the _Fields constant that matches fieldId, throwing an exception * if it is not found. */ public static _Fields findByThriftIdOrThrow(int fieldId) { _Fields fields = findByThriftId(fieldId); if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); return fields; } /** * Find the _Fields constant that matches name, or null if its not found. */ public static _Fields findByName(String name) { return byName.get(name); } private final short _thriftId; private final String _fieldName; _Fields(short thriftId, String fieldName) { _thriftId = thriftId; _fieldName = fieldName; } public short getThriftFieldId() { return _thriftId; } public String getFieldName() { return _fieldName; } } // isset id assignments private static final int __IPV4_ISSET_ID = 0; private static final int __PORT_ISSET_ID = 1; private byte __isset_bitfield = 0; private static final _Fields optionals[] = {_Fields.IPV6}; public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; static { Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); tmpMap.put(_Fields.IPV4, new org.apache.thrift.meta_data.FieldMetaData("ipv4", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I32))); tmpMap.put(_Fields.PORT, new org.apache.thrift.meta_data.FieldMetaData("port", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.I16))); tmpMap.put(_Fields.SERVICE_NAME, new org.apache.thrift.meta_data.FieldMetaData("service_name", org.apache.thrift.TFieldRequirementType.DEFAULT, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING))); tmpMap.put(_Fields.IPV6, new org.apache.thrift.meta_data.FieldMetaData("ipv6", org.apache.thrift.TFieldRequirementType.OPTIONAL, new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , true))); metaDataMap = Collections.unmodifiableMap(tmpMap); org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(Endpoint.class, metaDataMap); } public Endpoint() { } public Endpoint( int ipv4, short port, String service_name) { this(); this.ipv4 = ipv4; setIpv4IsSet(true); this.port = port; setPortIsSet(true); this.service_name = service_name; } /** * Performs a deep copy on <i>other</i>. */ public Endpoint(Endpoint other) { __isset_bitfield = other.__isset_bitfield; this.ipv4 = other.ipv4; this.port = other.port; if (other.isSetService_name()) { this.service_name = other.service_name; } if (other.isSetIpv6()) { this.ipv6 = org.apache.thrift.TBaseHelper.copyBinary(other.ipv6); } } public Endpoint deepCopy() { return new Endpoint(this); } @Override public void clear() { setIpv4IsSet(false); this.ipv4 = 0; setPortIsSet(false); this.port = 0; this.service_name = null; this.ipv6 = null; } /** * IPv4 host address packed into 4 bytes. * * Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 */ public int getIpv4() { return this.ipv4; } /** * IPv4 host address packed into 4 bytes. * * Ex for the ip 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 */ public Endpoint setIpv4(int ipv4) { this.ipv4 = ipv4; setIpv4IsSet(true); return this; } public void unsetIpv4() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __IPV4_ISSET_ID); } /** Returns true if field ipv4 is set (has been assigned a value) and false otherwise */ public boolean isSetIpv4() { return EncodingUtils.testBit(__isset_bitfield, __IPV4_ISSET_ID); } public void setIpv4IsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __IPV4_ISSET_ID, value); } /** * IPv4 port or 0, if unknown. * * Note: this is to be treated as an unsigned integer, so watch for negatives. */ public short getPort() { return this.port; } /** * IPv4 port or 0, if unknown. * * Note: this is to be treated as an unsigned integer, so watch for negatives. */ public Endpoint setPort(short port) { this.port = port; setPortIsSet(true); return this; } public void unsetPort() { __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __PORT_ISSET_ID); } /** Returns true if field port is set (has been assigned a value) and false otherwise */ public boolean isSetPort() { return EncodingUtils.testBit(__isset_bitfield, __PORT_ISSET_ID); } public void setPortIsSet(boolean value) { __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __PORT_ISSET_ID, value); } /** * Classifier of a source or destination in lowercase, such as "zipkin-web". * * This is the primary parameter for trace lookup, so should be intuitive as * possible, for example, matching names in service discovery. * * Conventionally, when the service name isn't known, service_name = "unknown". * However, it is also permissible to set service_name = "" (empty string). * The difference in the latter usage is that the span will not be queryable * by service name unless more information is added to the span with non-empty * service name, e.g. an additional annotation from the server. * * Particularly clients may not have a reliable service name at ingest. One * approach is to set service_name to "" at ingest, and later assign a * better label based on binary annotations, such as user agent. */ public String getService_name() { return this.service_name; } /** * Classifier of a source or destination in lowercase, such as "zipkin-web". * * This is the primary parameter for trace lookup, so should be intuitive as * possible, for example, matching names in service discovery. * * Conventionally, when the service name isn't known, service_name = "unknown". * However, it is also permissible to set service_name = "" (empty string). * The difference in the latter usage is that the span will not be queryable * by service name unless more information is added to the span with non-empty * service name, e.g. an additional annotation from the server. * * Particularly clients may not have a reliable service name at ingest. One * approach is to set service_name to "" at ingest, and later assign a * better label based on binary annotations, such as user agent. */ public Endpoint setService_name(String service_name) { this.service_name = service_name; return this; } public void unsetService_name() { this.service_name = null; } /** Returns true if field service_name is set (has been assigned a value) and false otherwise */ public boolean isSetService_name() { return this.service_name != null; } public void setService_nameIsSet(boolean value) { if (!value) { this.service_name = null; } } /** * IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes() */ public byte[] getIpv6() { setIpv6(org.apache.thrift.TBaseHelper.rightSize(ipv6)); return ipv6 == null ? null : ipv6.array(); } public ByteBuffer bufferForIpv6() { return org.apache.thrift.TBaseHelper.copyBinary(ipv6); } /** * IPv6 host address packed into 16 bytes. Ex Inet6Address.getBytes() */ public Endpoint setIpv6(byte[] ipv6) { this.ipv6 = ipv6 == null ? (ByteBuffer)null : ByteBuffer.wrap(Arrays.copyOf(ipv6, ipv6.length)); return this; } public Endpoint setIpv6(ByteBuffer ipv6) { this.ipv6 = org.apache.thrift.TBaseHelper.copyBinary(ipv6); return this; } public void unsetIpv6() { this.ipv6 = null; } /** Returns true if field ipv6 is set (has been assigned a value) and false otherwise */ public boolean isSetIpv6() { return this.ipv6 != null; } public void setIpv6IsSet(boolean value) { if (!value) { this.ipv6 = null; } } public void setFieldValue(_Fields field, Object value) { switch (field) { case IPV4: if (value == null) { unsetIpv4(); } else { setIpv4((Integer)value); } break; case PORT: if (value == null) { unsetPort(); } else { setPort((Short)value); } break; case SERVICE_NAME: if (value == null) { unsetService_name(); } else { setService_name((String)value); } break; case IPV6: if (value == null) { unsetIpv6(); } else { setIpv6((ByteBuffer)value); } break; } } public Object getFieldValue(_Fields field) { switch (field) { case IPV4: return getIpv4(); case PORT: return getPort(); case SERVICE_NAME: return getService_name(); case IPV6: return getIpv6(); } throw new IllegalStateException(); } /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case IPV4: return isSetIpv4(); case PORT: return isSetPort(); case SERVICE_NAME: return isSetService_name(); case IPV6: return isSetIpv6(); } throw new IllegalStateException(); } @Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof Endpoint) return this.equals((Endpoint)that); return false; } public boolean equals(Endpoint that) { if (that == null) return false; boolean this_present_ipv4 = true; boolean that_present_ipv4 = true; if (this_present_ipv4 || that_present_ipv4) { if (!(this_present_ipv4 && that_present_ipv4)) return false; if (this.ipv4 != that.ipv4) return false; } boolean this_present_port = true; boolean that_present_port = true; if (this_present_port || that_present_port) { if (!(this_present_port && that_present_port)) return false; if (this.port != that.port) return false; } boolean this_present_service_name = true && this.isSetService_name(); boolean that_present_service_name = true && that.isSetService_name(); if (this_present_service_name || that_present_service_name) { if (!(this_present_service_name && that_present_service_name)) return false; if (!this.service_name.equals(that.service_name)) return false; } boolean this_present_ipv6 = true && this.isSetIpv6(); boolean that_present_ipv6 = true && that.isSetIpv6(); if (this_present_ipv6 || that_present_ipv6) { if (!(this_present_ipv6 && that_present_ipv6)) return false; if (!this.ipv6.equals(that.ipv6)) return false; } return true; } @Override public int hashCode() { List<Object> list = new ArrayList<Object>(); boolean present_ipv4 = true; list.add(present_ipv4); if (present_ipv4) list.add(ipv4); boolean present_port = true; list.add(present_port); if (present_port) list.add(port); boolean present_service_name = true && (isSetService_name()); list.add(present_service_name); if (present_service_name) list.add(service_name); boolean present_ipv6 = true && (isSetIpv6()); list.add(present_ipv6); if (present_ipv6) list.add(ipv6); return list.hashCode(); } @Override public int compareTo(Endpoint other) { if (!getClass().equals(other.getClass())) { return getClass().getName().compareTo(other.getClass().getName()); } int lastComparison = 0; lastComparison = Boolean.valueOf(isSetIpv4()).compareTo(other.isSetIpv4()); if (lastComparison != 0) { return lastComparison; } if (isSetIpv4()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.ipv4, other.ipv4); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetPort()).compareTo(other.isSetPort()); if (lastComparison != 0) { return lastComparison; } if (isSetPort()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.port, other.port); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetService_name()).compareTo(other.isSetService_name()); if (lastComparison != 0) { return lastComparison; } if (isSetService_name()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.service_name, other.service_name); if (lastComparison != 0) { return lastComparison; } } lastComparison = Boolean.valueOf(isSetIpv6()).compareTo(other.isSetIpv6()); if (lastComparison != 0) { return lastComparison; } if (isSetIpv6()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.ipv6, other.ipv6); if (lastComparison != 0) { return lastComparison; } } return 0; } public _Fields fieldForId(int fieldId) { return _Fields.findByThriftId(fieldId); } public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { schemes.get(iprot.getScheme()).getScheme().read(iprot, this); } public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { schemes.get(oprot.getScheme()).getScheme().write(oprot, this); } @Override public String toString() { StringBuilder sb = new StringBuilder("Endpoint("); boolean first = true; sb.append("ipv4:"); sb.append(this.ipv4); first = false; if (!first) sb.append(", "); sb.append("port:"); sb.append(this.port); first = false; if (!first) sb.append(", "); sb.append("service_name:"); if (this.service_name == null) { sb.append("null"); } else { sb.append(this.service_name); } first = false; if (isSetIpv6()) { if (!first) sb.append(", "); sb.append("ipv6:"); if (this.ipv6 == null) { sb.append("null"); } else { org.apache.thrift.TBaseHelper.toString(this.ipv6, sb); } first = false; } sb.append(")"); return sb.toString(); } public void validate() throws org.apache.thrift.TException { // check for required fields // check for sub-struct validity } private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { try { write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { try { // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. __isset_bitfield = 0; read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); } catch (org.apache.thrift.TException te) { throw new java.io.IOException(te); } } private static class EndpointStandardSchemeFactory implements SchemeFactory { public EndpointStandardScheme getScheme() { return new EndpointStandardScheme(); } } private static class EndpointStandardScheme extends StandardScheme<Endpoint> { public void read(org.apache.thrift.protocol.TProtocol iprot, Endpoint struct) throws org.apache.thrift.TException { org.apache.thrift.protocol.TField schemeField; iprot.readStructBegin(); while (true) { schemeField = iprot.readFieldBegin(); if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { break; } switch (schemeField.id) { case 1: // IPV4 if (schemeField.type == org.apache.thrift.protocol.TType.I32) { struct.ipv4 = iprot.readI32(); struct.setIpv4IsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 2: // PORT if (schemeField.type == org.apache.thrift.protocol.TType.I16) { struct.port = iprot.readI16(); struct.setPortIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 3: // SERVICE_NAME if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { struct.service_name = iprot.readString(); struct.setService_nameIsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; case 4: // IPV6 if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { struct.ipv6 = iprot.readBinary(); struct.setIpv6IsSet(true); } else { org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } break; default: org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); } iprot.readFieldEnd(); } iprot.readStructEnd(); // check for required fields of primitive type, which can't be checked in the validate method struct.validate(); } public void write(org.apache.thrift.protocol.TProtocol oprot, Endpoint struct) throws org.apache.thrift.TException { struct.validate(); oprot.writeStructBegin(STRUCT_DESC); oprot.writeFieldBegin(IPV4_FIELD_DESC); oprot.writeI32(struct.ipv4); oprot.writeFieldEnd(); oprot.writeFieldBegin(PORT_FIELD_DESC); oprot.writeI16(struct.port); oprot.writeFieldEnd(); if (struct.service_name != null) { oprot.writeFieldBegin(SERVICE_NAME_FIELD_DESC); oprot.writeString(struct.service_name); oprot.writeFieldEnd(); } if (struct.ipv6 != null) { if (struct.isSetIpv6()) { oprot.writeFieldBegin(IPV6_FIELD_DESC); oprot.writeBinary(struct.ipv6); oprot.writeFieldEnd(); } } oprot.writeFieldStop(); oprot.writeStructEnd(); } } private static class EndpointTupleSchemeFactory implements SchemeFactory { public EndpointTupleScheme getScheme() { return new EndpointTupleScheme(); } } private static class EndpointTupleScheme extends TupleScheme<Endpoint> { @Override public void write(org.apache.thrift.protocol.TProtocol prot, Endpoint struct) throws org.apache.thrift.TException { TTupleProtocol oprot = (TTupleProtocol) prot; BitSet optionals = new BitSet(); if (struct.isSetIpv4()) { optionals.set(0); } if (struct.isSetPort()) { optionals.set(1); } if (struct.isSetService_name()) { optionals.set(2); } if (struct.isSetIpv6()) { optionals.set(3); } oprot.writeBitSet(optionals, 4); if (struct.isSetIpv4()) { oprot.writeI32(struct.ipv4); } if (struct.isSetPort()) { oprot.writeI16(struct.port); } if (struct.isSetService_name()) { oprot.writeString(struct.service_name); } if (struct.isSetIpv6()) { oprot.writeBinary(struct.ipv6); } } @Override public void read(org.apache.thrift.protocol.TProtocol prot, Endpoint struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(4); if (incoming.get(0)) { struct.ipv4 = iprot.readI32(); struct.setIpv4IsSet(true); } if (incoming.get(1)) { struct.port = iprot.readI16(); struct.setPortIsSet(true); } if (incoming.get(2)) { struct.service_name = iprot.readString(); struct.setService_nameIsSet(true); } if (incoming.get(3)) { struct.ipv6 = iprot.readBinary(); struct.setIpv6IsSet(true); } } } }