eta RMI a tata Sedas - PowerPoint PPT Presentation

About This Presentation
Title:

eta RMI a tata Sedas

Description:

?? ???se?? (classes) ??????? t?p??? a?t??e? ????. ... catch(IOException ioe) { } catch(Throwable) { throw new MyException(); } finally ... – PowerPoint PPT presentation

Number of Views:37
Avg rating:3.0/5.0
Slides: 34
Provided by: stou7
Category:
Tags: rmi | eta | ioexception | javac | sedas | tata

less

Transcript and Presenter's Notes

Title: eta RMI a tata Sedas


1
?e?t?????a RMI ?a???t?µata S?ed?as??
  • St??µp?? ?as????
  • stoumpos_at_di.uoa.gr
  • ?a?ep?st?µ?? ??????
  • ?µ?µa ?????f??????

2
?e??????
  • Crash course se Java.
  • ?a??de??µa se RMI.
  • ??t?µata s?ed?as?? (?ata?eµ?µ????) efa?µ????.
  • RMI.
  • S?ed?asµ??.

3
?e?????? - Java
  • Crash course se Java.
  • ???se?? ?a? a?t??e?µe?a.
  • ??af???? µe t? C.
  • ?a??de??µa se RMI.
  • ??t?µata s?ed?as?? (?ata?eµ?µ????) efa?µ????.
  • RMI.
  • S?ed?asµ??.

4
???se?? st?? Java
  • ?? ???se?? (classes) ??????? t?p??? a?t??e?µ????.
  • ?a a?t??e?µe?a (objects) e??a? st??µ??t?pa
    (instances) t?? ???se??.
  • ?? ???se?? ?µad?p?????ta? se µ?a ?e?a???a pa??t??
    (packages).
  • package gr.uoa.di.stoumpos
  • public class Counter
  • private int value
  • public Counter(int v)
  • this.value v
  • public int getValue()
  • return this.value
  • public void increment()
  • this.value

5
??t??e?µe?a st?? Java
  • ?a a?t??e?µe?a (objects) e??a? st??µ??t?pa
    (instances) t?? ???se??.
  • ???sßas? sta a?t??e?µe?a µ??? µ?s? a?af????
    (references).
  • ?ed?a a?t??e?µ???? ?a? ped?a ???se??
    (class/object fields).
  • Garbage collecting.
  • Counter a new Counter(12)
  • Counter b new Counter(-12)
  • for (int i0 ilt 10 i)
  • a.increment()
  • b.increment()
  • System.out.println(
  • Counter a value is
  • a.getValue())
  • System.out.println(
  • Counter b value is
  • b.getValue())

6
?????aµµa Java
  • ??a µ??? public ???s? se ???e a??e??.
  • ???µa t?? a??e??? ?p?? ? public ???s?.
  • ?eta???tt?s? µe javac.
  • ??t??es? µe java.
  • ?p???e? main µ???d?? ???s??.
  • ?deat? ???a?? (VM-Virtual Machine)
  • / ???e?? TestProg.java /
  • import gr.uoa.di.stoumpos
  • public class TestProg
  • public static void main(
  • String args)
  • for(i0 iltargs.length i)
  • System.out.println(
  • arg i
  • argsi)

7
??a???se?? (Exceptions) st? Java
  • ? e?a??es? e??a? ??a a?t??e?µe?? µ?a? ???s??.
  • ??a???se?? ???s?µ?p?????ta? se e?a??et????
    pe??pt?se??.
  • ? d??at?t?ta e?a??es?? (throw exception)
    d????eta? st?? µe??d???.
  • ??a?e???s? ?a??? µe try-catch µp???.
  • ??a???se??
  • Runtime
  • Error
  • ???e?
  • try
  • FileInputStream stream
  • new FileInputStream(
  • new File(foo.dat))
  • catch(FileNotFoundException fnfe)
  • // ...
  • catch(SecurityException se)
  • // ...
  • catch(IOException ioe)
  • // ...
  • catch(Throwable)
  • throw new MyException()
  • finally
  • // ...

8
??t??e?µe??st?ef?? ???t???st? Java
  • ???????µ???t?ta (inheritance)
  • ???? ap?? (??? multiple inheritance ap? C).
  • ???s? Interface sa? ???s? ????? s?µata µe??d??
  • ????µ??f?sµ?? (polymorphism)
  • ?p?? st? C.
  • Strong-typed ???ssa.
  • ????????s? (encapsulation)
  • ??sse?a ep?peda pe?????sµ?? (visibility scope)
    private, protected, public ?a? package.

9
?e?????? - RMI
  • Crash course se Java.
  • ?a??de??µa se RMI.
  • ?p?? pa??de??µa.
  • ???at?stas? s?st?µat??.
  • ??d???? pe??pt?se??.
  • ??t?µata s?ed?as?? (?ata?eµ?µ????) efa?µ????.
  • RMI.
  • S?ed?asµ??.

10
??p??? ?a? ?p?µa???sµ??? ???s? ?e??d??
  • ??? ß??s?eta? t? a?t??e?µe??
  • ??? ???eta? ? ???s?
  • ????? a?a?aµß??e? t?? ?ept?µ??e?e? t?? ???s??

11
?a??de??µa RMI
  • ?? ?a pe? ap?µa???sµ??? ???s?
  • ??a µ???d??, ??p???? a?t??e?µ????, ?a?e?ta? ap?
    ??p??a ????.
  • ??af??et???? ????? d?e????se??.
  • ??af??et??? µ?????µa (d??t??).
  • ???p?? ???s?? ?????? µe t?p??? ???s?.
  • ??af???p????µe
  • ??epaf? (interface).
  • ???p???s? (implementation).
  • Ta d??µe t?? µet??t? sa? pa??de??µa.

12
??epaf? ?et??t?
  • ??e? ?? d?epaf?? e??a? e?e?d??e?se?? t??
    java.rmi.Remote d?epaf??.
  • ??e? ?? µ???d?? µp??e? ?a d?s??? RemoteException.
  • ?? ?d?? interface p??pe? ?a ???s?µ?p??e? ?a? ?
    ?a???µe??? ?a? ? ?a???.
  • import java.rmi.
  • public interface Counter extends java.rmi.Remote
  • public void setValue(int v)
  • throws RemoteException
  • public int getValue()
  • throws RemoteException
  • public void increment()
  • throws RemoteException

13
???p???s? ?et??t?
  • ? ???p???s? epe?te??e? t? java.rmi.UnicastRemoteOb
    ject ?a? ???p??e? t? Counter.
  • ?p????? ?a ???st??? ped?a t?? ???p???s??.
  • ?pa?a?t?t?? default constructor.
  • ?? ???p???se?? de? ep??e????ta? ap? t? e?d??
    ???s??.
  • import java.rmi.
  • public class CounterImpl extends
  • java.rmi.UnicastRemoteObject
  • implements Counter
  • int value 0
  • public Counter()
  • throws RemoteException
  • super()
  • public void setValue(int v)
  • throws RemoteException
  • this.value v
  • //...

14
???p???t?? ?et??t?
  • ?pa?te?ta? ?a
  • ?atas?e?aste? t? a?t??e?µe?? e??p???t??.
  • ?esµe??e? ??a ???µa ??a a?t?.
  • ?a s??de?e? (bind) µe µ?a d?e????s?.
  • ? e??p???t?? t???e? s????e?a.
  • ??e???eta? ?a t???e? t? rmiregistry.
  • import java.rmi.
  • public class CounterServer
  • public static void main(
  • String args)
  • Counter counter null
  • String url
  • rmi//localhost
  • 1099/MyNiceCounter
  • try
  • counter new Counter()
  • Naming.bind(url, counter)
  • catch(Exception e)
  • System.exit(-1)

15
?p?µa???sµ??? ???s? ?et??t?
  • ?pa?te?ta? ?a
  • ??a?????s?e? t? ???µa t?? a?t??e?µ????.
  • ??af??? st? ap?µa???sµ??? a?t??e?µe??.
  • ???s? t?? a?af????.
  • ?????? pe??te? e?te????ta? ta?t?????a.
  • ??e???eta? ?a t???e? ? e??p???t??.
  • Counter counter null
  • String url
  • rmi//localhost
  • "1099/MyNiceCounter
  • try
  • counter
  • Naming.lookup(url)
  • counter.increment()
  • System.out.println(
  • Counter a value is
  • counter.getValue())
  • catch(Exception e)
  • //...

16
?p?te??? ?p?µa???sµ???? ???s??
  • ?ept?µ??e?e? t?? ???s??
  • ??d??a? p?? ?e????ta? a?t?µata.
  • Stubs ?a? Skeletons.
  • ???asµa pa?aµ?t??? ?a? ap?te?esµ?t??.
  • ?? d?epaf?? ????? ??? t?? p????f???a.
  • Marshalling/Unmarshalling.

17
???at?stas? S?st?µat??
  • ?eta???tt????µe ??e? t?? ???se??.
  • ???s? javac.
  • ?atas?e?????µe t?? a?t?µat? ??d??a.
  • ???s? rmic.
  • ????????µe ???se?? st?? t?p??es?e? p?? ?a
    ??e?ast???
  • jar
  • ??te???µe (se ????st? shells)
  • rmiregistry
  • java gr.uoa.di.
  • stoumpos.CounterServer
  • Java gr.uoa.di.
  • stoumpos.CounterClient

18
?e?????? S?ed?asµ?? (RMI)
  • Crash course se Java.
  • ?a??de??µa se RMI.
  • ??t?µata s?ed?as?? (?ata?eµ?µ????) efa?µ????.
  • RMI.
  • ??a???se??.
  • ?a??µet???.
  • S?ed?asµ??.

19
?e?????? S?ed?asµ?? (RMI)
  • Crash course se Java.
  • ?a??de??µa se RMI.
  • ??t?µata s?ed?as?? (?ata?eµ?µ????) efa?µ????.
  • RMI.
  • ??a???se??.
  • ?a??µet???.
  • S?ed?asµ??.

20
???asµa ?a?aµ?t??? st? RMI
  • ???t??e?e?? ??p??
  • int, char, double,
  • ??t???af? t?? t?µ??.
  • ??t??e?µe?a Java.
  • ?p?µa???sµ??a RMI a?t??e?µe?a.

21
???asµa ??t??e?µ???? st? RMI
  • ??t??e?µe?a Java
  • ???pe? ?a e??a? serializable!
  • ???p????? t?? d?epaf? java.io.Serializable.
  • ?etaf??? st??µ??t?p?? se se??? ap? bytes.
  • ??a ta µ??? e??? se????p???s?µ?? a?t??e?µ????
    p??pe? ?a e??a? se????p???s?µa.
  • ?a ped?a t?? ???se?? de? ?aµß????ta? ?p??? st?
    se????p???s?.
  • ??t???af? bytes, ?a? a?ad?µ?s? st?? p?????sµ?.
  • ??t???af? ????????? a?t??e?µ????.

22
???asµa RMI ??t??e?µ????st? RMI
  • ??t??e?µe?a RMI
  • St?? ?atas?e?? (constructor) t??? ta a?t??e?µe?a
    a?t? e??a? ?t??µa ?a de????? ap?µa???sµ??? ???s?.
  • ?e? ????? s??de?e? (bind) µe ???µa p??a???.
  • ?atas?e?? ap?µa???sµ???? a?af???? sta
    a?t??e?µe?a.
  • ??t???af? a?af????.

23
??a?e???s? ?a???
  • ???e f??? p?? ??t? p?e? st?aß? ????µe e?a??es?
    (exception).
  • ??? e?d?? e?a???se??
  • ?fa?µ????.
  • S?st?µat??.
  • ?p?t??peta? ?a ????µe st?? d?epaf? ?a? e?a???se??
    efa?µ????.
  • ??p?? e??a? ?a??te?? ?a ???s?µ?p???s??µe
    wrappers
  • ? ???s? Exception ???p??e? t? Serialized.
  • ??a e?a??es? µp??e? ?a ??e? eµf???asµ??e?
    e?a???se?? (nested exceptions).

24
?e?????? S?ed?asµ??
  • Crash course se Java.
  • ?a??de??µa se RMI.
  • ??t?µata s?ed?as?? (?ata?eµ?µ????) efa?µ????.
  • RMI.
  • S?ed?asµ??.
  • S???????sµ??.
  • Callbacks.
  • Blocking/Callbacks/Polling.
  • Push ?a? Pull.

25
S?ed?asµ?? S???????sµ??
  • ?atas?e?????µe ??a a?t??e?µe?? p?? ??at? Strings
    p?? ft????? se a?t?.
  • ??t??µe ta strings µe de??te?.
  • ?e? afa????µe strings p?t?.
  • public interface List
  • public void addString(
  • String s) throws ...
  • public String getString(
  • int i) throws ...
  • public int getNumOfStrings()
  • throws RemoteException

26
S?ed?asµ?? S???????sµ?? (s??.)
  • St?? ???p???s? ??at??µe ta strings se ??a
    p??a?a.
  • S?????a ?a ??s??µe strings!
  • //...
  • public void addString(
  • String s)
  • if (this.counter)
  • throw new Exception(
  • No space!)
  • this.stringArray
  • this.counter s
  • // ...

27
S?ed?asµ?? S???????sµ?? (s??.)
  • S??????????µe t?? p??sßas? st?? p??? (resource).
  • ???s?µ?p????µe t?? synchronized µ??a??sµ? t??
    Java.
  • ???s??? st?? ??tas? s???????sµ??!
  • ???s??? st? ????? s?µe?? s???????sµ??!
  • //...
  • public void addString(
  • String s)
  • synchronized(
  • this.stringArray)
  • if (this.counter)
  • throw new Exception(
  • No space!)
  • this.stringArray
  • this.counter s
  • // ...

28
???p?? ???s??
  • ??e? ?? RMI ???se?? e??a? s??????e?
    (synchronous/blocking).
  • ? ?a???µe??? a?ast???e? t?? e?t??es? t?? µ???? ?a
    e?te?este? ? ap?µa???sµ??? µ???d??.
  • ?p????µe ?a ????µe ???s? as???????
  • Se ep?ped? s?ed?as?? ?a?.
  • ??? ??se??
  • Callbacks
  • Polling

29
Blocking ???s?
Client
Stub
Skeleton
Server
idle
30
Callback ???s?
Client
Callback
Server
create
thread
idle
other processing
31
Polling µet? t?? ???s?
Client
Request
Server
thread
create
poll
updte
poll
other processing
32
???e? ?e??????
  • Push ?a? Pull
  • Thread Pools
  • ???a

33
??af????
  • Java
  • Thinking in Java, Bruce Eckel, d?a??s?µ? ap? t?
    www.bruceeckel.com.
  • The Java Tutorial, Sun, d?a??s?µ? ap? t?
    http//java.sun.com/docs/books/tutorial/index.html
    .
  • RMI
  • Fundamentals of RMI, jGuru, d?a??s?µ? (µa?? µe
    ???a) ap? t? http//developer.java.sun.com/develop
    er/onlineTraining/.
  • Architecture (p??a p???? ??a ??? t??µe??)
  • Pattern-Oriented Software Architecture, Douglas
    C. Schmidt, d?a??s?µ? ap? (s??desµ?? powerpoint
    slides) t? http//www.cs.wustl.edu/schmidt/POSA/.
  • ???a
  • ?? www.google.com e??e? p??? ?a?? ap?te??sµata
    ?ta? ??a?a.
Write a Comment
User Comments (0)
About PowerShow.com