Let’s first understand the concept using newspaper subscription. I subscribe to a monthly newspaper. I signed a contract with the company and received a newspaper every month. The contract records what I have subscribed to. The company which produces the newspapers will look at the contract and send the product to me each month. I am also able to unsubscribe through their website. In this example, we have three objects, the company producing the products, the receiver(me), and the contract. The important and subtle object is the contract. It’s the contract that connects me and the company together.
Another example, I have subscribed to two copies of the same products. Each of them is monthly. However, I actually don’t get a monthly delivery. Instead, the company sends the goods to me every two months because they want to save delivery fees. …
The core design idea behind GraphQL is to treat our application as a database. A database is able to return the values restricted by the fields specified in the select statement. GraphQL gives the frontend the options of returning only the fields it specifies.
In the following, we compare GraphQL architecture with the Rest architecture.
In the Rest architecture, there are multiple controllers, facades, services and DAOs. Every controller is responsible for different request mapping. In controllers, we deal with DTO. Facade is usually used for data conversion between DTO and DAO. …
Before talking about Work Stealing, we need to talk about task management. We could use Tomcat as one example. Tomcat will use multiple threads to handle concurrent connections. The number of threads can go very high when there are many concurrent connections at the same time.
However, a computer has a fixed number of cores. The number of threads that could be run at the same time is equal to the number of cores. All other threads have to be in waiting/ready states. The ready state threads will be scheduled to take over the CPU when the current running thread starts to do blocking IO. Scheduling in and out of threads is done by OS and it takes time. Too many threads will also consume more system resources, like the memory used for the thread data structure. …
This article is based on some basic understanding of Rabbitmq(Queue,Consumer,Producer etc). When communicating with Rabbitmq server, a connection is required. The design of the connection in any framework is more or less the same. The Connection has to wrap a TCP/UDP Socket connection in one way or another. In amqp-client, SocketFrameHandler is used to wrap a TCP Socket.
SocketFrameHandler provides the functionality of reading from and writing to the socket.
Netty is one NIO framework in Java. What Netty provides is the event loop. If you don’t understand what event loop is, please read https://medium.com/@Ryan_Zheng/event-loop-distilled-3a47b9923c66.
NIO In General
In network programming, the server socket needs to bind to a port and network interface. Then the server socket will call accept function. This accept function will return a new Socket when a new client connects to the server. Now the server and client can communicate over this connected socket. The server socket could return to accept function again to wait for other connections.
server = new ServerSocket(port, interface)newSocket = server.accept()
The socket could be nonblocking. When it’s a non-block socket, the function call on the socket will return immediately. OS provides select, poll, epoll etc to check whether there are events on the socket, such as data coming, new connections. Epoll scales better than select. …
The Channel here we talked about is different from the Channel in Java NIO. NIO Channel is a wrapper around file descriptors. The Channel here is about message sending.
Spring Channel is the fundamental building block of Spring Messaging. Channel is a way to send messages. Here send means literally “send”. That’s why the very top interface of Spring Channel has only send method.
Since MessageChannel is a way to send messages, so who is invoking the send method?
The answer is some other consumer is using the channel to send messages.
But we care about how to connect channels together, pipe the messages down the stream. Since the send method of the channel is used to send a message. Then we could just call another channel’s send method inside the current channel to link the channels together. Dummy implementation looks like…
Before we are able to understand what event loop is, we have to understand what problem the event loop wants to solve.
Let’s first describe the problem by using one example.
When we open a file for reading, if we synchronously read the content, the current thread will be blocked until the read is successful. When a file is being open for read, there are two modes you could choose, synchronous and asynchronous.
Synchronous read: The OS kernel will put the thread onto the wait state and when the kernel finishes the read and puts the read data into the file descriptor buffer, it will wake up this thread. …
There are many articles on the internet explaining what JoinColumn and MappedBy do in Hibernate. But I always find it confusing, and I always forget after a while.
I know that if I keep forgetting something that I learned, that means I didn’t really understand it in the first place.
So today I want to explain what uni-directional, bi-directional from a human-understandable way instead of using a bunch of codes that do not explain the essence.
Let’s use Room, Channels as an example. One Room could have many Channels.
So what is really JoinColumn saying?
JoinColumn basically mandates that it is me who is controlling the creation of the foreign key column. Since I am controlling it, of course, I know what the column name of the foreign key is. …