blob: 293a20c64bd320541a7a33eb3a59856d6922d886 [file] [log] [blame]
/*
* Copyright (c) 2020 Kentyou.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kentyou - initial API and implementation
*/
package org.eclipse.sensinact.gateway.core.message;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.json.JSONObject;
import org.eclipse.sensinact.gateway.common.props.KeysCollection;
import org.eclipse.sensinact.gateway.common.props.TypedKey;
/**
* Update dedicated {@link SnaMessage}
*
* @author <a href="mailto:christophe.munilla@cea.fr">Christophe Munilla</a>
*/
public interface SnaUpdateMessage extends SnaNotificationMessage<SnaUpdateMessage.Update> {
public static final SnaMessage.Type TYPE = SnaMessage.Type.UPDATE;
static final TypedKey<?>[] PERMANENT_KEYS = new TypedKey[] {
new TypedKey<JSONObject>(SnaConstants.UPDATE_KEY, JSONObject.class, false) };
enum Update implements SnaMessageSubType, KeysCollection {
ATTRIBUTE_VALUE_UPDATED, METADATA_VALUE_UPDATED, ACTUATED;
final Set<TypedKey<?>> keys;
Update() {
List<TypedKey<?>> list = Arrays.asList(new SnaMessage.KeysBuilder(SnaErrorMessage.class).keys());
Set<TypedKey<?>> tmpKeys = new HashSet<TypedKey<?>>();
tmpKeys.addAll(list);
keys = Collections.unmodifiableSet(tmpKeys);
}
/**
* @inheritDoc
*
* @see SnaMessageSubType#getSnaMessageType()
*/
@Override
public SnaMessage.Type getSnaMessageType() {
return SnaUpdateMessage.TYPE;
}
/**
* @inheritDoc
*
* @see KeysCollection#keys()
*/
@Override
public Set<TypedKey<?>> keys() {
return this.keys;
}
/**
* @inheritDoc
*
* @see KeysCollection#key(java.lang.String)
*/
@Override
public TypedKey<?> key(String key) {
TypedKey<?> typedKey = null;
Iterator<TypedKey<?>> iterator = this.keys.iterator();
while (iterator.hasNext()) {
typedKey = iterator.next();
if (typedKey.equals(key)) {
break;
}
typedKey = null;
}
return typedKey;
}
}
}