Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.service.servlet;
  
  
  
  
Servlet that handles basic CRUD operations for individual entries.
 
 @SuppressWarnings("serial")
 public class StoreEntryServlet<K extends EntryKey, E extends StoredEntry<K>>
     extends ServletBase
 {
     /*
     /**********************************************************************
     /* Helper objects
     /**********************************************************************
      */
     
 //    private final Log LOG = Log.forClass(getClass());
 
     protected final StoreHandler<K,E,?> _storeHandler;
 
     protected final TimeMaster _timeMaster;
 
     protected final ObjectWriter _jsonWriter;
 
     protected final EntryKeyConverter<K> _keyConverter;
 
     /*
     /**********************************************************************
     /* Life-cycle
     /**********************************************************************
      */
     
     public StoreEntryServlet(SharedServiceStuff stuffClusterViewByServer clusterView,
             StoreHandler<K,E,?> storeHandler)
     {
         // null -> use servlet path base as-is
         super(clusterViewnull);
          = storeHandler;
          = stuff.getTimeMaster();
          = stuff.jsonWriter();
          = stuff.getKeyConverter();
     }
 
     /*
     /**********************************************************************
     /* Default implementation for key handling
     /**********************************************************************
      */
 
     protected K _findKey(ServletServiceRequest requestServletServiceResponse response)
     {
         return .extractFromPath(request);
     }
     
     /*
     /**********************************************************************
     /* Delegated methods for more control
     /**********************************************************************
      */
 
     @Override
     public void handleGet(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics statsthrows IOException
     {
         K key = _findKey(requestresponse);
         if (key != null) { // null means trouble; response has all we need
             .getEntry(requestresponsekeystats);
             _addStdHeaders(response);
         }
         response.writeOut();
     }
 
     @Override
     public void handleHead(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics statsthrows IOException
     {
         K key = _findKey(requestresponse);
         if (key != null) {
             .getEntryStats(requestresponsekeystats);
             _addStdHeaders(response);
         }
         // note: should be enough to just add headers; no content to write
     }
 
     // We'll allow POST as an alias to PUT
     @Override
    public void handlePost(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        handlePut(requestresponsestats);
    }
    
    @Override
    public void handlePut(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        K key = _findKey(requestresponse);
        if (key != null) {
            .putEntry(requestresponsekey,
                    request.getNativeRequest().getInputStream(),
                    stats);
            _addStdHeaders(response);
        }
        response.writeOut();
    }
    @Override
    public void handleDelete(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics metadatathrows IOException
    {
        K key = _findKey(requestresponse);
        if (key != null) {
            .removeEntry(requestresponsekeymetadata);
            _addStdHeaders(response);
        }
        response.writeOut();
    }
New to GrepCode? Check out our FAQ X