james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r532386 - in /james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf: core/ impl/ policies/
Date Wed, 25 Apr 2007 15:24:09 GMT
Author: norman
Date: Wed Apr 25 08:24:07 2007
New Revision: 532386

URL: http://svn.apache.org/viewvc?view=rev&rev=532386
Log:
Add some javadocs
Replace anonymous inner classes whith nested inner classes 
Some minor refactoring

Modified:
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/IResponseImpl.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/StagedMultipleSPFExecutor.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFStrictCheckerRetriever.java

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/IResponseImpl.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/IResponseImpl.java?view=diff&rev=532386&r1=532385&r2=532386
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/IResponseImpl.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/IResponseImpl.java
Wed Apr 25 08:24:07 2007
@@ -26,20 +26,34 @@
     private Exception exception = null;
     private List value = null;
     private Object id = null;
+    
     public IResponseImpl(Object id, Exception e) {
         this.exception = e;
         this.id = id;
     }
+    
     public IResponseImpl(Object id, List result) {
         this.value = result;
         this.id = id;
     }
+    
+    /**
+     * @see org.apache.james.jspf.core.IResponse#getException()
+     */
     public Exception getException() {
         return exception;
     }
+    
+    /**
+     * @see org.apache.james.jspf.core.IResponse#getId()
+     */
     public Object getId() {
         return id;
     }
+    
+    /**
+     * @see org.apache.james.jspf.core.IResponse#getValue()
+     */
     public Object getValue() {
         return value;
     }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java?view=diff&rev=532386&r1=532385&r2=532386
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SPFSession.java
Wed Apr 25 08:24:07 2007
@@ -359,6 +359,16 @@
     public void setAttribute(String key, Object value) {
         this.attributes.put(key, value);
     }
+    
+    /**
+     * Remove the attribute stored under the given key
+     * 
+     * @param key the key of the attribute
+     * @return object the attribute which was stored with the key
+     */
+    public Object removeAttribute(String key) {
+        return this.attributes.remove(key);
+    }
 
     /**
      * Add the given SPFChecker on top of the stack

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/StagedMultipleSPFExecutor.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/StagedMultipleSPFExecutor.java?view=diff&rev=532386&r1=532385&r2=532386
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/StagedMultipleSPFExecutor.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/StagedMultipleSPFExecutor.java
Wed Apr 25 08:24:07 2007
@@ -125,8 +125,8 @@
             IResponse resp = responseQueue.removeResponse();
             
             SPFSession session = (SPFSession) resp.getId();
-            FutureSPFResult result = (FutureSPFResult) sessions.get(resp.getId());
-            sessions.remove(session);
+            FutureSPFResult result = (FutureSPFResult) sessions.remove(session);
+            
             DNSLookupContinuation cont = (DNSLookupContinuation) session.getAttribute(ATTRIBUTE_STAGED_EXECUTOR_CONTINUATION);
             
             DNSResponse response;

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java?view=diff&rev=532386&r1=532385&r2=532386
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java
Wed Apr 25 08:24:07 2007
@@ -28,6 +28,10 @@
 
 import java.util.LinkedList;
 
+/**
+ * Wrap a DNSService an excute the calls asynch in a new Thread
+ * 
+ */
 public class DNSServiceAsynchSimulator implements Runnable, DNSAsynchLookupService {
 
     private DNSService dnsService;
@@ -62,7 +66,7 @@
         this.queue = new LinkedList();
         this.worker = new Thread(this);
         this.worker.setDaemon(true);
-        this.worker.setName("SPFExecutor");
+        this.worker.setName("DNSServiceAsynchSimulator");
         this.worker.start();
 
     }
@@ -80,6 +84,9 @@
         
     }
 
+    /**
+     * Run the async dns call in a new thread
+     */
     public void run() {
         while (true) {
             Request req;

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java?view=diff&rev=532386&r1=532385&r2=532386
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFRetriever.java
Wed Apr 25 08:24:07 2007
@@ -23,7 +23,63 @@
  * Get the raw dns txt or spf entry which contains a spf entry
  */
 public class SPFRetriever implements SPFChecker {
+    
+    private static final class SPFRecordHandlerDNSResponseListener implements SPFCheckerDNSResponseListener
{
 
+        public DNSLookupContinuation onDNSResponse(
+                DNSResponse response, SPFSession session)
+                throws PermErrorException,
+                NoneException, TempErrorException,
+                NeutralException {
+            
+            List spfR;
+            try {
+                spfR = response.getResponse();
+                String record = extractSPFRecord(spfR);
+                if (record != null) {
+                    session.setAttribute(SPF.ATTRIBUTE_SPF1_RECORD, new SPF1Record(record));
+                }
+            } catch (TimeoutException e) {
+                throw new TempErrorException("Timeout querying dns");
+            }
+            return null;
+            
+        }
+        
+    }
+
+    private static final class SPFRetrieverDNSResponseListener implements SPFCheckerDNSResponseListener
{
+
+        public DNSLookupContinuation onDNSResponse(
+                DNSResponse response, SPFSession session)
+                throws PermErrorException, NoneException,
+                TempErrorException, NeutralException {
+            try {
+                List spfR = response.getResponse();
+                
+                if (spfR == null || spfR.isEmpty()) {
+                    
+                    String currentDomain = session.getCurrentDomain();
+                    return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.TXT),
new SPFRecordHandlerDNSResponseListener());
+
+                } else {
+                    
+                    String record = extractSPFRecord(spfR);
+                    if (record != null) {
+                        session.setAttribute(SPF.ATTRIBUTE_SPF1_RECORD, new SPF1Record(record));
+                    }
+                    
+                }
+                
+                return null;
+                
+            } catch (DNSService.TimeoutException e) {
+                throw new TempErrorException("Timeout querying dns");
+            }
+        }
+        
+    }
+    
     /**
      * Return the extracted SPF-Record 
      *  
@@ -32,7 +88,7 @@
      * @throws PermErrorException if more then one SPF - Record was found in the 
      *                            given List.
      */
-    protected String extractSPFRecord(List spfR) throws PermErrorException {
+    protected static String extractSPFRecord(List spfR) throws PermErrorException {
         if (spfR == null || spfR.isEmpty()) return null;
         
         String returnValue = null;
@@ -74,61 +130,8 @@
         SPF1Record res = (SPF1Record) spfData.getAttribute(SPF.ATTRIBUTE_SPF1_RECORD);
         if (res == null) {
             String currentDomain = spfData.getCurrentDomain();
-            
-            //TODO: Should we better used nested classes for better readablity ?
-            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.SPF),
new SPFCheckerDNSResponseListener() {
 
-                public DNSLookupContinuation onDNSResponse(
-                        DNSResponse response, SPFSession session)
-                        throws PermErrorException, NoneException,
-                        TempErrorException, NeutralException {
-                    try {
-                        List spfR = response.getResponse();
-                        
-                        if (spfR == null || spfR.isEmpty()) {
-                            
-                            String currentDomain = session.getCurrentDomain();
-                            return new DNSLookupContinuation(new DNSRequest(currentDomain,
DNSRequest.TXT), new SPFCheckerDNSResponseListener() {
-
-                                public DNSLookupContinuation onDNSResponse(
-                                        DNSResponse response, SPFSession session)
-                                        throws PermErrorException,
-                                        NoneException, TempErrorException,
-                                        NeutralException {
-                                    
-                                    List spfR;
-                                    try {
-                                        spfR = response.getResponse();
-                                        String record = extractSPFRecord(spfR);
-                                        if (record != null) {
-                                            session.setAttribute(SPF.ATTRIBUTE_SPF1_RECORD,
new SPF1Record(record));
-                                        }
-                                    } catch (TimeoutException e) {
-                                        throw new TempErrorException("Timeout querying dns");
-                                    }
-                                    return null;
-                                    
-                                }
-                                
-                            });
-                            
-                        } else {
-                            
-                            String record = extractSPFRecord(spfR);
-                            if (record != null) {
-                                session.setAttribute(SPF.ATTRIBUTE_SPF1_RECORD, new SPF1Record(record));
-                            }
-                            
-                        }
-                        
-                        return null;
-                        
-                    } catch (DNSService.TimeoutException e) {
-                        throw new TempErrorException("Timeout querying dns");
-                    }
-                }
-                
-            });
+            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.SPF),
new SPFRetrieverDNSResponseListener());
             
         }
         return null;

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFStrictCheckerRetriever.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFStrictCheckerRetriever.java?view=diff&rev=532386&r1=532385&r2=532386
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFStrictCheckerRetriever.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/policies/SPFStrictCheckerRetriever.java
Wed Apr 25 08:24:07 2007
@@ -22,9 +22,58 @@
  */
 public class SPFStrictCheckerRetriever extends SPFRetriever {
 
-    
 
     private static final String ATTRIBUTE_SPFSTRICT_CHECK_SPFRECORDS = "SPFStrictCheck.SPFRecords";
+    
+    private static final class SPFStrictSPFRecordsDNSResponseListener implements SPFCheckerDNSResponseListener
{
+
+        public DNSLookupContinuation onDNSResponse(
+                DNSResponse response, SPFSession session)
+                throws PermErrorException,
+                NoneException, TempErrorException,
+                NeutralException {
+            
+            List spfR = (List) session.getAttribute(ATTRIBUTE_SPFSTRICT_CHECK_SPFRECORDS);
+            List spfTxtR = null;
+            try {
+                spfTxtR = response.getResponse();
+            } catch (TimeoutException e) {
+                throw new TempErrorException("Timeout querying dns");
+            }
+
+            String record = calculateSpfRecord(spfR, spfTxtR);
+            if (record != null) {
+                session.setAttribute(SPF.ATTRIBUTE_SPF1_RECORD, new SPF1Record(record));
+            }
+
+            return null;
+            
+        }
+        
+    }
+    
+    
+    private static final class SPFStrictCheckDNSResponseListener implements SPFCheckerDNSResponseListener
{
+
+        public DNSLookupContinuation onDNSResponse(
+                DNSResponse response, SPFSession session)
+                throws PermErrorException, NoneException,
+                TempErrorException, NeutralException {
+            try {
+                List spfR = response.getResponse();
+                
+                session.setAttribute(ATTRIBUTE_SPFSTRICT_CHECK_SPFRECORDS, spfR);
+                
+                String currentDomain = session.getCurrentDomain();
+                return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.TXT),
new SPFStrictSPFRecordsDNSResponseListener());
+                    
+            } catch (DNSService.TimeoutException e) {
+                throw new TempErrorException("Timeout querying dns");
+            }
+        }
+        
+        
+    }
 
 
     public DNSLookupContinuation checkSPF(SPFSession spfData)
@@ -33,60 +82,15 @@
         SPF1Record res = (SPF1Record) spfData.getAttribute(SPF.ATTRIBUTE_SPF1_RECORD);
         if (res == null) {
             String currentDomain = spfData.getCurrentDomain();
-            
-            //TODO: Should we use better a nested class ?
-            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.SPF),
new SPFCheckerDNSResponseListener() {
 
-                public DNSLookupContinuation onDNSResponse(
-                        DNSResponse response, SPFSession session)
-                        throws PermErrorException, NoneException,
-                        TempErrorException, NeutralException {
-                    try {
-                        List spfR = response.getResponse();
-                        
-                        session.setAttribute(ATTRIBUTE_SPFSTRICT_CHECK_SPFRECORDS, spfR);
-                        
-                        String currentDomain = session.getCurrentDomain();
-                        return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.TXT),
new SPFCheckerDNSResponseListener() {
-
-                            public DNSLookupContinuation onDNSResponse(
-                                    DNSResponse response, SPFSession session)
-                                    throws PermErrorException,
-                                    NoneException, TempErrorException,
-                                    NeutralException {
-                                
-                                List spfR = (List) session.getAttribute(ATTRIBUTE_SPFSTRICT_CHECK_SPFRECORDS);
-                                List spfTxtR = null;
-                                try {
-                                    spfTxtR = response.getResponse();
-                                } catch (TimeoutException e) {
-                                    throw new TempErrorException("Timeout querying dns");
-                                }
-
-                                String record = calculateSpfRecord(spfR, spfTxtR);
-                                if (record != null) {
-                                    session.setAttribute(SPF.ATTRIBUTE_SPF1_RECORD, new SPF1Record(record));
-                                }
-
-                                return null;
-                                
-                            }
-                            
-                        });
-                            
-                    } catch (DNSService.TimeoutException e) {
-                        throw new TempErrorException("Timeout querying dns");
-                    }
-                }
-                
-            });
+            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.SPF),
new SPFStrictCheckDNSResponseListener());
             
         }
         return null;
     }
 
 
-    private String calculateSpfRecord(List spfR, List spfTxtR)
+    private static String calculateSpfRecord(List spfR, List spfTxtR)
             throws PermErrorException {
         String spfR1 = null;
         String spfR2 = null;



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message