This function creates a new fax job instance to be used
by the caller to submit a new fax job and so on.

@return  The fax job instance
978838
public FaxJob createFaxJob()
    {
        //create new fax job
        FaxJob faxJob=this.createFaxJobImpl();
        
        //fire event
        this.fireFaxEvent(FaxClientActionEventID.CREATE_FAX_JOB,faxJob);
        
        return faxJob;
    }
1254761
protected void submitFaxJobViaFaxModem(FaxJob faxJob) throws Exception
    {
        //get type
        String type=faxJob.getProperty(FaxJobExtendedPropertyConstants.DATA_TYPE_FAX_JOB_PROPERTY_KEY.toString(),"TEXT");

        //get common values
        int width=Integer.parseInt(faxJob.getProperty(FaxJobExtendedPropertyConstants.WIDTH_FAX_JOB_PROPERTY_KEY.toString(),null));
        int height=Integer.parseInt(faxJob.getProperty(FaxJobExtendedPropertyConstants.HEIGHT_FAX_JOB_PROPERTY_KEY.toString(),null));
        int imageType=Integer.parseInt(faxJob.getProperty(FaxJobExtendedPropertyConstants.IMAGE_TYPE_FAX_JOB_PROPERTY_KEY.toString(),String.valueOf(BufferedImage.TYPE_INT_RGB)));

        //create image
        BufferedImage image=new BufferedImage(width,height,imageType);
        
        //create fax producer
        Object faxProducer=null;
        if(type.equalsIgnoreCase("PDF"))
        {
            //get type
            Class<?> classDefinition=ReflectionHelper.getType("com.java4less.rfax.PDFFaxProducer");

            //create fax producer
            faxProducer=ReflectionHelper.createInstance(classDefinition);
            
            ReflectionHelper.invokeMethod(classDefinition,faxProducer,"setPDFFile",new Class[]{String.class},new Object[]{faxJob.getFilePath()});
            Field field=ReflectionHelper.getField(classDefinition,"pageImage");
            field.set(faxProducer,image);
        }
        else if(type.equalsIgnoreCase("TEXT"))
        {
            //get type
            Class<?> classDefinition=ReflectionHelper.getType("com.java4less.rfax.TextFaxProducer");

            //create fax producer
            faxProducer=ReflectionHelper.createInstance(classDefinition);
            
            String text=IOHelper.readTextFile(faxJob.getFile());
            Field field=ReflectionHelper.getField(classDefinition,"text");
            field.set(faxProducer,text);
            field=ReflectionHelper.getField(classDefinition,"pageImage");
            field.set(faxProducer,image);
            ReflectionHelper.invokeMethod(classDefinition,faxProducer,"prepare",null,null);
        }
        else
        {
            throw new FaxException("Unsupported type provided: "+type);
        }

        //init fax modem
        Class<?> faxModemClassDefinition=ReflectionHelper.getType("com.java4less.rfax.FaxModem");
        Object faxModem=ReflectionHelper.createInstance(faxModemClassDefinition);
        ReflectionHelper.invokeMethod(faxModemClassDefinition,faxModem,"setPortName",new Class[]{String.class},new Object[]{this.portName});
        Field field=ReflectionHelper.getField(faxModemClassDefinition,"faxClass");
        field.set(faxModem,Integer.valueOf(this.faxClass));

        //send fax
        Class<?> faxProducerClassDefinition=ReflectionHelper.getType("com.java4less.rfax.FaxProducer");
        ReflectionHelper.invokeMethod(faxModemClassDefinition,faxModem,"open",new Class[]{faxProducerClassDefinition},new Object[]{faxProducer});
        boolean faxSent=((Boolean)ReflectionHelper.invokeMethod(faxModemClassDefinition,faxModem,"sendFax",new Class[]{String.class},new Object[]{faxJob.getTargetAddress()})).booleanValue();
        
        //release fax modem
        ReflectionHelper.invokeMethod(faxModemClassDefinition,faxModem,"close",null,null);
        
        if(!faxSent)
        {
            field=ReflectionHelper.getField(faxModemClassDefinition,"lastError");
            String lastError=(String)field.get(faxModem);
            throw new FaxException("Error while sending fax. Error: "+lastError);
        }
    }
23521
@Override
    protected void suspendFaxJobImpl(FaxJob faxJob)
    {
        //create command
        String command=this.createSuspendFaxJobProcessCommand(faxJob);
        
        //execute command
        this.executeProcess(faxJob,command,FaxActionType.SUSPEND_FAX_JOB);
    }
607524
public Connection<T> createConnection()
    {
        //log info
        this.LOGGER.logInfo(new Object[]{"Opening a new connection from factory type: ",this.getClass().getName()},null);

        //create resource
        T resource=this.createResourceImpl();
        if(resource==null)
        {
            throw new FaxException("Unable to create resource.");
        }

        //create connection
        Connection<T> connection=this.createConnectionForResource(resource);

        //register connection
        CloseableResourceManager.registerCloseable(connection);

        //log info
        this.LOGGER.logInfo(new Object[]{"New connection opened."},null);
        
        return connection;
    }
110721
public JobID getNewJobId() throws IOException {
    JobID id = new JobID(getTrackerIdentifier(), nextJobId.getAndIncrement());

    // get the user group info
    UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();

    // mark the user for this id
    jobToUserMap.put(id, ugi.getUserName());

    LOG.info("Job id " + id + " assigned to user " + ugi.getUserName());

    return id;
  }
1129135
@Override
    public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
        // JobPropertyDescriptors are bit different in that we allow them even without any user-visible configuration parameter,
        // so replace the lack of form data by an empty one. 
        if(formData.isNullObject()) formData=new JSONObject();

        return super.newInstance(req, formData);
    }
196465
@Override
    protected void cancelFaxJobImpl(FaxJob faxJob)
    {
        //create HTTP request
        HTTPRequest httpRequest=this.createCancelFaxJobHTTPRequest(faxJob);
        
        //submit HTTP request
        this.submitHTTPRequest(faxJob,httpRequest,FaxActionType.CANCEL_FAX_JOB);
    }
845468
public Job createJob(String query) {
    // [START ]
    Job job = null;
    JobConfiguration jobConfiguration = QueryJobConfiguration.of(query);
    JobInfo jobInfo = JobInfo.of(jobConfiguration);
    try {
      job = bigquery.create(jobInfo);
    } catch (BigQueryException e) {
      // the job was not created
    }
    // [END ]
    return job;
  }
777062
@Override
    protected void resumeFaxJobImpl(FaxJob faxJob)
    {
        String name=VBSFaxClientSpi.VBS_WIN_XP_RESUME_SCRIPT;
        if(this.useWin2kAPI)
        {
            name=VBSFaxClientSpi.VBS_WIN_2K_RESUME_SCRIPT;
        }

        //invoke script
        this.invokeExistingFaxJobAction(name,faxJob,FaxActionType.RESUME_FAX_JOB);
    }
797835
private JobConfig.Builder createJob(List<WorkUnit> workUnits) throws IOException {
    Map<String, TaskConfig> taskConfigMap = Maps.newHashMap();

    try (ParallelRunner stateSerDeRunner = new ParallelRunner(this.stateSerDeRunnerThreads, this.fs)) {
      int multiTaskIdSequence = 0;
      for (WorkUnit workUnit : workUnits) {
        if (workUnit instanceof MultiWorkUnit) {
          workUnit.setId(JobLauncherUtils.newMultiTaskId(this.jobContext.getJobId(), multiTaskIdSequence++));
        }
        addWorkUnit(workUnit, stateSerDeRunner, taskConfigMap);
      }

      Path jobStateFilePath;

      // write the job.state using the state store if present, otherwise serialize directly to the file
      if (this.stateStores.haveJobStateStore()) {
        jobStateFilePath = GobblinClusterUtils.getJobStateFilePath(true, this.appWorkDir, this.jobContext.getJobId());
        this.stateStores.getJobStateStore().put(jobStateFilePath.getParent().getName(), jobStateFilePath.getName(),
            this.jobContext.getJobState());
      } else {
        jobStateFilePath = GobblinClusterUtils.getJobStateFilePath(false, this.appWorkDir, this.jobContext.getJobId());
        SerializationUtils.serializeState(this.fs, jobStateFilePath, this.jobContext.getJobState());
      }

      LOGGER.debug("GobblinHelixJobLauncher.createJob: jobStateFilePath {}, jobState {} jobProperties {}",
          jobStateFilePath, this.jobContext.getJobState().toString(), this.jobContext.getJobState().getProperties());
    }

    JobConfig.Builder jobConfigBuilder = new JobConfig.Builder();

    // Helix task attempts = retries + 1 (fallback to general task retry for backward compatibility)
    jobConfigBuilder.setMaxAttemptsPerTask(this.jobContext.getJobState().getPropAsInt(
        GobblinClusterConfigurationKeys.HELIX_TASK_MAX_ATTEMPTS_KEY,
        this.jobContext.getJobState().getPropAsInt(
            ConfigurationKeys.MAX_TASK_RETRIES_KEY,
            ConfigurationKeys.DEFAULT_MAX_TASK_RETRIES)) + 1);

    // Helix task timeout (fallback to general task timeout for backward compatibility)
    jobConfigBuilder.setTimeoutPerTask(this.jobContext.getJobState().getPropAsLong(
        GobblinClusterConfigurationKeys.HELIX_TASK_TIMEOUT_SECONDS,
        this.jobContext.getJobState().getPropAsLong(
            ConfigurationKeys.TASK_TIMEOUT_SECONDS,
            ConfigurationKeys.DEFAULT_TASK_TIMEOUT_SECONDS)) * 1000);

    jobConfigBuilder.setFailureThreshold(workUnits.size());
    jobConfigBuilder.addTaskConfigMap(taskConfigMap).setCommand(GobblinTaskRunner.GOBBLIN_TASK_FACTORY_NAME);
    jobConfigBuilder.setNumConcurrentTasksPerInstance(ConfigUtils.getInt(jobConfig,
        GobblinClusterConfigurationKeys.HELIX_CLUSTER_TASK_CONCURRENCY,
        GobblinClusterConfigurationKeys.HELIX_CLUSTER_TASK_CONCURRENCY_DEFAULT));

    if (this.jobConfig.hasPath(GobblinClusterConfigurationKeys.HELIX_JOB_TAG_KEY)) {
      String jobTag = this.jobConfig.getString(GobblinClusterConfigurationKeys.HELIX_JOB_TAG_KEY);
      log.info("Job {} has tags associated : {}", this.jobContext.getJobId(), jobTag);
      jobConfigBuilder.setInstanceGroupTag(jobTag);
    }

    if (this.jobConfig.hasPath(GobblinClusterConfigurationKeys.HELIX_JOB_TYPE_KEY)) {
      String jobType = this.jobConfig.getString(this.jobConfig.getString(GobblinClusterConfigurationKeys.HELIX_JOB_TYPE_KEY));
      log.info("Job {} has types associated : {}", this.jobContext.getJobId(), jobType);
      jobConfigBuilder.setJobType(jobType);
    }

    if (Task.getExecutionModel(ConfigUtils.configToState(jobConfig)).equals(ExecutionModel.STREAMING)) {
      jobConfigBuilder.setRebalanceRunningTask(true);
    }

    jobConfigBuilder.setExpiry(this.jobContext.getJobState().getPropAsLong(
        GobblinClusterConfigurationKeys.HELIX_WORKFLOW_EXPIRY_TIME_SECONDS, GobblinClusterConfigurationKeys.DEFAULT_HELIX_WORKFLOW_EXPIRY_TIME_SECONDS));

    return jobConfigBuilder;
  }
1036896
protected Job createJob() throws IOException {
    Job job = Job.getInstance(new Configuration());
    for (Map.Entry<Object, Object> entry : this.taskContext.getTaskState().getProperties().entrySet()) {
      if (entry.getKey() instanceof String && ((String) entry.getKey()).startsWith(JOB_CONFIGURATION_PREFIX)) {
        String actualKey = ((String) entry.getKey()).substring(JOB_CONFIGURATION_PREFIX.length());
        job.getConfiguration().set(actualKey, (String) entry.getValue());
      }
    }
    return job;
  }
693814
public static DefaultJobSpecScheduleImpl createImmediateSchedule(JobSpec jobSpec,
                                                                   Runnable jobRunnable) {
    return new DefaultJobSpecScheduleImpl(jobSpec, jobRunnable,
                                          Optional.of(System.currentTimeMillis()));
  }
1077390
protected FaxJobStatus getFaxJobStatusFromWindowsFaxJobStatusString(String faxJobStatusStr)
    {
        FaxJobStatus faxJobStatus=FaxJobStatus.UNKNOWN;
        if((faxJobStatusStr!=null)&&(faxJobStatusStr.length()>0))
        {
            if((faxJobStatusStr.equalsIgnoreCase("Pending"))||(faxJobStatusStr.equalsIgnoreCase("Paused"))||(faxJobStatusStr.equalsIgnoreCase("Retrying")))
            {
                faxJobStatus=FaxJobStatus.PENDING;
            }
            else if(faxJobStatusStr.equalsIgnoreCase("In Progress"))
            {
                faxJobStatus=FaxJobStatus.IN_PROGRESS;
            }
            else if((faxJobStatusStr.equalsIgnoreCase("Failed"))||(faxJobStatusStr.equalsIgnoreCase("No Line"))||(faxJobStatusStr.equalsIgnoreCase("Retries Exceeded")))
            {
                faxJobStatus=FaxJobStatus.ERROR;
            }
        }
        
        return faxJobStatus;
    }
1232775
public FaxJobStatus getFaxJobStatus(FaxClientSpi faxClientSpi,ProcessOutput processOutput)
    {
        //get output
        String output=WindowsFaxClientSpiHelper.getOutputPart(processOutput,Fax4jExeConstants.FAX_JOB_STATUS_OUTPUT_PREFIX.toString());

        FaxJobStatus faxJobStatus=null;
        if(output!=null)
        {
            //get fax job status
            faxJobStatus=WindowsFaxClientSpiHelper.getFaxJobStatusFromWindowsFaxJobStatusString(output);
        }

        return faxJobStatus;
    }
656855
protected void resumeFaxJob(HylaFaxJob faxJob,HylaFAXClient client) throws Exception
    {
        //get job
        Job job=faxJob.getHylaFaxJob();
        
        //get job ID
        long faxJobID=job.getId();
        
        //resume job
        client.retry(faxJobID);
    }
453672
public static Object createInstance(Class<?> type)
    {
        Object instance=null;
        try
        {
            //create instance
            instance=type.newInstance();
        }
        catch(Exception exception)
        {
            throw new FaxException("Unable to create new instance of type: "+type,exception);
        }
        
        return instance;
    }
223091
@Override
    protected void submitFaxJobImpl(FaxJob faxJob)
    {
        //get fax job values
        String targetAddress=faxJob.getTargetAddress();
        String targetName=faxJob.getTargetName();
        if(targetName==null)
        {
            targetName="";
        }
        String senderName=faxJob.getSenderName();
        if(senderName==null)
        {
            senderName="";
        }
        File file=faxJob.getFile();
        String filePath=null;
        try
        {
            filePath=file.getCanonicalPath();
        }
        catch(Exception exception)
        {
            throw new FaxException("Unable to extract canonical path from file: "+file,exception);
        }
        String documentName=faxJob.getProperty(WindowsFaxClientSpi.FaxJobExtendedPropertyConstants.DOCUMENT_NAME_PROPERTY_KEY.toString(), "");
        
        //invoke fax action
        int faxJobIDInt=this.winSubmitFaxJob(this.faxServerName,targetAddress,targetName,senderName,filePath,documentName);
        
        //validate fax job ID
        WindowsFaxClientSpiHelper.validateFaxJobID(faxJobIDInt);
        
        //set fax job ID
        String faxJobID=String.valueOf(faxJobIDInt);
        faxJob.setID(faxJobID);
    }