use of org.apache.commons.math3.util.Pair in project DataX by alibaba.
the class OtsWriterSlaveProxy method write.
public void write(RecordReceiver recordReceiver, TaskPluginCollector collector) throws Exception {
LOG.info("Writer slave started.");
WriterConfig writerConfig = new WriterConfig();
writerConfig.setConcurrency(conf.getConcurrencyWrite());
writerConfig.setMaxBatchRowsCount(conf.getBatchWriteCount());
writerConfig.setMaxBatchSize(conf.getRestrictConf().getRequestTotalSizeLimition());
writerConfig.setBufferSize(conf.getBufferSize());
writerConfig.setMaxAttrColumnSize(conf.getRestrictConf().getAttributeColumnSize());
writerConfig.setMaxColumnsCount(conf.getRestrictConf().getMaxColumnsCount());
writerConfig.setMaxPKColumnSize(conf.getRestrictConf().getPrimaryKeyColumnSize());
otsWriter = new DefaultOTSWriter(otsAsync, conf.getTableName(), writerConfig, new WriterCallback(collector), Executors.newFixedThreadPool(3));
int expectColumnCount = conf.getPrimaryKeyColumn().size() + conf.getAttributeColumn().size();
Record record;
while ((record = recordReceiver.getFromReader()) != null) {
LOG.debug("Record Raw: {}", record.toString());
int columnCount = record.getColumnNumber();
if (columnCount != expectColumnCount) {
// 如果Column的个数和预期的个数不一致时,认为是系统故障或者用户配置Column错误,异常退出
throw new IllegalArgumentException(String.format(OTSErrorMessage.RECORD_AND_COLUMN_SIZE_ERROR, columnCount, expectColumnCount));
}
// 类型转换
try {
RowPrimaryKey primaryKey = Common.getPKFromRecord(conf.getPrimaryKeyColumn(), record);
List<Pair<String, ColumnValue>> attributes = Common.getAttrFromRecord(conf.getPrimaryKeyColumn().size(), conf.getAttributeColumn(), record);
RowChange rowChange = Common.columnValuesToRowChange(conf.getTableName(), conf.getOperation(), primaryKey, attributes);
WithRecord withRecord = (WithRecord) rowChange;
withRecord.setRecord(record);
otsWriter.addRowChange(rowChange);
} catch (IllegalArgumentException e) {
LOG.warn("Found dirty data.", e);
collector.collectDirtyRecord(record, e.getMessage());
} catch (ClientException e) {
LOG.warn("Found dirty data.", e);
collector.collectDirtyRecord(record, e.getMessage());
}
}
otsWriter.close();
LOG.info("Writer slave finished.");
}
use of org.apache.commons.math3.util.Pair in project DataX by alibaba.
the class Common method getAttrFromRecord.
public static List<Pair<String, ColumnValue>> getAttrFromRecord(int pkCount, List<OTSAttrColumn> attrColumns, Record r) {
List<Pair<String, ColumnValue>> attr = new ArrayList<Pair<String, ColumnValue>>(r.getColumnNumber());
for (int i = 0; i < attrColumns.size(); i++) {
Column col = r.getColumn(i + pkCount);
OTSAttrColumn expect = attrColumns.get(i);
if (col.getRawData() == null) {
attr.add(new Pair<String, ColumnValue>(expect.getName(), null));
continue;
}
ColumnValue cv = ColumnConversion.columnToColumnValue(col, expect);
attr.add(new Pair<String, ColumnValue>(expect.getName(), cv));
}
return attr;
}
use of org.apache.commons.math3.util.Pair in project android by owncloud.
the class FileDataStorageManager method getAvailableOfflineFilesFromEveryAccount.
/**
* Get a collection with all the files set by the user as available offline, from all the accounts
* in the device.
*
* This is the only method working with a NULL account in {@link #mAccount}. Not something to do often.
*
* @return List with all the files set by the user as available offline.
*/
public List<Pair<OCFile, String>> getAvailableOfflineFilesFromEveryAccount() {
List<Pair<OCFile, String>> result = new ArrayList<>();
Cursor cursorOnKeptInSync = null;
try {
// query for any favorite file in any OC account
cursorOnKeptInSync = getContentResolver().query(ProviderTableMeta.CONTENT_URI, null, ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ?", new String[] { String.valueOf(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE.getValue()) }, // do NOT get also AVAILABLE_OFFLINE_PARENT: only those SET BY THE USER (files or folders)
null);
if (cursorOnKeptInSync != null && cursorOnKeptInSync.moveToFirst()) {
OCFile file;
String accountName;
do {
file = createFileInstance(cursorOnKeptInSync);
accountName = cursorOnKeptInSync.getString(cursorOnKeptInSync.getColumnIndex(ProviderTableMeta.FILE_ACCOUNT_OWNER));
result.add(new Pair<>(file, accountName));
} while (cursorOnKeptInSync.moveToNext());
}
} catch (Exception e) {
Log_OC.e(TAG, "Exception retrieving all the available offline files", e);
} finally {
if (cursorOnKeptInSync != null) {
cursorOnKeptInSync.close();
}
}
return result;
}
use of org.apache.commons.math3.util.Pair in project android by owncloud.
the class FileObserverService method startObservation.
/**
* Read from the local database the list of files that must to be kept
* synchronized and starts observers to monitor local changes on them.
*
* Updates the list of currently observed files if called multiple times.
*/
private void startObservation() {
Log_OC.d(TAG, "Loading all available offline files from database to start watching them");
FileDataStorageManager fds = new FileDataStorageManager(// this is dangerous - handle with care
null, getContentResolver());
List<Pair<OCFile, String>> availableOfflineFiles = fds.getAvailableOfflineFilesFromEveryAccount();
OCFile file;
String accountName;
Account account;
for (Pair<OCFile, String> pair : availableOfflineFiles) {
file = pair.first;
accountName = pair.second;
account = new Account(accountName, MainApp.getAccountType());
if (!AccountUtils.exists(account, this)) {
continue;
}
addObservedFile(file, account);
}
// watch for instant uploads
updateInstantUploadsObservers();
// service does not stopSelf() ; that way it tries to be alive forever
}
use of org.apache.commons.math3.util.Pair in project GSYVideoPlayer by CarGuo.
the class JumpUtils method goToVideoPlayer.
/**
* 跳转到视频播放
*
* @param activity
* @param view
*/
public static void goToVideoPlayer(Activity activity, View view) {
Intent intent = new Intent(activity, PlayActivity.class);
intent.putExtra(PlayActivity.TRANSITION, true);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
Pair pair = new Pair<>(view, PlayActivity.IMG_TRANSITION);
ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pair);
ActivityCompat.startActivity(activity, intent, activityOptions.toBundle());
} else {
activity.startActivity(intent);
activity.overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
}
}
Aggregations