MODEL SISTEM
TERDISTRIBUSI
MODEL DS?
• Hubungan dan interkoneksi antar
komponen penyusun sistem
Model Client Server
Server
Client
Client
Client Client
Model Client Server
• Client:
– Proses akses data
– Melakukan operasi pada komputer lain
• Server:
– Proses mengatur data
– Proses mengatur resources
– Proses komputasi
Model Multiple Server
Server
Server
Server
Client
Client
Model Multiple Server
• Service disediakan oleh beberapa server
• Contoh:
– Sebuah situs yang jalankan dibeberapa
server
• Server menggunakan replikasi atau
database terdistribusi
Model Proxy Server
Proxy Server
Server
Server
Client
Model Proxy Server
• Proxy server membuat duplikasi beberapa
server yang diakses oleh client
• Caching:
– Penyimpanan lokal untuk item yang sering
diakses
Contoh Model Proxy Server
• Searching satu topik namun dilakukan dua
kali maka searching terakhir memiliki
waktu yang lebih kecil
Model Mobile Code
Web
Server
Web
Client
Request Applet CodeModel Mobile Code
• Kode yang berpindah dan dijalankan pada
pc yang berbeda
• Contoh: Applet
Model Mobile Agent
• Sebuah program yang berpindah dari satu
komputer ke komputer yang lain
• Melakukan perkerjaan otomatis
• Contoh:
– Untuk install dan pemeliharan software pada
komputer sebuah organisasi
KOMUNIKASI ANTAR PROSES
Inter Process Communication
Komunikasi Antar Proses
• Remote Procedure Call (RPC)
• Remote Object Invocation
• Message-Oreinted Communication
Procedure Call
Local vs Remote Proc Call
• Local Procedure Call:
– Proses client dan server berada dalam satu
PC
• Remote Procedure Call:
– Sebuah proses dalam PC lokal memanggil
procedure proses di PC lain
Model RPC
Langkah2 RPC
1. Client memanggil procedure lokal (client stub)
secara normal. Client Stub=actual remote
procedure
2. Client stub membuat network message yang
berisi nama procedure dan parameternya dan
memanggil OS lokal
3. OS client mengirim message ke OS remote
4. Remote OS memberikan message ke Server
5. Server stub mengambil nama procedure dan
parameternya dari dalam message. Server
stub memanggil procedure dari proses server
6. Server mengeksekusi procedure dan
memberikan hasilnya ke server stub
7. Server stub memasukkan hasil ke dalam
message dan memanggil OS server
8. OS server mengirimkan message ke OS
client
9. OS client memberikan message ke client
stub
10. Client stub membaca hasilnya dan
memberikannya ke proses client
Binding a client to a server
RPC Implementation
• Sun Microsystems’ Open Network
Computing:
• Open Software Foundation – Distributed
Computing Environment
• Xerox Courier
Remote Object Invocation
Background
• RPC:
– Standar de facto untuk komunikasi dalam
sistem terdistribusi
• Teknologi berbasis object:
– Sudah terbukti bagus untuk pengembangan
aplikasi stand alone
Distributed Object
• Obejct:
– Data
– Operation/Methode diakses melalui
Interface
• Object dan Interface berada di mesin yang
lain
Proxy
(istilah dalam remote object)
• Apa?
– Mirip dengan client stub dalam RPC
– Implementasi Interface Object yang mana
object sesungguhnya berada di mesin yang
lain
– Proxy berjalan di address space client
• Marshals/assamble method invocation intomessage
• Unmarshals/disassemble reply message to client
Skeleton
• Apa?
– Mirip dengan server stub dalam RPC
• Fungsi:
– Unmarshals incoming invocation request to
proper method invocation at the object
interface at server
Implementasi?
• Java RMI (Remote Method Invocation)
• Teknologi DS yang memungkinkan
sebuah JVM memanggil metode sebuah
object yang berjalan di JVM yang lain
Ilustrasi
Local Machine (Client)
SampleServer remoteObject; int s;
…
s = remoteObject.sum(1,2);
System.out.println(s);
Remote Machine (Server)
public int sum(int a,int b) { return a + b;
}
1,2
• Aplikasi RMI sering terbagi menjadi dua bagian: server dan client.
• Server mempunyai beberapa remote objects, dan reference-nya, serta menunggu jika client ingin memanggil remote object tersebut
• Client mendapatkan remote refernce untuk satu atau lebih remote object di dalam server, dan kemudian memanggil metode di dalamnya.
• RMI menyediakan mekanisme sehingga server dan client dapat berkomunikasi dan tukar menukar informasi timbal balik. Aplikasi seperti ini disebut dengan
distributed object application.
Remote Interfaces, Remote
Objects, Remote Methods
• Aplikasi terdistribusi dengan Java RMI terdiri atas interfaces and classes.
• Interfaces mendifinisikan methods. Class
meng-implement metode yang didefinisikan di dalam interfaces • Objects (perwujudan dari class) yang mempunyai
metode tersebut (yang dapat dipanggil dari jauh) disebut dengan remote objects.
• Suatu object akan menjadi remote jika meng-implement suatu remote interface, yang mempunyai karakteristik sbb
• RMI memperlakukan remote object berbeda dengan yang non-remote object, ketika object tersebut dikirim ke VM yang lain.
• Selain membuat copy object ke VM penerima, RMI mengirim satu remote stub untuk satu remote object.
– stub ini beraksi sebagai perwakilan lokal, proxy, untuk remote object tsb, dan untuk pemanggilnya, remote reference. – Remote reference memanggil metode pada stub lokal, yang
bertanggung jawab untuk memanggil ke remote object.
• Stub (untuk remote object) meng-implements remote interfaces yang remote object juga meng-implements.
Arsitektur RMI
• The server must first bind its name to the
registry
• The client lookup the server name in the
registry to establish remote references.
• The Stub serializing the parameters to
skeleton, the skeleton invoking the remote
method and serializing the result back to
the stub.
S
tu
b
RMI Client RMI Server
s k e le to n return call Registry lookup bind
Stub dan Skeleton
• A client invokes a remote method, the call is first
forwarded to stub.
• The stub is responsible for sending the remote
call over to the server-side skeleton
• The stub opening a socket to the remote server,
marshaling the object parameters and
forwarding the data stream to the skeleton.
• A skeleton contains a method that receives the
S
tu
b
RMI Client RMI Server
s k e le to n return call
Membuat Aplikasi Terdistribusi
dengan RMI
•
Ada beberapa langkah untuk membuat aplikasi
terdistribusi dengan RMI
– Buat satu (atau lebih) Remote Interface
– Buat Class di server (remote object) yang meng-implement Remote Interface tersebut
– Buat program di client yang memanggil remote object tersebut
– Kompilasi source dan generate stub dan skeleton – Start RMI Registry
Design Remote Interface
• To create an RMI application, the first step is the defining of a remote interface between the client and server objects.
• remote interfaces: menspesifikasikan metode yang dapat dipanggil oleh client.
• /* SampleServer.java */ • import java.rmi.*;
• public interface SampleServer extends Remote • {
• public int sum(int a,int b) throws RemoteException; • }
Remote Object
• Remote objects harus meng-implement satu atau lebih remote interfaces. Remote object class bisa saja meng-implement interface yang lain (baik lokal ataupun remote) dan metode yang lain (yang hanya lokal)
• The server is a simple unicast remote server.
• Create server by extending java.rmi.server.UnicastRemoteObject. • The server uses the RMISecurityManager to protect its resources
while engaging in remote communication.
• The server must bind its name to the registry, the client will look up the server name.
Remote Object
• /* SampleServerImpl.java */ • import java.rmi.*;
• import java.rmi.server.*; • import java.rmi.registry.*;
• public class SampleServerImpl extends UnicastRemoteObject
• implements SampleServer {
• SampleServerImpl() throws RemoteException { • super();
• }
• public int sum(int a,int b) throws RemoteException { • return a + b;
• }
Remote Object
• public static void main(String args[]) { • try {
• System.setSecurityManager(new RMISecurityManager()); • //set the security manager
• //create a local instance of the object
• SampleServerImpl Server = new SampleServerImpl(); • //put the local instance in the registry
• Naming.rebind("SAMPLE-SERVER" , Server);
• System.out.println("Server waiting...");
• }
• catch (java.net.MalformedURLException me) {
Program Client
• In order for the client object to invoke methods on the server, it must first look up the name of server in the registry. You use the java.rmi.Naming class to lookup the server name.
• The server name is specified as URL in the from ( rmi://host:port/name )
• Default RMI port is 1099.
• The name specified in the URL must exactly match the name that the server has bound to the registry. In this example, the name is “SAMPLE-SERVER”
• The remote method invocation is programmed using the remote interface name (remoteObject) as prefix and the remote method name (sum) as suffix.
Program Client
• import java.rmi.*;
• import java.rmi.server.*;
• public class SampleClient {
•
public static void main(String[] args) {
•
// set the security manager for the client
•
System.setSecurityManager(new
• try {
•
System.out.println("Security Manager
loaded");
•
String url = "//localhost/SAMPLE-SERVER";
•
SampleServer remoteObject =
(SampleServer)Naming.lookup(url);
•
System.out.println("Got remote object");
•
System.out.println(" 1 + 2 = " +
remoteObject.sum(1,2) );
•
}
• catch (RemoteException exc) {
• System.out.println("Error in lookup: " + exc.toString()); }
• catch (java.net.MalformedURLException exc) { • System.out.println("Malformed URL: " +
exc.toString()); }
• catch (java.rmi.NotBoundException exc) {
• System.out.println("NotBound: " + exc.toString()); • }
• } • }
Compile sources dan buat
(generate) stubs
• Pertama, gunakan javac compiler untuk
meng-kompile source files, yang di sana terdapat
implementasi remote interfaces, server class,
dan client classes.
• Kedua, gunakan rmic compiler untuk membuat
stubs untuk remote objects. RMI menggunakan
stub remote object sebagai proxy pada clients,
sehingga client dapat berkomunikasi dengan
remote object tertentu.
javac SampleServer.java
javac SampleServerImpl.java
rmic SampleServerImpl
Start RMI Registry
• The RMI applications need install to Registry. And the Registry must start manual by call rmiregisty.
• The rmiregistry us uses port 1099 by default. You can also bind rmiregistry to a different port by indicating the new port number as : rmiregistry <new port>
•
• # rmiregistry
• Remark: On Windows, you have to type in from the
command line:
• > start rmiregistry
Start Server dan Client
• Once the Registry is started, the server can be started and will be able to store itself in the Registry.
• Because of the grained security model in Java 2.0, you must setup a security policy for RMI by set
java.security.policy to the file policy.all
• elpis:~/rmi> java –Djava.security.policy=policy.all SampleServerImpl