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 ServletWithMetricsBase
 {
     /*
     /**********************************************************************
     /* Helper objects
     /**********************************************************************
      */
 
     protected final SharedServiceStuff _stuff;
 //    protected final ServiceConfig _serviceConfig;
     
     protected final StoreHandler<K,E,?> _storeHandler;
 
     protected final ObjectWriter _jsonWriter;
 
     protected final EntryKeyConverter<K> _keyConverter;
 
     /*
     /**********************************************************************
     /* Metrics info
     /**********************************************************************
      */
 
     protected final OperationMetrics _getMetrics;
 
     protected final OperationMetrics _putMetrics;
 
     protected final OperationMetrics _deleteMetrics;
     
     /*
     /**********************************************************************
     /* 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(stuffclusterViewnull);
          = stuff;
          = storeHandler;
          = stuff.jsonWriter();
          = stuff.getKeyConverter();
         ServiceConfig serviceConfig = stuff.getServiceConfig();
         if (serviceConfig.metricsEnabled) {
              = OperationMetrics.forEntityOperation(serviceConfig"entryGet");
              = OperationMetrics.forEntityOperation(serviceConfig"entryPut");
              = OperationMetrics.forNonPayloadOperation(serviceConfig"entryDelete");
         } else {
              = null;
              = null;
              = null;
         }
     }
 
     protected StoreEntryServlet(StoreEntryServlet<K,E> base,
             boolean copyMetrics)
     {
         super(base._stuffbase._clusterViewnull);
          = base._stuff;
          = base._storeHandler;
          = base._jsonWriter;
          = base._keyConverter;
         if (copyMetrics) {
              = base._getMetrics;
              = base._putMetrics;
             = base._deleteMetrics;
        } else {
             = null;
             = null;
             = null;
        }
    }
    
    
"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);
    }
    /*
    /**********************************************************************
    /* Access to metrics (AllOperationMetrics.Provider impl)
    /**********************************************************************
     */
    @Override
    public void fillOperationMetrics(AllOperationMetrics metrics)
    {
        metrics.GET = ExternalOperationMetrics.create();
        metrics.PUT = ExternalOperationMetrics.create();
        metrics.DELETE = ExternalOperationMetrics.create();
        .augmentOperationMetrics(metrics);
    }
    
    /*
    /**********************************************************************
    /* Default implementations for key handling
    /**********************************************************************
     */
    protected K _findKey(ServletServiceRequest requestServletServiceResponse response)
    {
        return .extractFromPath(request);
    }
    
    /*
    /**********************************************************************
    /* Main Verb handlers
    /**********************************************************************
     */
    @Override
    public void handleGet(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        final OperationMetrics metrics = ;
        Context timer = (metrics == null) ? null : metrics.start();
        try {
            K key = _findKey(requestresponse);
            if (key != null) { // null means trouble; response has all we need
                response = _handleGet(requestresponsestatskey);
            }
            response.writeOut();
        } finally {
            if (metrics != null) {
                 metrics.finish(timerstats);
            }
        }
    }
    @Override
    public void handleHead(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        K key = _findKey(requestresponse);
        if (key != null) {
            response = _handleHead(requestresponsestatskey);
        }
        // note: should be enough to just add headers; no content to write
    }
    // We'll allow POST as an alias to PUT
    @Override // NOTE: final since it should be aliased, not overridden
    public final void handlePost(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        handlePut(requestresponsestats);
    }
    
    @Override
    public void handlePut(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        final OperationMetrics metrics = ;
        Context timer = (metrics == null) ? null : metrics.start();
        try {
            K key = _findKey(requestresponse);
            if (key != null) {
                response = _handlePut(requestresponsestatskey);
            }
            response.writeOut();
        } finally {
            if (metrics != null) {
                 metrics.finish(timerstats);
            }
        }
    }
    @Override
    public void handleDelete(ServletServiceRequest requestServletServiceResponse response,
            OperationDiagnostics statsthrows IOException
    {
        final OperationMetrics metrics = ;
        Context timer = (metrics == null) ? null : metrics.start();
        try {
            K key = _findKey(requestresponse);
            if (key != null) {
                response = _handleDelete(requestresponsestatskey);
            }
            response.writeOut();
        } finally {
            if (metrics != null) {
                metrics.finish(timerstats);
            }
        }
    }
    /*
    /**********************************************************************
    /* Handlers for actual operations, overridable
    /**********************************************************************
     */
            OperationDiagnostics stats, K key)
        throws IOException
    {
        response = (ServletServiceResponse.getEntry(requestresponsekeystats);
        _addStdHeaders(response);
        return response;
    }
            OperationDiagnostics stats, K key)
        throws IOException
    {
        response = (ServletServiceResponse.getEntryStats(requestresponsekeystats);
        _addStdHeaders(response);
        return response;
    }
            OperationDiagnostics stats, K key)
        throws IOException
    {
        response = (ServletServiceResponse.putEntry(requestresponsekeyrequest.getInputStream(), stats);
        _addStdHeaders(response);
        return response;
    }
            OperationDiagnostics stats, K key)
        throws IOException
    {
        response = (ServletServiceResponse.removeEntry(requestresponsekeystats);
        _addStdHeaders(response);
        return response;
    }    
New to GrepCode? Check out our FAQ X