Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.service.servlet;
  
  
Specialized sub-type of Entry servlet that will either serve request locally (if data available), or return redirect code to indicate client who to call instead.

TODO: complete -- not yet ready

 
 @SuppressWarnings("serial")
 public class RoutingEntryServlet<K extends EntryKey, E extends StoredEntry<K>>
     extends StoreEntryServlet<K,E>
 {
     public RoutingEntryServlet(StoreEntryServlet<K,E> base)
     {
         // true -> share metrics with the "real" servlet. Can separate in future if need be
         super(basetrue);
     }
     
     /*
     /**********************************************************************
     /* Overridable helper methods
     /**********************************************************************
      */
     
     protected boolean _isStoredLocally(K key) {
         return .containsLocally(key);
     }
 
     protected int _findRetryCount(ServletServiceRequest request)
     {
         if (str != null) {
             str = str.trim();
             if (str.length() > 0) {
                 try {
                     return Integer.parseInt(str);
                 } catch (NumberFormatException e) { }
             }
         }
         return -1;
     }
 
     /*
     /**********************************************************************
     /* Overriden handler methods
     /**********************************************************************
      */
 
     @Override
     protected void _handleGet(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics stats, K key)
         throws IOException
     {
         .getEntry(requestresponsekeystats);
         _addStdHeaders(response);
     }
 
     @Override
     protected void _handleHead(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics stats, K key)
         throws IOException
     {
         .getEntryStats(requestresponsekeystats);
         _addStdHeaders(response);
     }
 
     @Override
     protected void _handlePut(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics stats, K key)
         throws IOException
     {
         .putEntry(requestresponsekey,
                 request.getNativeRequest().getInputStream(),
                 stats);
         _addStdHeaders(response);
     }
 
     @Override
     protected void _handleDelete(ServletServiceRequest requestServletServiceResponse response,
             OperationDiagnostics stats, K key)
         throws IOException
     {
         .removeEntry(requestresponsekeystats);
         _addStdHeaders(response);
     }
 
     /*
     /**********************************************************************
     /* Helper methods
     /**********************************************************************
     */
    protected NodeState _findRedirect(ServletServiceRequest requestServletServiceResponse response, K key)
    {
        // First: retry count always affects things
        int retry = _findRetryCount(request);
        // except for one case; first try, and we have entry locally
        boolean hasLocally = _isStoredLocally(key);
        if (hasLocally && (retry == 0)) {
            return null;
        }
        // otherwise need to find ordered set of targets
        
        // !!! TODO
        return null;
    }
New to GrepCode? Check out our FAQ X