List of usage examples for java.util ArrayList clear
public void clear()
From source file:com.android.exchange.EasAccountService.java
private void runPingLoop() throws IOException, StaleFolderListException, IllegalHeartbeatException, CommandStatusException { int pingHeartbeat = mPingHeartbeat; userLog("runPingLoop"); // Do push for all sync services here long endTime = System.currentTimeMillis() + (30 * DateUtils.MINUTE_IN_MILLIS); HashMap<String, Integer> pingErrorMap = new HashMap<String, Integer>(); ArrayList<String> readyMailboxes = new ArrayList<String>(); ArrayList<String> notReadyMailboxes = new ArrayList<String>(); int pingWaitCount = 0; long inboxId = -1; android.accounts.Account amAccount = new android.accounts.Account(mAccount.mEmailAddress, Eas.EXCHANGE_ACCOUNT_MANAGER_TYPE); while ((System.currentTimeMillis() < endTime) && !isStopped()) { // Count of pushable mailboxes int pushCount = 0; // Count of mailboxes that can be pushed right now int canPushCount = 0; // Count of uninitialized boxes int uninitCount = 0; Serializer s = new Serializer(); Cursor c = mContentResolver.query(Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION, MailboxColumns.ACCOUNT_KEY + '=' + mAccount.mId + AND_FREQUENCY_PING_PUSH_AND_NOT_ACCOUNT_MAILBOX, null, null);//from ww w. ja v a2s .c om if (c == null) throw new ProviderUnavailableException(); notReadyMailboxes.clear(); readyMailboxes.clear(); // Look for an inbox, and remember its id if (inboxId == -1) { inboxId = Mailbox.findMailboxOfType(mContext, mAccount.mId, Mailbox.TYPE_INBOX); } try { // Loop through our pushed boxes seeing what is available to push while (c.moveToNext()) { pushCount++; // Two requirements for push: // 1) ExchangeService tells us the mailbox is syncable (not running/not stopped) // 2) The syncKey isn't "0" (i.e. it's synced at least once) long mailboxId = c.getLong(Mailbox.CONTENT_ID_COLUMN); String mailboxName = c.getString(Mailbox.CONTENT_DISPLAY_NAME_COLUMN); // See what type of box we've got and get authority int mailboxType = c.getInt(Mailbox.CONTENT_TYPE_COLUMN); String authority = EmailContent.AUTHORITY; switch (mailboxType) { case Mailbox.TYPE_CALENDAR: authority = CalendarContract.AUTHORITY; break; case Mailbox.TYPE_CONTACTS: authority = ContactsContract.AUTHORITY; break; } // See whether we can ping for this mailbox int pingStatus; if (!ContentResolver.getSyncAutomatically(amAccount, authority)) { pingStatus = ExchangeService.PING_STATUS_DISABLED; } else { pingStatus = ExchangeService.pingStatus(mailboxId); } if (pingStatus == ExchangeService.PING_STATUS_OK) { String syncKey = c.getString(Mailbox.CONTENT_SYNC_KEY_COLUMN); if ((syncKey == null) || syncKey.equals("0")) { // We can't push until the initial sync is done pushCount--; uninitCount++; continue; } if (canPushCount++ == 0) { // Initialize the Ping command s.start(Tags.PING_PING) .data(Tags.PING_HEARTBEAT_INTERVAL, Integer.toString(pingHeartbeat)) .start(Tags.PING_FOLDERS); } String folderClass = getTargetCollectionClassFromCursor(c); s.start(Tags.PING_FOLDER).data(Tags.PING_ID, c.getString(Mailbox.CONTENT_SERVER_ID_COLUMN)) .data(Tags.PING_CLASS, folderClass).end(); readyMailboxes.add(mailboxName); } else if ((pingStatus == ExchangeService.PING_STATUS_RUNNING) || (pingStatus == ExchangeService.PING_STATUS_WAITING)) { notReadyMailboxes.add(mailboxName); } else if (pingStatus == ExchangeService.PING_STATUS_UNABLE) { pushCount--; userLog(mailboxName, " in error state; ignore"); continue; } else if (pingStatus == ExchangeService.PING_STATUS_DISABLED) { pushCount--; userLog(mailboxName, " disabled by user; ignore"); continue; } } } finally { c.close(); } if (Eas.USER_LOG) { if (!notReadyMailboxes.isEmpty()) { userLog("Ping not ready for: " + notReadyMailboxes); } if (!readyMailboxes.isEmpty()) { userLog("Ping ready for: " + readyMailboxes); } } // If we've waited 10 seconds or more, just ping with whatever boxes are ready // But use a shorter than normal heartbeat boolean forcePing = !notReadyMailboxes.isEmpty() && (pingWaitCount > 5); if ((canPushCount > 0) && ((canPushCount == pushCount) || forcePing)) { // If all pingable boxes are ready for push, send Ping to the server s.end().end().done(); pingWaitCount = 0; mPostAborted = false; mPostReset = false; // If we've been stopped, this is a good time to return if (isStopped()) return; long pingTime = SystemClock.elapsedRealtime(); try { // Send the ping, wrapped by appropriate timeout/alarm if (forcePing) { userLog("Forcing ping after waiting for all boxes to be ready"); } EasResponse resp = sendPing(s.toByteArray(), forcePing ? mPingForceHeartbeat : pingHeartbeat); try { int code = resp.getStatus(); userLog("Ping response: ", code); // If we're not allowed to sync (e.g. roaming policy), terminate gracefully // now; otherwise we might start a sync based on the response if (!ExchangeService.canAutoSync(mAccount)) { stop(); } // Return immediately if we've been asked to stop during the ping if (isStopped()) { userLog("Stopping pingLoop"); return; } if (code == HttpStatus.SC_OK) { if (!resp.isEmpty()) { InputStream is = resp.getInputStream(); int pingResult = parsePingResult(is, mContentResolver, pingErrorMap); // If our ping completed (status = 1), and wasn't forced and we're // not at the maximum, try increasing timeout by two minutes if (pingResult == PROTOCOL_PING_STATUS_COMPLETED && !forcePing) { if (pingHeartbeat > mPingHighWaterMark) { mPingHighWaterMark = pingHeartbeat; userLog("Setting high water mark at: ", mPingHighWaterMark); } if ((pingHeartbeat < mPingMaxHeartbeat) && !mPingHeartbeatDropped) { pingHeartbeat += PING_HEARTBEAT_INCREMENT; if (pingHeartbeat > mPingMaxHeartbeat) { pingHeartbeat = mPingMaxHeartbeat; } userLog("Increase ping heartbeat to ", pingHeartbeat, "s"); } } else if (pingResult == PROTOCOL_PING_STATUS_BAD_PARAMETERS || pingResult == PROTOCOL_PING_STATUS_RETRY) { // These errors appear to be server-related (I've seen a bad // parameters result with known good parameters...) userLog("Server error during Ping: " + pingResult); // Act as if we have an IOException (backoff, etc.) throw new IOException(); } // Make sure to clear out any pending sync errors ExchangeService.removeFromSyncErrorMap(mMailboxId); } else { userLog("Ping returned empty result; throwing IOException"); // Act as if we have an IOException (backoff, etc.) throw new IOException(); } } else if (resp.isAuthError()) { mExitStatus = EasSyncService.EXIT_LOGIN_FAILURE; userLog("Authorization error during Ping: ", code); throw new IOException(); } } finally { resp.close(); } } catch (IOException e) { String message = e.getMessage(); // If we get the exception that is indicative of a NAT timeout and if we // haven't yet "fixed" the timeout, back off by two minutes and "fix" it boolean hasMessage = message != null; userLog("IOException runPingLoop: " + (hasMessage ? message : "[no message]")); if (mPostReset) { // Nothing to do in this case; this is ExchangeService telling us to try // another ping. } else if (mPostAborted || isLikelyNatFailure(message)) { long pingLength = SystemClock.elapsedRealtime() - pingTime; if ((pingHeartbeat > mPingMinHeartbeat) && (pingHeartbeat > mPingHighWaterMark)) { pingHeartbeat -= PING_HEARTBEAT_INCREMENT; mPingHeartbeatDropped = true; if (pingHeartbeat < mPingMinHeartbeat) { pingHeartbeat = mPingMinHeartbeat; } userLog("Decreased ping heartbeat to ", pingHeartbeat, "s"); } else if (mPostAborted) { // There's no point in throwing here; this can happen in two cases // 1) An alarm, which indicates minutes without activity; no sense // backing off // 2) ExchangeService abort, due to sync of mailbox. Again, we want to // keep on trying to ping userLog("Ping aborted; retry"); } else if (pingLength < 2000) { userLog("Abort or NAT type return < 2 seconds; throwing IOException"); throw e; } else { userLog("NAT type IOException"); } } else if (hasMessage && message.contains("roken pipe")) { // The "broken pipe" error (uppercase or lowercase "b") seems to be an // internal error, so let's not throw an exception (which leads to delays) // but rather simply run through the loop again } else { throw e; } } } else if (forcePing) { // In this case, there aren't any boxes that are pingable, but there are boxes // waiting (for IOExceptions) userLog("pingLoop waiting 60s for any pingable boxes"); sleep(60 * DateUtils.SECOND_IN_MILLIS, true); } else if (pushCount > 0) { // If we want to Ping, but can't just yet, wait a little bit // TODO Change sleep to wait and use notify from ExchangeService when a sync ends sleep(2 * DateUtils.SECOND_IN_MILLIS, false); pingWaitCount++; //userLog("pingLoop waited 2s for: ", (pushCount - canPushCount), " box(es)"); } else if (uninitCount > 0) { // In this case, we're doing an initial sync of at least one mailbox. Since this // is typically a one-time case, I'm ok with trying again every 10 seconds until // we're in one of the other possible states. userLog("pingLoop waiting for initial sync of ", uninitCount, " box(es)"); sleep(10 * DateUtils.SECOND_IN_MILLIS, true); } else if (inboxId == -1) { // In this case, we're still syncing mailboxes, so sleep for only a short time sleep(45 * DateUtils.SECOND_IN_MILLIS, true); } else { // We've got nothing to do, so we'll check again in 20 minutes at which time // we'll update the folder list, check for policy changes and/or remote wipe, etc. // Let the device sleep in the meantime... userLog(ACCOUNT_MAILBOX_SLEEP_TEXT); sleep(ACCOUNT_MAILBOX_SLEEP_TIME, true); } } // Save away the current heartbeat mPingHeartbeat = pingHeartbeat; }
From source file:com.tulskiy.musique.library.Library.java
public void rescan(Map<String, Object> progress) { List<String> folders = LibraryConfiguration.getFolders(); if (CollectionUtils.isEmpty(folders)) { return;/*from w ww .ja v a 2 s . c o m*/ } progress.put("processing.file", ""); data.removeDeadItems(); HashMap<TrackData, Track> trackDatas = new HashMap<TrackData, Track>(); for (Track track : data) { trackDatas.put(track.getTrackData(), track); } LinkedList<File> queue = new LinkedList<File>(); for (String path : folders) { File f = new File(path); if (f.exists()) queue.add(f); } HashSet<Track> processed = new HashSet<Track>(); final Set<String> formats = Codecs.getFormats(); ArrayList<Track> temp = new ArrayList<Track>(); while (!queue.isEmpty()) { try { File file = queue.pop(); if (progress != null) { if (progress.get("processing.stop") != null) { break; } progress.put("processing.file", file.getAbsolutePath()); } if (file.isDirectory()) { queue.addAll(0, Arrays.asList(file.listFiles(new FileFilter() { @Override public boolean accept(File file) { if (file.isHidden() || !file.canRead()) { return false; } if (file.isDirectory()) return true; String ext = Util.getFileExt(file).toLowerCase(); if (formats.contains(ext)) { String name = Util.removeExt(file.getAbsolutePath()) + ".cue"; return !new File(name).exists(); } return ext.equals("cue"); } }))); } else { TrackData trackData = new TrackData(file.toURI(), 0); Track track = trackDatas.get(trackData); if (track != null) { if (track.getTrackData().getLastModified() != file.lastModified()) { track.getTrackData().clearTags(); TrackIO.getAudioFileReader(file.getName()).reload(track); } processed.add(track); } else { temp.clear(); TrackIO.getAudioFileReader(file.getName()).read(file, temp); for (Track newTrack : temp) { trackData = newTrack.getTrackData(); if (trackDatas.containsKey(trackData)) { // it must be the cue file, so merge the track data trackData.merge(newTrack.getTrackData()); } processed.add(newTrack); } } } } catch (Exception e) { e.printStackTrace(); } } data.clear(); data.addAll(processed); processed.clear(); trackDatas.clear(); rebuildTree(); }
From source file:org.apache.accumulo.storagehandler.CustomIndexPredicateAnalyzer.java
/** * Analyzes a predicate.//w w w .j av a 2 s .c o m * * @param predicate predicate to be analyzed * * @param searchConditions receives conditions produced by analysis * * @return residual predicate which could not be translated to * searchConditions */ public ExprNodeDesc analyzePredicate(ExprNodeDesc predicate, final List<IndexSearchCondition> searchConditions) { //pre-process the graph to determine if there are any OR statements and what level of nesting they are at orFirstLevel = false; orOtherLevel = false; NodeProcessor upFrontNodeProcessor = new NodeProcessor() { @Override public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, Object... nodeOutputs) throws SemanticException { int position = 0; for (Node ancestor : stack) { if (nd == ancestor) { break; } if (!FunctionRegistry.isOpOr((ExprNodeDesc) ancestor)) { if (position == 0) { orFirstLevel = true; } else { orOtherLevel = true; } return nd; } position++; } return analyzeExpr((ExprNodeDesc) nd, searchConditions, nodeOutputs); } }; Dispatcher upFrontDisp = new DefaultRuleDispatcher(upFrontNodeProcessor, new LinkedHashMap<Rule, NodeProcessor>(), null); GraphWalker upFrontOgw = new DefaultGraphWalker(upFrontDisp); ArrayList<Node> topNodes = new ArrayList<Node>(); topNodes.add(predicate); HashMap<Node, Object> nodeOutput = new HashMap<Node, Object>(); try { upFrontOgw.startWalking(topNodes, nodeOutput); } catch (SemanticException ex) { throw new RuntimeException(ex); } //if there are no OR statements or any OR statements are the first level then we can just treat this normally //if there are OR statements but they are only at nesting levels then we need to look for any rowid checks at the first level and process them Map<Rule, NodeProcessor> opRules = new LinkedHashMap<Rule, NodeProcessor>(); NodeProcessor nodeProcessor = new NodeProcessor() { @Override public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx procCtx, Object... nodeOutputs) throws SemanticException { // We can only push down stuff which appears as part of // a pure conjunction: reject OR, CASE, etc. for (Node ancestor : stack) { if (nd == ancestor) { break; } if ((!FunctionRegistry.isOpAnd((ExprNodeDesc) ancestor)) && (!FunctionRegistry.isOpOr((ExprNodeDesc) ancestor))) { return nd; } } return analyzeExpr((ExprNodeDesc) nd, searchConditions, nodeOutputs); } }; Dispatcher disp = new DefaultRuleDispatcher(nodeProcessor, opRules, null); GraphWalker ogw = new DefaultGraphWalker(disp); topNodes.clear(); topNodes.add(predicate); nodeOutput.clear(); try { ogw.startWalking(topNodes, nodeOutput); } catch (SemanticException ex) { throw new RuntimeException(ex); } ExprNodeDesc residualPredicate = (ExprNodeDesc) nodeOutput.get(predicate); return residualPredicate; }
From source file:com.allwinner.theatreplayer.launcher.activity.LaunchActivity.java
@SuppressWarnings("unchecked") private void setCellDate() { if (mCellInfoList == null || mCellViews == null) { return;//from w w w .ja v a2s . c o m } int listCount = mCellInfoList.size(); if (Constants.CELL_COUNT >= listCount) { CellInfo cellInfo = null; CellViews cellViews = null; ArrayList<CellInfo> cloneList = (ArrayList<CellInfo>) mCellInfoList.clone(); // Log.i("jim", "cloneList.size() = "+cloneList.size()); for (int i = 0; i < listCount; i++) { cellInfo = cloneList.get(i); cellViews = mCellViews.get(i); if (cellInfo != null) { if (cellViews != null && cellViews.iLayout != null) { if (cellInfo.type == 4) { cellViews.iLayout.setVisibility(View.INVISIBLE); } else if (cellInfo.type == 3) { cellViews.iLayout.setVisibility(View.GONE); } } if (cellInfo.type == 4 && !LoadApplicationInfo.isInstalled(this, cellInfo.packageName)) { mCellInfoList.remove(cellInfo); } } } cloneList.clear(); cloneList = null; listCount = mCellInfoList.size(); } for (int i = 0; i < listCount; i++) { CellInfo cellInfo = mCellInfoList.get(i); CellViews cellViews = mCellViews.get(i); if (cellViews != null && cellViews.iLayout != null) { cellViews.iLayout.setTag(cellInfo); cellViews.iLayout.setVisibility(View.VISIBLE); if (!mIsFiveLayout && cellInfo.type == 3 && !LoadApplicationInfo.isInstalled(this, cellInfo.packageName)) { cellViews.iLayout.setVisibility(View.GONE); } if (cellInfo.backgroundPic != null && !cellInfo.backgroundPic.equals("")) { BitmapDrawable bitmapDrawable = (BitmapDrawable) ImageUtils.getShortcutIconFromSys(this, cellInfo.backgroundPic); if (bitmapDrawable != null) { Bitmap bitmap = bitmapDrawable.getBitmap(); cellViews.iLayout.setImageBitmap(bitmap); } } else if (cellInfo.backgroundColour != null && !cellInfo.backgroundColour.equals("")) { cellViews.iLayout.setBackgroundColor(Color.parseColor(cellInfo.backgroundColour)); } // if (i != 0) { // if(cellInfo.packageName.equals("com.vst.live.allwinner")){ // Log.i("jim", "55555555555======"+cellInfo.packageName); // // } Drawable iconDrawable = null; if (cellInfo.icon != null && !cellInfo.icon.equals("")) { iconDrawable = ImageUtils.getShortcutIconFromSys(this, cellInfo.icon); } if (iconDrawable == null && cellInfo.type == 4) { iconDrawable = ImageUtils.getAppIcon(cellInfo.packageName, this); } if (iconDrawable != null && cellViews.iconView != null) { cellViews.iconView.setImageDrawable(iconDrawable); } if (cellViews.textView != null) { cellViews.textView.setText(cellInfo.title); } // } if (cellViews.imgView != null) { Bitmap bitmap = ImageUtils.loadImageFromLocat(this, cellInfo.className); if (bitmap == null) { bitmap = ImageUtils.getBitmapByPicName(this, "img_" + cellInfo.className); } if (bitmap != null) { cellViews.imgView.setImageBitmap(bitmap); } } } } }
From source file:logdruid.util.DataMiner.java
public static Map<String, ArrayList<FileRecord>> getSourceFileGroup(Map<Integer, FileRecord> sourceFiles, Source src, Repository repo) { PatternCache patternCache = new PatternCache(); String patternString = ""; Map<String, ArrayList<FileRecord>> sourceFileGroup = new HashMap<String, ArrayList<FileRecord>>(); ArrayList<FileRecord> groupedFiles = new ArrayList<FileRecord>(); // ArrayList<SourceItem> sourceItemArrayList = src.getSourceItem(); ArrayList<Recording> recordings = (ArrayList<Recording>) repo.getRecordings(MetadataRecording.class); Matcher matcher = null;/*from w w w . j a v a2s . co m*/ if (recordings != null) { Iterator<Recording> it = recordings.iterator(); // logger.info("recordings not null "); while (it.hasNext()) { Recording rec = it.next(); if (src.isActiveRecordingOnSource(rec)) { ArrayList<RecordingItem> rIV = ((MetadataRecording) rec).getRecordingItem(); Iterator<RecordingItem> itV = rIV.iterator(); int nbRec = 0; while (itV.hasNext()) { RecordingItem rI = itV.next(); String type = rI.getType(); if (type == "date") { patternString += rI.getBefore() + "(" + repo.getDateFormat(rec.getDateFormatID()) + ")" + rI.getAfter(); } else { patternString += rI.getBefore() + "(" + DataMiner.getTypeString(type) + ")" + rI.getAfter(); } // logger.info("patternString: " + patternString // + " getType: " + // DataMiner.getTypeString(rI.getType())); nbRec++; } Iterator<FileRecord> sourceFileIterator = sourceFiles.values().iterator(); String key = ""; // tempV = new ArrayList<String>(); while (sourceFileIterator.hasNext()) { groupedFiles.clear(); FileRecord fileName = sourceFileIterator.next(); // logger.info("file: "+fileName); try { if (logger.isDebugEnabled()) logger.debug("patternString: " + patternString); if (logger.isDebugEnabled()) logger.debug("filename: " + fileName); // Pattern pattern = Pattern.compile(patternString + // ".*"); // Matcher matcher = pattern.matcher(fileName); matcher = patternCache.getPattern(patternString + ".*") .matcher(new File(repo.getBaseSourcePath()).toURI() .relativize(new File(fileName.getFile().getCanonicalPath()).toURI()) .getPath()); //*** if (matcher.find()) { if (logger.isDebugEnabled()) logger.debug("found filename " + fileName + " with group"); key = ""; int i = 1; for (i = 1; i <= matcher.groupCount(); i++) { if (recordings.get(i).getIsActive()) { if (logger.isDebugEnabled()) logger.debug("one : " + matcher.group(i)); key += matcher.group(i) + " "; } } if (logger.isDebugEnabled()) logger.debug("i : " + i + " nbRec: " + nbRec); if (i - 1 == nbRec) { if (logger.isDebugEnabled()) logger.debug(" passed!"); if (!sourceFileGroup.containsKey(key)) { ArrayList<FileRecord> v = new ArrayList<FileRecord>(); v.add(fileName); sourceFileGroup.put(key, v); if (logger.isDebugEnabled()) logger.debug(" to key: " + key + " added : " + fileName); } else { sourceFileGroup.get(key).add(fileName); if (logger.isDebugEnabled()) logger.debug(" to key: " + key + " added : " + fileName); } } /* * if (tempV != null) { sourceFileGroup.put(key, * tempV); logger.info("Added file " + fileName * + " to group " + key.toString()); * logger.info("files " + tempV); * * } */ } } catch (Exception e1) { e1.printStackTrace(); // System.exit(1); } // logger.info("found group " + key + "with " + // groupedFiles.size() + " files in source " + // src.getSourceName()); } } } } // TODO Auto-generated method stub return sourceFileGroup; }
From source file:org.alfresco.solr.tracker.MetadataTracker.java
protected void trackTransactions() throws AuthenticationException, IOException, JSONException, EncoderException { long startElapsed = System.nanoTime(); boolean indexed = false; boolean upToDate = false; Transactions transactions;/*from www . j a va 2 s .c o m*/ BoundedDeque<Transaction> txnsFound = new BoundedDeque<Transaction>(100); HashSet<Transaction> txsIndexed = new LinkedHashSet<>(); TrackerState state = this.getTrackerState(); long totalUpdatedDocs = 0; int docCount = 0; do { Long fromCommitTime = getTxFromCommitTime(txnsFound, state.getLastGoodTxCommitTimeInIndex()); transactions = getSomeTransactions(txnsFound, fromCommitTime, TIME_STEP_1_HR_IN_MS, 2000, state.getTimeToStopIndexing()); setLastTxCommitTimeAndTxIdInTrackerState(transactions, state); log.info("Scanning transactions ..."); if (transactions.getTransactions().size() > 0) { log.info(".... from " + transactions.getTransactions().get(0)); log.info( ".... to " + transactions.getTransactions().get(transactions.getTransactions().size() - 1)); } else { log.info(".... none found after lastTxCommitTime " + ((txnsFound.size() > 0) ? txnsFound.getLast().getCommitTimeMs() : state.getLastIndexedTxCommitTime())); } ArrayList<Transaction> txBatch = new ArrayList<>(); for (Transaction info : transactions.getTransactions()) { boolean isInIndex = (info.getCommitTimeMs() <= state.getLastIndexedTxCommitTime()) && this.infoSrv.isInIndex(AlfrescoSolrDataModel.getTransactionDocumentId(info.getId())); if (isInIndex) { txnsFound.add(info); } else { // Make sure we do not go ahead of where we started - we will check the holes here // correctly next time if (info.getCommitTimeMs() > state.getTimeToStopIndexing()) { upToDate = true; break; } txBatch.add(info); if (getUpdateAndDeleteCount(txBatch) > this.transactionDocsBatchSize) { indexed = true; docCount += indexBatchOfTransactions(txBatch); for (Transaction scheduledTx : txBatch) { txnsFound.add(scheduledTx); txsIndexed.add(scheduledTx); } txBatch.clear(); } } if (docCount > batchCount) { if (super.infoSrv.getRegisteredSearcherCount() < getMaxLiveSearchers()) { indexTransactionsAfterAsynchronous(txsIndexed, state); long endElapsed = System.nanoTime(); trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed); startElapsed = endElapsed; docCount = 0; } } checkShutdown(); } if (!txBatch.isEmpty()) { indexed = true; if (this.getUpdateAndDeleteCount(txBatch) > 0) { docCount += indexBatchOfTransactions(txBatch); } for (Transaction scheduledTx : txBatch) { txnsFound.add(scheduledTx); txsIndexed.add(scheduledTx); } txBatch.clear(); } totalUpdatedDocs += docCount; } while ((transactions.getTransactions().size() > 0) && (upToDate == false)); log.info("total number of docs with metadata updated: " + totalUpdatedDocs); if (indexed) { indexTransactionsAfterAsynchronous(txsIndexed, state); long endElapsed = System.nanoTime(); trackerStats.addElapsedNodeTime(docCount, endElapsed - startElapsed); } }
From source file:com.marklogic.contentpump.DelimitedTextInputFormat.java
public List<InputSplit> getSplits(JobContext job) throws IOException { boolean delimSplit = isSplitInput(job.getConfiguration()); //if delimSplit is true, size of each split is determined by //Math.max(minSize, Math.min(maxSize, blockSize)) in FileInputFormat List<InputSplit> splits = super.getSplits(job); if (!delimSplit) { return splits; }/*from www . j a v a2 s . c om*/ if (splits.size() >= SPLIT_COUNT_LIMIT) { //if #splits > 1 million, there is enough parallelism //therefore no point to split LOG.warn("Exceeding SPLIT_COUNT_LIMIT, input_split is off:" + SPLIT_COUNT_LIMIT); DefaultStringifier.store(job.getConfiguration(), false, ConfigConstants.CONF_SPLIT_INPUT); return splits; } // add header info into splits List<InputSplit> populatedSplits = new ArrayList<InputSplit>(); LOG.info(splits.size() + " DelimitedSplits generated"); Configuration conf = job.getConfiguration(); char delimiter = 0; ArrayList<Text> hlist = new ArrayList<Text>(); for (InputSplit file : splits) { FileSplit fsplit = ((FileSplit) file); Path path = fsplit.getPath(); FileSystem fs = path.getFileSystem(conf); if (fsplit.getStart() == 0) { // parse the inSplit, get the header FSDataInputStream fileIn = fs.open(path); String delimStr = conf.get(ConfigConstants.CONF_DELIMITER, ConfigConstants.DEFAULT_DELIMITER); if (delimStr.length() == 1) { delimiter = delimStr.charAt(0); } else { LOG.error("Incorrect delimitor: " + delimiter + ". Expects single character."); } String encoding = conf.get(MarkLogicConstants.OUTPUT_CONTENT_ENCODING, MarkLogicConstants.DEFAULT_OUTPUT_CONTENT_ENCODING); InputStreamReader instream = new InputStreamReader(fileIn, encoding); CSVParser parser = new CSVParser(instream, CSVParserFormatter.getFormat(delimiter, DelimitedTextReader.encapsulator, true, true)); Iterator<CSVRecord> it = parser.iterator(); String[] header = null; if (it.hasNext()) { CSVRecord record = (CSVRecord) it.next(); Iterator<String> recordIterator = record.iterator(); int recordSize = record.size(); header = new String[recordSize]; for (int i = 0; i < recordSize; i++) { if (recordIterator.hasNext()) { header[i] = (String) recordIterator.next(); } else { throw new IOException("Record size doesn't match the real size"); } } EncodingUtil.handleBOMUTF8(header, 0); hlist.clear(); for (String s : header) { hlist.add(new Text(s)); } } instream.close(); } DelimitedSplit ds = new DelimitedSplit(new TextArrayWritable(hlist.toArray(new Text[hlist.size()])), path, fsplit.getStart(), fsplit.getLength(), fsplit.getLocations()); populatedSplits.add(ds); } return populatedSplits; }
From source file:com.geotrackin.gpslogger.GpsMainActivity.java
private void ShowFileListDialog(final Intent settingsIntent, final IFileSender sender) { final File gpxFolder = new File(AppSettings.getGpsLoggerFolder()); if (gpxFolder != null && gpxFolder.exists()) { File[] enumeratedFiles = Utilities.GetFilesInFolder(gpxFolder, sender); //Order by last modified Arrays.sort(enumeratedFiles, new Comparator<File>() { public int compare(File f1, File f2) { if (f1 != null && f2 != null) { return -1 * Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); }/* ww w . j a v a 2 s . c o m*/ return -1; } }); List<String> fileList = new ArrayList<String>(enumeratedFiles.length); for (File f : enumeratedFiles) { fileList.add(f.getName()); } final String settingsText = getString(R.string.menu_settings); //Add 'settings' to top of list fileList.add(0, settingsText); final String[] files = fileList.toArray(new String[fileList.size()]); final ArrayList selectedItems = new ArrayList(); // Where we track the selected items AlertDialog.Builder builder = new AlertDialog.Builder(this); // Set the dialog title builder.setTitle(R.string.osm_pick_file) // Specify the list array, the items to be selected by default (null for none), // and the listener through which to receive callbacks when items are selected .setMultiChoiceItems(files, null, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { if (which == 0) { //Unselect all others ((AlertDialog) dialog).getListView().clearChoices(); ((AlertDialog) dialog).getListView().setItemChecked(which, isChecked); selectedItems.clear(); } else { //Unselect the settings item ((AlertDialog) dialog).getListView().setItemChecked(0, false); if (selectedItems.contains(0)) { selectedItems.remove(selectedItems.indexOf(0)); } } selectedItems.add(which); } else if (selectedItems.contains(which)) { // Else, if the item is already in the array, remove it selectedItems.remove(Integer.valueOf(which)); } } }) // Set the action buttons .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (selectedItems.size() > 0 && selectedItems.get(0).equals(0)) { startActivity(settingsIntent); } else { List<File> chosenFiles = new ArrayList<File>(); for (Object item : selectedItems) { tracer.info( "Selected file to upload- " + files[Integer.valueOf(item.toString())]); chosenFiles.add(new File(gpxFolder, files[Integer.valueOf(item.toString())])); } selectedItems.clear(); if (chosenFiles.size() > 0) { Utilities.ShowProgress(GpsMainActivity.this, getString(R.string.please_wait), getString(R.string.please_wait)); sender.UploadFile(chosenFiles); } } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { selectedItems.clear(); } }); builder.create(); builder.show(); } else { Utilities.MsgBox(getString(R.string.sorry), getString(R.string.no_files_found), this); } }
From source file:nl.knaw.dans.common.lang.file.UnzipUtil.java
private static List<File> extract(final ZipInputStream zipInputStream, String destPath, final int initialCapacityForFiles, final UnzipListener unzipListener, final long totSize) throws FileNotFoundException, IOException { if (unzipListener != null) unzipListener.onUnzipStarted(totSize); final File destPathFile = new File(destPath); if (!destPathFile.exists()) throw new FileNotFoundException(destPath); if (!destPathFile.isDirectory()) throw new IOException("Expected directory, got file."); if (!destPath.endsWith(File.separator)) destPath += File.separator; // now unzip/*w ww . j av a 2 s .c o m*/ BufferedOutputStream out = null; ZipEntry entry; int count; final byte data[] = new byte[BUFFER_SIZE]; final ArrayList<File> files = new ArrayList<File>(initialCapacityForFiles); String entryname; String filename; String path; boolean cancel = false; final DefaultUnzipFilenameFilter filter = new DefaultUnzipFilenameFilter(); try { long bytesWritten = 0; while (((entry = zipInputStream.getNextEntry()) != null) && !cancel) { entryname = entry.getName(); final int fpos = entryname.lastIndexOf(File.separator); if (fpos >= 0) { path = entryname.substring(0, fpos); filename = entryname.substring(fpos + 1); } else { path = ""; filename = new String(entryname); } if (!filter.accept(destPathFile, filename)) { // file filtered out continue; } if (entry.isDirectory()) { if (!createPath(destPath, entryname, files, filter)) // directory filtered out continue; } else { if (!StringUtils.isBlank(path)) { if (!createPath(destPath, path, files, filter)) // path filtered out continue; } final String absFilename = destPath + entryname; final FileOutputStream fos = new FileOutputStream(absFilename); out = new BufferedOutputStream(fos, BUFFER_SIZE); try { // inner loop while ((count = zipInputStream.read(data, 0, BUFFER_SIZE)) != -1) { out.write(data, 0, count); bytesWritten += count; if (unzipListener != null) cancel = !unzipListener.onUnzipUpdate(bytesWritten, totSize); if (cancel) break; } out.flush(); } finally { out.close(); files.add(new File(absFilename)); } } } } finally { zipInputStream.close(); // rollback? if (cancel) { // first remove files for (final File file : files) { if (!file.isDirectory()) file.delete(); } // then folders for (final File file : files) { if (file.isDirectory()) file.delete(); } files.clear(); } } if (unzipListener != null) unzipListener.onUnzipComplete(files, cancel); return files; }
From source file:net.floodlightcontroller.devicemanager.internal.DeviceManagerImpl.java
/** * Clean up expired entities/devices/*from ww w .j a va2s . com*/ */ protected void cleanupEntities() { Calendar c = Calendar.getInstance(); c.add(Calendar.MILLISECOND, -ENTITY_TIMEOUT); Date cutoff = c.getTime(); ArrayList<Entity> toRemove = new ArrayList<Entity>(); ArrayList<Entity> toKeep = new ArrayList<Entity>(); Iterator<Device> diter = deviceMap.values().iterator(); LinkedList<DeviceUpdate> deviceUpdates = new LinkedList<DeviceUpdate>(); while (diter.hasNext()) { Device d = diter.next(); while (true) { deviceUpdates.clear(); toRemove.clear(); toKeep.clear(); for (Entity e : d.getEntities()) { if (e.getLastSeenTimestamp() != null && 0 > e.getLastSeenTimestamp().compareTo(cutoff)) { // individual entity needs to be removed toRemove.add(e); } else { toKeep.add(e); } } if (toRemove.size() == 0) { break; } for (Entity e : toRemove) { removeEntity(e, d.getEntityClass(), d, toKeep); } if (toKeep.size() > 0) { Device newDevice = allocateDevice(d.getDeviceKey(), d.getDhcpClientName(), d.getOldAPs(), //XXX d.getAps(), toKeep, d.getEntityClass()); EnumSet<DeviceField> changedFields = EnumSet.noneOf(DeviceField.class); for (Entity e : toRemove) { changedFields.addAll(findChangedFields(newDevice, e)); } DeviceUpdate update = null; if (changedFields.size() > 0) update = new DeviceUpdate(d, CHANGE, changedFields); //FIXME if (!deviceMap.insert(newDevice.getDeviceKey(), newDevice)) { // concurrent modification; try again // need to use device that is the map now for the next // iteration d = deviceMap.get(d.getDeviceKey()); if (null != d) continue; } if (update != null) deviceUpdates.add(update); } else { DeviceUpdate update = new DeviceUpdate(d, DELETE, null); if (!deviceMap.remove(d.getDeviceKey(), d)) { // concurrent modification; try again // need to use device that is the map now for the next // iteration d = deviceMap.get(d.getDeviceKey()); if (null != d) continue; } deviceUpdates.add(update); } processUpdates(deviceUpdates); break; } } }