Search in sources :

Example 1 with CfgConfigPayloadBuilder

use of com.yahoo.config.subscription.CfgConfigPayloadBuilder 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 2 with CfgConfigPayloadBuilder

use of com.yahoo.config.subscription.CfgConfigPayloadBuilder 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)

Aggregations

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