com.clustercontrol.agent.job.DeleteProcessThread.java Source code

Java tutorial

Introduction

Here is the source code for com.clustercontrol.agent.job.DeleteProcessThread.java

Source

/*
    
Copyright (C) 2011 NTT DATA Corporation
    
This program is free software; you can redistribute it and/or
Modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, version 2.
    
This program is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the GNU General Public License for more details.
    
 */

package com.clustercontrol.agent.job;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.clustercontrol.agent.SendQueue;
import com.clustercontrol.agent.util.AgentProperties;
import com.clustercontrol.jobmanagement.bean.RunStatusConstant;
import com.clustercontrol.util.HinemosTime;
import com.clustercontrol.ws.jobmanagement.RunInstructionInfo;
import com.clustercontrol.ws.jobmanagement.RunResultInfo;

/**
 * ?<BR>
 * 
 * ?????????
 * 
 */
public class DeleteProcessThread extends AgentThread {

    // 
    static private Log m_log = LogFactory.getLog(DeleteProcessThread.class);

    // ?????
    private String m_inputEncoding = null;

    /**
     * 
     * 
     * @param info
     *            
     * @param sendQueue
     *            ?
     * @param runHistory
     *            
     */
    public DeleteProcessThread(RunInstructionInfo info, SendQueue sendQueue) {
        super(info, sendQueue);

        // ?
        m_inputEncoding = AgentProperties.getProperty("job.stream.charset");
        if (m_inputEncoding == null) {
            m_inputEncoding = System.getProperty("file.encoding");
        }
        m_log.info("job.encoding.stdstream = " + m_inputEncoding);
    }

    /**
     * ?<BR>
     * 
     * ReceiveTopic??????????? ??????
     * 
     */
    /*
     * (non-Javadoc)
     * 
     * @see java.lang.Runnable#run()
     */
    @Override
    public void run() {
        m_log.debug("run start");

        Process process = null;

        //??
        process = RunHistoryUtil.findRunHistory(m_info);

        if (process == null) {
            // ????????
            m_log.warn("run() : process is null");
            RunResultInfo info = new RunResultInfo();
            info.setSessionId(m_info.getSessionId());
            info.setJobunitId(m_info.getJobunitId());
            info.setJobId(m_info.getJobId());
            info.setFacilityId(m_info.getFacilityId());
            info.setCommand(m_info.getCommand());
            info.setCommandType(m_info.getCommandType());
            info.setStopType(m_info.getStopType());
            info.setStatus(RunStatusConstant.ERROR);
            info.setTime(HinemosTime.getDateInstance().getTime());
            info.setEndValue(-1);
            info.setMessage("Internal Error : Ex. Agent restarted or Job already terminated.");
            info.setErrorMessage("");
            // ?
            m_sendQueue.put(info);
            return;
        }

        // ---------------------------
        // -- ?
        // ---------------------------

        // ?
        RunResultInfo info = new RunResultInfo();
        info.setSessionId(m_info.getSessionId());
        info.setJobunitId(m_info.getJobunitId());
        info.setJobId(m_info.getJobId());
        info.setFacilityId(m_info.getFacilityId());
        info.setCommand(m_info.getCommand());
        info.setCommandType(m_info.getCommandType());
        info.setStopType(m_info.getStopType());
        info.setStatus(RunStatusConstant.START);
        info.setTime(HinemosTime.getDateInstance().getTime());

        m_log.info("Process Delete SessionID=" + m_info.getSessionId() + ", JobID=" + m_info.getJobId());

        // ?
        m_sendQueue.put(info);

        //??
        m_log.info("run() : shutdown process : " + process.toString());
        try {
            process.destroy();
            info.setEndValue(process.waitFor());
        } catch (Exception e) {
            m_log.warn("shutdown process : " + e.getMessage());

            // ?
            info.setTime(HinemosTime.getDateInstance().getTime());
            info.setEndValue(-1);
            info.setStatus(RunStatusConstant.ERROR);
            info.setMessage(e.getMessage());
            info.setErrorMessage("");
            m_sendQueue.put(info);
            return;
        }

        // ---------------------------
        // -- ?
        // ---------------------------

        info.setTime(HinemosTime.getDateInstance().getTime());
        info.setStatus(RunStatusConstant.END);
        m_sendQueue.put(info);

        ////?
        RunHistoryUtil.delRunHistory(m_info);

        m_log.debug("run end");
    }
}