Search in sources :

Example 1 with ConfigInterruptedException

use of com.yahoo.config.subscription.ConfigInterruptedException in project vespa by vespa-engine.

the class FileConfigSubscription method nextConfig.

@Override
public boolean nextConfig(long timeout) {
    if (!file.exists() && !file.isFile())
        throw new IllegalArgumentException("Not a file: " + file);
    if (checkReloaded()) {
        log.log(LogLevel.DEBUG, "User forced config reload at " + System.currentTimeMillis());
        // User forced reload
        setConfigIfChanged(updateConfig());
        ConfigState<T> configState = getConfigState();
        log.log(LogLevel.DEBUG, "Config updated at " + System.currentTimeMillis() + ", changed: " + configState.isConfigChanged());
        log.log(LogLevel.DEBUG, "Config: " + configState.getConfig().toString());
        return true;
    }
    if (file.lastModified() != ts) {
        setConfigIncGen(updateConfig());
        return true;
    }
    try {
        Thread.sleep(timeout);
    } catch (InterruptedException e) {
        throw new ConfigInterruptedException(e);
    }
    return false;
}
Also used : ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException)

Example 2 with ConfigInterruptedException

use of com.yahoo.config.subscription.ConfigInterruptedException in project vespa by vespa-engine.

the class JarConfigSubscription method nextConfig.

@Override
public boolean nextConfig(long timeout) {
    if (checkReloaded()) {
        // Not supporting changing the payload for jar
        return true;
    }
    if (zipEntry == null) {
        // First time polled
        JarFile jarFile = null;
        try {
            jarFile = new JarFile(jarName);
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
        zipEntry = getEntry(jarFile, path);
        if (zipEntry == null)
            throw new IllegalArgumentException("Config '" + key.getName() + "' not found in '" + jarName + "!/" + path + "'.");
        T config = null;
        try {
            ConfigPayload payload = new CfgConfigPayloadBuilder().deserialize(Arrays.asList(IOUtils.readAll(new InputStreamReader(jarFile.getInputStream(zipEntry), "UTF-8")).split("\n")));
            config = payload.toInstance(configClass, key.getConfigId());
        } catch (UnsupportedEncodingException e) {
            throw new IllegalStateException(e);
        } catch (IOException e) {
            throw new ConfigurationRuntimeException(e);
        }
        setConfig(0L, config);
        try {
            jarFile.close();
        } catch (IOException e) {
            throw new ConfigurationRuntimeException(e);
        }
        return true;
    }
    // TODO: Should wait and detect changes
    try {
        Thread.sleep(timeout);
    } catch (InterruptedException e) {
        throw new ConfigInterruptedException(e);
    }
    return false;
}
Also used : CfgConfigPayloadBuilder(com.yahoo.config.subscription.CfgConfigPayloadBuilder) ConfigurationRuntimeException(com.yahoo.config.ConfigurationRuntimeException) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) InputStreamReader(java.io.InputStreamReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException)

Example 3 with ConfigInterruptedException

use of com.yahoo.config.subscription.ConfigInterruptedException in project vespa by vespa-engine.

the class RawConfigSubscription method nextConfig.

@Override
public boolean nextConfig(long timeout) {
    if (checkReloaded()) {
        return true;
    }
    if (payload == null) {
        payload = inputPayload;
        ConfigPayload configPayload = new CfgConfigPayloadBuilder().deserialize(Arrays.asList(payload.split("\n")));
        setConfig(0L, configPayload.toInstance(configClass, key.getConfigId()));
        return true;
    }
    try {
        Thread.sleep(timeout);
    } catch (InterruptedException e) {
        throw new ConfigInterruptedException(e);
    }
    return false;
}
Also used : CfgConfigPayloadBuilder(com.yahoo.config.subscription.CfgConfigPayloadBuilder) ConfigPayload(com.yahoo.vespa.config.ConfigPayload) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException)

Example 4 with ConfigInterruptedException

use of com.yahoo.config.subscription.ConfigInterruptedException in project vespa by vespa-engine.

the class JRTConfigSubscription method subscribe.

@Override
public boolean subscribe(long timeout) {
    lastOK = System.currentTimeMillis();
    requester = getRequester();
    requester.request(this);
    JRTClientConfigRequest req = reqQueue.peek();
    while (req == null && (System.currentTimeMillis() - lastOK <= timeout)) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            throw new ConfigInterruptedException(e);
        }
        req = reqQueue.peek();
    }
    return req != null;
}
Also used : JRTClientConfigRequest(com.yahoo.vespa.config.protocol.JRTClientConfigRequest) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException) ConfigInterruptedException(com.yahoo.config.subscription.ConfigInterruptedException)

Aggregations

ConfigInterruptedException (com.yahoo.config.subscription.ConfigInterruptedException)4 CfgConfigPayloadBuilder (com.yahoo.config.subscription.CfgConfigPayloadBuilder)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)2 ConfigurationRuntimeException (com.yahoo.config.ConfigurationRuntimeException)1 JRTClientConfigRequest (com.yahoo.vespa.config.protocol.JRTClientConfigRequest)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 JarFile (java.util.jar.JarFile)1