Skip to content

Commit

Permalink
[ISSUE #1747]🤡Implement netty Timer for rust trait🚀 (#1750)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm authored Dec 13, 2024
1 parent 7ca0d7e commit 91b73f4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rocketmq/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
mod arc_mut;
mod blocking_queue;
pub mod count_down_latch;
mod netty_rust;
pub use netty_rust::timer::Timer;
pub mod rocketmq_tokio_lock;
mod shutdown;

Expand Down
19 changes: 19 additions & 0 deletions rocketmq/src/netty_rust.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pub mod timeout;
pub mod timer;
pub mod timer_task;
20 changes: 20 additions & 0 deletions rocketmq/src/netty_rust/timeout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

///convert from netty [Timeout](https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/Timeout.java)
#[allow(dead_code)]
pub trait Timeout {}
46 changes: 46 additions & 0 deletions rocketmq/src/netty_rust/timer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use std::collections::HashSet;
use std::sync::Arc;
use std::time::Duration;

use crate::netty_rust::timeout::Timeout;
use crate::netty_rust::timer_task::TimerTask;

///convert from netty [Timeout](https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/Timer.java)
/// A trait representing a timer that can schedule and manage timed tasks.
#[allow(dead_code)]
pub trait Timer: Send + Sync {
/// Schedules a new timeout task to be executed after the specified delay.
///
/// # Arguments
///
/// * `task` - An `Arc` containing the task to be executed.
/// * `delay` - The duration to wait before executing the task.
///
/// # Returns
///
/// An `Arc` containing the scheduled timeout.
fn new_timeout(&self, task: Arc<dyn TimerTask>, delay: Duration) -> Arc<dyn Timeout>;

/// Stops the timer and cancels all scheduled tasks.
///
/// # Returns
///
/// A `HashSet` containing all the cancelled timeouts.
fn stop(&self) -> HashSet<Arc<dyn Timeout>>;
}
20 changes: 20 additions & 0 deletions rocketmq/src/netty_rust/timer_task.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

///convert from netty [Timeout](https://github.com/netty/netty/blob/4.1/common/src/main/java/io/netty/util/TimerTask.java)
#[allow(dead_code)]
pub trait TimerTask {}

0 comments on commit 91b73f4

Please # to comment.