下面列出了com.google.common.collect.Table#Cell ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static Map<String, String> parseTable(String data, boolean trimValue) throws IOException {
if (data == null) {
return ImmutableMap.of();
}
TableConfig.TableParser parser;
if (trimValue) {
parser = TableConfig.TRIM_PARSER;
} else {
parser = TableConfig.NOT_TRIM_PARSER;
}
Table<String, String, String> table = parser.parse(data);
Map<String, String> map = new LinkedHashMap<String, String>(table.size());
for (Table.Cell<String, String, String> cell : table.cellSet()) {
map.put(generateKey(cell.getRowKey(), cell.getColumnKey()), cell.getValue());
}
return ImmutableMap.copyOf(map);
}
static Stream<MavenDependency> createCellDependencies(
final String scalaAbi, final Table.Cell<String, String, Dependencies.Maven> cell) {
final String groupIdBase = cell.getRowKey();
final String artifactIdBase = cell.getColumnKey();
final Dependencies.Maven dependencySpec = cell.getValue();
assert dependencySpec != null;
return buildCoords(groupIdBase, artifactIdBase, dependencySpec.modules())
.map(
coord ->
MavenDependency.create(
dependencySpec.kind().isScala() ? coord.withScalaAbi(scalaAbi) : coord,
dependencySpec.version(),
dependencySpec.neverLink(),
dependencySpec.kind()));
}
/**
* Renews the {@link SecureStore} for all the running applications.
*
* @param liveApps set of running applications that need to have secure store renewal
* @param renewer the {@link SecureStoreRenewer} for renewal
* @param mergeCredentials {@code true} to merge with existing credentials
* @return a {@link Multimap} containing the application runs that were failed to have secure store renewed
*/
private Multimap<String, RunId> renewSecureStore(Table<String, RunId, YarnTwillController> liveApps,
SecureStoreRenewer renewer, boolean mergeCredentials) {
Multimap<String, RunId> failureRenews = HashMultimap.create();
// Renew the secure store for each running application
for (Table.Cell<String, RunId, YarnTwillController> liveApp : liveApps.cellSet()) {
String application = liveApp.getRowKey();
RunId runId = liveApp.getColumnKey();
YarnTwillController controller = liveApp.getValue();
try {
renewer.renew(application, runId, new YarnSecureStoreWriter(application, runId, controller, mergeCredentials));
} catch (Exception e) {
LOG.warn("Failed to renew secure store for {}:{}", application, runId, e);
failureRenews.put(application, runId);
}
}
return failureRenews;
}
@Override
public Set<Pair<Unit, Abstraction>> endSummary(SootMethod m, Abstraction d3) {
Set<Pair<Unit, Abstraction>> res = null;
for (Unit sP : icfg.getStartPointsOf(m)) {
Set<Table.Cell<Unit,Abstraction,EdgeFunction<IFDSSolver.BinaryDomain>>> endSum =
super.endSummary(sP, d3);
if (endSum == null || endSum.isEmpty())
continue;
if (res == null)
res = new HashSet<>();
for (Table.Cell<Unit,Abstraction,EdgeFunction<IFDSSolver.BinaryDomain>> cell : endSum)
res.add(new Pair<>(cell.getRowKey(), cell.getColumnKey()));
}
return res;
}
@Override
public Table<?, ASTNode, ArrayList<String>> performOp(final FoldableNode fn,
final Table<?, ASTNode, ArrayList<String>> prev) {
// Check if ASTNode has a FoldableNode parent
// If so, add it to a child FoldableNode (along with its terms)
for (final Table.Cell<?, ASTNode, ArrayList<String>> cell : prev.cellSet()) {
if (cell.getColumnKey() == fn.node) {
final FoldableNode fnChild = new FoldableNode((ASTNode) cell.getRowKey());
fnChild.addTerms(cell.getValue());
fn.addChild(fnChild);
}
}
return prev;
}
public Table<String, String, Property> loadFromConfiguration(Configuration config) {
final Table<String, String, Property> properties = HashBasedTable.create();
for (Table.Cell<String, String, FeatureEntry> cell : features.cellSet()) {
final FeatureEntry entry = cell.getValue();
if (!entry.isConfigurable) continue;
final String categoryName = cell.getRowKey();
final String featureName = cell.getColumnKey();
final Property prop = config.get(categoryName, featureName, entry.isEnabled);
properties.put(categoryName, featureName, prop);
if (!prop.wasRead()) continue;
if (!prop.isBooleanValue()) prop.set(entry.isEnabled);
else entry.isEnabled = prop.getBoolean(entry.isEnabled);
}
return ImmutableTable.copyOf(properties);
}
public DefaultValidateQTable(QTable table) {
rowKeyToIndex = makeIndex(table.rowKeySet());
columnKeyToIndex = makeIndex(table.columnKeySet());
rowSize = rowKeyToIndex.size();
columnSize = columnKeyToIndex.size();
Set<Table.Cell<String, String, String>> inputCells = table.cellSet();
size = inputCells.size();
cells = new Cell[rowSize][columnSize];
countInRow = new int[rowSize];
countInColumn = new int[columnSize];
ImmutableList.Builder<Cell> cellListBuilder = ImmutableList.builder();
for (Table.Cell<String, String, String> inputCell : inputCells) {
int rowIndex = rowKeyToIndex.get(inputCell.getRowKey());
int columnIndex = columnKeyToIndex.get(inputCell.getColumnKey());
Cell cell = new Cell(inputCell.getRowKey(), inputCell.getColumnKey(), inputCell.getValue());
cells[rowIndex][columnIndex] = cell;
cellListBuilder.add(cell);
countInRow[rowIndex]++;
countInColumn[columnIndex]++;
}
cellList = cellListBuilder.build();
ImmutableMap.Builder<String, Row> rowsBuilder = ImmutableMap.builder();
for (String row : table.rowKeySet()) {
rowsBuilder.put(row, new Row(row));
}
rows = rowsBuilder.build();
ImmutableMap.Builder<String, Column> columnsBuilder = ImmutableMap.builder();
for (String column : table.columnKeySet()) {
columnsBuilder.put(column, new Column(column));
}
columns = columnsBuilder.build();
}
/**
* Java Serialization support for the entryUtilization field.
* @param oos stream to write to
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
ArrayList<UtilizationBean> entryUtilizationElements = null;
if (entryUtilization != null) {
entryUtilizationElements = new ArrayList<>(entryUtilization.size());
for (Table.Cell<Integer, String, AtomicInteger> cell: entryUtilization.cellSet()) {
entryUtilizationElements.add(
new UtilizationBean(cell.getRowKey(), cell.getColumnKey(), cell.getValue()));
}
}
oos.writeObject(entryUtilizationElements);
}
/**
* Java Serialization support for the utilization field.
* @param oos stream to write to
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
ArrayList<Payer.UtilizationBean> entryUtilizationElements = null;
if (utilization != null) {
entryUtilizationElements = new ArrayList<>(utilization.size());
for (Table.Cell<Integer, String, AtomicInteger> cell: utilization.cellSet()) {
entryUtilizationElements.add(
new Payer.UtilizationBean(cell.getRowKey(), cell.getColumnKey(), cell.getValue()));
}
}
oos.writeObject(entryUtilizationElements);
}
private boolean isInErrorState(WeightedForwardQuery<TransitionFunction> key, ForwardBoomerangResults<TransitionFunction> forwardBoomerangResults) {
Table<Statement, Val, TransitionFunction> objectDestructingStatements = forwardBoomerangResults.asStatementValWeightTable();
for(Table.Cell<Statement,Val,TransitionFunction> c : objectDestructingStatements.cellSet()){
for(ITransition t : c.getValue().values()){
if(t.to() != null){
if(t.to().isErrorState()){
return true;
}
}
}
}
return false;
}
/**
* Signals that the last target has finished. This event
* will still be fired if an error occurred during the build.
*
* @param event An event with any relevant extra information.
* Must not be <code>null</code>.
* @see BuildEvent#getException()
*/
@Override
public void buildFinished(BuildEvent event) {
/* ******* post-Test reporting ********* */
// ant file runs junitreporter, so those reports are done
// just log the traffic, until we write the coverage-tests
for (Table.Cell<String, String, Integer> cell : Base.getMessages().cellSet()) {
trafficlog.info(cell.getRowKey() + " " + cell.getColumnKey() + " " + cell.getValue());
}
String todir = event.getProject().getUserProperty("ctk.todir");
log.debug("buildFinished for " + todir);
// signal the listener to proceed
result.complete(todir +"report/html/index.html");
}
public CodeReferenceMap build() {
ImmutableTable.Builder<String, String, ImmutableSet<String>> deadMethodsBuilder =
ImmutableTable.builder();
for (Table.Cell<String, String, Set<String>> cell : this.deadMethods.cellSet()) {
deadMethodsBuilder.put(
cell.getRowKey(),
cell.getColumnKey(),
ImmutableSet.copyOf(cell.getValue()));
}
return new CodeReferenceMap(
ImmutableSet.copyOf(deadClasses),
deadMethodsBuilder.build(),
ImmutableMultimap.copyOf(deadFields));
}
/**
* Fetches a {@link com.rackspacecloud.blueflood.types.Points} object for a
* particular locator and rollupType from the specified column family and
* range
*
* @param locator
* @param rollupType
* @param range
* @param columnFamilyName
* @return
*/
@Override
public Points getDataToRollup(final Locator locator,
RollupType rollupType,
Range range,
String columnFamilyName) throws IOException {
Timer.Context ctx = Instrumentation.getReadTimerContext(columnFamilyName);
try {
// read the rollup object from the proper IO class
DAbstractMetricIO io = getIO( rollupType.name().toLowerCase(), CassandraModel.getGranularity( columnFamilyName ) );
Table<Locator, Long, Object> locatorTimestampRollup = io.getRollupsForLocator( locator, columnFamilyName, range );
Points points = new Points();
for (Table.Cell<Locator, Long, Object> cell : locatorTimestampRollup.cellSet()) {
points.add( createPoint( cell.getColumnKey(), cell.getValue()));
}
return points;
} catch( Exception e ) {
Instrumentation.markReadError();
LOG.error( String.format( "Unable to read locator=%s rolluptype=%s columnFamilyName=%s for rollup",
locator, rollupType.name(), columnFamilyName ), e );
throw new IOException( e );
}
finally {
ctx.stop();
}
}
@Override
public void putAll( Table<Locator, String, String> meta ) throws IOException {
Timer.Context ctx = Instrumentation.getWriteTimerContext( CassandraModel.CF_METRICS_METADATA_NAME );
Session session = DatastaxIO.getSession();
Map<Locator, ResultSetFuture> futures = new HashMap<Locator, ResultSetFuture>();
try {
for( Table.Cell<Locator, String, String> cell : meta.cellSet() ) {
BoundStatement bound = putValue.bind( cell.getRowKey().toString(), cell.getColumnKey(), serDes.serialize( cell.getValue() ) );
futures.put( cell.getRowKey(), session.executeAsync( bound ) );
}
for( Map.Entry<Locator, ResultSetFuture> future : futures.entrySet() ) {
try {
ResultSet result = future.getValue().getUninterruptibly();
LOG.trace( "result.size=" + result.all().size() );
}
catch (Exception e ){
Instrumentation.markWriteError();
LOG.error( String.format( "error writing to metrics_metadata for %s", future.getKey()), e );
}
}
}
finally {
ctx.stop();
}
}
/** Returns the attribute keys contained in the attributes map for the file. */
@VisibleForTesting
final synchronized ImmutableSet<String> getAttributeKeys() {
if (attributes == null) {
return ImmutableSet.of();
}
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (Table.Cell<String, String, Object> cell : attributes.cellSet()) {
builder.add(cell.getRowKey() + ':' + cell.getColumnKey());
}
return builder.build();
}
/**
* Creates a {@link Runnable} for renewing {@link SecureStore} for running applications.
*
* @param scheduler the schedule to schedule next renewal execution
* @param renewer the {@link SecureStoreRenewer} to use for renewal
* @param retryRuns if non-empty, only the given set of application name and run id that need to have
* secure store renewed; if empty, renew all running applications
* @param retryDelay the delay before retrying applications that are failed to have secure store renewed
* @param timeUnit the unit for the {@code delay} and {@code failureDelay}.
* @return a {@link Runnable}
*/
private Runnable createSecureStoreUpdateRunnable(final ScheduledExecutorService scheduler,
final SecureStoreRenewer renewer,
final Multimap<String, RunId> retryRuns,
final long retryDelay, final TimeUnit timeUnit) {
return new Runnable() {
@Override
public void run() {
// Collects the set of running application runs
Table<String, RunId, YarnTwillController> liveApps;
synchronized (YarnTwillRunnerService.this) {
if (retryRuns.isEmpty()) {
liveApps = HashBasedTable.create(controllers);
} else {
// If this is a renew retry, only renew the one in the retryRuns set
liveApps = HashBasedTable.create();
for (Table.Cell<String, RunId, YarnTwillController> cell : controllers.cellSet()) {
if (retryRuns.containsEntry(cell.getRowKey(), cell.getColumnKey())) {
liveApps.put(cell.getRowKey(), cell.getColumnKey(), cell.getValue());
}
}
}
}
Multimap<String, RunId> failureRenews = renewSecureStore(liveApps, renewer, false);
if (!failureRenews.isEmpty()) {
// If there are failure during the renewal, schedule a retry with a new Runnable.
LOG.info("Schedule to retry on secure store renewal for applications {} in {} {}",
failureRenews.keySet(), retryDelay, timeUnit.name().toLowerCase());
try {
scheduler.schedule(
createSecureStoreUpdateRunnable(scheduler, renewer, failureRenews, retryDelay, timeUnit),
retryDelay, timeUnit);
} catch (RejectedExecutionException e) {
// If the renewal is stopped, the scheduler will be stopped,
// hence this exception will be thrown and can be safely ignore.
}
}
}
};
}
/**
* Add to root set, methods from CodeReferenceMap and also all public methods in input classes.
* Then, do tree shaker traversal starting from this root set.
* @param publicRootSet: CodeReferenceMap with public root methods and classes.
*/
//TODO(malvania): Current paradigm: All methods in input CodeReferenceMap are assumed to be
// public roots to traverse from.
//Classes in input CodeReferenceMap here allow user to add Dynamically Loaded Classes and keep
// their public methods in the public root set.
//In the future, when we add support for libraries, we will want to include protected methods
// of those library classes as well, so we should add "|| ElementUtil.isProtected(method)" after
// the isPublic check.
public void markUsedElements(CodeReferenceMap publicRootSet) {
if (publicRootSet == null) {
markUsedElements();
return;
}
//Add all public methods in publicRootClasses to root set
for (String clazz : publicRootSet.getReferencedClasses()) {
ClassReferenceNode classNode = (ClassReferenceNode) elementReferenceMap
.get(ElementReferenceMapper.stitchClassIdentifier(clazz));
assert(classNode != null);
Iterable<ExecutableElement> methods = ElementUtil.getMethods(classNode.classElement);
for (ExecutableElement method : methods) {
if (ElementUtil.isPublic(method)) {
rootSet.add(ElementReferenceMapper.stitchMethodIdentifier(method, env.typeUtil(),
env.elementUtil()));
}
}
}
//Add input root methods to static set
for (Table.Cell<String, String, ImmutableSet<String>> cell : publicRootSet
.getReferencedMethods().cellSet()) {
String clazzName = cell.getRowKey();
String methodName = cell.getColumnKey();
for (String signature : cell.getValue()) {
rootSet.add(ElementReferenceMapper
.stitchMethodIdentifier(clazzName, methodName, signature));
}
}
markUsedElements(staticSet);
markUsedElements(rootSet);
}
@Encoding.Naming("*CellSet")
public ImmutableSet<Table.Cell<R, C, V>> cellSet() {
return value.cellSet();
}