rocketmq_rust/
lib.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#![feature(sync_unsafe_cell)]
18#![allow(dead_code)]
19
20mod arc_mut;
21mod blocking_queue;
22pub mod count_down_latch;
23mod netty_rust;
24pub use netty_rust::timer::Timer;
25pub mod rocketmq_tokio_lock;
26mod shutdown;
27
28pub use arc_mut::ArcMut;
29pub use arc_mut::SyncUnsafeCellWrapper;
30pub use arc_mut::WeakArcMut;
31pub use blocking_queue::BlockingQueue as RocketMQBlockingQueue;
32pub use count_down_latch::CountDownLatch;
33/// Re-export rocketmq main.
34pub use rocketmq::main;
35pub use rocketmq_tokio_lock::RocketMQTokioMutex;
36pub use rocketmq_tokio_lock::RocketMQTokioRwLock;
37pub use shutdown::Shutdown;
38/// Re-export tokio module.
39pub use tokio as rocketmq;
40
41/// On unix platforms we want to intercept SIGINT and SIGTERM
42/// This method returns if either are signalled
43#[cfg(unix)]
44pub async fn wait_for_signal() {
45    use tokio::signal::unix::signal;
46    use tokio::signal::unix::SignalKind;
47    use tracing::info;
48    let mut term = signal(SignalKind::terminate()).expect("failed to register signal handler");
49    let mut int = signal(SignalKind::interrupt()).expect("failed to register signal handler");
50
51    tokio::select! {
52        _ = term.recv() => info!("Received SIGTERM"),
53        _ = int.recv() => info!("Received SIGINT"),
54    }
55}
56
57#[cfg(windows)]
58/// ctrl_c is the cross-platform way to intercept the equivalent of SIGINT
59/// This method returns if this occurs
60pub async fn wait_for_signal() {
61    let _ = tokio::signal::ctrl_c().await;
62}