mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-18 21:55:45 +02:00
[368454] provide thread safety for cachedRemoteFiles hashmap
This commit is contained in:
parent
49423f4665
commit
065065194f
2 changed files with 53 additions and 33 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2010 IBM Corporation and others.
|
* Copyright (c) 2006, 2011 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -46,6 +46,7 @@
|
||||||
* David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService()
|
* David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService()
|
||||||
* David McKnight (IBM) - [244041] [files] Renaming a file looses Encoding property
|
* David McKnight (IBM) - [244041] [files] Renaming a file looses Encoding property
|
||||||
* David McKnight (IBM) - [320713] [dstore] xml file transfer error on zOS
|
* David McKnight (IBM) - [320713] [dstore] xml file transfer error on zOS
|
||||||
|
* David McKnight (IBM) - [368454] provide thread safety for cachedRemoteFiles hashmap
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.subsystems.files.core.servicesubsystem;
|
package org.eclipse.rse.subsystems.files.core.servicesubsystem;
|
||||||
|
@ -1154,7 +1155,9 @@ public class FileServiceSubSystem extends RemoteFileSubSystem implements IFileSe
|
||||||
IHost host = getHost();
|
IHost host = getHost();
|
||||||
IFileServiceSubSystemConfiguration config = (IFileServiceSubSystemConfiguration) newConfig;
|
IFileServiceSubSystemConfiguration config = (IFileServiceSubSystemConfiguration) newConfig;
|
||||||
// file subsystem specific bits
|
// file subsystem specific bits
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
_cachedRemoteFiles.clear();
|
_cachedRemoteFiles.clear();
|
||||||
|
}
|
||||||
_languageUtilityFactory = null;
|
_languageUtilityFactory = null;
|
||||||
setFileService(config.getFileService(host));
|
setFileService(config.getFileService(host));
|
||||||
setHostFileToRemoteFileAdapter(config.getHostFileAdapter());
|
setHostFileToRemoteFileAdapter(config.getHostFileAdapter());
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2002, 2009 IBM Corporation and others.
|
* Copyright (c) 2002, 2011 IBM Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
* Martin Oberhuber (Wind River) - [226574][api] Add ISubSystemConfiguration#supportsEncoding()
|
* Martin Oberhuber (Wind River) - [226574][api] Add ISubSystemConfiguration#supportsEncoding()
|
||||||
* David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE
|
* David McKnight (IBM) - [225747] [dstore] Trying to connect to an "Offline" system throws an NPE
|
||||||
* David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService()
|
* David McKnight (IBM) - [272882] [api] Handle exceptions in IService.initService()
|
||||||
|
* David McKnight (IBM) - [368454] provide thread safety for cachedRemoteFiles hashmap
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.subsystems.files.core.subsystems;
|
package org.eclipse.rse.subsystems.files.core.subsystems;
|
||||||
|
@ -1271,22 +1272,27 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
||||||
*/
|
*/
|
||||||
public void cacheRemoteFile(IRemoteFile file, String path)
|
public void cacheRemoteFile(IRemoteFile file, String path)
|
||||||
{
|
{
|
||||||
|
boolean containsKey = false;
|
||||||
if (_cachedRemoteFiles.containsKey(path))
|
synchronized (_cachedRemoteFiles){
|
||||||
{
|
containsKey = _cachedRemoteFiles.containsKey(path);
|
||||||
IRemoteFile oldFile = (IRemoteFile)_cachedRemoteFiles.remove(path);
|
}
|
||||||
if (oldFile == file)
|
if (containsKey){
|
||||||
{
|
IRemoteFile oldFile = null;
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
|
oldFile = (IRemoteFile)_cachedRemoteFiles.remove(path);
|
||||||
|
}
|
||||||
|
if (oldFile == file){
|
||||||
// already cached - recache
|
// already cached - recache
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
_cachedRemoteFiles.put(path, file);
|
_cachedRemoteFiles.put(path, file);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace file under parent
|
// replace file under parent
|
||||||
if (oldFile instanceof RemoteFile) {
|
if (oldFile instanceof RemoteFile) {
|
||||||
RemoteFile roldFile = (RemoteFile)oldFile;
|
RemoteFile roldFile = (RemoteFile)oldFile;
|
||||||
if (roldFile._parentFile != null) // prevent parent query from bug #196664
|
if (roldFile._parentFile != null){ // prevent parent query from bug #196664
|
||||||
{
|
|
||||||
roldFile._parentFile.replaceContent(oldFile, file);
|
roldFile._parentFile.replaceContent(oldFile, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1295,12 +1301,15 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
||||||
}
|
}
|
||||||
|
|
||||||
// preserve persistent information from old file to new
|
// preserve persistent information from old file to new
|
||||||
if (oldFile != null)
|
if (oldFile != null){
|
||||||
oldFile.copyContentsTo(file);
|
oldFile.copyContentsTo(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
_cachedRemoteFiles.put(path, file);
|
_cachedRemoteFiles.put(path, file);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the IRemoteFile in a hashmap to quick subsequent retrieval
|
* Store the IRemoteFile in a hashmap to quick subsequent retrieval
|
||||||
|
@ -1321,6 +1330,7 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
||||||
*/
|
*/
|
||||||
public IRemoteFile getCachedRemoteFile(String path)
|
public IRemoteFile getCachedRemoteFile(String path)
|
||||||
{
|
{
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
if (_cachedRemoteFiles.size() > 0)
|
if (_cachedRemoteFiles.size() > 0)
|
||||||
{
|
{
|
||||||
path = path.replaceAll("//", "/"); //$NON-NLS-1$ //$NON-NLS-2$
|
path = path.replaceAll("//", "/"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
@ -1332,7 +1342,7 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
||||||
{
|
{
|
||||||
{return (IRemoteFile)_cachedRemoteFiles.get(path);}
|
{return (IRemoteFile)_cachedRemoteFiles.get(path);}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -1356,7 +1366,10 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
||||||
//If getContents() is implemented correctly, no matches should be removed
|
//If getContents() is implemented correctly, no matches should be removed
|
||||||
String prefix = file.getAbsolutePath() + file.getSeparator();
|
String prefix = file.getAbsolutePath() + file.getSeparator();
|
||||||
//Clone the hashMap in order to avoid ConcurrentModificationException in the iterator
|
//Clone the hashMap in order to avoid ConcurrentModificationException in the iterator
|
||||||
HashMap tmpMap = (HashMap)_cachedRemoteFiles.clone();
|
HashMap tmpMap = null;
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
|
tmpMap = (HashMap)_cachedRemoteFiles.clone();
|
||||||
|
}
|
||||||
Iterator it = tmpMap.keySet().iterator();
|
Iterator it = tmpMap.keySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
String remotePath = (String)it.next();
|
String remotePath = (String)it.next();
|
||||||
|
@ -1367,14 +1380,16 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_cachedRemoteFiles.remove(file.getAbsolutePath());
|
removeCachedRemoteFile(file.getAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeCachedRemoteFile(String path)
|
protected void removeCachedRemoteFile(String path)
|
||||||
{
|
{
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
_cachedRemoteFiles.remove(path);
|
_cachedRemoteFiles.remove(path);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void communicationsStateChange(CommunicationsEvent e)
|
public void communicationsStateChange(CommunicationsEvent e)
|
||||||
|
@ -1382,7 +1397,9 @@ public abstract class RemoteFileSubSystem extends SubSystem implements IRemoteFi
|
||||||
switch (e.getState())
|
switch (e.getState())
|
||||||
{
|
{
|
||||||
case CommunicationsEvent.AFTER_DISCONNECT :
|
case CommunicationsEvent.AFTER_DISCONNECT :
|
||||||
|
synchronized (_cachedRemoteFiles){
|
||||||
_cachedRemoteFiles.clear();
|
_cachedRemoteFiles.clear();
|
||||||
|
}
|
||||||
// DKM - taking this out because it causes an exception when the event occurs in Modal Context
|
// DKM - taking this out because it causes an exception when the event occurs in Modal Context
|
||||||
//ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry();
|
//ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry();
|
||||||
//sr.connectedStatusChange(this, false, true, true);
|
//sr.connectedStatusChange(this, false, true, true);
|
||||||
|
|
Loading…
Add table
Reference in a new issue