ResourceConfigSupplier.java

  1. /*
  2.  * Copyright 2016,2017 Providence Authors
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements. See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership. The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License. You may obtain a copy of the License at
  11.  *
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  *
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied. See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  */
  21. package net.morimekta.providence.config.impl;

  22. import net.morimekta.providence.PMessage;
  23. import net.morimekta.providence.config.parser.ConfigException;
  24. import net.morimekta.providence.config.parser.ConfigParser;

  25. import javax.annotation.Nonnull;
  26. import java.nio.file.Path;
  27. import java.time.Clock;

  28. /**
  29.  * A supplier to get a config (aka message) from a providence config. This is
  30.  * essentially the initiator for the config. It will always have a config
  31.  * message instance, and will log (error) if it later fails to load an updated
  32.  * config.
  33.  */
  34. public class ResourceConfigSupplier<Message extends PMessage<Message>>
  35.         extends FixedConfigSupplier<Message> {
  36.     private final Path resourcePath;

  37.     public ResourceConfigSupplier(@Nonnull Path resourcePath,
  38.                                   @Nonnull ConfigParser configParser,
  39.                                   @Nonnull Clock clock)
  40.             throws ConfigException {
  41.         super(configParser.<Message>parseConfig(resourcePath, null).first,
  42.               clock.millis(), clock);
  43.         this.resourcePath = resourcePath;
  44.     }

  45.     @Override
  46.     public String toString() {
  47.         return "ResourceConfig{" + resourcePath + "}";
  48.     }

  49.     @Override
  50.     public String getName() {
  51.         return "ResourceConfig{" + resourcePath.getFileName() + "}";
  52.     }
  53. }