package org.argeo.slc.detached.drivers;
-import java.util.Stack;
-
import org.argeo.slc.detached.DetachedAnswer;
import org.argeo.slc.detached.DetachedClient;
import org.argeo.slc.detached.DetachedRequest;
public class MemoryDriver extends AbstractDriver implements DetachedClient {
- private final static Stack stack = new Stack();
+ private DetachedRequest currentRequest = null;
+ private DetachedAnswer currentAnswer = null;
// DRIVER
- public DetachedRequest receiveRequest() throws Exception {
- // TODO Auto-generated method stub
- return null;
+ public synchronized DetachedRequest receiveRequest() throws Exception {
+ while (currentRequest == null)
+ this.wait(500);
+ return currentRequest;
}
- public void sendAnswer(DetachedAnswer answer) throws Exception {
- // TODO Auto-generated method stub
-
+ public synchronized void sendAnswer(DetachedAnswer answer) throws Exception {
+ currentAnswer = answer;
+ this.notify();
}
// CLIENT
- public DetachedAnswer receiveAnswer() throws Exception {
- // TODO Auto-generated method stub
- return null;
+ public synchronized DetachedAnswer receiveAnswer() throws Exception {
+ while (currentAnswer == null)
+ this.wait(500);
+ DetachedAnswer answer = currentAnswer;
+ currentAnswer = null;
+ currentRequest = null;
+ return answer;
}
- public void sendRequest(DetachedRequest request) throws Exception {
- // TODO Auto-generated method stub
-
+ public synchronized void sendRequest(DetachedRequest request)
+ throws Exception {
+ currentRequest = request;
+ this.notify();
}
}