dods.servlet
Interface GuardedDataset

All Known Subinterfaces:
GuardedSQLDataset
All Known Implementing Classes:
sqlDataset, testDataset

public interface GuardedDataset

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:


    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 (DODSException de){
          dodsExceptionHandler(de,response);
        }
        catch (ParseException pe) {
          parseExceptionHandler(pe,response);
        }
        finally {                           // release lock if needed
          if (ds != null) ds.release();
        }
   }
   
Its important that the DDS or DAS not be used after release() is called. See dods.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.

Author:
jcaron
See Also:
dods.servers.netcdf.NcDataset, dods.servers.agg.Dataset

Method Summary
 DAS getDAS()
          Get the DAS for this Dataset.
 ServerDDS getDDS()
          Get the DDS for this Dataset.
 void release()
          Release the lock, if any, on this dataset.
 

Method Detail

getDDS

public ServerDDS getDDS()
                 throws DODSException,
                        ParseException
Get the DDS for this Dataset.

Returns:
the ServerDDS
Throws:
DODSException
ParseException

getDAS

public DAS getDAS()
           throws DODSException,
                  ParseException
Get the DAS for this Dataset.

Returns:
the DAS
Throws:
DODSException
ParseException

release

public void release()
Release the lock, if any, on this dataset.