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

Do not expose runtime.internal imports in runtime.api package #40212

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8a75273
Remove internal imports in StrandMetadata
Nadeeshan96 Apr 3, 2023
7415859
Remove internal imports in creator APIs
Nadeeshan96 Apr 3, 2023
000083e
Remove internal imports in types package
Nadeeshan96 Apr 11, 2023
11b2ad7
Remove internal imports in utils package
Nadeeshan96 Apr 11, 2023
4ddc3b2
Deprecate StringUtils.getStringValue method
Nadeeshan96 Apr 12, 2023
627d632
Deprecate StringUtils.getExpressionStringValue
Nadeeshan96 Apr 12, 2023
d6ae1c8
Deprecate StringUtils.parseExpressionStringValue
Nadeeshan96 Apr 12, 2023
1ed5f5d
Remove internal imports in TypeUtils and XmlUtils
Nadeeshan96 Apr 12, 2023
14a1ca7
Remove internal imports in values package
Nadeeshan96 Apr 17, 2023
6d6593f
Change return type of BString.getIterator()
Nadeeshan96 Apr 17, 2023
e40bcf4
Remove internal imports in api package
Nadeeshan96 Apr 17, 2023
25704cd
Fix failing test
Nadeeshan96 Apr 17, 2023
7b1a8fd
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 Apr 21, 2023
844779f
Replace internal objects with proper ones
Nadeeshan96 Apr 21, 2023
22a6578
Deprecate methods that accept or return internals
Nadeeshan96 Apr 21, 2023
fc7da55
Refactor Environment Future and Runtime classes
Nadeeshan96 Apr 21, 2023
5f275e7
Fix code generation issues
Nadeeshan96 May 2, 2023
4c14846
Remove deprecated getCurrentRuntime API
Nadeeshan96 May 2, 2023
520372f
Fix failing test
Nadeeshan96 May 2, 2023
e571262
Change interfaces to abstract classes
Nadeeshan96 May 2, 2023
8b6aedd
Add deprecated getCurrentRuntime method back
Nadeeshan96 May 2, 2023
ecb721b
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 May 2, 2023
fb65e40
Address PR review comments
Nadeeshan96 May 8, 2023
fc68a15
Extend BObject with BRefValue
Nadeeshan96 May 8, 2023
d13db25
Change runtime casts of RefValue to BRefValue
Nadeeshan96 May 9, 2023
c8d9093
Change codegen instance of check to BRefValue
Nadeeshan96 May 9, 2023
879282d
Change RefValue usages to BRefValue
Nadeeshan96 May 9, 2023
ba62f35
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 May 9, 2023
593dde0
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 May 11, 2023
c24a2fb
Remove unnecessary blank lines
Nadeeshan96 May 11, 2023
35bb219
Address PR review comments
Nadeeshan96 May 15, 2023
fcbcb3a
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 May 15, 2023
d8cf259
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 May 16, 2023
d916107
Move PredefinedTypes private constructor
Nadeeshan96 May 16, 2023
e6c3ade
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 May 17, 2023
0485e50
Merge branch 'master' into master-remove-imports-38077
Nadeeshan96 May 18, 2023
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 @@ -149,7 +149,7 @@ public static String encodeIdentifier(String string) {
* @return Converted string.
*/
public static String getExpressionStringValue(Object object) {
return io.ballerina.runtime.api.utils.StringUtils.getExpressionStringValue(object, null);
return io.ballerina.runtime.api.utils.StringUtils.getExpressionStringValue(object);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,131 +19,90 @@

import io.ballerina.runtime.api.async.StrandMetadata;
import io.ballerina.runtime.api.types.Parameter;
import io.ballerina.runtime.internal.scheduling.State;
import io.ballerina.runtime.internal.scheduling.Strand;

import java.util.Optional;

/**
* When this class is used as the first argument of an interop method, Ballerina will inject an instance of the class
* when calling. That instance can be used to communicate with currently executing Ballerina runtime.
* When this class is used as the first argument of an interop method, Ballerina will inject an instance of
* the class when calling. That instance can be used to communicate with currently executing Ballerina runtime.
*
* @since 2.0.0
*/
public class Environment {

private final Strand strand;
private Future future;
private Module currentModule;
private String funcName;
private Parameter[] funcPathParams;

public Environment(Strand strand) {
this.strand = strand;
}

public Environment(Strand strand, Module currentModule) {
this.strand = strand;
this.currentModule = currentModule;
future = new Future(this.strand);
}

public Environment(Strand strand, Module currentModule, String funcName, Parameter[] funcPathParams) {
this(strand, currentModule);
this.funcName = funcName;
this.funcPathParams = funcPathParams;
}
public abstract class Environment {

/**
* Returns the Ballerina function name for the corresponding external interop method.
*
* @return function name
*/
public String getFunctionName() {
return funcName;
}
public abstract String getFunctionName();

/**
* Returns an array consisting of the path parameters of the resource function defined as external.
*
* @return array of {@link Parameter}
*/
public Parameter[] getFunctionPathParameters() {
return funcPathParams;
}
public abstract Parameter[] getFunctionPathParameters();

/**
* Mark the current executing strand as async. Execution of Ballerina code after the current
* interop will stop until given BalFuture is completed. However the java thread will not be blocked
* interop will stop until given Ballerina Future is completed. However the java thread will not be blocked
* and will be reused for running other Ballerina code in the meantime. Therefore callee of this method
* must return as soon as possible to avoid starvation of ballerina code execution.
* must return as soon as possible to avoid starvation of Ballerina code execution.
*
* @return BalFuture which will resume the current strand when completed.
* @return {@link Future} which will resume the current strand when completed.
*/
public Future markAsync() {
strand.blockedOnExtern = true;
strand.setState(State.BLOCK_AND_YIELD);
return future;
}
public abstract Future markAsync();

public Runtime getRuntime() {
return new Runtime(strand.scheduler);
}
/**
* Gets an instance of Ballerina runtime.
*
* @return Ballerina runtime instance.
*/
public abstract Runtime getRuntime();

/**
* Gets current module @{@link Module}.
* Gets current module {@link Module}.
*
* @return module of the environment.
*/
public Module getCurrentModule() {
return currentModule;
}
public abstract Module getCurrentModule();

/**
* Gets the strand id. This will be generated on strand initialization.
*
* @return Strand id.
*/
public int getStrandId() {
return strand.getId();
}
public abstract int getStrandId();

/**
* Gets the strand name. This will be optional. Strand name can be either name given in strand annotation or async
* call or function pointer variable name.
*
* @return Optional strand name.
*/
public Optional<String> getStrandName() {
return strand.getName();
}
public abstract Optional<String> getStrandName();

/**
* Gets @{@link StrandMetadata}.
* Gets {@link StrandMetadata}.
*
* @return metadata of the strand.
*/
public StrandMetadata getStrandMetadata() {
return strand.getMetadata();
}
public abstract StrandMetadata getStrandMetadata();

/**
* Sets given local key value pair in strand.
*
* @param key string key
* @param value value to be store in the strand
*/
public void setStrandLocal(String key, Object value) {
strand.setProperty(key, value);
}
public abstract void setStrandLocal(String key, Object value);

/**
* Gets the value stored in the strand on given key.
*
* @param key key
* @return value stored in the strand.
*/
public Object getStrandLocal(String key) {
return strand.getProperty(key);
}
public abstract Object getStrandLocal(String key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,12 @@

package io.ballerina.runtime.api;

import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.internal.scheduling.Strand;
import io.ballerina.runtime.internal.values.MapValueImpl;

import java.util.concurrent.atomic.AtomicBoolean;

/**
* A future that will resume the underling strand when completed.
*
* @since 2.0.0
*/
public class Future {
private final Strand strand;
private final AtomicBoolean visited = new AtomicBoolean();
Future(Strand strand) {
this.strand = strand;
}
public abstract class Future {

public void complete(Object returnValue) {
if (visited.getAndSet(true)) {
throw ErrorCreator.createError(StringUtils.fromString("cannot complete the same future twice."),
new MapValueImpl<>(PredefinedTypes.TYPE_ERROR_DETAIL));
}
strand.returnValue = returnValue;
strand.scheduler.unblockStrand(strand);
}
public abstract void complete(Object returnValue);
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import io.ballerina.runtime.api.types.StringType;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.types.TypedescType;
import io.ballerina.runtime.api.types.UnionType;
import io.ballerina.runtime.api.types.XmlAttributesType;
import io.ballerina.runtime.api.types.XmlType;
import io.ballerina.runtime.internal.IteratorUtils;
Expand Down Expand Up @@ -175,17 +176,19 @@ public class PredefinedTypes {
public static final MapType TYPE_DETAIL;
public static final Type TYPE_ERROR_DETAIL;
public static final ErrorType TYPE_ERROR;
public static final BUnionType TYPE_CLONEABLE;
public static final UnionType TYPE_CLONEABLE;

public static final BUnionType TYPE_JSON_DECIMAL;
public static final BUnionType TYPE_JSON_FLOAT;
public static final UnionType TYPE_JSON_DECIMAL;
public static final UnionType TYPE_JSON_FLOAT;

Nadeeshan96 marked this conversation as resolved.
Show resolved Hide resolved
public static final RecordType STRING_ITR_NEXT_RETURN_TYPE =
IteratorUtils.createIteratorNextReturnType(PredefinedTypes.TYPE_STRING_CHAR);

public static final Type ANY_AND_READONLY_TYPE = ReadOnlyUtils.setImmutableTypeAndGetEffectiveType(TYPE_ANY);
public static final Type ANY_AND_READONLY_OR_ERROR_TYPE;

private PredefinedTypes() {}

// type anydata = ()|boolean|int|float|decimal|string|xml|anydata[]|map<anydata>|table<map<anydata>>
static {
ArrayList<Type> members = new ArrayList<>();
Expand All @@ -201,9 +204,6 @@ public class PredefinedTypes {
TYPE_ANYDATA_ARRAY = new BArrayType(TYPE_ANYDATA);
}

private PredefinedTypes() {
}

private static BAnydataType getAnydataType(List<Type> members, String typeName, boolean readonly) {
BAnydataType anydataType = new BAnydataType(new BUnionType(TypeConstants.ANYDATA_TNAME, EMPTY_MODULE, members
, readonly), typeName, readonly);
Expand Down
Loading