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;
}
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();
}
}
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);
}
Aggregations