protected static void execute(
      Collection<Callable<Void>> callables,
      AtomicInteger noEstimateCounter,
      RunningAverageAndStdDev timing)
      throws TasteException {

    Collection<Callable<Void>> wrappedCallables =
        wrapWithStatsCallables(callables, noEstimateCounter, timing);
    int numProcessors = Runtime.getRuntime().availableProcessors();
    ExecutorService executor = Executors.newFixedThreadPool(numProcessors);
    /*int numProcessors = 50; GAE
    ThreadFactory tf = ThreadManager.currentRequestThreadFactory();
    ExecutorService executor = Executors.newCachedThreadPool(tf);*/
    log.info("Starting timing of {} tasks in {} threads", wrappedCallables.size(), numProcessors);
    try {
      List<Future<Void>> futures = executor.invokeAll(wrappedCallables);
      // Go look for exceptions here, really
      for (Future<Void> future : futures) {
        future.get();
      }

    } catch (InterruptedException ie) {
      throw new TasteException(ie);
    } catch (ExecutionException ee) {
      throw new TasteException(ee.getCause());
    }

    executor.shutdown();
    try {
      executor.awaitTermination(10, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
      throw new TasteException(e.getCause());
    }
  }
Example #2
0
  @Override
  public boolean performFinish() {
    // validate the status output
    String outputDirName = getFinishPage().getOutputDir();
    File statusDir = new File(outputDirName);
    if (!statusDir.exists() || !statusDir.isDirectory()) {
      UIUtils.errorMessageBox(
          getShell(), Labels.getString("LoadWizard.errorValidDirectory")); // $NON-NLS-1$
      return false;
    }
    // set the files for status output
    try {
      getController().setStatusFiles(outputDirName, false, true);
      getController().saveConfig();
    } catch (ProcessInitializationException e) {
      UIUtils.errorMessageBox(getShell(), e);
      return false;
    }

    int val = UIUtils.warningConfMessageBox(getShell(), getConfirmationText());

    if (val != SWT.YES) {
      return false;
    }

    if (!wizardhook_validateFinish()) {
      return false;
    }

    try {
      ProgressMonitorDialog dlg = new ProgressMonitorDialog(getShell());
      dlg.run(true, true, new SWTLoadRunable(getController()));

    } catch (InvocationTargetException e) {
      logger.error(Labels.getString("LoadWizard.errorAction"), e); // $NON-NLS-1$
      UIUtils.errorMessageBox(getShell(), e.getCause() != null ? e.getCause() : e);
      return false;
    } catch (InterruptedException e) {
      logger.error(Labels.getString("LoadWizard.errorAction"), e); // $NON-NLS-1$
      UIUtils.errorMessageBox(getShell(), e.getCause() != null ? e.getCause() : e);
      return false;
    }

    return true;
  }
Example #3
0
 private SubscriberInfo registeMessageType(FetchRequest req) {
   SubscriberInfo info = this.topicSubcriberRegistry.get(req.getTopic());
   if (info == null) {
     log.warn("query topic's[" + req.getTopic() + "] subscriberInfo is null.");
     return null;
   }
   Set<String> messageTypeList = info.getMessageTypes();
   MessageTypeCommand mtCmd =
       new MessageTypeCommand(
           this.consumerConfig.getVersion(),
           this.consumerConfig.getGroup(),
           req.getTopic(),
           OpaqueGenerator.getNextOpaque(),
           messageTypeList,
           MetaMessageSessionFactory.startTime);
   try {
     ResponseCommand response =
         this.remotingClient.invokeToGroup(
             req.getBroker().getZKString(),
             mtCmd,
             this.consumerConfig.getFetchTimeoutInMills(),
             TimeUnit.MILLISECONDS);
     if (response instanceof BooleanCommand) {
       BooleanCommand bc = (BooleanCommand) response;
       if (bc.getCode() == HttpStatus.Success) {
         return info;
       } else {
         return null;
       }
     }
   } catch (InterruptedException e) {
     log.error("registe message type interrupted," + e.getMessage(), e.getCause());
   } catch (TimeoutException e) {
     log.error("registe message type timeout," + e.getMessage(), e.getCause());
   } catch (NotifyRemotingException e) {
     log.error("registe message type failed, " + e.getMessage(), e.getCause());
   }
   return null;
 }
Example #4
0
  /* (non-Javadoc)
   * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected Control createContents(Composite parent) {
    // first try to adapt to IFileStore directly
    final IFileStore fileStore = Utils.getFileStore(getElement());
    if (fileStore == null) {
      Label label = new Label(parent, SWT.NONE);
      label.setText(IDEWorkbenchMessages.ResourceInfoPage_noResource);
      return label;
    }
    try {
      if (getElement().getAdapter(File.class) != null) {
        fFileInfo = fileStore.fetchInfo(EFS.NONE, new NullProgressMonitor());
      } else {
        final IFileInfo[] result = new IFileInfo[1];
        ProgressMonitorDialog dlg = new ProgressMonitorDialog(parent.getShell());
        try {
          dlg.run(
              true,
              true,
              new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  try {
                    result[0] = fileStore.fetchInfo(IExtendedFileStore.DETAILED, monitor);
                  } catch (CoreException e) {
                    throw new InvocationTargetException(e, e.getLocalizedMessage());
                  } finally {
                    monitor.done();
                  }
                }
              });
        } catch (InvocationTargetException e) {
          throw (CoreException) e.getTargetException();
        } catch (InterruptedException e) {
          e.getCause();
        }
        fFileInfo = result[0];
      }
    } catch (CoreException e) {
      UIUtils.showErrorMessage(Messages.FileInfoPropertyPage_FailedToFetchInfo, e);
    }
    if (fFileInfo == null) {
      Label label = new Label(parent, SWT.NONE);
      label.setText(IDEWorkbenchMessages.ResourceInfoPage_noResource);
      return label;
    }

    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(GridLayoutFactory.swtDefaults().margins(0, 0).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite basicInfo = createBasicInfoGroup(composite, fileStore, fFileInfo);
    basicInfo.setLayoutData(GridDataFactory.fillDefaults().create());

    Label separator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());

    Composite state = createStateGroup(composite, fileStore, fFileInfo);
    state.setLayoutData(GridDataFactory.fillDefaults().create());

    if (fFileInfo instanceof IExtendedFileInfo) {
      IExtendedFileInfo extendedInfo = (IExtendedFileInfo) fFileInfo;
      Composite owner = createOwnerGroup(composite, extendedInfo);
      owner.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).indent(0, 10).create());

      Composite permissions = createPermissionsGroup(composite, extendedInfo);
      permissions.setLayoutData(
          GridDataFactory.fillDefaults().grab(true, false).indent(0, 5).create());
    }

    /* TODO
    new Label(composite, SWT.NONE); // a vertical spacer
    encodingEditor = new EncodingFieldEditor("",
    		fileInfo.isDirectory() ? IDEWorkbenchMessages.ResourceInfo_fileEncodingTitle : IDEWorkbenchMessages.WorkbenchPreference_encoding,
    		composite);
    encodingEditor.setPreferenceStore(null);
    encodingEditor.setPage(this);
    encodingEditor.load();

    encodingEditor.setPropertyChangeListener(new IPropertyChangeListener() {
    	public void propertyChange(PropertyChangeEvent event) {
    		if (event.getProperty().equals(FieldEditor.IS_VALID)) {
    			setValid(encodingEditor.isValid());
    		}
    	}
    });

    if (fileInfo.isDirectory()) {
    	lineDelimiterEditor = new LineDelimiterEditor(composite, resource.getProject());
    	lineDelimiterEditor.doLoad();
    }
    */

    Dialog.applyDialogFont(composite);

    return composite;
  }