001    /*
002     * Copyright 2011-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2011-2015 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk;
022    
023    
024    
025    import java.io.Serializable;
026    
027    import com.unboundid.util.InternalUseOnly;
028    import com.unboundid.util.Mutable;
029    import com.unboundid.util.ThreadSafety;
030    import com.unboundid.util.ThreadSafetyLevel;
031    
032    
033    
034    /**
035     * This class provides a basic implementation of the
036     * {@link AsyncCompareResultListener} interface that will merely set the
037     * result object to a local variable that can be accessed through a getter
038     * method.  It provides a listener that may be easily used when processing
039     * an asynchronous compare operation using the {@link AsyncRequestID} as a
040     * {@code java.util.concurrent.Future} object.
041     */
042    @Mutable()
043    @ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE)
044    public final class BasicAsyncCompareResultListener
045           implements AsyncCompareResultListener, Serializable
046    {
047      /**
048       * The serial version UID for this serializable class.
049       */
050      private static final long serialVersionUID = 8119461093491566432L;
051    
052    
053    
054      // The compare result that has been received for the associated compare
055      // operation.
056      private volatile CompareResult compareResult;
057    
058    
059    
060      /**
061       * Creates a new instance of this class for use in processing a single
062       * compare operation.  A single basic async compare result listener object
063       * may not be used for multiple operations.
064       */
065      public BasicAsyncCompareResultListener()
066      {
067        compareResult = null;
068      }
069    
070    
071    
072      /**
073       * {@inheritDoc}
074       */
075      @InternalUseOnly()
076      public void compareResultReceived(final AsyncRequestID requestID,
077                                        final CompareResult compareResult)
078      {
079        this.compareResult = compareResult;
080      }
081    
082    
083    
084      /**
085       * Retrieves the result that has been received for the associated asynchronous
086       * compare operation, if it has been received.
087       *
088       * @return  The result that has been received for the associated asynchronous
089       *          compare operation, or {@code null} if no response has been
090       *          received yet.
091       */
092      public CompareResult getCompareResult()
093      {
094        return compareResult;
095      }
096    }