Java Reference
In-Depth Information
Implementing a remote object and defining a remote interface
Examining the Factory pattern and learning why we are using it for our RMI
implementation
Marshaling and demarshaling in RMI
Registering your remote objects
Caution The next chapter describes Java sockets, which is the other networking protocol the examinee
may opt to use for the certification project. However, be advised that for the certification project, you must
send serialized objects if opting for a sockets solution as a networking protocol. Java RMI requires serializa-
tion, but it is not absolutely necessary to use serialization in a Java socket implementation. You could, for
instance, implement your own wire format in a socket implementation so that any client-side technology
could submit requests to a Java socket server. In the next chapter, we explain the technique of using sockets
with serialization objects. If you decide to implement your solution using sockets as the networking protocol,
the next section, “What Is Serialization?”, will still be useful.
What Is Serialization?
So what is serialization, and why would you need it in your program? Let's consider an example.
Suppose there are two machines on the same network. Machine A sends a message to a Java
program on machine B; how does machine B receive and understand the message? What's
required is a transfer protocol. A transfer protocol will flatten the data that needs to be trans-
ferred by putting it into a format that can be sent across a network.
Part of the process of sending data across a network involves serialization. Serialization
is the process of deconstructing an object into its components of type information and state,
and then reconstructing a copy of the original object on the receiving end by reading in the
type information and then the field values. The term often used to describe the process of
transferring serialized objects across a network is marshaling . Sometimes the reverse process,
restoring the serialized object on the other end, is referred to as demarshaling , or unmarshaling .
Serialized objects can be persisted to a local file system, courtesy of Java file I/O, or sent across a
network via a socket. This is accomplished by converting the object into a serial stream of bytes,
transmitting that stream across a network or to a file system, and then reading the persisted
byte stream back into memory in order to re-create the object graph (see Figure 6-2), which is
Java vernacular for reconstructing the original object and its state as if nothing ever happened.
When a byte stream is loaded into memory in the form of an object, it is said to be in an active
state. When that same byte stream is located in a file, rather than in a Java Virtual Machine
( JVM) memory bank, it is said to be in a passive state. Keep in mind the notion of an object
being in an active or passive state, as it will come in handy when we introduce the Activatable
interface later in this chapter. Let's discuss the process in a little more detail.
Search WWH ::




Custom Search