blob: a7a784efd200050058d10f3197608a35e617b62e (
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
|
/*******************************************************************************
* Copyright (c) 2011, 2012 Wind River Systems 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;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.tcf.debug.test.services.ResetMap.IResettable;
import org.eclipse.tcf.protocol.IToken;
/**
*
*/
public abstract class TokenCache<V> extends AbstractCache<V> implements IResettable {
private AtomicReference<IToken> fToken = new AtomicReference<IToken>();
@Override
final protected void retrieve() {
fToken.set(retrieveToken());
}
protected boolean checkToken(IToken token) {
return fToken.compareAndSet(token, null);
}
abstract protected IToken retrieveToken();
protected void set(IToken token, V data, Throwable error) {
if (checkToken(token) ) {
set(data, error, true);
}
}
@Override
protected void canceled() {
IToken token = fToken.getAndSet(null);
token.cancel();
}
}
|