initial ehcache support

This commit is contained in:
Athou
2013-06-05 11:58:35 +02:00
parent b99a7fb14a
commit 7cbcf1080b
15 changed files with 106 additions and 8 deletions

View File

@@ -1,10 +1,20 @@
package com.commafeed.backend;
import javax.ejb.Singleton;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.ejb.EntityManagerImpl;
import org.hibernate.stat.Statistics;
@Singleton
public class MetricsBean {
@PersistenceContext
EntityManager em;
private Metric lastMinute = new Metric();
private Metric thisMinute = new Metric();
@@ -61,6 +71,14 @@ public class MetricsBean {
return lastHour;
}
public String getCacheStats() {
EntityManagerImpl impl = (EntityManagerImpl) em.getDelegate();
Session session = impl.getSession();
SessionFactory sessionFactory = session.getSessionFactory();
Statistics statistics = sessionFactory.getStatistics();
return statistics.toString();
}
public static class Metric {
private int feedsRefreshed;
private int feedsUpdated;

View File

@@ -3,6 +3,7 @@ package com.commafeed.backend.model;
import java.util.Date;
import java.util.Set;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -13,6 +14,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;
import com.google.common.collect.Sets;
@@ -22,6 +25,8 @@ import com.google.common.collect.Sets;
@org.hibernate.annotations.Table(appliesTo = "FEEDS", indexes = { @Index(name = "disabled_lastupdated_index", columnNames = {
"disabledUntil", "lastUpdated" }), })
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Feed extends AbstractModel {
/**

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.model;
import java.util.Set;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -10,11 +11,16 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import com.google.common.collect.Sets;
@Entity
@Table(name = "FEEDCATEGORIES")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class FeedCategory extends AbstractModel {
@Column(length = 128, nullable = false)

View File

@@ -3,6 +3,7 @@ package com.commafeed.backend.model;
import java.util.Date;
import java.util.Set;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -17,6 +18,8 @@ import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;
import com.google.api.client.util.Sets;
@@ -24,6 +27,8 @@ import com.google.api.client.util.Sets;
@Entity
@Table(name = "FEEDENTRIES")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class FeedEntry extends AbstractModel {
@Column(length = 2048, nullable = false)

View File

@@ -1,5 +1,6 @@
package com.commafeed.backend.model;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -7,9 +8,14 @@ import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Table(name = "FEEDENTRYSTATUSES")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class FeedEntryStatus extends AbstractModel {
@ManyToOne(fetch = FetchType.LAZY)

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.model;
import java.util.Date;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -11,11 +12,15 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;
@Entity
@Table(name = "FEEDPUSHINFOS")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class FeedPushInfo extends AbstractModel {
@JoinColumn(unique = true)

View File

@@ -2,6 +2,7 @@ package com.commafeed.backend.model;
import java.util.Set;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -11,9 +12,14 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Table(name = "FEEDSUBSCRIPTIONS")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class FeedSubscription extends AbstractModel {
@ManyToOne(fetch = FetchType.LAZY)

View File

@@ -3,6 +3,7 @@ package com.commafeed.backend.model;
import java.util.Date;
import java.util.Set;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -11,6 +12,8 @@ import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Index;
import com.google.common.collect.Sets;
@@ -18,6 +21,8 @@ import com.google.common.collect.Sets;
@Entity
@Table(name = "USERS")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User extends AbstractModel {
@Column(length = 32, nullable = false, unique = true)

View File

@@ -1,5 +1,6 @@
package com.commafeed.backend.model;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
@@ -9,9 +10,14 @@ import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Table(name = "USERROLES")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class UserRole extends AbstractModel {
public static enum Role {

View File

@@ -1,5 +1,6 @@
package com.commafeed.backend.model;
import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
@@ -10,9 +11,14 @@ import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
@Entity
@Table(name = "USERSETTINGS")
@SuppressWarnings("serial")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class UserSettings extends AbstractModel {
public enum ReadingMode {

View File

@@ -85,8 +85,8 @@ public class SubscriptionHandler {
}
log.debug("subscribed to {} for {}", hub, topic);
} catch (Exception e) {
log.error("Could not subscribe to {} for {} : {}", hub, topic,
e.getMessage(), e);
log.error("Could not subscribe to {} for {} : " + e.getMessage(),
hub, topic);
} finally {
client.getConnectionManager().shutdown();
}

View File

@@ -21,7 +21,6 @@ import com.commafeed.frontend.SecurityCheck;
import com.commafeed.frontend.model.UserModel;
import com.commafeed.frontend.model.request.IDRequest;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.wordnik.swagger.annotations.Api;
@@ -176,11 +175,13 @@ public class AdminREST extends AbstractResourceREST {
@Path("/metrics")
@GET
public Response getMetrics() {
Map<String, ? extends Object> map = ImmutableMap.of("lastMinute",
metricsBean.getLastMinute(), "lastHour",
metricsBean.getLastHour(), "backlog",
feedDAO.getUpdatableCount(), "queue",
feedRefreshUpdater.getQueueSize());
Map<String, Object> map = Maps.newLinkedHashMap();
map.put("lastMinute", metricsBean.getLastMinute());
map.put("lastHour", metricsBean.getLastHour());
map.put("backlog", feedDAO.getUpdatableCount());
map.put("queue", feedRefreshUpdater.getQueueSize());
map.put("cache", metricsBean.getCacheStats());
return Response.ok(map).build();
}
}