Exemplo n.º 1
0
  /**
   * {@inheritDoc}
   *
   * @see net.sf.hajdbc.util.concurrent.Registry#get(java.lang.Object, java.lang.Object)
   */
  @Override
  public V get(K key, C context) throws E {
    RegistryEntry entry = this.store.get(key);

    if (entry != null) {
      return entry.getValue();
    }

    V value = this.factory.create(key, context);

    entry = new RegistryEntry(value);

    RegistryEntry existing = this.store.setIfAbsent(key, entry);

    if (existing != null) {
      return existing.getValue();
    }

    try {
      value.start();

      entry.started();

      return value;
    } catch (Exception e) {
      this.store.clear(key);

      try {
        value.stop();
      } catch (Exception re) {
        this.logger.log(Level.INFO, re);
      }

      throw this.exceptionFactory.createException(e);
    }
  }