james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r532347 - in /james/jspf/branches/asynch-jspf/src: main/java/org/apache/james/jspf/core/ main/java/org/apache/james/jspf/impl/ main/java/org/apache/james/jspf/macro/ main/java/org/apache/james/jspf/policies/ main/java/org/apache/james/jspf/...
Date Wed, 25 Apr 2007 13:09:21 GMT
Author: bago
Date: Wed Apr 25 06:09:08 2007
New Revision: 532347

URL: http://svn.apache.org/viewvc?view=rev&rev=532347
Log:
Moved DNS requestType constants to DNSRequest.
Refactore DNSService to use DNSRequest object as parameters.
Removed the asynch lookup method from the DNSService interface.
Added a DNSAsynchLookupService to run asynchronous lookups and created an adapter to simulate
asynchronous behaviour given a synchronous DNSService (this uses a request queue and a working
thread).

Added:
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSAsynchLookupService.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java
Modified:
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSRequest.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSService.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/core/SynchronousSPFExecutor.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.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
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
    james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
    james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
    james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/LoggingDNSService.java

Added: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSAsynchLookupService.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSAsynchLookupService.java?view=auto&rev=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSAsynchLookupService.java
(added)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSAsynchLookupService.java
Wed Apr 25 06:09:08 2007
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.james.jspf.core;
+
+
+/**
+ * Interface which should be used to access all necassary DNS-Records
+ *  
+ */
+public interface DNSAsynchLookupService {
+
+    /**
+     * Retrieve dns records for the given host asynchronously
+     * 
+     * @param request the dns request
+     * @param id the identification key for the response.
+     * @param responsePool the queue where the response will be appended.
+     */
+    public void getRecordsAsynch(DNSRequest request, Object id,
+            final IResponseQueue responsePool);
+
+}
\ No newline at end of file

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSRequest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSRequest.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSRequest.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSRequest.java
Wed Apr 25 06:09:08 2007
@@ -19,17 +19,25 @@
 
 package org.apache.james.jspf.core;
 
-public class DNSRequest {
+public final class DNSRequest {
+
+    /** The record types for the lookups */
+    public static final int A = 1;
+    public static final int AAAA = 2;
+    public static final int MX = 3;
+    public static final int PTR = 4;
+    public static final int TXT = 5;
+    public static final int SPF = 6;
 
     /**
      * The hostname to be resolved
      */
-    private String hostname;
+    private final String hostname;
     
     /**
      * The record type to look for
      */
-    private int recordType;
+    private final int recordType;
 
     public DNSRequest(String hostname, int recordType) {
         this.hostname = hostname;
@@ -41,7 +49,7 @@
      * 
      * @return the hostname
      */
-    public String getHostname() {
+    public final String getHostname() {
         return hostname;
     }
 
@@ -50,7 +58,7 @@
      * 
      * @return the RecordType
      */
-    public int getRecordType() {
+    public final int getRecordType() {
         return recordType;
     }
 

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSService.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSService.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSService.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/DNSService.java
Wed Apr 25 06:09:08 2007
@@ -33,37 +33,16 @@
     public static class TimeoutException extends Exception {
         
     }
-    
-    /** The record types for the lookups */
-    public int A = 1;
-    public int AAAA = 2;
-    public int MX = 3;
-    public int PTR = 4;
-    public int TXT = 5;
-    public int SPF = 6;
 
     /**
      * Retrieve dns records for the given host
      * 
-     * @param hostname host to be queried
-     * @param recordType the record type: MX, A, AAAA, PTR, TXT, SPF 
+     * @param request the dns request
      * @return an array of Strings representing the records
      * @throws NoneException when no record is found or a textparse exception happen
      * @throws TempErrorException on timeout.
      */
-    public List getRecords(String hostname, int recordType) throws TimeoutException;
-    
-    
-    /**
-     * Execute the query and store the response in the given IResponseQueue
-     * 
-     * @param hostname host to be queried
-     * @param recordType the record type: MX, A, AAAA, PTR, TXT, SPF
-     * @param id the id which will be used to store the response to the queue
-     * @param responsePool the queue in which the response will get stored
-     */
-    public void getRecordsAsynch(String hostname, int recordType, Object id, IResponseQueue
responsePool);
-    
+    public List getRecords(DNSRequest request) throws TimeoutException;
 
     /**
      * Try to get all domain names for the running host

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=532347&r1=532346&r2=532347
==============================================================================
--- 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 06:09:08 2007
@@ -53,29 +53,22 @@
          * @see org.apache.james.jspf.core.IResponseQueue#removeResponse()
          */
         public synchronized IResponse removeResponse() {
-            if ( isEmpty() ) {
+            if ( (size() - waitingThreads <= 0) ) {
                 try { waitingThreads++; wait();}
                 catch (InterruptedException e)  {Thread.interrupted();}
                 waitingThreads--;
             }
             return (IResponse)removeFirst();        }
 
-        /**
-         * @see java.util.AbstractCollection#isEmpty()
-         */
-        public boolean isEmpty() {
-            return  (size() - waitingThreads <= 0);
-        }
-
     }
 
     private Logger log;
-    private DNSService dnsProbe;
+    private DNSAsynchLookupService dnsProbe;
     private Thread worker;
     private Map sessions;
     private ResponseQueueImpl responseQueue;
 
-    public StagedMultipleSPFExecutor(Logger log, DNSService service) {
+    public StagedMultipleSPFExecutor(Logger log, DNSAsynchLookupService service) {
         this.log = log;
         this.dnsProbe = service;
 
@@ -102,9 +95,9 @@
                 DNSLookupContinuation cont = checker.checkSPF(session);
                 // if the checker returns a continuation we return it
                 if (cont != null) {
-                    dnsProbe.getRecordsAsynch(cont.getRequest().getHostname(), cont.getRequest().getRecordType(),
session, responseQueue);
-                    session.setAttribute(ATTRIBUTE_STAGED_EXECUTOR_CONTINUATION, cont);
                     sessions.put(session, result);
+                    session.setAttribute(ATTRIBUTE_STAGED_EXECUTOR_CONTINUATION, cont);
+                    dnsProbe.getRecordsAsynch(cont.getRequest(), session, responseQueue);
                     return;
                 } else {
                     sessions.remove(sessions);
@@ -122,13 +115,13 @@
                 }
             }
         }
-        System.out.println("================> RESULT!!!!!");
         result.setSPFResult(session);
     }
 
     public void run() {
 
         while (true) {
+            
             IResponse resp = responseQueue.removeResponse();
             
             SPFSession session = (SPFSession) resp.getId();
@@ -148,7 +141,7 @@
                 cont = cont.getListener().onDNSResponse(response, session);
                 
                 if (cont != null) {
-                    dnsProbe.getRecordsAsynch(cont.getRequest().getHostname(), cont.getRequest().getRecordType(),
session, responseQueue);
+                    dnsProbe.getRecordsAsynch(cont.getRequest(), session, responseQueue);
                     session.setAttribute(ATTRIBUTE_STAGED_EXECUTOR_CONTINUATION, cont);
                     sessions.put(session, result);
                 } else {

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SynchronousSPFExecutor.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SynchronousSPFExecutor.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SynchronousSPFExecutor.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/core/SynchronousSPFExecutor.java
Wed Apr 25 06:09:08 2007
@@ -51,8 +51,7 @@
                     DNSResponse response;
                     try {
                         response = new DNSResponse(dnsProbe.getRecords(cont
-                                .getRequest().getHostname(), cont.getRequest()
-                                .getRecordType()));
+                                .getRequest()));
                     } catch (TimeoutException e) {
                         response = new DNSResponse(e);
                     }

Added: 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=auto&rev=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java
(added)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceAsynchSimulator.java
Wed Apr 25 06:09:08 2007
@@ -0,0 +1,109 @@
+/****************************************************************
+ * 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.james.jspf.impl;
+
+import org.apache.james.jspf.core.DNSAsynchLookupService;
+import org.apache.james.jspf.core.DNSRequest;
+import org.apache.james.jspf.core.DNSService;
+import org.apache.james.jspf.core.IResponseImpl;
+import org.apache.james.jspf.core.IResponseQueue;
+import org.apache.james.jspf.core.DNSService.TimeoutException;
+
+import java.util.LinkedList;
+
+public class DNSServiceAsynchSimulator implements Runnable, DNSAsynchLookupService {
+
+    private DNSService dnsService;
+    private Thread worker;
+    private LinkedList queue;
+    private int waitingThreads = 0;
+    
+    public static final class Request {
+        private final DNSRequest value;
+        private final Object id;
+        private final IResponseQueue responseQueue;
+        public Request(DNSRequest value, Object id, IResponseQueue responseQueue) {
+            this.value = value;
+            this.id = id;
+            this.responseQueue = responseQueue;
+        }
+        public DNSRequest getValue() {
+            return value;
+        }
+        public Object getId() {
+            return id;
+        }
+        public IResponseQueue getResponseQueue() {
+            return responseQueue;
+        }
+        
+    }
+
+    public DNSServiceAsynchSimulator(DNSService service) {
+        this.dnsService = service;
+
+        this.queue = new LinkedList();
+        this.worker = new Thread(this);
+        this.worker.setDaemon(true);
+        this.worker.setName("SPFExecutor");
+        this.worker.start();
+
+    }
+
+    /**
+     * @see org.apache.james.jspf.core.DNSService#getRecordsAsynch(java.lang.String, int,
java.lang.Object, org.apache.james.jspf.core.IResponseQueue)
+     */
+    public void getRecordsAsynch(DNSRequest request, Object id,
+            final IResponseQueue responsePool) {
+        
+        synchronized (queue) {
+            queue.addLast(new Request(request, id, responsePool));
+            queue.notify();
+        }
+        
+    }
+
+    public void run() {
+        while (true) {
+            Request req;
+            synchronized (queue) {
+                if ( (queue.size() - waitingThreads <= 0) ) {
+                    try {
+                        waitingThreads++; queue.wait();
+                    } catch (InterruptedException e) {
+                        Thread.interrupted();
+                    }
+                    waitingThreads--;
+                }
+                req = (Request) queue.removeFirst();
+            }
+            
+            IResponseImpl response;
+            try {
+                response = new IResponseImpl(req.getId(), dnsService.getRecords(req.getValue()));
+            } catch (TimeoutException e) {
+                response = new IResponseImpl(req.getId(), e);
+            }
+
+            req.getResponseQueue().insertResponse(response);
+        }
+    }
+
+}

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/impl/DNSServiceXBillImpl.java
Wed Apr 25 06:09:08 2007
@@ -19,11 +19,10 @@
 
 package org.apache.james.jspf.impl;
 
+import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IPAddr;
 import org.apache.james.jspf.core.Logger;
-import org.apache.james.jspf.core.IResponseQueue;
-import org.apache.james.jspf.core.IResponseImpl;
 import org.xbill.DNS.AAAARecord;
 import org.xbill.DNS.ARecord;
 import org.xbill.DNS.Lookup;
@@ -111,30 +110,30 @@
     }
     
     /**
-     * @see org.apache.james.jspf.core.DNSService#getRecords(java.lang.String, int)
+     * @see org.apache.james.jspf.core.DNSService#getRecords(org.apache.james.jspf.core.DNSRequest)
      */
-    public List getRecords(String hostname, int recordType)
+    public List getRecords(DNSRequest request)
             throws TimeoutException {
         String recordTypeDescription;
         int dnsJavaType;
         int recordCount = 0;
-        switch (recordType) {
-            case A: recordTypeDescription = "A"; dnsJavaType = Type.A; break;
-            case AAAA: recordTypeDescription = "AAAA"; dnsJavaType = Type.AAAA; break;
-            case MX: recordTypeDescription = "MX"; dnsJavaType = Type.MX; break;
-            case PTR: recordTypeDescription = "PTR"; dnsJavaType = Type.PTR; break;
-            case TXT: recordTypeDescription = "TXT"; dnsJavaType = Type.TXT; break;
-            case SPF: recordTypeDescription= "SPF"; dnsJavaType = Type.SPF; break;
+        switch (request.getRecordType()) {
+            case DNSRequest.A: recordTypeDescription = "A"; dnsJavaType = Type.A; break;
+            case DNSRequest.AAAA: recordTypeDescription = "AAAA"; dnsJavaType = Type.AAAA;
break;
+            case DNSRequest.MX: recordTypeDescription = "MX"; dnsJavaType = Type.MX; break;
+            case DNSRequest.PTR: recordTypeDescription = "PTR"; dnsJavaType = Type.PTR; break;
+            case DNSRequest.TXT: recordTypeDescription = "TXT"; dnsJavaType = Type.TXT; break;
+            case DNSRequest.SPF: recordTypeDescription= "SPF"; dnsJavaType = Type.SPF; break;
             default: // TODO fail!
                 return null;
         }
         List records;
         try {
 
-            log.debug("Start "+recordTypeDescription+"-Record lookup for : " + hostname);
+            log.debug("Start "+recordTypeDescription+"-Record lookup for : " + request.getHostname());
 
             Lookup.getDefaultResolver().setTimeout(timeOut);
-            Lookup query = new Lookup(hostname, dnsJavaType);
+            Lookup query = new Lookup(request.getHostname(), dnsJavaType);
 
             Record[] rr = query.run();
             int queryResult = query.getResult();
@@ -147,28 +146,28 @@
                 records = new ArrayList();
                 for (int i = 0; i < rr.length; i++) {
                     String res;
-                    switch (recordType) {
-                        case A:
+                    switch (request.getRecordType()) {
+                        case DNSRequest.A:
                             ARecord a = (ARecord) rr[i];
                             res = a.getAddress().getHostAddress();
                             break;
-                        case AAAA:
+                        case DNSRequest.AAAA:
                             AAAARecord aaaa = (AAAARecord) rr[i];
                             res = aaaa.getAddress().getHostAddress();
                             break;
-                        case MX:
+                        case DNSRequest.MX:
                             MXRecord mx = (MXRecord) rr[i];
                             res = mx.getTarget().toString();
                             break;
-                        case PTR:
+                        case DNSRequest.PTR:
                             PTRRecord ptr = (PTRRecord) rr[i];
                             res = IPAddr.stripDot(ptr.getTarget().toString());
                             break;
-                        case TXT:
+                        case DNSRequest.TXT:
                             TXTRecord txt = (TXTRecord) rr[i];
                             res = txt.rdataToString();
                             break;
-                        case SPF:
+                        case DNSRequest.SPF:
                             SPFRecord spf = (SPFRecord) rr[i];
                             res = spf.rdataToString();
                             break;
@@ -185,38 +184,10 @@
             log.debug("Found " + recordCount + " "+recordTypeDescription+"-Records");
         } catch (TextParseException e) {
             // i think this is the best we could do
-            log.debug("No "+recordTypeDescription+" Record found for host: " + hostname);
+            log.debug("No "+recordTypeDescription+" Record found for host: " + request.getHostname());
             records = null;
         }
         return records;
-    }
-
-    /**
-     * @see org.apache.james.jspf.core.DNSService#getRecordsAsynch(java.lang.String, int,
java.lang.Object, org.apache.james.jspf.core.IResponseQueue)
-     */
-    public void getRecordsAsynch(String hostname, int recordType, Object id,
-            final IResponseQueue responsePool) {
-        IResponseImpl response;
-        try {
-            response = new IResponseImpl(id, getRecords(hostname, recordType));
-        } catch (TimeoutException e) {
-            response = new IResponseImpl(id, e);
-        }
-        new Thread() {
-
-            private IResponseImpl response;
-
-            public void run() {
-                responsePool.insertResponse(response);
-            }
-
-            public Thread setResponse(IResponseImpl response) {
-                this.response = response;
-                return this;
-            }
-            
-        }.setResponse(response).start();
-
     }
 
 }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/macro/MacroExpand.java
Wed Apr 25 06:09:08 2007
@@ -150,7 +150,7 @@
                             record);
 
                     return new DNSLookupContinuation(new DNSRequest(record,
-                            ip6 ? DNSService.AAAA : DNSService.A), 
+                            ip6 ? DNSRequest.AAAA : DNSRequest.A), 
                             new AResponseListener());
 
                 }
@@ -172,7 +172,7 @@
 
                 return new DNSLookupContinuation(new DNSRequest(IPAddr
                         .getAddress(session.getIpAddress()).getReverseIP(),
-                        DNSService.PTR), new PTRResponseListener());
+                        DNSRequest.PTR), new PTRResponseListener());
             }
         }
         return null;

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=532347&r1=532346&r2=532347
==============================================================================
--- 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 06:09:08 2007
@@ -76,7 +76,7 @@
             String currentDomain = spfData.getCurrentDomain();
             
             //TODO: Should we better used nested classes for better readablity ?
-            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSService.SPF),
new SPFCheckerDNSResponseListener() {
+            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.SPF),
new SPFCheckerDNSResponseListener() {
 
                 public DNSLookupContinuation onDNSResponse(
                         DNSResponse response, SPFSession session)
@@ -88,7 +88,7 @@
                         if (spfR == null || spfR.isEmpty()) {
                             
                             String currentDomain = session.getCurrentDomain();
-                            return new DNSLookupContinuation(new DNSRequest(currentDomain,
DNSService.TXT), new SPFCheckerDNSResponseListener() {
+                            return new DNSLookupContinuation(new DNSRequest(currentDomain,
DNSRequest.TXT), new SPFCheckerDNSResponseListener() {
 
                                 public DNSLookupContinuation onDNSResponse(
                                         DNSResponse response, SPFSession session)

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=532347&r1=532346&r2=532347
==============================================================================
--- 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 06:09:08 2007
@@ -35,7 +35,7 @@
             String currentDomain = spfData.getCurrentDomain();
             
             //TODO: Should we use better a nested class ?
-            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSService.SPF),
new SPFCheckerDNSResponseListener() {
+            return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.SPF),
new SPFCheckerDNSResponseListener() {
 
                 public DNSLookupContinuation onDNSResponse(
                         DNSResponse response, SPFSession session)
@@ -47,7 +47,7 @@
                         session.setAttribute(ATTRIBUTE_SPFSTRICT_CHECK_SPFRECORDS, spfR);
                         
                         String currentDomain = session.getCurrentDomain();
-                        return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSService.TXT),
new SPFCheckerDNSResponseListener() {
+                        return new DNSLookupContinuation(new DNSRequest(currentDomain, DNSRequest.TXT),
new SPFCheckerDNSResponseListener() {
 
                             public DNSLookupContinuation onDNSResponse(
                                     DNSResponse response, SPFSession session)

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/AMechanism.java
Wed Apr 25 06:09:08 2007
@@ -76,7 +76,7 @@
 
                     List aRecords = getARecords(host);
                     if (aRecords == null) {
-                        return new DNSLookupContinuation(new DNSRequest(host, DNSService.A),
AMechanism.this);
+                        return new DNSLookupContinuation(new DNSRequest(host, DNSRequest.A),
AMechanism.this);
                     } else {
                         return onDNSResponse(new DNSResponse(aRecords), spfData);
                     }
@@ -85,7 +85,7 @@
                     
                     List aaaaRecords = getAAAARecords(host);
                     if (aaaaRecords == null) {
-                        return new DNSLookupContinuation(new DNSRequest(host, DNSService.AAAA),
AMechanism.this);
+                        return new DNSLookupContinuation(new DNSRequest(host, DNSRequest.AAAA),
AMechanism.this);
                     } else {
                         return onDNSResponse(new DNSResponse(aaaaRecords), spfData);
                     }

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExistsMechanism.java
Wed Apr 25 06:09:08 2007
@@ -46,7 +46,7 @@
         public DNSLookupContinuation checkSPF(SPFSession spfData) throws PermErrorException,
                 TempErrorException, NeutralException, NoneException {
             String host = expandHost(spfData);
-            return new DNSLookupContinuation(new DNSRequest(host,DNSService.A), ExistsMechanism.this);
+            return new DNSLookupContinuation(new DNSRequest(host,DNSRequest.A), ExistsMechanism.this);
         }
     }
 

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/ExpModifier.java
Wed Apr 25 06:09:08 2007
@@ -73,7 +73,7 @@
                 NoneException, TempErrorException, NeutralException {
             String host = macroExpand.expand(getHost(), spfData, MacroExpand.DOMAIN);
 
-            return new DNSLookupContinuation(new DNSRequest(host, DNSService.TXT), ExpModifier.this);
+            return new DNSLookupContinuation(new DNSRequest(host, DNSRequest.TXT), ExpModifier.this);
         }
     }
 

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/MXMechanism.java
Wed Apr 25 06:09:08 2007
@@ -56,7 +56,7 @@
             // Get the right host.
             String host = expandHost(spfData);
             
-            return new DNSLookupContinuation(new DNSRequest(host, DNSService.MX), MXMechanism.this);
+            return new DNSLookupContinuation(new DNSRequest(host, DNSRequest.MX), MXMechanism.this);
         }
     }
 
@@ -127,7 +127,7 @@
             while (records.size() > 0 && (mx = (String) records.remove(0)) !=
null && mx.length() > 0) {
                 log.debug("Add MX-Record " + mx + " to list");
 
-                return new DNSLookupContinuation(new DNSRequest(mx, isIPv6 ? DNSService.AAAA
: DNSService.A), MXMechanism.this);
+                return new DNSLookupContinuation(new DNSRequest(mx, isIPv6 ? DNSRequest.AAAA
: DNSRequest.A), MXMechanism.this);
                 
             }
                 

Modified: james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
(original)
+++ james/jspf/branches/asynch-jspf/src/main/java/org/apache/james/jspf/terms/PTRMechanism.java
Wed Apr 25 06:09:08 2007
@@ -78,7 +78,7 @@
             
             spfData.pushChecker(cleanupChecker);
 
-            return new DNSLookupContinuation(new DNSRequest(ip.getReverseIP(), DNSService.PTR),
PTRMechanism.this);
+            return new DNSLookupContinuation(new DNSRequest(ip.getReverseIP(), DNSRequest.PTR),
PTRMechanism.this);
         }
     }
 
@@ -180,10 +180,10 @@
             // check if the connecting ip is ip6. If so lookup AAAA record
             if (IPAddr.isIPV6(spfSession.getIpAddress())) {
                 // Get aaaa record for this
-                dnsRequest = new DNSRequest(currentDomain, DNSService.AAAA);
+                dnsRequest = new DNSRequest(currentDomain, DNSRequest.AAAA);
             } else {
                 // Get a record for this
-                dnsRequest = new DNSRequest(currentDomain, DNSService.A);
+                dnsRequest = new DNSRequest(currentDomain, DNSRequest.A);
             }
             
             spfSession.setAttribute(ATTRIBUTE_CURRENT_DOMAIN, currentDomain);

Modified: james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/AbstractYamlTest.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
(original)
+++ james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/AbstractYamlTest.java
Wed Apr 25 06:09:08 2007
@@ -19,6 +19,7 @@
 
 package org.apache.james.jspf;
 
+import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.IResponseQueue;
 import org.apache.james.jspf.core.Logger;
@@ -26,6 +27,7 @@
 import org.apache.james.jspf.core.SPFExecutor;
 import org.apache.james.jspf.core.SPFRecordParser;
 import org.apache.james.jspf.core.StagedMultipleSPFExecutor;
+import org.apache.james.jspf.impl.DNSServiceAsynchSimulator;
 import org.apache.james.jspf.macro.MacroExpand;
 import org.apache.james.jspf.parser.DefaultSPF1Parser;
 import org.apache.james.jspf.parser.DefaultTermsFactory;
@@ -168,7 +170,7 @@
         }
         dns = new LoggingDNSService(getDNSService(), log.getChildLogger("dns"));
         macroExpand = new MacroExpand(log.getChildLogger("macroExpand"), dns);
-        executor = new StagedMultipleSPFExecutor(log, dns); 
+        executor = new StagedMultipleSPFExecutor(log, new DNSServiceAsynchSimulator(dns));

         spf = new SPF(dns, parser, log.getChildLogger("spf"), macroExpand, executor);
         /* PREVIOUS SLOW WAY 
         // we add this after the creation because it is a loop reference
@@ -274,8 +276,8 @@
             this.recordLimit = recordLimit;
         }
 
-        public List getRecords(String hostname, int recordType) throws TimeoutException {
-            return getRecords(hostname, recordType, 6);
+        public List getRecords(DNSRequest request) throws TimeoutException {
+            return getRecords(request.getHostname(), request.getRecordType(), 6);
         }
 
         public List getRecords(String hostname, int recordType, int depth) throws TimeoutException
{
@@ -298,7 +300,7 @@
                     if (o instanceof HashMap) {
                         HashMap hm = (HashMap) o;
                         if (hm.get(type) != null) {
-                            if (recordType == DNSService.MX) {
+                            if (recordType == DNSRequest.MX) {
                                 List mxList = (List) hm.get(type);
     
                                 // For MX records we overwrite the result ignoring the priority.
@@ -339,10 +341,10 @@
             return null;
         }
         
-        public void getRecordsAsynch(String hostname, int recordType, Object id,
+        public void getRecordsAsynch(DNSRequest request, Object id,
                 IResponseQueue responsePool) {
             try {
-                responsePool.insertResponse(new IResponseImpl(id, getRecords(hostname, recordType)));
+                responsePool.insertResponse(new IResponseImpl(id, getRecords(request)));
             } catch (TimeoutException e) {
                 responsePool.insertResponse(new IResponseImpl(id, e));
             }
@@ -358,12 +360,12 @@
      */
     public static String getRecordTypeDescription(int recordType) {
         switch (recordType) {
-            case DNSService.A: return "A";
-            case DNSService.AAAA: return "AAAA";
-            case DNSService.MX: return "MX";
-            case DNSService.PTR: return "PTR";
-            case DNSService.TXT: return "TXT";
-            case DNSService.SPF: return "SPF";
+            case DNSRequest.A: return "A";
+            case DNSRequest.AAAA: return "AAAA";
+            case DNSRequest.MX: return "MX";
+            case DNSRequest.PTR: return "PTR";
+            case DNSRequest.TXT: return "TXT";
+            case DNSRequest.SPF: return "SPF";
             default: return null;
         }
     }

Modified: james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/LoggingDNSService.java
URL: http://svn.apache.org/viewvc/james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/LoggingDNSService.java?view=diff&rev=532347&r1=532346&r2=532347
==============================================================================
--- james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/LoggingDNSService.java
(original)
+++ james/jspf/branches/asynch-jspf/src/test/java/org/apache/james/jspf/LoggingDNSService.java
Wed Apr 25 06:09:08 2007
@@ -19,9 +19,9 @@
 
 package org.apache.james.jspf;
 
+import org.apache.james.jspf.core.DNSRequest;
 import org.apache.james.jspf.core.DNSService;
 import org.apache.james.jspf.core.Logger;
-import org.apache.james.jspf.core.IResponseQueue;
 
 import java.util.List;
 
@@ -68,11 +68,11 @@
         // MOCK
     }
 
-    public List getRecords(String hostname, int recordType) throws TimeoutException {
+    public List getRecords(DNSRequest request) throws TimeoutException {
         try {
-            List result = dnsService.getRecords(hostname, recordType);
+            List result = dnsService.getRecords(request);
             StringBuffer logBuff = new StringBuffer();
-            logBuff.append("getRecords(" + hostname + "," + recordType + ") = ");
+            logBuff.append("getRecords(" + request.getHostname() + "," + request.getRecordType()
+ ") = ");
             if (result != null) {
                 for (int i = 0; i < result.size(); i++) {
                     logBuff.append(result.get(i));
@@ -88,15 +88,10 @@
             logger.debug(logBuff.toString());
             return result;
         } catch (TimeoutException e) {
-            logger.debug("getRecords(" + hostname
+            logger.debug("getRecords(" + request.getHostname()
                     + ") = TempErrorException[" + e.getMessage() + "]");
             throw e;
         }
     }
 
-    public void getRecordsAsynch(String hostname, int recordType, Object id,
-            IResponseQueue responsePool) {
-        logger.debug("getRecordsAsynch("+hostname+","+recordType);
-        dnsService.getRecordsAsynch(hostname, recordType, id, responsePool);
-    }
 }



---------------------------------------------------------------------
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