Skip to content

Instantly share code, notes, and snippets.

@sharrissf
sharrissf / ehcache.xml
Created September 26, 2011 05:07
Weather Service Example with ARC
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
<!-- Line 4 --> maxBytesLocalHeap="50%">
<diskStore path="java.io.tmpdir/EhCacheSpringExample1" />
<cache name="weatherCache" statistics="true" />
@sharrissf
sharrissf / ehcache.xml
Created September 26, 2011 02:42
Original Ehcache.xml file for WeatherService sample
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2011 Nicholas Blair, Eric Dalquist
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@sharrissf
sharrissf / gist:1077193
Created July 12, 2011 01:21
Ehcache Bytes Based Tuning
//Go from this
<ehcache>
// to this
<ehcache maxBytesLocalHeap="100M" >
// or
<ehcache maxBytesLocalHeap="50%" >
public Collection getAllAlbumsBy(Artist artist){
List results = new ArrayList();
for(Iterator i = getAllAlbums();i.hasNext();){
Album album = (Album)i.next();
if(album.isBy(artist)){
results.add(album);
}
}
return results;
albums = getAllAlbumsBy(artist);
songs = getAllSongs(artist);
printSongCountHeader(songs.size());
pringAlbumCountHeader(albums.size());
Configuration config;
FactoryConfiguration factoryConfig = new FactoryConfiguration();
factoryConfig.setClass("org.terracotta.ehcachedx.monitor.probe.ProbePeerListenerFactory");
factoryConfig.setProperties("monitorAddress=localhost, monitorPort=9889");
config.addCacheManagerPeerListenerFactory(factoryConfig);
... and in pom.xml:
<dependency>
<groupId>org.terracotta</groupId>
@sharrissf
sharrissf / gist:828611
Created February 16, 2011 00:37
Sample of doing a query
Query query = cache.createQuery();
query.includeKeys();
query.includeValues();
query.addCriteria(name.ilike(“Greg*”).and(gender.eq(Gender.MALE))).addOrderBy(age, Direction.ASCENDING).maxResults(10);
Results results = query.execute();
System.out.println(” Size: ” + results.size());
for (Result result : results.all()) {
System.out.println(“Got: Key[" + result.getKey() + "] Value class [" + result.getValue().getClass() + "] Value [" + result.getValue() + "]“);
}
@sharrissf
sharrissf / gist:769735
Created January 7, 2011 17:01
Terracotta Maven repos
<repositories>
<repository>
<id>terracotta-snapshots</id>
<name>Terracotta Repo</name>
<url>http://www.terracotta.org/download/reflector/releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
@sharrissf
sharrissf / gist:720910
Created November 30, 2010 00:33
Quartz Scheduler Example 3 comparison
//Quartz 1.8.4 Example 3 snippet
// job 7 will run every 30 seconds but only on Weekends (Saturday and
// Sunday)
job = new JobDetail("job7", "group1", SimpleJob.class);
trigger = new CronTrigger("trigger7", "group1", "job7", "group1",
"0,30 * * ? * SAT,SUN");
sched.addJob(job, true);
ft = sched.scheduleJob(trigger);
@sharrissf
sharrissf / gist:720905
Created November 30, 2010 00:27
Quartz Scheduler Example 2 comparison
//Quartz scheduler Example 2 from 1.8.3
// job3 will run 11 times (run once and repeat 10 more times)
// job3 will repeat every 10 seconds (10000 ms)
job = new JobDetail("job3", "group1", SimpleJob.class);
trigger = new SimpleTrigger("trigger3", "group1", "job3", "group1",
new Date(ts), null, 10, 10000L);
ft = sched.scheduleJob(job, trigger);
// the same job (job3) will be scheduled by a another trigger