Esempio n. 1
0
  private void exportChildren(final ExportTransaction transaction) throws CommandException {
    final int timeOutFactor = 40;
    final CnATreeElement element = transaction.getElement();
    final Set<CnATreeElement> children = element.getChildren();
    if (FinishedRiskAnalysis.TYPE_ID.equals(element.getTypeId())) {
      children.addAll(getRiskAnalysisOrphanElements(element));
    }

    final List<ExportTransaction> transactionList = new ArrayList<ExportTransaction>();

    taskExecutor = Executors.newFixedThreadPool(getMaxNumberOfThreads());
    if (!children.isEmpty()) {
      for (final CnATreeElement child : children) {
        final ExportTransaction childTransaction = new ExportTransaction(child);
        transactionList.add(childTransaction);
        final ExportThread thread = new ExportThread(childTransaction);
        configureThread(thread);

        // Multi thread:
        thread.addListener(
            new IThreadCompleteListener() {
              @Override
              public void notifyOfThreadComplete(final Thread thread) {
                final ExportThread exportThread = (ExportThread) thread;
                synchronized (LOCK) {
                  if (exportThread.getSyncObject() != null) {
                    transaction.getTarget().getChildren().add(exportThread.getSyncObject());
                  }
                  getValuesFromThread(exportThread);
                }
              }
            });
        taskExecutor.execute(thread);
      }
    }

    awaitTermination(transactionList.size() * timeOutFactor);

    if (getLog().isDebugEnabled() && transactionList.size() > 0) {
      getLog().debug(transactionList.size() + " export threads finished.");
    }

    for (final ExportTransaction childTransaction : transactionList) {
      if (checkElement(childTransaction.getElement())) {
        exportChildren(childTransaction);
      }
    }
  }
Esempio n. 2
0
  /**
   * Export (i.e. "create XML representation of" the given cnATreeElement and its successors. For
   * this, child elements are exported recursively. All elements that have been processed are
   * returned as a list of {@code syncObject}s with their respective attributes, represented as
   * {@code syncAttribute}s.
   *
   * @return XML representation of elements
   * @throws CommandException
   */
  private byte[] export() throws CommandException {
    if (getLog().isInfoEnabled()) {
      getLog().info("Max number of threads is: " + getMaxNumberOfThreads());
    }

    getCache().removeAll();

    final SyncVnaSchemaVersion formatVersion = createVersionData();

    final SyncData syncData = new SyncData();
    final ExportTransaction exportTransaction = new ExportTransaction();

    for (final CnATreeElement element : elements) {
      exportTransaction.setElement(element);
      exportElement(exportTransaction);
      syncData.getSyncObject().add(exportTransaction.getTarget());
    }

    exportLinks(syncData);

    if (getLog().isDebugEnabled()) {
      final Statistics s = getCache().getStatistics();
      getLog().debug("Cache size: " + s.getObjectCount() + ", hits: " + s.getCacheHits());
    }

    final SyncMapping syncMapping = new SyncMapping();
    createMapping(syncMapping.getMapObjectType());

    final SyncRequest syncRequest = new SyncRequest();
    syncRequest.setSourceId(sourceId);
    syncRequest.setSyncData(syncData);
    syncRequest.setSyncMapping(syncMapping);
    syncRequest.setSyncVnaSchemaVersion(formatVersion);

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ExportFactory.marshal(syncRequest, bos);
    return bos.toByteArray();
  }