View Javadoc

1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  package org.apache.james.jspf.executor;
21  
22  import org.apache.james.jspf.core.SPFSession;
23  
24  
25  /**
26   * A Blocking version of SPFResult which block until the SPFResult is fully set
27   *
28   */
29  public class FutureSPFResult extends SPFResult {
30      
31      private boolean isReady;
32      
33      public FutureSPFResult() {
34          isReady = false;
35      }
36      
37      /**
38       * Set SPFResult using the given SPFsession
39       * 
40       * @param session 
41       * 
42       */
43      public synchronized void setSPFResult(SPFSession session) {
44          setSPFSession(session);
45          isReady = true;
46          notify();
47      }
48  
49      /**
50       * Waits until the SPFResult is set 
51       *
52       */
53      private synchronized void checkReady() {
54          while (!isReady) {
55              try {
56                  wait();
57              } catch (InterruptedException e) {
58                  //
59              }
60          }
61      }
62  
63      /**
64       * @see org.apache.james.jspf.executor.SPFResult#getExplanation()
65       */
66      public String getExplanation() {
67          checkReady();
68          return super.getExplanation();
69      }
70  
71      /**
72       * @see org.apache.james.jspf.executor.SPFResult#getHeader()
73       */
74      public String getHeader() {
75          checkReady();
76          return super.getHeader();
77      }
78  
79      /**
80       * @see org.apache.james.jspf.executor.SPFResult#getHeaderName()
81       */
82      public String getHeaderName() {
83          checkReady();
84          return super.getHeaderName();
85      }
86  
87      /**
88       * @see org.apache.james.jspf.executor.SPFResult#getHeaderText()
89       */
90      public String getHeaderText() {
91          checkReady();
92          return super.getHeaderText();
93      }
94  
95      /**
96       * @see org.apache.james.jspf.executor.SPFResult#getResult()
97       */
98      public String getResult() {
99          checkReady();
100         return super.getResult();
101     }
102 
103     /**
104      * Return true if the result was fully builded 
105      * 
106      * @return true or false
107      */
108     public boolean isReady() {
109         return isReady;
110     }
111 }