1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 14:25:37 +02:00

[197167][persistence][api] Need callback API to know when RSE model is fully restored

https://bugs.eclipse.org/bugs/show_bug.cgi?id=197167
This commit is contained in:
David Dykstal 2008-03-06 12:30:22 +00:00
parent 9a1cd021d1
commit 53cbc7574a
22 changed files with 546 additions and 382 deletions

View file

@ -152,5 +152,12 @@
<initializer class="org.eclipse.rse.internal.core.RSEPreferenceInitializer"/>
<initializer class="org.eclipse.rse.internal.logging.LoggingPreferenceInitializer"/>
</extension>
<extension
point="org.eclipse.rse.core.modelInitializers">
<modelInitializer
class="org.eclipse.rse.internal.core.RSELocalConnectionInitializer"
type="workspace">
</modelInitializer>
</extension>
</plugin>

View file

@ -54,6 +54,21 @@
</appinfo>
</annotation>
</attribute>
<attribute name="type">
<annotation>
<documentation>
The type of initialization that is to take place. If this is a one time initialization for this workspace then use &quot;workspace&quot;. If this initialization is to occur at the beginning of each workspace session then use &quot;session&quot;. If nothing is specfied then &quot;session&quot; is assumed.
</documentation>
</annotation>
<simpleType>
<restriction base="string">
<enumeration value="workspace">
</enumeration>
<enumeration value="session">
</enumeration>
</restriction>
</simpleType>
</attribute>
</complexType>
</element>

View file

@ -23,18 +23,8 @@ public interface IRSEModelInitializer {
* Runs the initializer. The initializer should set the monitor to done when complete.
* @param monitor the monitor that measures progress of this initializer.
* @return an IStatus indicating the success of the initializer. The status will
* be logged if it is not an OK status. If a status is an IStatus.Error then the
* initializer will be assumed to have failed and will not be queried for its
* completion status.
* be logged if it is not an OK status.
*/
public IStatus run(IProgressMonitor monitor);
/**
* Reports if an initializer is complete. If an initializer runs synchronously then it must
* report true immediately after it is run.
* An initializer may choose to do some of its work asynchronously. If so, it must
* report true when the initializer considers its work to be complete.
* @return true if the initializer has completed its initialization.
*/
public boolean isComplete();
}

View file

@ -7,6 +7,7 @@
* Contributors:
* Kushal Munir (IBM) - Initial API and implementation.
* David Dykstal (IBM) - updated with comments, removed keys that are not to be used globally
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
********************************************************************************/
package org.eclipse.rse.core;
@ -57,4 +58,11 @@ public interface IRSEPreferenceNames {
*/
public static final String DEFAULT_PERSISTENCE_PROVIDER = "DEFAULT_PERSISTENCE_PROVIDER"; //$NON-NLS-1$
/**
* The key of the string containing the id of the boolean value to create a local connection.
* Value is "CREATE_LOCAL_CONNECTION".
* This value is part of the API and may be used to customize products.
*/
public static final String CREATE_LOCAL_CONNECTION = "CREATE_LOCAL_CONNECTION"; //$NON-NLS-1$
}

View file

@ -39,7 +39,7 @@ import org.eclipse.rse.core.comm.SystemKeystoreProviderManager;
import org.eclipse.rse.core.model.ISystemProfileManager;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy;
import org.eclipse.rse.internal.core.InitRSEJob;
import org.eclipse.rse.internal.core.RSEInitJob;
import org.eclipse.rse.internal.core.RSECoreRegistry;
import org.eclipse.rse.internal.core.model.SystemProfileManager;
import org.eclipse.rse.internal.core.model.SystemRegistry;
@ -74,6 +74,15 @@ public class RSECorePlugin extends Plugin {
*/
public static final String CURRENT_RELEASE_NAME = "2.0.0"; //$NON-NLS-1$
/**
* Value 0.
* Used in isInitComplete(int) which will return true if all phases of
* initialization are complete.
* Clients must not assume any particular ordering
* among phases based on the value.
*/
public static final int INIT_ALL = 0;
/**
* Value 1.
* Used in isInitComplete(int) which will return true if the model phase of the
@ -84,14 +93,14 @@ public class RSECorePlugin extends Plugin {
public static final int INIT_MODEL = 1;
/**
* Value 999.
* Used in isInitComplete(int) which will return true if all phases of
* initialization are complete.
* Value 2.
* Used in isInitComplete(int) which will return true if the initializer phase of the
* initialization is complete.
* Clients must not assume any particular ordering
* among phases based on the value.
*/
public static final int INIT_ALL = 999;
public static final int INIT_INITIALIZER = 2;
private static RSECorePlugin plugin = null; // the singleton instance of this plugin
private Logger logger = null;
private ISystemRegistry _systemRegistry = null;
@ -113,7 +122,20 @@ public class RSECorePlugin extends Plugin {
* @throws InterruptedException if this wait was interrupted for some reason.
*/
public static IStatus waitForInitCompletion() throws InterruptedException {
return InitRSEJob.getInstance().waitForCompletion();
return RSEInitJob.getInstance().waitForCompletion();
}
/**
* Waits until the RSE has completed a specific phase of its initialization.
* @param phase the phase to wait for completion.
* @throws InterruptedException if this wait was interrupted for some reason.
* @throws IllegalArgumentException if the phase is undefined.
* @see #INIT_ALL
* @see #INIT_INITIALIZER
* @see #INIT_MODEL
*/
public static void waitForInitCompletion(int phase) throws InterruptedException {
RSEInitJob.getInstance().waitForCompletion(phase);
}
/**
@ -123,10 +145,11 @@ public class RSECorePlugin extends Plugin {
* initialization for that phase has completed regardless its status of that completion.
* @throws IllegalArgumentException if the phase is undefined.
* @see #INIT_ALL
* @see #INIT_INITIALIZER
* @see #INIT_MODEL
*/
public static boolean isInitComplete(int phase) {
return InitRSEJob.getInstance().isComplete(phase);
return RSEInitJob.getInstance().isComplete(phase);
}
/**
@ -137,7 +160,7 @@ public class RSECorePlugin extends Plugin {
* @param listener the listener to be added
*/
public static void addInitListener(IRSEInitListener listener) {
InitRSEJob.getInstance().addInitListener(listener);
RSEInitJob.getInstance().addInitListener(listener);
}
/**
@ -146,7 +169,7 @@ public class RSECorePlugin extends Plugin {
* @param listener the listener to be removed
*/
public static void removeInitListener(IRSEInitListener listener) {
InitRSEJob.getInstance().removeInitListener(listener);
RSEInitJob.getInstance().removeInitListener(listener);
}
/**
@ -252,7 +275,7 @@ public class RSECorePlugin extends Plugin {
public void start(BundleContext context) throws Exception {
super.start(context);
registerKeystoreProviders();
InitRSEJob job = InitRSEJob.getInstance();
RSEInitJob job = RSEInitJob.getInstance();
job.schedule();
}
@ -261,10 +284,10 @@ public class RSECorePlugin extends Plugin {
* @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
LoggerFactory.freeLogger(this);
logger = null;
plugin = null;
super.stop(context);
}
/**

View file

@ -8,6 +8,7 @@
* David Dykstal (IBM) - initial API and implementation
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
* Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
********************************************************************************/
package org.eclipse.rse.core;
@ -446,6 +447,15 @@ public class RSEPreferencesManager {
}
return keyValues;
}
/**
* @return the boolean value indicating whether or not to create a local connection on a fresh workspace.
*/
public static boolean getCreateLocalConnection() {
Preferences prefs = RSECorePlugin.getDefault().getPluginPreferences();
boolean result = prefs.getBoolean(IRSEPreferenceNames.CREATE_LOCAL_CONNECTION);
return result;
}
/*
* Having this method private disables instance creation.

View file

@ -1,231 +0,0 @@
/********************************************************************************
* Copyright (c) 2008 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
********************************************************************************/
package org.eclipse.rse.internal.core;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS;
import org.eclipse.rse.core.IRSEInitListener;
import org.eclipse.rse.core.IRSEModelInitializer;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.logging.Logger;
/**
* The InitRSEJob is a job named "Initialize RSE". It is instantiated and run during
* RSE startup. It must not be run at any other time. The job restores the
* persistent form of the RSE model. Use the extension point
* org.eclipse.rse.core.modelInitializers to supplement the model once it is
* restored.
*/
public final class InitRSEJob extends Job {
/**
* The name of this job. This is API. Clients may use this name to find this job by name.
*/
public final static String NAME = "Initialize RSE"; //$NON-NLS-1$
private static InitRSEJob singleton = null;
private boolean isComplete = false;
private boolean isModelComplete = false;
private Set listeners = new HashSet(10);
private Logger logger = null;
/**
* Returns the singleton instance of this job.
* @return the InitRSEJob instance for this workbench.
*/
public synchronized static InitRSEJob getInstance() {
if (singleton == null) {
singleton = new InitRSEJob();
}
return singleton;
}
private InitRSEJob() {
super(NAME);
logger = RSECorePlugin.getDefault().getLogger();
}
/**
* Adds a new listener to the set of listeners to be notified when initialization phases complete.
* If the listener is added after the phase has completed it will not be invoked.
* If the listener is already in the set it will not be added again.
* Listeners may be notified in any order.
* @param listener the listener to be added
*/
public void addInitListener(IRSEInitListener listener) {
synchronized (listeners) {
listeners.add(listener);
}
}
/**
* Removes a listener to the set of listeners to be notified when phases complete.
* If the listener is not in the set this does nothing.
* @param listener the listener to be removed
*/
public void removeInitListener(IRSEInitListener listener) {
synchronized (listeners) {
listeners.remove(listener);
}
}
/**
* Notify all registered listeners of a phase completion
* @param phase the phase just completed.
*/
private void notifyListeners(int phase) {
List myListeners = new ArrayList(listeners.size());
synchronized (listeners) {
myListeners.addAll(listeners);
}
for (Iterator z = myListeners.iterator(); z.hasNext();) {
IRSEInitListener listener = (IRSEInitListener) z.next();
try {
listener.phaseComplete(phase);
} catch (RuntimeException e) {
logger.logError(RSECoreMessages.InitRSEJob_listener_ended_in_error, e);
}
}
}
public IStatus run(IProgressMonitor monitor) {
IStatus result = Status.OK_STATUS;
Logger logger = RSECorePlugin.getDefault().getLogger();
// get and initialize the profile manager
RSECorePlugin.getTheSystemProfileManager();
isModelComplete = true;
notifyListeners(RSECorePlugin.INIT_MODEL);
// instantiate initializers
List initializers = new ArrayList(10);
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.rse.core.modelInitializers"); //$NON-NLS-1$
IStatus status = Status.OK_STATUS;
for (int i = 0; i < elements.length; i++) {
IConfigurationElement element = elements[i];
String initializerName = element.getAttribute("class"); //$NON-NLS-1$
try {
IRSEModelInitializer initializer = (IRSEModelInitializer) element.createExecutableExtension("class"); //$NON-NLS-1$
initializers.add(initializer);
} catch (CoreException e) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_initializer_failed_to_load, initializerName);
logger.logError(message, e);
status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, message, e);
}
if (result.getSeverity() < status.getSeverity()) {
result = status;
}
}
// run initializers
monitor.beginTask(RSECoreMessages.InitRSEJob_initializing_rse, elements.length);
for (Iterator z = initializers.iterator(); z.hasNext() && !monitor.isCanceled();) {
IRSEModelInitializer initializer = (IRSEModelInitializer) z.next();
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 1);
String initializerName = initializer.getClass().getName();
try {
status = initializer.run(submonitor);
if (status.getSeverity() < IStatus.ERROR) {
try {
while (!initializer.isComplete()) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_waiting_for_initializer, initializerName);
logger.logInfo(message);
Thread.sleep(1000l); // wait 1 second
}
} catch (InterruptedException e) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_initializer_interrupted, initializerName);
logger.logWarning(message, e);
status = new Status(IStatus.WARNING, RSECorePlugin.PLUGIN_ID, message);
}
}
} catch (RuntimeException e) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_initializer_ended_in_error, initializerName);
logger.logError(message, e);
status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, message, e);
}
if (result.getSeverity() < status.getSeverity()) {
result = status;
}
submonitor.done();
}
if (monitor.isCanceled()) {
result = Status.CANCEL_STATUS;
} else {
monitor.done();
}
// finish up
isComplete = true;
notifyListeners(RSECorePlugin.INIT_ALL);
return result;
}
/**
* Waits until the job is completed.
* @return the status of the job upon its completion.
* @throws InterruptedException if the job is interrupted while waiting.
*/
public IStatus waitForCompletion() throws InterruptedException {
IStatus result = Status.OK_STATUS;
while (!isComplete(RSECorePlugin.INIT_ALL)) {
try {
if (getState() != Job.RUNNING) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_waiting_for_job, NAME);
logger.logInfo(message);
Thread.sleep(1000l);
} else {
String message = NLS.bind(RSECoreMessages.InitRSEJob_joining_job, NAME);
logger.logInfo(message);
join();
}
} catch (InterruptedException e) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_job_interrupted, NAME);
logger.logError(message, e);
throw e;
}
}
result = getResult();
return result;
}
/**
* @param phase the phase for which completion is requested.
* Phases are defined in {@link RSECorePlugin}.
* @return true if this phase has completed.
* @throws IllegalArgumentException if the phase is undefined.
* @see RSECorePlugin#INIT_ALL
* @see RSECorePlugin#INIT_MODEL
*/
public boolean isComplete(int phase) {
boolean result = false;
switch (phase) {
case RSECorePlugin.INIT_MODEL:
result = isModelComplete;
break;
case RSECorePlugin.INIT_ALL:
result = isComplete;
break;
default:
throw new IllegalArgumentException("undefined phase"); //$NON-NLS-1$
}
return result;
}
}

View file

@ -11,6 +11,7 @@
* Martin Oberhuber (Wind River) - [215820] Move SystemRegistry implementation to Core
* David McKnight (IBM) - [220309] [nls] Some GenericMessages and SubSystemResources should move from UI to Core
* David McKnight (IBM) - [220547] [api][breaking] SimpleSystemMessage needs to specify a message id and some messages should be shared
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
********************************************************************************/
package org.eclipse.rse.internal.core;
@ -54,7 +55,9 @@ public class RSECoreMessages extends NLS {
// Password Persistence Manager
public static String DefaultSystemType_Label;
// InitRSEJob
// Initialization
public static String RSELocalConnectionInitializer_localConnectionName;
public static String InitRSEJob_error_creating_mark;
public static String InitRSEJob_initializer_ended_in_error;
public static String InitRSEJob_initializer_failed_to_load;
public static String InitRSEJob_initializer_interrupted;

View file

@ -0,0 +1,334 @@
/********************************************************************************
* Copyright (c) 2008 IBM Corporation and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
********************************************************************************/
package org.eclipse.rse.internal.core;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.util.NLS;
import org.eclipse.rse.core.IRSEInitListener;
import org.eclipse.rse.core.IRSEModelInitializer;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.logging.Logger;
/**
* This is a job named "Initialize RSE". It is instantiated and run during
* RSE startup. It must not be run at any other time. The job restores the
* persistent form of the RSE model. Use the extension point
* org.eclipse.rse.core.modelInitializers to supplement the model once it is
* restored.
*/
public final class RSEInitJob extends Job {
/**
* The name of this job. This is API. Clients may use this name to find this job by name.
*/
public final static String NAME = "Initialize RSE"; //$NON-NLS-1$
private static RSEInitJob instance = new RSEInitJob();
private class Phase {
private volatile boolean isCanceled = false;
private volatile boolean isComplete = false;
private int phaseNumber = 0;
public Phase(int phaseNumber) {
this.phaseNumber = phaseNumber;
}
public synchronized void waitForCompletion() throws InterruptedException {
while (!isComplete && !isCanceled) {
wait();
}
if (isCanceled) {
throw new InterruptedException();
}
}
public synchronized void done() {
isComplete = true;
notifyAll();
notifyListeners(phaseNumber);
}
public synchronized void cancel() {
isCanceled = true;
notifyAll();
}
public boolean isComplete() {
return isComplete;
}
}
private class MyJobChangeListener implements IJobChangeListener {
public void aboutToRun(IJobChangeEvent event) {
}
public void awake(IJobChangeEvent event) {
}
public void done(IJobChangeEvent event) {
IStatus status = event.getJob().getResult();
if (status.getSeverity() == IStatus.CANCEL) {
modelPhase.cancel();
initializerPhase.cancel();
finalPhase.cancel();
} else {
finalPhase.done();
}
}
public void running(IJobChangeEvent event) {
}
public void scheduled(IJobChangeEvent event) {
}
public void sleeping(IJobChangeEvent event) {
}
}
private Phase finalPhase = new Phase(RSECorePlugin.INIT_ALL);
private Phase modelPhase = new Phase(RSECorePlugin.INIT_MODEL);
private Phase initializerPhase = new Phase(RSECorePlugin.INIT_INITIALIZER);
private List listeners = new ArrayList(10);
private Logger logger = RSECorePlugin.getDefault().getLogger();
private MyJobChangeListener myJobChangeListener = new MyJobChangeListener();
/**
* Returns the singleton instance of this job.
* @return the InitRSEJob instance for this workbench.
*/
public static RSEInitJob getInstance() {
return instance;
}
private RSEInitJob() {
super(NAME);
addJobChangeListener(myJobChangeListener);
}
/**
* Adds a new listener to the set of listeners to be notified when initialization phases complete.
* If the listener is added after the phase has completed it will not be invoked.
* If the listener is already in the set it will not be added again.
* Listeners may be notified in any order.
* @param listener the listener to be added
*/
public void addInitListener(IRSEInitListener listener) {
synchronized (listeners) {
listeners.add(listener);
}
}
/**
* Removes a listener to the set of listeners to be notified when phases complete.
* If the listener is not in the set this does nothing.
* @param listener the listener to be removed
*/
public void removeInitListener(IRSEInitListener listener) {
synchronized (listeners) {
listeners.remove(listener);
}
}
/**
* Notify all registered listeners of a phase completion
* @param phase the phase just completed.
*/
private void notifyListeners(int phase) {
IRSEInitListener[] myListeners = new IRSEInitListener[listeners.size()];
synchronized (listeners) {
listeners.toArray(myListeners);
}
for (int i = 0; i < myListeners.length; i++) {
IRSEInitListener listener = myListeners[i];
try {
listener.phaseComplete(phase);
} catch (RuntimeException e) {
logger.logError(RSECoreMessages.InitRSEJob_listener_ended_in_error, e);
}
}
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus run(IProgressMonitor monitor) {
IStatus result = Status.OK_STATUS;
// get and initialize the profile manager
RSECorePlugin.getTheSystemProfileManager();
modelPhase.done();
// instantiate and run initializers
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.rse.core.modelInitializers"); //$NON-NLS-1$
monitor.beginTask(RSECoreMessages.InitRSEJob_initializing_rse, elements.length);
for (int i = 0; i < elements.length && !monitor.isCanceled(); i++) {
IConfigurationElement element = elements[i];
IProgressMonitor submonitor = new SubProgressMonitor(monitor, 1);
String initializerType = element.getAttribute("type"); //$NON-NLS-1$
boolean isMarked = isMarked(element);
boolean isSessionType = initializerType == null || initializerType.equals("session"); //$NON-NLS-1$
boolean isWorkspaceType = initializerType != null && initializerType.equals("workspace"); //$NON-NLS-1$
if (isSessionType || (isWorkspaceType && !isMarked)) {
IStatus status = runInitializer(element, submonitor);
if (status.getSeverity() < IStatus.ERROR && isWorkspaceType) {
mark(element);
}
if (result.getSeverity() < status.getSeverity()) {
result = status;
}
}
submonitor.done();
}
initializerPhase.done();
// finish up - propogate cancel if necessary
if (monitor.isCanceled()) {
result = Status.CANCEL_STATUS;
} else {
monitor.done();
}
return result;
}
/**
* Returns a handle to a mark file based on the initializer class name.
* @param element the element that defines the initializer
* @return a handle to a file in the state location of this plugin
*/
private File getMarkFile(IConfigurationElement element) {
String initializerName = element.getAttribute("class"); //$NON-NLS-1$
String markName = initializerName + ".mark"; //$NON-NLS-1$
IPath stateLocation = RSECorePlugin.getDefault().getStateLocation();
IPath marksLocation = stateLocation.append("initializerMarks"); //$NON-NLS-1$
IPath markPath = marksLocation.append(markName);
File markFile = new File(markPath.toOSString());
return markFile;
}
/**
* @param element the element to test for marking
* @return true if the element is marked
*/
private boolean isMarked(IConfigurationElement element) {
File markFile = getMarkFile(element);
return markFile.exists();
}
/**
* @param element the element to mark
* @return a status indicating if the marking was successful
*/
private IStatus mark(IConfigurationElement element) {
IStatus status = Status.OK_STATUS;
File markFile = getMarkFile(element);
File markFolder = markFile.getParentFile();
try {
markFolder.mkdirs();
markFile.createNewFile();
} catch (IOException e) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_error_creating_mark, markFile.getPath());
status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, message, e);
logger.logError(message, e);
}
return status;
}
/**
* Instantiate and run an initializer
* @param element the configuration element from which to instantiate the initializer
* @param submonitor the monitor with which to run the initializer
* @return the status of this initializer
*/
private IStatus runInitializer(IConfigurationElement element, IProgressMonitor submonitor) {
IStatus status = Status.OK_STATUS;
String initializerName = element.getAttribute("class"); //$NON-NLS-1$
try {
IRSEModelInitializer initializer = (IRSEModelInitializer) element.createExecutableExtension("class"); //$NON-NLS-1$
try {
status = initializer.run(submonitor);
} catch (RuntimeException e) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_initializer_ended_in_error, initializerName);
logger.logError(message, e);
status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, message, e);
}
} catch (CoreException e) {
String message = NLS.bind(RSECoreMessages.InitRSEJob_initializer_failed_to_load, initializerName);
logger.logError(message, e);
status = new Status(IStatus.ERROR, RSECorePlugin.PLUGIN_ID, message, e);
}
return status;
}
/**
* Waits until a job is completed.
* @return the status of the job upon its completion.
* @throws InterruptedException if the job is interrupted while waiting.
*/
public IStatus waitForCompletion() throws InterruptedException {
waitForCompletion(RSECorePlugin.INIT_ALL);
return getResult();
}
/**
* Wait for the completion of a particular phase
* @param phase the phase to wait for
* @see RSECorePlugin#INIT_ALL
* @see RSECorePlugin#INIT_MODEL
* @see RSECorePlugin#INIT_INITIALIZER
*/
public void waitForCompletion(int phase) throws InterruptedException {
switch (phase) {
case RSECorePlugin.INIT_MODEL:
modelPhase.waitForCompletion();
break;
case RSECorePlugin.INIT_INITIALIZER:
initializerPhase.waitForCompletion();
break;
case RSECorePlugin.INIT_ALL:
finalPhase.waitForCompletion();
break;
default:
throw new IllegalArgumentException("undefined phase"); //$NON-NLS-1$
}
}
/**
* @param phase the phase for which completion is requested.
* Phases are defined in {@link RSECorePlugin}.
* @return true if this phase has completed.
* @throws IllegalArgumentException if the phase is undefined.
* @see RSECorePlugin#INIT_ALL
* @see RSECorePlugin#INIT_MODEL
* @see RSECorePlugin#INIT_INITIALIZER
*/
public boolean isComplete(int phase) {
boolean result = false;
switch (phase) {
case RSECorePlugin.INIT_MODEL:
result = modelPhase.isComplete();
break;
case RSECorePlugin.INIT_INITIALIZER:
result = initializerPhase.isComplete();
break;
case RSECorePlugin.INIT_ALL:
result = finalPhase.isComplete();
break;
default:
throw new IllegalArgumentException("undefined phase"); //$NON-NLS-1$
}
return result;
}
}

View file

@ -0,0 +1,40 @@
package org.eclipse.rse.internal.core;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.rse.core.IRSEModelInitializer;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.RSEPreferencesManager;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemProfile;
import org.eclipse.rse.core.model.ISystemProfileManager;
import org.eclipse.rse.core.model.ISystemRegistry;
public class RSELocalConnectionInitializer implements IRSEModelInitializer {
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSEModelInitializer#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
// create a local host object if one is desired and one has not yet been created in this workspace.
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
ISystemProfileManager profileManager = RSECorePlugin.getTheSystemProfileManager();
ISystemProfile profile = profileManager.getDefaultPrivateSystemProfile();
String localConnectionName = RSECoreMessages.RSELocalConnectionInitializer_localConnectionName;
IHost localHost = registry.getHost(profile, localConnectionName);
if (localHost == null && RSEPreferencesManager.getCreateLocalConnection()) {
// create the connection only if the local system type is enabled
IRSESystemType systemType = RSECorePlugin.getTheCoreRegistry().getSystemTypeById(IRSESystemType.SYSTEMTYPE_LOCAL_ID);
if (systemType != null && systemType.isEnabled()) {
String userName = System.getProperty("user.name"); //$NON-NLS-1$
registry.createLocalHost(profile, localConnectionName, userName);
}
}
monitor.done();
return status;
}
}

View file

@ -25,6 +25,8 @@ public class RSEPreferenceInitializer extends AbstractPreferenceInitializer {
Preferences prefs = RSECorePlugin.getDefault().getPluginPreferences();
// The ID of the default persistence provider
prefs.setDefault(IRSEPreferenceNames.DEFAULT_PERSISTENCE_PROVIDER, "org.eclipse.rse.persistence.MetadataPropertyFileProvider"); //$NON-NLS-1$
// whether or not to create a local connection in a fresh workspace
prefs.setDefault(IRSEPreferenceNames.CREATE_LOCAL_CONNECTION, true);
}
}

View file

@ -49,7 +49,9 @@ SerializingProvider_UnexpectedException=Unexpected Exception
# Password Persistence Manager
DefaultSystemType_Label=Default
# InitRSEJob
# Initialization
RSELocalConnectionInitializer_localConnectionName=Local
InitRSEJob_error_creating_mark=IOException creating mark file {0}.
InitRSEJob_initializer_ended_in_error=Initializer {0} ended in error.
InitRSEJob_initializer_failed_to_load=Failed to load initializer {0}.
InitRSEJob_initializer_interrupted=Initializer {0} interrupted.

View file

@ -14,6 +14,7 @@
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
* David Dykstal (IBM) - [188863] created out of SaveRSEDOMJob
* David McKnight (IBM) - [216252] MessageFormat.format -> NLS.bind
* David Dykstal (IBM) - [197167] adding notification and waiting for RSE model
********************************************************************************/
package org.eclipse.rse.internal.persistence;
@ -35,6 +36,8 @@ import org.eclipse.rse.persistence.dom.RSEDOM;
* save a DOM to the workspace metadata area. A DOM corresponds to a profile.
*/
public class PFMetatdataJob extends Job {
private static Object jobFamily = RSECorePlugin.getThePersistenceManager();
private RSEDOM _dom;
private IRSEPersistenceProvider _provider;
@ -67,7 +70,7 @@ public class PFMetatdataJob extends Job {
}
public boolean belongsTo(Object family) {
Object[] families = new Object[] {RSECorePlugin.getThePersistenceManager()};
Object[] families = new Object[] {jobFamily};
for (int i = 0; i < families.length; i++) {
Object object = families[i];
if (family == object) return true;

View file

@ -0,0 +1,47 @@
/*********************************************************************************
* Copyright (c) 2008 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* David Dykstal (IBM) - [197167] initial contribution.
*********************************************************************************/
package org.eclipse.rse.internal.ui;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.SystemResourceManager;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemBasePlugin;
public class RSEUIInitJob extends Job {
public RSEUIInitJob() {
super("RSE_UI_INIT"); //$NON-NLS-1$
}
public IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
try {
RSECorePlugin.waitForInitCompletion();
} catch (InterruptedException e) {
String message = "UI Initialization interrupted"; //$NON-NLS-1$
status = new Status(IStatus.INFO, RSEUIPlugin.PLUGIN_ID, message);
SystemBasePlugin.logInfo(message);
}
// listen for project change events if a project is being used
IProject remoteSystemsProject = SystemResourceManager.getRemoteSystemsProject(false);
if (remoteSystemsProject.exists()) {
SystemResourceListener listener = SystemResourceListener.getListener(remoteSystemsProject);
SystemResourceManager.startResourceEventListening(listener);
}
return status;
}
}

View file

@ -1,71 +0,0 @@
/*********************************************************************************
* Copyright (c) 2008 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* David Dykstal (IBM) - [197167] initial contribution.
*********************************************************************************/
package org.eclipse.rse.internal.ui;
import java.io.File;
import java.io.IOException;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.IRSEModelInitializer;
import org.eclipse.rse.core.SystemResourceManager;
import org.eclipse.rse.core.model.ISystemProfile;
import org.eclipse.rse.core.model.ISystemProfileManager;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.eclipse.rse.ui.RSEUIPlugin;
import org.eclipse.rse.ui.SystemPreferencesManager;
public class RSEUIPluginModelInitializer implements IRSEModelInitializer {
private boolean isComplete = false;
public IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
// create a local host object if one is desired and one has not yet been created in this workspace.
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
IPath statePath = RSECorePlugin.getDefault().getStateLocation();
IPath markPath = statePath.append("localHostCreated.mark"); //$NON-NLS-1$
File markFile = new File(markPath.toOSString());
if (!markFile.exists() && SystemPreferencesManager.getShowLocalConnection()) {
// create the connection only if the local system type is enabled
IRSESystemType systemType = RSECorePlugin.getTheCoreRegistry().getSystemTypeById(IRSESystemType.SYSTEMTYPE_LOCAL_ID);
if (systemType != null && systemType.isEnabled()) {
ISystemProfileManager profileManager = RSECorePlugin.getTheSystemProfileManager();
ISystemProfile profile = profileManager.getDefaultPrivateSystemProfile();
String userName = System.getProperty("user.name"); //$NON-NLS-1$
registry.createLocalHost(profile, SystemResources.TERM_LOCAL, userName);
try {
markFile.createNewFile();
} catch (IOException e) {
status = new Status(IStatus.ERROR, RSEUIPlugin.PLUGIN_ID, "IOException creating mark file during local host creation", e); //$NON-NLS-1$
}
}
}
monitor.done();
// listen for project change events if a project is being used
IProject remoteSystemsProject = SystemResourceManager.getRemoteSystemsProject(false);
if (remoteSystemsProject.exists()) {
SystemResourceListener listener = SystemResourceListener.getListener(remoteSystemsProject);
SystemResourceManager.startResourceEventListening(listener);
}
isComplete = true;
return status;
}
public boolean isComplete() {
return isComplete;
}
}

View file

@ -40,6 +40,7 @@ import java.util.Vector;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.SystemResourceManager;
import org.eclipse.rse.core.events.ISystemResourceChangeEvents;
@ -51,6 +52,7 @@ import org.eclipse.rse.core.subsystems.ISubSystemConfigurationProxy;
import org.eclipse.rse.internal.core.model.SystemProfileManager;
import org.eclipse.rse.internal.core.model.SystemRegistry;
import org.eclipse.rse.internal.ui.RSESystemTypeAdapterFactory;
import org.eclipse.rse.internal.ui.RSEUIInitJob;
import org.eclipse.rse.internal.ui.SystemResources;
import org.eclipse.rse.internal.ui.actions.SystemShowPreferencesPageAction;
import org.eclipse.rse.internal.ui.subsystems.SubSystemConfigurationProxyAdapterFactory;
@ -407,6 +409,8 @@ public class RSEUIPlugin extends SystemBasePlugin
svraf = new SystemTeamViewResourceAdapterFactory();
svraf.registerWithManager(manager);
Job initJob = new RSEUIInitJob();
initJob.schedule();
}
/**

View file

@ -490,11 +490,5 @@ Martin Oberhuber (Wind River) - [185552] Remove remoteSystemsViewPreferencesActi
</includes>
</viewerContentBinding>
</extension>
<extension
point="org.eclipse.rse.core.modelInitializers">
<modelInitializer
class="org.eclipse.rse.internal.ui.RSEUIPluginModelInitializer">
</modelInitializer>
</extension>
</plugin>

View file

@ -16,12 +16,11 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.rse.core.IRSEModelInitializer;
/**
* An ill-behaved initializer that returns a lousy status
* An initializer that returns a warning status
*/
public class BadInitializer implements IRSEModelInitializer {
private static BadInitializer instance = null;
private boolean isComplete = false;
private boolean wasRun = false;
public static BadInitializer getInstance() {
@ -32,13 +31,6 @@ public class BadInitializer implements IRSEModelInitializer {
instance = this;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSEModelInitializer#isComplete()
*/
public boolean isComplete() {
return isComplete;
}
public boolean wasRun() {
return wasRun;
}
@ -47,9 +39,8 @@ public class BadInitializer implements IRSEModelInitializer {
* @see org.eclipse.rse.core.IRSEModelInitializer#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus run(IProgressMonitor monitor) {
IStatus result = new Status(IStatus.WARNING, "org.eclipse.rse.tests", "bwaahahaha");
wasRun = true;
IStatus result = new Status(IStatus.ERROR, "org.eclipse.rse.tests", "bwaahahaha");
// oh darn, forgot to set the "isComplete"!
return result;
}

View file

@ -21,7 +21,6 @@ import org.eclipse.rse.core.IRSEModelInitializer;
public class GoodInitializer implements IRSEModelInitializer {
private static GoodInitializer instance = null;
private boolean isComplete = false;
private boolean wasRun = false;
public static GoodInitializer getInstance() {
@ -32,13 +31,6 @@ public class GoodInitializer implements IRSEModelInitializer {
instance = this;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSEModelInitializer#isComplete()
*/
public boolean isComplete() {
return isComplete;
}
public boolean wasRun() {
return wasRun;
}
@ -48,7 +40,6 @@ public class GoodInitializer implements IRSEModelInitializer {
*/
public IStatus run(IProgressMonitor monitor) {
wasRun = true;
isComplete = true;
return Status.OK_STATUS;
}

View file

@ -13,6 +13,7 @@ package org.eclipse.rse.tests.initialization;
import junit.framework.TestCase;
import org.eclipse.rse.core.IRSEInitListener;
import org.eclipse.rse.core.RSECorePlugin;
/**
@ -29,6 +30,11 @@ public class InitializationTest extends TestCase {
*/
protected void setUp() throws Exception {
super.setUp();
RSECorePlugin.addInitListener(new IRSEInitListener() {
public void phaseComplete(int phase) {
System.out.println("I see phase " + phase);
}
});
}
/* (non-Javadoc)
@ -44,16 +50,19 @@ public class InitializationTest extends TestCase {
RSECorePlugin.waitForInitCompletion();
} catch (InterruptedException e) {
fail("interrupted");
} catch (RuntimeException e) {
throw e;
}
System.out.println("Init job should be done");
assertTrue("not indicating complete", RSECorePlugin.isInitComplete(RSECorePlugin.INIT_ALL));
GoodInitializer goodInitializer = GoodInitializer.getInstance();
BadInitializer badInitializer = BadInitializer.getInstance();
UglyInitializer uglyInitializer = UglyInitializer.getInstance();
ListenerInitializer listenerInitializer = ListenerInitializer.getInstance();
assertTrue("good initializer not run", goodInitializer.wasRun() && goodInitializer.isComplete());
assertTrue("bad initializer not run", badInitializer.wasRun() && !badInitializer.isComplete());
assertTrue("ugly initializer not run", uglyInitializer.wasRun() && uglyInitializer.isComplete());
assertTrue("listener initializer not run", listenerInitializer.wasRun() && listenerInitializer.isComplete());
assertTrue("good initializer not run", goodInitializer.wasRun());
assertTrue("bad initializer not run", badInitializer.wasRun());
assertTrue("ugly initializer not run", uglyInitializer.wasRun());
assertTrue("listener initializer not run", listenerInitializer.wasRun());
InitListener listener = listenerInitializer.getListener();
assertFalse("listener saw phase INIT_MODEL", listener.sawPhase(RSECorePlugin.INIT_MODEL)); // shouldn't see this since it occurs before the listener is added
assertTrue("listener missed phase INIT_ALL", listener.sawPhase(RSECorePlugin.INIT_ALL));

View file

@ -17,12 +17,11 @@ import org.eclipse.rse.core.IRSEModelInitializer;
import org.eclipse.rse.core.RSECorePlugin;
/**
* A plain vanilla initializer that does its thing without exceptions.
* An initializer that adds a listener to the initialization job.
*/
public class ListenerInitializer implements IRSEModelInitializer {
private static ListenerInitializer instance = null;
private boolean isComplete = false;
private boolean wasRun = false;
private InitListener listener = new InitListener();
@ -34,13 +33,6 @@ public class ListenerInitializer implements IRSEModelInitializer {
instance = this;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSEModelInitializer#isComplete()
*/
public boolean isComplete() {
return isComplete;
}
public boolean wasRun() {
return wasRun;
}
@ -55,7 +47,6 @@ public class ListenerInitializer implements IRSEModelInitializer {
public IStatus run(IProgressMonitor monitor) {
RSECorePlugin.addInitListener(listener);
wasRun = true;
isComplete = true;
return Status.OK_STATUS;
}

View file

@ -22,8 +22,7 @@ import org.eclipse.rse.core.IRSEModelInitializer;
public class UglyInitializer implements IRSEModelInitializer {
private static UglyInitializer instance = null;
boolean isComplete = false;
boolean wasRun = false;
volatile boolean wasRun = false;
public static UglyInitializer getInstance() {
return instance;
@ -33,13 +32,6 @@ public class UglyInitializer implements IRSEModelInitializer {
instance = this;
}
/* (non-Javadoc)
* @see org.eclipse.rse.core.IRSEModelInitializer#isComplete()
*/
public boolean isComplete() {
return isComplete;
}
public boolean wasRun() {
return wasRun;
}
@ -48,19 +40,29 @@ public class UglyInitializer implements IRSEModelInitializer {
* @see org.eclipse.rse.core.IRSEModelInitializer#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public IStatus run(IProgressMonitor monitor) {
wasRun = true;
Job job = new Job("test initializer job") {
Job job1 = new Job("test initializer job 1") {
protected IStatus run(IProgressMonitor monitor) {
try {
Thread.sleep(5000l); // sleep for a bit
Thread.sleep(3000); // sleep for a bit
} catch (InterruptedException e) {
// eat the exception
}
isComplete = true;
return Status.OK_STATUS;
}
};
job.schedule(1000l);
Job job2 = new Job("test initializer job 2") {
protected IStatus run(IProgressMonitor monitor) {
try {
Thread.sleep(3000); // sleep for a bit
} catch (InterruptedException e) {
// eat the exception
}
return Status.OK_STATUS;
}
};
job1.schedule(1000);
job2.schedule(2000);
wasRun = true;
return Status.OK_STATUS;
}