Search in sources :

Example 11 with EventManager

use of org.apache.cayenne.event.EventManager in project cayenne by apache.

the class DataContext method attachToChannel.

/**
 * @since 3.1
 */
@Override
protected void attachToChannel(DataChannel channel) {
    super.attachToChannel(channel);
    if (mergeHandler != null) {
        mergeHandler.setActive(false);
        mergeHandler = null;
    }
    EventManager eventManager = channel.getEventManager();
    if (eventManager != null) {
        mergeHandler = new DataContextMergeHandler(this);
        // listen to our channel events...
        // note that we must reset listener on channel switch, as there is
        // no
        // guarantee that a new channel uses the same EventManager.
        EventUtil.listenForChannelEvents(channel, mergeHandler);
    }
    if (!usingSharedSnaphsotCache && getObjectStore() != null) {
        DataRowStore cache = getObjectStore().getDataRowCache();
        if (cache != null) {
            cache.setEventManager(eventManager);
        }
    }
}
Also used : EventManager(org.apache.cayenne.event.EventManager)

Example 12 with EventManager

use of org.apache.cayenne.event.EventManager in project cayenne by apache.

the class CayenneContext method attachToChannel.

/**
 * @since 3.1
 */
@Override
protected void attachToChannel(DataChannel channel) {
    super.attachToChannel(channel);
    if (mergeHandler != null) {
        mergeHandler.active = false;
        mergeHandler = null;
    }
    EventManager eventManager = channel.getEventManager();
    if (eventManager != null) {
        mergeHandler = new CayenneContextMergeHandler(this);
        // listen to our channel events...
        // note that we must reset listener on channel switch, as there is
        // no
        // guarantee that a new channel uses the same EventManager.
        EventUtil.listenForChannelEvents(channel, mergeHandler);
    }
}
Also used : EventManager(org.apache.cayenne.event.EventManager)

Example 13 with EventManager

use of org.apache.cayenne.event.EventManager in project cayenne by apache.

the class BaseContext method fireDataChannelChanged.

/**
 * @since 1.2
 */
protected void fireDataChannelChanged(Object postedBy, GraphDiff changes) {
    EventManager manager = getEventManager();
    if (manager != null) {
        GraphEvent e = new GraphEvent(this, postedBy, changes);
        manager.postEvent(e, DataChannel.GRAPH_CHANGED_SUBJECT);
    }
}
Also used : GraphEvent(org.apache.cayenne.graph.GraphEvent) EventManager(org.apache.cayenne.event.EventManager)

Example 14 with EventManager

use of org.apache.cayenne.event.EventManager in project cayenne by apache.

the class ClientRuntimeTest method testShutdown.

@Test
public void testShutdown() throws Exception {
    Map<String, String> properties = new HashMap<>();
    ClientRuntime runtime = ClientRuntime.builder().properties(properties).build();
    // make sure objects to be shut down are resolved
    EventManager em = runtime.getInjector().getInstance(EventManager.class);
    assertNotNull(em);
    assertTrue(em instanceof DefaultEventManager);
    assertFalse(((DefaultEventManager) em).isStopped());
    runtime.getInjector().shutdown();
    assertTrue(((DefaultEventManager) em).isStopped());
}
Also used : DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) EventManager(org.apache.cayenne.event.EventManager) HashMap(java.util.HashMap) DefaultEventManager(org.apache.cayenne.event.DefaultEventManager) Test(org.junit.Test)

Aggregations

EventManager (org.apache.cayenne.event.EventManager)14 Test (org.junit.Test)7 Module (org.apache.cayenne.di.Module)6 DefaultRuntimeProperties (org.apache.cayenne.configuration.DefaultRuntimeProperties)5 RuntimeProperties (org.apache.cayenne.configuration.RuntimeProperties)5 DIBootstrap (org.apache.cayenne.di.DIBootstrap)5 Injector (org.apache.cayenne.di.Injector)5 EventBridge (org.apache.cayenne.event.EventBridge)5 NoopEventBridgeProvider (org.apache.cayenne.event.NoopEventBridgeProvider)5 JdbcEventLogger (org.apache.cayenne.log.JdbcEventLogger)5 Slf4jJdbcEventLogger (org.apache.cayenne.log.Slf4jJdbcEventLogger)5 TransactionFactory (org.apache.cayenne.tx.TransactionFactory)5 Collections (java.util.Collections)4 DefaultTransactionFactory (org.apache.cayenne.tx.DefaultTransactionFactory)4 DefaultTransactionManager (org.apache.cayenne.tx.DefaultTransactionManager)4 TransactionManager (org.apache.cayenne.tx.TransactionManager)4 Assert (org.junit.Assert)4 DataContext (org.apache.cayenne.access.DataContext)3 DataDomain (org.apache.cayenne.access.DataDomain)3 DataRowStoreFactory (org.apache.cayenne.access.DataRowStoreFactory)3