@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AbstractDownlinkRequest<?> other = (AbstractDownlinkRequest<?>) obj; if (path == null) { if (other.path != null) return false; } else if (!path.equals(other.path)) return false; return true; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Observation other = (Observation) obj; if (context == null) { if (other.context != null) return false; } else if (!context.equals(other.context)) return false; if (!Arrays.equals(id, other.id)) return false; if (path == null) { if (other.path != null) return false; } else if (!path.equals(other.path)) return false; if (registrationId == null) { if (other.registrationId != null) return false; } else if (!registrationId.equals(other.registrationId)) return false; return true; }
private Set<Observation> getObservations(String registrationId, String resourcePath) { if (registrationId == null || resourcePath == null) return Collections.emptySet(); Set<Observation> result = new HashSet<>(); LwM2mPath lwPath = new LwM2mPath(resourcePath); for (Observation obs : getObservations(registrationId)) { if (lwPath.equals(obs.getPath())) { result.add(obs); } } return result; }
@Override public Collection<Observation> addObservation(String registrationId, Observation observation) { List<Observation> removed = new ArrayList<>(); try { lock.writeLock().lock(); // cancel existing observations for the same path and registration id. for (Observation obs : unsafeGetObservations(registrationId)) { if (observation.getPath().equals(obs.getPath()) && !Arrays.equals(observation.getId(), obs.getId())) { unsafeRemoveObservation(new Token(obs.getId())); removed.add(obs); } } } finally { lock.writeLock().unlock(); } return removed; }
@Override public Collection<Observation> addObservation(String registrationId, Observation observation) { List<Observation> removed = new ArrayList<>(); try (Jedis j = pool.getResource()) { // fetch the client ep by registration ID index byte[] ep = j.get(toRegIdKey(registrationId)); if (ep == null) { return null; } byte[] lockValue = null; byte[] lockKey = toLockKey(ep); try { lockValue = RedisLock.acquire(j, lockKey); // cancel existing observations for the same path and registration id. for (Observation obs : getObservations(j, registrationId)) { if (observation.getPath().equals(obs.getPath()) && !Arrays.equals(observation.getId(), obs.getId())) { removed.add(obs); unsafeRemoveObservation(j, registrationId, obs.getId()); } } } finally { RedisLock.release(j, lockKey, lockValue); } } return removed; }
@Override public Collection<Observation> addObservation(String registrationId, Observation observation) { List<Observation> removed = new ArrayList<>(); try (Jedis j = pool.getResource()) { // fetch the client ep by registration ID index byte[] ep = j.get(toRegIdKey(registrationId)); if (ep == null) { return null; } byte[] lockValue = null; byte[] lockKey = toLockKey(ep); try { lockValue = RedisLock.acquire(j, lockKey); // cancel existing observations for the same path and registration id. for (Observation obs : getObservations(j, registrationId)) { if (observation.getPath().equals(obs.getPath()) && !Arrays.equals(observation.getId(), obs.getId())) { removed.add(obs); unsafeRemoveObservation(j, registrationId, obs.getId()); } } } finally { RedisLock.release(j, lockKey, lockValue); } } return removed; }