Omaha #4532 Thin client sync localization now goes through normal PathManager.

Former-commit-id: fb033fdb0c841af5aae3238310ae7315b34e744d
This commit is contained in:
Ben Steffensmeier 2015-05-29 17:27:49 -05:00
parent ee34457d03
commit 4658c92027
3 changed files with 62 additions and 10 deletions

View file

@ -37,10 +37,11 @@ import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.viz.core.localization.CAVELocalizationAdapter;
import com.raytheon.uf.viz.thinclient.preferences.ThinClientPreferenceConstants;
/**
* TODO Add Description
* A {@link BooleanFieldEditor} which adds a button that can be used to
* synchronize localization files with the server.
*
* <pre>
*
@ -48,7 +49,8 @@ import com.raytheon.uf.viz.core.localization.CAVELocalizationAdapter;
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Nov 22, 2011 bsteffen Initial creation
* Nov 22, 2011 bsteffen Initial creation
* May 29, 2015 4532 bsteffen Notify the preference store when sync is running.
*
* </pre>
*
@ -75,8 +77,9 @@ public class SyncLocalizationEditor extends BooleanFieldEditor {
@Override
protected IStatus run(IProgressMonitor monitor) {
IPathManager pathManager = PathManagerFactory
.getPathManager(new CAVELocalizationAdapter());
getPreferenceStore().firePropertyChangeEvent(ThinClientPreferenceConstants.P_SYNC_REMOTE_LOCALIZATION,
false, true);
IPathManager pathManager = PathManagerFactory.getPathManager();
LocalizationType[] types = { LocalizationType.CAVE_CONFIG,
LocalizationType.CAVE_STATIC,
LocalizationType.COMMON_STATIC };
@ -105,6 +108,8 @@ public class SyncLocalizationEditor extends BooleanFieldEditor {
System.out.println("Time to download " + type + ": "
+ (endTime - startTime) + "ms");
}
getPreferenceStore().firePropertyChangeEvent(ThinClientPreferenceConstants.P_SYNC_REMOTE_LOCALIZATION,
true, false);
monitor.done();
return Status.OK_STATUS;
}

View file

@ -25,6 +25,7 @@ import java.util.Date;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
@ -53,6 +54,7 @@ import com.raytheon.uf.viz.thinclient.preferences.ThinClientPreferenceConstants;
* Aug 9, 2011 njensen Initial creation
* Aug 13, 2013 2033 mschenke Changed to search all plugins when
* CAVE_STATIC BASE context searched
* May 29, 2015 4532 bsteffen Always use super when sync job is running.
*
* </pre>
*
@ -63,6 +65,12 @@ import com.raytheon.uf.viz.thinclient.preferences.ThinClientPreferenceConstants;
public class ThinClientLocalizationAdapter extends CAVELocalizationAdapter
implements IPropertyChangeListener {
/**
* Whenever there is a sync job running, always call super to allow it to go
* to the server.
*/
private final AtomicInteger syncJobsRunning = new AtomicInteger(0);
private boolean useRemoteFiles = true;
public ThinClientLocalizationAdapter() {
@ -83,6 +91,10 @@ public class ThinClientLocalizationAdapter extends CAVELocalizationAdapter
@Override
public void retrieve(LocalizationFile file)
throws LocalizationOpFailedException {
if (syncJobsRunning.get() > 0) {
super.retrieve(file);
return;
}
try {
File localFile = file.getFile(false);
if (localFile.exists() == false || localFile.length() == 0) {
@ -91,8 +103,15 @@ public class ThinClientLocalizationAdapter extends CAVELocalizationAdapter
} catch (LocalizationOpFailedException e) {
throw e;
} catch (LocalizationException e) {
// Ignore exception
e.printStackTrace();
/*
* At the time of this writing, nothing will actually throw any
* LocalizationException other than LocalizationOpFailedException.
* However since LocalizationFile.getFile(boolean) has a method
* signature indicating it could throw any LocalizationException
* this code should be able to handle any LocalizationException in
* case the implementation of getFile changes in the future.
*/
throw new LocalizationOpFailedException(e);
}
}
@ -108,7 +127,7 @@ public class ThinClientLocalizationAdapter extends CAVELocalizationAdapter
public ListResponse[] listDirectory(LocalizationContext[] contexts,
String path, boolean recursive, boolean filesOnly)
throws LocalizationOpFailedException {
if (useRemoteFiles) {
if (shouldUseRemoteFiles()) {
return super.listDirectory(contexts, path, recursive, filesOnly);
} else {
@ -164,7 +183,7 @@ public class ThinClientLocalizationAdapter extends CAVELocalizationAdapter
public ListResponse[] getLocalizationMetadata(
LocalizationContext[] context, String fileName)
throws LocalizationOpFailedException {
if (useRemoteFiles) {
if (shouldUseRemoteFiles()) {
return super.getLocalizationMetadata(context, fileName);
} else {
List<ListResponse> responses = new ArrayList<ListResponse>(
@ -193,19 +212,30 @@ public class ThinClientLocalizationAdapter extends CAVELocalizationAdapter
@Override
public boolean exists(LocalizationFile file) {
if (useRemoteFiles) {
if (shouldUseRemoteFiles()) {
return super.exists(file);
} else {
return file.getFile().exists();
}
}
private boolean shouldUseRemoteFiles() {
return useRemoteFiles || syncJobsRunning.get() > 0;
}
@Override
public void propertyChange(PropertyChangeEvent event) {
if (ThinClientPreferenceConstants.P_DISABLE_REMOTE_LOCALIZATION
.equals(event.getProperty())) {
useRemoteFiles = !Boolean.valueOf(String.valueOf(event
.getNewValue()));
} else if (ThinClientPreferenceConstants.P_SYNC_REMOTE_LOCALIZATION.equals(event.getProperty())) {
boolean sync = Boolean.valueOf(String.valueOf(event.getNewValue()));
if (sync) {
syncJobsRunning.incrementAndGet();
} else {
syncJobsRunning.decrementAndGet();
}
}
}

View file

@ -19,6 +19,8 @@
**/
package com.raytheon.uf.viz.thinclient.preferences;
import org.eclipse.jface.preference.IPreferenceStore;
/**
* Preference constants for the thin client mode
*
@ -32,6 +34,8 @@ package com.raytheon.uf.viz.thinclient.preferences;
* Jan 14, 2013 1469 bkowal The hdf5 data directory is no longer a preference constant.
* Feb 04, 2014 2704 njensen Consolidate services and pypies proxy addresses
* Jun 24, 2014 3236 njensen Added proxy address options
* May 29, 2015 4532 bsteffen Add sync localization option.
*
*
* </pre>
*
@ -61,6 +65,19 @@ public class ThinClientPreferenceConstants {
public static String P_DISABLE_REMOTE_LOCALIZATION = "disableRemoteLocalization";
/**
* This preference is not stored but is used to send notification through
* the preference store that the {@link #P_CACHE_LOCALIZATION} and
* {@link #P_DISABLE_REMOTE_LOCALIZATION} should be temporarily ignored so
* that the localization files can be synchronized with the server. Before
* performing synchronization, an event should be fired using
* {@link IPreferenceStore#firePropertyChangeEvent(String, Object, Object)}
* with the preference name as {@link #P_SYNC_REMOTE_LOCALIZATION} and a
* newValue of true. When synchronization has completed another event should
* be fired with a newValue of false.
*/
public static String P_SYNC_REMOTE_LOCALIZATION = "syncRemoteFiles";
public static String P_DISABLE_MENU_TIMES = "disableMenuTimes";
public static String P_DISABLE_JMS = "disableJms";