public static Deferred < byte [ ] > tsuidFromMetric ( final TSDB tsdb , final String metric , final Map < String , String > tags ) { if ( metric == null || metric . isEmpty ( ) ) { throw new IllegalArgumentException ( "The metric cannot be empty" ) ; } if ( tags == null || tags . isEmpty ( ) ) { throw new IllegalArgumentException ( "Tags cannot be null or empty " + "when getting a TSUID" ) ; } final byte [ ] metric_uid = new byte [ TSDB . metrics_width ( ) ] ; class TagsCB implements Callback < byte [ ] , ArrayList < byte [ ] > > { @ Override public byte [ ] call ( final ArrayList < byte [ ] > tag_list ) throws Exception { final byte [ ] tsuid = new byte [ metric_uid . length + ( ( TSDB . tagk_width ( ) + TSDB . tagv_width ( ) ) * tag_list . size ( ) ) ] ; int idx = 0 ; System . arraycopy ( metric_uid , 0 , tsuid , 0 , metric_uid . length ) ; idx += metric_uid . length ; for ( final byte [ ] t : tag_list ) { System . arraycopy ( t , 0 , tsuid , idx , t . length ) ; idx += t . length ; } return tsuid ; } @ Override public String toString ( ) { return "Tag resolution callback" ; } } class MetricCB implements Callback < Deferred < byte [ ] > , byte [ ] > { @ Override public Deferred < byte [ ] > call ( final byte [ ] uid ) throws Exception { System . arraycopy ( uid , 0 , metric_uid , 0 , uid . length ) ; return Tags . resolveAllAsync ( tsdb , tags ) . addCallback ( new TagsCB ( ) ) ; } @ Override public String toString ( ) { return "Metric resolution callback" ; } } return tsdb . getUIDAsync ( UniqueIdType . METRIC , metric ) . addCallbackDeferring ( new MetricCB ( ) ) ; }
Converts the given metric and tags to a TSUID by resolving the strings to their UIDs . Note that the resulting TSUID may not exist if the combination was not written to TSDB