Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.service;
  
  
 
 
Since we need to pass lots of shared helper objects this class is used to collect them in one place to make passing of things bit easier. Not very elegant but works and is not overly complex.
 
 public abstract class SharedServiceStuff
 {
     /*
     /**********************************************************************
     /* Standard fields
     /**********************************************************************
      */
     
     protected final TimeMaster _timeMaster;
 
     protected final FileManager _fileManager;
     
     protected final ObjectMapper _jsonMapper_smileMapper;
 
     protected final RequestPathStrategy _pathStrategy;
 
     /*
     /**********************************************************************
     /* Construction
     /**********************************************************************
      */
 
     protected SharedServiceStuff(TimeMaster timeMasterFileManager fileManager,
             RequestPathStrategy pathStrategy)
     {
          = timeMaster;
          = fileManager;
          = pathStrategy;
 
         /* Ok, JSON/Smile support: need to register type handlers
          * (partly to avoid having to annotate types)
          */
          = new ObjectMapper();
         // with JSON, don't force numerics
         .registerModule(new ClusterMateTypesModule(false));
         
         SmileFactory sf = new SmileFactory();
         // for our data, sharing names fine, shared values are 'meh', but enable
 
         // and although we don't necessarily embed binary data, if we do, better be raw
         // as to header, trailer: header, absolutely must write and require for reads;
         // trailer: let's not; harmless but useless for our uses
         
         ObjectMapper smileMapper = new ObjectMapper(sf);
         // with Smile, numerics make sense:
         smileMapper.registerModule(new ClusterMateTypesModule(true));
 
         // JAX-RS doesn't quite like if we try to close output...
         smileMapper.configure(..false);
          = smileMapper;
     }
     
     /*
     /**********************************************************************
     /* Basic config access
     /**********************************************************************
      */
 
     public abstract <C extends ServiceConfig> C getServiceConfig();
     
     public abstract StoreConfig getStoreConfig();
 
     public abstract <K extends EntryKeyEntryKeyConverter<K> getKeyConverter();
    public abstract <K extends EntryKey, E extends StoredEntry<K>, L extends ListItem>
    public FileManager getFileManager() {
        return ;
    }
    public TimeMaster getTimeMaster() {
        return ;
    }
        return ;
    }
    /*
    /**********************************************************************
    /* Data formats
    /**********************************************************************
     */
    public ObjectMapper jsonMapper() {
        return ;
    }
    
    public ObjectReader jsonReader(Class<?> type) {
        return .reader(type);
    }
    public ObjectReader smileReader(Class<?> type) {
        return .reader(type);
    }
    public ObjectWriter jsonWriter() {
        return .writer();
    }
    public ObjectWriter jsonWriter(Class<?> type) {
        return .writerWithType(type);
    }
    public ObjectWriter smileWriter() {
        return .writer();
    }
    public ObjectWriter smileWriter(Class<?> type) {
        return .writerWithType(type);
    }
    
    public <T> T convertValue(Object valueClass<T> targetTypethrows IOException {
        return .convertValue(valuetargetType);
    }
    
    /*
    /**********************************************************************
    /* Support for tests
    /**********************************************************************
     */

    
Separate flag set by unit tests, to help reduce some log pollution during tests.

Oh yes, ugly it is. Dark times live in we....

    protected boolean _areWeTesting = false;
    
    public void markAsTest() {
         = true;
    }
    public boolean isRunningTests() {
        return ;
    }
New to GrepCode? Check out our FAQ X