* Javadoc
* Added EstimatableObjectWrapper and make ChannelEventRunnable implement it to avoid an evil circular dependency
This commit is contained in:
parent
73853f1b04
commit
28511fcb9e
@ -26,6 +26,7 @@ import java.util.concurrent.Executor;
|
||||
|
||||
import org.jboss.netty.channel.ChannelEvent;
|
||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
import org.jboss.netty.util.EstimatableObjectWrapper;
|
||||
|
||||
/**
|
||||
* a {@link Runnable} which sends the specified {@link ChannelEvent} upstream.
|
||||
@ -38,7 +39,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
|
||||
* @version $Rev$, $Date$
|
||||
*
|
||||
*/
|
||||
public class ChannelEventRunnable implements Runnable {
|
||||
public class ChannelEventRunnable implements Runnable, EstimatableObjectWrapper {
|
||||
|
||||
private final ChannelHandlerContext ctx;
|
||||
private final ChannelEvent e;
|
||||
@ -74,4 +75,8 @@ public class ChannelEventRunnable implements Runnable {
|
||||
public void run() {
|
||||
ctx.sendUpstream(e);
|
||||
}
|
||||
|
||||
public Object unwrap() {
|
||||
return e;
|
||||
}
|
||||
}
|
@ -22,6 +22,8 @@
|
||||
*/
|
||||
package org.jboss.netty.util;
|
||||
|
||||
import org.jboss.netty.channel.ChannelPipeline;
|
||||
import org.jboss.netty.channel.ChannelSink;
|
||||
import org.jboss.netty.util.internal.SystemPropertyUtil;
|
||||
|
||||
/**
|
||||
@ -29,6 +31,13 @@ import org.jboss.netty.util.internal.SystemPropertyUtil;
|
||||
* this is not a Java debug mode. You can enable Netty debug mode by
|
||||
* specifying the {@code "org.jboss.netty.debug"} system property (e.g.
|
||||
* {@code java -Dorg.jboss.netty.debug ...})
|
||||
* <p>
|
||||
* If debug mode is disabled (default), the stack trace of the exceptions are
|
||||
* compressed to help debugging a user application.
|
||||
* <p>
|
||||
* If debug mode is enabled, the stack trace of the exceptions raised in
|
||||
* {@link ChannelPipeline} or {@link ChannelSink} are retained as it is to help
|
||||
* debugging Netty.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
|
@ -31,7 +31,6 @@ import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.jboss.netty.buffer.ChannelBuffer;
|
||||
import org.jboss.netty.channel.MessageEvent;
|
||||
import org.jboss.netty.handler.execution.ChannelEventRunnable;
|
||||
import org.jboss.netty.util.internal.ConcurrentIdentityWeakKeyHashMap;
|
||||
|
||||
/**
|
||||
@ -70,9 +69,8 @@ public class DefaultObjectSizeEstimator implements ObjectSizeEstimator {
|
||||
|
||||
int answer = 8 + estimateSize(o.getClass(), null);
|
||||
|
||||
// FIXME: Cyclic dependency
|
||||
if (o instanceof ChannelEventRunnable) {
|
||||
answer += estimateSize(((ChannelEventRunnable) o).getEvent());
|
||||
if (o instanceof EstimatableObjectWrapper) {
|
||||
answer += estimateSize(((EstimatableObjectWrapper) o).unwrap());
|
||||
} else if (o instanceof MessageEvent) {
|
||||
answer += estimateSize(((MessageEvent) o).getMessage());
|
||||
} else if (o instanceof ChannelBuffer) {
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* JBoss, Home of Professional Open Source
|
||||
*
|
||||
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
|
||||
* by the @author tags. See the COPYRIGHT.txt 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.netty.util;
|
||||
|
||||
/**
|
||||
* Represents a type which contains an object that needs to be taken into
|
||||
* account by {@link ObjectSizeEstimator} for more accurate object size
|
||||
* estimation.
|
||||
*
|
||||
* @author The Netty Project (netty-dev@lists.jboss.org)
|
||||
* @author Trustin Lee (tlee@redhat.com)
|
||||
* @version $Rev$, $Date$
|
||||
*/
|
||||
public interface EstimatableObjectWrapper {
|
||||
|
||||
/**
|
||||
* Returns the underlying object that needs to be taken into account
|
||||
* by {@link ObjectSizeEstimator} for more accurate object size estimation.
|
||||
*/
|
||||
Object unwrap();
|
||||
}
|
Loading…
Reference in New Issue
Block a user