Search in sources :

Example 1 with EdgeEventId

use of org.thingsboard.server.common.data.id.EdgeEventId in project thingsboard by thingsboard.

the class EdgeEventEntity method toData.

@Override
public EdgeEvent toData() {
    EdgeEvent edgeEvent = new EdgeEvent(new EdgeEventId(this.getUuid()));
    edgeEvent.setCreatedTime(createdTime);
    edgeEvent.setTenantId(TenantId.fromUUID(tenantId));
    edgeEvent.setEdgeId(new EdgeId(edgeId));
    if (entityId != null) {
        edgeEvent.setEntityId(entityId);
    }
    edgeEvent.setType(edgeEventType);
    edgeEvent.setAction(edgeEventAction);
    edgeEvent.setBody(entityBody);
    edgeEvent.setUid(edgeEventUid);
    return edgeEvent;
}
Also used : EdgeId(org.thingsboard.server.common.data.id.EdgeId) EdgeEventId(org.thingsboard.server.common.data.id.EdgeEventId) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Example 2 with EdgeEventId

use of org.thingsboard.server.common.data.id.EdgeEventId in project thingsboard by thingsboard.

the class JpaBaseEdgeEventDao method save.

@Override
public EdgeEvent save(EdgeEvent edgeEvent) {
    final Lock readWriteLock = readWriteLocks.computeIfAbsent(edgeEvent.getEdgeId(), id -> new ReentrantLock());
    readWriteLock.lock();
    try {
        log.debug("Save edge event [{}] ", edgeEvent);
        if (edgeEvent.getId() == null) {
            UUID timeBased = Uuids.timeBased();
            edgeEvent.setId(new EdgeEventId(timeBased));
            edgeEvent.setCreatedTime(Uuids.unixTimestamp(timeBased));
        } else if (edgeEvent.getCreatedTime() == 0L) {
            UUID eventId = edgeEvent.getId().getId();
            if (eventId.version() == 1) {
                edgeEvent.setCreatedTime(Uuids.unixTimestamp(eventId));
            } else {
                edgeEvent.setCreatedTime(System.currentTimeMillis());
            }
        }
        if (StringUtils.isEmpty(edgeEvent.getUid())) {
            edgeEvent.setUid(edgeEvent.getId().toString());
        }
        return save(new EdgeEventEntity(edgeEvent)).orElse(null);
    } finally {
        readWriteLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) EdgeEventId(org.thingsboard.server.common.data.id.EdgeEventId) EdgeEventEntity(org.thingsboard.server.dao.model.sql.EdgeEventEntity) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) UUID(java.util.UUID) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 3 with EdgeEventId

use of org.thingsboard.server.common.data.id.EdgeEventId in project thingsboard by thingsboard.

the class BaseEdgeEventServiceTest method saveEdgeEventWithProvidedTime.

private EdgeEvent saveEdgeEventWithProvidedTime(long time, EdgeId edgeId, EntityId entityId, TenantId tenantId) throws Exception {
    EdgeEvent edgeEvent = generateEdgeEvent(tenantId, edgeId, entityId, EdgeEventActionType.ADDED);
    edgeEvent.setId(new EdgeEventId(Uuids.startOf(time)));
    return edgeEventService.save(edgeEvent);
}
Also used : EdgeEventId(org.thingsboard.server.common.data.id.EdgeEventId) EdgeEvent(org.thingsboard.server.common.data.edge.EdgeEvent)

Aggregations

EdgeEventId (org.thingsboard.server.common.data.id.EdgeEventId)3 EdgeEvent (org.thingsboard.server.common.data.edge.EdgeEvent)2 UUID (java.util.UUID)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 EdgeId (org.thingsboard.server.common.data.id.EdgeId)1 NULL_UUID (org.thingsboard.server.dao.model.ModelConstants.NULL_UUID)1 EdgeEventEntity (org.thingsboard.server.dao.model.sql.EdgeEventEntity)1