3535import java .net .URI ;
3636import java .net .URISyntaxException ;
3737import java .net .UnknownHostException ;
38+ import java .util .Arrays ;
3839import java .util .Collections ;
3940import java .util .Date ;
4041import java .util .List ;
@@ -109,6 +110,12 @@ public class UdpStreamMonitor implements StreamMonitor {
109110
110111 public static final String METATYPE_NETWORK_INTERFACE = "networkInterface" ;
111112
113+ public static final String METATYPE_START_IMMEDIATELY = "startImmediately" ;
114+
115+ public static final String METATYPE_STREAM_ID = "streamId" ;
116+
117+ public static final String METATYPE_ADDITIONAL_PROPERTIES = "additionalProperties" ;
118+
112119 public static final String STREAM_ID = "streamId" ;
113120
114121 static final int MONITORED_PORT_MIN = 1 ;
@@ -428,38 +435,46 @@ public void updateCallback(Map<String, Object> properties) {
428435 LOGGER .debug ("--updateCallback-- properties={}" , properties );
429436 if (properties != null ) {
430437
431- if (! checkMetaTypeClass (properties , METATYPE_MONITORED_ADDRESS , String .class )) {
438+ if (isRequiredPropertyWrongType (properties , METATYPE_MONITORED_ADDRESS , String .class )) {
432439 return ;
433440 }
434441
435- if (properties .containsKey (METATYPE_NETWORK_INTERFACE )
436- && !checkMetaTypeClass (properties , METATYPE_NETWORK_INTERFACE , String .class )) {
442+ if (isOptionalPropertyWrongType (properties , METATYPE_NETWORK_INTERFACE , String .class )) {
437443 return ;
438444 }
439445
440- if (!checkMetaTypeClass (properties , METATYPE_BYTE_COUNT_ROLLOVER_CONDITION , Integer .class )) {
446+ if (isRequiredPropertyWrongType (
447+ properties , METATYPE_BYTE_COUNT_ROLLOVER_CONDITION , Integer .class )) {
448+ return ;
449+ }
450+ if (isRequiredPropertyWrongType (
451+ properties , METATYPE_ELAPSED_TIME_ROLLOVER_CONDITION , Long .class )) {
452+ return ;
453+ }
454+ if (isRequiredPropertyWrongType (properties , METATYPE_FILENAME_TEMPLATE , String .class )) {
441455 return ;
442456 }
443- if (! checkMetaTypeClass (properties , METATYPE_ELAPSED_TIME_ROLLOVER_CONDITION , Long .class )) {
457+ if (isRequiredPropertyWrongType (properties , METATYPE_PARENT_TITLE , String .class )) {
444458 return ;
445459 }
446- if (!checkMetaTypeClass (properties , METATYPE_FILENAME_TEMPLATE , String .class )) {
460+ if (isRequiredPropertyWrongType (
461+ properties , METATYPE_METACARD_UPDATE_INITIAL_DELAY , Long .class )) {
447462 return ;
448463 }
449- if (!checkMetaTypeClass (properties , METATYPE_PARENT_TITLE , String .class )) {
464+
465+ if (isOptionalPropertyWrongType (properties , METATYPE_DISTANCE_TOLERANCE , Double .class )) {
450466 return ;
451467 }
452- if (!checkMetaTypeClass (properties , METATYPE_METACARD_UPDATE_INITIAL_DELAY , Long .class )) {
468+
469+ if (isOptionalPropertyWrongType (properties , METATYPE_STREAM_ID , String .class )) {
453470 return ;
454471 }
455472
456- if (! checkMetaTypeClass (properties , METATYPE_TITLE , String .class )) {
473+ if (isRequiredPropertyWrongType (properties , METATYPE_START_IMMEDIATELY , Boolean .class )) {
457474 return ;
458475 }
459476
460- if (properties .containsKey (METATYPE_DISTANCE_TOLERANCE )
461- && properties .get (METATYPE_DISTANCE_TOLERANCE ) != null
462- && !checkMetaTypeClass (properties , METATYPE_DISTANCE_TOLERANCE , Double .class )) {
477+ if (isOptionalPropertyWrongType (properties , METATYPE_ADDITIONAL_PROPERTIES , String [].class )) {
463478 return ;
464479 }
465480
@@ -473,22 +488,31 @@ public void updateCallback(Map<String, Object> properties) {
473488 setMetacardUpdateInitialDelay ((Long ) properties .get (METATYPE_METACARD_UPDATE_INITIAL_DELAY ));
474489 setParentTitle ((String ) properties .get (METATYPE_PARENT_TITLE ));
475490 setDistanceTolerance ((Double ) properties .get (METATYPE_DISTANCE_TOLERANCE ));
491+ setStreamId ((String ) properties .get (METATYPE_STREAM_ID ));
492+ setStartImmediately ((Boolean ) properties .get (METATYPE_START_IMMEDIATELY ));
493+ setAdditionalProperties (
494+ Arrays .asList ((String []) properties .get (METATYPE_ADDITIONAL_PROPERTIES )));
476495
477496 init ();
478497 }
479498 }
480499
481- private boolean checkMetaTypeClass (
500+ private boolean isOptionalPropertyWrongType (
482501 Map <String , Object > properties , String fieldName , Class <?> clazz ) {
483- if (! properties .containsKey (fieldName )) {
484- LOGGER .debug ("the metatype id {} field was null" , fieldName );
502+ if (properties .get (fieldName ) == null ) {
503+ LOGGER .debug ("the metatype id {} field was null, but the field is optional " , fieldName );
485504 return false ;
486505 }
506+ return isRequiredPropertyWrongType (properties , fieldName , clazz );
507+ }
508+
509+ private boolean isRequiredPropertyWrongType (
510+ Map <String , Object > properties , String fieldName , Class <?> clazz ) {
487511 if (!clazz .isInstance (properties .get (fieldName ))) {
488512 LOGGER .debug ("the metatype id {} field should be type {}" , fieldName , clazz );
489- return false ;
513+ return true ;
490514 }
491- return true ;
515+ return false ;
492516 }
493517
494518 public String getMonitoredAddress () {
@@ -577,7 +601,7 @@ private Optional<Pair<NetworkInterface, InetAddress>> findLocalAddress(String in
577601
578602 if (networkIntf != null ) {
579603 return Collections .list (networkIntf .getInetAddresses ()).stream ()
580- .filter (inetAddress -> inetAddress instanceof Inet4Address )
604+ .filter (Inet4Address . class :: isInstance )
581605 .map (inetAddress -> create (networkIntf , inetAddress ))
582606 .findFirst ();
583607 }
0 commit comments