Skip to content

Commit

Permalink
Move placeholder methods to native side
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisaruGuruge committed Mar 10, 2025
1 parent d1ba32b commit b5e55c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
23 changes: 12 additions & 11 deletions ballerina/ping_message_job.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// specific language governing permissions and limitations
// under the License.

import ballerina/websocket;
import ballerina/task;
import ballerina/websocket;

class PingMessageJob {
*task:Job;
Expand Down Expand Up @@ -49,18 +49,19 @@ class PingMessageJob {

private isolated function sendPeriodicPingMessageRequests() {
do {
task:JobId? id;
lock {
task:JobId? id = self.id;
if id == () {
return;
}
if !self.caller.isOpen() {
check self.unschedule();
return;
}
PingMessage message = {'type: WS_PING};
check writeMessage(self.caller, message);
id = self.id;
}
if id == () {
return;

Check warning on line 57 in ballerina/ping_message_job.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/ping_message_job.bal#L57

Added line #L57 was not covered by tests
}
if !self.caller.isOpen() {
check self.unschedule();
return;
}
PingMessage message = {'type: WS_PING};
check writeMessage(self.caller, message);
} on fail error cause {
string message = cause is websocket:Error ? "Failed to send ping message: "
: "Failed to unschedule PingMessageJob: ";
Expand Down
16 changes: 6 additions & 10 deletions ballerina/place_holder.bal
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ isolated class Placeholder {
self.setField('field);
}

isolated function setValue(anydata value) {
lock {
self.value = value.clone();
}
}
isolated function setValue(anydata value) = @java:Method {
'class: "io.ballerina.stdlib.graphql.runtime.engine.Placeholder"
} external;

isolated function getValue() returns anydata {
lock {
return self.value.clone();
}
}
isolated function getValue() returns anydata = @java:Method {
'class: "io.ballerina.stdlib.graphql.runtime.engine.Placeholder"
} external;

isolated function setField(Field 'field) = @java:Method {
name: "setFieldValue",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@
* This class provides native implementations of the Ballerina Placeholder class.
*/
public class Placeholder {
private static final BString PLACE_HOLDER_VALUE_OBJECT = StringUtils.fromString("value");
private static final BString PLACE_HOLDER_FIELD_OBJECT = StringUtils.fromString("field");

private Placeholder() {
}

public static void setValue(BObject placeholder, Object value) {
placeholder.set(PLACE_HOLDER_VALUE_OBJECT, value);
}

public static Object getValue(BObject placeholder) {
return placeholder.get(PLACE_HOLDER_VALUE_OBJECT);
}

public static void setFieldValue(BObject placeholder, BObject field) {
placeholder.set(PLACE_HOLDER_FIELD_OBJECT, field);
}
Expand Down

0 comments on commit b5e55c8

Please sign in to comment.