001/* 002 * Copyright 2011-2017 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2011-2017 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 */ 021package com.unboundid.ldap.sdk; 022 023 024 025import java.io.Serializable; 026 027import com.unboundid.util.InternalUseOnly; 028import com.unboundid.util.Mutable; 029import com.unboundid.util.ThreadSafety; 030import com.unboundid.util.ThreadSafetyLevel; 031 032 033 034/** 035 * This class provides a basic implementation of the {@link AsyncResultListener} 036 * interface that will merely set the result object to a local variable that can 037 * be accessed through a getter method. It provides a listener that may be 038 * easily used when processing an asynchronous operation using the 039 * {@link AsyncRequestID} as a {@code java.util.concurrent.Future} object. 040 */ 041@Mutable() 042@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE) 043public final class BasicAsyncResultListener 044 implements AsyncResultListener, Serializable 045{ 046 /** 047 * The serial version UID for this serializable class. 048 */ 049 private static final long serialVersionUID = -2701328904233458257L; 050 051 052 053 // The result that has been received for the associated operation. 054 private volatile LDAPResult ldapResult; 055 056 057 058 /** 059 * Creates a new instance of this class for use in processing a single add, 060 * delete, modify, or modify DN operation. A single basic async result 061 * listener object may not be used for multiple operations. 062 */ 063 public BasicAsyncResultListener() 064 { 065 ldapResult = null; 066 } 067 068 069 070 /** 071 * {@inheritDoc} 072 */ 073 @InternalUseOnly() 074 public void ldapResultReceived(final AsyncRequestID requestID, 075 final LDAPResult ldapResult) 076 { 077 this.ldapResult = ldapResult; 078 } 079 080 081 082 /** 083 * Retrieves the result that has been received for the associated asynchronous 084 * operation, if it has been received. 085 * 086 * @return The result that has been received for the associated asynchronous 087 * operation, or {@code null} if no response has been received yet. 088 */ 089 public LDAPResult getLDAPResult() 090 { 091 return ldapResult; 092 } 093}