Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 018f9077 authored by dzak27567's avatar dzak27567
Browse files

Answer Reflection Subscriber-1

parent 09e59325
No related branches found
No related tags found
No related merge requests found
# BambangShop Receiver App
Tutorial and Example for Advanced Programming 2024 - Faculty of Computer Science, Universitas Indonesia
Tutorial and Example for Advanced Programming 2025 - Faculty of Computer Science, Universitas Indonesia
---
......@@ -59,15 +59,15 @@ You can install Postman via this website: https://www.postman.com/downloads/
- Open another new terminal, edit `ROCKET_PORT` in `.env` to `8003`, then execute `cargo run`.
## Mandatory Checklists (Subscriber)
- [ ] Clone https://gitlab.com/ichlaffterlalu/bambangshop-receiver to a new repository.
- [x] Clone https://gitlab.com/ichlaffterlalu/bambangshop-receiver to a new repository.
- **STAGE 1: Implement models and repositories**
- [ ] Commit: `Create Notification model struct.`
- [ ] Commit: `Create SubscriberRequest model struct.`
- [ ] Commit: `Create Notification database and Notification repository struct skeleton.`
- [ ] Commit: `Implement add function in Notification repository.`
- [ ] Commit: `Implement list_all_as_string function in Notification repository.`
- [ ] Write answers of your learning module's "Reflection Subscriber-1" questions in this README.
- **STAGE 3: Implement services and controllers**
- [x] Commit: `Create Notification model struct.`
- [x] Commit: `Create SubscriberRequest model struct.`
- [x] Commit: `Create Notification database and Notification repository struct skeleton.`
- [x] Commit: `Implement add function in Notification repository.`
- [x] Commit: `Implement list_all_as_string function in Notification repository.`
- [x] Write answers of your learning module's "Reflection Subscriber-1" questions in this README.
- **STAGE 2: Implement services and controllers**
- [ ] Commit: `Create Notification service struct skeleton.`
- [ ] Commit: `Implement subscribe function in Notification service.`
- [ ] Commit: `Implement subscribe function in Notification controller.`
......@@ -85,5 +85,13 @@ This is the place for you to write reflections:
### Mandatory (Subscriber) Reflections
#### Reflection Subscriber-1
> In this tutorial, we used RwLock<> to synchronise the use of Vec of Notifications. Explain why it is necessary for this case, and explain why we do not use Mutex<> instead?
1. Dalam tutorial ini kita menggunakan `RwLock<>` untuk menyinkronisasi vektor `Notification` karena ia memungkinkan banyak thread membaca data secara bersamaan, namun hanya satu thread yang dapat menulis pada satu waktu. Ini sangat efisien karena dalam aplikasi web kita, operasi pembacaan notifikasi jauh lebih sering terjadi dibanding penulisan. Jika menggunakan `Mutex<>`, hanya satu thread yang dapat mengakses data pada satu waktu, baik untuk membaca maupun menulis, yang akan menciptakan bottleneck yang tidak perlu. Dengan `RwLock<>`, thread yang hanya membaca tidak akan terblokir ketika tidak ada operasi penulisan, sehingga meningkatkan konkurensi dan performa aplikasi.
> In this tutorial, we used lazy_static external library to define Vec and DashMap as a “static” variable. Compared to Java where we can mutate the content of a static variable via a static function, why did not Rust allow us to do so?
2. Rust tidak mengizinkan modifikasi langsung pada variabel static karena prinsip keamanan yang menjadi inti dari bahasa ini. Tidak seperti Java, Rust memiliki aturan ketat tentang mutabilitas untuk mencegah race condition dalam lingkungan multi-threaded. Variabel static yang bersifat global dan dapat diakses dari mana saja sehingga memungkinkan modifikasi langsung akan bertentangan dengan sistem kepemilikan dan peminjaman Rust. Oleh karena itu, kita menggunakan library lazy_static bersama dengan RwLock untuk membuat variabel static yang bisa diubah dengan aman, dengan memastikan hanya satu thread yang bisa melakukan perubahan pada satu waktu.
#### Reflection Subscriber-2
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment