|
From: <ha...@us...> - 2006-10-18 20:54:19
|
Revision: 1011
http://svn.sourceforge.net/cogkit/?rev=1011&view=rev
Author: hategan
Date: 2006-10-18 13:54:16 -0700 (Wed, 18 Oct 2006)
Log Message:
-----------
async cached resource shutdown; mkdirs() file operation
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java
Added Paths:
-----------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2006-10-18 20:51:35 UTC (rev 1010)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2006-10-18 20:54:16 UTC (rev 1011)
@@ -51,41 +51,52 @@
private Timer timer;
private int maxIdleResources = DEFAULT_MAX_IDLE_RESOURCES;
private long maxIdleTime = DEFAULT_MAX_IDLE_TIME;
+ private ResourceStopper stopper;
public FileResourceCache() {
fileResources = new Hashtable();
inUse = new HashSet();
order = new LinkedList();
releaseTimes = new Hashtable();
+ stopper = new ResourceStopper();
}
- public synchronized FileResource getResource(Service service) throws InvalidProviderException,
+ public FileResource getResource(Service service) throws InvalidProviderException,
ProviderMethodException, IllegalHostException, InvalidSecurityContextException,
GeneralException {
logger.debug("Got request for resource for " + service);
checkTimer();
ServiceContact contact = service.getServiceContact();
- if (fileResources.containsKey(contact)) {
- List resources = (List) fileResources.get(contact);
- Iterator i = resources.iterator();
- while (i.hasNext()) {
- FileResource fileResource = (FileResource) i.next();
- if (!inUse.contains(fileResource)) {
- inUse.add(fileResource);
- order.remove(fileResource);
- releaseTimes.remove(fileResource);
- logger.debug("Found cached resource");
- return fileResource;
+ FileResource fileResource;
+ synchronized (this) {
+ if (fileResources.containsKey(contact)) {
+ List resources = (List) fileResources.get(contact);
+ Iterator i = resources.iterator();
+ while (i.hasNext()) {
+ fileResource = (FileResource) i.next();
+ if (!inUse.contains(fileResource)) {
+ inUse.add(fileResource);
+ order.remove(fileResource);
+ releaseTimes.remove(fileResource);
+ logger.debug("Found cached resource");
+ return fileResource;
+ }
}
}
+ fileResource = newResource(service);
}
- return newResource(service);
+ synchronized (fileResource) {
+ if (!fileResource.isStarted()) {
+ fileResource.start();
+ }
+ }
+ return fileResource;
}
private FileResource newResource(Service service) throws InvalidProviderException,
ProviderMethodException, IllegalHostException, InvalidSecurityContextException,
GeneralException {
- //TODO Are file resources reentrant?
+ // TODO Are file resources reentrant?
logger.debug("Instantiating new resource for " + service);
String provider = service.getProvider();
ServiceContact contact = service.getServiceContact();
@@ -99,7 +110,6 @@
FileResource fileResource = AbstractionFactory.newFileResource(provider);
fileResource.setServiceContact(contact);
fileResource.setSecurityContext(securityContext);
- fileResource.start();
List resources;
if (fileResources.containsKey(contact)) {
resources = (List) fileResources.get(contact);
@@ -113,30 +123,29 @@
return fileResource;
}
- public synchronized void releaseResource(FileResource resource) {
+ public void releaseResource(FileResource resource) {
if (resource == null) {
return;
}
- logger.debug("Releasing resource for " + resource.getServiceContact());
- if (!inUse.contains(resource)) {
- throw new RuntimeException("Attempted to release resource that is not in use");
+ synchronized (this) {
+ logger.debug("Releasing resource for " + resource.getServiceContact());
+ if (!inUse.contains(resource)) {
+ throw new RuntimeException("Attempted to release resource that is not in use");
+ }
+ inUse.remove(resource);
+ order.addLast(resource);
+ releaseTimes.put(resource, new Long(System.currentTimeMillis()));
}
- inUse.remove(resource);
- order.addLast(resource);
- releaseTimes.put(resource, new Long(System.currentTimeMillis()));
checkIdleResourceCount();
}
private void removeResource(FileResource resource) {
- if (fileResources.containsKey(resource.getServiceContact())) {
- List resources = (List) fileResources.get(resource.getServiceContact());
- resources.remove(resource);
- try {
- resource.stop();
+ synchronized (this) {
+ if (fileResources.containsKey(resource.getServiceContact())) {
+ List resources = (List) fileResources.get(resource.getServiceContact());
+ resources.remove(resource);
+ stopper.addResource(resource);
}
- catch (GeneralException e) {
- logger.warn("Failed to stop resource", e);
- }
}
}
@@ -188,8 +197,7 @@
+ resource.getServiceContact());
removeResource(resource);
}
- }
- while (last < threshold);
+ } while (last < threshold);
}
private class ResourceSwipe extends TimerTask {
@@ -203,4 +211,54 @@
cache.checkIdleResourceAges();
}
}
+
+ public static class ResourceStopper implements Runnable {
+ private LinkedList resources;
+ private boolean running;
+
+ public ResourceStopper () {
+ resources = new LinkedList();
+ running = false;
+ }
+
+ public void addResource(FileResource fr) {
+ synchronized(this) {
+ resources.add(fr);
+ if (!running) {
+ running = true;
+ Thread t = new Thread(this);
+ t.setName("File resource stopper");
+ t.setDaemon(true);
+ t.start();
+ }
+ }
+ }
+
+ public void run() {
+ FileResource fr = nextResource();
+ while (fr != null) {
+ try {
+ fr.stop();
+ }
+ catch (GeneralException e) {
+ logger.warn("Failed to stop resource", e);
+ }
+ fr = nextResource();
+ }
+ synchronized(this) {
+ running = false;
+ }
+ }
+
+ private FileResource nextResource() {
+ synchronized(this) {
+ if (resources.isEmpty()) {
+ return null;
+ }
+ else {
+ return (FileResource) resources.removeFirst();
+ }
+ }
+ }
+ }
}
\ No newline at end of file
Added: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java (rev 0)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java 2006-10-18 20:54:16 UTC (rev 1011)
@@ -0,0 +1,42 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Oct 18, 2006
+ */
+package org.globus.cog.abstraction.impl.file;
+
+import java.util.StringTokenizer;
+
+import org.globus.cog.abstraction.interfaces.FileResource;
+
+public class FileResourceUtil {
+
+ public static void createDirectories(FileResource fr, String dir) throws GeneralException {
+ // TODO this should be in an AbstractFileResource
+ // there is an assumption here on the path separators
+ // I'd really suggest enforcing only one of them at the level of the
+ // interface
+ StringTokenizer st = new StringTokenizer(dir, "/");
+ StringBuffer sb = new StringBuffer();
+ if (dir.startsWith("/")) {
+ sb.append('/');
+ }
+ while (st.hasMoreTokens()) {
+ try {
+ String partial = sb.toString();
+ if (!fr.exists(partial)) {
+ fr.createDirectory(partial);
+ }
+ sb.append(st.nextToken());
+ sb.append('/');
+ }
+ catch (Exception e) {
+ throw new GeneralException("Could not create directory structure " + dir, e);
+ }
+ }
+ }
+}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java 2006-10-18 20:51:35 UTC (rev 1010)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java 2006-10-18 20:54:16 UTC (rev 1011)
@@ -8,7 +8,9 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Hashtable;
+import java.util.Set;
import java.util.Vector;
import org.apache.log4j.Logger;
@@ -48,9 +50,39 @@
private Hashtable activeFileResources;
private Identity defaultSessionId = null;
- private Vector oneWordCommands = null;
- private Vector twoWordCommands = null;
- private Vector threeWordCommands = null;
+ private static final Set oneWordCommands, twoWordCommands, threeWordCommands;
+
+ static {
+ oneWordCommands = new HashSet();
+ twoWordCommands = new HashSet();
+ threeWordCommands = new HashSet();
+
+ // Add all one word commands
+ oneWordCommands.add(FileOperationSpecification.START);
+ oneWordCommands.add(FileOperationSpecification.STOP);
+ oneWordCommands.add(FileOperationSpecification.LS);
+ oneWordCommands.add(FileOperationSpecification.PWD);
+
+ // Add all two word commands
+ twoWordCommands.add(FileOperationSpecification.LS);
+ twoWordCommands.add(FileOperationSpecification.MKDIR);
+ twoWordCommands.add(FileOperationSpecification.MKDIRS);
+ twoWordCommands.add(FileOperationSpecification.RMDIR);
+ twoWordCommands.add(FileOperationSpecification.RMFILE);
+ twoWordCommands.add(FileOperationSpecification.EXISTS);
+ twoWordCommands.add(FileOperationSpecification.CD);
+ twoWordCommands.add(FileOperationSpecification.ISDIRECTORY);
+
+ // Add all three word commands
+ threeWordCommands.add(FileOperationSpecification.RMDIR);
+ threeWordCommands.add(FileOperationSpecification.GETFILE);
+ threeWordCommands.add(FileOperationSpecification.PUTFILE);
+ threeWordCommands.add(FileOperationSpecification.GETDIR);
+ threeWordCommands.add(FileOperationSpecification.PUTDIR);
+ threeWordCommands.add(FileOperationSpecification.RENAME);
+ threeWordCommands.add(FileOperationSpecification.CHMOD);
+ }
+
private int type;
private Task task = null;
@@ -59,7 +91,6 @@
static Logger logger = Logger.getLogger(TaskHandlerImpl.class.getName());
public TaskHandlerImpl() {
-
this.submittedList = new Vector();
this.activeList = new Vector();
this.suspendedList = new Vector();
@@ -70,11 +101,6 @@
this.handleMap = new Hashtable();
this.type = TaskHandler.FILE_OPERATION;
this.activeFileResources = new Hashtable();
- oneWordCommands = new Vector();
- twoWordCommands = new Vector();
- threeWordCommands = new Vector();
- addValidCommands();
-
}
/** set type of task handler */
@@ -267,6 +293,10 @@
&& spec.getArgumentSize() == 1) {
fileResource.createDirectory(spec.getArgument(0));
} else if (operation
+ .equalsIgnoreCase(FileOperationSpecification.MKDIRS)
+ && spec.getArgumentSize() == 1) {
+ fileResource.createDirectories(spec.getArgument(0));
+ } else if (operation
.equalsIgnoreCase(FileOperationSpecification.RMDIR)
&& spec.getArgumentSize() == 2) {
fileResource.deleteDirectory(spec.getArgument(0), Boolean
@@ -499,33 +529,6 @@
}
}
- /** Add a list of valid commands to a vector */
- public void addValidCommands() {
- // Add all one word commands
- oneWordCommands.add(FileOperationSpecification.START);
- oneWordCommands.add(FileOperationSpecification.STOP);
- oneWordCommands.add(FileOperationSpecification.LS);
- oneWordCommands.add(FileOperationSpecification.PWD);
-
- // Add all two word commands
- twoWordCommands.add(FileOperationSpecification.LS);
- twoWordCommands.add(FileOperationSpecification.MKDIR);
- twoWordCommands.add(FileOperationSpecification.RMDIR);
- twoWordCommands.add(FileOperationSpecification.RMFILE);
- twoWordCommands.add(FileOperationSpecification.EXISTS);
- twoWordCommands.add(FileOperationSpecification.CD);
- twoWordCommands.add(FileOperationSpecification.ISDIRECTORY);
-
- // Add all three word commands
- threeWordCommands.add(FileOperationSpecification.RMDIR);
- threeWordCommands.add(FileOperationSpecification.GETFILE);
- threeWordCommands.add(FileOperationSpecification.PUTFILE);
- threeWordCommands.add(FileOperationSpecification.GETDIR);
- threeWordCommands.add(FileOperationSpecification.PUTDIR);
- threeWordCommands.add(FileOperationSpecification.RENAME);
- threeWordCommands.add(FileOperationSpecification.CHMOD);
- }
-
private SecurityContext getSecurityContext() {
SecurityContext securityContext = this.task.getService(0)
.getSecurityContext();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ha...@us...> - 2006-11-28 22:39:19
|
Revision: 1428
http://svn.sourceforge.net/cogkit/?rev=1428&view=rev
Author: hategan
Date: 2006-11-28 14:39:18 -0800 (Tue, 28 Nov 2006)
Log Message:
-----------
cleaned up the resources stuff
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IllegalHostException.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java
Added Paths:
-----------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceException.java
Removed Paths:
-------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/GeneralException.java
Added: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java (rev 0)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -0,0 +1,316 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Nov 28, 2006
+ */
+package org.globus.cog.abstraction.impl.file;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.globus.cog.abstraction.impl.common.IdentityImpl;
+import org.globus.cog.abstraction.interfaces.FileResource;
+import org.globus.cog.abstraction.interfaces.GridFile;
+import org.globus.cog.abstraction.interfaces.GridResource;
+import org.globus.cog.abstraction.interfaces.Identity;
+import org.globus.cog.abstraction.interfaces.SecurityContext;
+import org.globus.cog.abstraction.interfaces.ServiceContact;
+
+public abstract class AbstractFileResource implements FileResource {
+ private String name;
+ private Map attributes;
+ private ServiceContact serviceContact;
+ private SecurityContext securityContext;
+ private Identity identity;
+ private final int type = GridResource.FILE;
+ private String protocol;
+ private boolean started;
+
+ protected AbstractFileResource() {
+ this(null, null, null, null);
+ }
+
+ protected AbstractFileResource(String name, String protocol, ServiceContact serviceContact,
+ SecurityContext securityContext) {
+ attributes = new HashMap();
+ identity = new IdentityImpl();
+ this.name = name;
+ this.protocol = protocol;
+ this.serviceContact = serviceContact;
+ this.securityContext = securityContext;
+ }
+
+ /** Set the name of the resource */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /** Return name of the resource */
+ public String getName() {
+ return this.name;
+ }
+
+ /** set service contact */
+ public void setServiceContact(ServiceContact serviceContact) {
+ this.serviceContact = serviceContact;
+ }
+
+ /** return service contact */
+ public ServiceContact getServiceContact() {
+ return serviceContact;
+ }
+
+ /** Set identity of the resource */
+ public void setIdentity(Identity identity) {
+ this.identity = identity;
+ }
+
+ /** return identity of the resource */
+ public Identity getIdentity() {
+ return this.identity;
+ }
+
+ /** return type = FILE which is defined in GridResource */
+ public int getType() {
+ return this.type;
+ }
+
+ /** return protocol */
+ public String getProtocol() {
+ return this.protocol;
+ }
+
+ /** Set the appropriate SecurityContext for the FileResource */
+ public void setSecurityContext(SecurityContext securityContext) {
+ this.securityContext = securityContext;
+ }
+
+ /** Get the securityContext for the remote resource */
+ public SecurityContext getSecurityContext() {
+ return this.securityContext;
+ }
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ protected synchronized void setStarted(boolean started) {
+ this.started = started;
+ }
+
+ /** set attribute for ftp resource */
+ public void setAttribute(String name, Object value) {
+ this.attributes.put(name, value);
+ }
+
+ public Collection getAttributeNames() {
+ return this.attributes.keySet();
+ }
+
+ /** get attribute */
+ public Object getAttribute(String name) {
+ return this.attributes.get(name);
+ }
+
+ /** Equivalent to the cp -r command for copying directories */
+ public void getDirectory(String remoteDirName, String localDirName)
+ throws FileResourceException, IOException {
+ File localDir = new File(localDirName);
+ GridFile gridFile = null;
+
+ if (!localDir.exists()) {
+ localDir.mkdir();
+ }
+
+ if (isDirectory(remoteDirName) == false) {
+ throw new DirectoryNotFoundException("Remote directory not found");
+ }
+
+ for (Iterator iterator = list(remoteDirName).iterator(); iterator.hasNext();) {
+ gridFile = (GridFile) iterator.next();
+ if (gridFile.isFile()) {
+ getFile(remoteDirName + "/" + gridFile.getName(), localDirName + File.separator
+ + gridFile.getName());
+ }
+ else {
+ getDirectory(remoteDirName + "/" + gridFile.getName(), localDirName
+ + File.separator + gridFile.getName());
+ }
+ }
+ }
+
+ /** Equivalent to cp -r command for copying directories */
+ public void putDirectory(String localDirName, String remoteDirName)
+ throws FileResourceException, IOException {
+ File localDir = new File(localDirName);
+ if (!localDir.exists()) {
+ throw new DirectoryNotFoundException("Local directory not found");
+ }
+
+ if (localDir.isFile()) {
+ throw new DirectoryNotFoundException(localDirName + " is a file");
+ }
+
+ try {
+ if (!exists(remoteDirName)) {
+ createDirectory(remoteDirName);
+ }
+ }
+ catch (FileNotFoundException fe) {
+ throw new DirectoryNotFoundException("Cannot create the remote directory: "
+ + remoteDirName);
+ }
+
+ if (!isDirectory(remoteDirName)) {
+ throw new DirectoryNotFoundException(remoteDirName + " is a file");
+ }
+
+ String files[] = localDir.list();
+ for (int index = 0; index < files.length; index++) {
+ File localFile = new File(localDirName + File.separator + files[index]);
+ if (!localFile.isDirectory()) {
+ putFile(localDirName + File.separator + files[index], remoteDirName + "/"
+ + files[index]);
+ }
+ else {
+ putDirectory(localDirName + File.separator + files[index], remoteDirName + "/"
+ + files[index]);
+ }
+ }
+ }
+
+ /**
+ * mget - Obtain multiple files from the remote server
+ */
+ public void getMultipleFiles(String[] remoteFileNames, String[] localFileNames)
+ throws FileResourceException, IOException {
+
+ // If the list of sources not equal to destination lists then error
+ if (localFileNames.length != remoteFileNames.length)
+ throw new IllegalArgumentException(
+ "Number of source and destination file names has to be the same");
+
+ // Check every remote file name provided. If file, use getfile else use
+ // getdir
+ for (int index = 0; index < remoteFileNames.length; index++) {
+ if (exists(remoteFileNames[index])) {
+ if (isDirectory(remoteFileNames[index]) == false) {
+ getFile(remoteFileNames[index], localFileNames[index]);
+ }
+ else {
+ getDirectory(remoteFileNames[index], localFileNames[index]);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * mget - Obtain multiple files from the ftp server
+ */
+ public void getMultipleFiles(String[] remoteFileNames, String localDirName)
+ throws FileResourceException, IOException {
+ for (int index = 0; index < remoteFileNames.length; index++) {
+ // Extract only the file name to be appended to the destination
+ // directory
+ // in getfile or getdir
+ String remoteFileName = remoteFileNames[index].substring(remoteFileNames[index].lastIndexOf("/") + 1);
+
+ if (exists(remoteFileNames[index])) {
+ // Check every remote file name provided. If file, use
+ // getfile else use getdir
+ if (isDirectory(remoteFileNames[index]) == false) {
+
+ getFile(remoteFileNames[index], localDirName + File.separator + remoteFileName);
+ }
+ else {
+ getDirectory(remoteFileNames[index], localDirName + File.separator
+ + remoteFileName);
+ }
+ }
+ }
+ }
+
+ /**
+ * mput - copy multiple files to the resource
+ */
+ public void putMultipleFiles(String[] localFileNames, String remoteDirName)
+ throws FileResourceException, IOException {
+
+ for (int index = 0; index < localFileNames.length; index++) {
+ // Check every remote file name provided. If file, use putfile else
+ // use putdir
+ File localFile = new File(localFileNames[index]);
+ if (!localFile.isDirectory()) {
+ putFile(localFileNames[index], remoteDirName + "/" + localFile.getName());
+ }
+ else {
+ putDirectory(localFileNames[index], remoteDirName + "/" + localFile.getName());
+ }
+ }
+ }
+
+ /**
+ * mput - copy multiple files into the resource server
+ */
+ public void putMultipleFiles(String[] localFileNames, String[] remoteFileNames)
+ throws FileResourceException, IOException {
+ // If list of sources not equal to list of destinations then error
+ if (localFileNames.length != remoteFileNames.length)
+ throw new IllegalArgumentException(
+ "Number of source and destination file names has to be the same");
+
+ for (int index = 0; index < localFileNames.length; index++) {
+ // Check every local file name provided. If file, use putfile else
+ // use putdir
+ File localFile = new File(localFileNames[index]);
+ if (!localFile.isDirectory()) {
+ putFile(localFileNames[index], remoteFileNames[index]);
+ }
+ else {
+ putDirectory(localFileNames[index], remoteFileNames[index]);
+ }
+ }
+ }
+
+ public void createDirectories(String dir) throws FileResourceException,
+ IOException {
+ // TODO there is an assumption here on the path separators
+ // I'd really suggest enforcing only one of them (hint: '/') at the
+ // level of the
+ // interface
+ if (dir.equals("/")) {
+ return;
+ }
+ try {
+ if (!exists(dir)) {
+ int i = dir.lastIndexOf('/');
+ if (i <= 0) {
+ createDirectory(dir);
+ }
+ else {
+ createDirectories(dir.substring(0, i));
+ if (i != dir.length() - 1) {
+ createDirectory(dir);
+ }
+ else {
+ // trailing '/'
+ }
+ }
+ }
+ }
+ catch (FileResourceException e) {
+ if (!isDirectory(dir)) {
+ throw e;
+ }
+ }
+ }
+}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -9,6 +9,8 @@
*/
package org.globus.cog.abstraction.impl.file;
+import java.io.IOException;
+
import org.globus.cog.abstraction.impl.common.ProviderMethodException;
import org.globus.cog.abstraction.impl.common.StatusImpl;
import org.globus.cog.abstraction.impl.common.task.IllegalSpecException;
@@ -24,7 +26,7 @@
public class CachingDelegatedFileOperationHandler extends TaskHandlerImpl {
private FileResource resource;
-
+
public synchronized void submit(Task task) throws IllegalSpecException,
InvalidSecurityContextException, InvalidServiceContactException,
TaskSubmissionException {
@@ -64,9 +66,9 @@
protected FileResource getResource(Service service) throws InvalidProviderException,
ProviderMethodException, IllegalHostException, InvalidSecurityContextException,
- GeneralException {
+ FileResourceException, IOException {
resource = FileResourceCache.getDefault().getResource(service);
- return resource;
+ return resource;
}
public void stopResources() {
@@ -78,7 +80,7 @@
}
protected Object execute(FileResource fileResource, FileOperationSpecification spec)
- throws DirectoryNotFoundException, FileNotFoundException, GeneralException {
+ throws FileResourceException, IOException {
Object ret;
try {
ret = super.execute(fileResource, spec);
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -8,10 +8,11 @@
package org.globus.cog.abstraction.impl.file;
+
/**
* Directory not found exception to be thrown when the directory being accessed does not exist
*/
-public class DirectoryNotFoundException extends Exception
+public class DirectoryNotFoundException extends FileResourceException
{
/** Set a string message to the exception */
public DirectoryNotFoundException(String message)
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -8,10 +8,11 @@
package org.globus.cog.abstraction.impl.file;
+
/**
* File not found exception to be thrown when the file being accessed does not exist
*/
-public class FileNotFoundException extends Exception
+public class FileNotFoundException extends FileResourceException
{
/** Set a string message to the exception */
public FileNotFoundException(String message)
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -9,6 +9,7 @@
*/
package org.globus.cog.abstraction.impl.file;
+import java.io.IOException;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
@@ -63,8 +64,10 @@
public FileResource getResource(Service service) throws InvalidProviderException,
ProviderMethodException, IllegalHostException, InvalidSecurityContextException,
- GeneralException {
- logger.debug("Got request for resource for " + service);
+ FileResourceException, IOException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Got request for resource for " + service);
+ }
checkTimer();
ServiceContact contact = service.getServiceContact();
FileResource fileResource;
@@ -78,7 +81,9 @@
inUse.add(fileResource);
order.remove(fileResource);
releaseTimes.remove(fileResource);
- logger.debug("Found cached resource");
+ if (logger.isDebugEnabled()) {
+ logger.debug("Found cached resource");
+ }
return fileResource;
}
}
@@ -95,9 +100,11 @@
private FileResource newResource(Service service) throws InvalidProviderException,
ProviderMethodException, IllegalHostException, InvalidSecurityContextException,
- GeneralException {
+ FileResourceException, IOException {
// TODO Are file resources reentrant?
- logger.debug("Instantiating new resource for " + service);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Instantiating new resource for " + service);
+ }
String provider = service.getProvider();
ServiceContact contact = service.getServiceContact();
if (provider == null) {
@@ -122,7 +129,7 @@
inUse.add(fileResource);
return fileResource;
}
-
+
private Throwable lastRelease;
public void releaseResource(FileResource resource) {
@@ -130,7 +137,9 @@
return;
}
synchronized (this) {
- logger.debug("Releasing resource for " + resource.getServiceContact());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Releasing resource for " + resource.getServiceContact());
+ }
/*
* if (!inUse.contains(resource)) { throw new
* RuntimeException("Attempted to release resource that is not in
@@ -161,14 +170,21 @@
resources.remove(resource);
stopper.addResource(resource);
}
+ else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("removeResource called with resource not in set");
+ }
+ }
}
}
private void checkIdleResourceCount() {
while (order.size() > maxIdleResources) {
FileResource fileResource = (FileResource) order.removeFirst();
- logger.debug("Idle resource count exceeded. Removing resource for "
- + fileResource.getServiceContact());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Idle resource count exceeded. Removing resource for "
+ + fileResource.getServiceContact());
+ }
removeResource(fileResource);
}
}
@@ -208,8 +224,10 @@
if (last < threshold) {
order.removeFirst();
releaseTimes.remove(resource);
- logger.debug("Maximum idle time exceeded. Removing resource for "
- + resource.getServiceContact());
+ if (logger.isDebugEnabled()) {
+ logger.debug("Maximum idle time exceeded. Removing resource for "
+ + resource.getServiceContact());
+ }
removeResource(resource);
}
} while (last < threshold);
@@ -238,6 +256,7 @@
public void addResource(FileResource fr) {
synchronized (this) {
+ System.err.println("Scheduling " + fr + " for closing");
resources.add(fr);
if (!running) {
running = true;
@@ -253,9 +272,11 @@
FileResource fr = nextResource();
while (fr != null) {
try {
+ System.err.println("Stopping " + fr);
fr.stop();
+ System.err.println("Stopped " + fr);
}
- catch (GeneralException e) {
+ catch (Exception e) {
logger.warn("Failed to stop resource", e);
}
fr = nextResource();
Added: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceException.java (rev 0)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceException.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -0,0 +1,29 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Nov 28, 2006
+ */
+package org.globus.cog.abstraction.impl.file;
+
+public class FileResourceException extends Exception {
+
+ public FileResourceException() {
+ super();
+ }
+
+ public FileResourceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public FileResourceException(String message) {
+ super(message);
+ }
+
+ public FileResourceException(Throwable cause) {
+ super(cause);
+ }
+}
Deleted: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceUtil.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -1,52 +0,0 @@
-//----------------------------------------------------------------------
-//This code is developed as part of the Java CoG Kit project
-//The terms of the license can be found at http://www.cogkit.org/license
-//This message may not be removed or altered.
-//----------------------------------------------------------------------
-
-/*
- * Created on Oct 18, 2006
- */
-package org.globus.cog.abstraction.impl.file;
-
-import org.globus.cog.abstraction.interfaces.FileResource;
-
-public class FileResourceUtil {
-
- public static void createDirectories(FileResource fr, String dir) throws GeneralException {
- // TODO this should be in an AbstractFileResource
- // there is an assumption here on the path separators
- // I'd really suggest enforcing only one of them (hint: '/') at the
- // level of the
- // interface
- if (dir.equals("/")) {
- return;
- }
- try {
- if (!fr.exists(dir)) {
- int i = dir.lastIndexOf('/');
- if (i <= 0) {
- fr.createDirectory(dir);
- }
- else {
- createDirectories(fr, dir.substring(0, i));
- if (i != dir.length() - 1) {
- fr.createDirectory(dir);
- }
- else {
- // trailing '/'
- }
- }
- }
- }
- catch (GeneralException e) {
- if (!fr.isDirectory(dir)) {
- throw e;
- }
- }
- catch (FileNotFoundException e) {
- // [m] why on earth is this thrown here?
- throw new GeneralException(e.getMessage(), e);
- }
- }
-}
Deleted: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/GeneralException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/GeneralException.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/GeneralException.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -1,28 +0,0 @@
-// ----------------------------------------------------------------------
-// This code is developed as part of the Java CoG Kit project
-// The terms of the license can be found at http://www.cogkit.org/license
-// This message may not be removed or altered.
-// ----------------------------------------------------------------------
-
-
-
-package org.globus.cog.abstraction.impl.file;
-
-/**
- * General Exception to handle exceptions that do not fall into the
- * specific categories
- */
-public class GeneralException extends Exception
-{
- /** Assign message to exception */
- public GeneralException(String message)
- {
- super(message);
- }
-
-/** Assign message and throwable for exception*/
- public GeneralException(String message, Throwable parent)
- {
- super(message, parent);
- }
-}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IllegalHostException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IllegalHostException.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IllegalHostException.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -9,7 +9,7 @@
/**
* IllegalHostException is thrown
*/
-public class IllegalHostException extends Exception
+public class IllegalHostException extends FileResourceException
{
/** Assign message for the exception */
public IllegalHostException(String message)
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java 2006-11-28 22:37:38 UTC (rev 1427)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java 2006-11-28 22:39:18 UTC (rev 1428)
@@ -6,6 +6,7 @@
package org.globus.cog.abstraction.impl.file;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -39,507 +40,492 @@
* The base class for task handlers in all file providers
*/
public class TaskHandlerImpl implements TaskHandler, StatusListener {
- private Vector submittedList = null;
- private Vector activeList = null;
- private Vector suspendedList = null;
- private Vector resumedList = null;
- private Vector failedList = null;
- private Vector canceledList = null;
- private Vector completedList = null;
- private Hashtable handleMap = null;
- private Hashtable activeFileResources;
- private Identity defaultSessionId = null;
+ private Vector submittedList = null;
+ private Vector activeList = null;
+ private Vector suspendedList = null;
+ private Vector resumedList = null;
+ private Vector failedList = null;
+ private Vector canceledList = null;
+ private Vector completedList = null;
+ private Hashtable handleMap = null;
+ private Hashtable activeFileResources;
+ private Identity defaultSessionId = null;
- private static final Set oneWordCommands, twoWordCommands, threeWordCommands;
-
- static {
- oneWordCommands = new HashSet();
- twoWordCommands = new HashSet();
- threeWordCommands = new HashSet();
+ private static final Set oneWordCommands, twoWordCommands, threeWordCommands;
- // Add all one word commands
- oneWordCommands.add(FileOperationSpecification.START);
- oneWordCommands.add(FileOperationSpecification.STOP);
- oneWordCommands.add(FileOperationSpecification.LS);
- oneWordCommands.add(FileOperationSpecification.PWD);
+ static {
+ oneWordCommands = new HashSet();
+ twoWordCommands = new HashSet();
+ threeWordCommands = new HashSet();
- // Add all two word commands
- twoWordCommands.add(FileOperationSpecification.LS);
- twoWordCommands.add(FileOperationSpecification.MKDIR);
- twoWordCommands.add(FileOperationSpecification.MKDIRS);
- twoWordCommands.add(FileOperationSpecification.RMDIR);
- twoWordCommands.add(FileOperationSpecification.RMFILE);
- twoWordCommands.add(FileOperationSpecification.EXISTS);
- twoWordCommands.add(FileOperationSpecification.CD);
- twoWordCommands.add(FileOperationSpecification.ISDIRECTORY);
+ // Add all one word commands
+ oneWordCommands.add(FileOperationSpecification.START);
+ oneWordCommands.add(FileOperationSpecification.STOP);
+ oneWordCommands.add(FileOperationSpecification.LS);
+ oneWordCommands.add(FileOperationSpecification.PWD);
- // Add all three word commands
- threeWordCommands.add(FileOperationSpecification.RMDIR);
- threeWordCommands.add(FileOperationSpecification.GETFILE);
- threeWordCommands.add(FileOperationSpecification.PUTFILE);
- threeWordCommands.add(FileOperationSpecification.GETDIR);
- threeWordCommands.add(FileOperationSpecification.PUTDIR);
- threeWordCommands.add(FileOperationSpecification.RENAME);
- threeWordCommands.add(FileOperationSpecification.CHMOD);
- }
-
- private int type;
+ // Add all two word commands
+ twoWordCommands.add(FileOperationSpecification.LS);
+ twoWordCommands.add(FileOperationSpecification.MKDIR);
+ twoWordCommands.add(FileOperationSpecification.MKDIRS);
+ twoWordCommands.add(FileOperationSpecification.RMDIR);
+ twoWordCommands.add(FileOperationSpecification.RMFILE);
+ twoWordCommands.add(FileOperationSpecification.EXISTS);
+ twoWordCommands.add(FileOperationSpecification.CD);
+ twoWordCommands.add(FileOperationSpecification.ISDIRECTORY);
- private Task task = null;
- private FileResource fileResource = null;
+ // Add all three word commands
+ threeWordCommands.add(FileOperationSpecification.RMDIR);
+ threeWordCommands.add(FileOperationSpecification.GETFILE);
+ threeWordCommands.add(FileOperationSpecification.PUTFILE);
+ threeWordCommands.add(FileOperationSpecification.GETDIR);
+ threeWordCommands.add(FileOperationSpecification.PUTDIR);
+ threeWordCommands.add(FileOperationSpecification.RENAME);
+ threeWordCommands.add(FileOperationSpecification.CHMOD);
+ }
- static Logger logger = Logger.getLogger(TaskHandlerImpl.class.getName());
+ private int type;
- public TaskHandlerImpl() {
- this.submittedList = new Vector();
- this.activeList = new Vector();
- this.suspendedList = new Vector();
- this.resumedList = new Vector();
- this.failedList = new Vector();
- this.canceledList = new Vector();
- this.completedList = new Vector();
- this.handleMap = new Hashtable();
- this.type = TaskHandler.FILE_OPERATION;
- this.activeFileResources = new Hashtable();
- }
+ private Task task = null;
+ private FileRes...
[truncated message content] |
|
From: <ha...@us...> - 2006-11-28 22:42:40
|
Revision: 1429
http://svn.sourceforge.net/cogkit/?rev=1429&view=rev
Author: hategan
Date: 2006-11-28 14:42:39 -0800 (Tue, 28 Nov 2006)
Log Message:
-----------
with the right formatting this time
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceException.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/GridFileImpl.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IllegalHostException.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/PermissionsImpl.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/TaskHandlerImpl.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/UnixPermissionsImpl.java
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java 2006-11-28 22:39:18 UTC (rev 1428)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java 2006-11-28 22:42:39 UTC (rev 1429)
@@ -25,292 +25,298 @@
import org.globus.cog.abstraction.interfaces.ServiceContact;
public abstract class AbstractFileResource implements FileResource {
- private String name;
- private Map attributes;
- private ServiceContact serviceContact;
- private SecurityContext securityContext;
- private Identity identity;
- private final int type = GridResource.FILE;
- private String protocol;
- private boolean started;
+ private String name;
+ private Map attributes;
+ private ServiceContact serviceContact;
+ private SecurityContext securityContext;
+ private Identity identity;
+ private final int type = GridResource.FILE;
+ private String protocol;
+ private boolean started;
- protected AbstractFileResource() {
- this(null, null, null, null);
- }
+ protected AbstractFileResource() {
+ this(null, null, null, null);
+ }
- protected AbstractFileResource(String name, String protocol, ServiceContact serviceContact,
- SecurityContext securityContext) {
- attributes = new HashMap();
- identity = new IdentityImpl();
- this.name = name;
- this.protocol = protocol;
- this.serviceContact = serviceContact;
- this.securityContext = securityContext;
- }
+ protected AbstractFileResource(String name, String protocol,
+ ServiceContact serviceContact, SecurityContext securityContext) {
+ attributes = new HashMap();
+ identity = new IdentityImpl();
+ this.name = name;
+ this.protocol = protocol;
+ this.serviceContact = serviceContact;
+ this.securityContext = securityContext;
+ }
- /** Set the name of the resource */
- public void setName(String name) {
- this.name = name;
- }
+ /** Set the name of the resource */
+ public void setName(String name) {
+ this.name = name;
+ }
- /** Return name of the resource */
- public String getName() {
- return this.name;
- }
+ /** Return name of the resource */
+ public String getName() {
+ return this.name;
+ }
- /** set service contact */
- public void setServiceContact(ServiceContact serviceContact) {
- this.serviceContact = serviceContact;
- }
+ /** set service contact */
+ public void setServiceContact(ServiceContact serviceContact) {
+ this.serviceContact = serviceContact;
+ }
- /** return service contact */
- public ServiceContact getServiceContact() {
- return serviceContact;
- }
+ /** return service contact */
+ public ServiceContact getServiceContact() {
+ return serviceContact;
+ }
- /** Set identity of the resource */
- public void setIdentity(Identity identity) {
- this.identity = identity;
- }
+ /** Set identity of the resource */
+ public void setIdentity(Identity identity) {
+ this.identity = identity;
+ }
- /** return identity of the resource */
- public Identity getIdentity() {
- return this.identity;
- }
+ /** return identity of the resource */
+ public Identity getIdentity() {
+ return this.identity;
+ }
- /** return type = FILE which is defined in GridResource */
- public int getType() {
- return this.type;
- }
+ /** return type = FILE which is defined in GridResource */
+ public int getType() {
+ return this.type;
+ }
- /** return protocol */
- public String getProtocol() {
- return this.protocol;
- }
+ /** return protocol */
+ public String getProtocol() {
+ return this.protocol;
+ }
- /** Set the appropriate SecurityContext for the FileResource */
- public void setSecurityContext(SecurityContext securityContext) {
- this.securityContext = securityContext;
- }
+ /** Set the appropriate SecurityContext for the FileResource */
+ public void setSecurityContext(SecurityContext securityContext) {
+ this.securityContext = securityContext;
+ }
- /** Get the securityContext for the remote resource */
- public SecurityContext getSecurityContext() {
- return this.securityContext;
- }
+ /** Get the securityContext for the remote resource */
+ public SecurityContext getSecurityContext() {
+ return this.securityContext;
+ }
- public boolean isStarted() {
- return started;
- }
+ public boolean isStarted() {
+ return started;
+ }
- protected synchronized void setStarted(boolean started) {
- this.started = started;
- }
+ protected synchronized void setStarted(boolean started) {
+ this.started = started;
+ }
- /** set attribute for ftp resource */
- public void setAttribute(String name, Object value) {
- this.attributes.put(name, value);
- }
+ /** set attribute for ftp resource */
+ public void setAttribute(String name, Object value) {
+ this.attributes.put(name, value);
+ }
- public Collection getAttributeNames() {
- return this.attributes.keySet();
- }
+ public Collection getAttributeNames() {
+ return this.attributes.keySet();
+ }
- /** get attribute */
- public Object getAttribute(String name) {
- return this.attributes.get(name);
- }
+ /** get attribute */
+ public Object getAttribute(String name) {
+ return this.attributes.get(name);
+ }
- /** Equivalent to the cp -r command for copying directories */
- public void getDirectory(String remoteDirName, String localDirName)
- throws FileResourceException, IOException {
- File localDir = new File(localDirName);
- GridFile gridFile = null;
+ /** Equivalent to the cp -r command for copying directories */
+ public void getDirectory(String remoteDirName, String localDirName)
+ throws FileResourceException, IOException {
+ File localDir = new File(localDirName);
+ GridFile gridFile = null;
- if (!localDir.exists()) {
- localDir.mkdir();
- }
+ if (!localDir.exists()) {
+ localDir.mkdir();
+ }
- if (isDirectory(remoteDirName) == false) {
- throw new DirectoryNotFoundException("Remote directory not found");
- }
+ if (isDirectory(remoteDirName) == false) {
+ throw new DirectoryNotFoundException("Remote directory not found");
+ }
- for (Iterator iterator = list(remoteDirName).iterator(); iterator.hasNext();) {
- gridFile = (GridFile) iterator.next();
- if (gridFile.isFile()) {
- getFile(remoteDirName + "/" + gridFile.getName(), localDirName + File.separator
- + gridFile.getName());
- }
- else {
- getDirectory(remoteDirName + "/" + gridFile.getName(), localDirName
- + File.separator + gridFile.getName());
- }
- }
- }
+ for (Iterator iterator = list(remoteDirName).iterator(); iterator
+ .hasNext();) {
+ gridFile = (GridFile) iterator.next();
+ if (gridFile.isFile()) {
+ getFile(remoteDirName + "/" + gridFile.getName(), localDirName
+ + File.separator + gridFile.getName());
+ }
+ else {
+ getDirectory(remoteDirName + "/" + gridFile.getName(),
+ localDirName + File.separator + gridFile.getName());
+ }
+ }
+ }
- /** Equivalent to cp -r command for copying directories */
- public void putDirectory(String localDirName, String remoteDirName)
- throws FileResourceException, IOException {
- File localDir = new File(localDirName);
- if (!localDir.exists()) {
- throw new DirectoryNotFoundException("Local directory not found");
- }
+ /** Equivalent to cp -r command for copying directories */
+ public void putDirectory(String localDirName, String remoteDirName)
+ throws FileResourceException, IOException {
+ File localDir = new File(localDirName);
+ if (!localDir.exists()) {
+ throw new DirectoryNotFoundException("Local directory not found");
+ }
- if (localDir.isFile()) {
- throw new DirectoryNotFoundException(localDirName + " is a file");
- }
+ if (localDir.isFile()) {
+ throw new DirectoryNotFoundException(localDirName + " is a file");
+ }
- try {
- if (!exists(remoteDirName)) {
- createDirectory(remoteDirName);
- }
- }
- catch (FileNotFoundException fe) {
- throw new DirectoryNotFoundException("Cannot create the remote directory: "
- + remoteDirName);
- }
+ try {
+ if (!exists(remoteDirName)) {
+ createDirectory(remoteDirName);
+ }
+ }
+ catch (FileNotFoundException fe) {
+ throw new DirectoryNotFoundException(
+ "Cannot create the remote directory: " + remoteDirName);
+ }
- if (!isDirectory(remoteDirName)) {
- throw new DirectoryNotFoundException(remoteDirName + " is a file");
- }
+ if (!isDirectory(remoteDirName)) {
+ throw new DirectoryNotFoundException(remoteDirName + " is a file");
+ }
- String files[] = localDir.list();
- for (int index = 0; index < files.length; index++) {
- File localFile = new File(localDirName + File.separator + files[index]);
- if (!localFile.isDirectory()) {
- putFile(localDirName + File.separator + files[index], remoteDirName + "/"
- + files[index]);
- }
- else {
- putDirectory(localDirName + File.separator + files[index], remoteDirName + "/"
- + files[index]);
- }
- }
- }
+ String files[] = localDir.list();
+ for (int index = 0; index < files.length; index++) {
+ File localFile = new File(localDirName + File.separator
+ + files[index]);
+ if (!localFile.isDirectory()) {
+ putFile(localDirName + File.separator + files[index],
+ remoteDirName + "/" + files[index]);
+ }
+ else {
+ putDirectory(localDirName + File.separator + files[index],
+ remoteDirName + "/" + files[index]);
+ }
+ }
+ }
- /**
- * mget - Obtain multiple files from the remote server
- */
- public void getMultipleFiles(String[] remoteFileNames, String[] localFileNames)
- throws FileResourceException, IOException {
+ /**
+ * mget - Obtain multiple files from the remote server
+ */
+ public void getMultipleFiles(String[] remoteFileNames,
+ String[] localFileNames) throws FileResourceException, IOException {
- // If the list of sources not equal to destination lists then error
- if (localFileNames.length != remoteFileNames.length)
- throw new IllegalArgumentException(
- "Number of source and destination file names has to be the same");
+ // If the list of sources not equal to destination lists then error
+ if (localFileNames.length != remoteFileNames.length)
+ throw new IllegalArgumentException(
+ "Number of source and destination file names has to be the same");
- // Check every remote file name provided. If file, use getfile else use
- // getdir
- for (int index = 0; index < remoteFileNames.length; index++) {
- if (exists(remoteFileNames[index])) {
- if (isDirectory(remoteFileNames[index]) == false) {
- getFile(remoteFileNames[index], localFileNames[index]);
- }
- else {
- getDirectory(remoteFileNames[index], localFileNames[index]);
- }
- }
- }
+ // Check every remote file name provided. If file, use getfile else use
+ // getdir
+ for (int index = 0; index < remoteFileNames.length; index++) {
+ if (exists(remoteFileNames[index])) {
+ if (isDirectory(remoteFileNames[index]) == false) {
+ getFile(remoteFileNames[index], localFileNames[index]);
+ }
+ else {
+ getDirectory(remoteFileNames[index], localFileNames[index]);
+ }
+ }
+ }
- }
+ }
- /**
- * mget - Obtain multiple files from the ftp server
- */
- public void getMultipleFiles(String[] remoteFileNames, String localDirName)
- throws FileResourceException, IOException {
- for (int index = 0; index < remoteFileNames.length; index++) {
- // Extract only the file name to be appended to the destination
- // directory
- // in getfile or getdir
- String remoteFileName = remoteFileNames[index].substring(remoteFileNames[index].lastIndexOf("/") + 1);
+ /**
+ * mget - Obtain multiple files from the ftp server
+ */
+ public void getMultipleFiles(String[] remoteFileNames, String localDirName)
+ throws FileResourceException, IOException {
+ for (int index = 0; index < remoteFileNames.length; index++) {
+ // Extract only the file name to be appended to the destination
+ // directory
+ // in getfile or getdir
+ String remoteFileName = remoteFileNames[index]
+ .substring(remoteFileNames[index].lastIndexOf("/") + 1);
- if (exists(remoteFileNames[index])) {
- // Check every remote file name provided. If file, use
- // getfile else use getdir
- if (isDirectory(remoteFileNames[index]) == false) {
+ if (exists(remoteFileNames[index])) {
+ // Check every remote file name provided. If file, use
+ // getfile else use getdir
+ if (isDirectory(remoteFileNames[index]) == false) {
- getFile(remoteFileNames[index], localDirName + File.separator + remoteFileName);
- }
- else {
- getDirectory(remoteFileNames[index], localDirName + File.separator
- + remoteFileName);
- }
- }
- }
- }
+ getFile(remoteFileNames[index], localDirName
+ + File.separator + remoteFileName);
+ }
+ else {
+ getDirectory(remoteFileNames[index], localDirName
+ + File.separator + remoteFileName);
+ }
+ }
+ }
+ }
- /**
- * mput - copy multiple files to the resource
- */
- public void putMultipleFiles(String[] localFileNames, String remoteDirName)
- throws FileResourceException, IOException {
+ /**
+ * mput - copy multiple files to the resource
+ */
+ public void putMultipleFiles(String[] localFileNames, String remoteDirName)
+ throws FileResourceException, IOException {
- for (int index = 0; index < localFileNames.length; index++) {
- // Check every remote file name provided. If file, use putfile else
- // use putdir
- File localFile = new File(localFileNames[index]);
- if (!localFile.isDirectory()) {
- putFile(localFileNames[index], remoteDirName + "/" + localFile.getName());
- }
- else {
- putDirectory(localFileNames[index], remoteDirName + "/" + localFile.getName());
- }
- }
- }
+ for (int index = 0; index < localFileNames.length; index++) {
+ // Check every remote file name provided. If file, use putfile else
+ // use putdir
+ File localFile = new File(localFileNames[index]);
+ if (!localFile.isDirectory()) {
+ putFile(localFileNames[index], remoteDirName + "/"
+ + localFile.getName());
+ }
+ else {
+ putDirectory(localFileNames[index], remoteDirName + "/"
+ + localFile.getName());
+ }
+ }
+ }
- /**
- * mput - copy multiple files into the resource server
- */
- public void putMultipleFiles(String[] localFileNames, String[] remoteFileNames)
- throws FileResourceException, IOException {
- // If list of sources not equal to list of destinations then error
- if (localFileNames.length != remoteFileNames.length)
- throw new IllegalArgumentException(
- "Number of source and destination file names has to be the same");
+ /**
+ * mput - copy multiple files into the resource server
+ */
+ public void putMultipleFiles(String[] localFileNames,
+ String[] remoteFileNames) throws FileResourceException, IOException {
+ // If list of sources not equal to list of destinations then error
+ if (localFileNames.length != remoteFileNames.length)
+ throw new IllegalArgumentException(
+ "Number of source and destination file names has to be the same");
- for (int index = 0; index < localFileNames.length; index++) {
- // Check every local file name provided. If file, use putfile else
- // use putdir
- File localFile = new File(localFileNames[index]);
- if (!localFile.isDirectory()) {
- putFile(localFileNames[index], remoteFileNames[index]);
- }
- else {
- putDirectory(localFileNames[index], remoteFileNames[index]);
- }
- }
- }
+ for (int index = 0; index < localFileNames.length; index++) {
+ // Check every local file name provided. If file, use putfile else
+ // use putdir
+ File localFile = new File(localFileNames[index]);
+ if (!localFile.isDirectory()) {
+ putFile(localFileNames[index], remoteFileNames[index]);
+ }
+ else {
+ putDirectory(localFileNames[index], remoteFileNames[index]);
+ }
+ }
+ }
- public void createDirectories(String dir) throws FileResourceException,
- IOException {
- // TODO there is an assumption here on the path separators
- // I'd really suggest enforcing only one of them (hint: '/') at the
- // level of the
- // interface
- if (dir.equals("/")) {
- return;
- }
- try {
- if (!exists(dir)) {
- int i = dir.lastIndexOf('/');
- if (i <= 0) {
- createDirectory(dir);
- }
- else {
- createDirectories(dir.substring(0, i));
- if (i != dir.length() - 1) {
- createDirectory(dir);
- }
- else {
- // trailing '/'
- }
- }
- }
- }
- catch (FileResourceException e) {
- if (!isDirectory(dir)) {
- throw e;
- }
- }
- }
+ public void createDirectories(String dir) throws FileResourceException,
+ IOException {
+ // TODO there is an assumption here on the path separators
+ // I'd really suggest enforcing only one of them (hint: '/') at the
+ // level of the
+ // interface
+ if (dir.equals("/")) {
+ return;
+ }
+ try {
+ if (!exists(dir)) {
+ int i = dir.lastIndexOf('/');
+ if (i <= 0) {
+ createDirectory(dir);
+ }
+ else {
+ createDirectories(dir.substring(0, i));
+ if (i != dir.length() - 1) {
+ createDirectory(dir);
+ }
+ else {
+ // trailing '/'
+ }
+ }
+ }
+ }
+ catch (FileResourceException e) {
+ if (!isDirectory(dir)) {
+ throw e;
+ }
+ }
+ }
}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2006-11-28 22:39:18 UTC (rev 1428)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2006-11-28 22:42:39 UTC (rev 1429)
@@ -25,73 +25,76 @@
import org.globus.cog.abstraction.interfaces.Task;
public class CachingDelegatedFileOperationHandler extends TaskHandlerImpl {
- private FileResource resource;
+ private FileResource resource;
- public synchronized void submit(Task task) throws IllegalSpecException,
- InvalidSecurityContextException, InvalidServiceContactException,
- TaskSubmissionException {
- Service service = task.getService(0);
- if (service == null) {
- setTaskStatus(task, Status.FAILED, null, "Service is not set");
- throw new IllegalSpecException("Service is not set");
- }
- try {
- super.submit(task, getResource(service));
- setTaskStatus(task, Status.COMPLETED, null, null);
- }
- catch (TaskSubmissionException e) {
- setTaskStatus(task, Status.FAILED, e, e.getMessage());
- throw e;
- }
- catch (IllegalSpecException e) {
- setTaskStatus(task, Status.FAILED, e, e.getMessage());
- throw e;
- }
- catch (Exception e) {
- setTaskStatus(task, Status.FAILED, e, e.getMessage());
- throw new TaskSubmissionException(e.getMessage(), e);
- }
- finally {
- stopResources();
- }
- }
+ public synchronized void submit(Task task) throws IllegalSpecException,
+ InvalidSecurityContextException, InvalidServiceContactException,
+ TaskSubmissionException {
+ Service service = task.getService(0);
+ if (service == null) {
+ setTaskStatus(task, Status.FAILED, null, "Service is not set");
+ throw new IllegalSpecException("Service is not set");
+ }
+ try {
+ super.submit(task, getResource(service));
+ setTaskStatus(task, Status.COMPLETED, null, null);
+ }
+ catch (TaskSubmissionException e) {
+ setTaskStatus(task, Status.FAILED, e, e.getMessage());
+ throw e;
+ }
+ catch (IllegalSpecException e) {
+ setTaskStatus(task, Status.FAILED, e, e.getMessage());
+ throw e;
+ }
+ catch (Exception e) {
+ setTaskStatus(task, Status.FAILED, e, e.getMessage());
+ throw new TaskSubmissionException(e.getMessage(), e);
+ }
+ finally {
+ stopResources();
+ }
+ }
- protected void setTaskStatus(Task task, int statusCode, Exception exception, String message) {
- Status status = new StatusImpl();
- status.setStatusCode(statusCode);
- status.setException(exception);
- status.setMessage(message);
- task.setStatus(status);
- }
+ protected void setTaskStatus(Task task, int statusCode,
+ Exception exception, String message) {
+ Status status = new StatusImpl();
+ status.setStatusCode(statusCode);
+ status.setException(exception);
+ status.setMessage(message);
+ task.setStatus(status);
+ }
- protected FileResource getResource(Service service) throws InvalidProviderException,
- ProviderMethodException, IllegalHostException, InvalidSecurityContextException,
- FileResourceException, IOException {
- resource = FileResourceCache.getDefault().getResource(service);
- return resource;
- }
+ protected FileResource getResource(Service service)
+ throws InvalidProviderException, ProviderMethodException,
+ IllegalHostException, InvalidSecurityContextException,
+ FileResourceException, IOException {
+ resource = FileResourceCache.getDefault().getResource(service);
+ return resource;
+ }
- public void stopResources() {
- if (resource == null) {
- return;
- }
- FileResourceCache.getDefault().releaseResource(resource);
- resource = null;
- }
+ public void stopResources() {
+ if (resource == null) {
+ return;
+ }
+ FileResourceCache.getDefault().releaseResource(resource);
+ resource = null;
+ }
- protected Object execute(FileResource fileResource, FileOperationSpecification spec)
- throws FileResourceException, IOException {
- Object ret;
- try {
- ret = super.execute(fileResource, spec);
- }
- finally {
- stopResources();
- }
- return ret;
- }
+ protected Object execute(FileResource fileResource,
+ FileOperationSpecification spec) throws FileResourceException,
+ IOException {
+ Object ret;
+ try {
+ ret = super.execute(fileResource, spec);
+ }
+ finally {
+ stopResources();
+ }
+ return ret;
+ }
- protected FileResource getResource() {
- return resource;
- }
+ protected FileResource getResource() {
+ return resource;
+ }
}
\ No newline at end of file
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java 2006-11-28 22:39:18 UTC (rev 1428)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/DirectoryNotFoundException.java 2006-11-28 22:42:39 UTC (rev 1429)
@@ -4,25 +4,20 @@
// This message may not be removed or altered.
// ----------------------------------------------------------------------
-
-
package org.globus.cog.abstraction.impl.file;
-
/**
- * Directory not found exception to be thrown when the directory being accessed does not exist
+ * Directory not found exception to be thrown when the directory being accessed
+ * does not exist
*/
-public class DirectoryNotFoundException extends FileResourceException
-{
- /** Set a string message to the exception */
- public DirectoryNotFoundException(String message)
- {
+public class DirectoryNotFoundException extends FileResourceException {
+ /** Set a string message to the exception */
+ public DirectoryNotFoundException(String message) {
super(message);
}
/** Set a message and throwable for the exception */
- public DirectoryNotFoundException(String message, Throwable parent)
- {
+ public DirectoryNotFoundException(String message, Throwable parent) {
super(message, parent);
}
}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java 2006-11-28 22:39:18 UTC (rev 1428)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileNotFoundException.java 2006-11-28 22:42:39 UTC (rev 1429)
@@ -4,25 +4,20 @@
// This message may not be removed or altered.
// ----------------------------------------------------------------------
-
-
package org.globus.cog.abstraction.impl.file;
-
/**
- * File not found exception to be thrown when the file being accessed does not exist
+ * File not found exception to be thrown when the file being accessed does not
+ * exist
*/
-public class FileNotFoundException extends FileResourceException
-{
- /** Set a string message to the exception */
- public FileNotFoundException(String message)
- {
+public class FileNotFoundException extends FileResourceException {
+ /** Set a string message to the exception */
+ public FileNotFoundException(String message) {
super(message);
}
- /** Set a message and throwable for the exception */
- public FileNotFoundException(String message, Throwable parent)
- {
+ /** Set a message and throwable for the exception */
+ public FileNotFoundException(String message, Throwable parent) {
super(message, parent);
}
}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2006-11-28 22:39:18 UTC (rev 1428)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2006-11-28 22:42:39 UTC (rev 1429)
@@ -31,270 +31,280 @@
import org.globus.cog.abstraction.interfaces.ServiceContact;
public class FileResourceCache {
- private static Logger logger = Logger.getLogger(FileResourceCache.class);
+ private static Logger logger = Logger.getLogger(FileResourceCache.class);
- private static FileResourceCache defaultFileResourceCache;
+ private static FileResourceCache defaultFileResourceCache;
- private static int DEFAULT_MAX_IDLE_RESOURCES = 20;
- private static long DEFAULT_MAX_IDLE_TIME = 120000;
+ private static int DEFAULT_MAX_IDLE_RESOURCES = 20;
+ private static long D...
[truncated message content] |
|
From: <ha...@us...> - 2007-01-28 17:26:45
|
Revision: 1550
http://svn.sourceforge.net/cogkit/?rev=1550&view=rev
Author: hategan
Date: 2007-01-28 09:26:42 -0800 (Sun, 28 Jan 2007)
Log Message:
-----------
exceptions...
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java
Added Paths:
-----------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IrrecoverableResourceException.java
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java 2007-01-28 17:24:52 UTC (rev 1549)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/AbstractFileResource.java 2007-01-28 17:26:42 UTC (rev 1550)
@@ -10,7 +10,6 @@
package org.globus.cog.abstraction.impl.file;
import java.io.File;
-import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -122,7 +121,7 @@
/** Equivalent to the cp -r command for copying directories */
public void getDirectory(String remoteDirName, String localDirName)
- throws FileResourceException, IOException {
+ throws FileResourceException {
File localDir = new File(localDirName);
GridFile gridFile = null;
@@ -150,7 +149,7 @@
/** Equivalent to cp -r command for copying directories */
public void putDirectory(String localDirName, String remoteDirName)
- throws FileResourceException, IOException {
+ throws FileResourceException {
File localDir = new File(localDirName);
if (!localDir.exists()) {
throw new DirectoryNotFoundException("Local directory not found");
@@ -193,7 +192,7 @@
* mget - Obtain multiple files from the remote server
*/
public void getMultipleFiles(String[] remoteFileNames,
- String[] localFileNames) throws FileResourceException, IOException {
+ String[] localFileNames) throws FileResourceException {
// If the list of sources not equal to destination lists then error
if (localFileNames.length != remoteFileNames.length)
@@ -219,7 +218,7 @@
* mget - Obtain multiple files from the ftp server
*/
public void getMultipleFiles(String[] remoteFileNames, String localDirName)
- throws FileResourceException, IOException {
+ throws FileResourceException {
for (int index = 0; index < remoteFileNames.length; index++) {
// Extract only the file name to be appended to the destination
// directory
@@ -247,7 +246,7 @@
* mput - copy multiple files to the resource
*/
public void putMultipleFiles(String[] localFileNames, String remoteDirName)
- throws FileResourceException, IOException {
+ throws FileResourceException {
for (int index = 0; index < localFileNames.length; index++) {
// Check every remote file name provided. If file, use putfile else
@@ -268,7 +267,7 @@
* mput - copy multiple files into the resource server
*/
public void putMultipleFiles(String[] localFileNames,
- String[] remoteFileNames) throws FileResourceException, IOException {
+ String[] remoteFileNames) throws FileResourceException {
// If list of sources not equal to list of destinations then error
if (localFileNames.length != remoteFileNames.length)
throw new IllegalArgumentException(
@@ -287,8 +286,7 @@
}
}
- public void createDirectories(String dir) throws FileResourceException,
- IOException {
+ public void createDirectories(String dir) throws FileResourceException {
// TODO there is an assumption here on the path separators
// I'd really suggest enforcing only one of them (hint: '/') at the
// level of the
Added: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IrrecoverableResourceException.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IrrecoverableResourceException.java (rev 0)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/IrrecoverableResourceException.java 2007-01-28 17:26:42 UTC (rev 1550)
@@ -0,0 +1,35 @@
+//----------------------------------------------------------------------
+//This code is developed as part of the Java CoG Kit project
+//The terms of the license can be found at http://www.cogkit.org/license
+//This message may not be removed or altered.
+//----------------------------------------------------------------------
+
+/*
+ * Created on Jan 27, 2007
+ */
+package org.globus.cog.abstraction.impl.file;
+
+/**
+ * Signifies an exception that puts a file resource in an irrecoverable
+ * state. If a resource throws this exception during a request, future
+ * requests on this resource will will fail or cause unpredictable
+ * behavior.
+ */
+public class IrrecoverableResourceException extends FileResourceException {
+
+ public IrrecoverableResourceException() {
+ super();
+ }
+
+ public IrrecoverableResourceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public IrrecoverableResourceException(String message) {
+ super(message);
+ }
+
+ public IrrecoverableResourceException(Throwable cause) {
+ super(cause);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ha...@us...> - 2007-01-28 17:31:59
|
Revision: 1551
http://svn.sourceforge.net/cogkit/?rev=1551&view=rev
Author: hategan
Date: 2007-01-28 09:31:47 -0800 (Sun, 28 Jan 2007)
Log Message:
-----------
deal better with irrecoverable errors
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2007-01-28 17:26:42 UTC (rev 1550)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2007-01-28 17:31:47 UTC (rev 1551)
@@ -35,8 +35,10 @@
setTaskStatus(task, Status.FAILED, null, "Service is not set");
throw new IllegalSpecException("Service is not set");
}
+ FileResource fr = null;
try {
- super.submit(task, getResource(service));
+ fr = getResource(service);
+ super.submit(task, fr);
setTaskStatus(task, Status.COMPLETED, null, null);
}
catch (TaskSubmissionException e) {
@@ -47,6 +49,10 @@
setTaskStatus(task, Status.FAILED, e, e.getMessage());
throw e;
}
+ catch (IrrecoverableResourceException e) {
+ FileResourceCache.getDefault().invalidateResource(resource);
+ setTaskStatus(task, Status.FAILED, e, e.getMessage());
+ }
catch (Exception e) {
setTaskStatus(task, Status.FAILED, e, e.getMessage());
throw new TaskSubmissionException(e.getMessage(), e);
@@ -65,7 +71,7 @@
task.setStatus(status);
}
- protected FileResource getResource(Service service)
+ protected synchronized FileResource getResource(Service service)
throws InvalidProviderException, ProviderMethodException,
IllegalHostException, InvalidSecurityContextException,
FileResourceException, IOException {
@@ -73,7 +79,7 @@
return resource;
}
- public void stopResources() {
+ public synchronized void stopResources() {
if (resource == null) {
return;
}
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2007-01-28 17:26:42 UTC (rev 1550)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java 2007-01-28 17:31:47 UTC (rev 1551)
@@ -48,6 +48,7 @@
private LinkedList order;
private Map releaseTimes;
private Map fileResources;
+ private Set invalid;
private Set inUse;
private Timer timer;
private int maxIdleResources = DEFAULT_MAX_IDLE_RESOURCES;
@@ -57,6 +58,7 @@
public FileResourceCache() {
fileResources = new Hashtable();
inUse = new HashSet();
+ invalid = new HashSet();
order = new LinkedList();
releaseTimes = new Hashtable();
stopper = new ResourceStopper();
@@ -83,7 +85,8 @@
order.remove(fileResource);
releaseTimes.remove(fileResource);
if (logger.isDebugEnabled()) {
- logger.debug("Found cached resource");
+ logger.debug("Found cached resource ("
+ + fileResource + ")");
}
return fileResource;
}
@@ -142,7 +145,7 @@
synchronized (this) {
if (logger.isDebugEnabled()) {
logger.debug("Releasing resource for "
- + resource.getServiceContact());
+ + resource.getServiceContact() + " (" + resource + ")");
}
/*
* if (!inUse.contains(resource)) { throw new
@@ -150,13 +153,19 @@
* use"); }
*/
if (inUse.remove(resource)) {
- order.addLast(resource);
- releaseTimes
- .put(resource, new Long(System.currentTimeMillis()));
- if (logger.isDebugEnabled()) {
- logger.debug("Resource successfully released");
- lastRelease = new Throwable();
+ if (invalid.remove(resource)) {
+ removeResource(resource);
}
+ else {
+ order.addLast(resource);
+ releaseTimes.put(resource, new Long(System
+ .currentTimeMillis()));
+ if (logger.isDebugEnabled()) {
+ logger.debug("Resource (" + resource
+ + ") successfully released");
+ lastRelease = new Throwable();
+ }
+ }
}
else {
if (logger.isDebugEnabled()) {
@@ -169,6 +178,10 @@
}
}
+ public synchronized void invalidateResource(FileResource resource) {
+ invalid.add(resource);
+ }
+
private void removeResource(FileResource resource) {
synchronized (this) {
if (fileResources.containsKey(resource.getServiceContact())) {
@@ -214,7 +227,7 @@
this.maxIdleTime = maxIdleTime;
}
- private void checkTimer() {
+ private synchronized void checkTimer() {
if (timer == null) {
timer = new Timer(true);
timer.schedule(new ResourceSwipe(this), 60000, 60000);
@@ -284,7 +297,7 @@
fr.stop();
}
catch (Exception e) {
- logger.warn("Failed to stop resource", e);
+ logger.info("Failed to stop resource", e);
}
fr = nextResource();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ha...@us...> - 2008-02-12 17:11:15
|
Revision: 1886
http://cogkit.svn.sourceforge.net/cogkit/?rev=1886&view=rev
Author: hategan
Date: 2008-02-12 09:11:11 -0800 (Tue, 12 Feb 2008)
Log Message:
-----------
...
Modified Paths:
--------------
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/fileTransfer/DelegatedFileTransferHandler.java
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2008-02-12 17:10:23 UTC (rev 1885)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/CachingDelegatedFileOperationHandler.java 2008-02-12 17:11:11 UTC (rev 1886)
@@ -30,6 +30,7 @@
public synchronized void submit(Task task) throws IllegalSpecException,
InvalidSecurityContextException, InvalidServiceContactException,
TaskSubmissionException {
+ task.setStatus(Status.SUBMITTING);
Service service = task.getService(0);
if (service == null) {
throw new IllegalSpecException("Service is not set");
Modified: trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/fileTransfer/DelegatedFileTransferHandler.java
===================================================================
--- trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/fileTransfer/DelegatedFileTransferHandler.java 2008-02-12 17:10:23 UTC (rev 1885)
+++ trunk/current/src/cog/modules/abstraction-common/src/org/globus/cog/abstraction/impl/fileTransfer/DelegatedFileTransferHandler.java 2008-02-12 17:11:11 UTC (rev 1886)
@@ -10,7 +10,6 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Enumeration;
-import java.util.GregorianCalendar;
import org.apache.log4j.Logger;
import org.globus.cog.abstraction.impl.common.AbstractionFactory;
@@ -467,6 +466,7 @@
}
public void run() {
+ this.task.setStatus(Status.ACTIVE);
// todo retreive progress markers
if (this.thirdparty) {
doThirdPartyTransfer();
@@ -583,7 +583,6 @@
status.setPrevStatusCode(this.task.getStatus().getStatusCode());
status.setStatusCode(Status.FAILED);
status.setException(e);
- status.setTime(new GregorianCalendar());
this.task.setStatus(status);
stopResources();
if (logger.isDebugEnabled()) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|