Search in sources :

Example 1 with EventAdapter

use of org.apache.ignite.events.EventAdapter in project ignite by apache.

the class GridEventStorageManagerSelfTest method testWaitForEvent.

/**
 * @throws Exception If failed.
 */
@Test
public void testWaitForEvent() throws Exception {
    Ignite ignite = grid();
    final int usrType = Integer.MAX_VALUE - 1;
    IgniteFuture<Event> fut = waitForLocalEvent(ignite.events(), new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event e) {
            return e.type() == usrType;
        }
    }, usrType);
    try {
        fut.get(500);
        fail("GridFutureTimeoutException must have been thrown.");
    } catch (IgniteFutureTimeoutException e) {
        info("Caught expected exception: " + e);
    }
    ignite.events().recordLocal(new EventAdapter(null, "Test message.", usrType) {
    });
    assert fut.get() != null;
    assertEquals(usrType, fut.get().type());
}
Also used : IgniteFutureTimeoutException(org.apache.ignite.lang.IgniteFutureTimeoutException) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite) EventAdapter(org.apache.ignite.events.EventAdapter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with EventAdapter

use of org.apache.ignite.events.EventAdapter in project ignite by apache.

the class PlatformContextImpl method writeEvent.

/**
 * {@inheritDoc}
 */
@Override
public void writeEvent(BinaryRawWriterEx writer, Event evt) {
    assert writer != null;
    if (evt == null) {
        writer.writeInt(-1);
        return;
    }
    EventAdapter evt0 = (EventAdapter) evt;
    if (evt0 instanceof CacheEvent) {
        writer.writeInt(2);
        writeCommonEventData(writer, evt0);
        CacheEvent event0 = (CacheEvent) evt0;
        writer.writeString(event0.cacheName());
        writer.writeInt(event0.partition());
        writer.writeBoolean(event0.isNear());
        writeNode(writer, event0.eventNode());
        writer.writeObject(event0.key());
        writer.writeObject(event0.xid());
        writer.writeObject(event0.newValue());
        writer.writeObject(event0.oldValue());
        writer.writeBoolean(event0.hasOldValue());
        writer.writeBoolean(event0.hasNewValue());
        writer.writeUuid(event0.subjectId());
        writer.writeString(event0.closureClassName());
        writer.writeString(event0.taskName());
    } else if (evt0 instanceof CacheQueryExecutedEvent) {
        writer.writeInt(3);
        writeCommonEventData(writer, evt0);
        CacheQueryExecutedEvent event0 = (CacheQueryExecutedEvent) evt0;
        writer.writeString(event0.queryType());
        writer.writeString(event0.cacheName());
        writer.writeString(event0.className());
        writer.writeString(event0.clause());
        writer.writeUuid(event0.subjectId());
        writer.writeString(event0.taskName());
    } else if (evt0 instanceof CacheQueryReadEvent) {
        writer.writeInt(4);
        writeCommonEventData(writer, evt0);
        CacheQueryReadEvent event0 = (CacheQueryReadEvent) evt0;
        writer.writeString(event0.queryType());
        writer.writeString(event0.cacheName());
        writer.writeString(event0.className());
        writer.writeString(event0.clause());
        writer.writeUuid(event0.subjectId());
        writer.writeString(event0.taskName());
        writer.writeObject(event0.key());
        writer.writeObject(event0.value());
        writer.writeObject(event0.oldValue());
        writer.writeObject(event0.row());
    } else if (evt0 instanceof CacheRebalancingEvent) {
        writer.writeInt(5);
        writeCommonEventData(writer, evt0);
        CacheRebalancingEvent event0 = (CacheRebalancingEvent) evt0;
        writer.writeString(event0.cacheName());
        writer.writeInt(event0.partition());
        writeNode(writer, event0.discoveryNode());
        writer.writeInt(event0.discoveryEventType());
        writer.writeString(event0.discoveryEventName());
        writer.writeLong(event0.discoveryTimestamp());
    } else if (evt0 instanceof CheckpointEvent) {
        writer.writeInt(6);
        writeCommonEventData(writer, evt0);
        CheckpointEvent event0 = (CheckpointEvent) evt0;
        writer.writeString(event0.key());
    } else if (evt0 instanceof DiscoveryEvent) {
        writer.writeInt(7);
        writeCommonEventData(writer, evt0);
        DiscoveryEvent event0 = (DiscoveryEvent) evt0;
        writeNode(writer, event0.eventNode());
        writer.writeLong(event0.topologyVersion());
        writeNodes(writer, event0.topologyNodes());
    } else if (evt0 instanceof JobEvent) {
        writer.writeInt(8);
        writeCommonEventData(writer, evt0);
        JobEvent event0 = (JobEvent) evt0;
        writer.writeString(event0.taskName());
        writer.writeString(event0.taskClassName());
        writer.writeObject(event0.taskSessionId());
        writer.writeObject(event0.jobId());
        writeNode(writer, event0.taskNode());
        writer.writeUuid(event0.taskSubjectId());
    } else if (evt0 instanceof TaskEvent) {
        writer.writeInt(10);
        writeCommonEventData(writer, evt0);
        TaskEvent event0 = (TaskEvent) evt0;
        writer.writeString(event0.taskName());
        writer.writeString(event0.taskClassName());
        writer.writeObject(event0.taskSessionId());
        writer.writeBoolean(event0.internal());
        writer.writeUuid(event0.subjectId());
    } else
        throw new IgniteException("Unsupported event: " + evt);
}
Also used : CacheQueryReadEvent(org.apache.ignite.events.CacheQueryReadEvent) JobEvent(org.apache.ignite.events.JobEvent) IgniteException(org.apache.ignite.IgniteException) CacheEvent(org.apache.ignite.events.CacheEvent) TaskEvent(org.apache.ignite.events.TaskEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) CheckpointEvent(org.apache.ignite.events.CheckpointEvent) CacheRebalancingEvent(org.apache.ignite.events.CacheRebalancingEvent) EventAdapter(org.apache.ignite.events.EventAdapter) CacheQueryExecutedEvent(org.apache.ignite.events.CacheQueryExecutedEvent)

Example 3 with EventAdapter

use of org.apache.ignite.events.EventAdapter in project ignite by apache.

the class PlatformEvents method startWaitForLocal.

/**
 * Starts the waitForLocal.
 *
 * @param reader Reader
 * @param events Events.
 * @return Result.
 */
private EventAdapter startWaitForLocal(BinaryRawReaderEx reader, IgniteEvents events) {
    Long filterHnd = reader.readObject();
    IgnitePredicate filter = filterHnd != null ? localFilter(filterHnd) : null;
    int[] eventTypes = readEventTypes(reader);
    return (EventAdapter) events.waitForLocal(filter, eventTypes);
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) EventAdapter(org.apache.ignite.events.EventAdapter)

Aggregations

EventAdapter (org.apache.ignite.events.EventAdapter)3 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 CacheEvent (org.apache.ignite.events.CacheEvent)1 CacheQueryExecutedEvent (org.apache.ignite.events.CacheQueryExecutedEvent)1 CacheQueryReadEvent (org.apache.ignite.events.CacheQueryReadEvent)1 CacheRebalancingEvent (org.apache.ignite.events.CacheRebalancingEvent)1 CheckpointEvent (org.apache.ignite.events.CheckpointEvent)1 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)1 Event (org.apache.ignite.events.Event)1 JobEvent (org.apache.ignite.events.JobEvent)1 TaskEvent (org.apache.ignite.events.TaskEvent)1 IgniteFutureTimeoutException (org.apache.ignite.lang.IgniteFutureTimeoutException)1 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1