From: Tom E. <te...@us...> - 2004-08-12 06:35:27
|
User: telrod Date: 04/08/11 23:35:21 Modified: src/main/org/jboss/remoting Tag: JBossRemoting_1_0_1 InvokerLocator.java RemoteClientInvoker.java Log: Initial checkin for marshalling changes. Revision Changes Path No revision No revision 1.6.8.1 +7 -3 jboss-remoting/src/main/org/jboss/remoting/InvokerLocator.java Index: InvokerLocator.java =================================================================== RCS file: /cvsroot/jboss/jboss-remoting/src/main/org/jboss/remoting/InvokerLocator.java,v retrieving revision 1.6 retrieving revision 1.6.8.1 diff -u -r1.6 -r1.6.8.1 --- InvokerLocator.java 21 Oct 2003 18:28:02 -0000 1.6 +++ InvokerLocator.java 12 Aug 2004 06:35:20 -0000 1.6.8.1 @@ -39,11 +39,11 @@ * NOTE: the hostname will automatically be resolved to the outside IP address of the local machine * if <tt>localhost</tt> or <tt>127.0.0.1</tt> is used as the hostname in the URI. If it cannot be * determined or resolved, it will use what was passed. - * + * * * @author <a href="mailto:jh...@vo...">Jeff Haynie</a> * @author <a href="mailto:te...@e2...">Tom Elrod</a> - * @version $Revision: 1.6 $ + * @version $Revision: 1.6.8.1 $ */ public class InvokerLocator implements Serializable { @@ -54,8 +54,12 @@ protected String path; protected Map parameters; private String uri; + /** + * Constant to define the param name to be used when defining the data type. + */ + public static final String DATATYPE = "datatype"; - public InvokerLocator (String uri) + public InvokerLocator (String uri) throws MalformedURLException { int i = uri.indexOf("://"); 1.2.6.1 +81 -7 jboss-remoting/src/main/org/jboss/remoting/RemoteClientInvoker.java Index: RemoteClientInvoker.java =================================================================== RCS file: /cvsroot/jboss/jboss-remoting/src/main/org/jboss/remoting/RemoteClientInvoker.java,v retrieving revision 1.2 retrieving revision 1.2.6.1 diff -u -r1.2 -r1.2.6.1 --- RemoteClientInvoker.java 21 Oct 2003 18:28:03 -0000 1.2 +++ RemoteClientInvoker.java 12 Aug 2004 06:35:20 -0000 1.2.6.1 @@ -18,6 +18,8 @@ import org.jboss.remoting.loading.ClassRequiredMethodInvocation; import org.jboss.remoting.loading.ClassUtil; import org.jboss.remoting.transport.ClientInvoker; +import org.jboss.remoting.marshal.Marshaller; +import org.jboss.remoting.marshal.MarshalFactory; /** * RemoteClientInvoker is an abstract client part handler that implements the bulk of the heavy @@ -34,13 +36,14 @@ * * @author <a href="mailto:jh...@vo...">Jeff Haynie</a> * @author <a href="mailto:te...@e2...">Tom Elrod</a> - * @version $Revision: 1.2 $ + * @version $Revision: 1.2.6.1 $ */ public abstract class RemoteClientInvoker extends AbstractInvoker implements ClientInvoker { - protected boolean connected=false; + protected boolean connected=false; + private String dataType; - public RemoteClientInvoker (InvokerLocator locator) + public RemoteClientInvoker (InvokerLocator locator) { super (locator); } @@ -91,13 +94,18 @@ { log.debug((++invokeCount)+") invoking =>"+invocation+" with parameter: "+in.getParameter()); } - // serialize invocation into buffer - byte send[] = ClassUtil.serialize (invocation); + +//TODO: -TME Need to remove ClassUtil all together after convert it to SerializeMarshaller + Marshaller marshaller = MarshalFactory.getMarshaller(getDataType()); + +// // serialize invocation into buffer +// byte send[] = ClassUtil.serialize (invocation); try { // send to remote end - byte receive[] = transport (in.getSessionId(), send); +// byte receive[] = transport (in.getSessionId(), send); + byte receive[] = transport(in.getSessionId(), invocation, marshaller); // deserialize result buffer into invocation result Object obj = ClassUtil.deserialize (receive, classbyteloader); @@ -242,7 +250,73 @@ } } - /** + /** + * //TODO: -TME Need to fully javadoc. + * //TODO: -TME Need to think more on what the signature should be for this. Have to pass the marshaller + * to the actual transport implementation as will be up to the transport to figure out how + * it should get the data from the marshaller (streamed or one chunck). Am passing the invocation + * at this point, because don't know if will need to do anything with it later on down the call stack + * and currently, the marshaller does not have a reference to it (so HAVE to pass to marshaller at + * some point). Could change to pass invocation to MarshalFactory when getting Marshaller and + * add it to Marshaller constructor, but then not part of it's interface. + * + * @param sessionId + * @param invocation + * @param marshaller + * @return + * @throws IOException + * @throws ConnectionFailedException + */ + protected abstract byte[] transport(String sessionId, Object invocation, Marshaller marshaller) + throws IOException, ConnectionFailedException; + + /** + * Will get the data type for the marshaller factory so know which marshaller to + * get to marshal the data. Will first check the locator uri for a 'datatype' + * parameter and take that value if it exists. Otherwise, will use the + * default datatype for the client invoker, based on transport. + * //TODO: -TME Need to document this in InvokerLocator javadoc as + * well as in remoting doc. + * @return + */ + private String getDataType() + { + if(dataType == null) + { + dataType = getDataType(getLocator()); + if(dataType == null) + { + dataType = getDefaultDataType(); + } + } + return dataType; + } + + private String getDataType(InvokerLocator locator) + { + String type = null; + + if(locator != null) + { + Map params = locator.getParameters(); + if(params != null) + { + type = (String)params.get(InvokerLocator.DATATYPE); + } + } + return type; + } + + /** + * Each implementation of the remote client invoker should have + * a default data type that is uses in the case it is not specified + * in the invoker locator uri. + * + * @return + */ + protected abstract String getDefaultDataType(); + + /** * this method is called prior to making the remote invocation to allow the subclass the ability * to provide additional data or modify the invocation * |