/** * Triggers deleting the existing group entry. * * @param deviceId the device ID * @param appCookie the group key */ @Override public void deleteGroupDescription(DeviceId deviceId, GroupKey appCookie) { // Check if a group is existing with the provided key StoredGroupEntry existing = (groupEntriesByKey.get(deviceId) != null) ? groupEntriesByKey.get(deviceId).get(appCookie) : null; if (existing == null) { return; } synchronized (existing) { existing.setState(GroupState.PENDING_DELETE); } notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, existing)); }
@Override public void addOrUpdateExtraneousGroupEntry(Group group) { ConcurrentMap<GroupId, Group> extraneousIdTable = getExtraneousGroupIdTable(group.deviceId()); extraneousIdTable.put(group.id(), group); // Check the reference counter if (group.referenceCount() == 0) { notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, group)); } }
@Override public void groupOperationFailed(DeviceId deviceId, GroupOperation operation) { StoredGroupEntry existing = (groupEntriesById.get( deviceId) != null) ? groupEntriesById.get(deviceId).get(operation.groupId()) : null; if (existing == null) { log.warn("No group entry with ID {} found ", operation.groupId()); return; } switch (operation.opType()) { case ADD: notifyDelegate(new GroupEvent(Type.GROUP_ADD_FAILED, existing)); break; case MODIFY: notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_FAILED, existing)); break; case DELETE: notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_FAILED, existing)); break; default: log.warn("Unknown group operation type {}", operation.opType()); } ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(existing.deviceId()); ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(existing.deviceId()); idTable.remove(existing.id()); keyTable.remove(existing.appCookie()); }
/** * Removes the group entry from store. * * @param group group entry */ @Override public void removeGroupEntry(Group group) { StoredGroupEntry existing = (groupEntriesById.get( group.deviceId()) != null) ? groupEntriesById.get(group.deviceId()).get(group.id()) : null; if (existing != null) { ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(existing.deviceId()); ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(existing.deviceId()); idTable.remove(existing.id()); keyTable.remove(existing.appCookie()); notifyDelegate(new GroupEvent(Type.GROUP_REMOVED, existing)); } }
existing.state()); existing.setState(Group.GroupState.PENDING_ADD); notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group)); break;
if (existing.state() == GroupState.PENDING_ADD) { existing.setState(GroupState.ADDED); event = new GroupEvent(Type.GROUP_ADDED, existing); } else { if (existing.state() == GroupState.PENDING_UPDATE) { existing.setState(GroupState.ADDED); event = new GroupEvent(Type.GROUP_UPDATED, existing);
private void storeGroupDescriptionInternal(GroupDescription groupDesc) { // Check if a group is existing with the same key if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) { return; } GroupId id = null; if (groupDesc.givenGroupId() == null) { // Get a new group identifier id = new DefaultGroupId(getFreeGroupIdValue(groupDesc.deviceId())); } else { id = new DefaultGroupId(groupDesc.givenGroupId()); } // Create a group entry object StoredGroupEntry group = new DefaultGroup(id, groupDesc); // Insert the newly created group entry into concurrent key and id maps ConcurrentMap<GroupKey, StoredGroupEntry> keyTable = getGroupKeyTable(groupDesc.deviceId()); keyTable.put(groupDesc.appCookie(), group); ConcurrentMap<GroupId, StoredGroupEntry> idTable = getGroupIdTable(groupDesc.deviceId()); idTable.put(id, group); notifyDelegate(new GroupEvent(GroupEvent.Type.GROUP_ADD_REQUESTED, group)); }
keyTable.put(newGroup.appCookie(), newGroup); idTable.put(newGroup.id(), newGroup); notifyDelegate(new GroupEvent(Type.GROUP_UPDATE_REQUESTED, newGroup));