Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-1803 #897

Merged
merged 5 commits into from
Jan 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -190,9 +191,9 @@ public String toString() {
return "ComponentMetadata{" +
"name='" + name + '\'' +
", dependencies=" + dependencies +
", injectMetadata=" + injectMetadata +
", startMethods=" + startMethods +
", stopMethods=" + stopMethods +
", injectMetadata=" + Arrays.toString(injectMetadata) +
", startMethods=" + Arrays.toString(startMethods) +
", stopMethods=" + Arrays.toString(stopMethods) +
", globalScope=" + globalScope +
", survivesRestarts=" + survivesRestarts +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@
public abstract class AbstractJBossMarshaller extends AbstractMarshaller {

protected static final BasicLogger log = BasicLogFactory.getLog(AbstractJBossMarshaller.class);
protected final MarshallingConfiguration baseCfg;
protected static final boolean trace = log.isTraceEnabled();
protected static final MarshallerFactory factory = new JBossMarshallerFactory();
protected static final int DEF_INSTANCE_COUNT = 16;
protected static final int DEF_CLASS_COUNT = 8;

protected final MarshallingConfiguration baseCfg;

/**
* Cache of classes that are considered to be marshallable. Since checking
* whether a type is marshallable requires attempting to marshalling them,
Expand All @@ -51,18 +56,20 @@ public abstract class AbstractJBossMarshaller extends AbstractMarshaller {
public AbstractJBossMarshaller() {
// Class resolver now set when marshaller/unmarshaller will be created
baseCfg = new MarshallingConfiguration();
baseCfg.setCreator(new SunReflectiveCreator());
baseCfg.setExternalizerCreator(new SunReflectiveCreator());
baseCfg.setExceptionListener(new DebuggingExceptionListener());
baseCfg.setClassExternalizerFactory(new SerializeWithExtFactory());
baseCfg.setInstanceCount(DEF_INSTANCE_COUNT);
baseCfg.setClassCount(DEF_CLASS_COUNT);
baseCfg.setVersion(3);
}

public void objectToObjectStream(Object obj, ObjectOutput out) throws IOException {
final public void objectToObjectStream(final Object obj, final ObjectOutput out) throws IOException {
out.writeObject(obj);
}

@Override
protected ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOException {
final protected ByteBuffer objectToBuffer(final Object o, final int estimatedSize) throws IOException {
ExposedByteArrayOutputStream baos = new ExposedByteArrayOutputStream(estimatedSize);
ObjectOutput marshaller = startObjectOutput(baos, false);
try {
Expand All @@ -73,26 +80,25 @@ protected ByteBuffer objectToBuffer(Object o, int estimatedSize) throws IOExcept
return new ByteBuffer(baos.getRawBuffer(), 0, baos.size());
}

public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
final public ObjectOutput startObjectOutput(final OutputStream os, final boolean isReentrant) throws IOException {
org.jboss.marshalling.Marshaller marshaller = getMarshaller(isReentrant);
marshaller.start(Marshalling.createByteOutput(os));
return marshaller;
}

protected abstract Marshaller getMarshaller(boolean isReentrant) throws IOException;

public void finishObjectOutput(ObjectOutput oo) {
final public void finishObjectOutput(final ObjectOutput oo) {
try {
if (log.isTraceEnabled())
log.trace("Stop marshaller");
if (trace) log.trace("Stop marshaller");

((org.jboss.marshalling.Marshaller) oo).finish();
} catch (IOException ignored) {
}
}

@Override
public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IOException,
final public Object objectFromByteBuffer(final byte[] buf, final int offset, final int length) throws IOException,
ClassNotFoundException {
ByteArrayInputStream is = new ByteArrayInputStream(buf, offset, length);
ObjectInput unmarshaller = startObjectInput(is, false);
Expand All @@ -105,10 +111,10 @@ public Object objectFromByteBuffer(byte[] buf, int offset, int length) throws IO
return o;
}

public ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws IOException {
final public ObjectInput startObjectInput(final InputStream is, final boolean isReentrant) throws IOException {
Unmarshaller unmarshaller = getUnmarshaller(isReentrant);

if (log.isTraceEnabled())
if (trace)
log.tracef("Start unmarshaller after retrieving marshaller from %s",
isReentrant ? "factory" : "thread local");

Expand All @@ -118,13 +124,13 @@ public ObjectInput startObjectInput(InputStream is, boolean isReentrant) throws

protected abstract Unmarshaller getUnmarshaller(boolean isReentrant) throws IOException;

public Object objectFromObjectStream(ObjectInput in) throws IOException, ClassNotFoundException {
final public Object objectFromObjectStream(final ObjectInput in) throws IOException, ClassNotFoundException {
return in.readObject();
}

public void finishObjectInput(ObjectInput oi) {
final public void finishObjectInput(final ObjectInput oi) {
try {
if (log.isTraceEnabled())
if (trace)
log.trace("Stop unmarshaller");

if (oi != null) ((Unmarshaller) oi).finish();
Expand Down Expand Up @@ -164,18 +170,18 @@ protected boolean isMarshallableCandidate(Object o) {
return o instanceof Serializable;
}

protected static class DebuggingExceptionListener implements ExceptionListener {
protected static final class DebuggingExceptionListener implements ExceptionListener {
private static final URL[] EMPTY_URLS = {};

@Override
public void handleMarshallingException(Throwable problem, Object subject) {
public void handleMarshallingException(final Throwable problem, final Object subject) {
if (log.isDebugEnabled()) {
TraceInformation.addUserInformation(problem, "toString = " + subject.toString());
}
}

@Override
public void handleUnmarshallingException(Throwable problem, Class<?> subjectClass) {
public void handleUnmarshallingException(final Throwable problem, final Class<?> subjectClass) {
if (log.isDebugEnabled()) {
StringBuilder builder = new StringBuilder();
ClassLoader cl = subjectClass.getClassLoader();
Expand Down Expand Up @@ -204,7 +210,7 @@ public void handleUnmarshallingException(Throwable problem) {
// no-op
}

private static URL[] getClassLoaderURLs(ClassLoader cl) {
private static URL[] getClassLoaderURLs(final ClassLoader cl) {
URL[] urls = EMPTY_URLS;
try {
Class returnType = urls.getClass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
* @version 4.1
* @see <a href="http://www.jboss.org/jbossmarshalling">JBoss Marshalling</a>
*/
public class GenericJBossMarshaller extends AbstractJBossMarshaller {
public final class GenericJBossMarshaller extends AbstractJBossMarshaller {

/**
* Marshaller thread local. In non-internal marshaller usages, such as Java
* Hot Rod client, this is a singleton shared by all so no urgent need for
* static here. JBMAR clears pretty much any state during finish(), so no
* urgent need to clear the thread local since it shouldn't be leaking.
*/
private ThreadLocal<org.jboss.marshalling.Marshaller> marshallerTL =
private final ThreadLocal<org.jboss.marshalling.Marshaller> marshallerTL =
new ThreadLocal<org.jboss.marshalling.Marshaller>() {
@Override
protected org.jboss.marshalling.Marshaller initialValue() {
Expand All @@ -63,7 +63,7 @@ protected org.jboss.marshalling.Marshaller initialValue() {
* for static here. JBMAR clears pretty much any state during finish(), so
* no urgent need to clear the thread local since it shouldn't be leaking.
*/
private ThreadLocal<Unmarshaller> unmarshallerTL = new
private final ThreadLocal<Unmarshaller> unmarshallerTL = new
ThreadLocal<Unmarshaller>() {
@Override
protected Unmarshaller initialValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@
* @since 4.0
*/
public class JBossMarshaller extends AbstractJBossMarshaller implements StreamingMarshaller {
private InvocationContextContainer icc;

ExternalizerTable externalizerTable;

public void inject(ExternalizerTable externalizerTable, ClassLoader cl, InvocationContextContainer icc) {
if (log.isDebugEnabled()) log.debug("Using JBoss Marshalling");
this.icc = icc;
this.externalizerTable = externalizerTable;
baseCfg.setInstanceCount(16);
baseCfg.setClassCount(8);
baseCfg.setObjectTable(externalizerTable);
// Override the class resolver with one that can detect injected
// classloaders via AdvancedCache.with(ClassLoader) calls.
baseCfg.setClassResolver(new EmbeddedContextClassResolver(cl));
baseCfg.setClassResolver(new EmbeddedContextClassResolver(cl, icc));
}

@Override
Expand All @@ -72,6 +69,7 @@ protected Unmarshaller getUnmarshaller(boolean isReentrant) throws IOException {
return factory.createUnmarshaller(baseCfg);
}

@Override
public void stop() {
super.stop();
// Just in case, to avoid leaking class resolver which references classloader
Expand All @@ -88,9 +86,13 @@ public boolean isMarshallableCandidate(Object o) {
* loader from the embedded Infinispan call context. This might happen when
* {@link org.infinispan.AdvancedCache#with(ClassLoader)} is used.
*/
public class EmbeddedContextClassResolver extends DefaultContextClassResolver {
public EmbeddedContextClassResolver(ClassLoader defaultClassLoader) {
public static final class EmbeddedContextClassResolver extends DefaultContextClassResolver {

private final InvocationContextContainer icc;

public EmbeddedContextClassResolver(ClassLoader defaultClassLoader, InvocationContextContainer icc) {
super(defaultClassLoader);
this.icc = icc;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
* @since 4.0
*/
public class CommandAwareRpcDispatcher extends RpcDispatcher {
private ExecutorService asyncExecutor;

private final ExecutorService asyncExecutor;
private final InboundInvocationHandler inboundInvocationHandler;
private static final Log log = LogFactory.getLog(CommandAwareRpcDispatcher.class);
private static final boolean trace = log.isTraceEnabled();
Expand Down