Search in sources :

Example 1 with ScopeAwareSetting

use of org.neo4j.graphdb.config.ScopeAwareSetting in project neo4j by neo4j.

the class Settings method advertisedAddress.

public static BaseSetting<AdvertisedSocketAddress> advertisedAddress(String name, Setting<ListenSocketAddress> listenAddressSetting) {
    return new ScopeAwareSetting<AdvertisedSocketAddress>() {

        @Override
        protected String provideName() {
            return name;
        }

        @Override
        public String getDefaultValue() {
            return default_advertised_address.getDefaultValue() + ":" + LISTEN_SOCKET_ADDRESS.apply(listenAddressSetting.getDefaultValue()).socketAddress().getPort();
        }

        @Override
        public AdvertisedSocketAddress from(Configuration config) {
            return config.get(this);
        }

        @Override
        public AdvertisedSocketAddress apply(Function<String, String> config) {
            ListenSocketAddress listenSocketAddress = listenAddressSetting.apply(config);
            String hostname = default_advertised_address.apply(config);
            int port = listenSocketAddress.socketAddress().getPort();
            String name = name();
            String value = config.apply(name);
            return SocketAddressFormat.socketAddress(name, value, hostname, port, AdvertisedSocketAddress::new);
        }

        @Override
        public void withScope(Function<String, String> scopingRule) {
            super.withScope(scopingRule);
            listenAddressSetting.withScope(scopingRule);
        }

        @Override
        public String valueDescription() {
            return ADVERTISED_SOCKET_ADDRESS.toString();
        }
    };
}
Also used : BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) Configuration(org.neo4j.graphdb.config.Configuration) ListenSocketAddress(org.neo4j.helpers.ListenSocketAddress) ScopeAwareSetting(org.neo4j.graphdb.config.ScopeAwareSetting) AdvertisedSocketAddress(org.neo4j.helpers.AdvertisedSocketAddress)

Example 2 with ScopeAwareSetting

use of org.neo4j.graphdb.config.ScopeAwareSetting in project neo4j by neo4j.

the class Settings method pathSetting.

public static Setting<File> pathSetting(String name, String defaultValue) {
    return new ScopeAwareSetting<File>() {

        @Override
        protected String provideName() {
            return name;
        }

        @Override
        public String getDefaultValue() {
            return defaultValue;
        }

        @Override
        public File from(Configuration config) {
            return config.get(this);
        }

        @Override
        public File apply(Function<String, String> config) {
            String value = config.apply(name());
            if (value == null) {
                value = defaultValue;
            }
            if (value == null) {
                return null;
            }
            String setting = fixSeparatorsInPath(value);
            File settingFile = new File(setting);
            if (settingFile.isAbsolute()) {
                return settingFile;
            } else {
                return new File(GraphDatabaseSettings.neo4j_home.apply(config), setting);
            }
        }

        @Override
        public String valueDescription() {
            return "A filesystem path; relative paths are resolved against the installation root, _<neo4j-home>_";
        }
    };
}
Also used : BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) Configuration(org.neo4j.graphdb.config.Configuration) ScopeAwareSetting(org.neo4j.graphdb.config.ScopeAwareSetting) File(java.io.File)

Aggregations

BiFunction (java.util.function.BiFunction)2 Function (java.util.function.Function)2 Configuration (org.neo4j.graphdb.config.Configuration)2 ScopeAwareSetting (org.neo4j.graphdb.config.ScopeAwareSetting)2 File (java.io.File)1 AdvertisedSocketAddress (org.neo4j.helpers.AdvertisedSocketAddress)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1