1
1
package com .aol .micro .server .application .registry ;
2
2
3
3
import java .text .SimpleDateFormat ;
4
- import java .util .Date ;
5
- import java .util .List ;
6
- import java .util .Map ;
7
- import java .util .UUID ;
4
+ import java .util .*;
8
5
6
+ import javax .ws .rs .QueryParam ;
9
7
import javax .xml .bind .annotation .XmlAccessType ;
10
8
import javax .xml .bind .annotation .XmlAccessorType ;
11
9
import javax .xml .bind .annotation .XmlRootElement ;
14
12
import lombok .AccessLevel ;
15
13
import lombok .Builder ;
16
14
import lombok .Getter ;
15
+ import lombok .ToString ;
17
16
import lombok .experimental .FieldDefaults ;
18
17
import lombok .experimental .Wither ;
19
18
24
23
@ Getter
25
24
@ Wither
26
25
@ Builder
26
+ @ ToString
27
27
public class RegisterEntry {
28
28
29
- private static SimpleDateFormat f = new SimpleDateFormat (
30
- "EEE, d MMM yyyy HH:mm:ss Z" );
29
+ private static SimpleDateFormat f = new SimpleDateFormat ("EEE, d MMM yyyy HH:mm:ss Z" );
31
30
@ Wither
32
- int port ;
31
+ private final int port ;
33
32
@ Wither
34
- String hostname ;
33
+ private final String hostname ;
35
34
@ Wither
36
- String module ;
35
+ private final String module ;
37
36
@ Wither
38
- String context ;
39
- Date time ;
37
+ private final String context ;
38
+ private final Date time ;
40
39
@ Wither
41
- String uuid ;
40
+ private final String uuid ;
42
41
@ Wither
43
- String target ;
44
- String formattedDate ;
45
- Map <String , String > manifest = ManifestLoader . instance . getManifest ();
42
+ private final String target ;
43
+ private final String formattedDate ;
44
+ private final Map <String , String > manifest = new HashMap <> ();
46
45
@ Wither
47
- Health health ;
46
+ private final Health health ;
48
47
@ Wither
49
- List <Map <String , Map <String , String >>> stats ;
48
+ private final List <Map <String , Map <String , String >>> stats ;
50
49
@ Wither
51
- int externalPort ;
50
+ private final int externalPort ;
52
51
53
52
public RegisterEntry () {
54
- this (
55
- -1 , null , null , null , null , null , null , -1 );
53
+ this (-1 , null , null , null , null , null , null , -1 );
56
54
}
57
55
58
56
public RegisterEntry (int port , String hostname , String module , String context , Date time , String uuid ,
59
- String target , int externalPort ) {
60
- this (
61
- port , hostname , module , context , time , UUID .randomUUID ()
62
- .toString (),
63
- target , null , Health .OK , null , externalPort );
57
+ String target , int externalPort ) {
58
+ this (port , hostname , module , context , time , uuid , target , null , Health .OK , null , externalPort );
59
+ }
60
+
61
+ public RegisterEntry (int port , String hostname , String module , String context , Date time , String target ,
62
+ int externalPort ) {
63
+ this (port , hostname , module , context , time , UUID .randomUUID ().toString (), target , externalPort );
64
64
}
65
65
66
66
private RegisterEntry (int port , String hostname , String module , String context , Date time , String uuid ,
@@ -82,14 +82,28 @@ private RegisterEntry(int port, String hostname, String module, String context,
82
82
else
83
83
this .formattedDate = null ;
84
84
85
+ this .manifest .putAll (ManifestLoader .instance .getManifest ());
86
+
85
87
}
86
88
87
- public RegisterEntry (int port , String hostname , String module , String context , Date time , String target ,
88
- int externalPort ) {
89
- this (
90
- port , hostname , module , context , time , UUID .randomUUID ()
91
- .toString (),
92
- target , externalPort );
89
+ public boolean matches (RegisterEntry re ) {
90
+ //Only the fields which make sense to query is added for now.
91
+ return (re .port == -1 || re .port == port ) &&
92
+ (Objects .isNull (re .hostname ) || Objects .nonNull (hostname ) && hostname .startsWith (re .hostname )) &&
93
+ (Objects .isNull (re .module ) || Objects .nonNull (module ) && module .startsWith (re .module )) &&
94
+ (Objects .isNull (re .context ) || Objects .nonNull (context ) && context .startsWith (re .context )) &&
95
+ (Objects .isNull (re .health ) || re .health .equals (health )) &&
96
+ (re .externalPort == -1 || re .externalPort == externalPort ) &&
97
+ (Objects .isNull (re .manifest ) || re .manifest .isEmpty () || matchManifest (re .manifest ));
98
+ }
99
+
100
+ private boolean matchManifest (Map <String , String > manifest ) {
101
+ return match (manifest , this .manifest , "Implementation-revision" ) &&
102
+ match (manifest , this .manifest , "Implementation-Timestamp" ) &&
103
+ match (manifest , this .manifest , "Implementation-Version" );
93
104
}
94
105
95
- }
106
+ private boolean match (Map <String , String > map1 , Map <String , String > map2 , String key ) {
107
+ return !map1 .containsKey (key ) || (map2 .containsKey (key ) && map2 .get (key ).startsWith (map1 .get (key )));
108
+ }
109
+ }
0 commit comments