net.sf.ehcache.Status Java Examples

The following examples show how to use net.sf.ehcache.Status. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EhCacheDataCache.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TableModel get( final DataCacheKey key ) {
  final Cache cache = this.cache;
  synchronized ( this ) {
    if ( cache == null ) {
      return null;
    }

    if ( cache.getStatus() != Status.STATUS_ALIVE ) {
      this.cache = null;
      return null;
    }
  }

  final Element element = cache.get( key );
  if ( element == null ) {
    return null;
  }
  return (TableModel) element.getObjectValue();
}
 
Example #2
Source File: InstrumentedEhCacheCacheManager.java    From kylin-on-parquet-v2 with Apache License 2.0 6 votes vote down vote up
@Override
protected Collection<Cache> loadCaches() {
    Assert.notNull(this.cacheManager, "A backing EhCache CacheManager is required");
    Status status = this.cacheManager.getStatus();
    Assert.isTrue(Status.STATUS_ALIVE.equals(status),
            "An 'alive' EhCache CacheManager is required - current cache is " + status.toString());

    String[] names = this.cacheManager.getCacheNames();
    Collection<Cache> caches = Sets.newLinkedHashSetWithExpectedSize(names.length);
    for (String name : names) {
        if (enableMetrics) {
            caches.add(new InstrumentedEhCacheCache(this.cacheManager.getEhcache(name)));
        } else {
            caches.add(new EhCacheCache(this.cacheManager.getEhcache(name)));
        }
    }
    return caches;
}
 
Example #3
Source File: EhCacheCacheManager.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
protected Collection<Cache> loadCaches() {
	net.sf.ehcache.CacheManager cacheManager = getCacheManager();
	Assert.state(cacheManager != null, "No CacheManager set");

	Status status = cacheManager.getStatus();
	if (!Status.STATUS_ALIVE.equals(status)) {
		throw new IllegalStateException(
				"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
	}

	String[] names = getCacheManager().getCacheNames();
	Collection<Cache> caches = new LinkedHashSet<>(names.length);
	for (String name : names) {
		caches.add(new EhCacheCache(getCacheManager().getEhcache(name)));
	}
	return caches;
}
 
Example #4
Source File: InstrumentedEhCacheCacheManager.java    From kylin with Apache License 2.0 6 votes vote down vote up
@Override
protected Collection<Cache> loadCaches() {
    Assert.notNull(this.cacheManager, "A backing EhCache CacheManager is required");
    Status status = this.cacheManager.getStatus();
    Assert.isTrue(Status.STATUS_ALIVE.equals(status),
            "An 'alive' EhCache CacheManager is required - current cache is " + status.toString());

    String[] names = this.cacheManager.getCacheNames();
    Collection<Cache> caches = Sets.newLinkedHashSetWithExpectedSize(names.length);
    for (String name : names) {
        if (enableMetrics) {
            caches.add(new InstrumentedEhCacheCache(this.cacheManager.getEhcache(name)));
        } else {
            caches.add(new EhCacheCache(this.cacheManager.getEhcache(name)));
        }
    }
    return caches;
}
 
Example #5
Source File: EhCacheCacheManager.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
protected Collection<Cache> loadCaches() {
	net.sf.ehcache.CacheManager cacheManager = getCacheManager();
	Assert.state(cacheManager != null, "No CacheManager set");

	Status status = cacheManager.getStatus();
	if (!Status.STATUS_ALIVE.equals(status)) {
		throw new IllegalStateException(
				"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
	}

	String[] names = getCacheManager().getCacheNames();
	Collection<Cache> caches = new LinkedHashSet<>(names.length);
	for (String name : names) {
		caches.add(new EhCacheCache(getCacheManager().getEhcache(name)));
	}
	return caches;
}
 
Example #6
Source File: EhCacheCache.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create an {@link EhCacheCache} instance.
 * @param ehcache backing Ehcache instance
 */
public EhCacheCache(Ehcache ehcache) {
	Assert.notNull(ehcache, "Ehcache must not be null");
	Status status = ehcache.getStatus();
	Assert.isTrue(Status.STATUS_ALIVE.equals(status),
			"An 'alive' Ehcache is required - current cache is " + status.toString());
	this.cache = ehcache;
}
 
Example #7
Source File: ApiEhcache.java    From iaf with Apache License 2.0 5 votes vote down vote up
/**
 * The cache can only check if a key exists if it's state is ALIVE
 */
private boolean isCacheAlive() {
	if(cache == null)
		return false;

	return Status.STATUS_ALIVE.equals(cache.getStatus());
}
 
Example #8
Source File: AbstractAutoCreatingEhCacheCacheManagerTest.java    From find with MIT License 5 votes vote down vote up
@Test
public void getMissingCacheDefault() {
    final Ehcache ehcache = mock(Ehcache.class);
    when(ehcache.getStatus()).thenReturn(Status.STATUS_ALIVE);
    when(cacheManager.getEhcache(anyString())).thenReturn(ehcache);
    assertNotNull(autoCreatingEhCacheCacheManager.getMissingCache("SomeName"));
}
 
Example #9
Source File: EhCacheCache.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create an {@link EhCacheCache} instance.
 * @param ehcache backing Ehcache instance
 */
public EhCacheCache(Ehcache ehcache) {
	Assert.notNull(ehcache, "Ehcache must not be null");
	Status status = ehcache.getStatus();
	Assert.isTrue(Status.STATUS_ALIVE.equals(status),
			"An 'alive' Ehcache is required - current cache is " + status.toString());
	this.cache = ehcache;
}
 
Example #10
Source File: EhCacheCacheManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<Cache> loadCaches() {
	Status status = getCacheManager().getStatus();
	if (!Status.STATUS_ALIVE.equals(status)) {
		throw new IllegalStateException(
				"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
	}

	String[] names = getCacheManager().getCacheNames();
	Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
	for (String name : names) {
		caches.add(new EhCacheCache(getCacheManager().getEhcache(name)));
	}
	return caches;
}
 
Example #11
Source File: EhCacheCacheManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Collection<Cache> loadCaches() {
	Status status = getCacheManager().getStatus();
	if (!Status.STATUS_ALIVE.equals(status)) {
		throw new IllegalStateException(
				"An 'alive' EhCache CacheManager is required - current cache is " + status.toString());
	}

	String[] names = getCacheManager().getCacheNames();
	Collection<Cache> caches = new LinkedHashSet<Cache>(names.length);
	for (String name : names) {
		caches.add(new EhCacheCache(getCacheManager().getEhcache(name)));
	}
	return caches;
}
 
Example #12
Source File: EhCacheCache.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create an {@link EhCacheCache} instance.
 * @param ehcache the backing Ehcache instance
 */
public EhCacheCache(Ehcache ehcache) {
	Assert.notNull(ehcache, "Ehcache must not be null");
	Status status = ehcache.getStatus();
	if (!Status.STATUS_ALIVE.equals(status)) {
		throw new IllegalArgumentException(
				"An 'alive' Ehcache is required - current cache is " + status.toString());
	}
	this.cache = ehcache;
}
 
Example #13
Source File: EhCacheCache.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create an {@link EhCacheCache} instance.
 * @param ehcache the backing Ehcache instance
 */
public EhCacheCache(Ehcache ehcache) {
	Assert.notNull(ehcache, "Ehcache must not be null");
	Status status = ehcache.getStatus();
	if (!Status.STATUS_ALIVE.equals(status)) {
		throw new IllegalArgumentException(
				"An 'alive' Ehcache is required - current cache is " + status.toString());
	}
	this.cache = ehcache;
}
 
Example #14
Source File: EhcacheLoaderImpl.java    From c2mon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Status getStatus() {
  // TODO Auto-generated method stub
  return null;
}
 
Example #15
Source File: CustomerCacheManagerEventListener.java    From cache with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Status getStatus() {
    return null;
}
 
Example #16
Source File: InstrumentedEhCacheCache.java    From kylin with Apache License 2.0 4 votes vote down vote up
/**
 * Create an {@link EhCacheCache} instance.
 * @param ehcache backing Ehcache instance
 */
public InstrumentedEhCacheCache(Ehcache ehcache) {
    Assert.notNull(ehcache, "Ehcache must not be null");
    Status status = ehcache.getStatus();
    Assert.isTrue(Status.STATUS_ALIVE.equals(status),
            "An 'alive' Ehcache is required - current cache is " + status.toString());
    this.cache = ehcache;

    final String prefix = name(cache.getClass(), cache.getName());
    Metrics.register(name(prefix, "hits"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().cacheHitCount();
        }
    });

    Metrics.register(name(prefix, "in-memory-hits"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().localHeapHitCount();
        }
    });

    Metrics.register(name(prefix, "misses"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().cacheMissCount();
        }
    });

    Metrics.register(name(prefix, "in-memory-misses"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().localHeapMissCount();
        }
    });

    Metrics.register(name(prefix, "objects"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().getSize();
        }
    });

    Metrics.register(name(prefix, "in-memory-objects"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().getLocalHeapSize();
        }
    });

    Metrics.register(name(prefix, "mean-get-time"), new Gauge<Double>() {
        @Override
        public Double getValue() {
            return cache.getStatistics().cacheGetOperation().latency().average().value();
        }
    });

    Metrics.register(name(prefix, "mean-search-time"), new Gauge<Double>() {
        @Override
        public Double getValue() {
            return cache.getStatistics().cacheSearchOperation().latency().average().value();
        }
    });

    Metrics.register(name(prefix, "eviction-count"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().cacheEvictionOperation().count().value();
        }
    });

    Metrics.register(name(prefix, "writer-queue-size"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().getWriterQueueLength();
        }
    });
}
 
Example #17
Source File: InstrumentedEhCacheCache.java    From kylin-on-parquet-v2 with Apache License 2.0 4 votes vote down vote up
/**
 * Create an {@link EhCacheCache} instance.
 * @param ehcache backing Ehcache instance
 */
public InstrumentedEhCacheCache(Ehcache ehcache) {
    Assert.notNull(ehcache, "Ehcache must not be null");
    Status status = ehcache.getStatus();
    Assert.isTrue(Status.STATUS_ALIVE.equals(status),
            "An 'alive' Ehcache is required - current cache is " + status.toString());
    this.cache = ehcache;

    final String prefix = name(cache.getClass(), cache.getName());
    Metrics.register(name(prefix, "hits"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().cacheHitCount();
        }
    });

    Metrics.register(name(prefix, "in-memory-hits"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().localHeapHitCount();
        }
    });

    Metrics.register(name(prefix, "misses"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().cacheMissCount();
        }
    });

    Metrics.register(name(prefix, "in-memory-misses"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().localHeapMissCount();
        }
    });

    Metrics.register(name(prefix, "objects"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().getSize();
        }
    });

    Metrics.register(name(prefix, "in-memory-objects"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().getLocalHeapSize();
        }
    });

    Metrics.register(name(prefix, "mean-get-time"), new Gauge<Double>() {
        @Override
        public Double getValue() {
            return cache.getStatistics().cacheGetOperation().latency().average().value();
        }
    });

    Metrics.register(name(prefix, "mean-search-time"), new Gauge<Double>() {
        @Override
        public Double getValue() {
            return cache.getStatistics().cacheSearchOperation().latency().average().value();
        }
    });

    Metrics.register(name(prefix, "eviction-count"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().cacheEvictionOperation().count().value();
        }
    });

    Metrics.register(name(prefix, "writer-queue-size"), new Gauge<Long>() {
        @Override
        public Long getValue() {
            return cache.getStatistics().getWriterQueueLength();
        }
    });
}