Skip to content

Commit

Permalink
TEIIDDES-1459: Make server manager initialisation lazy
Browse files Browse the repository at this point in the history
* Plugin start() methods are executed by worker threads when eclipse starts.
  The UI can be stopped by requests for passwords and other dialogs while
  the plugins continue to be initialised. This means it is dangerous to
  initialise components using the plugin start() methods when other parts
  of eclipse are not actually started.

* DqpPlugin
 * The server manager should be initialised lazily as its Teiid Servers are
   now dependent on checking installed jboss server, which need access to
   the eclipse secure storage, which may have not been initialised if the
   master password is requested from the user.

* DqpUiPlugin
 * Requests the server manager in it start() method which is no longer
   appropriate. Instead, it simply sets the DqpPlugin's password provider
   for use by the server manager's own preview manager when it is initialised.
 * Remove shell field in the password provider as it cannot be guaranteed
   that a shell has been assigned to the workbench when the plugin is started.
 * The PasswordProvider implementation fetches the shell from the workbench
   when its dialog display is requested.

* Tidy up calls to shells for display of dialogs.
  • Loading branch information
Paul Richardson committed Aug 30, 2012
1 parent 8b6cb3f commit ed71afc
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 486 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.lang.reflect.InvocationTargetException;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.dialogs.MessageDialog;
Expand All @@ -28,7 +27,6 @@
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.TeiidServerManager;
import org.teiid.designer.runtime.connection.IPasswordProvider;
import org.teiid.designer.runtime.preview.PreviewManager;
import org.teiid.designer.runtime.preview.jobs.TeiidPreviewVdbCleanupJob;
import org.teiid.designer.runtime.ui.connection.PreviewMissingPasswordDialog;
import org.teiid.designer.ui.common.AbstractUiPlugin;
Expand Down Expand Up @@ -126,14 +124,6 @@ private Image getOrCreateImage( String key ) {
return image;
}

/**
* @param shell the shell used to display any UI that is needed (can be <code>null</code>)
* @return the password provider (never <code>null</code>)
*/
public IPasswordProvider getPasswordProvider(Shell shell) {
return new PasswordProvider(shell);
}

@Override
public PluginUtil getPluginUtil() {
return UTIL;
Expand All @@ -155,13 +145,8 @@ public void start( BundleContext context ) throws Exception {
super.start(context);
// Initialize logging/i18n/debugging utility
((PluginUtilImpl)UTIL).initializePlatformLogger(this);

// set the password provider
PreviewManager previewManager = DqpPlugin.getInstance().getServerManager().getPreviewManager();

if (previewManager != null) {
previewManager.setPasswordProvider(new PasswordProvider(UiUtil.getWorkbenchShellOnlyIfUiThread()));
}

DqpPlugin.getInstance().setPasswordProvider(new PasswordProvider());
}

@Override
Expand Down Expand Up @@ -218,12 +203,7 @@ public void run( IProgressMonitor monitor ) throws InvocationTargetException, In
}

class PasswordProvider implements IPasswordProvider {
final Shell shell;

public PasswordProvider( Shell shell ) {
this.shell = shell;
}


/**
* {@inheritDoc}
*
Expand All @@ -244,7 +224,9 @@ public String getPassword( final String modelName,
public void run() {
String message = DqpUiConstants.UTIL.getString("PasswordProvider.missingPasswordMessage", //$NON-NLS-1$
new Object[] {modelName, profileName});
PreviewMissingPasswordDialog dialog = new PreviewMissingPasswordDialog(getShell(), message);

Shell workbenchShell = UiUtil.getWorkbenchShellOnlyIfUiThread();
PreviewMissingPasswordDialog dialog = new PreviewMissingPasswordDialog(workbenchShell, message);

if (dialog.open() == Window.OK) {
password[0] = dialog.getPassword();
Expand All @@ -254,9 +236,5 @@ public void run() {
false);
return password[0];
}

Shell getShell() {
return this.shell;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

import static org.teiid.designer.runtime.ui.DqpUiConstants.PLUGIN_ID;
import static org.teiid.designer.runtime.ui.DqpUiConstants.UTIL;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand Down Expand Up @@ -44,6 +42,7 @@
import org.teiid.designer.runtime.ui.vdb.VdbRequiresSaveChecker;
import org.teiid.designer.ui.actions.ISelectionAction;
import org.teiid.designer.ui.common.eventsupport.SelectionUtilities;
import org.teiid.designer.ui.common.util.UiUtil;
import org.teiid.designer.vdb.Vdb;


Expand Down Expand Up @@ -197,7 +196,7 @@ public static VDB deployVdb( TeiidServer teiidServer,
}

public static VDB deployVdb(TeiidServer teiidServer, final Object vdbOrVdbFile, final boolean doCreateDataSource) {
Shell shell = DqpUiPlugin.getDefault().getCurrentWorkbenchWindow().getShell();
Shell shell = UiUtil.getWorkbenchShellOnlyIfUiThread();
VDB[] result = new VDB[1];

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.teiid.designer.runtime.ui.vdb;

import static org.teiid.designer.runtime.ui.DqpUiConstants.UTIL;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
Expand All @@ -20,8 +19,8 @@
import org.teiid.core.util.I18nUtil;
import org.teiid.designer.core.util.StringUtilities;
import org.teiid.designer.metamodels.core.ModelType;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.ExecutionAdmin;
import org.teiid.designer.runtime.ui.DqpUiPlugin;
import org.teiid.designer.vdb.TranslatorOverride;
import org.teiid.designer.vdb.Vdb;
import org.teiid.designer.vdb.VdbModelEntry;
Expand Down Expand Up @@ -246,7 +245,7 @@ public void run() {
if (this.admin.getOrCreateDataSource(model,
jndiName,
false,
DqpUiPlugin.getDefault().getPasswordProvider(this.shell)) == null) {
DqpPlugin.getInstance().getPasswordProvider()) == null) {
this.status = DeployStatus.CREATE_DATA_SOURCE_FAILED;
break; // don't try again to create a DS
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@

import java.io.IOException;
import java.util.ResourceBundle;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.osgi.framework.BundleContext;
import org.teiid.core.PluginUtil;
import org.teiid.core.event.IChangeNotifier;
import org.teiid.core.util.PluginUtilImpl;
import org.teiid.designer.runtime.connection.IPasswordProvider;


/**
Expand Down Expand Up @@ -76,6 +75,11 @@ public static DqpPlugin getInstance() {
*/
private TeiidServerManager serverMgr;

/**
* The password provider to be used in the server manager's preview manager
*/
private IPasswordProvider passwordProvider;

/**
* Obtains the current plubin preferences values. <strong>This method should be used instead of
* {@link Plugin#getPluginPreferences()}.</strong>
Expand Down Expand Up @@ -103,8 +107,33 @@ public IPath getRuntimePath() {
* @return the server manager
*/
public TeiidServerManager getServerManager() {

if (serverMgr == null) {
try {
initializeServerRegistry();
} catch (final Exception e) {
throw new RuntimeException(e.getLocalizedMessage(), e);
}
}

return this.serverMgr;
}

/**
* Get the password provider if one has been set
*
* @return the password provider
*/
public IPasswordProvider getPasswordProvider() {
return passwordProvider;
}

/**
* @param passwordProvider
*/
public void setPasswordProvider(IPasswordProvider passwordProvider) {
this.passwordProvider = passwordProvider;
}

/**
* Cleans up the map of context helpers.
Expand Down Expand Up @@ -136,7 +165,8 @@ private void initializeDefaultPreferences() {
}

private void initializeServerRegistry() throws CoreException {
this.serverMgr = new TeiidServerManager(DqpPlugin.getInstance().getRuntimePath().toFile().getAbsolutePath());
String restoreRegistryPath = getRuntimePath().toFile().getAbsolutePath();
this.serverMgr = new TeiidServerManager(restoreRegistryPath, passwordProvider);

// restore registry
final IStatus status = this.serverMgr.restoreState();
Expand Down Expand Up @@ -177,16 +207,6 @@ public void start( final BundleContext context ) throws Exception {

// initialize preferences
initializeDefaultPreferences();

try {
initializeServerRegistry();
} catch (final Exception e) {
if (e instanceof CoreException) {
throw (CoreException)e;
}

throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e.getLocalizedMessage(), e));
}
}

/**
Expand Down

0 comments on commit ed71afc

Please sign in to comment.