Search in sources :

Example 1 with Property

use of org.omg.CosNotification.Property in project ACS by ACS-Community.

the class ChannelProperties method getCDBQoSProps.

// //////////////////////////////////////////////////////////////////////////
/**
	 * Given a channel name that exists in the ACS CDB
	 * ($ACS_CDB/CDB/MACI/Channels/channelName/channelName.xml), this function
	 * returns the channel's quality of service properties in their CORBA format.
	 * <p>
	 * The schema for this channel configuration is <code>urn:schemas-cosylab-com:EventChannel:1.0</code>.
	 * 
	 * @param channelName
	 *           name of the channel found in $ACS_CDB/CDB/MACI/Channels
	 * @return channel's quality of service properties
	 * @throws AcsJException
	 *            if the channel's CDB entry is corrupted in any way
	 */
public Property[] getCDBQoSProps(String channelName) throws alma.acs.exceptions.AcsJException {
    // use this object to get at channel information from the CDB
    DAO tempDAO = null;
    try {
        tempDAO = m_services.getCDB().get_DAO_Servant("MACI/Channels/" + channelName);
    } catch (alma.cdbErrType.CDBXMLErrorEx e) {
        m_logger.log(Level.WARNING, "Bad CDB entry found for '" + channelName + "' channel");
        throw new alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx(e);
    } catch (alma.cdbErrType.CDBRecordDoesNotExistEx e) {
        m_logger.log(Level.WARNING, "No CDB entry found for '" + channelName + "' channel");
        throw new alma.ACSErrTypeCommon.wrappers.AcsJFileNotFoundEx(e);
    } catch (AcsJContainerServicesEx e) {
        m_logger.log(Level.WARNING, "CDB unavailable", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJNoResourcesEx(e);
    }
    // EventReliability - ///////////////////////////////////////////////
    Any eventRelAny = m_services.getAdvancedContainerServices().getAny();
    short eventRelVal = Persistent.value;
    try {
        if (tempDAO.get_string(EventReliability.value).equals("BestEffort")) {
            eventRelVal = BestEffort.value;
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    eventRelAny.insert_short(eventRelVal);
    Property eventRel = new Property(EventReliability.value, eventRelAny);
    // ConnectionReliability - ///////////////////////////////////////////////
    Any connectRelAny = m_services.getAdvancedContainerServices().getAny();
    short connectRelVal = Persistent.value;
    try {
        if (tempDAO.get_string(ConnectionReliability.value).equals("BestEffort")) {
            connectRelVal = BestEffort.value;
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    connectRelAny.insert_short(Persistent.value);
    Property connectRel = new Property(ConnectionReliability.value, connectRelAny);
    //@TODO do something with this connectRel, e.g. check why it's commented out at the end of this method!
    // Also enforce that EventReliability=Persistent && ConnectionRelability=BestEffort is undefined (spec 2.5.5.1).
    // ConnectionRelability=Persistent requires TAO topology persistence to be enabled.
    // Priority - ///////////////////////////////////////////////
    Any priorityAny = m_services.getAdvancedContainerServices().getAny();
    try {
        priorityAny.insert_short((short) tempDAO.get_long(Priority.value));
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    Property priority = new Property(Priority.value, priorityAny);
    // Timeout - ///////////////////////////////////////////////
    Any timeoutAny = m_services.getAdvancedContainerServices().getAny();
    try {
        org.omg.TimeBase.TimeTHelper.insert(timeoutAny, tempDAO.get_long(Timeout.value));
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    Property timeout = new Property(Timeout.value, timeoutAny);
    // OrderPolicy - ///////////////////////////////////////////////
    Any orderPolAny = m_services.getAdvancedContainerServices().getAny();
    short orderPolicyVal;
    try {
        if (tempDAO.get_string(OrderPolicy.value).equals("AnyOrder")) {
            orderPolicyVal = AnyOrder.value;
        } else if (tempDAO.get_string(OrderPolicy.value).equals("FifoOrder")) {
            orderPolicyVal = FifoOrder.value;
        } else if (tempDAO.get_string(OrderPolicy.value).equals("PriorityOrder")) {
            orderPolicyVal = PriorityOrder.value;
        } else if (tempDAO.get_string(OrderPolicy.value).equals("DeadlineOrder")) {
            orderPolicyVal = DeadlineOrder.value;
        } else {
            m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel");
            throw new Exception("No value found for order policy.");
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    orderPolAny.insert_short(orderPolicyVal);
    Property orderPol = new Property(OrderPolicy.value, orderPolAny);
    // DiscardPolicy - ///////////////////////////////////////////////
    Any discardPolAny = m_services.getAdvancedContainerServices().getAny();
    short discardPolicyVal;
    try {
        if (tempDAO.get_string(DiscardPolicy.value).equals("AnyOrder")) {
            discardPolicyVal = AnyOrder.value;
        } else if (tempDAO.get_string(DiscardPolicy.value).equals("FifoOrder")) {
            discardPolicyVal = FifoOrder.value;
        } else if (tempDAO.get_string(DiscardPolicy.value).equals("PriorityOrder")) {
            discardPolicyVal = PriorityOrder.value;
        } else if (tempDAO.get_string(DiscardPolicy.value).equals("DeadlineOrder")) {
            discardPolicyVal = DeadlineOrder.value;
        } else if (tempDAO.get_string(DiscardPolicy.value).equals("LifoOrder")) {
            discardPolicyVal = LifoOrder.value;
        } else {
            m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel");
            throw new Exception("No value found for discard policy.");
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    discardPolAny.insert_short(discardPolicyVal);
    Property discardPol = new Property(DiscardPolicy.value, discardPolAny);
    // StartTimeSupported - ///////////////////////////////////////////////
    Any startTSAny = m_services.getAdvancedContainerServices().getAny();
    boolean startTSVal = true;
    try {
        if (tempDAO.get_string(StartTimeSupported.value).equals("false")) {
            startTSVal = false;
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    startTSAny.insert_boolean(startTSVal);
    Property startTS = new Property(StartTimeSupported.value, startTSAny);
    // StopTimeSupported - ///////////////////////////////////////////////
    Any stopTSAny = m_services.getAdvancedContainerServices().getAny();
    boolean stopTSVal = true;
    try {
        if (tempDAO.get_string(StopTimeSupported.value).equals("false")) {
            stopTSVal = false;
        }
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    stopTSAny.insert_boolean(stopTSVal);
    Property stopTS = new Property(StopTimeSupported.value, stopTSAny);
    // MaxEventsPerConsumer - ///////////////////////////////////////////////
    Any MEPCAny = m_services.getAdvancedContainerServices().getAny();
    try {
        MEPCAny.insert_long(tempDAO.get_long(MaxEventsPerConsumer.value));
    } catch (Exception e) {
        m_logger.log(Level.SEVERE, "Bad CDB entry datatype found for '" + channelName + "' channel", e);
        throw new alma.ACSErrTypeCommon.wrappers.AcsJTypeNotSupportedEx(e);
    }
    Property MEPC = new Property(MaxEventsPerConsumer.value, MEPCAny);
    Property[] qosProps = { // connectRel,
    priority, timeout, orderPol, discardPol, // stopTS,
    MEPC };
    return qosProps;
}
Also used : AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Any(org.omg.CORBA.Any) AcsJException(alma.acs.exceptions.AcsJException) DAO(com.cosylab.CDB.DAO) Property(org.omg.CosNotification.Property)

Example 2 with Property

use of org.omg.CosNotification.Property in project ACS by ACS-Community.

the class StructuredEventCreator method getCORBAEvent.

/**
	 * Method used to create a pre-filled CORBA event.
	 * 
	 * @param typeName
	 *           The structured event's type_name.
	 * @param eventName
	 *           Name of the event.
	 * @return A pre-filled CORBA event.
	 */
private StructuredEvent getCORBAEvent(String typeName, String eventName) {
    // return value
    StructuredEvent event = new StructuredEvent();
    // event.header.fixed_header.event_type
    String channelDomain = alma.acscommon.ALMADOMAIN.value;
    EventType event_type = new EventType(channelDomain, typeName);
    //
    FixedEventHeader fixed_header = new FixedEventHeader(event_type, eventName);
    // event.header.variable_header
    Property[] variable_header = new Property[0];
    // event.header
    event.header = new EventHeader(fixed_header, variable_header);
    return event;
}
Also used : EventType(org.omg.CosNotification.EventType) StructuredEvent(org.omg.CosNotification.StructuredEvent) FixedEventHeader(org.omg.CosNotification.FixedEventHeader) FixedEventHeader(org.omg.CosNotification.FixedEventHeader) EventHeader(org.omg.CosNotification.EventHeader) Property(org.omg.CosNotification.Property)

Example 3 with Property

use of org.omg.CosNotification.Property in project ACS by ACS-Community.

the class StructuredEventCreator method createEvent.

public StructuredEvent createEvent(IDLEntity customStruct) throws AcsJException {
    // The Java class name without package becomes the name of the "event type".
    String typeName = customStruct.getClass().getName().substring(customStruct.getClass().getName().lastIndexOf('.') + 1);
    // event to send
    StructuredEvent event = getCORBAEvent(typeName, "");
    // Store the info for Exec/I&T into the event.
    // create the any
    event.remainder_of_body = m_services.getAdvancedContainerServices().getAny();
    // get the useful data which includes the component's name, timestamp, and event count (=1 here)
    EventDescription descrip = new EventDescription(m_services.getName(), alma.acs.util.UTCUtility.utcJavaToOmg(System.currentTimeMillis()), 1);
    // store the IDL struct into the structured event
    EventDescriptionHelper.insert(event.remainder_of_body, descrip);
    // preallocate one name/value pair
    event.filterable_data = new Property[1];
    event.filterable_data[0] = new Property(alma.acscommon.DEFAULTDATANAME.value, m_anyAide.complexObjectToCorbaAny(customStruct));
    return event;
}
Also used : StructuredEvent(org.omg.CosNotification.StructuredEvent) EventDescription(alma.acsnc.EventDescription) Property(org.omg.CosNotification.Property)

Example 4 with Property

use of org.omg.CosNotification.Property in project ACS by ACS-Community.

the class NCPublisher method getCORBAEvent.

/**
	 * Method used to create a pre-filled CORBA event.
	 * 
	 * @param typeName
	 *            The structured event's type_name.
	 * @param eventName
	 *            Name of the event.
	 * @return A pre-filled CORBA event.
	 */
protected StructuredEvent getCORBAEvent(String typeName, String eventName) {
    // return value
    StructuredEvent event = new StructuredEvent();
    // event.header.fixed_header.event_type
    String channelDomain = alma.acscommon.ALMADOMAIN.value;
    EventType event_type = new EventType(channelDomain, typeName);
    FixedEventHeader fixed_header = new FixedEventHeader(event_type, eventName);
    // event.header.variable_header
    Property[] variable_header = new Property[0];
    // event.header
    event.header = new EventHeader(fixed_header, variable_header);
    return event;
}
Also used : InvalidEventType(org.omg.CosNotifyComm.InvalidEventType) EventType(org.omg.CosNotification.EventType) StructuredEvent(org.omg.CosNotification.StructuredEvent) FixedEventHeader(org.omg.CosNotification.FixedEventHeader) FixedEventHeader(org.omg.CosNotification.FixedEventHeader) EventHeader(org.omg.CosNotification.EventHeader) Property(org.omg.CosNotification.Property)

Example 5 with Property

use of org.omg.CosNotification.Property in project ACS by ACS-Community.

the class NCPublisher method publishEvent.

/**
	 * Takes the given Java object and tries to pack it into a CORBA Any and
	 * publish it to the notification channel. 
	 * This will fail if the parameter is not
	 * CORBA-generated from a user-defined IDL struct. In simple terms, trying
	 * to publish native Java types is impossible because they have no CORBA
	 * mapping to say Python or C++ types.
	 * 
	 * @param customStruct
	 *            An instance of the IDL struct (Java class) to be published.
	 * @throws AcsJPublishEventFailureEx If <code>customStruct</code> is not an IDL struct,
	 *            for which it must be a subclass of IDLEntity.
	 * @throws AcsJException
	 *            There are an enormous amount of possibilities pertaining to
	 *            why an AcsJException would be thrown by publishEvent.
	 */
@Override
public void publishEvent(T customStruct) throws AcsJException {
    // Let's first verify that the use of generics between base class and here is OK also for the DDS side. 
    if (!(customStruct instanceof IDLEntity)) {
        String msg = "ACS is using Corba NC as the underlying pub/sub framework. Event data must be IDL-defined structs that inherit from org.omg.CORBA.portable.IDLEntity.";
        AcsJPublishEventFailureEx ex = new AcsJPublishEventFailureEx();
        ex.setFailureDescription(msg);
        ex.setChannelName(channelName);
        ex.setEventName(customStruct.getClass().getName());
        throw ex;
    }
    IDLEntity customStructEntity = (IDLEntity) customStruct;
    String typeName = customStructEntity.getClass().getSimpleName();
    // Event to send 
    // Header: domain_name = "ALMA", type_name = simple name of IDL struct, event_name = ""
    StructuredEvent event = getCORBAEvent(typeName, "");
    // Send event meta data (client name, timestamp, counter) in the accompanying EventDescription object,
    // which we transmit as the Any field 'remainder_of_body'.
    event.remainder_of_body = services.getAdvancedContainerServices().getAny();
    EventDescription descrip = new EventDescription(services.getName(), alma.acs.util.UTCUtility.utcJavaToOmg(System.currentTimeMillis()), count.getAndIncrement());
    EventDescriptionHelper.insert(event.remainder_of_body, descrip);
    // In the 'filterable_data' field, we send our IDL struct coded as an Any
    event.filterable_data = new Property[1];
    event.filterable_data[0] = new Property(alma.acscommon.DEFAULTDATANAME.value, anyAide.complexObjectToCorbaAny(customStructEntity));
    // Check the queue for events from previous failures.
    synchronized (eventQueueSync) {
        if (eventQueue != null) {
            CircularQueue<T>.Data<T> tmp;
            try {
                while ((tmp = eventQueue.pop()) != null) {
                    publishCORBAEvent(tmp.corbaData, tmp.userData);
                }
            } catch (Exception ex) {
                Level lev = (isTraceEventsEnabled ? Level.INFO : Level.FINEST);
                logger.log(lev, "Failed to flush event queue.", ex);
            // go on and try to send the new event, to at least have it inserted into the queue.
            }
        }
    }
    try {
        publishCORBAEvent(event, customStruct);
    } catch (AcsJCORBAProblemEx ex) {
        String info = ex.getInfo();
        if (false == info.contains("org.omg.CORBA.TRANSIENT")) {
            throw ex;
        }
    }
}
Also used : AcsJCORBAProblemEx(alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx) NO_IMPLEMENT(org.omg.CORBA.NO_IMPLEMENT) TIMEOUT(org.omg.CORBA.TIMEOUT) StructuredEvent(org.omg.CosNotification.StructuredEvent) AcsLogLevel(alma.acs.logging.AcsLogLevel) Level(java.util.logging.Level) IDLEntity(org.omg.CORBA.portable.IDLEntity) AcsJPublishEventFailureEx(alma.acsncErrType.wrappers.AcsJPublishEventFailureEx) EventDescription(alma.acsnc.EventDescription) Property(org.omg.CosNotification.Property) AcsJException(alma.acs.exceptions.AcsJException)

Aggregations

Property (org.omg.CosNotification.Property)7 StructuredEvent (org.omg.CosNotification.StructuredEvent)5 AcsJException (alma.acs.exceptions.AcsJException)3 EventDescription (alma.acsnc.EventDescription)3 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)2 DAO (com.cosylab.CDB.DAO)2 Any (org.omg.CORBA.Any)2 EventHeader (org.omg.CosNotification.EventHeader)2 EventType (org.omg.CosNotification.EventType)2 FixedEventHeader (org.omg.CosNotification.FixedEventHeader)2 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)1 AcsLogLevel (alma.acs.logging.AcsLogLevel)1 AcsJPublishEventFailureEx (alma.acsncErrType.wrappers.AcsJPublishEventFailureEx)1 Level (java.util.logging.Level)1 NO_IMPLEMENT (org.omg.CORBA.NO_IMPLEMENT)1 TIMEOUT (org.omg.CORBA.TIMEOUT)1 IDLEntity (org.omg.CORBA.portable.IDLEntity)1 InvalidEventType (org.omg.CosNotifyComm.InvalidEventType)1