Skip to content

Commit

Permalink
core: Deprecated old Procedure interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cederberg committed Mar 12, 2024
1 parent c463c9e commit 8c8b2d8
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 73 deletions.
15 changes: 5 additions & 10 deletions src/java/org/rapidcontext/app/proc/ThreadContextProcedure.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ public Object call(CallContext cx, Bindings bindings)
*/
static Dict getContextData(CallContext cx) {
Dict res = new Dict();
org.rapidcontext.core.proc.Procedure proc =
(Procedure) cx.getAttribute(CallContext.ATTRIBUTE_PROCEDURE);
if (proc == null) {
res.set("procedure", null);
} else {
res.set("procedure", proc.getName());
}
Procedure proc = (Procedure) cx.getAttribute(CallContext.ATTRIBUTE_PROCEDURE);
res.set("procedure", (proc == null) ? null : proc.id());
Date startTime = (Date) cx.getAttribute(CallContext.ATTRIBUTE_START_TIME);
if (startTime == null) {
res.set("startMillis", null);
Expand Down Expand Up @@ -142,10 +137,10 @@ static Dict getContextData(CallContext cx) {
res.set("error", cx.getAttribute(CallContext.ATTRIBUTE_ERROR));
StringBuilder log = (StringBuilder) cx.getAttribute(CallContext.ATTRIBUTE_LOG_BUFFER);
res.set("log", (log == null) ? "" : log.toString());
org.rapidcontext.core.proc.Procedure[] procs = cx.getCallStack().toArray();
Procedure[] procs = cx.getCallStack().toArray();
Array list = new Array(procs.length);
for (org.rapidcontext.core.proc.Procedure p : procs) {
list.add(p.getName());
for (Procedure p : procs) {
list.add(p.id());
}
res.set("stack", list);
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

import org.rapidcontext.core.proc.CallContext;
import org.rapidcontext.core.proc.Interceptor;
import org.rapidcontext.core.proc.Procedure;
import org.rapidcontext.core.proc.ProcedureException;
import org.rapidcontext.core.type.Procedure;

/**
* A JavaScript compile procedure call interceptor. This interceptor
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/rapidcontext/core/js/JsRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import org.rapidcontext.core.data.Array;
import org.rapidcontext.core.data.Dict;
import org.rapidcontext.core.proc.CallContext;
import org.rapidcontext.core.proc.Procedure;
import org.rapidcontext.core.storage.StorableObject;
import org.rapidcontext.core.type.Channel;
import org.rapidcontext.core.type.Procedure;
import org.rapidcontext.util.DateUtil;

/**
Expand Down
7 changes: 3 additions & 4 deletions src/java/org/rapidcontext/core/js/ProcedureWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.mozilla.javascript.Wrapper;
import org.rapidcontext.core.proc.Bindings;
import org.rapidcontext.core.proc.CallContext;
import org.rapidcontext.core.proc.Procedure;
import org.rapidcontext.core.proc.ProcedureException;
import org.rapidcontext.core.type.Procedure;

/**
* A JavaScript procedure function wrapper. This class encapsulates a
Expand Down Expand Up @@ -91,9 +91,8 @@ public boolean hasInstance(Scriptable instance) {
public Object get(String name, Scriptable start) {
switch (name) {
case "name":
return "wrapped " + this.proc.getName();
case "arity":
case "length":
return "wrapped " + this.proc.id();
case "arity", "length":
Bindings bindings = proc.getBindings();
int args = 0;
try {
Expand Down
1 change: 1 addition & 0 deletions src/java/org/rapidcontext/core/proc/AddOnProcedure.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @version 1.0
*/
@Deprecated(forRemoval=true)
@SuppressWarnings({"deprecation", "removal"})
public abstract class AddOnProcedure implements Procedure {

/**
Expand Down
91 changes: 82 additions & 9 deletions src/java/org/rapidcontext/core/proc/CallContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.rapidcontext.core.type.ConnectionException;
import org.rapidcontext.core.type.Environment;
import org.rapidcontext.core.type.Role;
import org.rapidcontext.core.type.Procedure;
import org.rapidcontext.core.type.User;
import org.rapidcontext.util.DateUtil;

Expand Down Expand Up @@ -434,6 +435,26 @@ public Object execute(String name, Object[] args)
}
}

/**
* Reserves all adapter connections needed for executing the
* specified procedure. The reservation will be forwarded to the
* current call interceptor. Any connection or procedure in the
* default procedure bindings will be reserved recursively in
* this call context.
*
* @param proc the procedure definition
*
* @throws ProcedureException if the connections couldn't be
* reserved
*
* @deprecated Replaced with org.rapidcontext.core.type.Procedure signature.
*/
@Deprecated(forRemoval=true)
@SuppressWarnings({"deprecation", "removal"})
public void reserve(org.rapidcontext.core.proc.Procedure proc) throws ProcedureException {
this.reserve((Procedure) proc);
}

/**
* Reserves all adapter connections needed for executing the
* specified procedure. The reservation will be forwarded to the
Expand All @@ -447,7 +468,7 @@ public Object execute(String name, Object[] args)
* reserved
*/
public void reserve(Procedure proc) throws ProcedureException {
checkAccess("procedure/" + proc.getName(), readPermission(0));
checkAccess("procedure/" + proc.id(), readPermission(0));
getInterceptor().reserve(this, proc);
}

Expand All @@ -463,6 +484,32 @@ public void releaseAll(boolean commit) {
getInterceptor().releaseAll(this, commit);
}

/**
* Calls a procedure with the specified arguments. The call will
* be forwarded to the current call interceptor. The arguments
* must be specified in the same order as in the default bindings
* for the procedure. All the required arguments must be provided
* and all connections must already have been reserved. Use
* execute() when a procedure is to be called from outside a
* prepared call context.
*
* @param proc the procedure definition
* @param args the call arguments
*
* @return the call bindings
*
* @throws ProcedureException if the argument binding failed
*
* @deprecated Replaced with org.rapidcontext.core.type.Procedure signature.
*/
@Deprecated(forRemoval=true)
@SuppressWarnings({"deprecation", "removal"})
public Object call(org.rapidcontext.core.proc.Procedure proc, Object[] args)
throws ProcedureException {

return this.call((Procedure) proc, args);
}

/**
* Calls a procedure with the specified arguments. The call will
* be forwarded to the current call interceptor. The arguments
Expand Down Expand Up @@ -498,7 +545,7 @@ public Object call(Procedure proc, Object[] args)
callBindings.set(name, Bindings.CONNECTION, connections.get(id), null);
} else {
String msg = "no connection '" + name +
"' reserved for " + proc.getName();
"' reserved for " + proc.id();
throw new ProcedureException(msg);
}
} else if (bindings.getType(name) == Bindings.ARGUMENT) {
Expand All @@ -509,19 +556,47 @@ public Object call(Procedure proc, Object[] args)
pos++;
} catch (ProcedureException ignore) {
String msg = "missing '" + name + "' (" + (pos + 1) +
") argument for " + proc.getName();
") argument for " + proc.id();
throw new ProcedureException(msg);
}
}
}
if (pos < args.length) {
String msg = "too many arguments for '" + proc.getName() +
String msg = "too many arguments for '" + proc.id() +
"'; expected " + pos + ", found " + args.length;
throw new ProcedureException(msg);
}
return call(proc, callBindings);
}

/**
* Calls a procedure with the specified arguments. The call will
* be forwarded to the current call interceptor. All the
* required arguments must be provided and all connections must
* already have been reserved. Use execute() when a procedure is
* to be called from outside a prepared call context.
*
* @param proc the procedure definition
* @param bindings the bindings to use
*
* @return the result of the call, or
* null if the call produced no result
*
* @throws ProcedureException if the call execution caused an
* error
*
* @see #execute(String, Object[])
*
* @deprecated Replaced with org.rapidcontext.core.type.Procedure signature.
*/
@Deprecated(forRemoval=true)
@SuppressWarnings({"deprecation", "removal"})
public Object call(org.rapidcontext.core.proc.Procedure proc, Bindings bindings)
throws ProcedureException {

return this.call((Procedure) proc, bindings);
}

/**
* Calls a procedure with the specified arguments. The call will
* be forwarded to the current call interceptor. All the
Expand All @@ -546,11 +621,9 @@ public Object call(Procedure proc, Bindings bindings)
if (isInterrupted()) {
throw new ProcedureException(proc, "call interrupted");
}
if (proc instanceof org.rapidcontext.core.type.Procedure p) {
String deprecated = p.deprecated();
if (deprecated != null) {
LOG.warning("deprecated: " + proc + " called; " + deprecated);
}
String deprecated = proc.deprecated();
if (deprecated != null) {
LOG.warning("deprecated: " + proc + " called; " + deprecated);
}
stack.push(proc, bindings);
try {
Expand Down
24 changes: 21 additions & 3 deletions src/java/org/rapidcontext/core/proc/CallStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.util.ArrayList;

import org.rapidcontext.core.type.Procedure;

/**
* A procedure call stack. The stack contains an ordered list of the
* procedures currently being called.
Expand All @@ -35,6 +37,22 @@ public class CallStack {
*/
public CallStack() {}

/**
* Checks if the specified procedure exists in the call stack.
*
* @param proc the procedure definition
*
* @return true if the procedure exists in the call stack, or
* false otherwise
*
* @deprecated Replaced with org.rapidcontext.core.type.Procedure signature.
*/
@Deprecated(forRemoval=true)
@SuppressWarnings({"deprecation", "removal"})
public boolean contains(org.rapidcontext.core.proc.Procedure proc) {
return stack.contains(proc);
}

/**
* Checks if the specified procedure exists in the call stack.
*
Expand Down Expand Up @@ -64,7 +82,7 @@ public int height() {
* null if the stack is empty
*/
public Procedure bottom() {
return (stack.size() > 0) ? stack.get(0) : null;
return stack.isEmpty() ? null : stack.get(0);
}

/**
Expand All @@ -75,7 +93,7 @@ public Procedure bottom() {
* null if the stack is empty
*/
public Procedure top() {
return (stack.size() > 0) ? stack.get(stack.size() - 1) : null;
return stack.isEmpty() ? null : stack.get(stack.size() - 1);
}

/**
Expand Down Expand Up @@ -103,7 +121,7 @@ void push(Procedure proc, Bindings bindings) {
* Removes the last entry in the call stack.
*/
void pop() {
if (stack.size() > 0) {
if (!stack.isEmpty()) {
stack.remove(stack.size() - 1);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/rapidcontext/core/proc/DefaultInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.rapidcontext.core.proc;

import org.rapidcontext.core.type.Procedure;
import org.rapidcontext.core.type.Role;

/**
Expand Down Expand Up @@ -102,7 +103,7 @@ public Object call(CallContext cx, Procedure proc, Bindings bindings)

long start = System.currentTimeMillis();
try {
cx.logCall(proc.getName(), bindings);
cx.logCall(proc.id(), bindings);
Object obj = proc.call(cx, bindings);
cx.logResponse(obj);
cx.getLibrary().report(proc, start, true, null);
Expand Down
52 changes: 50 additions & 2 deletions src/java/org/rapidcontext/core/proc/Interceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package org.rapidcontext.core.proc;

import org.rapidcontext.core.type.Procedure;

/**
* A procedure call interceptor. This is an abstract class that
* allows subclasses to override, monitor or extend any resource
Expand Down Expand Up @@ -56,6 +58,27 @@ public final Interceptor getParent() {
return parent;
}

/**
* Reserves all adapter connections needed for executing the
* specified procedure. All connections needed by imported
* procedures will also be reserved recursively.
*
* @param cx the procedure context
* @param proc the procedure definition
*
* @throws ProcedureException if the connections couldn't be
* reserved
*
* @deprecated Replaced with org.rapidcontext.core.type.Procedure signature.
*/
@Deprecated(forRemoval=true)
@SuppressWarnings({"deprecation", "removal"})
public void reserve(CallContext cx, org.rapidcontext.core.proc.Procedure proc)
throws ProcedureException {

reserve(cx, (Procedure) proc);
}

/**
* Reserves all adapter connections needed for executing the
* specified procedure. All connections needed by imported
Expand All @@ -67,10 +90,11 @@ public final Interceptor getParent() {
* @throws ProcedureException if the connections couldn't be
* reserved
*/
@SuppressWarnings({"deprecation", "removal"})
public void reserve(CallContext cx, Procedure proc)
throws ProcedureException {

parent.reserve(cx, proc);
parent.reserve(cx, (org.rapidcontext.core.proc.Procedure) proc);
}

/**
Expand All @@ -85,6 +109,29 @@ public void releaseAll(CallContext cx, boolean commit) {
parent.releaseAll(cx, commit);
}

/**
* Calls a procedure with the specified bindings.
*
* @param cx the procedure context
* @param proc the procedure definition
* @param bindings the procedure bindings
*
* @return the result of the call, or
* null if the call produced no result
*
* @throws ProcedureException if the call execution caused an
* error
*
* @deprecated Replaced with org.rapidcontext.core.type.Procedure signature.
*/
@Deprecated(forRemoval=true)
@SuppressWarnings({"deprecation", "removal"})
public Object call(CallContext cx, org.rapidcontext.core.proc.Procedure proc, Bindings bindings)
throws ProcedureException {

return call(cx, (Procedure) proc, bindings);
}

/**
* Calls a procedure with the specified bindings.
*
Expand All @@ -98,9 +145,10 @@ public void releaseAll(CallContext cx, boolean commit) {
* @throws ProcedureException if the call execution caused an
* error
*/
@SuppressWarnings({"deprecation", "removal"})
public Object call(CallContext cx, Procedure proc, Bindings bindings)
throws ProcedureException {

return parent.call(cx, proc, bindings);
return parent.call(cx, (org.rapidcontext.core.proc.Procedure) proc, bindings);
}
}
Loading

0 comments on commit 8c8b2d8

Please sign in to comment.