Commit 7daa7454 authored by Jonathan Mace's avatar Jonathan Mace

Add generated sources for BDL examples

parent 2c884c47
/** Generated by BaggageBuffersCompiler */
package brown.tracingplane.bdl.examples;
import brown.tracingplane.ActiveBaggage;
import brown.tracingplane.BaggageContext;
import brown.tracingplane.baggageprotocol.BagKey;
import brown.tracingplane.baggageprotocol.BaggageReader;
import brown.tracingplane.baggageprotocol.BaggageWriter;
import brown.tracingplane.bdl.BDLUtils;
import brown.tracingplane.bdl.Bag;
import brown.tracingplane.bdl.BaggageHandler;
import brown.tracingplane.bdl.Brancher;
import brown.tracingplane.bdl.Branchers;
import brown.tracingplane.bdl.Joiner;
import brown.tracingplane.bdl.Joiners;
import brown.tracingplane.bdl.Parser;
import brown.tracingplane.bdl.Parsers;
import brown.tracingplane.bdl.Serializer;
import brown.tracingplane.bdl.Serializers;
import brown.tracingplane.impl.BDLContextProvider;
import brown.tracingplane.impl.BaggageHandlerRegistry;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SimpleBag implements Bag {
private static final Logger _log = LoggerFactory.getLogger(SimpleBag.class);
public Set<Long> ids = null;
public boolean _overflow = false;
/**
* <p>
* Get the {@link SimpleBag} set in the active {@link BaggageContext} carried by the current thread. If no baggage is being
* carried by the current thread, or if there is no SimpleBag in it, then this method returns {@code null}.
* </p>
*
* <p>
* To get SimpleBag from a specific Baggage instance, use {@link #getFrom(BaggageContext)}.
* </p>
*
* @return the SimpleBag being carried in the {@link BaggageContext} of the current thread, or {@code null}
* if none is being carried. The returned instance maybe be modified and modifications will be reflected in
* the baggage.
*/
public static SimpleBag get() {
Bag bag = BDLContextProvider.get(ActiveBaggage.peek(), Handler.registration());
if (bag instanceof SimpleBag) {
return (SimpleBag) bag;
} else {
return null;
}
}
/**
* <p>
* Get the {@link SimpleBag} set in {@code baggage}. If {@code baggage} has no SimpleBag set then
* this method returns null.
* </p>
*
* <p>
* This method does <b>not</b> affect the Baggage being carried by the current thread. To get SimpleBag
* from the current thread's Baggage, use {@link #get()}.
* </p>
*
* @param baggage A baggage instance to get the {@link SimpleBag} from
* @return the {@link SimpleBag} instance being carried in {@code baggage}, or {@code null} if none is being carried.
* The returned instance can be modified, and modifications will be reflected in the baggage.
*/
public static SimpleBag getFrom(BaggageContext baggage) {
Bag bag = BDLContextProvider.get(baggage, Handler.registration());
if (bag instanceof SimpleBag) {
return (SimpleBag) bag;
} else if (bag != null) {
Handler.checkRegistration();
}
return null;
}
/**
* <p>
* Update the {@link SimpleBag} set in the current thread's baggage. This method will overwrite any existing
* SimpleBag set in the current thread's baggage.
* </p>
*
* <p>
* To set the {@link SimpleBag} in a specific {@link BaggageContext} instance, use
* {@link #setIn(BaggageContext, SimpleBag)}
* </p>
*
* @param simpleBag the new {@link SimpleBag} to set in the current thread's {@link BaggageContext}. If {@code null}
* then any existing mappings will be removed.
*/
public static void set(SimpleBag simpleBag) {
ActiveBaggage.update(BDLContextProvider.set(ActiveBaggage.peek(), Handler.registration(), simpleBag));
}
/**
* <p>
* Update the {@link SimpleBag} set in {@code baggage}. This method will overwrite any existing
* SimpleBag set in {@code baggage}.
* </p>
*
* <p>
* This method does <b>not</b> affect the {@link BaggageContext} being carried by the current thread. To set the
* {@link SimpleBag} for the current thread, use {@link #set(SimpleBag)}
* </p>
*
* @param baggage A baggage instance to set the {@link SimpleBag} in
* @param simpleBag the new SimpleBag to set in {@code baggage}. If {@code null}, it will remove any
* mapping present.
* @return a possibly new {@link BaggageContext} instance that contains all previous mappings plus the new mapping.
*/
public static BaggageContext setIn(BaggageContext baggage, SimpleBag simpleBag) {
return BDLContextProvider.set(baggage, Handler.registration(), simpleBag);
}
@Override
public BaggageHandler<?> handler() {
return Handler.instance;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("SimpleBag{\n");
b.append(this.ids == null ? "" : BDLUtils.indent(String.format("ids = %s\n", BDLUtils.toString(this.ids))));
b.append("}");
return b.toString();
}
public static class Handler implements BaggageHandler<SimpleBag> {
public static final Handler instance = new Handler();
private static BagKey registration = null;
static synchronized BagKey checkRegistration() {
registration = BaggageHandlerRegistry.get(instance);
if (registration == null) {
_log.error("SimpleBag MUST be registered to a key before it can be propagated. " +
"There is currently no registration for SimpleBag and it will not be propagated. " +
"To register a bag set the bag.{index} property in your application.conf (eg, for " +
"index 10, bag.10 = \"brown.tracingplane.bdl.examples.SimpleBag\") or with -Dbag.{index} flag " +
"(eg, for index 10, -Dbag.10=brown.tracingplane.bdl.examples.SimpleBag)");
}
return registration;
}
static BagKey registration() {
return registration == null ? checkRegistration() : registration;
}
private Handler(){}
private static final BagKey _idsKey = BagKey.indexed(1);
private static final Parser<Set<Long>> _idsParser = Parsers.<Long>setParser(Parsers.fixed64Parser());
private static final Serializer<Set<Long>> _idsSerializer = Serializers.<Long>setSerializer(Serializers.fixed64Serializer());
private static final Brancher<Set<Long>> _idsBrancher = Branchers.<Long>set();
private static final Joiner<Set<Long>> _idsJoiner = Joiners.<Long>setUnion();
@Override
public boolean isInstance(Bag bag) {
return bag == null || bag instanceof SimpleBag;
}
@Override
public SimpleBag parse(BaggageReader reader) {
SimpleBag instance = new SimpleBag();
if (reader.enter(_idsKey)) {
instance.ids = _idsParser.parse(reader);
reader.exit();
}
instance._overflow = reader.didOverflow();
return instance;
}
@Override
public void serialize(BaggageWriter writer, SimpleBag instance) {
if (instance == null) {
return;
}
writer.didOverflowHere(instance._overflow);
if (instance.ids != null) {
writer.enter(_idsKey);
_idsSerializer.serialize(writer, instance.ids);
writer.exit();
}
}
@Override
public SimpleBag branch(SimpleBag instance) {
if (instance == null) {
return null;
}
SimpleBag newInstance = new SimpleBag();
newInstance.ids = _idsBrancher.branch(instance.ids);
return newInstance;
}
@Override
public SimpleBag join(SimpleBag left, SimpleBag right) {
if (left == null) {
return right;
} else if (right == null) {
return left;
} else {
left.ids = _idsJoiner.join(left.ids, right.ids);
return left;
}
}
}
}
\ No newline at end of file
/** Generated by BaggageBuffersCompiler */
package brown.tracingplane.bdl.examples;
import brown.tracingplane.ActiveBaggage;
import brown.tracingplane.BaggageContext;
import brown.tracingplane.baggageprotocol.BagKey;
import brown.tracingplane.baggageprotocol.BaggageReader;
import brown.tracingplane.baggageprotocol.BaggageWriter;
import brown.tracingplane.bdl.BDLUtils;
import brown.tracingplane.bdl.Bag;
import brown.tracingplane.bdl.BaggageHandler;
import brown.tracingplane.bdl.Brancher;
import brown.tracingplane.bdl.Branchers;
import brown.tracingplane.bdl.Joiner;
import brown.tracingplane.bdl.Joiners;
import brown.tracingplane.bdl.Parser;
import brown.tracingplane.bdl.Parsers;
import brown.tracingplane.bdl.Serializer;
import brown.tracingplane.bdl.Serializers;
import brown.tracingplane.impl.BDLContextProvider;
import brown.tracingplane.impl.BaggageHandlerRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SimpleBag2 implements Bag {
private static final Logger _log = LoggerFactory.getLogger(SimpleBag2.class);
public Integer firstField = null;
public String secondField = null;
public boolean _overflow = false;
/**
* <p>
* Get the {@link SimpleBag2} set in the active {@link BaggageContext} carried by the current thread. If no baggage is being
* carried by the current thread, or if there is no SimpleBag2 in it, then this method returns {@code null}.
* </p>
*
* <p>
* To get SimpleBag2 from a specific Baggage instance, use {@link #getFrom(BaggageContext)}.
* </p>
*
* @return the SimpleBag2 being carried in the {@link BaggageContext} of the current thread, or {@code null}
* if none is being carried. The returned instance maybe be modified and modifications will be reflected in
* the baggage.
*/
public static SimpleBag2 get() {
Bag bag = BDLContextProvider.get(ActiveBaggage.peek(), Handler.registration());
if (bag instanceof SimpleBag2) {
return (SimpleBag2) bag;
} else {
return null;
}
}
/**
* <p>
* Get the {@link SimpleBag2} set in {@code baggage}. If {@code baggage} has no SimpleBag2 set then
* this method returns null.
* </p>
*
* <p>
* This method does <b>not</b> affect the Baggage being carried by the current thread. To get SimpleBag2
* from the current thread's Baggage, use {@link #get()}.
* </p>
*
* @param baggage A baggage instance to get the {@link SimpleBag2} from
* @return the {@link SimpleBag2} instance being carried in {@code baggage}, or {@code null} if none is being carried.
* The returned instance can be modified, and modifications will be reflected in the baggage.
*/
public static SimpleBag2 getFrom(BaggageContext baggage) {
Bag bag = BDLContextProvider.get(baggage, Handler.registration());
if (bag instanceof SimpleBag2) {
return (SimpleBag2) bag;
} else if (bag != null) {
Handler.checkRegistration();
}
return null;
}
/**
* <p>
* Update the {@link SimpleBag2} set in the current thread's baggage. This method will overwrite any existing
* SimpleBag2 set in the current thread's baggage.
* </p>
*
* <p>
* To set the {@link SimpleBag2} in a specific {@link BaggageContext} instance, use
* {@link #setIn(BaggageContext, SimpleBag2)}
* </p>
*
* @param simpleBag2 the new {@link SimpleBag2} to set in the current thread's {@link BaggageContext}. If {@code null}
* then any existing mappings will be removed.
*/
public static void set(SimpleBag2 simpleBag2) {
ActiveBaggage.update(BDLContextProvider.set(ActiveBaggage.peek(), Handler.registration(), simpleBag2));
}
/**
* <p>
* Update the {@link SimpleBag2} set in {@code baggage}. This method will overwrite any existing
* SimpleBag2 set in {@code baggage}.
* </p>
*
* <p>
* This method does <b>not</b> affect the {@link BaggageContext} being carried by the current thread. To set the
* {@link SimpleBag2} for the current thread, use {@link #set(SimpleBag2)}
* </p>
*
* @param baggage A baggage instance to set the {@link SimpleBag2} in
* @param simpleBag2 the new SimpleBag2 to set in {@code baggage}. If {@code null}, it will remove any
* mapping present.
* @return a possibly new {@link BaggageContext} instance that contains all previous mappings plus the new mapping.
*/
public static BaggageContext setIn(BaggageContext baggage, SimpleBag2 simpleBag2) {
return BDLContextProvider.set(baggage, Handler.registration(), simpleBag2);
}
@Override
public BaggageHandler<?> handler() {
return Handler.instance;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("SimpleBag2{\n");
b.append(this.firstField == null ? "" : BDLUtils.indent(String.format("firstField = %s\n", String.valueOf(this.firstField))));
b.append(this.secondField == null ? "" : BDLUtils.indent(String.format("secondField = %s\n", String.valueOf(this.secondField))));
b.append("}");
return b.toString();
}
public static class Handler implements BaggageHandler<SimpleBag2> {
public static final Handler instance = new Handler();
private static BagKey registration = null;
static synchronized BagKey checkRegistration() {
registration = BaggageHandlerRegistry.get(instance);
if (registration == null) {
_log.error("SimpleBag2 MUST be registered to a key before it can be propagated. " +
"There is currently no registration for SimpleBag2 and it will not be propagated. " +
"To register a bag set the bag.{index} property in your application.conf (eg, for " +
"index 10, bag.10 = \"brown.tracingplane.bdl.examples.SimpleBag2\") or with -Dbag.{index} flag " +
"(eg, for index 10, -Dbag.10=brown.tracingplane.bdl.examples.SimpleBag2)");
}
return registration;
}
static BagKey registration() {
return registration == null ? checkRegistration() : registration;
}
private Handler(){}
private static final BagKey _firstFieldKey = BagKey.indexed(1);
private static final BagKey _secondFieldKey = BagKey.indexed(2);
private static final Parser<Integer> _firstFieldParser = Parsers.int32Parser();
private static final Serializer<Integer> _firstFieldSerializer = Serializers.int32Serializer();
private static final Brancher<Integer> _firstFieldBrancher = Branchers.<Integer>noop();
private static final Joiner<Integer> _firstFieldJoiner = Joiners.<Integer>first();
private static final Parser<String> _secondFieldParser = Parsers.stringParser();
private static final Serializer<String> _secondFieldSerializer = Serializers.stringSerializer();
private static final Brancher<String> _secondFieldBrancher = Branchers.<String>noop();
private static final Joiner<String> _secondFieldJoiner = Joiners.<String>first();
@Override
public boolean isInstance(Bag bag) {
return bag == null || bag instanceof SimpleBag2;
}
@Override
public SimpleBag2 parse(BaggageReader reader) {
SimpleBag2 instance = new SimpleBag2();
if (reader.enter(_firstFieldKey)) {
instance.firstField = _firstFieldParser.parse(reader);
reader.exit();
}
if (reader.enter(_secondFieldKey)) {
instance.secondField = _secondFieldParser.parse(reader);
reader.exit();
}
instance._overflow = reader.didOverflow();
return instance;
}
@Override
public void serialize(BaggageWriter writer, SimpleBag2 instance) {
if (instance == null) {
return;
}
writer.didOverflowHere(instance._overflow);
if (instance.firstField != null) {
writer.enter(_firstFieldKey);
_firstFieldSerializer.serialize(writer, instance.firstField);
writer.exit();
}
if (instance.secondField != null) {
writer.enter(_secondFieldKey);
_secondFieldSerializer.serialize(writer, instance.secondField);
writer.exit();
}
}
@Override
public SimpleBag2 branch(SimpleBag2 instance) {
if (instance == null) {
return null;
}
SimpleBag2 newInstance = new SimpleBag2();
newInstance.firstField = _firstFieldBrancher.branch(instance.firstField);
newInstance.secondField = _secondFieldBrancher.branch(instance.secondField);
return newInstance;
}
@Override
public SimpleBag2 join(SimpleBag2 left, SimpleBag2 right) {
if (left == null) {
return right;
} else if (right == null) {
return left;
} else {
left.firstField = _firstFieldJoiner.join(left.firstField, right.firstField);
left.secondField = _secondFieldJoiner.join(left.secondField, right.secondField);
return left;
}
}
}
}
\ No newline at end of file
/** Generated by BaggageBuffersCompiler */
package brown.tracingplane.bdl.examples;
import brown.tracingplane.bdl.Struct;
import brown.tracingplane.bdl.StructHelpers;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import brown.tracingplane.bdl.BDLUtils;
import java.nio.ByteBuffer;
public class SimpleStruct1 implements Struct {
private static final Logger _log = LoggerFactory.getLogger(SimpleStruct1.class);
public Integer integerField = 0;
public String stringField = "";
private static final SimpleStruct1 _defaultValue = new SimpleStruct1();
private static final Integer _integerField_defaultValue = 0;
private static final String _stringField_defaultValue = "";
@Override
public Struct.StructHandler<?> handler() {
return Handler.instance;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("SimpleStruct1{\n");
b.append(BDLUtils.indent(String.format("integerField = %s\n", String.valueOf(this.integerField == null ? _integerField_defaultValue : this.integerField))));
b.append(BDLUtils.indent(String.format("stringField = %s\n", String.valueOf(this.stringField == null ? _stringField_defaultValue : this.stringField))));
b.append("}");
return b.toString();
}
@Override
public boolean equals(Object other) {
if (other == null) {
return SimpleStruct1.equals(this, _defaultValue);
} else if (!(other instanceof SimpleStruct1)) {
return false;
} else {
return SimpleStruct1.equals(this, (SimpleStruct1) other);
}
}
@Override
public int hashCode() {
int result = 1;
result = result * 37 + (this.integerField == null ? _integerField_defaultValue : this.integerField).hashCode();
result = result * 37 + (this.stringField == null ? _stringField_defaultValue : this.stringField).hashCode();
return result;
}
private static boolean equals(SimpleStruct1 a, SimpleStruct1 b) {
if (!BDLUtils.equals(a.integerField, b.integerField, _integerField_defaultValue)) return false;
if (!BDLUtils.equals(a.stringField, b.stringField, _stringField_defaultValue)) return false;
return true;
}
public static class Handler implements Struct.StructHandler<SimpleStruct1> {
public static final Handler instance = new Handler();
private Handler(){}
private static final Struct.StructReader<Integer> _integerFieldReader = StructHelpers.int32Reader;
private static final Struct.StructSizer<Integer> _integerFieldSizer = StructHelpers.int32Sizer;
private static final Struct.StructWriter<Integer> _integerFieldWriter = StructHelpers.int32Writer;
private static final Struct.StructReader<String> _stringFieldReader = StructHelpers.stringReader;
private static final Struct.StructSizer<String> _stringFieldSizer = StructHelpers.stringSizer;
private static final Struct.StructWriter<String> _stringFieldWriter = StructHelpers.stringWriter;
@Override
public SimpleStruct1 readFrom(ByteBuffer buf) throws Exception {
SimpleStruct1 instance = new SimpleStruct1();
try {
instance.integerField = _integerFieldReader.readFrom(buf);
instance.stringField = _stringFieldReader.readFrom(buf);
} catch (Exception e) {
_log.warn("Exception parsing SimpleStruct1 ", e);
}
return instance;
}
@Override
public void writeTo(ByteBuffer buf, SimpleStruct1 instance) {
try {
_integerFieldWriter.writeTo(buf, instance.integerField == null ? _integerField_defaultValue : instance.integerField);
_stringFieldWriter.writeTo(buf, instance.stringField == null ? _stringField_defaultValue : instance.stringField);
} catch (Exception e) {
_log.warn("Exception serializing SimpleStruct1 ", e);
}
}
@Override
public int serializedSize(SimpleStruct1 instance) {
int size = 0;
size += _integerFieldSizer.serializedSize(instance.integerField == null ? _integerField_defaultValue : instance.integerField);
size += _stringFieldSizer.serializedSize(instance.stringField == null ? _stringField_defaultValue : instance.stringField);
return size;
}
}
}
\ No newline at end of file
/** Generated by BaggageBuffersCompiler */
package brown.tracingplane.bdl.examples;
import brown.tracingplane.bdl.Struct;
import brown.tracingplane.bdl.StructHelpers;
import brown.tracingplane.bdl.examples.SimpleStruct1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import brown.tracingplane.bdl.BDLUtils;
import java.nio.ByteBuffer;
public class SimpleStruct2 implements Struct {