001: /****************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one *
003: * or more contributor license agreements. See the NOTICE file *
004: * distributed with this work for additional information *
005: * regarding copyright ownership. The ASF licenses this file *
006: * to you under the Apache License, Version 2.0 (the *
007: * "License"); you may not use this file except in compliance *
008: * with the License. You may obtain a copy of the License at *
009: * *
010: * http://www.apache.org/licenses/LICENSE-2.0 *
011: * *
012: * Unless required by applicable law or agreed to in writing, *
013: * software distributed under the License is distributed on an *
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
015: * KIND, either express or implied. See the License for the *
016: * specific language governing permissions and limitations *
017: * under the License. *
018: ****************************************************************/package org.apache.james.jspf.executor;
019:
020: import org.apache.james.jspf.core.SPFSession;
021:
022: /**
023: * A Blocking version of SPFResult which block until the SPFResult is fully set
024: *
025: */
026: public class FutureSPFResult extends SPFResult {
027:
028: private boolean isReady;
029:
030: public FutureSPFResult() {
031: isReady = false;
032: }
033:
034: /**
035: * Set SPFResult using the given SPFsession
036: *
037: * @param session
038: *
039: */
040: public synchronized void setSPFResult(SPFSession session) {
041: setSPFSession(session);
042: isReady = true;
043: notify();
044: }
045:
046: /**
047: * Waits until the SPFResult is set
048: *
049: */
050: private synchronized void checkReady() {
051: while (!isReady) {
052: try {
053: wait();
054: } catch (InterruptedException e) {
055: //
056: }
057: }
058: }
059:
060: /**
061: * @see org.apache.james.jspf.executor.SPFResult#getExplanation()
062: */
063: public String getExplanation() {
064: checkReady();
065: return super .getExplanation();
066: }
067:
068: /**
069: * @see org.apache.james.jspf.executor.SPFResult#getHeader()
070: */
071: public String getHeader() {
072: checkReady();
073: return super .getHeader();
074: }
075:
076: /**
077: * @see org.apache.james.jspf.executor.SPFResult#getHeaderName()
078: */
079: public String getHeaderName() {
080: checkReady();
081: return super .getHeaderName();
082: }
083:
084: /**
085: * @see org.apache.james.jspf.executor.SPFResult#getHeaderText()
086: */
087: public String getHeaderText() {
088: checkReady();
089: return super .getHeaderText();
090: }
091:
092: /**
093: * @see org.apache.james.jspf.executor.SPFResult#getResult()
094: */
095: public String getResult() {
096: checkReady();
097: return super .getResult();
098: }
099:
100: /**
101: * Return true if the result was fully builded
102: *
103: * @return true or false
104: */
105: public boolean isReady() {
106: return isReady;
107: }
108: }
|