protected DocumentModel doCreateLeafNode(DocumentModel parent, SourceNode node) throws IOException { if (!shouldImportDocument(node)) { return null; } Stopwatch stopwatch = SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.create_leaf"); Split split = stopwatch.start(); DocumentModel leaf = null; try { leaf = getFactory().createLeafNode(session, parent, node); } catch (IOException e) { String errMsg = "Unable to create leaf document for " + node.getSourcePath() + ":" + e + (e.getCause() != null ? e.getCause() : ""); fslog(errMsg, true); log.error(errMsg); // Process leaf node creation error and check if the global // import task should continue boolean shouldImportTaskContinue = getFactory().processLeafNodeCreationError(session, parent, node); if (!shouldImportTaskContinue) { throw new NuxeoException(e); } } finally { split.stop(); } BlobHolder bh = node.getBlobHolder(); if (leaf != null && bh != null) { Blob blob = bh.getBlob(); if (blob != null) { long fileSize = blob.getLength(); String fileName = blob.getFilename(); if (fileSize > 0) { long kbSize = fileSize / 1024; String parentPath = (parent == null) ? "null" : parent.getPathAsString(); fslog( "Created doc " + leaf.getName() + " at " + parentPath + " with file " + fileName + " of size " + kbSize + "KB", true); } uploadedKO += fileSize; } // save session if needed commit(); } return leaf; }
/** Method that lasts randomly from ~0 to ~2500 ms. */ private static void strangeMethod() { Split split = SimonManager.getStopwatch("stopwatch").start(); long random = (long) (Math.random() * 50); try { Thread.sleep(random * random); } catch (InterruptedException e) { e.printStackTrace(); } split.stop(); }
protected void recursiveCreateDocumentFromNode(DocumentModel parent, SourceNode node) throws IOException { if (getFactory().isTargetDocumentModelFolderish(node)) { DocumentModel folder; Boolean newThread = false; if (skipContainerCreation) { folder = parent; skipContainerCreation = false; newThread = true; } else { folder = doCreateFolderishNode(parent, node); if (folder == null) { return; } } // get a new TaskImporter if available to start // processing the sub-tree GenericThreadedImportTask task = null; if (!newThread) { task = createNewTaskIfNeeded(folder, node); } if (task != null) { // force comit before starting new thread commit(true); try { GenericMultiThreadedImporter.getExecutor().execute(task); } catch (RejectedExecutionException e) { log.error("Import task rejected", e); } } else { Stopwatch stopwatch = SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.node_get_children"); Split split = stopwatch.start(); List<SourceNode> nodes = node.getChildren(); split.stop(); if (nodes != null) { for (SourceNode child : nodes) { recursiveCreateDocumentFromNode(folder, child); } } } } else { doCreateLeafNode(parent, node); } }
protected void commit(boolean force) { uploadedFiles++; if (uploadedFiles % 10 == 0) { GenericMultiThreadedImporter.addCreatedDoc(taskId, uploadedFiles); } if (uploadedFiles % batchSize == 0 || force) { Stopwatch stopwatch = SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.session_save"); Split split = stopwatch.start(); fslog("Committing Core Session after " + uploadedFiles + " files", true); session.save(); TransactionHelper.commitOrRollbackTransaction(); TransactionHelper.startTransaction(transactionTimeout); split.stop(); } }
protected DocumentModel doCreateFolderishNode(DocumentModel parent, SourceNode node) { if (!shouldImportDocument(node)) { return null; } Stopwatch stopwatch = SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.create_folder"); Split split = stopwatch.start(); DocumentModel folder = null; try { folder = getFactory().createFolderishNode(session, parent, node); } catch (IOException e) { String errorMsg = "Unable to create folderish document for " + node.getSourcePath() + ":" + e + (e.getCause() != null ? e.getCause() : ""); fslog(errorMsg, true); log.error(errorMsg); // Process folderish node creation error and check if the global // import task should continue boolean shouldImportTaskContinue = getFactory().processFolderishNodeCreationError(session, parent, node); if (!shouldImportTaskContinue) { throw new NuxeoException(e); } } finally { split.stop(); } if (folder != null) { String parentPath = (parent == null) ? "null" : parent.getPathAsString(); fslog("Created Folder " + folder.getName() + " at " + parentPath, true); // save session if needed commit(); } return folder; }
/** * When stopwatch is started, a new tree node is added to the parent tree node and pushed on the * call stack. As a result, child tree node becomes the current tree node. * * @return Current (child) tree node */ public CallTreeNode onStopwatchStart(Split split) { final String name = split.getStopwatch().getName(); CallTreeNode currentNode; if (callStack.isEmpty()) { // Root tree node rootNode = new CallTreeNode(name); currentNode = rootNode; onRootStopwatchStart(currentNode, split); } else { // Child node currentNode = callStack.getLast().getOrAddChild(name); } callStack.addLast(currentNode); return currentNode; }
/** Transforms this call tree into a loggable message. */ public String getLogMessage(Split context) { context.getStopwatch().setAttribute(CallTreeCallback.ATTR_NAME_LAST, this); return "Call Tree:\r\n" + rootNode.toString(); }
/** * Closes the real connection, stops lifespan Simon and decreases the active Simon. * * @throws java.sql.SQLException if real operation fails */ @Override public void close() throws SQLException { conn.close(); life.stop(); }