Search in sources :

Example 1 with ProcessingStrategy

use of com.microsoft.azuretools.azurecommons.rediscacheprocessors.ProcessingStrategy in project azure-tools-for-java by Microsoft.

the class CreateRedisCacheForm method onOK.

private void onOK() {
    try {
        Azure azure = azureManager.getAzure(currentSub.getSubscriptionId());
        setSubscription(currentSub);
        ProcessingStrategy processor = RedisCacheUtil.doGetProcessor(azure, skus, redisCacheNameValue, selectedLocationValue, selectedResGrpValue, selectedPriceTierValue, noSSLPort, newResGrp);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        ListeningExecutorService executorService = MoreExecutors.listeningDecorator(executor);
        ListenableFuture<Void> futureTask = executorService.submit(new CreateRedisCallable(processor));
        final ProcessingStrategy processorInner = processor;
        Futures.addCallback(futureTask, new FutureCallback<Void>() {

            @Override
            public void onSuccess(Void arg0) {
                if (onCreate != null) {
                    onCreate.run();
                }
            }

            @Override
            public void onFailure(Throwable throwable) {
                JOptionPane.showMessageDialog(null, throwable.getMessage(), "Error occurred when creating Redis Cache: " + redisCacheNameValue, JOptionPane.ERROR_MESSAGE, null);
                try {
                    // notify the waitting thread the thread being waited incurred exception to clear blocking queue
                    processorInner.notifyCompletion();
                } catch (InterruptedException ex) {
                    String msg = String.format(CREATING_ERROR_INDICATOR, "notifyCompletion", ex.getMessage());
                    PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, ex);
                }
            }
        });
        close(DialogWrapper.OK_EXIT_CODE, true);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) ProcessingStrategy(com.microsoft.azuretools.azurecommons.rediscacheprocessors.ProcessingStrategy) IOException(java.io.IOException) ExecutorService(java.util.concurrent.ExecutorService)

Example 2 with ProcessingStrategy

use of com.microsoft.azuretools.azurecommons.rediscacheprocessors.ProcessingStrategy in project azure-tools-for-java by Microsoft.

the class CreateRedisCacheForm method onOK.

private void onOK() {
    final Operation operation = TelemetryManager.createOperation(REDIS, CREATE_REDIS);
    try {
        operation.start();
        Azure azure = azureManager.getAzure(currentSub.getId());
        setSubscription(currentSub);
        ProcessingStrategy processor = RedisCacheUtil.doGetProcessor(azure, skus, redisCacheNameValue, selectedLocationValue, selectedResGrpValue, selectedPriceTierValue, noSSLPort, newResGrp);
        ExecutorService executor = Executors.newSingleThreadExecutor();
        ListeningExecutorService executorService = MoreExecutors.listeningDecorator(executor);
        ListenableFuture<Void> futureTask = executorService.submit(new CreateRedisCallable(processor));
        final ProcessingStrategy processorInner = processor;
        Futures.addCallback(futureTask, new FutureCallback<Void>() {

            @Override
            public void onSuccess(Void arg0) {
                if (onCreate != null) {
                    onCreate.run();
                    operation.complete();
                }
            }

            @Override
            public void onFailure(Throwable throwable) {
                DefaultLoader.getUIHelper().showError(throwable.getMessage(), "Error occurred when creating Redis Cache: " + redisCacheNameValue);
                EventUtil.logError(operation, ErrorType.userError, new Exception(throwable), null, null);
                operation.complete();
                try {
                    // notify the waitting thread the thread being waited incurred exception to clear blocking queue
                    processorInner.notifyCompletion();
                } catch (InterruptedException ex) {
                    String msg = String.format(CREATING_ERROR_INDICATOR, "notifyCompletion", ex.getMessage());
                    PluginUtil.displayErrorDialogAndLog(message("errTtl"), msg, ex);
                }
            }
        }, MoreExecutors.directExecutor());
        close(DialogWrapper.OK_EXIT_CODE, true);
    } catch (Exception ex) {
        ex.printStackTrace();
        EventUtil.logError(operation, ErrorType.userError, ex, null, null);
        operation.complete();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) ProcessingStrategy(com.microsoft.azuretools.azurecommons.rediscacheprocessors.ProcessingStrategy) IOException(java.io.IOException) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService)

Aggregations

Azure (com.microsoft.azure.management.Azure)2 ProcessingStrategy (com.microsoft.azuretools.azurecommons.rediscacheprocessors.ProcessingStrategy)2 IOException (java.io.IOException)2 ExecutorService (java.util.concurrent.ExecutorService)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 Operation (com.microsoft.azuretools.telemetrywrapper.Operation)1