Skip to content

Commit 5e8888a

Browse files
committed
Migrated to annotated preferences in channel finder client
1 parent ee828ea commit 5e8888a

File tree

3 files changed

+45
-48
lines changed

3 files changed

+45
-48
lines changed

app/channel/channelfinder/src/main/java/org/phoebus/channelfinder/CFProperties.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

app/channel/channelfinder/src/main/java/org/phoebus/channelfinder/ChannelFinderClientImpl.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ public class ChannelFinderClientImpl implements ChannelFinderClient {
7373
private static final String resourceProperties = "resources/properties";
7474
private static final String resourceTags = "resources/tags";
7575

76-
77-
private static CFProperties properties = new CFProperties();
7876
private static final Logger log = Logger.getLogger(ChannelFinderClient.class.getName());
7977
/**
8078
* A Builder class to help create the client to the Channelfinder Service
@@ -105,7 +103,7 @@ public static class CFCBuilder {
105103

106104
private CFCBuilder()
107105
{
108-
this.uri = URI.create(properties.getPreferenceValue("serviceURL"));
106+
this.uri = URI.create(org.phoebus.channelfinder.Preferences.serviceURL);
109107
this.protocol = this.uri.getScheme();
110108
}
111109

@@ -259,9 +257,8 @@ public boolean verify(String hostname, SSLSession session) {
259257
}
260258
}
261259
if (this.withHTTPAuthentication) {
262-
this.httpBasicAuthFilter = new HTTPBasicAuthFilter(
263-
properties.getPreferenceValue("username"),
264-
properties.getPreferenceValue("password"));
260+
this.httpBasicAuthFilter = new HTTPBasicAuthFilter(org.phoebus.channelfinder.Preferences.username,
261+
org.phoebus.channelfinder.Preferences.password);
265262
}
266263

267264
return new ChannelFinderClientImpl(this.uri, this.clientConfig, this.httpBasicAuthFilter, this.executor);
@@ -278,7 +275,7 @@ public boolean verify(String hostname, SSLSession session) {
278275
cfAuthenticatedResource.addFilter(httpBasicAuthFilter);
279276
}
280277
// TODO add a preference to add logging
281-
if(Boolean.parseBoolean(properties.getPreferenceValue("rawFiltering"))) {
278+
if(org.phoebus.channelfinder.Preferences.rawFiltering) {
282279
client.addFilter(new RawLoggingFilter(Logger.getLogger(RawLoggingFilter.class.getName())));
283280
}
284281
this.executor = executor;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2024 European Spallation Source ERIC.
3+
*/
4+
5+
package org.phoebus.channelfinder;
6+
7+
import org.phoebus.framework.preferences.AnnotatedPreferences;
8+
import org.phoebus.framework.preferences.Preference;
9+
10+
/**
11+
* The {@link Preferences} object holds the properties associated with the
12+
* channel finder client library initialized using the channelfinder_preferences.properties
13+
* or default values.
14+
*
15+
* The order in which these files will be read. 1. properties file specified
16+
* using the system property <tt>channelfinder_preferences.properties</tt>. 2.
17+
* channelfinder_preferences.properties file in the users home direcotory. 3.
18+
* channelfinder_preferences.properties file in the C:/ on windows and /etc/ on linux. 4.
19+
* channelfinder_preferences.properties default file packaged with the library.
20+
*
21+
* @author shroffk
22+
*
23+
*/
24+
public class Preferences {
25+
26+
@Preference
27+
public static String serviceURL;
28+
29+
@Preference
30+
public static boolean rawFiltering;
31+
32+
@Preference
33+
public static String username;
34+
35+
@Preference
36+
public static String password;
37+
38+
static {
39+
AnnotatedPreferences.initialize(Preferences.class, "/channelfinder_preferences.properties");
40+
}
41+
}

0 commit comments

Comments
 (0)