Skip to content
Permalink
Browse files

Minor protocol update

  • Loading branch information...
richturner committed Aug 13, 2019
1 parent 5fa6f7a commit 341318f837e595c777c47871a84fa901760c926e
@@ -112,19 +112,12 @@ protected void setCurrentConnectionStatus(ConnectionStatus currentConnectionStat
protected final Map<AttributeRef, AssetAttribute> linkedAttributes = new HashMap<>();
protected final Map<AttributeRef, LinkedProtocolInfo> linkedProtocolConfigurations = new HashMap<>();
protected final Map<AttributeRef, ValueFilter[]> linkedAttributeFilters = new HashMap<>();
protected static final List<MetaItemDescriptor> attributeMetaItemDescriptors;
protected MessageBrokerContext messageBrokerContext;
protected ProducerTemplate producerTemplate;
protected TimerService timerService;
protected ProtocolExecutorService executorService;
protected ProtocolAssetService assetService;

static {
attributeMetaItemDescriptors = Arrays.asList(
MetaItemType.VALUE_FILTERS
);
}

@Override
public int getPriority() {
return PRIORITY;
@@ -420,7 +413,7 @@ final public ProtocolDescriptor getProtocolDescriptor() {

@Override
public AssetAttribute getProtocolConfigurationTemplate() {
return ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute(), getProtocolName());
return ProtocolConfiguration.initProtocolConfiguration(new AssetAttribute("protocolConfig"), getProtocolName());
}

@Override
@@ -466,9 +459,7 @@ public String toString() {
* Get list of {@link MetaItemDescriptor}s that describe the {@link MetaItem}s an {@link Attribute} linked to this
* protocol supports
*/
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
return attributeMetaItemDescriptors;
}
abstract protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors();

/**
* Link the protocol configuration.
@@ -22,6 +22,7 @@
import org.apache.commons.codec.binary.BinaryCodec;
import org.apache.commons.codec.binary.Hex;
import org.openremote.agent.protocol.http.OAuthGrant;
import org.openremote.agent.protocol.websocket.WebsocketClientProtocol;
import org.openremote.model.value.*;
import org.openremote.container.Container;
import org.openremote.container.ContainerService;
@@ -43,9 +44,12 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.openremote.agent.protocol.http.HttpClientProtocol.PROTOCOL_NAME;
import static org.openremote.model.Constants.PROTOCOL_NAMESPACE;
import static org.openremote.model.attribute.MetaItemDescriptor.Access.ACCESS_PRIVATE;
import static org.openremote.model.attribute.MetaItemDescriptorImpl.*;
import static org.openremote.model.attribute.MetaItemDescriptorImpl.metaItemString;
import static org.openremote.model.util.TextUtil.REGEXP_PATTERN_STRING_NON_EMPTY;

/**
* A protocol is a thread-safe singleton {@link ContainerService} that connects devices and
@@ -180,6 +184,27 @@
false,
null);


/**
* Basic authentication username (string)
*/
MetaItemDescriptor META_PROTOCOL_USERNAME = metaItemString(
PROTOCOL_NAMESPACE + ":username",
ACCESS_PRIVATE,
false,
REGEXP_PATTERN_STRING_NON_EMPTY,
PatternFailure.STRING_EMPTY);

/**
* Basic authentication password (string)
*/
MetaItemDescriptor META_PROTOCOL_PASSWORD = metaItemString(
PROTOCOL_NAMESPACE + ":password",
ACCESS_PRIVATE,
false,
REGEXP_PATTERN_STRING_NON_EMPTY,
PatternFailure.STRING_EMPTY);

/**
* Value to be used for attribute writes, protocols that support this should also support dynamic value insertion,
* see interface javadoc for more details; use the {@link #createDynamicAttributeWriteConsumer} helper method where
@@ -197,9 +197,7 @@ public void init(Container container) throws Exception {

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -90,13 +90,13 @@
* the response received from this endpoint</b>)</li> <li>{@link #META_QUERY_PARAMETERS}</li>
* <li>{@link #META_FAILURE_CODES}</li>
* <li>{@link #META_HEADERS}</li>
* <li>{@link MetaItemType#META_VALUE_FILTERS}</li>
* <li>{@link MetaItemType#VALUE_FILTERS}</li>
* </ul>
* <p>
* <h1>Response filtering</h1>
* <p>
* Any {@link Attribute} whose value is to be set by the HTTP server response (i.e. it has an {@link
* #META_POLLING_MILLIS} {@link MetaItem}) can use the standard {@link MetaItemType#META_VALUE_FILTERS} in
* #META_POLLING_MILLIS} {@link MetaItem}) can use the standard {@link MetaItemType#VALUE_FILTERS} in
* order to filter the received HTTP response.
* <p>
* <h1>Connection Status</h1>
@@ -355,24 +355,6 @@ public Response build() {
REGEXP_PATTERN_STRING_NON_EMPTY,
MetaItemDescriptor.PatternFailure.STRING_EMPTY);

/**
* Basic authentication username (string)
*/
public static final MetaItemDescriptor META_PROTOCOL_USERNAME = metaItemString(
PROTOCOL_NAME + ":username",
ACCESS_PRIVATE,
false,
REGEXP_PATTERN_STRING_NON_EMPTY);
/**
* Basic authentication password (string)
*/
public static final MetaItemDescriptor META_PROTOCOL_PASSWORD = metaItemString(
PROTOCOL_NAME + ":password",
ACCESS_PRIVATE,
false,
REGEXP_PATTERN_STRING_NON_EMPTY,
MetaItemDescriptor.PatternFailure.STRING_EMPTY);

/**
* Relative path to endpoint that should be used for connection status ping (string)
*/
@@ -1032,9 +1014,7 @@ public String getVersion() {

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -199,9 +199,7 @@ public AttributeValidationResult validateProtocolConfiguration(AssetAttribute pr

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -173,9 +173,7 @@ public AttributeValidationResult validateProtocolConfiguration(AssetAttribute pr

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -190,9 +190,7 @@ public String getVersion() {

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -141,9 +141,7 @@ public AttributeValidationResult validateProtocolConfiguration(AssetAttribute pr

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -271,7 +271,6 @@ protected AttributeInfo(AttributeRef attributeRef, int retries, int responseTime

public static final List<MetaItemDescriptor> ATTRIBUTE_META_ITEM_DESCRIPTORS = Arrays.asList(
META_ATTRIBUTE_WRITE_VALUE,
MetaItemType.VALUE_FILTERS,
META_POLLING_MILLIS,
META_RESPONSE_TIMEOUT_MILLIS,
META_SEND_RETRIES,
@@ -118,9 +118,7 @@ public String getVersion() {

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -124,26 +124,6 @@
PatternFailure.STRING_EMPTY
);

/**
* Basic authentication username (string)
*/
public static final MetaItemDescriptor META_PROTOCOL_USERNAME = metaItemString(
PROTOCOL_NAME + ":username",
ACCESS_PRIVATE,
false,
REGEXP_PATTERN_STRING_NON_EMPTY,
PatternFailure.STRING_EMPTY);

/**
* Basic authentication password (string)
*/
public static final MetaItemDescriptor META_PROTOCOL_PASSWORD = metaItemString(
PROTOCOL_NAME + ":password",
ACCESS_PRIVATE,
false,
REGEXP_PATTERN_STRING_NON_EMPTY,
PatternFailure.STRING_EMPTY);

/**
* Headers for websocket connect call (see {@link HttpClientProtocol#META_HEADERS} for details)
*/
@@ -193,7 +173,8 @@
public static final List<MetaItemDescriptor> ATTRIBUTE_META_ITEM_DESCRIPTORS = Arrays.asList(
META_ATTRIBUTE_MESSAGE_MATCH_FILTERS,
META_ATTRIBUTE_MESSAGE_MATCH_PREDICATE,
META_ATTRIBUTE_WRITE_VALUE);
META_ATTRIBUTE_WRITE_VALUE,
META_SUBSCRIPTIONS);

public static final List<MetaItemDescriptor> PROTOCOL_META_ITEM_DESCRIPTORS = Arrays.asList(
META_PROTOCOL_CONNECT_URI,
@@ -203,6 +184,7 @@
META_PROTOCOL_OAUTH_GRANT,
META_SUBSCRIPTIONS);

public static final int CONNECTED_SEND_DELAY_MILLIS = 2000;
protected ResteasyClient client;
protected Map<AttributeRef, WebsocketClient> websocketClients = new HashMap<>();
protected Map<AttributeRef, List<Pair<AttributeRef, Consumer<String>>>> protocolMessageConsumers = new HashMap<>();
@@ -490,9 +472,7 @@ public String getVersion() {

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
List<MetaItemDescriptor> descriptors = new ArrayList<>(super.getLinkedAttributeMetaItemDescriptors());
descriptors.addAll(ATTRIBUTE_META_ITEM_DESCRIPTORS);
return descriptors;
return new ArrayList<>(ATTRIBUTE_META_ITEM_DESCRIPTORS);
}

@Override
@@ -542,7 +522,7 @@ protected void onClientConnectionStatusChanged(AttributeRef protocolRef, Connect
}
if (connectedTasks != null) {
// Execute after a delay to ensure connection is properly initialised
executorService.schedule(() -> connectedTasks.forEach(Runnable::run), 500);
executorService.schedule(() -> connectedTasks.forEach(Runnable::run), CONNECTED_SEND_DELAY_MILLIS);
}
}
}
@@ -22,6 +22,7 @@
import org.apache.commons.io.IOUtils;
import org.openremote.agent.protocol.simulator.SimulatorProtocol;
import org.openremote.container.Container;
import org.openremote.container.util.UniqueIdentifierGenerator;
import org.openremote.manager.security.UserConfiguration;
import org.openremote.manager.setup.AbstractManagerSetup;
import org.openremote.model.asset.Asset;
@@ -78,7 +79,7 @@
public String smartBuildingId;
public String apartment1Id;
public String apartment1ServiceAgentId;
public String apartment1LivingroomId;
public String apartment1LivingroomId = UniqueIdentifierGenerator.generateId("apartment1LivingroomId");
public String apartment1KitchenId;
public String apartment1HallwayId;
public String apartment1Bedroom1Id;
@@ -469,6 +470,7 @@ public void onStart() throws Exception {
new MetaItem(SimulatorProtocol.SIMULATOR_ELEMENT, Values.create(NumberSimulatorElement.ELEMENT_NAME))
});

apartment1Livingroom.setId(apartment1LivingroomId);
apartment1Livingroom = assetStorageService.merge(apartment1Livingroom);
apartment1LivingroomId = apartment1Livingroom.getId();

@@ -46,7 +46,7 @@

@Override
protected List<MetaItemDescriptor> getLinkedAttributeMetaItemDescriptors() {
return super.getLinkedAttributeMetaItemDescriptors();
return Collections.emptyList();
}

@Override

0 comments on commit 341318f

Please sign in to comment.
You can’t perform that action at this time.