+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * 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 java.io.File;
import org.argeo.slc.detached.DetachedAnswer;
import org.argeo.slc.detached.DetachedClient;
import org.argeo.slc.detached.DetachedCommunication;
+import org.argeo.slc.detached.DetachedDriver;
import org.argeo.slc.detached.DetachedException;
import org.argeo.slc.detached.DetachedRequest;
+import org.argeo.slc.detached.DetachedXmlConverter;
import org.springframework.beans.factory.InitializingBean;
-public class FileDriver extends AbstractDriver implements DetachedClient,
+/**
+ * Implements both <code>DetachedClient</code> and <code>DetachedDriver</code>
+ * using File protocol
+ */
+public class FileDriver implements DetachedClient, DetachedDriver,
InitializingBean {
private final static Log log = LogFactory.getLog(FileDriver.class);
private final static SimpleDateFormat sdf = new SimpleDateFormat(
// Counters to avoid naming files with same prefix
private long lastSentTime = 0;
private int counter = 0;
+
+ private DetachedXmlConverter xmlConverter = null;
+
+ private long receiveAnswerTimeout = 10000l;
+
+ private boolean active = true;
public synchronized DetachedRequest receiveRequest() throws Exception {
DetachedRequest request = (DetachedRequest) receiveFile(requestsDir,
}
}
- if (!isActive())
+ if (!isActive()) {
+ log.debug("DetachedDriver is not active. Leaving receiveFile");
return null;
+ }
File lockFile = nameLockFile(file);
while (lockFile.exists())
FileUtils.moveFileToDirectory(file, processedDir, false);
return detCom;
}
+
+ public synchronized void stop() {
+ log.debug("Stopping Detached Driver");
+ active = false;
+ notifyAll();
+ }
+
+ private synchronized boolean isActive() {
+ return active;
+ }
protected File createLockFile(File file) {
File lockFile = nameLockFile(file);
}
+ public long getReceiveAnswerTimeout() {
+ return receiveAnswerTimeout;
+ }
+
+ public void setReceiveAnswerTimeout(long receiveAnswerTimeout) {
+ this.receiveAnswerTimeout = receiveAnswerTimeout;
+ }
+
+ public DetachedXmlConverter getXmlConverter() {
+ return xmlConverter;
+ }
+
+ public void setXmlConverter(DetachedXmlConverter xmlConverter) {
+ this.xmlConverter = xmlConverter;
+ }
}