Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.clustermate.dw;
  
 
 
 
 
 public abstract class DWConfigBase<
   SCONFIG extends ServiceConfig,
   THIS extends DWConfigBase<SCONFIG, THIS>
 >
     extends Configuration
     implements Cloneable
 {
     protected String _appContext = "/";
 
     public DWConfigBase() {
         _ensureDefaults();
     }
 
     /*
     /**********************************************************************
     /* Overrides, to ensure invariants
     /**********************************************************************
      */
 
     // Overridden to ensure we have proper defaults. May become problematic
     // if users actually do want to change defaults; but let's worry about
     // that if this becomes issue.
     @Override
     public void setServerFactory(ServerFactory factory) {
         super.setServerFactory(factory);
         _ensureDefaults();
     }
     
     private void _ensureDefaults() {
         SimpleServerFactory simpleSF = simpleServerFactory();
         if (simpleSF != null) {
             simpleSF.setApplicationContextPath();
         }
         // and that gzip is not enabled by accident
         overrideGZIPEnabled(false);
     }
     
     /*
     /**********************************************************************
     /* Additional/abstract accessors
     /**********************************************************************
      */
 
     public abstract SCONFIG getServiceConfig();
 
     public int getApplicationPort() {
         AbstractServerFactory sf = serverFactory();
         if (sf instanceof SimpleServerFactory) {
             SimpleServerFactory ssf = (SimpleServerFactorysf;
             return ((HttpConnectorFactory)ssf.getConnector()).getPort();
         }
         if (sf instanceof DefaultServerFactory) {
             DefaultServerFactory dsf = (DefaultServerFactorysf;
             return ((HttpConnectorFactory)dsf.getApplicationConnectors().get(0)).getPort();
         }
         throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName());
     }
 
     public int getAdminPort() {
         AbstractServerFactory sf = serverFactory();
         if (sf instanceof SimpleServerFactory) {
             SimpleServerFactory ssf = (SimpleServerFactorysf;
             return ((HttpConnectorFactory)ssf.getConnector()).getPort();
         }
         if (sf instanceof DefaultServerFactory) {
             DefaultServerFactory dsf = (DefaultServerFactorysf;
             return ((HttpConnectorFactory)dsf.getAdminConnectors().get(0)).getPort();
         }
         throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName());
     }    
 
     /*
     /**********************************************************************
     /* Copying
     /**********************************************************************
      */
 
     @SuppressWarnings("unchecked")
     @Override
     public THIS clone() {
        try {
            return (THIS) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new IllegalStateException("Failed to clone "+getClass().getName()+", WTH?");
        }
    }
    /*
    /**********************************************************************
    /* Additional mutators; needed to work around DW strict access
    /**********************************************************************
     */
    @SuppressWarnings("unchecked")
    public THIS overrideHttpPort(int p) {
        AbstractServerFactory sf = serverFactory();
        if (sf instanceof SimpleServerFactory) {
            SimpleServerFactory ssf = (SimpleServerFactorysf;
            ((HttpConnectorFactory)ssf.getConnector()).setPort(p);
        } else if (sf instanceof DefaultServerFactory) {
            DefaultServerFactory dsf = (DefaultServerFactorysf;
            ((HttpConnectorFactory)dsf.getApplicationConnectors().get(0)).setPort(p);
        } else {
            throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName());
        }
        return (THIS) this;
    }
    @SuppressWarnings("unchecked")
    public THIS overrideAdminPort(int p) {
        AbstractServerFactory sf = serverFactory();
        if (sf instanceof SimpleServerFactory) {
            // no admin port; just ignore
        } else if (sf instanceof DefaultServerFactory) {
            DefaultServerFactory dsf = (DefaultServerFactorysf;
            ((HttpConnectorFactory)dsf.getAdminConnectors().get(0)).setPort(p);
        } else {
            throw new IllegalStateException("Unrecognized ServerFactory: "+sf.getClass().getName());
        }
        return (THIS) this;
    }
    @SuppressWarnings("unchecked")
    public THIS overrideGZIPEnabled(boolean state) {
        return (THIS) this;
    }
    
    @SuppressWarnings("unchecked")
    public THIS overrideLogLevel(Level minLevel) {
        // !!! TODO !!!
        //config.getLoggingConfiguration().setLevel(Level.WARN);
        return (THIS) this;
    }
    
    @SuppressWarnings("unchecked")
    public THIS overrideShutdownGracePeriod(Duration d) {
        return (THIS) this;
    }
    @SuppressWarnings("unchecked")
    public THIS overrideSyncGracePeriod(TimeSpan t) {
        getServiceConfig(). = t;
        return (THIS) this;
    }
    @SuppressWarnings("unchecked")
    public THIS overrideApplicationContextPath(String path) {
         = path;
        _overrideApplicationContextPath(path);
        return (THIS) this;
    }

    
Method called to suppress all request logging; usually during testing.
    @SuppressWarnings("unchecked")
    public THIS disableRequestLog() {
        reqLog.setAppenders(ImmutableList.<AppenderFactory>of());        
        return (THIS) this;
    }
    protected AbstractServerFactory serverFactory() {
        return (AbstractServerFactorygetServerFactory();
    }
        AbstractServerFactory sf = serverFactory();
        return (sf instanceof SimpleServerFactory) ? (SimpleServerFactorysf : null;
    }
    private void _overrideApplicationContextPath(String path) {
        SimpleServerFactory simpleSF = simpleServerFactory();
        if (simpleSF != null) {
            simpleSF.setApplicationContextPath(path);
        }
    }
New to GrepCode? Check out our FAQ X