@@ -0,0 +1,2894 @@
+package edu.brown.cs.systems.baggage;%0A%0Aimport java.nio.ByteBuffer;%0Aimport java.util.Set;%0A%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport com.google.protobuf.ByteString;%0A%0Aimport edu.brown.cs.systems.baggage.BaggageContents;%0A%0A/** Simple use of the baggage to propagate string tags with a request.%0A * Useful for prototyping and as an example of how to use Baggage for your own namespace%0A */%0Apublic class BaggageTags %7B%0A%0A      private static final Logger log = LoggerFactory.getLogger(BaggageTags.class);%0A%0A      /** Statically assign the namespace to use the byte '3' **/%0A      public static final ByteString BAGGAGE_TAG_NAMESPACE = ByteString.copyFrom(new byte%5B%5D %7B 0x05 %7D);%0A      %0A      /** Within the BaggageTag namespace, there is only one field -- the tenant ID */%0A      public static final ByteString TAG_ID_BAGGAGE_FIELD = ByteString.copyFrom(new byte%5B%5D %7B 0x01 %7D);%0A%0A      /**%0A       * Checks the baggage being propagated in the current thread to see whether%0A       * it contains a tenant ID%0A       * %0A       * @return true if the current thread has a tenant ID, false otherwise%0A       */%0A      public static boolean hasTenant() %7B%0A          return BaggageContents.contains(BAGGAGE_TAG_NAMESPACE, TAG_ID_BAGGAGE_FIELD);%0A      %7D%0A%0A      /**%0A       * Get the current tenant ID from the baggage, if one is being propagated%0A       * %0A       * @return the tenant ID being propagated in the baggage, or 0 if no tenant%0A       *         is being propagated%0A       */%0A      public static int%5B%5D getTenants() %7B%0A          if (BaggageContents.contains(BAGGAGE_TAG_NAMESPACE, TAG_ID_BAGGAGE_FIELD)) %7B%0A            Set%3CByteString%3E tenantIds = BaggageContents.get(BAGGAGE_TAG_NAMESPACE, TAG_ID_BAGGAGE_FIELD);%0A            if (tenantIds.size() %3E= 1) %7B%0A              int%5B%5D tags = new int%5BtenantIds.size()%5D;%0A              int i = 0;%0A              for (ByteString tenantId : tenantIds) %7B%0A                if (tenantId.size() == 4) %7B%0A                  tags%5Bi%5D = tenantId.asReadOnlyByteBuffer().getInt();%0A                %7D else %7B%0A                  log.warn(%22Expected 4-byte tenantID, actually got %7B%7D bytes: %7B%7D%22, tenantId.size(), tenantId);%0A                  tags%5Bi%5D = -1;%0A                %7D%0A                i++;%0A              %7D%0A              return tags;%0A            %7D%0A%0A            // Remove erroneous tenant ID value%0A            BaggageContents.remove(BAGGAGE_TAG_NAMESPACE, TAG_ID_BAGGAGE_FIELD);%0A          %7D%0A          return null;%0A      %7D%0A%0A      /**%0A       * Set the tenant ID for the current execution to the provided tenant ID%0A       * %0A       * @param tenantId%0A       *            the tenant ID to set for the current execution%0A       */%0A      public static void setTenant(int tenantId) %7B%0A          byte%5B%5D tenantIdBytes = ByteBuffer.allocate(4).putInt(tenantId).array();%0A          BaggageContents.replace(BAGGAGE_TAG_NAMESPACE, TAG_ID_BAGGAGE_FIELD, ByteString.copyFrom(tenantIdBytes));%0A      %7D%0A%7D%0A

Add simple BaggageTags class for adding random tags to baggage