Author: manik.surtani(a)jboss.com
Date: 2008-10-10 04:18:13 -0400 (Fri, 10 Oct 2008)
New Revision: 6900
Removed:
core/branches/flat/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValue.java
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueHelper.java
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java
Log:
Removed junk
Deleted:
core/branches/flat/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java 2008-10-09
16:51:41 UTC (rev 6899)
+++
core/branches/flat/src/main/java/org/jboss/cache/interceptors/CacheMgmtInterceptor.java 2008-10-10
08:18:13 UTC (rev 6900)
@@ -1,240 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.cache.interceptors;
-
-import org.jboss.cache.DataContainer;
-import org.jboss.cache.InvocationContext;
-import org.jboss.cache.commands.read.GetKeyValueCommand;
-import org.jboss.cache.commands.write.EvictCommand;
-import org.jboss.cache.commands.write.PutDataMapCommand;
-import org.jboss.cache.commands.write.PutForExternalReadCommand;
-import org.jboss.cache.commands.write.PutKeyValueCommand;
-import org.jboss.cache.interceptors.base.JmxStatsCommandInterceptor;
-import org.jboss.cache.jmx.annotations.ManagedAttribute;
-import org.jboss.cache.jmx.annotations.ManagedOperation;
-import org.jboss.starobrno.factories.annotations.Inject;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Captures cache management statistics
- *
- * @author Jerry Gauthier
- * @version $Id$
- */
-public class CacheMgmtInterceptor extends JmxStatsCommandInterceptor
-{
- private long hitTimes = 0;
- private long missTimes = 0;
- private long storeTimes = 0;
- private long hits = 0;
- private long misses = 0;
- private long stores = 0;
- private long evictions = 0;
- private long start = System.currentTimeMillis();
- private long reset = start;
-
- private DataContainer dataContainer;
-
- @Inject
- public void setDependencies(DataContainer dataContainer)
- {
- this.dataContainer = dataContainer;
- }
-
- @Override
- public Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws
Throwable
- {
- Object returnValue = invokeNextInterceptor(ctx, command);
- evictions++;
- return returnValue;
- }
-
- @Override
- public Object visitGetKeyValueCommand(InvocationContext ctx, GetKeyValueCommand
command) throws Throwable
- {
- long t1 = System.currentTimeMillis();
- Object retval = invokeNextInterceptor(ctx, command);
- long t2 = System.currentTimeMillis();
- if (retval == null)
- {
- missTimes = missTimes + (t2 - t1);
- misses++;
- }
- else
- {
- hitTimes = hitTimes + (t2 - t1);
- hits++;
- }
- return retval;
- }
-
- @Override
- public Object visitPutDataMapCommand(InvocationContext ctx, PutDataMapCommand command)
throws Throwable
- {
- Map data = command.getData();
- long t1 = System.currentTimeMillis();
- Object retval = invokeNextInterceptor(ctx, command);
- long t2 = System.currentTimeMillis();
-
- if (data != null && data.size() > 0)
- {
- storeTimes = storeTimes + (t2 - t1);
- stores = stores + data.size();
- }
- return retval;
- }
-
-
- @Override
- public Object visitPutForExternalReadCommand(InvocationContext ctx,
PutForExternalReadCommand command) throws Throwable
- {
- return visitPutKeyValueCommand(ctx, command);
- }
-
- @Override
- public Object visitPutKeyValueCommand(InvocationContext ctx, PutKeyValueCommand
command) throws Throwable
- {
- long t1 = System.currentTimeMillis();
- Object retval = invokeNextInterceptor(ctx, command);
- long t2 = System.currentTimeMillis();
- storeTimes = storeTimes + (t2 - t1);
- stores++;
- return retval;
- }
-
- @ManagedAttribute(description = "number of cache attribute hits")
- public long getHits()
- {
- return hits;
- }
-
- @ManagedAttribute(description = "number of cache attribute misses")
- public long getMisses()
- {
- return misses;
- }
-
- @ManagedAttribute(description = "number of cache attribute put operations")
- public long getStores()
- {
- return stores;
- }
-
- @ManagedAttribute(description = "number of cache eviction operations")
- public long getEvictions()
- {
- return evictions;
- }
-
- @ManagedAttribute(description = "hit/miss ratio for the cache")
- public double getHitMissRatio()
- {
- double total = hits + misses;
- if (total == 0)
- return 0;
- return (hits / total);
- }
-
- @ManagedAttribute(description = "read/writes ratio for the cache")
- public double getReadWriteRatio()
- {
- if (stores == 0)
- return 0;
- return (((double) (hits + misses) / (double) stores));
- }
-
- @ManagedAttribute(description = "average number of milliseconds for a read
operation")
- public long getAverageReadTime()
- {
- long total = hits + misses;
- if (total == 0)
- return 0;
- return (hitTimes + missTimes) / total;
- }
-
- @ManagedAttribute(description = "average number of milliseconds for a write
operation")
- public long getAverageWriteTime()
- {
- if (stores == 0)
- return 0;
- return (storeTimes) / stores;
- }
-
- @ManagedAttribute(description = "number of cache eviction operations")
- public int getNumberOfAttributes()
- {
- return dataContainer.getNumberOfAttributes();
- }
-
- @ManagedAttribute
- public int getNumberOfNodes()
- {
- return dataContainer.getNumberOfNodes();
- }
-
- @ManagedAttribute(description = "seconds since cache started")
- public long getElapsedTime()
- {
- return (System.currentTimeMillis() - start) / 1000;
- }
-
- @ManagedAttribute(description = "number of seconds since the cache statistics
were last reset")
- public long getTimeSinceReset()
- {
- return (System.currentTimeMillis() - reset) / 1000;
- }
-
- @ManagedOperation
- public Map<String, Object> dumpStatistics()
- {
- Map<String, Object> retval = new HashMap<String, Object>();
- retval.put("Hits", hits);
- retval.put("Misses", misses);
- retval.put("Stores", stores);
- retval.put("Evictions", evictions);
- retval.put("NumberOfAttributes", dataContainer.getNumberOfAttributes());
- retval.put("NumberOfNodes", dataContainer.getNumberOfNodes());
- retval.put("ElapsedTime", getElapsedTime());
- retval.put("TimeSinceReset", getTimeSinceReset());
- retval.put("AverageReadTime", getAverageReadTime());
- retval.put("AverageWriteTime", getAverageWriteTime());
- retval.put("HitMissRatio", getHitMissRatio());
- retval.put("ReadWriteRatio", getReadWriteRatio());
- return retval;
- }
-
- @ManagedOperation
- public void resetStatistics()
- {
- hits = 0;
- misses = 0;
- stores = 0;
- evictions = 0;
- hitTimes = 0;
- missTimes = 0;
- storeTimes = 0;
- reset = System.currentTimeMillis();
- }
-}
-
Deleted: core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValue.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValue.java 2008-10-09
16:51:41 UTC (rev 6899)
+++
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValue.java 2008-10-10
08:18:13 UTC (rev 6900)
@@ -1,229 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.cache.marshall;
-
-import org.jboss.starobrno.CacheException;
-import org.jboss.util.stream.MarshalledValueInputStream;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.NotSerializableException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.Arrays;
-
-/**
- * Wrapper that wraps cached data, providing lazy deserialization using the calling
thread's context class loader.
- * <p/>
- * The {@link org.jboss.cache.interceptors.MarshalledValueInterceptor} handles
transparent
- * wrapping/unwrapping of cached data.
- * <p/>
- *
- * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
- * @see org.jboss.cache.interceptors.MarshalledValueInterceptor
- * @since 2.1.0
- */
-public class MarshalledValue implements Externalizable
-{
- protected Object instance;
- protected byte[] raw;
- private int cachedHashCode = 0;
- // by default equals() will test on the istance rather than the byte array if
conversion is required.
- private transient boolean equalityPreferenceForInstance = true;
-
- public MarshalledValue(Object instance) throws NotSerializableException
- {
- if (instance == null) throw new NullPointerException("Null values cannot be
wrapped as MarshalledValues!");
-
- if (instance instanceof Serializable)
- this.instance = instance;
- else
- throw new NotSerializableException("Marshalled values can only wrap Objects
that are serializable! Instance of " + instance.getClass() + " won't
Serialize.");
- }
-
- public MarshalledValue()
- {
- // empty ctor for serialization
- }
-
- public void setEqualityPreferenceForInstance(boolean equalityPreferenceForInstance)
- {
- this.equalityPreferenceForInstance = equalityPreferenceForInstance;
- }
-
- public synchronized void serialize()
- {
- if (raw == null)
- {
- try
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(instance);
- oos.close();
- baos.close();
- // Do NOT set instance to null over here, since it may be used elsewhere
(e.g., in a cache listener).
- // this will be compacted by the MarshalledValueInterceptor when the call
returns.
-// instance = null;
- raw = baos.toByteArray();
- }
- catch (Exception e)
- {
- throw new CacheException("Unable to marshall value " + instance,
e);
- }
- }
- }
-
- public synchronized void deserialize()
- {
- if (instance == null)
- {
- try
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(raw);
- // use a MarshalledValueInputStream since it needs to be aware of any context
class loaders on the current thread.
- ObjectInputStream ois = new MarshalledValueInputStream(bais);
- instance = ois.readObject();
- ois.close();
- bais.close();
-// raw = null;
- }
- catch (Exception e)
- {
- throw new CacheException("Unable to unmarshall value", e);
- }
- }
- }
-
- /**
- * Compacts the references held by this class to a single reference. If only one
representation exists this method
- * is a no-op unless the 'force' parameter is used, in which case the
reference held is forcefully switched to the
- * 'preferred representation'.
- * <p/>
- * Either way, a call to compact() will ensure that only one representation is held.
- * <p/>
- *
- * @param preferSerializedRepresentation if true and both representations exist, the
serialized representation is favoured. If false, the deserialized representation is
preferred.
- * @param force ensures the preferred representation is
maintained and the other released, even if this means serializing or deserializing.
- */
- public void compact(boolean preferSerializedRepresentation, boolean force)
- {
- // reset the equalityPreference
- equalityPreferenceForInstance = true;
- if (force)
- {
- if (preferSerializedRepresentation && raw == null) serialize();
- else if (!preferSerializedRepresentation && instance == null)
deserialize();
- }
-
- if (instance != null && raw != null)
- {
- // need to lose one representation!
-
- if (preferSerializedRepresentation)
- {
- instance = null;
- }
- else
- {
- raw = null;
- }
- }
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- if (raw == null) serialize();
- out.writeInt(raw.length);
- out.write(raw);
- out.writeInt(hashCode());
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- int size = in.readInt();
- raw = new byte[size];
- cachedHashCode = 0;
- in.readFully(raw);
- cachedHashCode = in.readInt();
- }
-
- public Object get() throws IOException, ClassNotFoundException
- {
- if (instance == null) deserialize();
- return instance;
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- MarshalledValue that = (MarshalledValue) o;
-
- // if both versions are serialized or deserialized, just compare the relevant
representations.
- if (raw != null && that.raw != null) return Arrays.equals(raw, that.raw);
- if (instance != null && that.instance != null) return
instance.equals(that.instance);
-
- // if conversion of one representation to the other is necessary, then see which we
prefer converting.
- if (equalityPreferenceForInstance)
- {
- if (instance == null) deserialize();
- if (that.instance == null) that.deserialize();
- return instance.equals(that.instance);
- }
- else
- {
- if (raw == null) serialize();
- if (that.raw == null) that.serialize();
- return Arrays.equals(raw, that.raw);
- }
- }
-
- @Override
- public int hashCode()
- {
- if (cachedHashCode == 0)
- {
- // always calculate the hashcode based on the instance since this is where
we're getting the equals()
- if (instance == null) deserialize();
- cachedHashCode = instance.hashCode();
- if (cachedHashCode == 0) // degenerate case
- {
- cachedHashCode = 0xFEED;
- }
- }
- return cachedHashCode;
- }
-
- @Override
- public String toString()
- {
- return "MarshalledValue(cachedHashCode=" + cachedHashCode + ";
serialized=" + (raw != null) + ")";
- }
-}
Deleted:
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueHelper.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueHelper.java 2008-10-09
16:51:41 UTC (rev 6899)
+++
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueHelper.java 2008-10-10
08:18:13 UTC (rev 6900)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.cache.marshall;
-
-import org.jboss.cache.Fqn;
-import org.jboss.cache.commands.ReplicableCommand;
-import org.jboss.cache.transaction.GlobalTransaction;
-import org.jgroups.Address;
-
-/**
- * Common functionality used by the {@link
org.jboss.cache.interceptors.MarshalledValueInterceptor} and the {@link
MarshalledValueMap}.
- *
- * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
- * @see MarshalledValue
- * @see org.jboss.cache.interceptors.MarshalledValueInterceptor
- * @see org.jboss.cache.marshall.MarshalledValueMap
- * @since 2.1.0
- */
-public class MarshalledValueHelper
-{
- /**
- * Tests whether the type should be excluded from MarshalledValue wrapping.
- *
- * @param type type to test. Should not be null.
- * @return true if it should be excluded from MarshalledValue wrapping.
- */
- public static boolean isTypeExcluded(Class type)
- {
- return type.equals(String.class) || type.isPrimitive() ||
- type.equals(Void.class) || type.equals(Boolean.class) ||
type.equals(Character.class) ||
- type.equals(Byte.class) || type.equals(Short.class) ||
type.equals(Integer.class) ||
- type.equals(Long.class) || type.equals(Float.class) ||
type.equals(Double.class) ||
- (type.isArray() && isTypeExcluded(type.getComponentType())) ||
type.equals(Fqn.class) || type.equals(GlobalTransaction.class) ||
type.equals(Address.class) ||
- ReplicableCommand.class.isAssignableFrom(type) ||
type.equals(MarshalledValue.class);
- }
-}
Deleted:
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java
===================================================================
---
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java 2008-10-09
16:51:41 UTC (rev 6899)
+++
core/branches/flat/src/main/java/org/jboss/cache/marshall/MarshalledValueMap.java 2008-10-10
08:18:13 UTC (rev 6900)
@@ -1,181 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.cache.marshall;
-
-import net.jcip.annotations.Immutable;
-import org.jboss.starobrno.CacheException;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * A Map that is able to wrap/unwrap MarshalledValues in keys or values. Note that
calling keySet(), entrySet() or values()
- * could be expensive if this map is large!!
- * <p/>
- * Also note that this is an immutable Map.
- * <p/>
- *
- * @author Manik Surtani (<a
href="mailto:manik@jboss.org">manik@jboss.org</a>)
- * @see MarshalledValue
- * @since 2.1.0
- */
-@Immutable
-public class MarshalledValueMap implements Map, Externalizable
-{
- Map delegate;
- Map<Object, Object> unmarshalled;
-
- public MarshalledValueMap()
- {
- // for externalization
- }
-
- public MarshalledValueMap(Map delegate)
- {
- this.delegate = delegate;
- }
-
- @SuppressWarnings("unchecked")
- protected synchronized Map getUnmarshalledMap()
- {
- if (unmarshalled == null) unmarshalled = unmarshalledMap(delegate.entrySet());
- return unmarshalled;
- }
-
- public int size()
- {
- return delegate.size();
- }
-
- public boolean isEmpty()
- {
- return delegate.isEmpty();
- }
-
- public boolean containsKey(Object key)
- {
- return getUnmarshalledMap().containsKey(key);
- }
-
- public boolean containsValue(Object value)
- {
- return getUnmarshalledMap().containsValue(value);
- }
-
- public Object get(Object key)
- {
- return getUnmarshalledMap().get(key);
- }
-
- public Object put(Object key, Object value)
- {
- throw new UnsupportedOperationException("This is an immutable map!");
- }
-
- public Object remove(Object key)
- {
- throw new UnsupportedOperationException("This is an immutable map!");
- }
-
- public void putAll(Map t)
- {
- throw new UnsupportedOperationException("This is an immutable map!");
- }
-
- public void clear()
- {
- throw new UnsupportedOperationException("This is an immutable map!");
- }
-
- public Set keySet()
- {
- return getUnmarshalledMap().keySet();
- }
-
- public Collection values()
- {
- return getUnmarshalledMap().values();
- }
-
- public Set entrySet()
- {
- return getUnmarshalledMap().entrySet();
- }
-
- @SuppressWarnings("unchecked")
- protected Map unmarshalledMap(Set entries)
- {
- if (entries == null || entries.isEmpty()) return Collections.emptyMap();
- Map map = new HashMap(entries.size());
- for (Object e : entries)
- {
- Map.Entry entry = (Map.Entry) e;
- map.put(getUnmarshalledValue(entry.getKey()),
getUnmarshalledValue(entry.getValue()));
- }
- return map;
- }
-
- private Object getUnmarshalledValue(Object o)
- {
- try
- {
- return o instanceof MarshalledValue ? ((MarshalledValue) o).get() : o;
- }
- catch (Exception e)
- {
- throw new CacheException("Unable to unmarshall value", e);
- }
- }
-
- @Override
- public boolean equals(Object other)
- {
- if (other instanceof Map)
- {
- return getUnmarshalledMap().equals(other);
- }
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return getUnmarshalledMap().hashCode();
- }
-
- public void writeExternal(ObjectOutput out) throws IOException
- {
- out.writeObject(delegate);
- }
-
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- {
- delegate = (Map) in.readObject();
- }
-}