Search in sources :

Example 1 with AcsJUnknownEx

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

the class CommonPropertyImpl method mnemonicValue.

/**
	 * Mnemonic value retrival.
	 * If <code>keyTime == mnemonicTime</code> cached mnemonic value is returned.
	 * @param keyTime	time (java) of mnemonic request.
	 * @param completionHolder completion holder that will be given completion.
	 * 						   NOTE: completion is passsed by reference, so do not change its value,
	 * 						   copy its value before and do it on a local copy
	 * @return current property value.
	 * @see getSync
	 */
// TODO implement test with many threads calling this method... 
public Object mnemonicValue(long keyTime, CompletionHolder completionHolder) {
    for (; ; ) {
        // read mnemonic data lock
        try {
            mnemonicDataLock.readLock().lock();
        } catch (Throwable th) {
            completionHolder.value = mnemonicCompletion;
            return mnemonicValue;
        /* return old */
        }
        try {
            // if same time or newer exist return cached value
            if (keyTime <= mnemonicTime) {
                completionHolder.value = mnemonicCompletion;
                return mnemonicValue;
            }
        } finally {
            mnemonicDataLock.readLock().unlock();
        }
        // read value wait, if reading is already pending			
        synchronized (mnemonicValueRetrival) {
            // lock if not newer read
            if (keyTime <= mnemonicReadPending) {
                try {
                    mnemonicValueRetrival.wait();
                } catch (InterruptedException ie) {
                }
                // re-read again
                continue;
            } else {
                mnemonicReadPending = keyTime;
                break;
            }
        }
    }
    //		
    // value retrival
    //
    Object retValue = null;
    try {
        retValue = getSync(completionHolder);
    } catch (AcsJException acsex) {
        retValue = defaultValue;
        completionHolder.value = CompletionUtil.generateCompletion(acsex);
    } catch (Throwable th) {
        retValue = defaultValue;
        completionHolder.value = CompletionUtil.generateCompletion(new AcsJUnknownEx("Failed to retrieve value.", th));
    }
    // write mnemonic data lock
    try {
        mnemonicDataLock.writeLock().lock();
    } catch (Throwable th) {
        return mnemonicValue;
    /* return old */
    }
    try {
        if (keyTime > mnemonicTime) {
            mnemonicTime = keyTime;
            mnemonicValue = retValue;
            mnemonicCompletion = completionHolder.value;
        }
        return mnemonicValue;
    } finally {
        mnemonicDataLock.writeLock().unlock();
        // read value wait release
        synchronized (mnemonicValueRetrival) {
            mnemonicValueRetrival.notifyAll();
        }
    }
}
Also used : AcsJException(alma.acs.exceptions.AcsJException) AcsJUnknownEx(alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)

Example 2 with AcsJUnknownEx

use of alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx 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 AcsJUnknownEx

use of alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx 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 AcsJUnknownEx

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

the class ErrorComponentTest method testOutCompletion.

public void testOutCompletion() {
    alma.ACSErr.CompletionHolder comp = new alma.ACSErr.CompletionHolder();
    try {
        errorComp.outCompletion(comp);
    } 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");
    }
    assertEquals(0, comp.value.type);
    assertEquals(0, comp.value.code);
}
Also used : AcsJUnknownEx(alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)

Example 5 with AcsJUnknownEx

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

the class AcsContainer method activate_component_async.

/* (non-Javadoc)
	 * @see si.ijs.maci.ContainerOperations#activate_component_async(int, long, java.lang.String, java.lang.String, java.lang.String, si.ijs.maci.CBComponentInfo, alma.ACS.CBDescIn)
	 */
public void activate_component_async(final int h, final long execution_id, final String name, final String exe, final String type, final CBComponentInfo callback, final CBDescIn desc) {
    m_logger.finer("activate_component_async request received for '" + name + "', enqueueing (taskCount: " + threadPoolExecutor.getTaskCount() + ", active threads: " + threadPoolExecutor.getActiveCount() + ", maxPoolSize: " + threadPoolExecutor.getMaximumPoolSize() + ").");
    threadPoolExecutor.execute(new Runnable() {

        @Override
        public void run() {
            m_logger.finer("activate_component_async request for '" + name + "' is being processed now.");
            CBDescOut descOut = new CBDescOut(0, desc.id_tag);
            ComponentInfo componentInfo = null;
            try {
                componentInfo = activate_component(h, execution_id, name, exe, type);
            } catch (CannotActivateComponentEx ae) {
                AcsJCannotActivateComponentEx aae = AcsJCannotActivateComponentEx.fromCannotActivateComponentEx(ae);
                ComponentInfo dummyComponentInfo = new ComponentInfo(type, exe, null, name, new int[0], 0, m_containerName, h, 0, new String[0]);
                callback.done(dummyComponentInfo, aae.toAcsJCompletion().toCorbaCompletion(), descOut);
            } catch (Throwable th) {
                AcsJException ae = new AcsJUnknownEx(th);
                ComponentInfo dummyComponentInfo = new ComponentInfo(type, exe, null, name, new int[0], 0, m_containerName, h, 0, new String[0]);
                callback.done(dummyComponentInfo, ae.toAcsJCompletion().toCorbaCompletion(), descOut);
            }
            // Try to invoke the callback several times before giving up
            int retry = 0;
            boolean notified = false;
            while (retry < 3 && !notified) {
                try {
                    m_logger.log(AcsLogLevel.DELOUSE, "Calling maci::CBComponentInfo::done with descOut.id_tag = %d." + descOut.id_tag + " for '" + name + "'");
                    callback.done(componentInfo, new alma.ACSErrTypeOK.wrappers.ACSErrOKAcsJCompletion().toCorbaCompletion(), descOut);
                    notified = true;
                    m_logger.log(AcsLogLevel.DELOUSE, "Call to maci::CBComponentInfo::done with descOut.id_tag = %d." + descOut.id_tag + " for '" + name + "' completed");
                } catch (Throwable t) {
                    retry++;
                    m_logger.log(AcsLogLevel.DELOUSE, "Call to maci::CBComponentInfo::done with descOut.id_tag = %d." + descOut.id_tag + " for '" + name + "' failed, retrying...", t);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException ie) {
                    }
                }
            }
            if (!notified) {
                m_logger.log(AcsLogLevel.ERROR, "Call to maci::CBComponentInfo::done with descOut.id_tag = %d." + descOut.id_tag + " for '" + name + "' failed, deactivating the component.");
                try {
                    deactivate_component(h);
                } catch (ComponentDeactivationUncleanEx e) {
                    m_logger.log(AcsLogLevel.WARNING, "UNclean deactivation of component descOut.id_tag = %d." + descOut.id_tag + " for '" + name + "'", e);
                } catch (ComponentDeactivationFailedEx e) {
                    m_logger.log(AcsLogLevel.WARNING, "Deactivation of component failed descOut.id_tag = %d." + descOut.id_tag + " for '" + name + "'", e);
                } catch (Throwable t) {
                    m_logger.log(AcsLogLevel.WARNING, "Deactivation of component failed descOut.id_tag = %d." + descOut.id_tag + " for '" + name + "'", t);
                }
            }
        }
    });
}
Also used : AcsJComponentDeactivationFailedEx(alma.maciErrType.wrappers.AcsJComponentDeactivationFailedEx) ComponentDeactivationFailedEx(alma.maciErrType.ComponentDeactivationFailedEx) CBDescOut(alma.ACS.CBDescOut) AcsJCannotActivateComponentEx(alma.maciErrType.wrappers.AcsJCannotActivateComponentEx) AcsJException(alma.acs.exceptions.AcsJException) AcsJUnknownEx(alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx) CannotActivateComponentEx(alma.maciErrType.CannotActivateComponentEx) AcsJCannotActivateComponentEx(alma.maciErrType.wrappers.AcsJCannotActivateComponentEx) ComponentDeactivationUncleanEx(alma.maciErrType.ComponentDeactivationUncleanEx) AcsJComponentDeactivationUncleanEx(alma.maciErrType.wrappers.AcsJComponentDeactivationUncleanEx) ComponentInfo(si.ijs.maci.ComponentInfo) CBComponentInfo(si.ijs.maci.CBComponentInfo)

Aggregations

AcsJUnknownEx (alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)5 AcsJGenericErrorEx (alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx)2 AcsJCompletion (alma.acs.exceptions.AcsJCompletion)2 AcsJException (alma.acs.exceptions.AcsJException)2 CBDescOut (alma.ACS.CBDescOut)1 CannotActivateComponentEx (alma.maciErrType.CannotActivateComponentEx)1 ComponentDeactivationFailedEx (alma.maciErrType.ComponentDeactivationFailedEx)1 ComponentDeactivationUncleanEx (alma.maciErrType.ComponentDeactivationUncleanEx)1 AcsJCannotActivateComponentEx (alma.maciErrType.wrappers.AcsJCannotActivateComponentEx)1 AcsJComponentDeactivationFailedEx (alma.maciErrType.wrappers.AcsJComponentDeactivationFailedEx)1 AcsJComponentDeactivationUncleanEx (alma.maciErrType.wrappers.AcsJComponentDeactivationUncleanEx)1 CBComponentInfo (si.ijs.maci.CBComponentInfo)1 ComponentInfo (si.ijs.maci.ComponentInfo)1