List of usage examples for java.lang InterruptedException getMessage
public String getMessage()
From source file:msi.gama.application.workspace.WorkspaceModelsManager.java
private IFile findOutsideWorkspace(final IPath originalPath) { // GAMA.getGui().debug("WorkspaceModelsManager.findOutsideWorkspace " + originalPath); final File modelFile = new File(originalPath.toOSString()); // TODO If the file does not exist we return null (might be a good idea to check other locations) if (!modelFile.exists()) { return null; }//w w w . j a v a2 s . co m // We try to find a folder containing the model file which can be considered as a project File projectFileBean = new File(modelFile.getPath()); File dotFile = null; while (projectFileBean != null && dotFile == null) { projectFileBean = projectFileBean.getParentFile(); if (projectFileBean != null) { /* parcours des fils pour trouver le dot file et creer le lien vers le projet */ final File[] children = projectFileBean.listFiles(); if (children != null) for (int i = 0; i < children.length; i++) { if (children[i].getName().equals(".project")) { dotFile = children[i]; break; } } } } if (dotFile == null || projectFileBean == null) { MessageDialog.openInformation(Display.getDefault().getActiveShell(), "No project", "The model '" + modelFile.getAbsolutePath() + "' does not seem to belong to an existing GAML project. You can import it in an existing project or in the 'Unclassified models' project."); return createUnclassifiedModelsProjectAndAdd(originalPath); } final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IPath location = new Path(dotFile.getAbsolutePath()); final String pathToProject = projectFileBean.getName(); try { // We load the project description. final IProjectDescription description = workspace.loadProjectDescription(location); if (description != null) { final WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { // We try to get the project in the workspace IProject proj = workspace.getRoot().getProject(pathToProject); // If it does not exist, we create it if (!proj.exists()) { // If a project with the same name exists final IProject[] projects = workspace.getRoot().getProjects(); final String name = description.getName(); for (final IProject p : projects) { if (p.getName().equals(name)) { MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Existing project", "A project with the same name already exists in the workspace. The model '" + modelFile.getAbsolutePath() + " will be imported as part of the 'Unclassified models' project."); createUnclassifiedModelsProjectAndAdd(originalPath); return; } } proj.create(description, monitor); } else { // project exists but is not accessible, so we delete it and recreate it if (!proj.isAccessible()) { proj.delete(true, null); proj = workspace.getRoot().getProject(pathToProject); proj.create(description, monitor); } } // We open the project proj.open(IResource.NONE, monitor); // And we set some properties to it setValuesProjectDescription(proj, false, false, null); } }; operation.run(new NullProgressMonitor() { // @Override // public void done() { // RefreshHandler.run(); // // scope.getGui().tell("Project " + workspace.getRoot().getProject(pathToProject).getName() + // // " has been imported"); // } }); } } catch (final InterruptedException e) { return null; } catch (final InvocationTargetException e) { return null; } catch (final CoreException e) { GAMA.getGui().error("Error wien importing project: " + e.getMessage()); } final IProject project = workspace.getRoot().getProject(pathToProject); final String relativePathToModel = project.getName() + modelFile.getAbsolutePath().replace(projectFileBean.getPath(), ""); return findInWorkspace(new Path(relativePathToModel)); }
From source file:com.sm.store.client.ClusterClient.java
public List<KeyValue> query(String queryStr) { List<KeyCluster> keyClusterList = findAll(); OpType opType = OpType.QueryStatement; int size = keyClusterList.size(); CountDownLatch countDownLatch = new CountDownLatch(size); ExecutorService executor = Executors.newFixedThreadPool(size); List<Runnable> runnableList = new ArrayList<Runnable>(size); for (int i = 0; i < size; i++) { Request request = create4GetPutRequest(keyClusterList.get(i).getKeyList(), opType, queryStr); RunThread runThread = new RunThread(request, keyClusterList.get(i), countDownLatch, OpType.QueryStatement);// w w w .j av a2s. com runnableList.add(runThread); executor.submit(runThread); } try { countDownLatch.await(timeout * 5, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { logger.warn(ex.getMessage(), ex); } finally { executor.shutdown(); return mergeResponse(runnableList); } }
From source file:com.sm.store.client.ClusterClient.java
private List<KeyValue> executeRequest(List<KeyCluster> keyClusterList, OpType opType, String queryStr, List list) {// w ww. j a v a 2 s .c o m int size = keyClusterList.size(); //OpType opType = ( queryStr == null ? OpType.MultiGets : OpType.MultiSelectQuery); CountDownLatch countDownLatch = new CountDownLatch(size); ExecutorService executor = Executors.newFixedThreadPool(size); List<Runnable> runnableList = new ArrayList<Runnable>(size); for (int i = 0; i < size; i++) { Request request = create4GetPutRequest(list, opType, queryStr); RunThread runThread = new RunThread(request, keyClusterList.get(i).getCluster(), countDownLatch, keyClusterList.get(i).getKeyList().get(0), opType); runnableList.add(runThread); executor.submit(runThread); } try { countDownLatch.await(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { logger.warn(ex.getMessage(), ex); } finally { executor.shutdown(); return mergeResponse(runnableList); } }
From source file:com.jnj.b2b.test.orders.B2BAcceleratorTestOrderData.java
protected ScheduledCartData scheduleOrder(final String customerUid, final Map<String, Long> products, final AddressData deliveryAddress, final String purchaseOrderNumber, final String costCenterCode, final String quotePetition, final TriggerData triggerData) { // Impersonate site and customer final B2BCustomerModel customer = getUserService().getUserForUID(customerUid.toLowerCase(), B2BCustomerModel.class); final ImpersonationContext ctx = new ImpersonationContext(); ctx.setSite(getCmsAdminSiteService().getSiteForId(Jnjb2bTestConstants.POWERTOOLS_SITE)); ctx.setUser(customer);//from w w w . j a v a 2 s . c o m ctx.setCurrency(i18nService.getCurrency(CURRENCY_ISO_CODE)); return (ScheduledCartData) getImpersonationService().executeInContext(ctx, new ImpersonationService.Executor<Object, ImpersonationService.Nothing>() { @Override public Object execute() throws ImpersonationService.Nothing { ScheduledCartData scheduledCartData = null; // Check if the order already exists by PurchaseOrderNumber if (prepareANewSessionCartForCheckout(products, deliveryAddress, purchaseOrderNumber, costCenterCode, quotePetition, customer)) { scheduledCartData = b2bCheckoutFacade.scheduleOrder(triggerData); if (scheduledCartData == null) { LOG.error("Failed to placeOrder"); } else { LOG.info("Scheduled Order order job [" + scheduledCartData.getJobCode() + "]"); // Sleep for 10s to allow the fulfilment processes to run for this order // Only have to worry about this here if we are running initialize from ant // as the process will exit immediately that we finish initialising. // Also to allow approval process to locate approver try { Thread.sleep(10000); } catch (final InterruptedException e) { LOG.error(e.getMessage(), e); } } } return scheduledCartData; } }); }
From source file:com.mitre.test.orders.B2BAcceleratorTestOrderData.java
protected ScheduledCartData scheduleOrder(final String customerUid, final Map<String, Long> products, final AddressData deliveryAddress, final String purchaseOrderNumber, final String costCenterCode, final String quotePetition, final TriggerData triggerData) { // Impersonate site and customer final B2BCustomerModel customer = getUserService().getUserForUID(customerUid.toLowerCase(), B2BCustomerModel.class); final ImpersonationContext ctx = new ImpersonationContext(); ctx.setSite(getCmsAdminSiteService().getSiteForId(MitreTestConstants.POWERTOOLS_SITE)); ctx.setUser(customer);//from ww w . j av a 2 s . c o m ctx.setCurrency(i18nService.getCurrency(CURRENCY_ISO_CODE)); return (ScheduledCartData) getImpersonationService().executeInContext(ctx, new ImpersonationService.Executor<Object, ImpersonationService.Nothing>() { @Override public Object execute() throws ImpersonationService.Nothing { ScheduledCartData scheduledCartData = null; // Check if the order already exists by PurchaseOrderNumber if (prepareANewSessionCartForCheckout(products, deliveryAddress, purchaseOrderNumber, costCenterCode, quotePetition, customer)) { scheduledCartData = b2bCheckoutFacade.scheduleOrder(triggerData); if (scheduledCartData == null) { LOG.error("Failed to placeOrder"); } else { LOG.info("Scheduled Order order job [" + scheduledCartData.getJobCode() + "]"); // Sleep for 10s to allow the fulfilment processes to run for this order // Only have to worry about this here if we are running initialize from ant // as the process will exit immediately that we finish initialising. // Also to allow approval process to locate approver try { Thread.sleep(10000); } catch (final InterruptedException e) { LOG.error(e.getMessage(), e); } } } return scheduledCartData; } }); }
From source file:com.yahoo.yrlhaifa.liveqa.challenge.http_operation.QuestionOperationHttpRequestSender.java
private void sendRequestsWithRequestExecutor(final FutureRequestExecutionService requestExecutor) throws QuestionOperationException, InterruptedException { final long timeOut = requestGeneralParameters.getTimeForAnswerMilliseconds() + requestGeneralParameters.getExtraTimeForRequestResponseMilliseconds() + requestGeneralParameters.getSlackTimeForRequestExecutorTimeOutMilliseconds(); final long maximumAllowedDuration = requestGeneralParameters.getTimeForAnswerMilliseconds() + requestGeneralParameters.getExtraTimeForRequestResponseMilliseconds(); List<HttpRequestFutureTask<Participant>> futures = new ArrayList<HttpRequestFutureTask<Participant>>( participants.size());// ww w .j a v a 2 s . co m for (Participant participant : participants) { HttpRequestFutureTask<Participant> future = requestExecutor.execute(createRequest(participant), null, new AnswerResponseHandler(participant)); futures.add(future); } systemsSucceeded = new LinkedHashSet<Participant>(); final long loopStartTime = new Date().getTime(); long extraAdd = 0; for (HttpRequestFutureTask<Participant> future : futures) { try { final long timePassed = (new Date().getTime() - loopStartTime); extraAdd += Constants.EXTRA_ADD_TIMEOUT_FOR_EACH_THREAD_MILLISECONDS; final long currentIterationTimeOut = extraAdd + Math.max(0, (timeOut - timePassed)); if (logger.isDebugEnabled()) { logger.debug("Getting a future with time-out of " + currentIterationTimeOut + " milliseconds"); } Participant participantOfThisFuture = future.get(currentIterationTimeOut, TimeUnit.MILLISECONDS); logger.info("System " + participantOfThisFuture.getUniqueSystemId() + " has finished the question processing."); if (!future.isDone()) { logger.info("Processing by system: \"" + participantOfThisFuture.getUniqueSystemId() + "\" is not done, and is being cancelled now."); future.cancel(true); } else { if (!future.isCancelled()) { if (future.taskDuration() <= maximumAllowedDuration) { systemsSucceeded.add(participantOfThisFuture); boolean inMap = false; if (mapParticipantToAnswer.containsKey(participantOfThisFuture)) { final ParticipantResponse answer = mapParticipantToAnswer .get(participantOfThisFuture); if (answer != null) { inMap = true; ResponseOperationInformation responseOperationInformation = new ResponseOperationInformation( future.startedTime(), future.endedTime(), future.taskDuration()); answer.setResponseOperationInformation(responseOperationInformation); } } if (!inMap) { logger.info("A request-response for participant \"" + participantOfThisFuture.getUniqueSystemId() + "\" has completed with no answer."); // Such a behavior might follow // unsuccessful status code, or // when the participant decides // not to answer, while sending // an HTTP response. // logger.error("Unexpected behavior: A participant request-response ended successfully, // but the answer was not put in the map. This is a bug. Program continues, however."); } } else { logger.info("System \"" + participantOfThisFuture.getUniqueSystemId() + "\" has finished, but not in time (time out has not been reached, thanks to slack executor time. However, the required time constraints were not met).\n" + "It\'s answer (if exists) will be discarded."); // will be discarded by // not including that // system in the // "systemSucceeded" set. } } } } catch (InterruptedException e) { // I was interrupted (someone called Thread.interrupt() on this thread. This has nothing to do with the // executor's threads). // I must stop. There is nothing special for cleanup, so let's just stop. throw e; } catch (CancellationException e) { // The task was cancelled. Nothing to worry about. If it has been cancelled, than it will not write into // the map. Just log it. logger.info("One of the requests was cancelled: " + e.getMessage() + ". Program continues."); } catch (ExecutionException e) { // An HTTP problem. Either IO or protocol problem. Never mind. This is not system-wide fatal problem. // Let's log it, and continue. logger.error("One of the requests failed to execute. Program continues.", e); } catch (TimeoutException e) { // A time-out has been reached. Again, nothing to worry about. I have to cancel the task. // Its output should be discarded, and I take care of it above (in the try block) implicitly, when I do // not include this // system-id in the "systemsSucceeded" set. // Even if the task writes its result into the map, it will be removed, and the removal happens after // the executor.shutdownNow(), // So we can be sure it is finally not in the map. String exceptionMessage = e.getMessage(); if (null == exceptionMessage) { exceptionMessage = ""; } else exceptionMessage = " <" + exceptionMessage + ">"; logger.info("One of the requests has timed-out" + exceptionMessage + ". Program continues."); future.cancel(true); } } }
From source file:com.vmware.bdd.service.impl.ClusterHealService.java
@Override @SuppressWarnings("unchecked") public VcVirtualMachine createReplacementVm(String clusterName, String groupName, String nodeName, List<DiskSpec> replacementDisks) { ClusterCreate spec = configMgr.getClusterConfig(clusterName); NodeEntity node = clusterEntityMgr.findByName(spec.getName(), groupName, nodeName); List<DiskSpec> fullDiskList = getReplacedFullDisks(node.getVmName(), replacementDisks); CreateVmSP cloneVmSp = getReplacementVmSp(spec, groupName, node, fullDiskList); CompensateCreateVmSP deleteVmSp = new CompensateCreateVmSP(cloneVmSp); Pair<Callable<Void>, Callable<Void>>[] storeProcedures = new Pair[1]; storeProcedures[0] = new Pair<Callable<Void>, Callable<Void>>(cloneVmSp, deleteVmSp); // execute store procedures to create VMs logger.info("ClusterHealService, start to create replacement vm for node " + nodeName); Pair<ExecutionResult, ExecutionResult>[] result; try {/* www. j a v a 2 s. co m*/ result = Scheduler.executeStoredProcedures(com.vmware.aurora.composition.concurrent.Priority.BACKGROUND, storeProcedures, 1, null); if (result == null) { logger.error("vm creation failed for node " + nodeName); return null; } Pair<ExecutionResult, ExecutionResult> pair = result[0]; CreateVmSP sp = (CreateVmSP) storeProcedures[0].first; if (pair.first.finished && pair.first.throwable == null && pair.second.finished == false) { VcVirtualMachine vm = sp.getVM(); AuAssert.check(vm != null); return vm; } else if (pair.first.throwable != null) { logger.error("Failed to create replacement virtual machine for node " + node.getVmName(), pair.first.throwable); throw ClusterHealServiceException.FAILED_CREATE_REPLACEMENT_VM(node.getVmName()); } } catch (InterruptedException e) { logger.error("error in fixing vm " + nodeName, e); throw BddException.INTERNAL(e, e.getMessage()); } return null; }
From source file:com.octanner.test.orders.B2BAcceleratorTestOrderData.java
protected ScheduledCartData scheduleOrder(final String customerUid, final Map<String, Long> products, final AddressData deliveryAddress, final String purchaseOrderNumber, final String costCenterCode, final String quotePetition, final TriggerData triggerData) { // Impersonate site and customer final B2BCustomerModel customer = getUserService().getUserForUID(customerUid.toLowerCase(), B2BCustomerModel.class); final ImpersonationContext ctx = new ImpersonationContext(); ctx.setSite(getCmsAdminSiteService().getSiteForId(OctannerTestConstants.POWERTOOLS_SITE)); ctx.setUser(customer);/*from www. j a v a 2 s . c o m*/ ctx.setCurrency(i18nService.getCurrency(CURRENCY_ISO_CODE)); return (ScheduledCartData) getImpersonationService().executeInContext(ctx, new ImpersonationService.Executor<Object, ImpersonationService.Nothing>() { @Override public Object execute() throws ImpersonationService.Nothing { ScheduledCartData scheduledCartData = null; // Check if the order already exists by PurchaseOrderNumber if (prepareANewSessionCartForCheckout(products, deliveryAddress, purchaseOrderNumber, costCenterCode, quotePetition, customer)) { scheduledCartData = b2bCheckoutFacade.scheduleOrder(triggerData); if (scheduledCartData == null) { LOG.error("Failed to placeOrder"); } else { LOG.info("Scheduled Order order job [" + scheduledCartData.getJobCode() + "]"); // Sleep for 10s to allow the fulfilment processes to run for this order // Only have to worry about this here if we are running initialize from ant // as the process will exit immediately that we finish initialising. // Also to allow approval process to locate approver try { Thread.sleep(10000); } catch (final InterruptedException e) { LOG.error(e.getMessage(), e); } } } return scheduledCartData; } }); }
From source file:com.sm.store.client.ClusterClient.java
/** * OpType to determine deserialze payload during merge * MultiGets means payload is byte[], else payload is serialized object * @param from// ww w.j av a 2s. c o m * @param to * @param queryStr * @return */ public List<KeyValue> scan(Key from, Key to, String queryStr) { List<KeyCluster> keyClusterList = findAll(); OpType opType = (queryStr == null ? OpType.MultiGets : OpType.MultiSelectQuery); //return executeRequest( keyClusterList, opType); int size = keyClusterList.size(); List<Key> keyList = new ArrayList<Key>(2); keyList.add(from); keyList.add(to); ScanParaList scanParaList = new ScanParaList(OpType.Get, keyList, queryStr); CountDownLatch countDownLatch = new CountDownLatch(size); ExecutorService executor = Executors.newFixedThreadPool(size); List<Runnable> runnableList = new ArrayList<Runnable>(size); for (int i = 0; i < size; i++) { Request request = createScanRequest(scanParaList); RunThread runThread = new RunThread(request, keyClusterList.get(i), countDownLatch, OpType.Scan); runnableList.add(runThread); executor.submit(runThread); } try { countDownLatch.await(timeout * 5, TimeUnit.MILLISECONDS); } catch (InterruptedException ex) { logger.warn(ex.getMessage(), ex); } finally { executor.shutdown(); return mergeResponse(runnableList); } }