Author: nthaker
Date: Mon Mar 3 14:28:09 2008
New Revision: 633305
URL: http://svn.apache.org/viewvc?rev=633305&view=rev
Log:
WSCOMMONS-306
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManager.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManagerFactory.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/FileAccessor.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventDefinitions.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventHandler.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartOnFile.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java?rev=633305&r1=633304&r2=633305&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/Attachments.java
Mon Mar 3 14:28:09 2008
@@ -20,6 +20,7 @@
package org.apache.axiom.attachments;
import org.apache.axiom.attachments.impl.PartFactory;
+import org.apache.axiom.attachments.lifecycle.LifecycleManagerFactory;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.impl.MTOMConstants;
import org.apache.axiom.om.util.UUIDGenerator;
@@ -108,9 +109,18 @@
private String attachmentRepoDir;
private int fileStorageThreshold;
-
+
+ private static LifecycleManagerFactory lmf = new LifecycleManagerFactory();
+
protected static Log log = LogFactory.getLog(Attachments.class);
-
+
+ public static LifecycleManagerFactory getLifcycleManagerFactory() {
+ return lmf;
+ }
+
+ public static void setlifeCycleManagerFactory(LifecycleManagerFactory
lifeCycleManagerFactory) {
+ lmf = lifeCycleManagerFactory;
+ }
/**
* Moves the pointer to the beginning of the first MIME part. Reads till
first MIME boundary is
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartOnFile.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartOnFile.java?rev=633305&r1=633304&r2=633305&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartOnFile.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/impl/PartOnFile.java
Mon Mar 3 14:28:09 2008
@@ -18,18 +18,17 @@
*/
package org.apache.axiom.attachments.impl;
-import org.apache.axiom.attachments.CachedFileDataSource;
-import org.apache.axiom.om.util.UUIDGenerator;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Hashtable;
import javax.activation.DataHandler;
import javax.mail.MessagingException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Hashtable;
+import org.apache.axiom.attachments.lifecycle.LifecycleManager;
+import org.apache.axiom.attachments.lifecycle.LifecycleManagerFactory;
+import org.apache.axiom.attachments.lifecycle.impl.FileAccessor;
/**
* PartOnFile stores that attachment in a file.
@@ -41,7 +40,7 @@
*/
public class PartOnFile extends AbstractPart {
- File backingFile;
+ FileAccessor fileAccessor;
/**
@@ -53,76 +52,44 @@
*/
PartOnFile(Hashtable headers, InputStream is1, InputStream is2, String
attachmentDir) throws IOException {
super(headers);
- backingFile = createFile(attachmentDir);
-
+ LifecycleManager lm = LifecycleManagerFactory.getLifeCycleManager();
+ fileAccessor = lm.create(attachmentDir);
// Now write the data to the backing file
- FileOutputStream fos = new FileOutputStream(backingFile);
+ OutputStream fos = fileAccessor.getOutputStream();
BufferUtils.inputStream2OutputStream(is1, fos);
BufferUtils.inputStream2OutputStream(is2, fos);
fos.flush();
fos.close();
- }
-
- /**
- * Create a unique file in the designated directory
- * @param attachmentDir
- * @return File
- * @throws IOException
- */
- private static File createFile(String attachmentDir) throws IOException {
- File file = null;
- File dir = null;
- if (attachmentDir != null) {
- dir = new File(attachmentDir);
- if (!dir.exists()) {
- dir.mkdirs();
- }
- }
- if (!dir.isDirectory()) {
- throw new IllegalArgumentException("Given Axis2 Attachment File
Cache Location "
- + dir + " should be a directory.");
- }
- // Generate unique id. The UUID generator is used so that we can limit
- // synchronization with the java random number generator.
- String id = UUIDGenerator.getUUID();
- //Replace colons with underscores
- id = id.replaceAll(":", "_");
-
- String fileString = "Axis2" + id + ".att";
- file = new File(dir, fileString);
- return file;
}
-
+
/* (non-Javadoc)
* @see org.apache.axiom.attachments.impl.AbstractPart#getDataHandler()
*/
public DataHandler getDataHandler() throws MessagingException {
- CachedFileDataSource dataSource = new
CachedFileDataSource(backingFile);
- dataSource.setContentType(getContentType());
- return new DataHandler(dataSource);
+ return fileAccessor.getDataHandler(getContentType());
}
/* (non-Javadoc)
* @see org.apache.axiom.attachments.impl.AbstractPart#getFileName()
*/
public String getFileName() throws MessagingException {
- return backingFile.getAbsolutePath();
+ return fileAccessor.getFileName();
}
/* (non-Javadoc)
* @see org.apache.axiom.attachments.impl.AbstractPart#getInputStream()
*/
public InputStream getInputStream() throws IOException, MessagingException
{
- return new FileInputStream(backingFile);
+ return fileAccessor.getInputStream();
}
/* (non-Javadoc)
* @see org.apache.axiom.attachments.impl.AbstractPart#getSize()
*/
public int getSize() {
- return (int) backingFile.length();
+ return (int) fileAccessor.getSize();
}
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManager.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManager.java?rev=633305&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManager.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManager.java
Mon Mar 3 14:28:09 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.attachments.lifecycle;
+
+import java.io.IOException;
+
+import org.apache.axiom.attachments.lifecycle.impl.FileAccessor;
+
+/**
+ * Lifecycle Manager will be used to manage the lifecycle of attachment files.
+ *
+ * Axiom forks attachment processing based on the size of attachment to be
processed.
+ * Attachments are either processed by storing them in memory or by storing
them in
+ * file system based on the size of the attachment file.
+ *
+ * Lifecycle Manager provides and organized way of managing attachments, by
providing
+ * calls to create and delete attachments.
+ */
+public interface LifecycleManager {
+
+ /**
+ * Create a unique file in the designated directory
+ * @param attachmentDir
+ * @return
+ * @throws IOException
+ */
+ public FileAccessor create(String attachmentDir) throws IOException;
+
+ /**
+ * Deletes attachment file
+ * @param File
+ * @throws IOException
+ */
+ public void delete(String id) throws IOException;
+
+ /**
+ * Mark the file for deletion on application/VM exit
+ * @param File
+ * @throws IOException
+ */
+ public void deleteOnExit(String id) throws IOException;
+
+ /**
+ * Mark attachment file for deletion when designated time interval in
seconds
+ * has elapsed.
+ * @param interval
+ * @param File
+ * @throws IOException
+ */
+ public void deleteOnTimeInterval(int interval, String id) throws
IOException;
+}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManagerFactory.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManagerFactory.java?rev=633305&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManagerFactory.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/LifecycleManagerFactory.java
Mon Mar 3 14:28:09 2008
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.attachments.lifecycle;
+
+import org.apache.axiom.attachments.lifecycle.impl.LifecycleManagerImpl;
+
+public class LifecycleManagerFactory {
+ public static LifecycleManager getLifeCycleManager(){
+ return LifecycleManagerImpl.manager;
+ }
+}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/FileAccessor.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/FileAccessor.java?rev=633305&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/FileAccessor.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/FileAccessor.java
Mon Mar 3 14:28:09 2008
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.attachments.lifecycle.impl;
+
+import org.apache.axiom.attachments.CachedFileDataSource;
+import org.apache.axiom.attachments.lifecycle.LifecycleManager;
+import org.apache.axiom.attachments.lifecycle.LifecycleManagerFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * FileAccessor wraps the attachment temp file. It is created from PartOnFile.
+ * The idea behind wrapping the file is to give rumtime an ability to track
+ * when the file is accessed with streams or data handler and accordingly
trigger
+ * events to handle the the files lifecycle.
+ *
+ */
+public class FileAccessor implements LifecycleEventHandler{
+ private static final Log log = LogFactory.getLog(FileAccessor.class);
+ File file = null;
+ String id = null;
+ //TODO remove hard coded time interval, 30 mins/1800 secs
+ private final static int DELETE_INTERVAL = 1800;
+ public FileAccessor(File file, String id) {
+ super();
+ this.file = file;
+ this.id = id;
+ }
+
+ public DataHandler getDataHandler(String contentType) throws
MessagingException {
+ if(log.isDebugEnabled()){
+ log.debug("getDataHandler()");
+ }
+ CachedFileDataSource dataSource = new CachedFileDataSource(file);
+ dataSource.setContentType(contentType);
+ return new DataHandler(dataSource);
+ }
+
+ public String getFileName() throws MessagingException {
+ if(log.isDebugEnabled()){
+ log.debug("getFileName()");
+ }
+ return file.getAbsolutePath();
+ }
+
+ public InputStream getInputStream() throws IOException, MessagingException
{
+ if(log.isDebugEnabled()){
+ log.debug("getInputStream()");
+ }
+ return new FileInputStream(file);
+ }
+
+ public OutputStream getOutputStream() throws FileNotFoundException{
+ if(log.isDebugEnabled()){
+ log.debug("getOutputStream()");
+ }
+ return new FileOutputStream(file);
+ }
+
+ public int getSize() {
+ return (int) file.length();
+ }
+
+ public void handleEvent(int eventId) throws IOException {
+ LifecycleManager manager =
LifecycleManagerFactory.getLifeCycleManager();
+ switch (eventId) {
+ case LifecycleEventDefinitions.DELETE_ON_EXIT:
+ manager.deleteOnExit(id);
+ break;
+ case LifecycleEventDefinitions.DELETE_ON_TIME_INTERVAL:
+ manager.deleteOnTimeInterval(DELETE_INTERVAL, id);
+ break;
+ case LifecycleEventDefinitions.READ_ONCE_AND_DELETE:
+ manager.delete(id);
+ break;
+ default:
+ manager.delete(id);
+ break;
+ }
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public String getId() {
+ return id;
+ }
+}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventDefinitions.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventDefinitions.java?rev=633305&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventDefinitions.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventDefinitions.java
Mon Mar 3 14:28:09 2008
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.axiom.attachments.lifecycle.impl;
+
+public class LifecycleEventDefinitions {
+ public static final int DELETE_ON_EXIT = 1;
+ public static final int READ_ONCE_AND_DELETE = 2;
+ public static final int DELETE_ON_TIME_INTERVAL = 3;
+}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventHandler.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventHandler.java?rev=633305&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventHandler.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleEventHandler.java
Mon Mar 3 14:28:09 2008
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.attachments.lifecycle.impl;
+
+import java.io.IOException;
+
+/**
+ * The attachment life cycle manager supports create and delete operations on
the FileAccessor(which holds attachment file).
+ * These operations are coupled to events, the LifecycleManager needs to
execute an operation when an even
+ * causes that operation to trigger. For example a delete operation should
execute when a deleteOnExit
+ * or deleteOnTimeInterval event occur on FileAccessor.
+ *
+ * The LifecycleManager should execute operation on FileAccessor based on the
Events that trigger them.
+ * EventHandler defines methods to execute LifecycleManager operation when a
event occurs.
+ *
+ */
+public interface LifecycleEventHandler {
+
+ /**
+ * When a Event occurs in FileAccessor, execute the LifecycleManager
Operation
+ * For example, if the delete behaviour is readOnce and if the inputstream
on attachment is read
+ * and closed the first time, the delete operation in LifecycleManager
should be executed.
+ * @param eventName
+ */
+ public void handleEvent(int eventId) throws IOException;
+}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java?rev=633305&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/attachments/lifecycle/impl/LifecycleManagerImpl.java
Mon Mar 3 14:28:09 2008
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.attachments.lifecycle.impl;
+
+import org.apache.axiom.attachments.lifecycle.LifecycleManager;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Map;
+
+public class LifecycleManagerImpl implements LifecycleManager {
+ private static final Log log =
LogFactory.getLog(LifecycleManagerImpl.class);
+ private Map table = new Hashtable();
+ public static LifecycleManager manager = new LifecycleManagerImpl();
+
+ protected LifecycleManagerImpl() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.axiom.lifecycle.LifecycleManager#create(java.lang.String)
+ */
+ public FileAccessor create(String attachmentDir) throws IOException {
+ if(log.isDebugEnabled()){
+ log.debug("Start Create()");
+ }
+ File file = null;
+ File dir = null;
+ if (attachmentDir != null) {
+ dir = new File(attachmentDir);
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ }
+ if (!dir.isDirectory()) {
+ throw new IllegalArgumentException("Given Axis2 Attachment File
Cache Location "
+ + dir + " should be a directory.");
+ }
+ // Generate unique id. The UUID generator is used so that we can limit
+ // synchronization with the java random number generator.
+ String id = UUIDGenerator.getUUID();
+
+ //Replace colons with underscores
+ id = id.replaceAll(":", "_");
+
+ String fileString = "Axis2" + id + ".att";
+ file = new File(dir, fileString);
+ //add the file to table
+ table.put(id, file);
+ FileAccessor fa = new FileAccessor(file, id);
+ //TODO: change deleteOnExit call such that it's sent as an event to
+ //LifecycleEventHandler. example
fa.handleEvent(LifeCycleDefinition.DELETE_ON_EXIT)
+ //This is the default behaviour. Delete file on VM Exit.
+ deleteOnExit(id);
+ if(log.isDebugEnabled()){
+ log.debug("End Create()");
+ }
+ return fa;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.axiom.lifecycle.LifecycleManager#delete(java.io.File)
+ */
+ public void delete(String id) throws IOException {
+ if(log.isDebugEnabled()){
+ log.debug("Start delete()");
+ }
+ File file = getFile(id);
+
+ if(file!=null && file.exists()){
+ file.delete();
+ table.remove(id);
+ }
+ if(log.isDebugEnabled()){
+ log.debug("End delete()");
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.axiom.lifecycle.LifecycleManager#deleteOnExit(java.io.File)
+ */
+ public void deleteOnExit(String id) throws IOException {
+ if(log.isDebugEnabled()){
+ log.debug("Start deleteOnExit()");
+ }
+ File file = getFile(id);
+ if(file!=null){
+ file.deleteOnExit();
+ table.remove(id);
+ }
+ if(log.isDebugEnabled()){
+ log.debug("End deleteOnExit()");
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.axiom.lifecycle.LifecycleManager#deleteOnTimeInterval(int)
+ */
+ public void deleteOnTimeInterval(int interval, String id) throws
IOException {
+ if(log.isDebugEnabled()){
+ log.debug("Start deleteOnTimeInterval()");
+ }
+ File file = getFile(id);
+ Thread t = new Thread(new LifecycleManagerImpl.FileDeletor(interval,
file, id));
+ t.start();
+ if(log.isDebugEnabled()){
+ log.debug("End deleteOnTimeInterval()");
+ }
+ }
+
+ private File getFile(String id){
+ return (File)table.get(id);
+ }
+
+ public class FileDeletor implements Runnable{
+ int interval;
+ File _file;
+ String _id;
+ public FileDeletor(int interval, File file, String id) {
+ super();
+ this.interval = interval;
+ this._file = file;
+ this._id = id;
+ }
+
+ public void run() {
+ try{
+ Thread.sleep(interval*1000);
+ if(_file.exists()){
+ _file.delete();
+ table.remove(_id);
+ }
+ }catch(InterruptedException e){
+ //Log Exception
+ if(log.isDebugEnabled()){
+ log.warn("InterruptedException occured "+e.getMessage());
+ }
+ }
+ }
+ }
+
+}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]