]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.detached/src/main/java/org/argeo/slc/detached/drivers/MemoryDriver.java
Clean up directories
[gpl/argeo-slc.git] / runtime / org.argeo.slc.detached / src / main / java / org / argeo / slc / detached / drivers / MemoryDriver.java
index ffae5efda30b843cbec3f8203fbea59407154b16..353ef78fee658e3043f9bab8571e94038b76c789 100644 (file)
@@ -1,31 +1,62 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 package org.argeo.slc.detached.drivers;
 
 import org.argeo.slc.detached.DetachedAnswer;
 import org.argeo.slc.detached.DetachedClient;
+import org.argeo.slc.detached.DetachedDriver;
 import org.argeo.slc.detached.DetachedRequest;
 
-public class MemoryDriver extends AbstractDriver implements DetachedClient {
+/**
+ * Implements both <code>DetachedClient</code> and <code>DetachedDriver</code>
+ * using memory access
+ */
+public class MemoryDriver implements DetachedClient, DetachedDriver {
+       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();
        }
 
+       public void stop() {
+               // NOTHING
+       }
 }