Search in sources :

Example 1 with AcsJGenericErrorEx

use of alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx in project ACS by ACS-Community.

the class EventSupplierSpr2005067Impl method sendEvents.

/** Sends some events to an event channel.
    * @param param number of events to send
    */
public void sendEvents(short param) {
    /* 
	* This is OK
	*/
    m_logger.info("Now sending ControlSystemChangeOfStateEvent2 events. This should always be OK");
    try {
        ControlSystemChangeOfStateEvent2 t_block = new ControlSystemChangeOfStateEvent2(alma.SPR2005067.SystemState.INACCESSIBLE, alma.SPR2005067.SystemSubstate.STARTING_UP_PASS1, false, 0);
        for (short i = 0; i < param; i++) {
            m_supplier.publishEvent(t_block);
        }
    } catch (AcsJException e) {
        /*
	    * Here I just log the error trace.
	    * It would be nicer to throw it to the caller,
	    * but the interface of sendEvents does not allow it.
	    * We should change that interface.
	    */
        AcsJGenericErrorEx ex = new AcsJGenericErrorEx("This exception publishing events should have never occurred", e);
        ex.log(m_logger);
    } catch (Throwable thr) {
        AcsJUnexpectedExceptionEx ex = new AcsJUnexpectedExceptionEx("Got unexpected exception", thr);
        /*
	    * Here I just log the error trace.
	    * It would be nicer to throw it to the caller,
	    * but the interface of sendEvents does not allow it.
	    * We should change that interface.
	    */
        ex.log(m_logger);
    }
    /*
	* This fails with JacORB (tested up to version 2.2.4)
	* See SPR 2005067
	*/
    m_logger.info("Now sending ControlSystemChangeOfStateEvent events. This FAILS now but should be OK as well. See SPR2005067");
    try {
        ControlSystemChangeOfStateEvent t_block = new ControlSystemChangeOfStateEvent(alma.SPR2005067.SystemState.INACCESSIBLE, alma.SPR2005067.SystemSubstate.STARTING_UP_PASS1, alma.SPR2005067.SystemState.INACCESSIBLE, alma.SPR2005067.SystemSubstate.STARTING_UP_PASS1, false, 0);
        for (short i = 0; i < param; i++) {
            m_supplier.publishEvent(t_block);
        }
    } catch (AcsJException e) {
        /*
	    * Here I just log the error trace.
	    * It would be nicer to throw it to the caller,
	    * but the interface of sendEvents does not allow it.
	    * We should change that interface.
	    */
        AcsJGenericErrorEx ex = new AcsJGenericErrorEx("This exception is due to SPR2005067", e);
        ex.log(m_logger);
    } catch (Throwable thr) {
        /*
	    * The message int the exception logged is incomplete.
	    * Look at the println and compare to see the difference
	    */
        System.err.println(thr);
        AcsJUnexpectedExceptionEx ex = new AcsJUnexpectedExceptionEx("Got unexpected exception", thr);
        /*
	    * Here I just log the error trace.
	    * It would be nicer to throw it to the caller,
	    * but the interface of sendEvents does not allow it.
	    * We should change that interface.
	    */
        ex.log(m_logger);
    }
}
Also used : AcsJGenericErrorEx(alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx) AcsJException(alma.acs.exceptions.AcsJException) ControlSystemChangeOfStateEvent2(alma.SPR2005067.ControlSystemChangeOfStateEvent2) AcsJUnexpectedExceptionEx(alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx) ControlSystemChangeOfStateEvent(alma.SPR2005067.ControlSystemChangeOfStateEvent)

Example 2 with AcsJGenericErrorEx

use of alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx in project ACS by ACS-Community.

the class ErrorComponentTest method testCompletionFromCompletion.

public void testCompletionFromCompletion() {
    // depth == 0
    AcsJCompletion comp = null;
    try {
        // call the component method
        comp = AcsJCompletion.fromCorbaCompletion(errorComp.completionFromCompletion((short) 0));
    } catch (Throwable th) {
        m_logger.info("Caught an unexpected Exception");
        AcsJUnknownEx ex = new AcsJUnknownEx(th);
        ex.log(m_logger);
        fail("No exception should be thrown");
    }
    verifyErrorTrace(1, new AcsJGenericErrorEx(comp.getAcsJException()));
    // depth > 0
    short[] depths = new short[] { 1, 2, 3, 5, 13 };
    for (int i = 0; i < depths.length; i++) {
        try {
            // call the component method
            comp = AcsJCompletion.fromCorbaCompletion(errorComp.completionFromCompletion((depths[i])));
        } catch (Throwable th) {
            m_logger.info("Caught an unexpected Exception at depth " + depths[i]);
            AcsJUnknownEx ex = new AcsJUnknownEx(th);
            ex.log(m_logger);
            fail("No exception should be thrown");
        }
        verifyErrorTrace(depths[i] + 1, new AcsJGenericErrorEx(comp.getAcsJException()));
    }
}
Also used : AcsJCompletion(alma.acs.exceptions.AcsJCompletion) AcsJGenericErrorEx(alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx) AcsJUnknownEx(alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)

Example 3 with AcsJGenericErrorEx

use of alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx in project ACS by ACS-Community.

the class ErrorComponentTest method testCompletionFromException.

public void testCompletionFromException() {
    // depth == 0
    AcsJCompletion comp = null;
    try {
        // call the component method
        comp = AcsJCompletion.fromCorbaCompletion(errorComp.completionFromException((short) 0));
    } catch (Throwable th) {
        m_logger.info("Caught an unexpected Exception");
        AcsJUnknownEx ex = new AcsJUnknownEx(th);
        ex.log(m_logger);
        fail("No exception should be thrown");
    }
    verifyErrorTrace(1, new AcsJGenericErrorEx(comp.getAcsJException()));
    // depth > 0
    short[] depths = new short[] { 1, 2, 3, 5, 13 };
    for (int i = 0; i < depths.length; i++) {
        try {
            // call the component method
            comp = AcsJCompletion.fromCorbaCompletion(errorComp.completionFromException((depths[i])));
        } catch (Throwable th) {
            m_logger.info("Caught an unexpected Exception at depth " + depths[i]);
            AcsJUnknownEx ex = new AcsJUnknownEx(th);
            ex.log(m_logger);
            fail("No exception should be thrown");
        }
        verifyErrorTrace(depths[i] + 1, new AcsJGenericErrorEx(comp.getAcsJException()));
    }
}
Also used : AcsJCompletion(alma.acs.exceptions.AcsJCompletion) AcsJGenericErrorEx(alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx) AcsJUnknownEx(alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)

Example 4 with AcsJGenericErrorEx

use of alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx 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 5 with AcsJGenericErrorEx

use of alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx in project ACS by ACS-Community.

the class Helper method getNotificationChannel.

/**
	 * This method gets a reference to the event channel. If it is not already
	 * registered with the naming service, it is created.
	 * 
	 * @return Reference to the event channel specified by channelName. Never null.
	 * @param channelKind
	 *           Kind of the channel as registered with the CORBA naming service ("channels").
	 * @param notifyFactoryName
	 *           Name of the notification service as registered with the CORBA
	 *           naming service.
	 * @throws AcsJException
	 *            Standard ACS Java exception.
	 */
protected EventChannel getNotificationChannel(String notifyFactoryName) throws AcsJException {
    String channelKind = NC_KIND.value;
    // return value
    EventChannel retValue = null;
    NameComponent[] t_NameSequence = { new NameComponent(combineChannelAndDomainName(channelName, domainName), channelKind) };
    // (retryNumberAttempts * retrySleepSec) = the time before we give up to get a reference or create the channel if 
    // a channel of the given name supposedly gets created already (due to race conditions with other clients).
    int retryNumberAttempts = 20;
    int retrySleepSec = 2;
    do {
        try {
            // @TODO move the check for existing channel from naming service to the NC factory,
            // now that we use the TAO extension with named NCs.
            // The only advantage of still using the naming service is that the naming service is a real system-wide singleton
            // and can return also channels that were by mistake created from a different notify service factory than the one configured in the CDB.
            initializeNotifyFactory(notifyFactoryName);
            retValue = EventChannelHelper.narrow(getNamingService().resolve(t_NameSequence));
        } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
        // No other consumers or suppliers have registered the channel yet...
        // This can mean that the channel has never been created, or that it is currently being created but has not yet been registered.
        } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
            // Think there is virtually no chance of this every happening but...
            throw new AcsJUnexpectedExceptionEx(e);
        } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
            // Think there is virtually no chance of this every happening but...
            throw new AcsJUnexpectedExceptionEx(e);
        }
        if (retValue == null) {
            // but only because we use the TAO extensions that support named NCs.
            try {
                retValue = createNotificationChannel(channelKind, notifyFactoryName);
            } catch (NameAlreadyUsed ex) {
                m_logger.log(Level.INFO, "NC '" + channelName + "' seems to be getting created. Will wait and try again in " + retrySleepSec + " seconds.", ex);
                try {
                    Thread.sleep(retrySleepSec * 1000);
                } catch (InterruptedException ex1) {
                // too bad
                }
            }
        } else // The channel could be resolved from the Naming Service
        {
            // Get the channel timestamp located into the Naming Service or set it to the current time
            initChannelTimestamp();
        //				System.out.println("*** Got NC " + channelName + " from the naming service");
        }
    } while (retValue == null && --retryNumberAttempts >= 0);
    if (retValue == null) {
        AcsJGenericErrorEx ex = new AcsJGenericErrorEx();
        ex.setErrorDesc("Giving up to get reference to channel " + channelName);
        throw ex;
    }
    return retValue;
}
Also used : AcsJGenericErrorEx(alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx) NameComponent(org.omg.CosNaming.NameComponent) EventChannel(gov.sandia.NotifyMonitoringExt.EventChannel) AcsJUnexpectedExceptionEx(alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx) NameAlreadyUsed(gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)

Aggregations

AcsJGenericErrorEx (alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx)5 AcsJUnexpectedExceptionEx (alma.ACSErrTypeCommon.wrappers.AcsJUnexpectedExceptionEx)2 AcsJUnknownEx (alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)2 AcsJCompletion (alma.acs.exceptions.AcsJCompletion)2 AcsJException (alma.acs.exceptions.AcsJException)2 AcsJIllegalArgumentEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)1 AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)1 ControlSystemChangeOfStateEvent (alma.SPR2005067.ControlSystemChangeOfStateEvent)1 ControlSystemChangeOfStateEvent2 (alma.SPR2005067.ControlSystemChangeOfStateEvent2)1 EventChannel (gov.sandia.NotifyMonitoringExt.EventChannel)1 NameAlreadyUsed (gov.sandia.NotifyMonitoringExt.NameAlreadyUsed)1 Date (java.util.Date)1 NameComponent (org.omg.CosNaming.NameComponent)1