Pemrograman Remote Method Invocation. Husni

dokumen-dokumen yang mirip
MODEL SISTEM TERDISTRIBUSI

Pemrograman Jaringan 11 RMI

Pada Java, sebuah objek remote adalah instans dari suatu kelas yang mengimplementasikan antarmuka remote.

2.1. Sistem Komunikasi

Objek Terdistribusi dan Remote Invocation. I Made Andhika, S.Kom

Connection Oriented. Kholid F.

Client/Server dengan Java Remote Method Invocation (Java RMI), Sebuah Tutorial

Pemrograman Lanjut. Interface

BAHASA PEMROGRAMAN JAVA

Pemrograman Jaringan 12 CORBA

SISTEM PEMANTAUAN AKTIVITAS PENGGUNA PADA JARINGAN CLIENT-SERVER

Overriding Overloading Polymorphism

Pemrograman Web. Object Oriented Programming in PHP 5

Sistem Terdistribusi 5. Invocation

1. Keyword mana yang memiliki fungsi sama dengan keyword this dan menyediakan reference ke atribut turunan dari objek? super

KOMUNIKASI PENGANTAR DATA TERDISTRIBUSI. Materi: 1. Komunikasi Data 2. Protocol 3. Remote Procedure Call 4. Object Remote

Pemrograman Lanjut Class, Instance Variable dan Method PTIIK

Pemrograman Lanjut. Instance Variable Access Modifier Set dan Get Method

KONSEP OOP: POLYMORPHISM

1. Manakah jawaban yang benar,pada saat Anda mengcompile dan menjalankan class berikut ini:

Overriding, Overloading, Polymorphism. Pertemuan 10 Pemrograman Berbasis Obyek Dr. Rodiah

TUJUAN. Memahami Koneksi dan Pemrosesan Basis Data di Java Memahami JDBC Menggunakan MySQL pada program Java

06/03/2018. Tidak memiliki parameter. Melakukan inisialisasi semua variabel private dengan nilai awal.

Protokol. Pemrograman Client/Server dengan Java Socket. Protokol TCP/IP. Tipe pemrograman jaringan. Java Socket

Apa yang menjadi output potongan kode diatas? Error karena tidak ada String yang di-passing kedalam konstruktor Bapak

PRAKTIKUM 6 EXCEPTION

KONSEP OOP: POLYMORPHISM

1. Apa yang harus dilakukan oleh programmer untuk menangani user-defined exception? Menuliskan exception sebagai start method

PEMROGRAMAN SISTEM TERSEBAR

Overriding. Subclass yang berusaha memodifikasi tingkah laku yang diwarisi dari superclass. Tujuan: subclass memiliki tingkah laku yang lebih

Pemrograman Jaringan 10. Komunikasi Antar Obyek

2. Pilih instruksi yang dapat digunakan dalam method actionperformed untuk membedakan antara tombol buttonone dan buttontwo.

Network Programming 2010 Jaringan & Aplikasinya. Husni Husni.trunojoyo.ac.id

BAB V Remote Procedure Call (RPC)

DISTRIBUTED OBJECT CORBA & RMI. Sistem terdistribusi week 13

Pemrograman Jaringan 5.

PERCOBAAN 6 EXCEPTION

1.Tujuan. 2. Latar Belakang

Sukses. Kesalahan pada URL. File tidak lengkap. Kesalahan umum

BAB 8 Argumen dari Command-line

Konsep Dasar Pemrograman Berorientasi Objek

Variabel tersebut seharusnya bisa dideklarasikan didalam try block dan block catch

Waktu Sisa : 0:43:4. Sukses. Kesalahan pada URL. File tidak lengkap. Kesalahan umum. Mengerjakan finally. Diluar block

CENTOS : Membuat Server Menjadi Gateway dan Transparent Proxy dengan Squid

Common Object Request Broker Architecture (CORBA) (Minggu 4 Praktikum 1)

Exception Handling. Prepared by Viska Mutiawani. 1

Percobaan 6 Exception

Pemrograman Berorientasi Object

2 TIPE DATA DAN VARIABEL

Komunikasi Antar Proses Interprocess Communication (IPC)

Java Application. Menampilkan Tulisan

PEMROGRAMAN SOCKET LANJUTAN

JARINGAN KOMPUTER. 2. What is the IP address and port number used by gaia.cs.umass.edu to receive the file. gaia.cs.umass.edu :

Distributed Object CORBA and RMI

Java Application. Aplikasi: Menampilkan Tulisan

I/O Streams. Oleh Kholid Fathoni

PERTEMUAN 3 OBJEK DAN CLASS

5. Consider the following line of code : byte ohmy What is the range of values that could be assigned to the variable ohmy?

EXCEPTION. 2. Pada kondisi bagaimana klausa finally tidak akan dieksekusi? Kode didalam block try memiliki statement return

Exception Handling. Oleh : Agus Priyanto, M.Kom

JARINGAN KOMPUTER : ANALISA TCP MENGGUNAKAN WIRESHARK

PRAKTIKUM PEMROGRAMAN OBJEK DENGAN JAVA MODUL KE-5 EXCEPTION HANDLING

BAB 8 Argumen dari Command-line

Pemrograman Jaringan 6.

29 Februari Introduction Of Java

Membangun Aplikasi Client-Server Menggunakan Java

HTB (Hierarchical Token Bucket) Queue Tree-System Mikrotik user Meeting Jakarta, Indonesia(2016)

MODUL 3. Inheritance, Abstract Class, Interface TUJUAN PRAKTIKUM LANDASAN TEORI. A. Inheritance

BAB Tujuan. 2.2 Apa itu Exception? Pendahuluan Error dan Exception Classes

Exception Handling. Topik

Pemrograman Berorientasi Obyek (IT251) Ramos Somya, S.Kom., M.Cs.

CSG2H3 Object Oriented Programming INTERFACE -RSM-

Algoritma dan Pemrograman Leon Andretti Abdillah. 02 Basic Java with eclipse

MENGGUNAKAN TCP SOCKET. Oleh: M. Ghazali a.k.a. ghanoz 2480

PEMAHAMAN DASAR DASAR JAVA

POLIMORPHISM PEMROGRAMAN LANJUT. Dr. Eng. Herman Tolle. Sistem Informasi FILKOM UB Semester Genap 2016/2017

PERTEMUAN III OBJEK DAN CLASS TUJUAN PRAKTIKUM

Pemrograman Lanjut Class and Object PTIIK

PRAKTIKUM I EXCEPTION HANDLING

Game Technology Design Course College of Multi Media Yogyakarta Spring Tri Anggraeni, S.Kom., M.Sc.

Tidak ada satupun dari pilihan di atas yang benar karena checked exception tidak bisa ditulis

KOMUNIKASI. Universitas Informatika dan Bisnis Indonesia. 2.1 Komunikasi Data

Pertemuan 8. Dasar query basis data dengan SQLite ARFIAN HIDAYAT, S.KOM

Tutorial FDM Nurul Huda 2008, bundled by samsonasik. Modul Java 1

CONTOH PENDSTRIBUSIAN HARDWARE

OSI Data Link Layer. CCNA1-1 Chapter 7

PEMROGRAMAN SISTEM TERSEBAR

Pemrograman Berorientasi. Class dan Obyek 2

BAB II VARIABEL DAN TIPE DATA

Problem 1. Implementasi Interface. Diberikan definisi interface BentukDuaDimensi berikut:

Definisi Eksepsi (exception)

Applet (1) Oleh: Kholid Fathoni

RANCANG BANGUN PROTOTYPE RMI (REMOTE METHOD INVOCATION) UNTUK MENGHUBUNGKAN SISTEM BANK JATENG DENGAN SISTEM PEMBAYARAN UDINUS

Bab 2. Komunikasi. 1. Physical Layer

Komunikasi. Sistem Terdistribusi Reza Aditya Firdaus

TUGAS JARINGAN KOMPUTER

Pemrograman Berbasis Objek. Exception Handling. Politeknik Elektronika Negeri Surabaya

BAB Argument Command-Line dan System Properties

CSG2H3 Object Oriented Programming. Inheritance -RSM-

Transkripsi:

Pemrograman Remote Method Invocation Husni

Sasaran Hasil Belajar Setelah menyelesaikan pelajaran mengenai RMI ini, diharapkan anda: Memahami bagaimana proses-proses di dalam RMI bekerja Mampu mengimplementasi RMI (pada Bahasa Java) Mampu menjalankan client dan server RMI Mengetahui poin-poin penting keamanan RMI 2

Mengenal RMI 1. Dalam lingkungan distribusi, sering diharapkan mampu memanggil metode pada obyek jauh (yaitu pada obyek yang bertempat di sistem lain). RMI (Remote Method Invocation) menyediakan suatu sarana bebas platform untuk melakukan ini. 2. Sekali suatu referensi ke remote object diperoleh, metode dari obyek tersebut dapat dipanggil dengan cara yang sama seperti obyek berada di lokal. 3. RMI akan menggunakan aliran byte untuk mentransfer data dan pemanggilan metode. 3

Gambaran Aplikasi RMI 4

Model Client Server RMI 5

Proses RMI 6

Sistem RMI 7

Proses RMI Dasar 1. The server program that has control of the remote object registers an interface with a naming service. 2. The interface contains the signatures for those methods of the object that the server wishes to make publicly available. 3. Stub. 4. Skeleton. 5. The client program invokes a method of the remote object. 6. An equivalent method is being called in the stub. 7. Marshalling. 8. UnMarshalling. 9. Finally, the skeleton calls the implementation of the method on the server. 8

RMI Process 9

Arsitektur RMI Umum Pertama, server harus mengikatkan (bind) nama-nya ke registry Client mencari (lookup) nama server di dalam registry untuk membangun referensi remote Stub menyusun (serializing) parameterparameter ke skeleton, skeleton memanggil metode remote dan menyusun hasil balik ke stub tersebut 10

Rincian Implementasi Paket yang digunakan dalam implementasi aplikasi client-server RMI adalah java.rmi java.rmi.server dan java.rmi.registry Langkah-langkah dasarnya adalah 1. Membuat interface. 2. Mendefinisikan suatu kelas yang mengimplementasikan interface ini. 3. Membuat proses server. 4. Membuat proses client. 11

Kompilasi dan Eksekusi 1. Kompilasikan semua file dengan javac. 2. Buka command prompt pertama, jalankan registry RMI. 3. Buka jendela (console) baru dan jalankan server 4. Buka console ketiga dan jalankan client-nya. 12

Kompilasi dan Eksekusi (Lanj.) 1. Kompilasikan semua file dengan javac. javac Hello.java javac HelloImpl.java javac HelloServer.java javac HelloClient.java 2. Jalankan registry RMI. Masukkan perintah: rmiregistry Saat ini dieksekusi, indikasi bahwa sesuatu telah terjadi hanyalah perubahan pada judul jendela command prompt. 13

Kompilasi dan Eksekusi (Lanj.) 3. Buka console baru dan jalankan server. Dari jendela baru tersebut, panggil Java compiler: Output server terlihat sebagai berikut: java HelloServer 4. Buka console baru ketiga dan jalankan client. Lagi, panggil Java compiler: java HelloClient Output diperlihatkan sebagai berikut: 14

Pemanfaatan Kehebatan RMI Dalam aplikasi RMI nyata, banyak metode dan mungkin banyak obyek yang dikembangkan. Pada demikian, ada 2 kemungkinan strategi yang dapat diadopsi, yaitu: Menggunakan instance tunggal dari kelas Implementations untuk menangani instance dari suatu kelas yang mempunyai metode untuk dipanggil secara remote. Lewatkan instance dari kelas tersebut sebagai argumen dari constructor bagi kelas Implementations. Menggunakan kelas Implementations secara langsung untuk menyimpan data dan metode yang diperlukan, membuat instance dari kelas ini, bukan menggunakan kelas-kelas terpisah. 15

Keamanan RMI File java.policy mendefinisikan batasan-batasan keamanan. File java.security mendefinisikan properti keamanan. Implementasi kebijakan keamanan dikontrol oleh suatu obyekl dari kelas RMISecurityManager (sub-kelas dari SecurityManager ). Kita harus membuat security manager sendiri yang mengeksten RMISecurityManager. Manajer keamanan ini harus menyediakan suatu definisi untuk metode checkpermission, yang mengambil satu argumen dari kelas Permission dari paket java.security. 16

Tutorial Pemrograman Java RMI

Java RMI RMI = Remote Method Invocation Allows a method to be invoked that resides on a different JVM (Java Virtual Machine): Either a remote machine Or same machine, different processes Each process runs on a different Java Virtual Machines (JVM) Different address space per process/jvm RMI provides object-oriented RPC (Remote Procedure Calls)

Proses yang Terlibat Client Process that is invoking a method on a remote object Server Process that owns the remote object To the server, this is a local object Object Registry (rmiregistry) Name server that associates objects with names A server registers an object with rmiregistry URL namespace rmi://hostname:port/pathname Contoh: rmi://crapper.pk.org:12345/myserver Nomor Port

Classes & Interfaces needed for Java RMI Remote: for accessing remote methods Used for remote objects Serializable: for passing parameters to remote methods Used for parameters Juga diperlukan: RemoteException: network or RMI errors can occur UnicastRemoteObject: used to export a remote object reference or obtain a stub for a remote object Naming: methods to interact with the registry

Kelas Remote Remote class (remote object) Instances can be used remotely Works like any other object locally In other address spaces, object is referenced with an object handle The handle identifies the location of the object If a remote object is passed as a parameter, its handle is passed

Interface Serializable java.io.serializable interface (serializable object) Allows an object to be represented as a sequence of bytes Allows instances of objects to be copied between address spaces Can be passed as a parameter or be a return value to a remote object Value of object is copied (pass by value) Any objects that may be passed as parameters should be defined to implement the java.io.serializable interface Good news: you rarely need to implement anything o All core Java types already implement the interface o For your classes, the interface will serialize each variable iteratively

Kelas Remote Classes that will be accessed remotely have two parts: 1. interface definition 2. class definition Remote interface This will be the basis for the creation of stub functions Must be public Must extend java.rmi.remote Every method in the interface must declare that it throws java.rmi.remoteexception Remote class implements Remote interface extends java.rmi.server.unicastremoteobject

Contoh Program Super Sederhana Client invokes a remote method with strings as parameter Server returns a string containing the reversed input string and a message

Definisikan Interface Remote: SampleInterface.java import java.rmi.remote; import java.rmi.remoteexception; public interface SampleInterface extends Remote { } public String invert(string msg) throws RemoteException; Interface is public Extends the Remote interface Defines methods that will be accessed remotely We have just one method here: invert Each method must throw a RemoteException In case things go wrong in the remote method invocation

Definisikan Kelas Remote (Sample.java) import java.rmi.remote; import java.rmi.remoteexception; import java.rmi.server.*; public class Sample extends UnicastRemoteObject implements SampleInterface { public Sample() throws RemoteException { } public String invert(string m) throws RemoteException { // return input message with characters reversed return new StringBuffer(m).reverse().toString(); } } Defines the implementation of the remote methods It implements the interface we defined It extends the java.rmi.server.unicastremoteobject class Defines a unicast remote object whose references are valid only while the server process is alive.

Selanjutnya... Kita sudah mempelajari: The remote interface definition: SampleInterface.java The server-side (remote) class: Sample.java Selanjutnya, we ll write the server: SampleServer.java Two parts: 1. Create an instance of the remote class 2. Register it with the name server (rmiregistry)

Kode Server (SampleServer.java) Create the object new Sample() Register it with the name server (rmiregisty) Naming.rebind("Sample, new Sample()) rmiregistry runs on the server The default port is 1099 The name is a URL format and can be prefixed with a hostname and port: //localhost:1099/server

Kode Server: Bagian 1 (SampleServer.java) import java.rmi.naming; import java.rmi.remoteexception; import java.rmi.server.unicastremoteobject; public class SampleServer { public static void main(string args[]) { if (args.length!= 1) { System.err.println("usage: java SampleServer rmi_port"); System.exit(1); }

Kode Server: Bagian 2 (SampleServer.java) } } try { // first command-line arg: the port of the rmiregistry int port = Integer.parseInt(args[0]); // create the URL to contact the rmiregistry String url = "//localhost:" + port + "/Sample"; System.out.println("binding " + url); // register it with rmiregistry Naming.rebind(url, new Sample()); // Naming.rebind("Sample", new Sample()); System.out.println("server " + url + " is running..."); } catch (Exception e) { System.out.println("Sample server failed:" + e.getmessage()); }

File Kebijakan (Policy) When we run the server, we need to specify security policies A security policy file specifies what permissions you grant to the program This simple one grants all permissions grant { }; permission java.security.allpermission;

Client The first two arguments will contain the host & port Look up the remote function via the name server This gives us a handle to the remote method SampleInterface sample = (SampleInterface)Naming.lookup(url); Call the remote method for each argument sample.invert(args[i])); We have to be prepared for exceptions

Kode Client: Bagian 1 (SampleClient.java) public class SampleClient { public static void main(string args[]) { try { // basic argument count check if (args.length < 3) { System.err.println( "usage: java SampleClient rmihost rmiport string... \n"); System.exit(1); } // args[0] contains the hostname, args[1] contains the port int port = Integer.parseInt(args[1]); String url = "//" + args[0] + ":" + port + "/Sample"; System.out.println("looking up " + url); // look up the remote object named Sample SampleInterface sample = (SampleInterface)Naming.lookup(url);

Kode Client: Bagian 2 (SampleClient.java) } } // args[2] onward are the strings we want to reverse for (int i=2; i < args.length; ++i) // call the remote method and print the return System.out.println(sample.invert(args[i])); } catch(exception e) { System.out.println("SampleClient exception: " + e); }

Kompilasi Compile the interface and classes: javac SampleInterface.java Sample.java javac SampleServer.java And the client javac SampleClient.java (you can do it all on one command: javac *.java) Note Java used to use a separate RPC compiler Since Java 1.5, Java supports the dynamic generation of stub classes at runtime In the past, one had to use an RMI compiler, rmic If you want to, you can still use it but it s not needed

Menjalankan... Start the object registry (in the background): rmiregistry 12345 & An argument overrides the default port 1099 Start the server (giving it the port of the rmi registry): java -Djava.security.policy=policy SampleServer 12345 Run the client: java SampleClient svrname 12345 testing abcdefgh Where svrname is the name of the server host 12345 is the port number of the name server: rmiregistry, not the service! See the output: gnitset hgfedcba

RMI Sedikit Sisi Dalamnya

Interface Interfaces define behavior Classes define implementation RMI: two classes support the same interface client stub server implementation

Arsitektur Tiga Layer Stub functions Remote reference layer Transport layer Application interaction. Marshaling & unmarshaling Handles the creation & management of remote objects. Deals with the semantics of remote requests (how they behave). Setting up connections and sending/receiving data

Server Server creates an instance of the server object extends UnicastRemoteObject TCP socket is bound to an arbitrary port number thread is created which listens for connections on that socket Server registers object RMI registry is an RMI server (accepts RMI calls) Hands the registry the client stub for that server object contains information needed to call back to the server (hostname, port)

Client Client obtains stub from registry Client issues a remote method invocation stub class creates a RemoteCall opens socket to the server on port specified in the stub sends RMI header information stub marshals arguments over the network connection uses methods on RemoteCall to obtain a subclass of ObjectOutputStream knows how to deal with objects that extend java.rmi.remote o serializes Java objects over socket stub calls RemoteCall.executeCall() causes the remote method invocation to take place

Server (Lanj.) Server accepts connection from client Creates a new thread to deal with the incoming request Reads header information creates RemoteCall to deal with unmarshaling RMI arguments Calls dispatch method of the server-side stub (skeleton) calls appropriate method on the object sends result to network connection via RemoteCall interface if server threw exception, that is marshaled instead of a return value

Client (Lanj.) The client unmarshals the return value of the RMI using RemoteCall value is returned from the stub back to the client code or an exception is thrown to the client if the return was an exception

Pertanyaan?