Search in sources :

Example 31 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class ContainerServicesImpl method createNotificationChannelPublisher.

/**
	 * @TODO: once we support notification over other frameworks, check that configuration 
	 * and instantiate some class other than NCPublisher.
	 * 
	 * @see ContainerServices#createNotificationChannelPublisher(String, String)
	 */
@Override
public <T> AcsEventPublisher<T> createNotificationChannelPublisher(String channelName, String channelNotifyServiceDomainName, Class<T> eventType) throws AcsJContainerServicesEx {
    AcsEventPublisher<T> publisher = null;
    try {
        Object[] args = new Object[] { channelName, channelNotifyServiceDomainName, this, getNameService() };
        //			// TODO: Can we do this without the direct cast? The usual "asSubclass" is not enough 
        // because we don't create a subclass of Class<T> but rather of Class<U<T>>.
        // Also the getGenericInterfaces / ParameterizedType trick does not work because because we don't have a 
        // concrete parameterized type.
        Class<AcsEventPublisher<T>> clazz = (Class<AcsEventPublisher<T>>) Class.forName(CLASSNAME_NC_PUBLISHER);
        Constructor<? extends AcsEventPublisher<T>> constructor = clazz.getConstructor(String.class, String.class, ContainerServicesBase.class, NamingContext.class);
        publisher = constructor.newInstance(args);
    } catch (ClassNotFoundException e) {
        // TODO: maybe we could prevent future NCPublisher creation tries, since the class isn't and will not be loaded
        //       The same applies for the next "catch" block
        m_logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because the 'NCPublisher' class is not present in the classpath", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class not present in the classpath");
        throw ex;
    } catch (ClassCastException e) {
        m_logger.log(AcsLogLevel.ERROR, "Cannot create NC publisher because loaded class '" + CLASSNAME_NC_PUBLISHER + "' is not of type 'AcsEventPublisher", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        ex.setContextInfo("'" + CLASSNAME_NC_PUBLISHER + "' class does not extend 'AcsEventPublisher'");
        throw ex;
    } catch (Throwable e) {
        if (e instanceof InvocationTargetException) {
            // ctor ex, seen for example in ICT-1508
            e = e.getCause();
        }
        m_logger.log(AcsLogLevel.ERROR, "Unexpected error while creating new AcsEventPublisher object", e);
        AcsJContainerServicesEx ex = new AcsJContainerServicesEx(e);
        throw ex;
    }
    m_publishers.put((channelNotifyServiceDomainName == null ? "" : channelNotifyServiceDomainName) + "/" + channelName, publisher);
    // crude and arbitrary measure against misbehaving clients. In one case we've seen more than 2000 suppliers created by accident. 
    if (m_publishers.size() > 200) {
        m_logger.warning("Component or client '" + m_clientName + "' has already created " + m_publishers.size() + " event publishers. Developers should check if this is really necessary.");
    }
    return publisher;
}
Also used : AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) InvocationTargetException(java.lang.reflect.InvocationTargetException) AcsEventPublisher(alma.acs.nc.AcsEventPublisher) EntityT(alma.entities.commonentity.EntityT)

Example 32 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class AcsCorba method setORBLevelRoundtripTimeout.

/**
	 * Sets the roundtrip timeout for all calls going out through the ORB that is encapsulated by this class.
	 * For example, this applies to all corba calls made by a container and any of its components.
	 * @param timeoutSeconds
	 * @throws AcsJContainerServicesEx
	 * @see {@link #wrapForRoundtripTimeout(Object, double)}
	 */
public void setORBLevelRoundtripTimeout(double timeoutSeconds) throws AcsJContainerServicesEx {
    if (!isInitialized()) {
        throw new IllegalStateException("Only call when this object has been initialized!");
    }
    try {
        Any rrtPolicyAny = m_orb.create_any();
        rrtPolicyAny.insert_ulonglong(UTCUtility.durationJavaMillisToOmg((long) timeoutSeconds * 1000));
        Policy p = m_orb.create_policy(RELATIVE_RT_TIMEOUT_POLICY_TYPE.value, rrtPolicyAny);
        // about PolicyManager, see Corba spec (2.4) section 4.9.1
        PolicyManager pm = PolicyManagerHelper.narrow(m_orb.resolve_initial_references("ORBPolicyManager"));
        pm.set_policy_overrides(new Policy[] { p }, SetOverrideType.SET_OVERRIDE);
        p.destroy();
    } catch (Throwable thr) {
        AcsJContainerServicesEx ex2 = new AcsJContainerServicesEx(thr);
        ex2.setContextInfo("Failed to set the ORB-level client-side corba roundtrip timeout to " + timeoutSeconds);
        throw ex2;
    }
    m_logger.fine("Set ORB level roundtrip timeout to " + timeoutSeconds + " seconds.");
}
Also used : Policy(org.omg.CORBA.Policy) InvalidPolicy(org.omg.PortableServer.POAPackage.InvalidPolicy) PolicyManager(org.omg.CORBA.PolicyManager) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Any(org.omg.CORBA.Any)

Example 33 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class AcsCorba method wrapForRoundtripTimeout.

/**
	 * <p>
	 * Impl note: The corba spec (v 2.4, 4.3.8.1) describes the difference between 
	 * SetOverrideType.SET_OVERRIDE and SetOverrideType.ADD_OVERRIDE. It is not clear to me (HSO) 
	 * which one should be used, or if there is no practical difference.
	 * @param corbaRef
	 * @param timeoutSeconds
	 * @return
	 * @throws AcsJContainerServicesEx
	 * @see {@link #setORBLevelRoundtripTimeout(double)}
	 */
public org.omg.CORBA.Object wrapForRoundtripTimeout(org.omg.CORBA.Object corbaRef, double timeoutSeconds) throws AcsJContainerServicesEx {
    if (!isInitialized()) {
        throw new IllegalStateException("Only call when this object has been initialized!");
    }
    org.omg.CORBA.Object ret = null;
    try {
        Any rrtPolicyAny = m_orb.create_any();
        rrtPolicyAny.insert_ulonglong(UTCUtility.durationJavaMillisToOmg((long) timeoutSeconds * 1000));
        Policy p = m_orb.create_policy(RELATIVE_RT_TIMEOUT_POLICY_TYPE.value, rrtPolicyAny);
        ret = corbaRef._set_policy_override(new Policy[] { p }, SetOverrideType.SET_OVERRIDE);
        p.destroy();
    } catch (Throwable thr) {
        AcsJContainerServicesEx ex2 = new AcsJContainerServicesEx(thr);
        ex2.setContextInfo("Failed to set the object-level client-side corba roundtrip timeout to " + timeoutSeconds);
        throw ex2;
    }
    return ret;
}
Also used : Policy(org.omg.CORBA.Policy) InvalidPolicy(org.omg.PortableServer.POAPackage.InvalidPolicy) Object(org.omg.CORBA.Object) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx) Any(org.omg.CORBA.Any)

Example 34 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class ChannelProperties method getCDBAdminProps.

// //////////////////////////////////////////////////////////////////////////
/**
	 * Given a channel name that exists in the ACS CDB
	 * ($ACS_CDB/CDB/MACI/Channels/channelName/channelName.xml), this function
	 * returns the channels administrative properties in their CORBA format.
	 * 
	 * @param channelName
	 *           name of the channel found in $ACS_CDB/CDB/MACI/Channels
	 * @return channel's admin properties
	 * @throws AcsJException
	 *            if the channel's CDB entry is corrupted in any way
	 */
public Property[] getCDBAdminProps(String channelName) throws 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");
        throw new alma.ACSErrTypeCommon.wrappers.AcsJNoResourcesEx(e);
    }
    // MaxQueueLength - TAO 1.1 had a queque of ~5 events. TAO 1.3 allows an
    // infinite amount of events to be stored. 20 seems like
    // a reasonable default.
    Any maxQLAny = m_services.getAdvancedContainerServices().getAny();
    try {
        maxQLAny.insert_long(tempDAO.get_long("MaxQueueLength"));
    } 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 maxQL = new Property(MaxQueueLength.value, maxQLAny);
    // MaxConsumers - ///////////////////////////////////////////////////////
    Any maxConsumersAny = m_services.getAdvancedContainerServices().getAny();
    try {
        maxConsumersAny.insert_long(tempDAO.get_long("MaxConsumers"));
    } 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 maxConsumers = new Property(MaxConsumers.value, maxConsumersAny);
    // MaxSuppliers - ///////////////////////////////////////////////////////
    Any maxSuppliersAny = m_services.getAdvancedContainerServices().getAny();
    try {
        maxSuppliersAny.insert_long(tempDAO.get_long("MaxSuppliers"));
    } 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 maxSuppliers = new Property(MaxSuppliers.value, maxSuppliersAny);
    // RejectNewEvents - if the queque is full, suppliers get exceptions when
    // trying to push events onto the channel.
    Any rejectNEAny = m_services.getAdvancedContainerServices().getAny();
    boolean tBool = true;
    try {
        if (tempDAO.get_string("RejectNewEvents").equals("false")) {
            tBool = 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);
    }
    rejectNEAny.insert_boolean(tBool);
    Property rejectNE = new Property(RejectNewEvents.value, rejectNEAny);
    Property[] adminProps = { maxQL, maxConsumers, maxSuppliers, rejectNE };
    return adminProps;
}
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 35 with AcsJContainerServicesEx

use of alma.JavaContainerError.wrappers.AcsJContainerServicesEx in project ACS by ACS-Community.

the class AcsNcReconnectionCallback method disconnect.

public void disconnect() {
    if (id_is_valid_) {
        ReconnectionRegistry registry = ReconnectionRegistryHelper.narrow(ecf_);
        registry.unregister_callback(callback_id_);
        /* This should never occur, but in any case*/
        try {
            services.deactivateOffShoot(this);
        } catch (AcsJContainerServicesEx e) {
        }
        id_is_valid_ = false;
    }
}
Also used : ReconnectionRegistry(NotifyExt.ReconnectionRegistry) AcsJContainerServicesEx(alma.JavaContainerError.wrappers.AcsJContainerServicesEx)

Aggregations

AcsJContainerServicesEx (alma.JavaContainerError.wrappers.AcsJContainerServicesEx)51 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)10 AcsJException (alma.acs.exceptions.AcsJException)6 AcsJmaciErrTypeEx (alma.maciErrType.wrappers.AcsJmaciErrTypeEx)6 ComponentDescriptor (alma.acs.component.ComponentDescriptor)5 DAL (com.cosylab.CDB.DAL)5 ComponentLifecycleException (alma.acs.component.ComponentLifecycleException)4 ComponentInfo (si.ijs.maci.ComponentInfo)4 OffShootOperations (alma.ACS.OffShootOperations)3 AcsJIllegalArgumentEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalArgumentEx)3 EntityT (alma.entities.commonentity.EntityT)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Any (org.omg.CORBA.Any)3 NamingContext (org.omg.CosNaming.NamingContext)3 Servant (org.omg.PortableServer.Servant)3 OffShoot (alma.ACS.OffShoot)2 AcsJCORBAProblemEx (alma.ACSErrTypeCommon.wrappers.AcsJCORBAProblemEx)2 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)2 ComponentClient (alma.acs.component.client.ComponentClient)2 AcsManagerProxy (alma.acs.container.AcsManagerProxy)2