本文整理汇总了Java中net.opentsdb.uid.UniqueId类的典型用法代码示例。如果您正苦于以下问题:Java UniqueId类的具体用法?Java UniqueId怎么用?Java UniqueId使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UniqueId类属于net.opentsdb.uid包,在下文中一共展示了UniqueId类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tagMap
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
public static Map<String, String> tagMap(TSMeta tsMeta) {
List<UIDMeta> metas = tsMeta.getTags();
final int size = metas.size()/2;
List<String> keys = new ArrayList<String>(size);
List<String> values = new ArrayList<String>(size);
Map<String, String> map = new LinkedHashMap<String, String>(size);
for(UIDMeta u: metas) {
if(u.getType()==UniqueId.UniqueIdType.TAGK) {
keys.add(u.getName());
} else {
values.add(u.getName());
}
}
for(int i = 0; i < size; i++) {
map.put(keys.get(i), values.get(i));
}
return map;
}
示例2: newTSMeta
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Creates a new TSMeta with random content
* @param tagCount The number of tags
* @param customMapEntries The number of custom map entries in the TSMeta and underlying UIDMetas
* @return the built TSMeta
*/
public static TSMeta newTSMeta(final int tagCount, final int customMapEntries) {
LinkedList<UIDMeta> uidMetas = new LinkedList<UIDMeta>();
for(int i = 0; i < tagCount+1; i++) {
uidMetas.add(newUIDMeta(UniqueIdType.TAGK, customMapEntries));
uidMetas.add(newUIDMeta(UniqueIdType.TAGV, customMapEntries));
}
UIDMeta metricMeta = newUIDMeta(UniqueIdType.METRIC, customMapEntries);
StringBuilder strTsuid = new StringBuilder(metricMeta.getUID());
for(UIDMeta umeta: uidMetas) {
strTsuid.append(umeta.getUID());
}
byte[] tsuid = UniqueId.stringToUid(strTsuid.toString());
TSMeta tsMeta = new TSMeta(tsuid, SystemClock.unixTime());
setTags(tsMeta, new ArrayList<UIDMeta>(uidMetas));
setMetric(tsMeta, metricMeta);
return tsMeta;
}
示例3: buildUIDMeta
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Builds a UIDMeta from the current row in the passed result set
* @param rset The result set to read from
* @param type THe UIDMeta type to build
* @return the built UIDMeta
*/
private UIDMeta buildUIDMeta(final ResultSet rset, final UniqueIdType type) {
try {
UIDMeta meta = new UIDMeta(type, UniqueId.stringToUid(rset.getString("XUID")), rset.getString("NAME"));
meta.setCreated(mstou(rset.getTimestamp("CREATED").getTime()));
String mapStr = rset.getString("CUSTOM");
if(mapStr!=null) {
meta.setCustom((HashMap<String, String>) readMap(mapStr));
}
meta.setDescription(rset.getString("DESCRIPTION"));
meta.setNotes(rset.getString("NOTES"));
meta.setDisplayName(rset.getString("DISPLAY_NAME"));
return meta;
} catch (Exception ex) {
throw new RuntimeException("Failed to build UIDMeta of type [" + type + "]", ex);
}
}
示例4: publishDataPoint
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Loads this event for a double value data point publication
* @param metric The name of the metric associated with the data point
* @param timestamp Timestamp as a Unix epoch in seconds or milliseconds (depending on the TSD's configuration)
* @param value Value for the data point
* @param tags The metric tags
* @param tsuid Time series UID for the value
* @return the loaded event
*/
public TSDBEvent publishDataPoint(String metric, long timestamp, double value, Map<String,String> tags, byte[] tsuid) {
this.eventType = TSDBEventType.DPOINT_DOUBLE;
this.metric = metric;
this.timestamp = timestamp;
this.doubleValue = value;
this.tags = new LinkedHashMap<String, String>(tags);
this.tsuidBytes = tsuid;
this.tsuid = UniqueId.uidToString(tsuid);
return this;
}
示例5: index
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Indexes a time series id
* @param tsMeta the time series
*/
public void index(final TSMeta tsMeta) {
if(tsMeta!=null) {
if(filter.put(UniqueId.stringToUid(tsMeta.getTSUID()))) {
retained.incrementAndGet();
}
}
}
示例6: uidFor
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Returns the UIDMeta uid as a byte array for the passed int
* @param key The int ot generate a byte array for
* @return the uid byte array
*/
public static byte[] uidFor(int key) {
StringBuilder b = new StringBuilder(Integer.toHexString(key));
while(b.length()<6) {
b.insert(0, "0");
}
return UniqueId.stringToUid(b.toString());
}
示例7: readUIDMetas
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see com.heliosapm.streams.metrichub.MetaReader#readUIDMetas(java.sql.ResultSet, net.opentsdb.uid.UniqueId.UniqueIdType)
*/
@Override
public List<UIDMeta> readUIDMetas(final ResultSet rset, final UniqueIdType uidType) {
if(rset==null) throw new IllegalArgumentException("The passed result set was null");
List<UIDMeta> uidMetas = new ArrayList<UIDMeta>();
try {
while(rset.next()) {
UniqueIdType utype = null;
if(uidType!=null) {
utype = uidType;
} else {
utype = UniqueIdType.valueOf(rset.getString("TAG_TYPE"));
}
UIDMeta meta = new UIDMeta(utype, UniqueId.stringToUid(rset.getString("XUID")), rset.getString("NAME"));
meta.setCreated(mstou(rset.getTimestamp("CREATED").getTime()));
String mapStr = rset.getString("CUSTOM");
if(mapStr!=null) {
meta.setCustom((HashMap<String, String>) readMap(mapStr));
}
meta.setDescription(rset.getString("DESCRIPTION"));
meta.setNotes(rset.getString("NOTES"));
meta.setDisplayName(rset.getString("DISPLAY_NAME"));
uidMetas.add(meta);
}
} catch (Exception ex) {
throw new RuntimeException("Failed to read UIDMetas from ResultSet", ex);
}
return uidMetas;
}
示例8: buildTSMeta
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Builds a TSMeta from the current row in the passed result set
* @param rset The result set to read from
* @param includeUIDs true to load UIDs, false otherwise
* @return the built TSMeta
*/
protected TSMeta buildTSMeta(final ResultSet rset, final boolean includeUIDs) {
try {
TSMeta meta = new TSMeta(UniqueId.stringToUid(rset.getString("TSUID")), mstou(rset.getTimestamp("CREATED").getTime()));
String mapStr = rset.getString("CUSTOM");
if(mapStr!=null) {
meta.setCustom((HashMap<String, String>) readMap(mapStr));
}
meta.setDescription(rset.getString("DESCRIPTION"));
meta.setNotes(rset.getString("NOTES"));
String disp = rset.getString("DISPLAY_NAME");
if(disp==null || disp.trim().isEmpty()) disp = rset.getString("FQN");
meta.setDisplayName(disp);
meta.setDataType(rset.getString("DATA_TYPE"));
meta.setMax(rset.getDouble("MAX_VALUE"));
meta.setMin(rset.getDouble("MIN_VALUE"));
meta.setRetention(rset.getInt("RETENTION"));
meta.setUnits(rset.getString("UNITS"));
final long fqnId = rset.getLong("FQNID");
if(includeUIDs) {
loadUIDs(
rset.isClosed() ? null : rset.getStatement().getConnection(),
meta, rset.getString("METRIC_UID"), fqnId);
}
return meta;
} catch (Exception ex) {
throw new RuntimeException("Failed to read TSMetas from ResultSet", ex);
}
}
示例9: match
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see com.heliosapm.streams.metrichub.MetricsMetaAPI#match(java.lang.String, byte[])
*/
@Override
public Promise<Boolean> match(final String expression, final byte[] tsuid) {
if(tsuid==null || tsuid.length==0) {
throw new IllegalArgumentException("The passed tsuid was null or empty");
}
return match(expression, UniqueId.uidToString(tsuid));
}
示例10: getTSMetaAsync
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
protected Deferred<TSMeta> getTSMetaAsync(final TSDBMetricMeta meta) {
final Context ctx = getTSMetaTimer.time();
return TSMeta.getTSMeta(tsdb, UniqueId.uidToString(meta.getTsuid())).addCallback(new Callback<TSMeta, TSMeta>() {
@Override
public TSMeta call(final TSMeta tsMeta) throws Exception {
ctx.close();
return tsMeta;
}
});
}
示例11: UniqueIdRegistry
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Creates a new UniqueIdRegistry
* @param The TSDB used by this service
*/
private UniqueIdRegistry(TSDB t) {
this.tsdb = t;
metrics = (UniqueId) PrivateAccessor.getFieldValue(tsdb, "metrics");
byType.put(UniqueId.UniqueIdType.METRIC, metrics);
tag_names = (UniqueId) PrivateAccessor.getFieldValue(tsdb, "tag_names");
byType.put(UniqueId.UniqueIdType.TAGK, tag_names);
tag_values = (UniqueId) PrivateAccessor.getFieldValue(tsdb, "tag_values");
byType.put(UniqueId.UniqueIdType.TAGV, tag_values);
JMXHelper.registerMBean(this, OBJECT_NAME);
}
示例12: forType
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Returns the UniqueId for the passed UniqueIdType name
* @param name The UniqueIdType name to get the UniqueId for
* @return the UniqueIdType
*/
public UniqueId forType(String name) {
if(name==null) throw new IllegalArgumentException("The passed UniqueIdType name was null");
name = name.trim().toUpperCase();
UniqueId.UniqueIdType type = null;
try {
type = UniqueId.UniqueIdType.valueOf(name);
return forType(type);
} catch (Exception ex) {
throw new IllegalArgumentException("The name [" + name + "] is not a valid UniqueIdType");
}
}
示例13: start
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
@Override
public void start() throws UnableToStartException {
super.start();
String zkConnectString = getConfig().get(HConstants.ZOOKEEPER_QUORUM) + ":" + getConfig().get(HConstants.ZOOKEEPER_CLIENT_PORT);
getConfig().set("tsd.storage.hbase.zk_quorum", zkConnectString);
getConfig().set("tsd.storage.hbase.zk_basedir", getConfig().get(HConstants.ZOOKEEPER_ZNODE_PARENT));
getConfig().set("tsd.http.cachedir", "target/tsdb/cache");
getConfig().set("tsd.http.staticroot", "target/tsdb/staticroot");
getConfig().set("tsd.core.auto_create_metrics", "true");
//now we have to create tables
try {
getTestingUtility().createTable(Bytes.toBytes("tsdb"), Bytes.toBytes("t"));
getTestingUtility().createTable(TableName.valueOf("tsdb-uid"), new String[] {"id", "name"});
getTestingUtility().createTable(Bytes.toBytes("tsdb-tree"), Bytes.toBytes("t"));
getTestingUtility().createTable(Bytes.toBytes("tsdb-meta"), Bytes.toBytes("name"));
tsdb = new TSDB(new TSDBConfig(getConfig()));
if(metrics.size() > 0) {
final UniqueId uid = new UniqueId(tsdb.getClient(), tsdb.uidTable(), "metrics", (int) 3);
for (String metric : metrics) {
byte[] u = uid.getOrCreateId(metric);
}
}
} catch (IOException e) {
throw new UnableToStartException("Unable to create TSDB tables", e);
}
}
示例14: getTagKeys
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* {@inheritDoc}
* @see com.heliosapm.streams.metrichub.MetricsMetaAPI#getTagKeys(com.heliosapm.streams.metrichub.QueryContext, java.lang.String, java.lang.String[])
*/
@Override
public Stream<List<UIDMeta>> getTagKeys(final QueryContext queryContext, final String metric, final String...tagKeys) {
return getUIDsFor(null, queryContext, UniqueId.UniqueIdType.TAGK, UniqueId.UniqueIdType.METRIC, metric, tagKeys);
}
示例15: getUIDsFor
import net.opentsdb.uid.UniqueId; //导入依赖的package包/类
/**
* Executes a single correlated UID query, where the target is the type we want to query and the filter is the correlation data.
* @param priorDeferred An optional deferred result from a prior continuous call. If null, this is assumed
* to be the first call and a new deferred will be created.
* @param queryContext The query options
* @param targetType The type we're looking up
* @param filterType The type we're using to filter
* @param filterName The primary filter name driver
* @param excludes Values of the target name that we don't want
* @return A deferred result to a set of matching UIDMetas of the type defined in the target argument
*/
protected Stream<List<UIDMeta>> getUIDsFor(final Deferred<UIDMeta, Stream<UIDMeta>> priorDeferred, final QueryContext queryContext, final UniqueId.UniqueIdType targetType, final UniqueId.UniqueIdType filterType, final String filterName, final String...excludes) {
final Deferred<UIDMeta, Stream<UIDMeta>> def = getDeferred(priorDeferred, queryContext);
final Stream<List<UIDMeta>> stream = def.compose().collect();
final String _filterName = (filterName==null || filterName.trim().isEmpty()) ? "*" : filterName.trim();
fjPool.execute(new Runnable() {
@SuppressWarnings("boxing")
public void run() {
final List<Object> binds = new ArrayList<Object>();
String sql = null;
final String predicate = expandPredicate(_filterName, TAGK_SQL_BLOCK, binds);
try {
// binds.add(filterName);
StringBuilder keyBinds = new StringBuilder();
for(String key: excludes) {
keyBinds.append("?, ");
binds.add(key);
}
if(keyBinds.length()>0) {
keyBinds.deleteCharAt(keyBinds.length()-1);
keyBinds.deleteCharAt(keyBinds.length()-1);
}
// * 1. The target UID type
// * 2. The correlation UID type
// * 3. The bind symbols for #2
// * 4. The start at XUID expression
if(queryContext.getNextIndex()==null) {
sql = String.format(GET_KEY_TAGS_SQL, targetType, filterType, predicate, keyBinds, INITIAL_XUID_START_SQL);
} else {
sql = String.format(GET_KEY_TAGS_SQL, targetType, filterType, predicate, keyBinds, XUID_START_SQL);
binds.add(queryContext.getNextIndex());
}
binds.add(queryContext.getNextMaxLimit() + 1);
if(log.isDebugEnabled()) log.debug("Executing SQL [{}]", fillInSQL(sql, binds));
final ResultSet rset = sqlWorker.executeQuery(sql, true, binds.toArray(new Object[0]));
final IndexProvidingIterator<UIDMeta> iter = metaReader.iterateUIDMetas(rset, targetType);
try {
while(processStream(iter, def, queryContext)) {/* No Op */}
} finally {
try { rset.close(); } catch (Exception x) {/* No Op */}
}
} catch (Exception ex) {
log.error("Failed to execute getTagKeysFor.\nSQL was [{}]", sql, ex);
def.accept(new Exception("Failed to execute getTagValues", ex));
}
}
});
return stream;
}