<commit_before>/*
 * acssampConsumer.java
 *
 * Created on January 28, 2004, 9:58 AM
 */

/**
 *
 * @author  alma
 */
////////////////////////////////////////////////////////////////////////////////
package alma.acssamp.jtest;

////////////////////////////////////////////////////////////////////////////////

import org.omg.CORBA.portable.IDLEntity;
import org.omg.CosNotification.EventType;
import org.omg.CosNotification.StructuredEvent;

import abeans.models.acs.baci.util.TimeConverter;

import alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx;
import alma.acs.container.ContainerServices;
import alma.acs.exceptions.AcsJException;
import alma.acs.nc.Consumer;
import alma.acsnc.EventDescription;
import alma.acssamp.SampObjPackage.SampDataBlock;
import alma.acssamp.SampObjPackage.SampDataBlockSeqHelper;

public class acssampConsumer extends Consumer {

	/** 
	 * Total number of events that have been consumed.
	 */
	public int eventCount = 0;

	/** 
	 * Creates a new instance of acssampConsumer 
	 */
	public acssampConsumer(String ncChannel, ContainerServices cServices) throws AcsJException {

		super(ncChannel, cServices);
		
		try {
			// We subscribe to *all* events on this channel by using 'null' instead of the event class.
			// This is necessary because we are dealing with the rare and only partially supported case
			// that the event data is a sequence of IDL structs instead of a single IDL struct.
			// Alledgedly subscribing to "SampDataBlockSeq.class" worked before ACS 6.0, but then broke.			
			// As of ACS 6.0.1 it has become pointless to try to get it running this way, because now
			// the Class parameter must represent a subtype of IDLEntity (which all IDL struct derived classes come from).
			// If it should ever be necessary to subscribe to a particular event that has a sequence of IDL structs as attached data,
			// the same workaround as in acssampGui should be used: instead of calling 'addSubscription', 
			// we call the raw Corba subscription_change method:
			//		EventType[] added = {new EventType(alma.acscommon.ALMADOMAIN.value, "SampDataBlockSeq")};
			//		EventType[] removed = {};
			//		m_consumerAdmin.subscription_change(added, removed);
			addSubscription(null);
		} catch (Exception e) {
			String msg = "Failed to subscribe to archive events: ";
			AcsJGenericErrorEx ex2 = new AcsJGenericErrorEx(e);  
			ex2.setErrorDesc(msg);
			throw ex2;
		}
	}

	
	/**
	 * Should never be called as we don't register a receiver callback object with the NC framework.
	 */
	public void receive(SampDataBlock[] sampData) {
		m_logger.info("Got a call to method receive(SampDataBlock[" + sampData.length + "])");	
	}
	
	/**
	 * Currently never called because we override the default impl of push_structured_event.
	 */
	protected void processEvent(IDLEntity corbaData, EventDescription eventDescrip) {
		super.processEvent(corbaData, eventDescrip);
	}

	
	/** 
	 * We directly overload the push_structured_event to steal the raw events before any processing 
	 * by the NC classes can take place. Usually one would overload one of the processEvent methods.  
	 * @see alma.acs.nc.Consumer#push_structured_event(org.omg.CosNotification.StructuredEvent)
	 */
	public void push_structured_event(StructuredEvent structuredEvent)
			throws org.omg.CosEventComm.Disconnected {

		//Know how many events this instance has received.
		eventCount++;
		
		try {
			System.out.println("The domain is: " + structuredEvent.header.fixed_header.event_type.domain_name);
			System.out.println("The type is: " + structuredEvent.header.fixed_header.event_type.type_name);

			SampDataBlock[] sampledData = SampDataBlockSeqHelper.extract(structuredEvent.filterable_data[0].value);

			for (int i = 0; i < sampledData.length; i++) {
				// extract the time stamp
				long timeVal = sampledData[i].sampTime;
				System.out.println("TIME STAMP: " + timeVal);

				// extract the value
				double extVal = sampledData[i].sampVal.extract_double();
				System.out.println("VALUE: " + extVal);

				long javaTime = TimeConverter.toJava(timeVal);
				//model.addPoint((double)timeVal/1000.0,extVal);<commit_msg>Replaced the deleted abeans.models.acs.baci.util.TimeConverter with UTCUtility time converter, see COMP-3188<commit_after>/*
 * acssampConsumer.java
 *
 * Created on January 28, 2004, 9:58 AM
 */

/**
 *
 * @author  alma
 */
////////////////////////////////////////////////////////////////////////////////
package alma.acssamp.jtest;

////////////////////////////////////////////////////////////////////////////////

import org.omg.CORBA.portable.IDLEntity;
import org.omg.CosNotification.EventType;
import org.omg.CosNotification.StructuredEvent;

import alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx;
import alma.acs.container.ContainerServices;
import alma.acs.exceptions.AcsJException;
import alma.acs.nc.Consumer;
import alma.acs.util.UTCUtility;
import alma.acsnc.EventDescription;
import alma.acssamp.SampObjPackage.SampDataBlock;
import alma.acssamp.SampObjPackage.SampDataBlockSeqHelper;

public class acssampConsumer extends Consumer {

	/** 
	 * Total number of events that have been consumed.
	 */
	public int eventCount = 0;

	/** 
	 * Creates a new instance of acssampConsumer 
	 */
	public acssampConsumer(String ncChannel, ContainerServices cServices) throws AcsJException {

		super(ncChannel, cServices);
		
		try {
			// We subscribe to *all* events on this channel by using 'null' instead of the event class.
			// This is necessary because we are dealing with the rare and only partially supported case
			// that the event data is a sequence of IDL structs instead of a single IDL struct.
			// Alledgedly subscribing to "SampDataBlockSeq.class" worked before ACS 6.0, but then broke.			
			// As of ACS 6.0.1 it has become pointless to try to get it running this way, because now
			// the Class parameter must represent a subtype of IDLEntity (which all IDL struct derived classes come from).
			// If it should ever be necessary to subscribe to a particular event that has a sequence of IDL structs as attached data,
			// the same workaround as in acssampGui should be used: instead of calling 'addSubscription', 
			// we call the raw Corba subscription_change method:
			//		EventType[] added = {new EventType(alma.acscommon.ALMADOMAIN.value, "SampDataBlockSeq")};
			//		EventType[] removed = {};
			//		m_consumerAdmin.subscription_change(added, removed);
			addSubscription(null);
		} catch (Exception e) {
			String msg = "Failed to subscribe to archive events: ";
			AcsJGenericErrorEx ex2 = new AcsJGenericErrorEx(e);  
			ex2.setErrorDesc(msg);
			throw ex2;
		}
	}

	
	/**
	 * Should never be called as we don't register a receiver callback object with the NC framework.
	 */
	public void receive(SampDataBlock[] sampData) {
		m_logger.info("Got a call to method receive(SampDataBlock[" + sampData.length + "])");	
	}
	
	/**
	 * Currently never called because we override the default impl of push_structured_event.
	 */
	protected void processEvent(IDLEntity corbaData, EventDescription eventDescrip) {
		super.processEvent(corbaData, eventDescrip);
	}

	
	/** 
	 * We directly overload the push_structured_event to steal the raw events before any processing 
	 * by the NC classes can take place. Usually one would overload one of the processEvent methods.  
	 * @see alma.acs.nc.Consumer#push_structured_event(org.omg.CosNotification.StructuredEvent)
	 */
	public void push_structured_event(StructuredEvent structuredEvent)
			throws org.omg.CosEventComm.Disconnected {

		//Know how many events this instance has received.
		eventCount++;
		
		try {
			System.out.println("The domain is: " + structuredEvent.header.fixed_header.event_type.domain_name);
			System.out.println("The type is: " + structuredEvent.header.fixed_header.event_type.type_name);

			SampDataBlock[] sampledData = SampDataBlockSeqHelper.extract(structuredEvent.filterable_data[0].value);

			for (int i = 0; i < sampledData.length; i++) {
				// extract the time stamp
				long timeVal = sampledData[i].sampTime;
				System.out.println("TIME STAMP: " + timeVal);

				// extract the value
				double extVal = sampledData[i].sampVal.extract_double();
				System.out.println("VALUE: " + extVal);

				long javaTime = UTCUtility.utcOmgToJava(timeVal);
				//model.addPoint((double)timeVal/1000.0,extVal);
{'fraction_non_alphanumeric': 0.1272749042145594, 'fraction_numerical': 0.00646551724137931, 'mean_word_length': 3.366440146366963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5529818', 'n_tokens_mistral': 2721, 'n_tokens_neox': 2400, 'n_words': 736}