Example #1
0
 /**
  * Constructs a new instance for managing the given services.
  *
  * @param services The services to manage
  * @throws IllegalArgumentException if not all services are {@linkplain State#NEW new} or if there
  *     are any duplicate services.
  */
 public ServiceManager(Iterable<? extends Service> services) {
   ImmutableList<Service> copy = ImmutableList.copyOf(services);
   if (copy.isEmpty()) {
     // Having no services causes the manager to behave strangely. Notably, listeners are never
     // fired.  To avoid this we substitute a placeholder service.
     logger.log(
         Level.WARNING,
         "ServiceManager configured with no services.  Is your application configured properly?",
         new EmptyServiceManagerWarning());
     copy = ImmutableList.<Service>of(new NoOpService());
   }
   this.state = new ServiceManagerState(copy);
   this.services = copy;
   WeakReference<ServiceManagerState> stateReference =
       new WeakReference<ServiceManagerState>(state);
   for (Service service : copy) {
     service.addListener(new ServiceListener(service, stateReference), directExecutor());
     // We check the state after adding the listener as a way to ensure that our listener was added
     // to a NEW service.
     checkArgument(service.state() == NEW, "Can only manage NEW services, %s", service);
   }
   // We have installed all of our listeners and after this point any state transition should be
   // correct.
   this.state.markReady();
 }
Example #2
0
public enum FaultLevel {
  __unsmnp__, // ordinal 0 doesn't map to SNMP enumerations
  INFO,
  WARN,
  ERROR,
  FATAL;

  static final List<FaultLevel> values = ImmutableList.copyOf(values());

  public static final FaultLevel valueOf(int ordinal) {
    checkArgument(ordinal > __unsmnp__.ordinal() && ordinal < values.size());
    return values.get(ordinal);
  }
}
Example #3
0
  /**
   * Creates a CacheBuilderSpec from a string.
   *
   * @param cacheBuilderSpecification the string form
   */
  public static CacheBuilderSpec parse(String cacheBuilderSpecification) {
    CacheBuilderSpec spec = new CacheBuilderSpec(cacheBuilderSpecification);
    if (!cacheBuilderSpecification.isEmpty()) {
      for (String keyValuePair : KEYS_SPLITTER.split(cacheBuilderSpecification)) {
        List<String> keyAndValue = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyValuePair));
        checkArgument(!keyAndValue.isEmpty(), "blank key-value pair");
        checkArgument(
            keyAndValue.size() <= 2,
            "key-value pair %s with more than one equals sign",
            keyValuePair);

        // Find the ValueParser for the current key.
        String key = keyAndValue.get(0);
        ValueParser valueParser = VALUE_PARSERS.get(key);
        checkArgument(valueParser != null, "unknown key %s", key);

        String value = keyAndValue.size() == 1 ? null : keyAndValue.get(1);
        valueParser.parse(spec, key, value);
      }
    }

    return spec;
  }
Example #4
0
 TypeVariableImpl(D genericDeclaration, String name, Type[] bounds) {
   disallowPrimitiveType(bounds, "bound for type variable");
   this.genericDeclaration = checkNotNull(genericDeclaration);
   this.name = checkNotNull(name);
   this.bounds = ImmutableList.copyOf(bounds);
 }