User: mnf999
Date: 02/03/07 09:53:41
Added: src/main/org/jboss/invocation InvocationContext.java
InvokerInterceptor.java
Log:
2 of the basic classes for client interceptor support
We define the notion of the "client interceptor" and unlike the server friend it is
"free linked" a chain as opposed to anchored in the container.
The second part of it and a result of the previous point, is that the contextual
information is in the invocation attached in the "InvocationContext" object2 of the
basic classes for client interceptor support
We define the notion of the "client interceptor" and unlike the server friend it is
"free linked" a chain as opposed to anchored in the container.
The second part of it and a result of the previous point, is that the contextual
information is in the invocation attached in the "InvocationContext" object
Revision Changes Path
1.1 jboss/src/main/org/jboss/invocation/InvocationContext.java
Index: InvocationContext.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.invocation;
import java.util.Map;
import java.util.HashMap;
import javax.transaction.TransactionManager;
import org.jboss.invocation.Invoker;
import org.jboss.ejb.CacheKey;
/*
import java.lang.reflect.Method;
import java.security.Principal;
import javax.transaction.Transaction;
*/
/**
* The Invocation Context
*
* Describes the context in which this Invocation is being executed in the
interceptors
*
* <p>The heart of it is the payload map that can contain anything we then put
readers on them
* The first "reader" is this "Invocation" object that can interpret the data in
it.
*
* <p>Essentially we can carry ANYTHING from the client to the server, we keep a
series of
* of predifined variables and method calls to get at the pointers. But really
it is just
* a repository of objects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @version $Revision: 1.1 $
*
* Revisions:
*
* <p><b>Revisions:</b>
*
* <p><b>2001114 marc fleury:</b>
* <ul>
* <li>Initial check-in
* </ul>
*/
public class InvocationContext
implements java.io.Serializable
{
// Context is a map
public Map context;
/**
* We are using the generic payload to store some of our data, we define some
integer entries.
* These are just some variables that we define for use in "typed" getters and
setters.
* One can define anything either in here explicitely or through the use of
external calls to getValue
*/
public static final Integer
// We keep these around in case one wants to cache the data at the context
level
PRINCIPAL = new Integer(new String("PRINCIPAL").hashCode()),
CREDENTIAL = new Integer(new String("CREDENTIAL").hashCode()),
// We can keep a reference to an abstract "container"
OBJECT_NAME = new Integer(new String("OBJECT_NAME").hashCode()),
// The Cache-ID associates an instance in cache somewhere on the server with
this invocation
CACHE_ID = new Integer(new String("CACHE_ID").hashCode()),
// The invoker
INVOKER = new Integer(new String("INVOKER").hashCode());
/**
* Exposed for externalization only.
*/
public InvocationContext() { context = new HashMap();}
/**
* Invocation creation
*/
public InvocationContext(Map context) { this.context = context;}
//
// The generic getter and setter is really all that one needs to talk to this
object
// We introduce typed getters and setters for convenience and code readability in
the codebase
//
//The generic store of variables
public void setValue(Object key, Object value) { context.put(key,value); }
// Get a value from the stores
public Object getValue(Object key)
{
return context.get(key);
}
// A container for server side association
public void setObjectName(Object objectName) { context.put(OBJECT_NAME,
objectName);}
public Object getObjectName() { return context.get(OBJECT_NAME);}
// Return the invocation target ID. Can be used to identify a cached object
public void setCacheId(Object id) { context.put(CACHE_ID, id);}
public Object getCacheId() { return context.get(CACHE_ID);}
public void setInvoker(Invoker invoker) { context.put(INVOKER, invoker);}
public Invoker getInvoker() { return (Invoker) context.get(INVOKER);}
}
1.1 jboss/src/main/org/jboss/invocation/InvokerInterceptor.java
Index: InvokerInterceptor.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.invocation;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.jboss.invocation.Invocation;
import org.jboss.invocation.Invoker;
/*
import java.rmi.ServerException;
import java.rmi.NoSuchObjectException;
import java.rmi.MarshalledObject;
import javax.transaction.SystemException;
import org.jboss.invocation.MarshalledInvocation;
import org.jboss.invocation.local.LocalInvoker;
import org.jboss.security.SecurityAssociation;
import org.jboss.tm.TransactionPropagationContextFactory;
*/
import org.jboss.proxy.Interceptor;
/**
* InvokerInterceptor
*
* a very simple implementation of it that branches to the local stuff
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @version $Revision: 1.1 $
*
* <p><b>2001/02/28: marcf</b>
* <ol>
* <li>Initial checkin
* </ol>
*/
public class InvokerInterceptor
extends Interceptor
implements Externalizable
{
// Constants -----------------------------------------------------
/** Serial Version Identifier. */
// private static final long serialVersionUID = 1870461898442160570L;
// Attributes ----------------------------------------------------
// We use this startup time to find if we are in the original VM
private long containerStartup = Invoker.STARTUP;
// Invoker to the remote JMX node
protected Invoker remoteInvoker;
// Static references to local invokers
protected static Invoker localInvoker;
// Get and set methods
//Local invoker reference, useful for optimization
public static Invoker getLocal() { return localInvoker;}
public static void setLocal(Invoker invoker) { localInvoker = invoker ;}
// Constructors --------------------------------------------------
public InvokerInterceptor() {
// For externalization to work
}
// Public --------------------------------------------------------
/**
* Returns wether we are local to the originating container or not.
*/
public boolean isLocal() { return containerStartup == Invoker.STARTUP; }
/**
* The invocation on the delegate, calls the right invoker. Remote if we are
remote, local if we
* are local.
*/
public Object invoke(Invocation invocation)
throws Exception
{
// optimize if calling another bean in same EJB-application
if (isLocal()) {
// The payload as is is good
return localInvoker.invoke(invocation);
}
else {
// this payload will go through marshalling
return invocation.getInvocationContext().getInvoker().invoke(invocation);
}
}
/**
* Externalize this instance.
*
* If this instance lives in a different VM than its container
* invoker, the remote interface of the container invoker is
* not externalized.
*/
public void writeExternal(final ObjectOutput out)
throws IOException
{
out.writeLong(containerStartup);
}
/**
* Un-externalize this instance.
*
* We check timestamps of the interfaces to see if the instance is in the
original VM of creation
*/
public void readExternal(final ObjectInput in)
throws IOException, ClassNotFoundException
{
containerStartup = in.readLong();
}
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development