protected boolean initialize(Session session, boolean restrictHosts, 
            boolean getForwardHeader)
        throws IOException, RequestException {
        String queryText = INIT_QUERY;
        if (getForwardHeader) {
            StringBuilder buf = new StringBuilder();
            buf.append(HEADER_QUERY).append(";\n").append(queryText);
            queryText = buf.toString();
        }
        AdhocQuery query = session.newAdhocQuery(queryText);
        RequestOptions options = new RequestOptions();
        options.setDefaultXQueryVersion("1.0-ml");
        query.setOptions(options);
        ResultSequence result = null;
        if (LOG.isDebugEnabled()) {
            LOG.debug("init query: \n" + query.getQuery());
        }
        result = session.submitRequest(query);

        ResultItem item = result.next();
        boolean forwardHeaderExists = false;
        if (getForwardHeader) {
            forwardHeaderExists = item.asString().equals("true");
            item = result.next();
            if (forwardHeaderExists) {
                restrictHosts = true;
                conf.setBoolean(OUTPUT_RESTRICT_HOSTS, true);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("HTTP compliant mode enabled since x-forwarded-for exists");
                }
            } else {
                // check if input needs to be in HTTP compliant mode
                String inputRestrictHost = conf.getTrimmed(INPUT_RESTRICT_HOSTS);
                if (inputRestrictHost == null || 
                    inputRestrictHost.equalsIgnoreCase("false")) {
                    HttpChannel.setUseHTTP(false);
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("HTTP compliant mode disabled since x-forwarded-for doesn't exist");
                    }
                }
            }
        }
        initHostName = item.asString();
        item = result.next();
        am.setEffectiveVersion(((XSInteger)item.getItem()).asLong());
        item = result.next();
        failover = !restrictHosts && item.asString().equals("true");
        if (result.hasNext()) {
            item = result.next();
            String policyStr = item.asString();
            conf.set(ASSIGNMENT_POLICY, policyStr);
            policy = AssignmentPolicy.Kind.forName(policyStr);
            item = result.next();
            allowFastLoad = Boolean.parseBoolean(item.asString());
            if ((policy == AssignmentPolicy.Kind.STATISTICAL 
                || policy == AssignmentPolicy.Kind.RANGE
                || policy == AssignmentPolicy.Kind.QUERY)
                && !allowFastLoad && conf.getBoolean(OUTPUT_FAST_LOAD, false)) {
                throw new IOException(
                    "Fastload can't be used: rebalancer is on and "
                        + "forests are imbalanced in a database with "
                        + "statistics-based assignment policy");
            }
        } else {
        	policy = AssignmentPolicy.Kind.LEGACY;
        	legacy = true;
        }
        
        // initialize fastload mode
        if (conf.get(OUTPUT_FAST_LOAD) == null) {
            // fastload not set
            if (conf.get(OUTPUT_DIRECTORY) != null) {
                // output_dir is set, attempt to do fastload
                if(conf.get(OUTPUT_PARTITION) == null && 
                   (policy == AssignmentPolicy.Kind.RANGE ||
                    policy == AssignmentPolicy.Kind.QUERY)) {
                    fastLoad = false;
                } else if (policy == AssignmentPolicy.Kind.RANGE ||
                           policy == AssignmentPolicy.Kind.QUERY ||
                	   policy == AssignmentPolicy.Kind.STATISTICAL) {
                    fastLoad = allowFastLoad;
                } else {
                	fastLoad = true;
                }
            } else {
                //neither fastload nor output_dir is set
                fastLoad = false;
            }
        } else {
            fastLoad = conf.getBoolean(OUTPUT_FAST_LOAD, false);
            if (fastLoad && conf.get(OUTPUT_PARTITION) == null
                && (policy == AssignmentPolicy.Kind.RANGE ||
                    policy == AssignmentPolicy.Kind.QUERY)) {
                throw new IllegalArgumentException(
                    "output_partition is required for fastload mode.");
            }
        }
        conf.setBoolean(OUTPUT_FAST_LOAD, fastLoad);
        return restrictHosts;
    }
protected boolean initialize ( Session session , boolean restrictHosts , boolean getForwardHeader ) throws IOException , RequestException { String queryText = INIT_QUERY ; if ( getForwardHeader ) { StringBuilder buf = new StringBuilder ( ) ; buf . append ( HEADER_QUERY ) . append ( ";\n" ) . append ( queryText ) ; queryText = buf . toString ( ) ; } AdhocQuery query = session . newAdhocQuery ( queryText ) ; RequestOptions options = new RequestOptions ( ) ; options . setDefaultXQueryVersion ( "1.0-ml" ) ; query . setOptions ( options ) ; ResultSequence result = null ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "init query: \n" + query . getQuery ( ) ) ; } result = session . submitRequest ( query ) ; ResultItem item = result . next ( ) ; boolean forwardHeaderExists = false ; if ( getForwardHeader ) { forwardHeaderExists = item . asString ( ) . equals ( "true" ) ; item = result . next ( ) ; if ( forwardHeaderExists ) { restrictHosts = true ; conf . setBoolean ( OUTPUT_RESTRICT_HOSTS , true ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "HTTP compliant mode enabled since x-forwarded-for exists" ) ; } } else { String inputRestrictHost = conf . getTrimmed ( INPUT_RESTRICT_HOSTS ) ; if ( inputRestrictHost == null || inputRestrictHost . equalsIgnoreCase ( "false" ) ) { HttpChannel . setUseHTTP ( false ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "HTTP compliant mode disabled since x-forwarded-for doesn't exist" ) ; } } } } initHostName = item . asString ( ) ; item = result . next ( ) ; am . setEffectiveVersion ( ( ( XSInteger ) item . getItem ( ) ) . asLong ( ) ) ; item = result . next ( ) ; failover = ! restrictHosts && item . asString ( ) . equals ( "true" ) ; if ( result . hasNext ( ) ) { item = result . next ( ) ; String policyStr = item . asString ( ) ; conf . set ( ASSIGNMENT_POLICY , policyStr ) ; policy = AssignmentPolicy . Kind . forName ( policyStr ) ; item = result . next ( ) ; allowFastLoad = Boolean . parseBoolean ( item . asString ( ) ) ; if ( ( policy == AssignmentPolicy . Kind . STATISTICAL || policy == AssignmentPolicy . Kind . RANGE || policy == AssignmentPolicy . Kind . QUERY ) && ! allowFastLoad && conf . getBoolean ( OUTPUT_FAST_LOAD , false ) ) { throw new IOException ( "Fastload can't be used: rebalancer is on and " + "forests are imbalanced in a database with " + "statistics-based assignment policy" ) ; } } else { policy = AssignmentPolicy . Kind . LEGACY ; legacy = true ; } if ( conf . get ( OUTPUT_FAST_LOAD ) == null ) { if ( conf . get ( OUTPUT_DIRECTORY ) != null ) { if ( conf . get ( OUTPUT_PARTITION ) == null && ( policy == AssignmentPolicy . Kind . RANGE || policy == AssignmentPolicy . Kind . QUERY ) ) { fastLoad = false ; } else if ( policy == AssignmentPolicy . Kind . RANGE || policy == AssignmentPolicy . Kind . QUERY || policy == AssignmentPolicy . Kind . STATISTICAL ) { fastLoad = allowFastLoad ; } else { fastLoad = true ; } } else { fastLoad = false ; } } else { fastLoad = conf . getBoolean ( OUTPUT_FAST_LOAD , false ) ; if ( fastLoad && conf . get ( OUTPUT_PARTITION ) == null && ( policy == AssignmentPolicy . Kind . RANGE || policy == AssignmentPolicy . Kind . QUERY ) ) { throw new IllegalArgumentException ( "output_partition is required for fastload mode." ) ; } } conf . setBoolean ( OUTPUT_FAST_LOAD , fastLoad ) ; return restrictHosts ; }
Initialize initial server host name, assignment policy and fastload.

@param session
@return true if restrict_hosts is to be enabled; false otherwise
@throws IOException
@throws RequestException