1. Trang chủ
  2. » Công Nghệ Thông Tin

wiley interscience tools and environments for parallel and distributed computing phần 6 ppsx

23 244 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 23
Dung lượng 230,76 KB

Nội dung

java : \$(MAKE) -f Makefile.java clean_java : \$(MAKE) -f Makefile.java clean Makefile.java: .SUFFIXES: .java .class .idl .module .java.class: vbjc \$< .idl.module: idl2java \$< touch \$@ default: all clean: rm -rf Ping rm -f *.class *.tmp *.module *~ IDLS = \ Ping.idl MODULES = \$(IDLS: .idl = .module) SRCS = \ PingCorbaImpl.java \ PingCorbaClient.java \ PingCorbaServer.java CLASSES = \$(SRCS: .java=.class all: \$(MODULES) \$(CLASSES) Step 7: Launch the Application Before running the client programs or server applications, you must start the Visibroker Smart Agent [20] on at least one host in your local network. Launch the application as follows: • Start the Smart Agent: Prompt> osagent • Start the server: Prompt> vbj PingCorbaServer • Run the client: Prompt> vbj PingCorbaClient DCOM Step 1: Create the .idl file—PingDCOM.idl [ // A unique 128-bit identifier for the PingDCOM // library // This can be generated by using utilities like // guidgen, provided by Microsoft EXAMPLES 99 uuid(5f648dc9-00e2-1000-5000-86448cae0000), version(1.0), helpstring("PingDCOM library definition. ") ] library PingDCOM { // import the standard OLE library. This gives access // to the standard OLE types importlib("STDOLE2.TLB"); // Forward declare all types defined in this IDL file interface IPingServerDCOM; coclass PingServerDCOM; [ odl, uuid(5f651112-00e2-1000-5002-86448cae0000), helpstring("Interface for Java class PingServerDCOM "), dual, oleautomation ] interface IPingServerDCOM : IDispatch { [id(0x1), helpstring("Java method: public float[] PingServerDCOM.doReverse(float[])")] HRESULT doReverse([in] VARIANT p1, [out, retval] VARIANT *retVal); }; [ uuid(5f651112-00e2-1000-5001-86448cae0000), helpstring("Java class PingServerDCOM ") ] coclass PingServerDCOM { interface IPingServerDCOM; }; } HRESULT is the accepted form of return parameter for any DCOM method invocation. It defines a set of possible return values based on the success of the remote operation. S_OK, E_FAIL, E_POINTER, and E_UNEXPECTED are some of the common return values. Step 2: Run MIDL on the idl File The PingDCOM.idl file is compiled using Microsoft’s MIDL compiler. This is done by: midl PingDCOM.idl. This gen- 100 DISTRIBUTED-OBJECT COMPUTING TOOLS erates PingDCOM.tlb, which is the type library that will be used by the client. A type library is a binary representation of the component [5]. Step 3: Register the .tlb File The command javatlb PingDCOM.tlb is run next. This creates the .class files for the type library that have enough knowl- edge of how to convert the Java bytecode to COM-compatible calls. The tlb file, once registered, makes an entry into the system registry, which could be verified by running regedit. Step 4: Implement the PingDCOM Interface import java.io.*; import java.util.*; import com.ms.com.*; public class PingServerDCOM implements IPingServerDCOM { public float [] doReverse (float[] inputVect) { // reverse the input vector onto a temporary // vector and // return the temporary vector } // end of doReverse } // end of PingServerDCOM The implementation above is now compiled and the class file is placed in the <windows>\Java\Lib directory. Step 5: Register the Class File The implementation class file is registered using javareg/register/class PingServerD-COM.class/clsid:5f651112-00e2-1000- 5001-86448cae0000/surrogate. Javareg [22] is a command line tool provided by Microsoft SDK for Java that allows registering of Java classes as COM com- ponents in the Windows system registry. Surrogate suggests that this class server, when brought up, would associate itself with a surrogate process address space. Step 6: Set up DCOMCNFG The level and security and access are defined by DCOMCNFG for each registered class. Each registered class is treated as an application and the details pertaining to the location of where the appli- cation can be hosted and endpoints are furnished at this level. Machine-level access and launch rights are also set using this utility. The following steps are to be done at the client side. Step 7: Register the Type Library Javatlb PingDCOM.tlb is run on the client machine too, to register the interface IID on to the client’s registry. EXAMPLES 101 Step 8: Register the Object Class CLSID Javareg /register /class: PingServerDCOM.class /clsid:5f651112-00e2-1000-5001-86448cae0000. This command registers the remote object class id on to the local client machine. Step 9: Set up DCOMCNFG to Specify Location The server machine where the remote object is required to be hosted is specified using DCOMCNFG location tab. Step 10: Define Client Implementation import java.io.*; import java.util.*; public class PingDCOMClient { public static void main(String[] args) { try { // create the Ping Object – if the server // is not already running, this // would launch the server object IPingServerDCOM myPingObject = (IPingServerDCOM) new PingServerDCOM(); // initialize and populate the input vector // inputVect // initialize the output return vector // create a timer object TimeWrap oTimer = new TimeWrap(); // start the timer – this will be a native // interface call String sStartTime = oTimer.getFromTimer(); // loop around to perform repeated reversals through // remote call for(int i=0;i<iLoop;i++) { outVect = myPingObject.doReverse(inputVect); } // stop the timer String sEndTime = oTimer.getFromTimer(); // print the input and return vector contents for // verification // calculate the total time taken on an average for each // method call 102 DISTRIBUTED-OBJECT COMPUTING TOOLS lTimeDiff = (endTime-startTime) / iLoop; // display the ping results System.out.print("\nTime Taken for one DCOM call on an average (in MicroSec)= "); System.out.println(lTimeDiff); } catch(Exception e) { System.out.println("Exception in Client="+e.getMes- sage()); e.printStackTrace(); } } // end of main }// end of PingDCOMClient All the steps above outline the list of activities involved in implementing a DCOM server and client under a Windows environment. However, as the objective of this experiment was to measure the performance of DCOM and compare it with RMI and CORBA, the DCOM application was run on UNIX using a Pure Java-COM bridge [23]. Only the salient idiosyncrasies pertaining to that tool are outlined in brief as follows: • All COM-related libraries are implemented in the package com.linar. jintegra.*. • As UNIX-based systems do not have a system registry like-Windows, reg- istration of the COM components are done through monikers. When a server object is instantiated, the object moniker (named instance) is written down as a string into a moniker file. When a client requests for that server object reference, this moniker file is read and the string is con- verted back to an interface pointer pointing to the server object.This con- version is done internally at the time of binding to the server object after obtaining the moniker string. • The tool provides command line utilities, which allow the programmer to introduce COM-related specifics in a plain Java code. The command java2com converts a Java server implementation code to the corre- sponding COM IDL. The command com2java allows us to convert a type library (.tlb) into a Java package. 4.3.4 Experiment 2: Producer–Consumer Problem This problem gives an overview of how concurrency control can be achieved in a distributed environment using the three technologies RMI, CORBA, and DCOM. In this implementation the server object hosts a synchronized buffer. The client has a producer and a consumer, each running concurrently in its own thread and accessing the shared buffer on the server.The producer thread EXAMPLES 103 generates a float value which it writes onto the shared buffer, and the con- sumer thread reads this value. RMI Interface Definition of the Buffer: SyncBufferRMI.java public interface SyncBufferRMI extends java.rmi.Remote { public void deposit(float fInputData) throws java.rmi.RemoteException; public float consume() throws java.rmi.RemoteException; } // end of SyncBufferRMI This is the base interface, which represents the buffer, on to which the pro- ducer deposits new data and from which the consumer reads the next avail- able data. Interface Definition of the Buffer Manager: SyncBufferManagerRMI.java public interface SyncBufferManagerRMI extends java.rmi. Remote { SyncBufferRMI createNewSyncBuffer(int iSize) throws java.rmi.RemoteException; } // end of SyncBufferManagerRMI This is the interface that provides a new buffer to a client. This is required to make sure that each client creates and acts on a new synchronized buffer. Implementation of the Buffer: SyncBufferRMIImpl.java import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class SyncBufferRMIImpl extends UnicastRemoteObject implements SyncBufferRMI { private int m_iCapacity; private int m_iCount; private int m_iFront; private int m_iRear; private float[] m_data; 104 DISTRIBUTED-OBJECT COMPUTING TOOLS // this will be called by createNewSyncBuffer of the // SyncBufferManagerRMIImpl public SyncBufferRMIImpl(int iSize) throws Remote- Exception { super(); // initialise the matrix with the size provided } // end of constructor // deposit is called by the client directly by the pro // ducer thread public synchronized void deposit(float inputData) throws RemoteException { try { while(m_iCount==m_iCapacity) // means its full { wait(); } // write the new data into the next buffer position and // notify all notifyAll(); } catch(InterruptedException e) { System.out.println("Interrupted Exception in deposit()"); e.printStackTrace(); } } // end of deposit // consume is called by the client directly by the // consumer thread public synchronized float consume() throws RemoteEx- ception { try { while(m_iCount==0) { // means buff is empty and hence nothing to consume wait(); } } EXAMPLES 105 catch(InterruptedException e) { e.printStackTrace(); throw new RemoteException(); } // store the next available data into retValue and notify // all saying done notifyAll(); return retValue; } // end of consume } // end of SyncBufferRMIImpl Implementation of the Buffer Manager: SyncBufferManagerRMIImpl.java import java.rmi.*; import java.rmi.server.UnicastRemoteObject; public class SyncBufferManagerRMIImpl extends Unicast- RemoteObject implements SyncBufferManagerRMI { private String m_sName; // this is called by RMIServer code public SyncBufferManagerRMIImpl(String sName) throws RemoteException { super(); m_sName = sName; } // end of constructor // this is called by the client directly and acts as a // new buffer provider public SyncBufferRMI createNewSyncBuffer(int iSize) throws RemoteException { return new SyncBufferRMIImpl(iSize); } // end of createNewSyncBuffer } // end of SyncBufferManagerRMIImpl Implementation of the Buffer Server: SyncBufferRMIServer.java import java.rmi.*; import java.rmi.server.*; public class SyncBufferRMIServer { public static void main(String[] args) { System.setSecurityManager(new RMISecurityManager()); 106 DISTRIBUTED-OBJECT COMPUTING TOOLS try { SyncBufferManagerRMIImpl syncBufferManager = new SyncBufferManagerRMIImpl("SyncBufferMan- ager"); System.out.println("RMI Object Created"); Naming.rebind("SyncBufferManager",sync- BufferManager); System.out.println("Binding Done"); } catch (Exception e) { System.out.println("Exception in SyncBuffer- RMIServer main: " + e.getMessage()); e.printStackTrace(); } } // end of main } // end of SyncBufferRMIServer Implementation of the Buffer Client: SyncBufferRMIClient.java import java.rmi.*; import java.rmi.registry.*; import java.rmi.server.*; public class SyncBufferRMIClient { public static void main(String[] args) { System.setSecurityManager(new RMISecurityManager()); try { SyncBufferManagerRMI mySyncBufferManager = (SyncBufferManagerRMI) Naming.lookup("rmi://"+args[0]+"/SyncBufferManager"); // initialize buffer size SyncBufferRMI mySyncBuffer = mySyncBufferManager.create- NewSyncBuffer (iBufSize); int iLoop=100; // create new producer and consumer threads EXAMPLES 107 Producer myProducer = new Producer (mySyncBuffer,iLoop); Consumer myConsumer = new Consumer (mySyncBuffer,iLoop); // the producer thread when started would // keep writing onto the syncbuffer // iLoop times myProducer.start(); // the consumer thread when started would keep reading // from the sync buffer // the data written by the producer, iLoop // times myConsumer.start(); // Main Thread of client waiting for // the producer and consumer threads to // terminate } catch(Exception e) { System.out.println("Exception in Client="+e. getMessage()); e.printStackTrace(); } } // end of main } // end of SyncBufferRMIClient The implementation of the producer and consumer threads is not shown here. Makefile: Makefile.java default: javac SyncBufferRMI.java javac SyncBufferRMIImpl.java rmic SyncBufferRMIImpl javac SyncBufferManagerRMI.java javac SyncBufferManagerRMIImpl.java rmic SyncBufferManagerRMIImpl javac SyncBufferRMIServer.java javac SyncBufferRMIClient.java clean: rm -f *.class 108 DISTRIBUTED-OBJECT COMPUTING TOOLS [...]... bufferCount ) { try { 110 DISTRIBUTED- OBJECT COMPUTING TOOLS //Wait for Consumer to get Value wait(); }catch(InterruptedException ie) { System.out.println(ie); } }//end of while //Add the value to the buffer and increment available count //Notify Consumer that buffer has been set notifyAll(); }//end of deposit public synchronized float consume() { while(availableCount . oTimer.getFromTimer(); // print the input and return vector contents for // verification // calculate the total time taken on an average for each // method call 102 DISTRIBUTED- OBJECT COMPUTING TOOLS lTimeDiff = (endTime-startTime). process address space. Step 6: Set up DCOMCNFG The level and security and access are defined by DCOMCNFG for each registered class. Each registered class is treated as an application and the details pertaining. client directly public synchronized float consume() { 1 16 DISTRIBUTED- OBJECT COMPUTING TOOLS try { while(m_iCount==0) { // means buff is empty and hence nothing to consume wait(); } } catch(InterruptedException

Ngày đăng: 13/08/2014, 12:21