Package thredds.server.opendap.servlet
Interface GuardedDataset
-
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
GuardedDatasetCacheAndClone,GuardedDatasetImpl
public interface GuardedDataset extends Closeable
A GuardedDataset allows us to handle multithreaded stateful processing. In a multi-threaded environment such as a Servlet, multiple requests for the same dataset may happen at the same time. This is a problem only when there is some state that is being maintained. Caching strategies (eg the netcdf server caches open netcdf files) may need to maintain state information in order to manage resources efficiently. All accesses to the DDS and DAS are made through the GuardedDataset. Typically the server puts a mutex lock on the resource when getDDS() or getDAS() is called. When the dataset processing is complete, release() is called, and the server releases the mutex. Example use:
Its important that the DDS or DAS not be used after release() is called. See opendap.servers.netcdf.NcDataset for example of implementing a locking GuardedDataset. If a server is not keeping state, it can simply pass the DDS and DAS without locking, and implement a dummy release() method.public void doGetDAS(HttpServletRequest request, HttpServletResponse response, ReqState rs) throws IOException, ServletException { response.setContentType("text/plain"); response.setHeader("XDODS-Server", getServerVersion() ); response.setHeader("Content-Description", "dods-dds"); OutputStream Out = new BufferedOutputStream(response.getOutputStream()); GuardedDataset ds = null; try { ds = getDataset(rs); DAS myDAS = ds.getDAS(); // server would lock here myDAS.print(Out); response.setStatus(response.SC_OK); } catch (DAP2Exception de){ dap2ExceptionHandler(de,response); } catch (ParseException pe) { parseExceptionHandler(pe,response); } finally { // release lock if needed if (ds != null) ds.release(); } }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()opendap.dap.DASgetDAS()Get the DAS for this Dataset.ServerDDSgetDDS()Get the DDS for this Dataset.voidrelease()Release the lock, if any, on this dataset.
-
-
-
Method Detail
-
getDDS
ServerDDS getDDS() throws opendap.dap.DAP2Exception, opendap.dap.parsers.ParseException
Get the DDS for this Dataset.- Returns:
- the ServerDDS
- Throws:
opendap.dap.DAP2Exceptionopendap.dap.parsers.ParseException
-
getDAS
opendap.dap.DAS getDAS() throws opendap.dap.DAP2Exception, opendap.dap.parsers.ParseExceptionGet the DAS for this Dataset.- Returns:
- the DAS
- Throws:
opendap.dap.DAP2Exceptionopendap.dap.parsers.ParseException
-
release
void release()
Release the lock, if any, on this dataset.
-
close
void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-