|
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 FileResource fileResource = null;
- /** set type of task handler */
- public void setType(int type) {
- this.type = type;
- }
+ static Logger logger = Logger.getLogger(TaskHandlerImpl.class.getName());
- /** return type of task handler */
- public int getType() {
- return this.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();
+ }
- /**
- * submit the task for execution. Synchronized because additions and
- * deletions are made to the same data resource
- */
- public synchronized void submit(Task task) throws IllegalSpecException,
- InvalidSecurityContextException, InvalidServiceContactException,
- TaskSubmissionException {
- FileResource fileResource = null;
- if (task.getStatus().getStatusCode() != Status.UNSUBMITTED) {
- throw new TaskSubmissionException(
- "TaskHandler can execute only UNSUBMITTED tasks.");
- }
+ /** set type of task handler */
+ public void setType(int type) {
+ this.type = type;
+ }
- try {
- this.task = task;
- task.setStatus(Status.SUBMITTED);
- FileOperationSpecification spec = (FileOperationSpecification) task
- .getSpecification();
+ /** return type of task handler */
+ public int getType() {
+ return this.type;
+ }
- if (spec.getOperation().equalsIgnoreCase(
- FileOperationSpecification.START)) {
- // if the operation is "start", then always create a new
- // FileResource
- submit(task, null);
- } else {
+ /**
+ * submit the task for execution. Synchronized because additions and
+ * deletions are made to the same data resource
+ */
+ public synchronized void submit(Task task) throws IllegalSpecException,
+ InvalidSecurityContextException, InvalidServiceContactException,
+ TaskSubmissionException {
+ FileResource fileResource = null;
+ if (task.getStatus().getStatusCode() != Status.UNSUBMITTED) {
+ throw new TaskSubmissionException("TaskHandler can execute only UNSUBMITTED tasks.");
+ }
- /*
- * Obtain the file resource corresponding to the sessionid or
- * the default resource for all other operations
- */
- Identity identity = (Identity) task.getAttribute("sessionID");
- if (identity != null) {
- fileResource = (FileResource) this.activeFileResources
- .get(identity);
- } else {
- if (this.defaultSessionId != null) {
- fileResource = (FileResource) this.activeFileResources
- .get(this.defaultSessionId);
- } else {
- throw new TaskSubmissionException(
- "No default active connection available");
- }
- }
+ try {
+ this.task = task;
+ task.setStatus(Status.SUBMITTED);
+ FileOperationSpecification spec = (FileOperationSpecification) task.getSpecification();
- // if found file resource, submit task to file resource
- if (fileResource != null) {
- submit(task, fileResource);
- } else {
- throw new TaskSubmissionException(
- "Corresponding connection not active");
- }
- }
- } catch (Exception e) {
- Status status = new StatusImpl();
- status.setStatusCode(Status.FAILED);
- status.setException(e);
- task.setStatus(status);
- return;
- }
- task.setStatus(Status.COMPLETED);
- }
+ if (spec.getOperation().equalsIgnoreCase(FileOperationSpecification.START)) {
+ // if the operation is "start", then always create a new
+ // FileResource
+ submit(task, null);
+ }
+ else {
- /**
- * submit task to the appropriate file resource to carry out the operation.
- * Called from submit(Task)
- *
- * @throws TaskSubmissionException
- * @throws IllegalSpecException
- * @throws InvalidProviderException
- * @throws ProviderMethodException
- * @throws InvalidSecurityContextException
- * @throws IllegalHostException
- * @throws GeneralException
- * @throws FileNotFoundException
- * @throws DirectoryNotFoundException
- */
- public void submit(Task task, FileResource fileResource)
- throws TaskSubmissionException, IllegalSpecException,
- InvalidProviderException, ProviderMethodException,
- IllegalHostException, InvalidSecurityContextException,
- DirectoryNotFoundException, FileNotFoundException, GeneralException {
+ /*
+ * Obtain the file resource corresponding to the sessionid or
+ * the default resource for all other operations
+ */
+ Identity identity = (Identity) task.getAttribute("sessionID");
+ if (identity != null) {
+ fileResource = (FileResource) this.activeFileResources.get(identity);
+ }
+ else {
+ if (this.defaultSessionId != null) {
+ fileResource = (FileResource) this.activeFileResources.get(this.defaultSessionId);
+ }
+ else {
+ throw new TaskSubmissionException("No default active connection available");
+ }
+ }
- this.task = task;
+ // if found file resource, submit task to file resource
+ if (fileResource != null) {
+ submit(task, fileResource);
+ }
+ else {
+ throw new TaskSubmissionException("Corresponding connection not active");
+ }
+ }
+ }
+ catch (Exception e) {
+ Status status = new StatusImpl();
+ status.setStatusCode(Status.FAILED);
+ status.setException(e);
+ task.setStatus(status);
+ return;
+ }
+ task.setStatus(Status.COMPLETED);
+ }
- FileOperationSpecification spec = (FileOperationSpecification) this.task
- .getSpecification();
+ /**
+ * submit task to the appropriate file resource to carry out the operation.
+ * Called from submit(Task)
+ *
+ * @throws TaskSubmissionException
+ * @throws IllegalSpecException
+ * @throws InvalidProviderException
+ * @throws ProviderMethodException
+ * @throws InvalidSecurityContextException
+ * @throws IllegalHostException
+ * @throws GeneralException
+ * @throws FileNotFoundException
+ * @throws DirectoryNotFoundException
+ */
+ public void submit(Task task, FileResource fileResource) throws TaskSubmissionException,
+ IllegalSpecException, InvalidProviderException, ProviderMethodException,
+ IllegalHostException, InvalidSecurityContextException, FileResourceException,
+ IOException {
- if (task.getStatus().getStatusCode() == Status.CANCELED)
- throw new TaskSubmissionException("Task has been canceled");
- task.setStatus(Status.ACTIVE);
+ this.task = task;
- if (spec.getOperation().equalsIgnoreCase(
- FileOperationSpecification.START)) {
- // check if the security context and service contact attributes are
- // present
- if (!isValidSpecification(spec)) {
- throw new IllegalSpecException(
- "Invalid security context or service contact");
- }
+ FileOperationSpecification spec = (FileOperationSpecification) this.task.getSpecification();
- String provider = task.getProvider();
- if (provider == null) {
- throw new InvalidProviderException("Provider not available");
- }
- provider = provider.toLowerCase();
- fileResource = AbstractionFactory.newFileResource(provider);
- if (fileResource == null) {
- throw new InvalidProviderException("Invalid provider");
- }
+ if (task.getStatus().getStatusCode() == Status.CANCELED)
+ throw new TaskSubmissionException("Task has been canceled");
+ task.setStatus(Status.ACTIVE);
- fileResource.setServiceContact(task.getService(0)
- .getServiceContact());
- fileResource.setSecurityContext(getSecurityContext());
- fileResource.start();
- Identity sessionId = new IdentityImpl();
- task.setAttribute("output", sessionId);
- this.activeFileResources.put(sessionId, fileResource);
- if (this.defaultSessionId == null) {
- this.defaultSessionId = sessionId;
- }
+ if (spec.getOperation().equalsIgnoreCase(FileOperationSpecification.START)) {
+ // check if the security context and service contact attributes are
+ // present
+ if (!isValidSpecification(spec)) {
+ throw new IllegalSpecException("Invalid security context or service contact");
+ }
- } else if (spec.getOperation().equalsIgnoreCase(
- FileOperationSpecification.STOP)) {
- fileResource.stop();
- Identity identity = (Identity) this.task.getAttribute("sessionID");
- this.activeFileResources.remove(identity);
- if (this.defaultSessionId.equals(identity)) {
- this.defaultSessionId = null;
- }
+ String provider = task.getProvider();
+ if (provider == null) {
+ throw new InvalidProviderException("Provider not available");
+ }
+ provider = provider.toLowerCase();
+ fileResource = AbstractionFactory.newFileResource(provider);
+ if (fileResource == null) {
+ throw new InvalidProviderException("Invalid provider");
+ }
- } else {
- if (!isValidSpecification(spec)) {
- throw new IllegalSpecException(
- "Either "
- + spec.getOperation()
- + " is not a valid command or it is not supported with "
- + spec.getArgumentSize() + " arguments");
- }
- Object output = execute(fileResource, spec);
- if (output != null) {
- task.setAttribute("output", output);
- }
- }
- }
+ fileResource.setServiceContact(task.getService(0).getServiceContact());
+ fileResource.setSecurityContext(getSecurityContext());
+ fileResource.start();
+ Identity sessionId = new IdentityImpl();
+ task.setAttribute("output", sessionId);
+ this.activeFileResources.put(sessionId, fileResource);
+ if (this.defaultSessionId == null) {
+ this.defaultSessionId = sessionId;
+ }
- /**
- * execute the command on the file resource. Called from submit(Task,
- * FileResource)
- *
- * @throws GeneralException
- * @throws DirectoryNotFoundException
- * @throws GeneralException
- * @throws FileNotFoundException
- */
- protected Object execute(FileResource fileResource,
- FileOperationSpecification spec) throws DirectoryNotFoundException,
- FileNotFoundException, GeneralException {
- Object output = null;
- String operation = spec.getOperation();
- try {
- //System.err.println(operation + " + " + Thread.currentThread());
- if (operation.equalsIgnoreCase(FileOperationSpecification.LS)
- && spec.getArgumentSize() == 0) {
- output = fileResource.list();
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.LS)
- && spec.getArgumentSize() == 1) {
- output = fileResource.list(spec.getArgument(0));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.PWD)) {
- output = fileResource.getCurrentDirectory();
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.CD)
- && spec.getArgumentSize() == 1) {
- fileResource.setCurrentDirectory(spec.getArgument(0));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.MKDIR)
- && 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
- .valueOf(spec.getArgument(1)).booleanValue());
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.RMFILE)
- && spec.getArgumentSize() == 1) {
- fileResource.deleteFile(spec.getArgument(0));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.ISDIRECTORY)
- && spec.getArgumentSize() == 1) {
- output = Boolean.valueOf(fileResource.isDirectory(spec
- .getArgument(0)));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.EXISTS)
- && spec.getArgumentSize() == 1) {
- output = Boolean.valueOf(fileResource.exists(spec
- .getArgument(0)));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.GETFILE)
- && spec.getArgumentSize() == 2) {
- fileResource.getFile(spec.getArgument(0), spec.getArgument(1));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.PUTFILE)
- && spec.getArgumentSize() == 2) {
- fileResource.putFile(spec.getArgument(0), spec.getArgument(1));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.GETDIR)
- && spec.getArgumentSize() == 2) {
- fileResource.getDirectory(spec.getArgument(0), spec
- .getArgument(1));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.PUTDIR)
- && spec.getArgumentSize() == 2) {
- fileResource.putDirectory(spec.getArgument(0), spec
- .getArgument(1));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.RENAME)
- && spec.getArgumentSize() == 2) {
- fileResource.rename(spec.getArgument(0), spec.getArgument(1));
- } else if (operation
- .equalsIgnoreCase(FileOperationSpecification.CHMOD)
- && spec.getArgumentSize() == 2) {
- fileResource.changeMode(spec.getArgument(0), Integer.valueOf(
- spec.getArgument(1)).intValue());
- }
- return output;
- } finally {
- //System.err.println(operation + " - " + Thread.currentThread());
- }
- }
+ }
+ else if (spec.getOperation().equalsIgnoreCase(FileOperationSpecification.STOP)) {
+ fileResource.stop();
+ Identity identity = (Identity) this.task.getAttribute("sessionID");
+ this.activeFileResources.remove(identity);
+ if (this.defaultSessionId.equals(identity)) {
+ this.defaultSessionId = null;
+ }
- /** is the specification valid */
- public boolean isValidSpecification(FileOperationSpecification spec) {
+ }
+ else {
+ if (!isValidSpecification(spec)) {
+ throw new IllegalSpecException("Either " + spec.getOperation()
+ + " is not a valid command or it is not supported with "
+ + spec.getArgumentSize() + " arguments");
+ }
+ Object output = execute(fileResource, spec);
+ if (output != null) {
+ task.setAttribute("output", output);
+ }
+ }
+ }
- if (spec.getOperation().equalsIgnoreCase(
- FileOperationSpecification.START) == true) {
- if (task.getService(0).getServiceContact() == null) {
- return false;
- }
- if (task.getService(0).getSecurityContext() == null) {
- return false;
- }
- }
+ /**
+ * execute the command on the file resource. Called from submit(Task,
+ * FileResource)
+ *
+ * @throws GeneralException
+ * @throws DirectoryNotFoundException
+ * @throws GeneralException
+ * @throws FileNotFoundException
+ */
+ protected Object execute(FileResource fileResource, FileOperationSpecification spec)
+ throws FileResourceException, IOException {
+ Object output = null;
+ String operation = spec.getOperation();
+ try {
+ // System.err.println(operation + " + " + Thread.currentThread());
+ if (operation.equalsIgnoreCase(FileOperationSpecification.LS)
+ && spec.getArgumentSize() == 0) {
+ output = fileResource.list();
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.LS)
+ && spec.getArgumentSize() == 1) {
+ output = fileResource.list(spec.getArgument(0));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.PWD)) {
+ output = fileResource.getCurrentDirectory();
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.CD)
+ && spec.getArgumentSize() == 1) {
+ fileResource.setCurrentDirectory(spec.getArgument(0));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.MKDIR)
+ && 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.valueOf(
+ spec.getArgument(1)).booleanValue());
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.RMFILE)
+ && spec.getArgumentSize() == 1) {
+ fileResource.deleteFile(spec.getArgument(0));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.ISDIRECTORY)
+ && spec.getArgumentSize() == 1) {
+ output = Boolean.valueOf(fileResource.isDirectory(spec.getArgument(0)));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.EXISTS)
+ && spec.getArgumentSize() == 1) {
+ output = Boolean.valueOf(fileResource.exists(spec.getArgument(0)));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.GETFILE)
+ && spec.getArgumentSize() == 2) {
+ fileResource.getFile(spec.getArgument(0), spec.getArgument(1));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.PUTFILE)
+ && spec.getArgumentSize() == 2) {
+ fileResource.putFile(spec.getArgument(0), spec.getArgument(1));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.GETDIR)
+ && spec.getArgumentSize() == 2) {
+ fileResource.getDirectory(spec.getArgument(0), spec.getArgument(1));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.PUTDIR)
+ && spec.getArgumentSize() == 2) {
+ fileResource.putDirectory(spec.getArgument(0), spec.getArgument(1));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.RENAME)
+ && spec.getArgumentSize() == 2) {
+ fileResource.rename(spec.getArgument(0), spec.getArgument(1));
+ }
+ else if (operation.equalsIgnoreCase(FileOperationSpecification.CHMOD)
+ && spec.getArgumentSize() == 2) {
+ fileResource.changeMode(spec.getArgument(0),
+ Integer.valueOf(spec.getArgument(1)).intValue());
+ }
+ return output;
+ }
+ finally {
+ // System.err.println(operation + " - " + Thread.currentThread());
+ }
+ }
- if ((spec.getArgumentSize() == 0)
- && !oneWordCommands.contains(spec.getOperation())) {
- return false;
- } else if ((spec.getArgumentSize() == 1)
- && !twoWordCommands.contains(spec.getOperation())) {
- return false;
- } else if ((spec.getArgumentSize() == 2)
- && !threeWordCommands.contains(spec.getOperation())) {
- return false;
- } else {
- return true;
- }
- }
+ /** is the specification valid */
+ public boolean isValidSpecification(FileOperationSpecification spec) {
- /** Suspend a task */
- public void suspend(Task task) throws InvalidSecurityContextException,
- TaskSubmissionException {
- }
+ if (spec.getOperation().equalsIgnoreCase(FileOperationSpecification.START) == true) {
+ if (task.getService(0).getServiceContact() == null) {
+ return false;
+ }
+ if (task.getService(0).getSecurityContext() == null) {
+ return false;
+ }
+ }
- /** resume a task */
- public void resume(Task task) throws InvalidSecurityContextException,
- TaskSubmissionException {
- }
+ if ((spec.getArgumentSize() == 0) && !oneWordCommands.contains(spec.getOperation())) {
+ return false;
+ }
+ else if ((spec.getArgumentSize() == 1) && !twoWordCommands.contains(spec.getOperation())) {
+ return false;
+ }
+ else if ((spec.getArgumentSize() == 2) && !threeWordCommands.contains(spec.getOperation())) {
+ return false;
+ }
+ else {
+ return true;
+ }
+ }
- /** cancel a task */
- public void cancel(Task task) throws InvalidSecurityContextException,
- TaskSubmissionException {
- if (task.getStatus().getStatusCode() >= Status.FAILED) {
- throw new TaskSubmissionException(
- "Cancel cannot be performed on tasks that are not active");
- }
- if (task.getStatus().getStatusCode() <= Status.SUBMITTED) {
- task.setStatus(Status.CANCELED);
- } else {
- try {
- String currentDirectory = fileResource.getCurrentDirectory();
- fileResource.stop();
- fileResource.start();
- fileResource.setCurrentDirectory(currentDirectory);
- task.setStatus(Status.CANCELED);
- } catch (Exception e) {
- throw new TaskSubmissionException(
- "Exception in File TaskHandler while performing cancel",
- e);
- }
- }
- }
+ /** Suspend a task */
+ public void suspend(Task task) throws InvalidSecurityContextException, TaskSubmissionException {
+ }
- /** remove a task completely */
- public void remove(Task task) throws ActiveTaskException {
- if (!handleMap.containsKey(task)) {
- return;
- }
- int status = task.getStatus().getStatusCode();
- if ((status == Status.ACTIVE) || (status == Status.SUSPENDED)) {
- throw new ActiveTaskException(
- "Cannot remove an active or suspended Task");
- } else {
- this.failedList.remove(task);
- this.canceledList.remove(task);
- this.completedList.remove(task);
- this.activeList.remove(task);
- this.suspendedList.remove(task);
- this.submittedList.remove(task);
- this.handleMap.remove(task);
- }
- }
+ /** resume a task */
+ public void resume(Task task) throws InvalidSecurityContextException, TaskSubmissionException {
+ }
- /** return a collection of all tasks submitted to the handler */
- public Collection getAllTasks() {
- try {
- return new ArrayList(handleMap.keySet());
- } catch (Exception e) {
- return null;
- }
- }
+ /** cancel a task */
+ public void cancel(Task task) throws InvalidSecurityContextException, TaskSubmissionException {
+ if (task.getStatus().getStatusCode() >= Status.FAILED) {
+ throw new TaskSubmissionException(
+ "Cancel cannot be performed on tasks that are not active");
+ }
+ if (task.getStatus().getStatusCode() <= Status.SUBMITTED) {
+ task.setStatus(Status.CANCELED);
+ }
+ else {
+ try {
+ String currentDirectory = fileResource.getCurrentDirectory();
+ fileResource.stop();
+ fileResource.start();
+ fileResource.setCurrentDirectory(currentDirectory);
+ task.setStatus(Status.CANCELED);
+ }
+ catch (Exception e) {
+ throw new TaskSubmissionException(
+ "Exception in File TaskHandler while performing cancel", e);
+ }
+ }
+ }
- /** return a collection of active tasks */
- public Collection getActiveTasks() {
- return new ArrayList(this.activeList);
- }
+ /** remove a task completely */
+ public void remove(Task task) throws ActiveTaskException {
+ if (!handleMap.containsKey(task)) {
+ return;
+ }
+ int status = task.getStatus().getStatusCode();
+ if ((status == Status.ACTIVE) || (status == Status.SUSPENDED)) {
+ throw new ActiveTaskException("Cannot remove an active or suspended Task");
+ }
+ else {
+ this.failedList.remove(task);
+ this.canceledList.remove(task);
+ this.completedList.remove(task);
+ this.activeList.remove(task);
+ this.suspendedList.remove(task);
+ this.submittedList.remove(task);
+ this.handleMap.remove(task);
+ }
+ }
- /** return a collection of failed tasks */
- public Collection getFailedTasks() {
- return new ArrayList(this.failedList);
- }
+ /** return a collection of all tasks submitted to the handler */
+ public Collection getAllTasks() {
+ try {
+ return new ArrayList(handleMap.keySet());
+ }
+ catch (Exception e) {
+ return null;
+ }
+ }
- /** return a collection of completed tasks */
- public Collection getCompletedTasks() {
- return new ArrayList(this.completedList);
- }
+ /** return a collection of active tasks */
+ public Collection getActiveTasks() {
+ return new ArrayList(this.activeList);
+ }
- /** return a collection of suspended tasks */
- public Collection getSuspendedTasks() {
- return new ArrayList(this.suspendedList);
- }
+ /** return a collection of failed tasks */
+ public Collection getFailedTasks() {
+ return new ArrayList(this.failedList);
+ }
- /** return a collection of resumed tasks */
- public Collection getResumedTasks() {
- return new ArrayList(this.resumedList);
- }
+ /** return a collection of completed tasks */
+ public Collection getCompletedTasks() {
+ return new ArrayList(this.completedList);
+ }
- /** return a collection of canceled tasks */
- public Collection getCanceledTasks() {
- return new ArrayList(this.canceledList);
- }
+ /** return a collection of suspended tasks */
+ public Collection getSuspendedTasks() {
+ return new ArrayList(this.suspendedList);
+ }
- /** listen to the status changes of the task */
- public void statusChanged(StatusEvent event) {
- Task task = (Task) event.getSource();
- Status status = event.getStatus();
- int prevStatus = status.getPrevStatusCode();
- int curStatus = status.getStatusCode();
- switch (prevStatus) {
- case Status.SUBMITTED:
- this.submittedList.remove(task);
- break;
- case Status.ACTIVE:
- this.activeList.remove(task);
- break;
- case Status.SUSPENDED:
- this.suspendedList.remove(task);
- break;
- case Status.RESUMED:
- this.resumedList.remove(task);
- break;
- case Status.FAILED:
- this.failedList.remove(task);
- break;
- case Status.CANCELED:
- this.canceledList.remove(task);
- break;
- case Status.COMPLETED:
- this.completedList.remove(task);
- break;
- default:
- break;
- }
- if (task != null) {
- switch (curStatus) {
- case Status.SUBMITTED:
- this.submittedList.add(task);
- break;
- case Status.ACTIVE:
- this.activeList.add(task);
- break;
- case Status.SUSPENDED:
- this.suspendedList.add(task);
- break;
- case Status.RESUMED:
- this.resumedList.add(task);
- break;
- case Status.FAILED:
- this.failedList.add(task);
- break;
- case Status.CANCELED:
- this.canceledList.add(task);
- break;
- case Status.COMPLETED:
- this.completedList.add(task);
- break;
- default:
- break;
- }
- }
- }
+ /** return a collection of resumed tasks */
+ public Collection getResumedTasks() {
+ return new ArrayList(this.resumedList);
+ }
- private SecurityContext getSecurityContext() {
- SecurityContext securityContext = this.task.getService(0)
- .getSecurityContext();
- if (securityContext == null) {
- // create default credentials
- securityContext = new SecurityContextImpl();
- }
- return securityContext;
- }
+ /** return a collection of canceled tasks */
+ public Collection getCanceledTasks() {
+ return new ArrayList(this.canceledList);
+ }
- protected FileResource getResource() {
- return this.fileResource;
- }
+ /** listen to the status changes of the task */
+ public void statusChanged(StatusEvent event) {
+ Task task = (Task) event.getSource();
+ Status status ...
[truncated message content] |