Project

General

Profile

Download (2.58 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.common.monitor;
11

    
12
import java.io.Serializable;
13
import java.util.ArrayList;
14
import java.util.List;
15

    
16

    
17
/**
18
 * @author cmathew
19
 * @date 14 Oct 2015
20
 *
21
 */
22
public class RemotingProgressMonitor extends RestServiceProgressMonitor implements IRemotingProgressMonitor {
23

    
24
    private Serializable result;
25
    private List<String> reports = new ArrayList<String>();
26
    private String owner;
27
    private Serializable feedback;
28
    private transient Object feedbackLock;
29
    private boolean isWaitingForFeedback = false;
30

    
31

    
32
    /**
33
     * {@inheritDoc}
34
     */
35
    @Override
36
    public Object getResult() {
37
        return result;
38
    }
39

    
40

    
41
    /**
42
     * {@inheritDoc}
43
     */
44
    @Override
45
    public void setResult(Serializable result) {
46
        this.result = result;
47
    }
48

    
49

    
50
    /**
51
     * {@inheritDoc}
52
     */
53
    @Override
54
    public List<String> getReports() {
55
        return reports;
56
    }
57

    
58

    
59
    /**
60
     * {@inheritDoc}
61
     */
62
    @Override
63
    public void addReport(String report) {
64
        reports.add(report);
65
    }
66

    
67

    
68
    /**
69
     * {@inheritDoc}
70
     */
71
    @Override
72
    public String getOwner() {
73
        return owner;
74
    }
75

    
76

    
77
    /**
78
     * {@inheritDoc}
79
     */
80
    @Override
81
    public void setOwner(String owner) {
82
        this.owner = owner;
83
    }
84

    
85
    /**
86
     * {@inheritDoc}
87
     */
88
    @Override
89
    public void waitForFeedback() {
90
        if(feedbackLock == null) {
91
            feedbackLock =  new Object();
92
        }
93
        synchronized (feedbackLock) {
94
            feedback = null;
95
            while(feedback == null) {
96
                isWaitingForFeedback = true;
97
                try {
98
                    feedbackLock.wait();
99
                } catch (InterruptedException ie) {
100
                    throw new IllegalStateException(ie);
101
                }
102
            }
103
        }
104
    }
105

    
106
    /**
107
     * {@inheritDoc}
108
     */
109
    @Override
110
    public void setFeedback(Serializable feedback) {
111
        synchronized (feedbackLock) {
112
            this.feedback = feedback;
113
            this.feedbackLock.notifyAll();
114
            isWaitingForFeedback = false;
115
        }
116
    }
117

    
118

    
119
    /**
120
     * {@inheritDoc}
121
     */
122
    @Override
123
    public Serializable getFeedback() {
124
        return feedback;
125
    }
126

    
127
    /**
128
     * {@inheritDoc}
129
     */
130
    @Override
131
    public boolean isWaitingForFeedback() {
132
        return isWaitingForFeedback;
133
    }
134

    
135
}
(7-7/9)