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

Isolate the FTP listener #1287

Merged
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
org = "ballerina"
name = "ftp"
version = "2.9.1"
version = "2.9.2"
authors = ["Ballerina"]
keywords = ["FTP", "SFTP", "remote file", "file transfer", "client", "service"]
repository = "https://github.com/ballerina-platform/module-ballerina-ftp"
Expand Down Expand Up @@ -33,5 +33,5 @@ path = "./lib/commons-net-3.9.0.jar"
[[platform.java17.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "ftp-native"
version = "2.9.1"
path = "../native/build/libs/ftp-native-2.9.1.jar"
version = "2.9.2"
path = "../native/build/libs/ftp-native-2.9.2-SNAPSHOT.jar"
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ id = "ftp-compiler-plugin"
class = "io.ballerina.stdlib.ftp.plugin.FtpCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.9.1.jar"
path = "../compiler-plugin/build/libs/ftp-compiler-plugin-2.9.2-SNAPSHOT.jar"
4 changes: 2 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.8.0"
[[package]]
org = "ballerina"
name = "ftp"
version = "2.9.1"
version = "2.9.2"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -112,7 +112,7 @@ modules = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.2.0"
version = "1.2.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
22 changes: 14 additions & 8 deletions ballerina/listener_endpoint.bal
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
// specific language governing permissions and limitations
// under the License.

import ballerina/jballerina.java;
import ballerina/log;
import ballerina/task;
import ballerina/jballerina.java;

# Represents a service listener that monitors the FTP location.
public class Listener {
public isolated class Listener {

private handle EMPTY_JAVA_STRING = java:fromString("");
private ListenerConfiguration config = {};
Expand All @@ -30,8 +30,10 @@ public class Listener {
# + listenerConfig - Configurations for FTP listener
# + return - `()` or else an `ftp:Error` upon failure to initialize the listener
public isolated function init(ListenerConfiguration listenerConfig) returns Error? {
self.config = listenerConfig;
return initListener(self, self.config);
self.config = listenerConfig.clone();
lock {
return initListener(self, self.config);
}
}

# Starts the `ftp:Listener`.
Expand Down Expand Up @@ -91,13 +93,17 @@ public class Listener {
}

isolated function internalStart() returns error? {
self.jobId = check task:scheduleJobRecurByFrequency(new Job(self), self.config.pollingInterval);
lock {
self.jobId = check task:scheduleJobRecurByFrequency(new Job(self), self.config.pollingInterval);
}
}

isolated function stop() returns error? {
var id = self.jobId;
if id is task:JobId {
check task:unscheduleJob(id);
lock {
var id = self.jobId;
if id is task:JobId {
check task:unscheduleJob(id);
}
}
}

Expand Down
Loading