-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft of metadata API with timestamp tracking capabilities.
Signed-off-by: Łukasz Dywicki <[email protected]>
- Loading branch information
Showing
24 changed files
with
1,002 additions
and
378 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
plc4j/api/src/main/java/org/apache/plc4x/java/api/messages/PlcMetadataKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.plc4x.java.api.messages; | ||
|
||
import org.apache.plc4x.java.api.metadata.Metadata.Key; | ||
import org.apache.plc4x.java.api.metadata.time.TimeSource; | ||
|
||
/** | ||
* High level definition of common metadata keys which can occur across multiple drivers. | ||
*/ | ||
public interface PlcMetadataKeys { | ||
|
||
Key<Long> TIMESTAMP = Key.of("timestamp", Long.class); | ||
Key<TimeSource> TIMESTAMP_SOURCE = Key.of("timestamp_source", TimeSource.class); | ||
|
||
Key<Long> RECEIVE_TIMESTAMP = Key.of("receive_timestamp", Long.class); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
plc4j/api/src/main/java/org/apache/plc4x/java/api/metadata/Metadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.plc4x.java.api.metadata; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public interface Metadata { | ||
|
||
Metadata EMPTY = new Metadata() { | ||
@Override | ||
public Set<Key<?>> keys() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Map<Key<?>, Object> entries() { | ||
return Map.of(); | ||
} | ||
|
||
@Override | ||
public Object getValue(Key<?> key) { | ||
return null; | ||
} | ||
|
||
}; | ||
|
||
class Key<T> { | ||
|
||
private final String key; | ||
private final Class<T> type; | ||
|
||
protected Key(String key, Class<T> type) { | ||
this.key = key; | ||
this.type = type; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public boolean validate(Object value) { | ||
return type.isInstance(value); | ||
} | ||
|
||
public static <T> Key<T> of(String key, Class<T> type) { | ||
return new Key<>(key, type); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof Key)) { | ||
return false; | ||
} | ||
Key<?> key1 = (Key<?>) o; | ||
return Objects.equals(getKey(), key1.getKey()) && Objects.equals(type, key1.type); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getKey(), type); | ||
} | ||
} | ||
|
||
Set<Key<?>> keys(); | ||
Map<Key<?>, Object> entries(); | ||
Object getValue(Key<?> key); | ||
} |
33 changes: 33 additions & 0 deletions
33
plc4j/api/src/main/java/org/apache/plc4x/java/api/metadata/time/TimeSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.plc4x.java.api.metadata.time; | ||
|
||
public enum TimeSource { | ||
|
||
// Time information is assumed by PLC4X itself | ||
ASSUMPTION, | ||
// Time comes from software layer, kernel driver and similar | ||
SOFTWARE, | ||
// Time can is confronted through hardware i.e. microcontroller | ||
HARDWARE, | ||
// Other source of time which fall into separate truthiness category | ||
OTHER | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/OpcMetadataKeys.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.plc4x.java.opcua; | ||
|
||
import org.apache.plc4x.java.api.metadata.Metadata; | ||
import org.apache.plc4x.java.api.metadata.Metadata.Key; | ||
import org.apache.plc4x.java.opcua.tag.OpcuaQualityStatus; | ||
|
||
/** | ||
* OPC UA level metadata keys. | ||
*/ | ||
public interface OpcMetadataKeys { | ||
|
||
Key<OpcuaQualityStatus> QUALITY = Metadata.Key.of("opcua_quality", OpcuaQualityStatus.class); | ||
|
||
Key<Long> SERVER_TIMESTAMP = Metadata.Key.of("opcua_server_timestamp", Long.class); | ||
Key<Long> SOURCE_TIMESTAMP = Metadata.Key.of("opcua_source_timestamp", Long.class); | ||
|
||
} |
Oops, something went wrong.