Removed the need to supply a Client reference when making invocation service
calls on the Java side, to match this added convenience we introduced to the ActionScript side some time ago. Before arms are raised into the air and waved like they really do care, bear the following in mind: Nothing will change at all on your project until you take some action to do so. That action could include any of the following: 1. Continue to use narya-tools-1.2 to run genservice and you'll get the old style "pass a Client reference for every service method invocation" marshallers and you can continue to live happily in the past. 2. Leave some of your stuff un-regenerated, but generate new stuff using the new tools and use the Client-reference-free style for new services. This is likely to engender some PITA if you're trying to use both styles in the same project because genservice just wants to operate on everything, but I offer it as an option in case some other PITA motivates the tolerance of this (presumably smaller) PITA. 3. Embrace the brave new world of simplicity and wield your good friend sed for fun and profit: (make necessary build.xml updates to start using narya-tools-1.4-SNAPSHOT) % find src -name '*Service.java' | xargs sed -i 's:Client client, ::g' (this will remove the Client argument from most of your services, some manual fixes may be needed) % ant genservice % find src -name '*.java' | xargs sed -i 's:_ctx.getClient(), ::g' (this will fix most of the places that pass a client reference into an invocation service, some manual fixes will probably be needed) I did this on Vilya and it magically took care of like 95% of the places where changes were needed. The remaining half dozen changes were painless. Clearly something like Yohoho vastly dwarfs Vilya in scope, but someone looking for an hour or two of mindless typing to distract them on a lazy Sunday afternoon would likely breeze through even that vast codebase without breaking a sweat. Two more notes: 1. I'm going to switch Narya and Vilya over to the new style, and I'll be fixing all the projects that use their services. 2. I lied (a teeny bit) about nothing changing. I made the old Client-taking sendRequest methods deprecated, so projects that don't switch to the new style will be presented with a large number of deprecation warnings. If this is too terrible a burden to bear, I can remove the deprecation annotations on those methods. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6395 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -27,19 +27,21 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.WildcardType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import java.io.File;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import com.samskivert.util.Logger;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.presents.annotation.TransportHint;
|
||||
import com.threerings.presents.net.Transport;
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService.InvocationListener;
|
||||
import com.threerings.presents.net.Transport;
|
||||
|
||||
/**
|
||||
* A base Ant task for generating invocation service related marshalling and unmarshalling
|
||||
@@ -81,10 +83,6 @@ public abstract class InvocationTask extends GenTask
|
||||
return _index+1;
|
||||
}
|
||||
|
||||
public int getIndexSkipFirst () {
|
||||
return _index;
|
||||
}
|
||||
|
||||
protected int _index;
|
||||
}
|
||||
|
||||
@@ -140,18 +138,10 @@ public abstract class InvocationTask extends GenTask
|
||||
}
|
||||
}
|
||||
|
||||
public String getArgListSkipFirst () {
|
||||
return getArgList(true);
|
||||
}
|
||||
|
||||
public String getArgList () {
|
||||
return getArgList(false);
|
||||
}
|
||||
|
||||
public String getArgList (boolean skipFirst) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Type[] ptypes = method.getGenericParameterTypes();
|
||||
for (int ii = skipFirst ? 1 : 0; ii < ptypes.length; ii++) {
|
||||
for (int ii = 0; ii < ptypes.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
@@ -162,27 +152,19 @@ public abstract class InvocationTask extends GenTask
|
||||
} else {
|
||||
buf.append(simpleName);
|
||||
}
|
||||
buf.append(" arg").append(skipFirst ? ii : ii+1);
|
||||
buf.append(" arg").append(ii+1);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getASArgListSkipFirst () {
|
||||
return getASArgList(true);
|
||||
}
|
||||
|
||||
public String getASArgList () {
|
||||
return getASArgList(false);
|
||||
}
|
||||
|
||||
public String getASArgList (boolean skipFirst) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Class<?>[] args = method.getParameterTypes();
|
||||
for (int ii = skipFirst ? 1 : 0; ii < args.length; ii++) {
|
||||
for (int ii = 0; ii < args.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append("arg").append(skipFirst ? ii : ii+1).append(" :");
|
||||
buf.append("arg").append(ii+1).append(" :");
|
||||
buf.append(GenUtil.simpleASName(args[ii]));
|
||||
}
|
||||
return buf.toString();
|
||||
@@ -200,18 +182,10 @@ public abstract class InvocationTask extends GenTask
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getWrappedArgListSkipFirst () {
|
||||
return getWrappedArgList(true);
|
||||
}
|
||||
|
||||
public String getWrappedArgList () {
|
||||
return getWrappedArgList(false);
|
||||
}
|
||||
|
||||
public String getWrappedArgList (boolean skipFirst) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Class<?>[] args = method.getParameterTypes();
|
||||
for (int ii = (skipFirst ? 1 : 0); ii < args.length; ii++) {
|
||||
for (int ii = 0; ii < args.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
@@ -220,22 +194,14 @@ public abstract class InvocationTask extends GenTask
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public String getASWrappedArgListSkipFirst () {
|
||||
return getASWrappedArgList(true);
|
||||
}
|
||||
|
||||
public String getASWrappedArgList () {
|
||||
return getASWrappedArgList(false);
|
||||
}
|
||||
|
||||
public String getASWrappedArgList (boolean skipFirst) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Class<?>[] args = method.getParameterTypes();
|
||||
for (int ii = (skipFirst ? 1 : 0); ii < args.length; ii++) {
|
||||
for (int ii = 0; ii < args.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
String index = String.valueOf(skipFirst ? ii : (ii+1));
|
||||
String index = String.valueOf(ii+1);
|
||||
String arg;
|
||||
if (_ilistener.isAssignableFrom(args[ii])) {
|
||||
arg = GenUtil.boxASArgument(args[ii], "listener" + index);
|
||||
@@ -247,12 +213,8 @@ public abstract class InvocationTask extends GenTask
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public boolean hasArgsSkipFirst () {
|
||||
return (method.getParameterTypes().length > 1);
|
||||
}
|
||||
|
||||
public boolean hasArgs () {
|
||||
return (method.getParameterTypes().length > 0);
|
||||
return method.getParameterTypes().length > 0;
|
||||
}
|
||||
|
||||
public boolean hasParameterizedArgs () {
|
||||
@@ -276,11 +238,11 @@ public abstract class InvocationTask extends GenTask
|
||||
public String getUnwrappedArgList (boolean listenerMode) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Type[] ptypes = method.getGenericParameterTypes();
|
||||
for (int ii = (listenerMode ? 0 : 1); ii < ptypes.length; ii++) {
|
||||
for (int ii = 0; ii < ptypes.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
buf.append(unboxArgument(ptypes[ii], listenerMode ? ii : ii-1, listenerMode));
|
||||
buf.append(unboxArgument(ptypes[ii], ii, listenerMode));
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
@@ -296,12 +258,12 @@ public abstract class InvocationTask extends GenTask
|
||||
public String getASUnwrappedArgList (boolean listenerMode) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
Class<?>[] args = method.getParameterTypes();
|
||||
for (int ii = (listenerMode ? 0 : 1); ii < args.length; ii++) {
|
||||
for (int ii = 0; ii < args.length; ii++) {
|
||||
if (buf.length() > 0) {
|
||||
buf.append(", ");
|
||||
}
|
||||
String arg;
|
||||
int argidx = listenerMode ? ii : ii-1;
|
||||
int argidx = ii;
|
||||
if (listenerMode && _ilistener.isAssignableFrom(args[ii])) {
|
||||
arg = "listener" + argidx;
|
||||
} else {
|
||||
@@ -385,8 +347,9 @@ public abstract class InvocationTask extends GenTask
|
||||
@Override
|
||||
public void execute ()
|
||||
{
|
||||
// resolve the InvocationListener class using our classloader
|
||||
// resolve the InvocationListener and Client classes using our classloader
|
||||
_ilistener = loadClass(InvocationListener.class.getName());
|
||||
_iclient = loadClass(Client.class.getName());
|
||||
|
||||
super.execute();
|
||||
}
|
||||
@@ -404,7 +367,11 @@ public abstract class InvocationTask extends GenTask
|
||||
newstr.replace('/', File.separatorChar));
|
||||
}
|
||||
|
||||
/** {@link InvocationListener} resolved with the proper classloader so
|
||||
* that we can compare it to loaded derived classes. */
|
||||
/** {@link InvocationListener} resolved with the proper classloader so that we can compare it
|
||||
* to loaded derived classes. */
|
||||
protected Class<?> _ilistener;
|
||||
|
||||
/** {@link Client} resolved with the proper classloader so that we can compare it to loaded
|
||||
* derived classes. */
|
||||
protected Class<?> _iclient;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user