stevel 2003/06/18 21:51:57
Modified: java/src/org/apache/axis MessageContext.java Message.java
java/src/org/apache/axis/attachments
ManagedMemoryDataSource.java AttachmentsImpl.java
Attachments.java AttachmentPart.java
Log:
message disposal. All these classes now have a dispose() method which lets you
deterministically clean up attachment files without waiting for GC to do its thing.
I have not tied this to any transport (yet), though now it should be as simple as
calling dispose() at the end of message context processing.
Of course, then you have to be sure that the refs really are about to go out of
scope, something GC handles for you quite nicely...
Revision Changes Path
1.133 +37 -12 xml-axis/java/src/org/apache/axis/MessageContext.java
Index: MessageContext.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/MessageContext.java,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -r1.132 -r1.133
--- MessageContext.java 19 Apr 2003 05:15:28 -0000 1.132
+++ MessageContext.java 19 Jun 2003 04:51:56 -0000 1.133
@@ -392,6 +392,14 @@
}
/**
+ * during finalization, the dispose() method is called.
+ * @see #dispose()
+ */
+ protected void finalize() {
+ dispose();
+ }
+
+ /**
* Mappings of QNames to serializers/deserializers (and therfore
* to Java types).
*/
@@ -516,7 +524,7 @@
*/
public Message getRequestMessage() {
return requestMessage ;
- };
+ }
/**
* Set the request message, and make sure that message is associated
@@ -529,7 +537,7 @@
if (requestMessage != null) {
requestMessage.setMessageContext(this);
}
- };
+ }
/**
* Get the response message.
@@ -753,26 +761,26 @@
* (if it has been so configured - will our deployment
* tool do this by default? - todo by Jacek)
*/
- public final static String ENGINE_HANDLER = "engine.handler";
+ public static final String ENGINE_HANDLER = "engine.handler";
/** This String is the URL that the message came to
*/
- public final static String TRANS_URL = "transport.url";
+ public static final String TRANS_URL = "transport.url";
/** Has a quit been requested? Hackish... but useful... -- RobJ */
- public final static String QUIT_REQUESTED = "quit.requested";
+ public static final String QUIT_REQUESTED = "quit.requested";
/** Place to store an AuthenticatedUser */
- public final static String AUTHUSER = "authenticatedUser";
+ public static final String AUTHUSER = "authenticatedUser";
/** If on the client - this is the Call object */
- public final static String CALL = "call_object" ;
+ public static final String CALL = "call_object" ;
/** Are we doing Msg vs RPC? - For Java Binding */
- public final static String IS_MSG = "isMsg" ;
+ public static final String IS_MSG = "isMsg" ;
/** The directory where in coming attachments are created. */
- public final static String ATTACHMENTS_DIR = "attachments.directory" ;
+ public static final String ATTACHMENTS_DIR = "attachments.directory" ;
/** A boolean param, to control whether we accept missing parameters
* as nulls or refuse to acknowledge them.
@@ -782,13 +790,13 @@
/** The value of the property is used by service WSDL generation (aka ?WSDL)
* For the service's interface namespace if not set TRANS_URL property is used.
*/
- public final static String WSDLGEN_INTFNAMESPACE =
"axis.wsdlgen.intfnamespace";
+ public static final String WSDLGEN_INTFNAMESPACE =
"axis.wsdlgen.intfnamespace";
/** The value of the property is used by service WSDL generation (aka ?WSDL)
* For the service's location if not set TRANS_URL property is used.
* (helps provide support through proxies.
*/
- public final static String WSDLGEN_SERV_LOC_URL =
"axis.wsdlgen.serv.loc.url";
+ public static final String WSDLGEN_SERV_LOC_URL =
"axis.wsdlgen.serv.loc.url";
/** The value of the property is used by service WSDL generation (aka ?WSDL)
* Set this property to request a certain level of HTTP.
@@ -797,7 +805,7 @@
* The values MUST use
org.apache.axis.transport.http.HTTPConstants.HEADER_PROTOCOL_11
* for HTTP 1.1
*/
- public final static String HTTP_TRANSPORT_VERSION = "axis.transport.version";
+ public static final String HTTP_TRANSPORT_VERSION = "axis.transport.version";
public static final String SECURITY_PROVIDER = "securityProvider";
@@ -1138,5 +1146,22 @@
public String[] getRoles() {
//TODO: Flesh this out.
return null;
+ }
+
+ /**
+ * if a message (or subclass) has any disposal needs, this method
+ * is where it goes. Subclasses *must* call super.dispose(), and
+ * be prepared to be called from the finalizer as well as earlier
+ */
+ public synchronized void dispose() {
+ log.debug("disposing of message context");
+ if(requestMessage!=null) {
+ requestMessage.dispose();
+ requestMessage=null;
+ }
+ if(responseMessage!=null) {
+ responseMessage.dispose();
+ responseMessage=null;
+ }
}
}
1.99 +9 -0 xml-axis/java/src/org/apache/axis/Message.java
Index: Message.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/Message.java,v
retrieving revision 1.98
retrieving revision 1.99
diff -u -r1.98 -r1.99
--- Message.java 26 Apr 2003 23:09:06 -0000 1.98
+++ Message.java 19 Jun 2003 04:51:57 -0000 1.99
@@ -623,4 +623,13 @@
}
return null;
}
+
+ /**
+ * dispose of attachments
+ */
+ public void dispose() {
+ if(mAttachments!=null) {
+ mAttachments.dispose();
+ }
+ }
}
1.29 +0 -1
xml-axis/java/src/org/apache/axis/attachments/ManagedMemoryDataSource.java
Index: ManagedMemoryDataSource.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/attachments/ManagedMemoryDataSource.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- ManagedMemoryDataSource.java 22 Apr 2003 19:34:02 -0000 1.28
+++ ManagedMemoryDataSource.java 19 Jun 2003 04:51:57 -0000 1.29
@@ -65,7 +65,6 @@
/**
* This class allows small attachments to be cached in memory, while large ones are
* cached out. It implements a Java Activiation Data source interface.
- * TODO TODO TODO need to delete cached out data sources after a service ends.
*
* @author Rick Rineholt
*/
1.40 +30 -1
xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java
Index: AttachmentsImpl.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentsImpl.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- AttachmentsImpl.java 22 Apr 2003 19:34:02 -0000 1.39
+++ AttachmentsImpl.java 19 Jun 2003 04:51:57 -0000 1.40
@@ -604,7 +604,7 @@
public java.util.Iterator getAttachments(
javax.xml.soap.MimeHeaders headers) {
java.util.Vector vecParts = new java.util.Vector();
- java.util.Iterator iterator = attachments.values().iterator();
+ java.util.Iterator iterator = GetAttachmentsIterator();
while(iterator.hasNext()){
Part part = (Part) iterator.next();
if(part instanceof AttachmentPart){
@@ -617,6 +617,18 @@
}
/**
+ * get an iterator over all attachments. This
+ * @return iterator of Part Objects; some of which may be
+ * AttachmentPart instances
+ * @see org.apache.axis.Part
+ * @see AttachmentPart
+ */
+ private java.util.Iterator GetAttachmentsIterator() {
+ java.util.Iterator iterator = attachments.values().iterator();
+ return iterator;
+ }
+
+ /**
* Create a new attachment Part in this Message.
* Will actually, and always, return an AttachmentPart.
*
@@ -638,6 +650,23 @@
public int getSendType(){
return sendtype;
+ }
+
+ /**
+ * dispose of the attachments and their files; do not use the object
+ * after making this call.
+ */
+
+ public void dispose() {
+ java.util.Iterator iterator = GetAttachmentsIterator();
+ while (iterator.hasNext()) {
+ Part part = (Part) iterator.next();
+ if (part instanceof AttachmentPart) {
+ AttachmentPart apart=(AttachmentPart)part;
+ apart.dispose();
+ }
+ }
+
}
/**
1.16 +7 -0 xml-axis/java/src/org/apache/axis/attachments/Attachments.java
Index: Attachments.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/Attachments.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Attachments.java 22 Apr 2003 19:34:02 -0000 1.15
+++ Attachments.java 19 Jun 2003 04:51:57 -0000 1.16
@@ -266,4 +266,11 @@
*/
public int getSendType();
+
+ /**
+ * dispose of the attachments and their files; do not use the object
+ * after making this call.
+ */
+
+ public void dispose();
}
1.38 +6 -1
xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java
Index: AttachmentPart.java
===================================================================
RCS file:
/home/cvs/xml-axis/java/src/org/apache/axis/attachments/AttachmentPart.java,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- AttachmentPart.java 7 May 2003 14:24:31 -0000 1.37
+++ AttachmentPart.java 19 Jun 2003 04:51:57 -0000 1.38
@@ -562,7 +562,8 @@
/**
* when an attachment part is disposed, any associated files
- * are deleted
+ * are deleted, and the datahandler itself nulled. The object
+ * is no longer completely usable, at this point
*/
public synchronized void dispose() {
if(attachmentFile!=null) {
@@ -572,5 +573,9 @@
//set the filename to null to stop repeated use
setAttachmentFile(null);
}
+ //clean up the datahandler, as it will have been
+ //invalidated if it was bound to a file; if it wasnt
+ //we get to release memory anyway
+ datahandler=null;
}
}