Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 8e2c59f42eca1cd0a0bd1d9c7a15e5d080dd5b79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************************************
 * Copyright (c) 2014 Wind River Systems, Inc. and others. All rights reserved.
 * This program and the accompanying materials are made available under the terms
 * of the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.debug.test.util;



/**
 * Copied and apdapted from org.eclipse.cdt.dsf.concurrent.
 * 
 * Request monitor that allows data to be returned to the request initiator.
 * 
 * @param V The type of the data object that this monitor handles. 
 * 
 * @since 1.0
 */
public class DataCallback<V> extends Callback {

    /** Data object reference */
    private V fData; 
    
    public DataCallback() {
        this(null);
    }

    public DataCallback(Callback parentCallback) {
        super(parentCallback);
    }

    /** 
     * Sets the data object to specified value.  To be called by the 
     * asynchronous method implementor.
     * @param data Data value to set.
     */
    public synchronized void setData(V data) { fData = data; }
    
    /**
     * Returns the data value, null if not set.
     */
    public synchronized V getData() { return fData; }
    
    public void done(V data, Throwable error) {
        setData(data);
        done(error);
    }
    
    @Override
    public String toString() { 
        if (getData() != null) {
            return getData().toString();
        } else {
            return super.toString();
        }
    }    
}

Back to the top