<commit_before>/*
		* Copyright (c) 2010 Stiftung Deutsches Elektronen-Synchrotron,
		* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
		*
		* THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS.
		* WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT
		NOT LIMITED
		* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE
		AND
		* NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
		BE LIABLE
		* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
		CONTRACT,
		* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
		SOFTWARE OR
		* THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE
		DEFECTIVE
		* IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING,
		REPAIR OR
		* CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART
		OF THIS LICENSE.
		* NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
		DISCLAIMER.
		* DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
		ENHANCEMENTS,
		* OR MODIFICATIONS.
		* THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION,
		MODIFICATION,
		* USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE
		DISTRIBUTION OF THIS
		* PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU
		MAY FIND A COPY
		* AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM
		*/
package org.csstudio.alarm.dal2jms;


import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Session;

import org.csstudio.alarm.service.declaration.AlarmConnectionException;
import org.csstudio.alarm.service.declaration.AlarmMessageException;
import org.csstudio.alarm.service.declaration.IAlarmConnection;
import org.csstudio.alarm.service.declaration.IAlarmListener;
import org.csstudio.alarm.service.declaration.IAlarmMessage;


/**
 * TODO (jhatje) :
 *
 * @author jhatje
 * @author $Author$
 * @version $Revision$
 * @since 07.05.2010
 */
public class AlarmHandler {
   
    IAlarmConnection _connection;
    
	public final static int	JMS_MESSAGE_TYPE_ALARM		= 1;
	public final static int	JMS_MESSAGE_TYPE_LOG		= 2;
	public final static int	JMS_MESSAGE_TYPE_PUT_LOG	= 3;

    public AlarmHandler() {

        _connection = Activator.getDefault().getAlarmService().newAlarmConnection();
        try {
            _connection.connectWithListener(null, new IAlarmListener() {

                @Override
                public void onMessage(IAlarmMessage message) {
                    // TODO Auto-generated method stub
                    try {
						System.out.println(message.getMap().toString());
						
						Session session = JmsMessage.getInstance().createJmsSession();
						MapMessage mapMessage = message.getMapMessage ( session.createMapMessage());
						if ( mapMessage != null) {
							JmsMessage.getInstance().sendMessage( JMS_MESSAGE_TYPE_ALARM, mapMessage);
						} else {
							System.out.println("INVALID message !");
						}
					} catch (AlarmMessageException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (JMSException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
                }

                @Override
                public void stop() {
                    // TODO Auto-generated method stub
                    
                }
                
            });
        } catch (AlarmConnectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }       
}
<commit_msg>creation of jms message now internally<commit_after>/*
		* Copyright (c) 2010 Stiftung Deutsches Elektronen-Synchrotron,
		* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
		*
		* THIS SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "../AS IS" BASIS.
		* WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED, INCLUDING BUT
		NOT LIMITED
		* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR PARTICULAR PURPOSE
		AND
		* NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
		BE LIABLE
		* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
		CONTRACT,
		* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
		SOFTWARE OR
		* THE USE OR OTHER DEALINGS IN THE SOFTWARE. SHOULD THE SOFTWARE PROVE
		DEFECTIVE
		* IN ANY RESPECT, THE USER ASSUMES THE COST OF ANY NECESSARY SERVICING,
		REPAIR OR
		* CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART
		OF THIS LICENSE.
		* NO USE OF ANY SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
		DISCLAIMER.
		* DESY HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
		ENHANCEMENTS,
		* OR MODIFICATIONS.
		* THE FULL LICENSE SPECIFYING FOR THE SOFTWARE THE REDISTRIBUTION,
		MODIFICATION,
		* USAGE AND OTHER RIGHTS AND OBLIGATIONS IS INCLUDED WITH THE
		DISTRIBUTION OF THIS
		* PROJECT IN THE FILE LICENSE.HTML. IF THE LICENSE IS NOT INCLUDED YOU
		MAY FIND A COPY
		* AT HTTP://WWW.DESY.DE/LEGAL/LICENSE.HTM
		*/
package org.csstudio.alarm.dal2jms;

import javax.jms.JMSException;
import javax.jms.MapMessage;

import org.apache.log4j.Logger;
import org.csstudio.alarm.service.declaration.AlarmConnectionException;
import org.csstudio.alarm.service.declaration.AlarmMessageException;
import org.csstudio.alarm.service.declaration.IAlarmConnection;
import org.csstudio.alarm.service.declaration.IAlarmListener;
import org.csstudio.alarm.service.declaration.IAlarmMessage;
import org.csstudio.alarm.service.declaration.IAlarmMessage.Key;
import org.csstudio.platform.logging.CentralLogger;

/**
 * The alarm handler listens to DAL messages and forwards them to the JMS-based alarm system.
 * It is used in a headless application and allows the processing of alarm messages from IOCs which
 * are not connected to
 *
 * @author jhatje
 * @author $Author$
 * @version $Revision$
 * @since 07.05.2010
 */
public class AlarmHandler {

    private static final Logger LOG = CentralLogger.getInstance().getLogger(AlarmHandler.class);

    private final IAlarmConnection _connection;

    private final static int JMS_MESSAGE_TYPE_ALARM = 1;
    private final static int JMS_MESSAGE_TYPE_LOG = 2;
    private final static int JMS_MESSAGE_TYPE_PUT_LOG = 3;

    public AlarmHandler() {

        _connection = Activator.getDefault().getAlarmService().newAlarmConnection();
        try {
            _connection.connectWithListener(null, new IAlarmListener() {

                @Override
                public void onMessage(final IAlarmMessage message) {
                    try {
                        LOG.debug(message.getMap().toString());

                        MapMessage mapMessage = getMapMessage(message);
                        if (mapMessage != null) {
                            JmsMessage.getInstance()
                                    .sendMessage(JMS_MESSAGE_TYPE_ALARM, mapMessage);
                        } else {
                            LOG.debug("INVALID message !");
                        }
                    } catch (AlarmMessageException e) {
                        LOG.error("Error while creating mapMessage", e);
                    } catch (JMSException e) {
                        LOG.error("Error while creating mapMessage", e);
                    }
                }

                @Override
                public void stop() {
                    // Nothing to do

                }

            });
        } catch (AlarmConnectionException e) {
            LOG.error("Error. Could not connect.", e);
        }
    }

    private MapMessage getMapMessage(final IAlarmMessage message) throws AlarmMessageException,
                                                                 JMSException {
        MapMessage result = JmsMessage.getInstance().createJmsSession().createMapMessage();

        for (IAlarmMessage.Key key : Key.values()) {
            /*
             * if the value is noTimeStamp or Uninitialized or noMetaData
             * return null -> do NOT create message !
             */
            String value = message.getString(key);
            if (value != null && !value.equals("noTimeStamp") && !value.equals("Uninitialized")
                    && !value.equals("noMetaData")) {
                result.setString(key.name(), value);
            } else {
                return null;
            }
        }
        return result;
    }

}

{'fraction_non_alphanumeric': 0.07685901249256395, 'fraction_numerical': 0.003926234384295063, 'mean_word_length': 2.429620563035496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6005652', 'n_tokens_mistral': 2633, 'n_tokens_neox': 2334, 'n_words': 709}