Search in sources :

Example 11 with AcsJException

use of alma.acs.exceptions.AcsJException in project ACS by ACS-Community.

the class NCSubscriberTest method publish.

/*===================================*/
/* Support methods                   */
/*===================================*/
private void publish(int nEvents, EventType type) {
    IDLEntity event = null;
    if (type.equals(EventType.statusBlock1)) {
        event = new statusBlockEvent1();
        ((statusBlockEvent1) event).counter1 = 0;
        ((statusBlockEvent1) event).counter2 = 0;
        ((statusBlockEvent1) event).flipFlop = true;
        ((statusBlockEvent1) event).onOff = alma.ADMINTEST1.OnOffStates.ON;
    } else if (type.equals(EventType.statusBlock2)) {
        event = new statusBlockEvent2();
        ((statusBlockEvent2) event).counter1 = 0;
        ((statusBlockEvent2) event).counter2 = 0;
        ((statusBlockEvent2) event).flipFlop = true;
        ((statusBlockEvent2) event).onOff = alma.ADMINTEST2.OnOffStates.ON;
    }
    try {
        for (int i = 0; i != nEvents; i++) m_publisher.publishEvent(event);
    } catch (AcsJException e) {
        e.printStackTrace();
    }
}
Also used : ADMINTEST2.statusBlockEvent2(alma.ADMINTEST2.statusBlockEvent2) ADMINTEST1.statusBlockEvent1(alma.ADMINTEST1.statusBlockEvent1) AcsJException(alma.acs.exceptions.AcsJException) IDLEntity(org.omg.CORBA.portable.IDLEntity)

Example 12 with AcsJException

use of alma.acs.exceptions.AcsJException 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)

Example 13 with AcsJException

use of alma.acs.exceptions.AcsJException in project ACS by ACS-Community.

the class NCSubscriber method reconnect.

/**
     * Reconnect to the Notification Channel
     */
private void reconnect() throws AcsJException {
    Date oldChannelTimestamp = helper.getLastRegisteredChannelTimestamp();
    try {
        // get the channel
        channel = helper.getNotificationChannel(getNotificationFactoryName());
        // get the admin object
        sharedConsumerAdmin = getSharedAdmin();
        // get the proxy Supplier
        proxySupplier = createProxySupplier();
        // Just check if our shared consumer admin is handling more proxies than it should, and log it
        // (11) goes for the dummy proxy that we're using the transition between old and new NC classes
        int currentProxies = sharedConsumerAdmin.push_suppliers().length - 1;
        if (currentProxies > PROXIES_PER_ADMIN) {
            LOG_NC_ConsumerAdmin_Overloaded.log(logger, sharedConsumerAdmin.MyID(), currentProxies, PROXIES_PER_ADMIN, channelName, channelNotifyServiceDomainName == null ? "none" : channelNotifyServiceDomainName);
        }
        try {
            // Clean up callback for reconnection requests
            channelReconnectionCallback.disconnect();
        } catch (org.omg.CORBA.OBJECT_NOT_EXIST ex1) {
        // this is OK, because someone else has already destroyed the remote resources
        }
        channelReconnectionCallback = null;
        try {
            // Register callback for reconnection requests
            channelReconnectionCallback = new AcsNcReconnectionCallback(NCSubscriber.this, logger);
            // if the factory is null, the reconnection callback is not registered
            channelReconnectionCallback.registerForReconnect(services, helper.getNotifyFactory());
            proxySupplier.connect_structured_push_consumer(org.omg.CosNotifyComm.StructuredPushConsumerHelper.narrow(corbaRef));
        } catch (AcsJContainerServicesEx ex) {
            AcsJException e = new AcsJGenericErrorEx(ex);
            throw e;
        } catch (org.omg.CosEventChannelAdmin.AlreadyConnected ex) {
            AcsJException e = new AcsJGenericErrorEx(ex);
            throw e;
        } catch (org.omg.CosEventChannelAdmin.TypeError ex) {
            AcsJException e = new AcsJGenericErrorEx(ex);
            throw e;
        } catch (AcsJIllegalArgumentEx ex) {
            AcsJException e = new AcsJGenericErrorEx(ex);
            throw e;
        }
    /* We only have to resume the connection when it has been suspended
            try {
                proxySupplier.resume_connection();
            } catch (org.omg.CosNotifyChannelAdmin.ConnectionAlreadyActive ex) {
            } catch (Exception ex) {
                AcsJException e = new AcsJGenericErrorEx(ex);
                throw e;
            }*/
    // In case any exception occurs, ensure the channel timestamp has not changed            
    } catch (Throwable e) {
        helper.setLastRegisteredChannelTimestamp(oldChannelTimestamp);
        throw e;
    }
    logger.log(Level.INFO, "Consumer reconnected to the channel '" + channelName + "'");
}
Also used : AcsJGenericErrorEx(alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx) AcsJException(alma.acs.exceptions.AcsJException) AcsJIllegalArgumentEx(alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Date(java.util.Date)

Example 14 with AcsJException

use of alma.acs.exceptions.AcsJException in project ACS by ACS-Community.

the class AnyAideTest method testComplexObjectToCorbaAny.

public void testComplexObjectToCorbaAny() {
    NestedEvent neVal = new NestedEvent();
    neVal.sampVal = advancedCS.getAny();
    neVal.sampVal.insert_long(15);
    Any anyNe = null;
    try {
        anyNe = anyAide.complexObjectToCorbaAny(neVal);
    } catch (AcsJException ex) {
    }
    assertNotNull(anyNe);
    NestedEvent neVal2 = NestedEventHelper.extract(anyNe);
    assertEquals(neVal.sampVal.extract_long(), neVal2.sampVal.extract_long());
    try {
        anyAide.complexObjectToCorbaAny(null);
        fail();
    } catch (AcsJException ex) {
    }
}
Also used : AcsJException(alma.acs.exceptions.AcsJException) NotNestedEvent(alma.ADMINTEST1.NotNestedEvent) NestedEvent(alma.ADMINTEST1.InterfaceForNestedEventDefinitionPackage.NestedEvent) Any(org.omg.CORBA.Any)

Example 15 with AcsJException

use of alma.acs.exceptions.AcsJException in project ACS by ACS-Community.

the class AnyAideTest method testObjectToCorbaAny.

public void testObjectToCorbaAny() {
    final String strVal = "str";
    final Long lVal = 13L;
    final Double dVal = 13.7;
    final Float fVal = 13.3f;
    final Integer iVal = 11;
    final int[] intArr = new int[] { 1, 2, 3, 4 };
    final NestedEvent neVal = new NestedEvent();
    neVal.sampVal = advancedCS.getAny();
    neVal.sampVal.insert_long(15);
    Any anyNull = null, anyString = null, anyLong = null, anyDouble = null, anyFloat = null, anyInt = null;
    Any anyNe = null, anyIntArr = null;
    try {
        anyNull = anyAide.objectToCorbaAny(null);
        anyString = anyAide.objectToCorbaAny(strVal);
        anyLong = anyAide.objectToCorbaAny(lVal);
        anyDouble = anyAide.objectToCorbaAny(dVal);
        anyFloat = anyAide.objectToCorbaAny(fVal);
        anyInt = anyAide.objectToCorbaAny(iVal);
        anyNe = anyAide.objectToCorbaAny(neVal);
        anyIntArr = anyAide.objectToCorbaAny(intArr);
    } catch (AcsJException ex) {
    }
    assertNotNull(anyNull);
    assertNotNull(anyString);
    assertNotNull(anyLong);
    assertNotNull(anyDouble);
    assertNotNull(anyFloat);
    assertNotNull(anyInt);
    assertNotNull(anyNe);
    assertNotNull(anyIntArr);
    assertNull(anyNull.extract_Object());
    assertEquals(lVal.longValue(), anyLong.extract_longlong());
    assertEquals(dVal.doubleValue(), anyDouble.extract_double());
    assertEquals(fVal.floatValue(), anyFloat.extract_float());
    assertEquals(iVal.intValue(), anyInt.extract_long());
    assertEquals(strVal, anyString.extract_string());
    NestedEvent neVal2 = NestedEventHelper.extract(anyNe);
    assertEquals(neVal.sampVal.extract_long(), neVal2.sampVal.extract_long());
    int[] intArr2 = longSeqHelper.extract(anyIntArr);
    assertEquals(intArr.length, intArr2.length);
    for (int i = 0; i < intArr2.length; ++i) {
        assertEquals(intArr[i], intArr2[i]);
    }
    try {
        Any anyVector = anyAide.objectToCorbaAny(new Vector());
        fail();
    } catch (AcsJException ex) {
    }
}
Also used : AcsJException(alma.acs.exceptions.AcsJException) NotNestedEvent(alma.ADMINTEST1.NotNestedEvent) NestedEvent(alma.ADMINTEST1.InterfaceForNestedEventDefinitionPackage.NestedEvent) Any(org.omg.CORBA.Any) Vector(java.util.Vector)

Aggregations

AcsJException (alma.acs.exceptions.AcsJException)24 Any (org.omg.CORBA.Any)6 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)5 IDLEntity (org.omg.CORBA.portable.IDLEntity)4 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)3 CBDescOut (alma.ACS.CBDescOut)2 Completion (alma.ACSErr.Completion)2 CompletionHolder (alma.ACSErr.CompletionHolder)2 AcsJCouldntPerformActionEx (alma.ACSErrTypeCommon.wrappers.AcsJCouldntPerformActionEx)2 AcsJGenericErrorEx (alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx)2 AcsJUnknownEx (alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)2 NestedEvent (alma.ADMINTEST1.InterfaceForNestedEventDefinitionPackage.NestedEvent)2 NotNestedEvent (alma.ADMINTEST1.NotNestedEvent)2 ComponentClient (alma.acs.component.client.ComponentClient)2 StopWatch (alma.acs.util.StopWatch)2 ComponentDeactivationFailedEx (alma.maciErrType.ComponentDeactivationFailedEx)2 ComponentDeactivationUncleanEx (alma.maciErrType.ComponentDeactivationUncleanEx)2 AcsJComponentDeactivationFailedEx (alma.maciErrType.wrappers.AcsJComponentDeactivationFailedEx)2 AcsJComponentDeactivationUncleanEx (alma.maciErrType.wrappers.AcsJComponentDeactivationUncleanEx)2 AcsJNoPermissionEx (alma.maciErrType.wrappers.AcsJNoPermissionEx)2