use of java.util.Map.Entry in project android_frameworks_base by ResurrectionRemix.
the class MountService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
final IndentingPrintWriter pw = new IndentingPrintWriter(writer, " ", 160);
synchronized (mLock) {
pw.println("Disks:");
pw.increaseIndent();
for (int i = 0; i < mDisks.size(); i++) {
final DiskInfo disk = mDisks.valueAt(i);
disk.dump(pw);
}
pw.decreaseIndent();
pw.println();
pw.println("Volumes:");
pw.increaseIndent();
for (int i = 0; i < mVolumes.size(); i++) {
final VolumeInfo vol = mVolumes.valueAt(i);
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(vol.id))
continue;
vol.dump(pw);
}
pw.decreaseIndent();
pw.println();
pw.println("Records:");
pw.increaseIndent();
for (int i = 0; i < mRecords.size(); i++) {
final VolumeRecord note = mRecords.valueAt(i);
note.dump(pw);
}
pw.decreaseIndent();
pw.println();
pw.println("Primary storage UUID: " + mPrimaryStorageUuid);
final Pair<String, Long> pair = StorageManager.getPrimaryStoragePathAndSize();
if (pair == null) {
pw.println("Internal storage total size: N/A");
} else {
pw.print("Internal storage (");
pw.print(pair.first);
pw.print(") total size: ");
pw.print(pair.second);
pw.print(" (");
pw.print((float) pair.second / TrafficStats.GB_IN_BYTES);
pw.println(" GB)");
}
pw.println("Force adoptable: " + mForceAdoptable);
pw.println();
pw.println("Local unlocked users: " + Arrays.toString(mLocalUnlockedUsers));
pw.println("System unlocked users: " + Arrays.toString(mSystemUnlockedUsers));
}
synchronized (mObbMounts) {
pw.println();
pw.println("mObbMounts:");
pw.increaseIndent();
final Iterator<Entry<IBinder, List<ObbState>>> binders = mObbMounts.entrySet().iterator();
while (binders.hasNext()) {
Entry<IBinder, List<ObbState>> e = binders.next();
pw.println(e.getKey() + ":");
pw.increaseIndent();
final List<ObbState> obbStates = e.getValue();
for (final ObbState obbState : obbStates) {
pw.println(obbState);
}
pw.decreaseIndent();
}
pw.decreaseIndent();
pw.println();
pw.println("mObbPathToStateMap:");
pw.increaseIndent();
final Iterator<Entry<String, ObbState>> maps = mObbPathToStateMap.entrySet().iterator();
while (maps.hasNext()) {
final Entry<String, ObbState> e = maps.next();
pw.print(e.getKey());
pw.print(" -> ");
pw.println(e.getValue());
}
pw.decreaseIndent();
}
pw.println();
pw.println("mConnector:");
pw.increaseIndent();
mConnector.dump(fd, pw, args);
pw.decreaseIndent();
pw.println();
pw.println("mCryptConnector:");
pw.increaseIndent();
mCryptConnector.dump(fd, pw, args);
pw.decreaseIndent();
pw.println();
pw.print("Last maintenance: ");
pw.println(TimeUtils.formatForLogging(mLastMaintenance));
}
use of java.util.Map.Entry in project opennms by OpenNMS.
the class NewtsFetchStrategy method fetch.
@Override
public FetchResults fetch(long start, long end, long step, int maxrows, Long interval, Long heartbeat, List<Source> sources, boolean relaxed) {
final LateAggregationParams lag = getLagParams(step, interval, heartbeat);
final Optional<Timestamp> startTs = Optional.of(Timestamp.fromEpochMillis(start));
final Optional<Timestamp> endTs = Optional.of(Timestamp.fromEpochMillis(end));
final Map<String, Object> constants = Maps.newHashMap();
// Group the sources by resource id to avoid calling the ResourceDao
// multiple times for the same resource
Map<ResourceId, List<Source>> sourcesByResourceId = sources.stream().collect(Collectors.groupingBy((source) -> ResourceId.fromString(source.getResourceId())));
// Lookup the OnmsResources in parallel
Map<ResourceId, Future<OnmsResource>> resourceFuturesById = Maps.newHashMapWithExpectedSize(sourcesByResourceId.size());
for (ResourceId resourceId : sourcesByResourceId.keySet()) {
resourceFuturesById.put(resourceId, threadPool.submit(getResourceByIdCallable(resourceId)));
}
// Gather the results, fail if any of the resources were not found
Map<OnmsResource, List<Source>> sourcesByResource = Maps.newHashMapWithExpectedSize(sourcesByResourceId.size());
for (Entry<ResourceId, Future<OnmsResource>> entry : resourceFuturesById.entrySet()) {
try {
OnmsResource resource = entry.getValue().get();
if (resource == null) {
if (relaxed)
continue;
LOG.error("No resource with id: {}", entry.getKey());
return null;
}
sourcesByResource.put(resource, sourcesByResourceId.get(entry.getKey()));
} catch (ExecutionException | InterruptedException e) {
throw Throwables.propagate(e);
}
}
// Now group the sources by Newts Resource ID, which differs from the OpenNMS Resource ID.
Map<String, List<Source>> sourcesByNewtsResourceId = Maps.newHashMap();
for (Entry<OnmsResource, List<Source>> entry : sourcesByResource.entrySet()) {
final OnmsResource resource = entry.getKey();
for (Source source : entry.getValue()) {
// Gather the values from strings.properties
Utils.convertStringAttributesToConstants(source.getLabel(), resource.getStringPropertyAttributes(), constants);
// Grab the attribute that matches the source
RrdGraphAttribute rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
if (rrdGraphAttribute == null && !Strings.isNullOrEmpty(source.getFallbackAttribute())) {
LOG.error("No attribute with name '{}', using fallback-attribute with name '{}'", source.getAttribute(), source.getFallbackAttribute());
source.setAttribute(source.getFallbackAttribute());
source.setFallbackAttribute(null);
rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
}
if (rrdGraphAttribute == null) {
if (relaxed)
continue;
LOG.error("No attribute with name: {}", source.getAttribute());
return null;
}
// The Newts Resource ID is stored in the rrdFile attribute
String newtsResourceId = rrdGraphAttribute.getRrdRelativePath();
// Remove the file separator prefix, added by the RrdGraphAttribute class
if (newtsResourceId.startsWith(File.separator)) {
newtsResourceId = newtsResourceId.substring(File.separator.length(), newtsResourceId.length());
}
List<Source> listOfSources = sourcesByNewtsResourceId.get(newtsResourceId);
// Create the list if it doesn't exist
if (listOfSources == null) {
listOfSources = Lists.newLinkedList();
sourcesByNewtsResourceId.put(newtsResourceId, listOfSources);
}
listOfSources.add(source);
}
}
// The Newts API only allows us to perform a query using a single (Newts) Resource ID,
// so we perform multiple queries in parallel, and aggregate the results.
Map<String, Future<Collection<Row<Measurement>>>> measurementsByNewtsResourceId = Maps.newHashMapWithExpectedSize(sourcesByNewtsResourceId.size());
for (Entry<String, List<Source>> entry : sourcesByNewtsResourceId.entrySet()) {
measurementsByNewtsResourceId.put(entry.getKey(), threadPool.submit(getMeasurementsForResourceCallable(entry.getKey(), entry.getValue(), startTs, endTs, lag)));
}
long[] timestamps = null;
Map<String, double[]> columns = Maps.newHashMap();
for (Entry<String, Future<Collection<Row<Measurement>>>> entry : measurementsByNewtsResourceId.entrySet()) {
Collection<Row<Measurement>> rows;
try {
rows = entry.getValue().get();
} catch (InterruptedException | ExecutionException e) {
throw Throwables.propagate(e);
}
final int N = rows.size();
if (timestamps == null) {
timestamps = new long[N];
int k = 0;
for (final Row<Measurement> row : rows) {
timestamps[k] = row.getTimestamp().asMillis();
k++;
}
}
int k = 0;
for (Row<Measurement> row : rows) {
for (Measurement measurement : row.getElements()) {
double[] column = columns.get(measurement.getName());
if (column == null) {
column = new double[N];
columns.put(measurement.getName(), column);
}
column[k] = measurement.getValue();
}
k += 1;
}
}
FetchResults fetchResults = new FetchResults(timestamps, columns, lag.getStep(), constants);
if (relaxed) {
Utils.fillMissingValues(fetchResults, sources);
}
LOG.trace("Fetch results: {}", fetchResults);
return fetchResults;
}
use of java.util.Map.Entry in project tdi-studio-se by Talend.
the class TracesConnectionUtils method createConnection.
/**
* DOC hwang Comment method "createConnection".
*/
public static DatabaseConnection createConnection(ConnectionParameters parameters) {
ExtractMetaDataUtils extractMeta = ExtractMetaDataUtils.getInstance();
String dbType = parameters.getDbType();
boolean isNeedSchema = EDatabaseTypeName.getTypeFromDbType(dbType).isNeedSchema();
String productName = EDatabaseTypeName.getTypeFromDisplayName(dbType).getProduct();
// boolean isOralceWithSid = productName.equals(EDatabaseTypeName.ORACLEFORSID.getProduct());
String schema = parameters.getSchema();
EDatabaseTypeName type = EDatabaseTypeName.getTypeFromDbType(dbType);
if (ManagerConnection.isSchemaFromSidOrDatabase(type)) {
schema = parameters.getDbName();
}
if ("".equals(schema) && EDatabaseTypeName.INFORMIX.getProduct().equals(productName)) {
//$NON-NLS-1$
schema = parameters.getUserName();
}
if (EDatabaseTypeName.EXASOL.getProduct().equals(productName)) {
schema = parameters.getDbName();
}
boolean isSchemaInValid = //$NON-NLS-1$ //$NON-NLS-2$
(schema == null) || (schema.equals("\'\'")) || (schema.equals("\"\"")) || //$NON-NLS-1$
(schema.trim().equals(""));
// from 616 till line 622 modified by hyWang
NotReallyNeedSchemaDBS dbs = new NotReallyNeedSchemaDBS();
dbs.init();
List<String> names = dbs.getNeedSchemaDBNames();
boolean ifNeedSchemaDB = names.contains(productName);
if (isNeedSchema && isSchemaInValid && !ifNeedSchemaDB) {
//$NON-NLS-1$
parameters.setConnectionComment(Messages.getString("TracesConnectionUtils.connectionComment"));
return null;
}
DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
connection.setFileFieldName(parameters.getFilename());
connection.setDatabaseType(dbType);
connection.setUsername(parameters.getUserName());
connection.setPort(parameters.getPort());
connection.setRawPassword(parameters.getPassword());
if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName()) && parameters.getLocalServiceName() != null && !"".equals(parameters.getLocalServiceName())) {
connection.setSID(parameters.getLocalServiceName());
} else {
connection.setSID(parameters.getDbName());
}
connection.setLabel(parameters.getDbName());
connection.setDatasourceName(parameters.getDatasource());
if (parameters.getDbType().equals(EDatabaseTypeName.GODBC.getDisplayName()) && StringUtils.isEmpty(parameters.getDatasource())) {
connection.setDatasourceName(parameters.getDbName());
}
if ("".equals(connection.getLabel())) {
//$NON-NLS-1$
connection.setLabel(parameters.getDatasource());
}
String driverClassByDbType = null;
if (parameters.getDriverClass() != null) {
driverClassByDbType = parameters.getDriverClass();
} else {
driverClassByDbType = extractMeta.getDriverClassByDbType(dbType);
}
String driverJar = parameters.getDriverJar();
connection.setDriverClass(driverClassByDbType);
connection.setDriverJarPath(driverJar);
String databaseType = connection.getDatabaseType();
if (driverClassByDbType != null && !"".equals(driverClassByDbType) && EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(parameters.getDbType())) {
if (driverClassByDbType.startsWith("\"") && driverClassByDbType.endsWith("\"")) {
driverClassByDbType = TalendTextUtils.removeQuotes(driverClassByDbType);
}
String dbTypeByClassName = "";
if (driverJar != null && !"".equals(driverJar)) {
dbTypeByClassName = extractMeta.getDbTypeByClassNameAndDriverJar(driverClassByDbType, driverJar);
} else {
dbTypeByClassName = extractMeta.getDbTypeByClassName(driverClassByDbType);
}
if (dbTypeByClassName != null) {
databaseType = dbTypeByClassName;
}
}
final String product = EDatabaseTypeName.getTypeFromDisplayName(databaseType).getProduct();
;
connection.setProductId(product);
if (MetadataTalendType.getDefaultDbmsFromProduct(product) != null) {
final String mapping = MetadataTalendType.getDefaultDbmsFromProduct(product).getId();
connection.setDbmsId(mapping);
}
if (!isSchemaInValid && isNeedSchema) {
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\'", "");
//$NON-NLS-1$ //$NON-NLS-2$
schema = schema.replaceAll("\"", "");
connection.setUiSchema(schema);
}
connection.setServerName(parameters.getHost());
connection.setAdditionalParams(parameters.getJdbcProperties());
connection.setURL(parameters.getCombineURL());
connection.setDBRootPath(parameters.getDirectory());
connection.setDbVersionString(parameters.getDbVersion());
// Added by Marvin Wang to add other parameters.
Map<String, String> params = parameters.getParameters();
if (params != null && params.size() > 0) {
Set<Entry<String, String>> collection = params.entrySet();
for (Entry<String, String> para : collection) {
connection.getParameters().put(para.getKey(), para.getValue());
}
}
return connection;
}
use of java.util.Map.Entry in project tdi-studio-se by Talend.
the class JobletContainerFigure method removeFromParentMRFigure.
private void removeFromParentMRFigure() {
if (this.parentMRFigure == null) {
return;
}
Iterator<Entry<String, SimpleHtmlFigure>> ite = mrFigures.entrySet().iterator();
while (ite.hasNext()) {
Entry<String, SimpleHtmlFigure> entry = ite.next();
// String key = entry.getKey();
SimpleHtmlFigure value = entry.getValue();
if (this.parentMRFigure.getChildren().contains(value)) {
this.parentMRFigure.remove(value);
}
}
}
use of java.util.Map.Entry in project tdi-studio-se by Talend.
the class JobletContainerFigure method initializejobletContainer.
public void initializejobletContainer(Rectangle rectangle) {
Point location = this.getLocation();
if (location.equals(lastLocation) && !jobletContainer.getNode().isMapReduceStart() && mrFigures.isEmpty()) {
// avoid to calculate locations for nothing
return;
}
lastLocation = location;
collapseFigure.setCollapsed(jobletContainer.isCollapsed());
collapseFigure.setVisible(this.jobletContainer.getNode().isJoblet());
//$NON-NLS-1$ //$NON-NLS-2$
titleFigure.setText("<b> " + title + "</b>");
Dimension preferedSize = titleFigure.getPreferredSize();
preferedSize = preferedSize.getExpanded(0, 3);
collapseFigure.setLocation(new Point(location.x, location.y));
collapseFigure.setSize(preferedSize.height, preferedSize.height);
titleFigure.setSize(preferedSize.width, preferedSize.height - 2);
titleFigure.setLocation(new Point((rectangle.width - preferedSize.width) / 2 + location.x, location.y));
titleFigure.setVisible(showTitle);
outlineFigure.setLocation(new Point(location.x, location.y));
outlineFigure.setVisible(showTitle);
outlineFigure.setForegroundColor(ColorUtils.getCacheColor(new RGB(220, 120, 120)));
outlineFigure.setSize(rectangle.width, preferedSize.height);
refreshMRFigures();
Iterator<Entry<String, SimpleHtmlFigure>> ite = mrFigures.entrySet().iterator();
int i = 0;
while (ite.hasNext()) {
Entry<String, SimpleHtmlFigure> entry = ite.next();
String key = entry.getKey();
SimpleHtmlFigure value = entry.getValue();
int progressHeight = value.getBounds().height + 3;
Integer count = this.jobletContainer.getNode().getMrJobInGroupCount();
i = Integer.parseInt(key.substring(key.indexOf("_") + 1));
int mry = progressHeight * i;
int proWidth = value.getBounds().width;
int jcWidth = this.jobletContainer.getJobletContainerRectangle().width;
if (isSubjobDisplay) {
if (!this.jobletContainer.isMRGroupContainesReduce()) {
if (key.startsWith(KEY_MAP)) {
if (jcWidth > proWidth + 12) {
value.setLocation(new Point(location.x + jcWidth / 2 - proWidth / 2 - 6, location.y + rectangle.height - count * progressHeight + mry));
} else if (jcWidth > proWidth) {
value.setLocation(new Point(location.x + jcWidth / 2 - proWidth / 2, location.y + rectangle.height - count * progressHeight + mry));
} else {
value.setLocation(new Point(location.x, location.y + rectangle.height - count * progressHeight + mry));
}
}
} else {
if (jcWidth / 2 >= 120) {
if (key.startsWith(KEY_MAP)) {
value.setLocation(new Point(location.x + jcWidth / 2 - 120, location.y + rectangle.height - count * progressHeight + mry));
}
if (key.startsWith(KEY_REDUCE)) {
value.setLocation(new Point(location.x + jcWidth / 2, location.y + rectangle.height - count * progressHeight + mry));
}
} else if (jcWidth / 2 > proWidth) {
if (key.startsWith(KEY_MAP)) {
value.setLocation(new Point(location.x + jcWidth / 2 - proWidth, location.y + rectangle.height - count * progressHeight + mry));
}
if (key.startsWith(KEY_REDUCE)) {
value.setLocation(new Point(location.x + jcWidth / 2, location.y + rectangle.height - count * progressHeight + mry));
}
} else {
if (key.startsWith(KEY_MAP)) {
value.setLocation(new Point(location.x, location.y + rectangle.height - count * progressHeight + mry));
}
if (key.startsWith(KEY_REDUCE)) {
value.setLocation(new Point(location.x + 110, location.y + rectangle.height - count * progressHeight + mry));
}
}
}
}
}
rectFig.setLocation(new Point(location.x, /* preferedSize.height + */
location.y));
rectFig.setSize(new Dimension(rectangle.width, rectangle.height));
if (this.jobletContainer.getNode().isJoblet()) {
if (new JobletUtil().isRed(this.jobletContainer)) {
if (isSubjobDisplay) {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(red));
} else {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(white));
}
outlineFigure.setBackgroundColor(ColorUtils.getCacheColor(red));
} else {
if (isSubjobDisplay) {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(green));
} else {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(white));
}
outlineFigure.setBackgroundColor(ColorUtils.getCacheColor(green));
}
} else {
if (isSubjobDisplay) {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(mrGroupColor));
} else {
rectFig.setBackgroundColor(ColorUtils.getCacheColor(white));
}
outlineFigure.setBackgroundColor(ColorUtils.getCacheColor(mrGroupColor));
// progressFigure.setBackgroundColor(new Color(Display.getDefault(), red));
if (!this.jobletContainer.getNode().isMapReduceStart()) {
rectFig.setVisible(false);
outlineFigure.setVisible(false);
}
}
if (isSubjobDisplay) {
if (this.jobletContainer.getNode().isMapReduce()) {
rectFig.setForegroundColor(ColorUtils.getCacheColor(new RGB(121, 157, 175)));
} else {
rectFig.setForegroundColor(ColorUtils.getCacheColor(new RGB(220, 120, 120)));
}
} else {
rectFig.setForegroundColor(ColorUtils.getCacheColor(white));
}
markFigure.setSize(errorMarkImage.getImageData().width, errorMarkImage.getImageData().height);
}
Aggregations