Middle Ware 10

Embed Size (px)

Citation preview

  • 8/13/2019 Middle Ware 10

    1/24

    DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING

    WEATHER FORECAST INFORMATION USING CORBA

    AIM:To Create a Component for retrieving stock market exchange information usingCORBA

    DESCRIPTION: Steps required:

    1. efine the !" interface

    #. !mp$ement the !" interface using id$% compi$er

    &. Create a C$ient 'rogram

    (. Create a Server 'rogram

    ). Start or*d.

    +. Start the Server.

    ,. Start the c$ient

    // Define IDL Interface

    modu$e -eather

    interface forecast

    f$oat get/min02 f$oat get/max023232Nte: Save the a*ove modu$e as -eather.id$Compi$e the saved modu$e using the id$% compi$er as fo$$o-s .

    C:!"#$i!#eat%er&i'() #eat%er*i'(

    After compi$ation a su* director4 ca$$ed -eather same as modu$e name -i$$ *e createdand it generates the fo$$o-ing fi$es as $isted *e$o-.

    C:5so-mi5-eather6cd -eather

    C:5so-mi5-eather5-eather6dir7o$ume in drive C has no $a*e$.

    7o$ume Seria$ 8um*er is &(9A#,B,

    irector4 of C:5su%i5-eather5-eather;&!R6 ..

    ;&

  • 8/13/2019 Middle Ware 10

    2/24

    C:5so-mi5-eather5-eather6

    // I$+(e$ent t%e interfaceimport org.omg.CORBA.2import -eather.2

    import %ava.uti$.2

    pu*$ic c$ass -eatherimp$ extends forecast'OA

    private ORB or*2

    int rDEFne- intD1;E2 f$oat sDEFne- f$oatD1;E2

    Random rrFne- Random02

    pu*$ic void setORB0ORB vor*Fv23 pu*$ic f$oat get/min0

    for0int iF;2i>1;2iGG

    rDiEF=ath.a*s0rr.next!nt02

    sDiEF=ath.round00f$oatrDiE;.;;;;;;;123

    f$oat min2 minFsD;E2

    for0int iF12i>1;2iGG

    if 0min6sDiE min FsDiE2 3

    f$oat mintempF=ath.a*s00f$oat0min)1;2iGG

    rDiEF=ath.a*s0rr.next!nt02

    sDiEF=ath.round00f$oatrDiE;.;;;;;;;12 3 f$oat max2

    maxFsD;E2

    for0int iF12i>1;2iGG

    if 0max>sDiE

    max FsDiE2 3

    f$oat maxtempF=ath.a*s00f$oat0max)

  • 8/13/2019 Middle Ware 10

    3/24

    import org.omg.'orta*$eServer.'OA.2

    import %ava.uti$.'roperties2

    import -eather.2pu*$ic c$ass -eatherserver

    pu*$ic static void main0StringDE args

    tr4 ORB or*FORB.init0args?nu$$2

    'OA rootpoaF'OAe$per.narro-0or*.reso$ve/initia$/references0HRoot'OAH2

    rootpoa.the/'OA=anager0.activate02 -eatherimp$ ssFne- -eatherimp$02

    ss.setORB0or*2

    org.omg.CORBA.O*%ect refFrootpoa.servant/to/reference0ss2

    forecast hrfFforecaste$per.narro-0ref2 org.omg.CORBA.O*%ect orfFor*.reso$ve/initia$/references0H8ameServiceH2

    8amingContextIxt ncrfF8amingContextIxte$per.narro-0orf2

    8ameComponent pathDEFncrf.to/name0HforecastH2

    ncrf.re*ind0path?hrf2 S4stem.out.print$n0H-eather server is read4H2

    or*.run023

    catch0Ixception e

    e.printStackTrace02333

    // C(ient Pr-ra$import org.omg.CORBA.2

    import org.omg.Cos8aming.2

    import -eather.2import org.omg.Cos8aming.8amingContext'ackage.2

    import %ava.uti$.2pu*$ic c$ass -eatherc$ient

    pu*$ic static void main0StringDE args

    String cit4DEFHChennai H?HTrich4 H?H=adurai H?HCoim*atoreH?HSa$em H32

    Ca$endar ccFCa$endar.get!nstance02

    tr4

    ORB or*FORB.init0args?nu$$2

    8amingContextIxt

    ncRefF8amingContextIxte$per.narro-0or*.reso$ve/initia$/references0H8ameServiceH2 forecast frFforecaste$per.narro-0ncRef.reso$ve/str0HforecastH2

    S4stem.out.print$n0H5t5t5tJ I A T I R O R I C A S TH2

    S4stem.out.print$n0H5t5t5tKKKKKKKKKKKKKKKKKKKKKKKKKKKKKH2 S4stem.out.print$n02

    S4stem.out.print$n0H5tATI T!=I C!TL !MIST "OJIST H2

    S4stem.out.print$n0H5t TI='IRATNRI TI='IRATNRIH2

  • 8/13/2019 Middle Ware 10

    4/24

    for0int iF;2i>)2iGG S4stem.out.print0H5tHGcc.get0Ca$endar.ATI

    Gcc.get0Ca$endar.=O8TGcc.get0Ca$endar.LIARGH HGcc.get0Ca$endar.ONRGH

    HGcit4DiEGH HGH H2 S4stem.out.print0=ath.f$oor0fr.get/min0GH5t 5tHG=ath.cei$0fr.get/max02

    S4stem.out.print$n02 33

    catch0Ixception ee.printStackTrace02333

    Compi$e the a*ove fi$es as

    C:5so-mi5-eather6%avac .%avaC:5so-mi5-eather6start or*d ORB!nitia$'ort 1;); ORB!nitia$ost $oca$host

    C:5so-mi5cor*a6start %ava -eatherserver ORB!nitia$'ort 1;); ORB!nitia$ost$oca$host

    C:5so-mi5-eather6

    -eather server is read4

    C:5so-mi5cor*a6%ava -eatherc$ient ORB!nitia$'ort 1;); ORB!nitia$ost $oca$host

    C:5so-mi5-eather6%ava -eatherc$ient ORB!nitia$'ort 1;); ORB!nitia$ost

    $oca$host

  • 8/13/2019 Middle Ware 10

    5/24

    .De,e(+ a $i''(e#are c$+nent fr retrie,in- Stc Maret E0c%an-e infr$atin

    1"in-CORBA

    Aim:To develop a middleware component for retrieving stock market exchange

    using CORBA.

    Algorithm:1. Start the program. Create a class stock server ! activate the specified function.". Create a class stock client ! read choice such as #u$%sell! displa$.&. 'erform appropriate operations #ased on the choice.(. )n stock interface%declare the input function.*. Stop the program.

  • 8/13/2019 Middle Ware 10

    6/24

    De,e(+ a Mi''(e#are C$+nent fr Retrie,in- Stc Maret E0c%an-e

    Infr$atin 1"in- CORBA

    Stock Server.java

    import StockApp.*;

    import org.omg.CosNaming.*;import org.omg.CORBA.*;import org.omg.CORBA.Object;import org.omg.CosNaming.NamingContextPackage.*;import org.omg.PortableServer.*;import org.omg.PortableServer.POA;class StockImpl extens StockPOA!

    private ORB orb;p"blic voi setORB#ORB j$!

    orb % j;&p"blic o"ble inp"t#o"ble "nit' o"ble no$!

    ret"rn #"nit * no$;&

    &p"blic class StockServer!p"blic static voi main#String( )args$!

    r+!ORB orb % ORB.init#args' n"ll$;POA rootPOA %POA,elper.narro-#orb.resolveinitialre/erences#0RootPOA0$$;rootPOA.t1ePOA2anager#$.activate#$;StockImplstockImpl % ne- StockImpl#$;stockImpl.setORB#orb$;Object objectRe/3 % rootPOA.servanttore/erence#stockImpl$;Stock stockRe/ % Stock,elper.narro-#objectRe/3$;org.omg.CORBA.Object objectRe/4 %

    orb.resolveinitialre/erences#0NameService0$;NamingContext5xtncRe/ %NamingContext5xt,elper.narro-#objectRe/4$;String name % 0P30;NameComponentncPat1( ) % ncRe/.toname#name$;ncRe/.rebin#ncPat1' stockRe/$;S+stem.o"t.println#0Server is Rea+ 6 7aiting.....0$;orb.r"n#$;

  • 8/13/2019 Middle Ware 10

    7/24

    &

    catc1 #5xception e$

    !S+stem.o"t.println#05RROR809e$;e.printStackrace#$;&&&Stock Client.javaimport StockApp.*;import org.omg.CosNaming.*;import java.io.B"//ereReaer;import java.io.Inp"tStreamReaer;

    import org.omg.CORBA.ORB;import org.omg.CosNaming.NamingContext5xt;import org.omg.CosNaming.NamingContext5xt,elper;p"blic class StockClient!static Stock stock;p"blic static voi main#String args( )$!String( ) "i3 % ! 0234:0' 0p33:?0&;String( ) p % !0,@C,0' 0In/os+s0'0,"tc10'0In/os+s0&;o"ble ( ) "nit % !?''?'&;

    o"ble ( )nos1ares % !3

  • 8/13/2019 Middle Ware 10

    8/24

    S+stem.o"t.println#0@i Compan+ name t "nitt No.o/.S1arest total80$;/or #int i% % b"//ereReaer.reaKine#$;

    /or #int i%

  • 8/13/2019 Middle Ware 10

    9/24

    &&

    &break;case 48

    S+stem.o"t.println#05nter Seller IJ80$;String str: % b"//ereReaer.reaKine#$;S+stem.o"t.println#05nter Compan+ Name80$;String str? % b"//ereReaer.reaKine#$;S+stem.o"t.println#0No o/ S1ares " -ant to b"+80$;o"ble o"b4 % Jo"ble.parseJo"ble#b"//ereReaer.reaKine#$$;S+stem.o"t.println#05nter t1e Seller i80$;String str % b"//ereReaer.reaKine#$;/or #int i%8S+stem.o"t.println#0tt Stat"s o/ NS580$;

    S+stem.o"t.println#0t "i t Compan+name tt "nit tNo.o/.S1arettotal80$;

    /or #int i%

  • 8/13/2019 Middle Ware 10

    10/24

    &S+stem.o"t.println#0Jo +o" -ant to contin"e MN80$;c1oice % b"//ereReaer.reaKine#$;&

    -1ile #c1oice.eL"als#0+0$$;

    &catc1 #5xception e$!S+stem.o"t.println#05RROR809e$;e.printStackrace#$;

    &

    &&

    Stock.idlmo"le StockApp!

    inter/ace Stock!

    o"ble inp"t #in o"ble "nit' in o"ble rate$;&;

    &;

    OUTPUT:

    58Corbaset PA,%PA,.; 58Corba;58Corbaset CKASSPA,%CKASSPA,.; 58Corba;58Corbailj Stock.il58Corbailj G/all Stock.il58Corbajavac *.java StockApp*.javaNote8 StockAppStockPOA.java "ses "nc1ecke or "nsa/e operations.Note8 Recompile -it1 GElint8"nc1ecke /or etails.58CorbaStart orb GORBInitialPort 3

  • 8/13/2019 Middle Ware 10

    11/24

    =enu Options

    1. Bu4#. Se$$

    &. isp$a4

    Inter 4our choice: 1Inter Bu4er !: =1#(

    Inter Compan4 8ame: utch

    8o.of.shares 4ou -ant to *u4: )Inter the Se$$er !: 1

    o 4ou -ant to continue 4

  • 8/13/2019 Middle Ware 10

    12/24

    '$1@; !nfos4s +.; (.; #(.;

    =9@; utch ).; ,.; &).;

    &() !nfos4s +.; 9.; (9.;

    o 4ou -ant to continue 4

  • 8/13/2019 Middle Ware 10

    13/24

    De,e(+ a Mi''(e#are C$+nent fr Retrie,in- Weat%er Freca"t Infr$atin1"in- CORBA

    Weat%erSer,er*)a,a

    import org.omg.CORBA.ORB2

    import org.omg.CORBA.O*%ect2

    import org.omg.Cos8aming.8ameComponent2import org.omg.Cos8aming.8amingContextIxt2

    import org.omg.Cos8aming.8amingContextIxte$per2

    import org.omg.'orta*$eServer.'OA2

    import org.omg.'orta*$eServer.'OAe$per2pu*$ic c$ass JeatherServer

    pu*$ic static void main0StringD E args

    tr4 ORB or* F ORB.init0args? nu$$2

    'OA root'OA F

    'OAe$per.narro-0or*.reso$ve/initia$/references0HRoot'OAH2

    root'OA.the/'OA=anager0.activate02Jeather!mp$-eather!mp$ F ne- Jeather!mp$02

    -eather!mp$.setORB0or*2

    O*%ect o*%ectRef1 F root'OA.servant/to/reference0stock!mp$2Jeather -eatherRef F Jeathere$per.narro-0ref2

    org.omg.CORBA.O*%ect o*%ectRef# F

    or*.reso$ve/initia$/references0H8ameServiceH28amingContextIxtncRef F

    8amingContextIxte$per.narro-0o*%ectRef#2

    String name F He$$oH2

    8ameComponentnc'athD E F ncRef.to/name0name2ncRef.re*ind0nc'ath? -eatherRef2

    S4stem.out.print$n0HServer is Read4 P Jaiting.....H2

    or*.run023

    catch 0Ixception e

    S4stem.out.print$n0HIRROR:HGe2

    e.printStackTrace02

    3

    S4stem.out.print$n0HServer Ixsisting:.....H2

  • 8/13/2019 Middle Ware 10

    14/24

    3

    3

    Weat%erI$+(*)a,aimport org.omg.CORBA.ORB2

    pu*$ic c$ass Jeather!mp$ extends Jeather'OA

    private ORB or*2

    private dou*$e current2

    private dou*$e min2

    private dou*$e max2pu*$ic voidsetORB0ORB or*/va$

    or* F or*/va$2

    3pu*$ic voidad%ustTemp0dou*$e g

    currentGFg2

    if0current6 max

    max Fcurrent2e$se if0current>min

    min F current2

    3

    pu*$ic dou*$e get=ax0

    return max2

    3pu*$ic dou*$e get=in0

    return min23

    pu*$ic dou*$e getCurrent0

    return current23

    pu*$ic void ca$$10dou*$e dou*

    min F max F current F dou*2

    3

    pu*$ic void shutdo-n0

    or*.shutdo-n0fa$se2

    3

    3

  • 8/13/2019 Middle Ware 10

    15/24

    Weat%erC(ient*)a,a

    import org.omg.CORBA.ORB2

    import org.omg.Cos8aming.8amingContextIxt2import org.omg.Cos8aming.8amingContextIxte$per2

    pu*$ic c$ass JeatherC$ient

    static Jeather -eather2

    pu*$ic static void main0StringD E args

    dou*$eD ED E d1 F 1.)?(.#?).9?(.)3?#.&?,.9?+.#?(.,3?(.&?#.)?&.)?+.,3?).#?(.&?9.#?+.#332

    String D E str F HChennaiH?H=um*aiH?He$hiH?HCa$cuttaH32tr4

    ORB or* F ORB.init0args? nu$$2

    org.omg.CORBA.O*%ecto*%ectRef For*.reso$ve/initia$/references0H8amingServiceH2

    8amingContextIxtnamingContextRef F

    8amingContextIxte$per.narro-0o*%ectRef2

    String name F He$$oH2-eather F

    Jeathere$per.narro-0namingContextRef.reso$ve/str0name2

    -eather.ca$$10#;.;2S4stem.out.print$n0H5n5nH2

    S4stem.out.print$n0H5t5t JIATIR ORICAST!8MH2

    S4stem.out.print$n0H5t5t H2for 0int %F;2 %>(2 %GG

    S4stem.out.print$n0H5n5nH2

    S4stem.out.print$n0HCit4:HGstrD%E2for 0int iF;2 i>&2 iGG

    -eather.ad%ustTemp0d1D%EDiE23

    S4stem.out.print$n0H5t5t =aximum

    Temperature:HG-eather.get=ax02S4stem.out.print$n0H5t5t =inimum

    Temperature:HG-eather.get=in02

    3

    -eather.shutdo-n02

  • 8/13/2019 Middle Ware 10

    16/24

    3

    catch 0Ixception e

    S4stem.out.print$n0HIRROR:HGe2

    e.printStackTrace023

    3

    3

    Weat%er*i'(

    modu$e JeatherApp

    interface Jeather

    void ad%ustTemp0in dou*$e r2dou*$e getCurrent02

    dou*$e get=ax02dou*$e get=in02

    void ca$$10in dou*$e k2

    one-a4 void shutdo-n0232

    32

    OUTPUT:

    I:5Cor*a6set 'ATFQ'ATQ.2 I:5Cor*a2I:5Cor*a6set C"ASS'ATFQC"ASS'ATQ.2 I:5Cor*a2

    I:5Cor*a6id$% Jeather.id$

    I:5Cor*a6id$% fa$$ Jeather.id$I:5Cor*a6%avac .%ava JeatherApp

  • 8/13/2019 Middle Ware 10

    17/24

    =inimum Temperature: 19.(

    Cit4: I"!

    =aximum Temperature: #@.@=inimum Temperature: 19.(

    Cit4: O"ATTA

    Date Time Server Ti!eServer"n#.javainter/ace e/initionimport java.rmi.*;p"blic inter/ace imeServerIn/ extens Remote! p"blic String $etTi!e%&t1ro-s Remote5xception;&

    Ti!eServer"!'l.javaimport java.rmi.*;import java.rmi.server.*;p"blic class imeServerImpl extens @nicastRemoteObject implements

    imeServerIn/ !

    p"blic imeServerImpl#$ t1ro-s Remote5xception ! s"per#$; &

    p"blic String $etTi!e#$!

    ret"rn ne- java."til.Jate#$.toString#$; &

    p"blic static voi main# String args() $ t1ro-s 5xception!

    S+stem.err.println# 0InitialiQing server8 please -ait.0 $;

    Na!in$.re(ind% )**local+o,t*Ti!e)- ne Ti!eServer"!'l%& $;

    S+stem.err.println#01e ime Server is "p an r"nning.0 $; &&

    Ti!eClient.javaimport java.rmi.*;

    p"blic class imeClient !

    p"blic static voi main# String args() $ t1ro-s 5xception! Ti!eServer"n# t, / %Ti!eServer"n#&Na!in$.look0'% )**local+o,t*Ti!e) &1 S+stem.o"t.println#t,.$etTi!e%&$; &

  • 8/13/2019 Middle Ware 10

    18/24

    Ti!eClient O0t'0t1e time is8 "e "n 3 338> 5J 4C$ient!nterface6 c$ients F ne- Arra4"ist>C$ient!nterface602

    pu*$ic Server0 thro-s RemoteIxception

    3

    pu*$ic void $ogin0C$ient!nterface c$ient? String nickname thro-s

    RemoteIxception

    *roadcast=essage0H6 H G nickname G H is entering the chatroomH? HH2

    c$ients.add0c$ient23

    pu*$ic void *roadcast=essage0String message? String nickname thro-sRemoteIxception

    for 0int i F ;2 i > c$ients.sie02 iGG

    C$ient!nterface c F c$ients.get0i2tr4

    c.get=essage0message? nickname2

    3 catch 0RemoteIxception e

    $ogout0c2

    i F i 12

    33

    3

  • 8/13/2019 Middle Ware 10

    19/24

    pu*$ic void $ogout0C$ient!nterface c$ient

    c$ients.remove0c$ient2

    3

    pu*$ic static void main0StringDE args

    tr4

    8aming.re*ind0HServerH? ne- Server02

    S4stem.out.print$n0HServer is read4H23

    catch 0Ixception e

    e.printStackTrace023

    33

    Ser,er Interface

    import %ava.rmi.2

    pu*$ic interface Server!nterface extends Remote

    pu*$ic void $ogin0C$ient!nterface c$ient? String nickname thro-s

    RemoteIxception2

    pu*$ic void *roadcast=essage0String message? String nickname thro-s

    RemoteIxception23

    C(ient Interface

    import %ava.rmi.Remote2

    import %ava.rmi.RemoteIxception2

    pu*$ic interface C$ient!nterface extends Remote

    pu*$ic void get=essage0String message? String nickname thro-s

    RemoteIxception2

    3

  • 8/13/2019 Middle Ware 10

    20/24

    GUI

    import %ava.a-t.event.2import %ava.net.2

    import %ava.rmi.2

    import %avax.s-ing.2

    pu*$ic c$ass MN! extends %avax.s-ing.rame

    private C$ient c$ient2

  • 8/13/2019 Middle Ware 10

    21/24

    private void initMN!0

    tr4

    %Scro$$'aneistor4 F ne- Scro$$'ane02

    getContent'ane0.add0%Scro$$'aneistor42%Scro$$'aneistor4.setBounds0,? ,? &,9? #;&2

    %Scro$$'aneistor4.setorionta$Scro$$Bar'o$ic40Scro$$'ane.OR!VO8TA"/SCRO""

    BAR/8I7IR2

    istor4 F ne- TextArea02istor4.set"ineJrap0true2

    istor4.setIdita*$e0fa$se2

    %Scro$$'aneistor4.set7ie-port7ie-0istor42

    33

    =essage F ne- Textie$d02

    getContent'ane0.add0=essage2

    =essage.setBounds0,? #1,? &,9? (#2=essage.adde4"istener0ne- e4Adapter0

    pu*$ic void ke4Re$eased0e4Ivent evt

    =essagee4'ressed0evt2

    332

    3

    setefau$tC$oseOperation0Jindo-Constants.!S'OSI/O8/C"OSI2

    getContent'ane0.set"a4out0nu$$2

    this.setTit$e0H=4R=!Chat H G nickname2this.setResia*$e0fa$se2

    pack02

    setSie0(;;? &;;2

    3catch 0Ixception e

    e.printStackTrace023

    3

    pu*$ic static void sho-=essage0String message? String nickname

    if 0Unickname.equa$s0HH

    istor4.append0nickname G H: H G message G H5nH2

    e$se istor4.append0message G H5nH2

  • 8/13/2019 Middle Ware 10

    22/24

    3

    private void =essagee4'ressed0e4Ivent evt if 0evt.gete4Code0 FF e4Ivent.7/I8TIR PP U

    =essage.getText0.equa$s0HH

    tr4 server.*roadcast=essage0=essage.getText0? nickname2

    =essage.setText0HH2

    3 catch 0RemoteIxception e e.printStackTrace02

    3

    3

    33

    C(ient

    import %ava.rmi.RemoteIxception2

    import %ava.rmi.server.NnicastRemoteO*%ect2pu*$ic c$ass C$ient extends NnicastRemoteO*%ect imp$ements C$ient!nterface

    pu*$ic C$ient0 thro-s RemoteIxception

    3

    pu*$ic void get=essage0String message? String nickname thro-s

    RemoteIxception

    MN!.sho-=essage0message? nickname2

    3

    3

  • 8/13/2019 Middle Ware 10

    23/24

    Ti$e Ser,er

    C(ient

    import %ava.rmi.2

    import %ava.net.2

    import %ava.io.2pu*$ic c$ass C$ient

    pu*$ic static void main0StringargsDEthro-s Ixception

    tr4

    String sFHrmi:

  • 8/13/2019 Middle Ware 10

    24/24

    return ne- %ava.uti$.ate0.toString02

    33