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

[#76] Parallel request routing for Blue Ocean #77

Merged
merged 16 commits into from
Jun 17, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public Class getReturnType() {
return next.getReturnType();
}

// can't really call next.contextualize()
@Override
public Function contextualize(Object usage) {
return this;
}

@Override
public Type[] getGenericParameterTypes() {
return next.getGenericParameterTypes();
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/org/kohsuke/stapler/Function.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public abstract class Function {
*/
public abstract Class getReturnType();

/**
* Caller uses this method to tell {@link Function} about how it is being used.
* By default, this methods ignores the given context by returning {@code this}.
*/
public Function contextualize(Object usage) {
return this;
}

/**
* Calls {@link #bindAndInvoke(Object, StaplerRequest, StaplerResponse, Object...)} and then
* optionally serve the response object.
Expand Down Expand Up @@ -217,6 +225,9 @@ public Object invoke(StaplerRequest req, StaplerResponse rsp, Object o, Object..
});
}

/**
* @see StaticFunction#RETURN_NULL
*/
public static Object returnNull() { return null; }

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/kohsuke/stapler/FunctionList.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*
* @author Kohsuke Kawaguchi
*/
final class FunctionList extends AbstractList<Function> {
public final class FunctionList extends AbstractList<Function> {
private final Function[] functions;

public FunctionList(Function... functions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.kohsuke.stapler;

import org.kohsuke.stapler.bind.JavaScriptMethod;

/**
* {@link Function#contextualize(Object)} parameter that indicates
* the function is called to serve JavaScript method invocation from a proxy.
*
* @author Kohsuke Kawaguchi
* @see JavaScriptMethod
*/
public final class JavaScriptMethodContext {
private final String name;

// instantiation restricted to this class
/*package*/ JavaScriptMethodContext(String name) {
this.name = name;
}

/**
* Name of the web method. "" for index route.
*/
public String getName() {
return name;
}
}

29 changes: 29 additions & 0 deletions core/src/main/java/org/kohsuke/stapler/KlassDescriptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.kohsuke.stapler;

import org.kohsuke.stapler.lang.FieldRef;
import org.kohsuke.stapler.lang.Klass;

import java.util.List;

/**
* Reflection information of a {@link Klass} that drives the request routing.
*
* <p>
* Born as a generalization of {@link ClassDescriptor} to {@link Klass}.
* @author Kohsuke Kawaguchi
*/
class KlassDescriptor<C> {
final Klass<C> clazz;
final FunctionList methods;
final List<FieldRef> fields;

/**
* @param klazz
* The class to build a descriptor around.
*/
public KlassDescriptor(Klass<C> klazz) {
this.clazz = klazz;
this.fields = klazz.getFields();
this.methods = new FunctionList(klazz.getFunctions());
}
}
Loading