mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
[177332][api][breaking] added autostart attribute to persistence providers & minor changes to IRSEPersistenceManager API
This commit is contained in:
parent
891420a8af
commit
7ef8f1b99f
4 changed files with 64 additions and 22 deletions
|
@ -19,10 +19,12 @@
|
|||
<extension
|
||||
point="org.eclipse.rse.core.persistenceProviders">
|
||||
<persistenceProvider
|
||||
autostart="false"
|
||||
class="org.eclipse.rse.internal.persistence.SerializingProvider"
|
||||
id="org.eclipse.rse.persistence.SerializingProvider"
|
||||
name="Serializing Persistence Provider"/>
|
||||
<persistenceProvider
|
||||
autostart="true"
|
||||
class="org.eclipse.rse.internal.persistence.PropertyFileProvider"
|
||||
id="org.eclipse.rse.persistence.PropertyFileProvider"
|
||||
name="Property File Persistence Provider"/>
|
||||
|
|
|
@ -65,6 +65,13 @@
|
|||
</appInfo>
|
||||
</annotation>
|
||||
</attribute>
|
||||
<attribute name="autostart" type="boolean" use="default" value="false">
|
||||
<annotation>
|
||||
<documentation>
|
||||
The autostart attribute determines if the persistence provider will be loaded and asked to restore the profiles known to it at the time RSE starts.
|
||||
</documentation>
|
||||
</annotation>
|
||||
</attribute>
|
||||
</complexType>
|
||||
</element>
|
||||
|
||||
|
@ -81,7 +88,8 @@
|
|||
<persistenceProvider
|
||||
id="org.eclipse.rse.persistence.DefaultRSEpersistenceProvider"
|
||||
name="Default persistence Provider"
|
||||
class="org.eclipse.rse.persistence.DefaultRSEpersistenceProvider">
|
||||
class="org.eclipse.rse.persistence.DefaultRSEpersistenceProvider"
|
||||
autostart="true">
|
||||
</persistenceProvider>
|
||||
</extension>
|
||||
</pre>
|
||||
|
@ -112,13 +120,14 @@
|
|||
<meta.section type="copyright"/>
|
||||
</appInfo>
|
||||
<documentation>
|
||||
Copyright (c) 2006 IBM Corporation. All Rights Reserved.
|
||||
Copyright (c) 2006, 2007 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:
|
||||
IBM Corporation - initial API and implementation
|
||||
David Dykstal (IBM) - added autostart attribute
|
||||
</documentation>
|
||||
</annotation>
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.rse.internal.persistence;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -62,12 +63,17 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
|
|||
private IConfigurationElement configurationElement = null;
|
||||
private IRSEPersistenceProvider provider = null;
|
||||
private boolean restored = false;
|
||||
synchronized boolean getRestored() {
|
||||
synchronized boolean isRestored() {
|
||||
return restored;
|
||||
}
|
||||
synchronized void setRestored(boolean restored) {
|
||||
this.restored = restored;
|
||||
}
|
||||
boolean isAutostart() {
|
||||
boolean isAutostart = (configurationElement != null && ("true".equals(configurationElement.getAttribute("autostart")))); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
boolean isDefault = (providerId.equals(getDefaultPersistenceProviderId()));
|
||||
return isAutostart || isDefault;
|
||||
}
|
||||
}
|
||||
|
||||
private Map knownProviders = new HashMap(10);
|
||||
|
@ -198,16 +204,25 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
|
|||
* @see org.eclipse.rse.persistence.IRSEPersistenceManager#restoreProfiles()
|
||||
*/
|
||||
public ISystemProfile[] restoreProfiles(long timeout) {
|
||||
List profiles = new ArrayList(10);
|
||||
String[] ids = getPersistenceProviderIds();
|
||||
List selectedRecords = new ArrayList(10);
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
String id = ids[i];
|
||||
IRSEPersistenceProvider provider = getPersistenceProvider(id);
|
||||
if (provider != null) {
|
||||
ISystemProfile[] providerProfiles = restoreProfiles(provider, timeout);
|
||||
profiles.addAll(Arrays.asList(providerProfiles));
|
||||
ProviderRecord pr = getProviderRecord(id);
|
||||
if (pr.isAutostart()) {
|
||||
IRSEPersistenceProvider provider = getPersistenceProvider(id);
|
||||
if (provider != null) {
|
||||
pr.setRestored(false);
|
||||
selectedRecords.add(pr);
|
||||
}
|
||||
}
|
||||
}
|
||||
List profiles = new ArrayList(10);
|
||||
for (Iterator z = selectedRecords.iterator(); z.hasNext();) {
|
||||
ProviderRecord pr = (ProviderRecord) z.next();
|
||||
ISystemProfile[] providerProfiles = restoreProfiles(pr.provider, timeout);
|
||||
profiles.addAll(Arrays.asList(providerProfiles));
|
||||
}
|
||||
ISystemProfile[] result = new ISystemProfile[profiles.size()];
|
||||
profiles.toArray(result);
|
||||
return result;
|
||||
|
@ -218,7 +233,7 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
|
|||
*/
|
||||
public ISystemProfile[] restoreProfiles(IRSEPersistenceProvider provider, long timeout) {
|
||||
ProviderRecord pr = getProviderRecord(provider);
|
||||
pr.setRestored(false);
|
||||
pr.setRestored(false); // may already be false or true
|
||||
List profiles = loadProfiles(provider, timeout);
|
||||
pr.setRestored(true);
|
||||
ISystemProfile[] result = new ISystemProfile[profiles.size()];
|
||||
|
@ -229,10 +244,15 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.rse.persistence.IRSEPersistenceManager#isRestoreComplete(java.lang.String)
|
||||
*/
|
||||
public boolean isRestoreComplete(String providerId) {
|
||||
ProviderRecord providerRecord = getProviderRecord(providerId);
|
||||
boolean result = providerRecord.getRestored();
|
||||
return result;
|
||||
public boolean isRestoreComplete() {
|
||||
boolean isComplete = true;
|
||||
String[] ids = getPersistenceProviderIds();
|
||||
for (int i = 0; i < ids.length && isComplete; i++) {
|
||||
String id = ids[i];
|
||||
ProviderRecord pr = getProviderRecord(id);
|
||||
isComplete = pr.isAutostart() && pr.isRestored();
|
||||
}
|
||||
return isComplete;
|
||||
}
|
||||
|
||||
private ProviderRecord getProviderRecord(String providerId) {
|
||||
|
@ -277,6 +297,7 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
|
|||
if (candidateId != null) {
|
||||
ProviderRecord pr = getProviderRecord(candidateId);
|
||||
pr.configurationElement = configurationElement;
|
||||
pr.providerId = candidateId;
|
||||
} else {
|
||||
logger.logError("Missing id attribute in persistenceProvider element", null); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -296,11 +317,22 @@ public class RSEPersistenceManager implements IRSEPersistenceManager {
|
|||
* @return the default IRSEPersistenceProvider for this installation.
|
||||
*/
|
||||
private IRSEPersistenceProvider getDefaultPersistenceProvider() {
|
||||
Preferences preferences = RSECorePlugin.getDefault().getPluginPreferences();
|
||||
String providerId = preferences.getString(IRSEPreferenceNames.DEFAULT_PERSISTENCE_PROVIDER);
|
||||
String providerId = getDefaultPersistenceProviderId();
|
||||
IRSEPersistenceProvider provider = getPersistenceProvider(providerId);
|
||||
return provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default persistence provider id from the preferences.
|
||||
* This persistence provider identifier is specified in the org.eclipse.rse.core/DEFAULT_PERSISTENCE_PROVIDER
|
||||
* preference and can be specified a product's plugin_customization.ini file.
|
||||
* @return
|
||||
*/
|
||||
private String getDefaultPersistenceProviderId() {
|
||||
Preferences preferences = RSECorePlugin.getDefault().getPluginPreferences();
|
||||
String providerId = preferences.getString(IRSEPreferenceNames.DEFAULT_PERSISTENCE_PROVIDER);
|
||||
return providerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the profiles for a given persistence provider.
|
||||
|
|
|
@ -43,7 +43,7 @@ public interface IRSEPersistenceManager {
|
|||
public ISystemProfile[] commitProfiles(long timeout);
|
||||
|
||||
/**
|
||||
* Restore all profiles.
|
||||
* Restore all profiles known to autostart persistence providers.
|
||||
* @param timeout the maximum number of milliseconds to wait for the manager to become idle for each profile.
|
||||
* @return an array of restored profiles.
|
||||
*/
|
||||
|
@ -106,14 +106,13 @@ public interface IRSEPersistenceManager {
|
|||
public boolean isBusy();
|
||||
|
||||
/**
|
||||
* Indicate if all profiles for a particular persistence provider have been restored.
|
||||
* Profiles are typically restored when RSE is activated and when profiles
|
||||
* are reloaded by the user. This will not load the persistence provider. If the persistence
|
||||
* provider has not yet been loaded it will return false. This can be used from a different thread
|
||||
* Indicate if all profiles for all autostart persistence provider have been restored.
|
||||
* These profiles are restored when RSE is activated and when profiles
|
||||
* are reloaded by the user.
|
||||
* This can be used from a different thread
|
||||
* than the one that requested the restore.
|
||||
* @param providerId the persistence providerId
|
||||
* @return true if the profiles have been fully restored
|
||||
*/
|
||||
public boolean isRestoreComplete(String providerId);
|
||||
public boolean isRestoreComplete();
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue