Search in sources :

Example 1 with MIMPProcessorLog

use of org.compiere.model.MIMPProcessorLog in project adempiere by adempiere.

the class ReplicationProcessor method doWork.

@SuppressWarnings("unchecked")
@Override
protected void doWork() {
    if (isProcessRunning) {
    // process is already started successfully!
    } else {
        // process is not started!
        m_summary = new StringBuffer();
        String trxName = mImportProcessor.get_TrxName();
        if (trxName == null || "".equals(trxName)) {
        //				trxName = "ImportProcessor-" + System.currentTimeMillis();
        }
        log.fine("trxName = " + trxName);
        log.fine("ImportProcessor = " + mImportProcessor);
        int IMP_ProcessorType_ID = 0;
        IMP_ProcessorType_ID = mImportProcessor.getIMP_Processor_Type_ID();
        X_IMP_Processor_Type impProcessor_Type = new X_IMP_Processor_Type(mImportProcessor.getCtx(), IMP_ProcessorType_ID, trxName);
        // TODO --- REMOVE
        log.fine("impProcessor_Type = " + impProcessor_Type);
        String javaClass = impProcessor_Type.getJavaClass();
        IImportProcessor importProcessor = null;
        try {
            Class clazz = Class.forName(javaClass);
            importProcessor = (IImportProcessor) clazz.newInstance();
            importProcessor.process(mImportProcessor.getCtx(), this, trxName);
        } catch (Exception e) {
            isProcessRunning = false;
            log.fine("ReplicationProcessor caught an exception !!!");
            e.printStackTrace();
            log.severe(e.getMessage());
            MIMPProcessorLog pLog = new MIMPProcessorLog(mImportProcessor, e.getMessage());
            pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork)));
            pLog.saveEx();
            try {
                importProcessor.stop();
            } catch (Exception e1) {
                e1.printStackTrace();
                MIMPProcessorLog pLog2 = new MIMPProcessorLog(mImportProcessor, e1.getMessage());
                pLog2.saveEx();
            }
        }
        //
        int no = mImportProcessor.deleteLog();
        m_summary.append("Logs Records deleted=").append(no).append("; ");
        //
        MIMPProcessorLog pLog = new MIMPProcessorLog(mImportProcessor, m_summary.toString());
        pLog.setReference("#" + String.valueOf(p_runCount) + " - " + TimeUtil.formatElapsed(new Timestamp(p_startWork)));
        pLog.saveEx();
    }
}
Also used : MIMPProcessorLog(org.compiere.model.MIMPProcessorLog) IImportProcessor(org.adempiere.server.rpl.IImportProcessor) X_IMP_Processor_Type(org.compiere.model.X_IMP_Processor_Type) Timestamp(java.sql.Timestamp)

Example 2 with MIMPProcessorLog

use of org.compiere.model.MIMPProcessorLog in project adempiere by adempiere.

the class TopicListener method run.

public void run() throws JMSException {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
    log.finest("ActiveMQConnectionFactory = " + factory);
    if (userName != null && password != null) {
        conn = factory.createConnection(userName, password);
    } else {
        conn = factory.createConnection();
    }
    log.finest("conn = " + conn);
    if (conn.getClientID() == null) {
        try {
            conn.setClientID(clientID);
        } catch (Exception e) {
            //log.info("Connection with clientID '" + clientID +"' already exists" + e.toString());
            conn.close();
            return;
        }
    } else {
        if (conn.getClientID().equals(clientID)) {
            log.warning("Connection with clientID '" + clientID + "' already exists");
            conn.close();
            return;
        } else {
            try {
                conn.setClientID(clientID);
            } catch (Exception e) {
                log.info("Error while invoking setClientID(" + clientID + ")! " + e.getMessage());
                conn.close();
                return;
            }
        }
    }
    // TODO - could be parameter
    session = conn.createSession(true, Session.AUTO_ACKNOWLEDGE);
    log.finest("session = " + session);
    log.finest("topicName = " + topicName);
    log.finest("subscriptionName = " + subscriptionName);
    topic = session.createTopic(topicName);
    log.finest("topic = " + topic);
    MessageConsumer consumer = null;
    if (isDurableSubscription) {
        // http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.pmc.express.doc/tasks/tjn0012_.html
        // The subscriptionName assigned to a durable subscription must be unique within a given client ID.
        consumer = session.createDurableSubscriber(topic, subscriptionName);
    } else {
        consumer = session.createConsumer(topic);
    }
    log.finest("consumer = " + consumer);
    consumer.setMessageListener(this);
    conn.start();
    log.finest("Waiting for JMS messages...");
    if (replicationProcessor != null) {
        MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Connected to JMS Server. Waiting for messages!");
        StringBuffer logReference = new StringBuffer("topicName = ").append(topicName).append(", subscriptionName = ").append(subscriptionName);
        pLog.setReference(logReference.toString());
        boolean resultSave = pLog.save();
        log.finest("Result Save = " + resultSave);
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) MIMPProcessorLog(org.compiere.model.MIMPProcessorLog) JMSException(javax.jms.JMSException)

Example 3 with MIMPProcessorLog

use of org.compiere.model.MIMPProcessorLog in project adempiere by adempiere.

the class TopicListener method onMessage.

/**
	 * 
	 */
public void onMessage(Message message) {
    if (message instanceof TextMessage) {
        try {
            TextMessage txtMessage = (TextMessage) message;
            String text = txtMessage.getText();
            log.finest("Received message: \n" + text);
            Document documentToBeImported = XMLHelper.createDocumentFromString(text);
            StringBuffer result = new StringBuffer();
            ImportHelper impHelper = new ImportHelper(ctx);
            impHelper.importXMLDocument(result, documentToBeImported, trxName);
            log.finest("Message processed ...");
            if (replicationProcessor != null) {
                MIMPProcessorLog pLog = new MIMPProcessorLog(replicationProcessor.getMImportProcessor(), "Imported Document!");
                //pLog.setReference("topicName = " + topicName );
                if (text.length() > 2000) {
                    pLog.setTextMsg(text.substring(0, 1999));
                } else {
                    pLog.setTextMsg(text);
                }
                pLog.saveEx();
            }
            session.commit();
        } catch (Exception e) {
            log.finest("Rollback = " + e.toString());
            try {
                session.rollback();
                stop();
                //replicationProcessor.interrupt();
                //replicationProcessor.join();	
                replicationProcessor.setProcessRunning(false);
            }/*catch (InterruptedException e1) {
				    // TODO Auto-generated catch block
				    e1.printStackTrace();
				}*/
             catch (JMSException e2) {
                e2.printStackTrace();
            }
            e.printStackTrace();
        }
    } else {
        log.finest("Received NO TEXT Message: ");
    }
}
Also used : MIMPProcessorLog(org.compiere.model.MIMPProcessorLog) JMSException(javax.jms.JMSException) Document(org.w3c.dom.Document) TextMessage(javax.jms.TextMessage) ImportHelper(org.adempiere.process.rpl.imp.ImportHelper) JMSException(javax.jms.JMSException)

Aggregations

MIMPProcessorLog (org.compiere.model.MIMPProcessorLog)3 JMSException (javax.jms.JMSException)2 Timestamp (java.sql.Timestamp)1 MessageConsumer (javax.jms.MessageConsumer)1 TextMessage (javax.jms.TextMessage)1 ImportHelper (org.adempiere.process.rpl.imp.ImportHelper)1 IImportProcessor (org.adempiere.server.rpl.IImportProcessor)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 X_IMP_Processor_Type (org.compiere.model.X_IMP_Processor_Type)1 Document (org.w3c.dom.Document)1