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
     /**********************************************************************
      */
 
     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)
     {
         this(stuffclusterViewstoreHandlerfalse);
     }
 
     protected StoreEntryServlet(SharedServiceStuff stuffClusterViewByServer clusterView,
             StoreHandler<K,E,?> storeHandlerboolean handleRouting)
     {
         // null -> use servlet path base as-is
         super(clusterViewnull);
          = storeHandler;
          = stuff.getTimeMaster();
          = stuff.jsonWriter();
          = stuff.getKeyConverter();
     }
 
     protected StoreEntryServlet(StoreEntryServlet<K,E> base)
     {
         super(base._clusterViewnull);
          = base._storeHandler;
          = base._timeMaster;
          = base._jsonWriter;
          = base._keyConverter;
     }
    
    
"Mutant factory" method used to create "routing" version of this servlet: this will basically handle request locally (as t
 
     public ServletBase createRoutingServlet() {
         return new RoutingEntryServlet<K,E>(this);
     }
 
     /*
     /**********************************************************************
     /* Default implementations for key handling
     /**********************************************************************
      */
 
     protected K _findKey(ServletServiceRequest requestServletServiceResponse response)
     {
         return .extractFromPath(request);
     }
     
     /*
     /**********************************************************************
     /* Main Verb handlers
     /**********************************************************************
      */
     
     @Override
     public final void handleGet(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics statsthrows IOException
     {
         K key = _findKey(requestresponse);
        if (key != null) { // null means trouble; response has all we need
            _handleGet(requestresponsestatskey);
        }
        response.writeOut();
    }
    @Override
    public final void handleHead(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        K key = _findKey(requestresponse);
        if (key != null) {
            _handleHead(requestresponsestatskey);
        }
        // note: should be enough to just add headers; no content to write
    }
    // We'll allow POST as an alias to PUT
    @Override
    public final void handlePost(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        handlePut(requestresponsestats);
    }
    
    @Override
    public final void handlePut(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        K key = _findKey(requestresponse);
        if (key != null) {
            _handlePut(requestresponsestatskey);
        }
        response.writeOut();
    }
    @Override
    public void handleDelete(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        K key = _findKey(requestresponse);
        if (key != null) {
            _handleDelete(requestresponsestatskey);
        }
        response.writeOut();
    }
    /*
    /**********************************************************************
    /* Handlers for actual operations, overridable
    /**********************************************************************
     */
    protected void _handleGet(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics stats, K key)
        throws IOException
    {
        .getEntry(requestresponsekeystats);
        _addStdHeaders(response);
    }
    protected void _handleHead(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics stats, K key)
        throws IOException
    {
        .getEntryStats(requestresponsekeystats);
        _addStdHeaders(response);
    }
    protected void _handlePut(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics stats, K key)
        throws IOException
    {
        .putEntry(requestresponsekey,
                request.getNativeRequest().getInputStream(),
                stats);
        _addStdHeaders(response);
    }
    protected void _handleDelete(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics stats, K key)
        throws IOException
    {
        .removeEntry(requestresponsekeystats);
        _addStdHeaders(response);
    }    
New to GrepCode? Check out our FAQ X