Search in sources :

Example 6 with DALChangeListener

use of com.cosylab.CDB.DALChangeListener in project ACS by ACS-Community.

the class MyTestCBvoid method testActivateOffShoot.

public void testActivateOffShoot() throws Exception {
    // activate callback object
    MyTestCBvoid cb = new MyTestCBvoid(m_logger);
    m_logger.info("MyTestCBvoid instantiated...");
    CBvoid cbvoid = alma.ACS.CBvoidHelper.narrow(getContainerServices().activateOffShoot(cb));
    m_logger.info("MyTestCBvoid activated.");
    // activate dal listener object
    m_logger.info("activating dal listener offshoot...");
    DALChangeListenerPOA dalListenerSrv = new MyTestDALChangeListener();
    OffShoot offshoot2 = getContainerServices().activateOffShoot(dalListenerSrv);
    DALChangeListener dalListenerRef = DALChangeListenerHelper.narrow(offshoot2);
    m_logger.info("done activating dal listener offshoot.");
    // check if dal listener works...
    m_logger.info("calling dal listener...");
    dalListenerRef.object_changed("happyCurl");
    m_logger.info("done calling dal listener.");
    // check if callback works...
    RWdouble brightness = null;
    Lamp lamp = LampHelper.narrow(getContainerServices().getComponent(m_lampCurl));
    assertNotNull("reference to Lamp component not null", lamp);
    brightness = lamp.brightness();
    assertNotNull("brightness property of lamp not null", brightness);
    CBDescIn desc = new CBDescIn();
    m_logger.info("m_desc instantiated...");
    m_logger.info("before setting callback...");
    brightness.set_async(7.345, cbvoid, desc);
    m_logger.finer("callback set...");
//todo: do something and get feedback from the callback object		
//		m_logger.finer("changing value (sync)...");
//		brightness.set_sync(8.456);
}
Also used : DALChangeListenerPOA(com.cosylab.CDB.DALChangeListenerPOA) RWdouble(alma.ACS.RWdouble) OffShoot(alma.ACS.OffShoot) DALChangeListener(com.cosylab.CDB.DALChangeListener) Lamp(alma.acsexmplLamp.Lamp) CBvoid(alma.ACS.CBvoid) CBDescIn(alma.ACS.CBDescIn)

Example 7 with DALChangeListener

use of com.cosylab.CDB.DALChangeListener in project ACS by ACS-Community.

the class HibernateWDALImpl method clearCache.

protected void clearCache(String curl) {
    // NOTICE: this really does not reload the data from DB...
    // first take care of our own map
    m_logger.info("clear_cache(curl): clearCache1");
    object_changed(curl);
    m_logger.info("clear_cache(curl): clearCache2");
    // then notify all registered listeners
    synchronized (listenedCurls) {
        boolean needToSave = false;
        ArrayList<Integer> listeners = listenedCurls.get(curl);
        m_logger.info("clear_cache(curl): clearCache3");
        if (listeners == null) {
            return;
        }
        ArrayList<Integer> invalidListeners = new ArrayList<Integer>();
        m_logger.info("clear_cache(curl): clearCache4");
        for (int i = 0; i < listeners.size(); i++) {
            DALChangeListener listener = null;
            synchronized (regListeners) {
                listener = regListeners.get(listeners.get(i));
            }
            try {
                //System.out.println("Calling " + listener + " ...");
                listener.object_changed(curl);
            //System.out.println("Done " + listener);
            } catch (RuntimeException e) {
                // silent here because who knows what happend with clients
                invalidListeners.add(listeners.get(i));
            }
        }
        m_logger.info("clear_cache(curl): clearCache5");
        // now remove invalid listeners if any
        for (int i = 0; i < invalidListeners.size(); i++) {
            listeners.remove(invalidListeners.get(i));
            synchronized (regListeners) {
                regListeners.remove(invalidListeners.get(i));
            }
            needToSave = true;
        }
        m_logger.info("clear_cache(curl): clearCache6");
        if (needToSave) {
            cleanListenedCurls();
            saveListeners();
        }
        m_logger.info("clear_cache(curl): clearCache7");
    }
}
Also used : ArrayList(java.util.ArrayList) DALChangeListener(com.cosylab.CDB.DALChangeListener)

Example 8 with DALChangeListener

use of com.cosylab.CDB.DALChangeListener in project ACS by ACS-Community.

the class HibernateWDALImpl method cleanListenedCurls.

/**
	 * Cleans listened curls from invalid listeners
	 * to avoid repeatedly calling invalid listeners
	 */
protected void cleanListenedCurls() {
    Iterator iter = listenedCurls.keySet().iterator();
    while (iter.hasNext()) {
        String curl = (String) iter.next();
        ArrayList listeners = (ArrayList) listenedCurls.get(curl);
        if (listeners == null)
            continue;
        for (int i = 0; i < listeners.size(); i++) {
            DALChangeListener listener = null;
            synchronized (regListeners) {
                listener = (DALChangeListener) regListeners.get(listeners.get(i));
            }
            if (listener == null) {
                listeners.remove(i);
                i--;
            }
        }
    }
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) DALChangeListener(com.cosylab.CDB.DALChangeListener)

Aggregations

DALChangeListener (com.cosylab.CDB.DALChangeListener)8 ArrayList (java.util.ArrayList)5 LogConfigException (alma.acs.logging.config.LogConfigException)2 DALChangeListenerPOA (com.cosylab.CDB.DALChangeListenerPOA)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 CBDescIn (alma.ACS.CBDescIn)1 CBvoid (alma.ACS.CBvoid)1 OffShoot (alma.ACS.OffShoot)1 RWdouble (alma.ACS.RWdouble)1 Lamp (alma.acsexmplLamp.Lamp)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 NamingException (javax.naming.NamingException)1 HibernateException (org.hibernate.HibernateException)1 POA (org.omg.PortableServer.POA)1 DOMException (org.w3c.dom.DOMException)1