Search in sources :

Example 1 with Element

use of net.sf.ehcache.Element in project camel by apache.

the class CacheProducerTest method testAddingDataElementIdle.

@Test
public void testAddingDataElementIdle() throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).setHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_IDLE, constant(24)).to("cache://TestCache1");
        }
    });
    context.start();
    log.debug("------------Beginning CacheProducer Add Test---------------");
    sendOriginalFile();
    Element element = fetchElement("Ralph_Waldo_Emerson");
    assertEquals(24, element.getTimeToIdle());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Element(net.sf.ehcache.Element) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 2 with Element

use of net.sf.ehcache.Element in project camel by apache.

the class CacheProducerTest method testAddingDataElementEternal.

@Test
public void testAddingDataElementEternal() throws Exception {
    context.addRoutes(new RouteBuilder() {

        public void configure() {
            from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).setHeader(CacheConstants.CACHE_ELEMENT_EXPIRY_ETERNAL, constant(Boolean.TRUE)).to("cache://TestCache1");
        }
    });
    context.start();
    log.debug("------------Beginning CacheProducer Add Test---------------");
    sendOriginalFile();
    Element element = fetchElement("Ralph_Waldo_Emerson");
    assertTrue(element.isEternal());
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Element(net.sf.ehcache.Element) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 3 with Element

use of net.sf.ehcache.Element in project metrics by dropwizard.

the class InstrumentedCacheDecoratorFactoryTest method measuresPuts.

@Test
public void measuresPuts() throws Exception {
    cache.put(new Element("woo", "whee"));
    assertThat(registry.timer(name(Cache.class, "test-config", "puts")).getCount()).isEqualTo(1);
}
Also used : Element(net.sf.ehcache.Element) Test(org.junit.Test)

Example 4 with Element

use of net.sf.ehcache.Element in project qi4j-sdk by Qi4j.

the class EhCacheImpl method put.

@Override
public void put(String key, T value) {
    Element element = new Element(key, value);
    backingCache.put(element);
}
Also used : Element(net.sf.ehcache.Element)

Example 5 with Element

use of net.sf.ehcache.Element in project JMPjct by MPjct.

the class Eh method read_query.

@SuppressWarnings("unchecked")
public void read_query(Engine context) {
    if (Eh.cache == null)
        return;
    String query = context.query;
    String command = "";
    String value = "";
    // Reset all values on a new query
    this.TTL = 0;
    this.key = "";
    if (!query.startsWith("/* "))
        return;
    // Extract out the command
    command = query.substring(3, query.indexOf("*/")).trim();
    if (command.indexOf(":") != -1) {
        value = command.substring(command.indexOf(":") + 1).trim();
        command = command.substring(0, command.indexOf(":")).trim();
    }
    query = query.substring(query.indexOf("*/") + 2).trim();
    this.key = context.schema + ":" + query;
    this.logger.info("Cache Key: '" + this.key + "'");
    this.logger.trace("Command: '" + command + "'" + " value: '" + value + "'");
    if (command.equalsIgnoreCase("CACHE")) {
        this.logger.trace("CACHE");
        this.TTL = Integer.parseInt(value);
        context.buffer_result_set();
        Eh.cache.acquireWriteLockOnKey(this.key);
        Element element = Eh.cache.get(this.key);
        if (element != null) {
            this.logger.trace("Cache Hit!");
            Eh.cache.releaseWriteLockOnKey(this.key);
            context.clear_buffer();
            context.buffer = (ArrayList<byte[]>) element.getValue();
            context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
            if (context.buffer.size() == 0) {
                ERR err = new ERR();
                err.sequenceId = context.sequenceId + 1;
                err.errorCode = 1032;
                err.sqlState = "HY000";
                err.errorMessage = "Can't find record in ehcache";
                context.clear_buffer();
                context.buffer.add(err.toPacket());
                context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
                this.logger.fatal("Cache hit but invalid result!");
            }
        }
    } else if (command.equalsIgnoreCase("FLUSH")) {
        this.logger.trace("FLUSH");
        OK ok = new OK();
        boolean removed = Eh.cache.remove(this.key);
        if (removed)
            ok.affectedRows = 1;
        ok.sequenceId = context.sequenceId + 1;
        context.clear_buffer();
        context.buffer.add(ok.toPacket());
        context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
    } else if (command.equalsIgnoreCase("FLUSHALL")) {
        this.logger.trace("FLUSHALL");
        OK ok = new OK();
        Eh.cache.removeAll();
        ok.sequenceId = context.sequenceId + 1;
        context.clear_buffer();
        context.buffer.add(ok.toPacket());
        context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
    } else if (command.equalsIgnoreCase("REFRESH")) {
        this.logger.trace("REFRESH");
        Eh.cache.remove(this.key);
        this.TTL = Integer.parseInt(value);
        context.buffer_result_set();
    } else if (command.equalsIgnoreCase("STATS")) {
        this.logger.trace("STATS");
        ResultSet rs = new ResultSet();
        Row row = null;
        rs.addColumn(new Column("Key"));
        rs.addColumn(new Column("Value"));
        Statistics stats = Eh.cache.getStatistics();
        rs.addRow(new Row("AverageGetTime", stats.getAverageGetTime()));
        rs.addRow(new Row("AverageSearchTime", stats.getAverageSearchTime()));
        rs.addRow(new Row("ObjectCount", stats.getObjectCount()));
        rs.addRow(new Row("MemoryStoreObjectCount", stats.getMemoryStoreObjectCount()));
        rs.addRow(new Row("OffHeapStoreObjectCount", stats.getOffHeapStoreObjectCount()));
        rs.addRow(new Row("DiskStoreObjectCount", stats.getDiskStoreObjectCount()));
        rs.addRow(new Row("CacheHits", stats.getCacheHits()));
        rs.addRow(new Row("CacheMisses", stats.getCacheMisses()));
        rs.addRow(new Row("InMemoryHits", stats.getInMemoryHits()));
        rs.addRow(new Row("InMemoryMisses", stats.getInMemoryMisses()));
        rs.addRow(new Row("OffHeapHits", stats.getOffHeapHits()));
        rs.addRow(new Row("OffHeapMisses", stats.getOffHeapMisses()));
        rs.addRow(new Row("OnDiskHits", stats.getOnDiskHits()));
        rs.addRow(new Row("OnDiskMisses", stats.getOnDiskMisses()));
        rs.addRow(new Row("EvictionCount", stats.getEvictionCount()));
        rs.addRow(new Row("SearchesPerSecond", stats.getSearchesPerSecond()));
        rs.addRow(new Row("WriterQueueSize", stats.getWriterQueueSize()));
        context.clear_buffer();
        context.buffer = rs.toPackets();
        context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
    } else if (command.equalsIgnoreCase("INFO")) {
        this.logger.trace("INFO");
        ResultSet rs = new ResultSet();
        Row row = null;
        rs.addColumn(new Column("Key"));
        rs.addColumn(new Column("Value"));
        rs.addRow(new Row("getGuid", Eh.cache.getGuid()));
        rs.addRow(new Row("getName", Eh.cache.getName()));
        rs.addRow(new Row("getStatus", Eh.cache.getStatus().toString()));
        rs.addRow(new Row("isDisabled", Eh.cache.isDisabled()));
        rs.addRow(new Row("isSearchable", Eh.cache.isSearchable()));
        try {
            rs.addRow(new Row("isNodeBulkLoadEnabled", Eh.cache.isNodeBulkLoadEnabled()));
            rs.addRow(new Row("isClusterBulkLoadEnabled", Eh.cache.isClusterBulkLoadEnabled()));
        } catch (UnsupportedOperationException e) {
        } catch (TerracottaNotRunningException e) {
        }
        rs.addRow(new Row("isStatisticsEnabled", Eh.cache.isStatisticsEnabled()));
        rs.addRow(new Row("isSampledStatisticsEnabled", Eh.cache.isSampledStatisticsEnabled()));
        switch(Eh.cache.getStatisticsAccuracy()) {
            case Statistics.STATISTICS_ACCURACY_BEST_EFFORT:
                rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_BEST_EFFORT"));
                break;
            case Statistics.STATISTICS_ACCURACY_GUARANTEED:
                rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_GUARANTEED"));
                break;
            case Statistics.STATISTICS_ACCURACY_NONE:
                rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_NONE"));
                break;
            default:
                rs.addRow(new Row("getStatisticsAccuracy", "STATISTICS_ACCURACY_UNKNOWN"));
                break;
        }
        rs.addRow(new Row("hasAbortedSizeOf", Eh.cache.hasAbortedSizeOf()));
        context.clear_buffer();
        context.buffer = rs.toPackets();
        context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
    } else if (command.equalsIgnoreCase("DUMP KEYS")) {
        this.logger.trace("DUMP KEYS");
        List keys = this.cache.getKeysWithExpiryCheck();
        ResultSet rs = new ResultSet();
        rs.addColumn(new Column("Key"));
        for (Object k : keys) {
            this.logger.trace("Key: '" + k + "'");
            rs.addRow(new Row(k.toString()));
        }
        context.clear_buffer();
        context.buffer = rs.toPackets();
        context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
    } else {
        this.logger.trace("FAIL");
        ERR err = new ERR();
        err.sequenceId = context.sequenceId + 1;
        err.errorCode = 1047;
        err.sqlState = "08S01";
        err.errorMessage = "Unknown command '" + command + "'";
        context.clear_buffer();
        context.buffer.add(err.toPacket());
        context.nextMode = Flags.MODE_SEND_QUERY_RESULT;
        this.logger.fatal(command + " is unknown!");
    }
}
Also used : TerracottaNotRunningException(net.sf.ehcache.terracotta.TerracottaNotRunningException) ERR(com.github.mpjct.jmpjct.mysql.proto.ERR) Column(com.github.mpjct.jmpjct.mysql.proto.Column) Element(net.sf.ehcache.Element) ResultSet(com.github.mpjct.jmpjct.mysql.proto.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Row(com.github.mpjct.jmpjct.mysql.proto.Row) OK(com.github.mpjct.jmpjct.mysql.proto.OK) Statistics(net.sf.ehcache.Statistics)

Aggregations

Element (net.sf.ehcache.Element)114 Test (org.junit.Test)21 CacheKey (org.apereo.portal.utils.cache.CacheKey)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cache (net.sf.ehcache.Cache)7 HashSet (java.util.HashSet)6 CacheException (net.sf.ehcache.CacheException)6 MalformedURLException (java.net.MalformedURLException)5 ConfigurationException (javax.naming.ConfigurationException)5 Ehcache (net.sf.ehcache.Ehcache)5 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)5 EntityIdentifier (org.apereo.portal.EntityIdentifier)5 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 URISyntaxException (java.net.URISyntaxException)4 SQLException (java.sql.SQLException)4 EntityExistsException (javax.persistence.EntityExistsException)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 BaseCacheTest (org.apache.camel.component.BaseCacheTest)4